Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sonarqube tasks #5

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
language: android
sudo: required
jdk: oraclejdk8

before_cache:
-rm -f $HOME/outlay/.gradle/caches/modules-2/modules-2.lock
-rm -fr $HOME/outlay/.gradle/caches/*/plugin-resolution/

cache:
directories:
- $HOME/outlay/.gradle/caches/
- $HOME/outlay/.gradle/wrapper/

env:
global:
- ANDROID_API=25
- EMULATOR_API=21
- ANDROID_BUILD_TOOLS=25.0.2
- ADB_INSTALL_TIMEOUT=10 # minutes

android:
components:
- tools
- platform-tools
- build-tools-$ANDROID_BUILD_TOOLS
- android-$ANDROID_API
# - android-$EMULATOR_API_LEVEL
- extra-google-m2repository
- extra-android-m2repository # for design library
# - sys-img-armeabi-v7a-addon-google_apis-google-$EMULATOR_API_LEVEL
licenses:
- android-sdk-preview-license-.+
- android-sdk-license-.+
- google-gdk-license-.+

before_install:
- cd outlay
- chmod +x gradlew

notifications:
email: false

before_script:
# - echo no | android create avd --force -n test -t android-21 --abi armeabi-v7a
# - emulator -avd test -no-skin -no-audio -no-window &
# - android-wait-for-emulator
# - adb shell input keyevent 82 &

script:
- ./gradlew clean build -x test
#- ./gradlew test
#- ./gradlew connectedAndroidTest
9 changes: 8 additions & 1 deletion outlay/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ android {
release {
buildConfigField "boolean", "USE_ANALYTICS", "true"

signingConfig signingConfigs.release
if (propsFile.exists()) {
signingConfig signingConfigs.release
}

minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
Expand All @@ -70,6 +72,11 @@ android {
targetCompatibility JavaVersion.VERSION_1_8
}

dexOptions {
preDexLibraries true
javaMaxHeapSize "3g"
}

packagingOptions {
//<div>Icons made by <a href="http://www.flaticon.com/authors/gregor-cresnar" title="Gregor Cresnar">Gregor Cresnar</a> from <a href="http://www.flaticon.com" title="Flaticon">www.flaticon.com</a> is licensed by <a href="http://creativecommons.org/licenses/by/3.0/" title="Creative Commons BY 3.0" target="_blank">CC 3.0 BY</a></div>
exclude 'META-INF/services/javax.annotation.processing.Processor'
Expand Down
42 changes: 42 additions & 0 deletions outlay/app/google-services.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"project_info": {
"project_number": "834201765141",
"firebase_url": "https://outlay-fd552.firebaseio.com",
"project_id": "outlay-fd552",
"storage_bucket": "outlay-fd552.appspot.com"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:834201765141:android:95649c21a8bc6266",
"android_client_info": {
"package_name": "app.outlay"
}
},
"oauth_client": [
{
"client_id": "834201765141-ueg7cmk78qi1pucd0oao4u6qcnaljrs8.apps.googleusercontent.com",
"client_type": 3
}
],
"api_key": [
{
"current_key": "AIzaSyARlbnnAaxhWAK2vNyUk50bZndCFdIULbA"
}
],
"services": {
"analytics_service": {
"status": 1
},
"appinvite_service": {
"status": 1,
"other_platform_oauth_client": []
},
"ads_service": {
"status": 2
}
}
}
],
"configuration_version": "1"
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
package app.outlay.firebase;

import android.support.annotation.NonNull;
import android.text.TextUtils;

import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.Query;
import com.google.firebase.database.ValueEventListener;
import app.outlay.core.utils.DateUtils;
import app.outlay.data.source.CategoryDataSource;
import app.outlay.data.source.ExpenseDataSource;
Expand All @@ -15,17 +10,14 @@
import app.outlay.domain.model.User;
import app.outlay.firebase.dto.ExpenseDto;
import app.outlay.firebase.dto.adapter.ExpenseAdapter;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.ValueEventListener;
import rx.Observable;

import javax.inject.Inject;

import rx.Observable;
import java.util.*;

/**
* Created by bmelnychuk on 10/27/16.
Expand Down Expand Up @@ -54,19 +46,15 @@ public Observable<Expense> saveExpense(Expense expense) {
return Observable.create(subscriber -> {
String key = expense.getId();
if (TextUtils.isEmpty(key)) {
key = mDatabase.child("users")
.child(currentUser.getId())
.child("expenses")
key = getCurrentUserExpenses()
.child(DateUtils.toYearMonthString(expense.getReportedWhen()))
.push().getKey();
expense.setId(key);
}

ExpenseDto expenseDto = adapter.fromExpense(expense);

DatabaseReference databaseReference = mDatabase.child("users")
.child(currentUser.getId())
.child("expenses")
DatabaseReference databaseReference = getCurrentUserExpenses()
.child(DateUtils.toYearMonthString(expense.getReportedWhen()))
.child(key);
databaseReference.addValueEventListener(new ValueEventListener() {
Expand All @@ -87,44 +75,6 @@ public void onCancelled(DatabaseError databaseError) {

@Override
public Observable<List<Expense>> getExpenses(Date startDate, Date endDate, String categoryId) {
final Observable<List<Expense>> listObservable = Observable.create(subscriber -> {
DatabaseReference databaseReference = mDatabase.child("users").child(currentUser.getId()).child("expenses");
Query query = databaseReference.orderByKey();
query = query.startAt(DateUtils.toYearMonthString(startDate)).endAt(DateUtils.toYearMonthString(endDate));
query.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
List<Expense> expenses = new ArrayList<>();
for (DataSnapshot monthSnapshot : dataSnapshot.getChildren()) {
for (DataSnapshot expensesSnapshot : monthSnapshot.getChildren()) {
ExpenseDto expenseDto = expensesSnapshot.getValue(ExpenseDto.class);
if (!TextUtils.isEmpty(categoryId) && !expenseDto.getCategoryId().equals(categoryId)) {
continue;
}
expenses.add(adapter.toExpense(expenseDto));
}
}
// at this point we ave monthly data

Iterator<Expense> expenseIterator = expenses.iterator();
while (expenseIterator.hasNext()) {
Expense e = expenseIterator.next();
if (!DateUtils.isInPeriod(e.getReportedWhen(), startDate, endDate)) {
expenseIterator.remove();
}
}

subscriber.onNext(expenses);
subscriber.onCompleted();
}

@Override
public void onCancelled(DatabaseError databaseError) {
subscriber.onError(databaseError.toException());
}
});
});

return categoryDataSource.getAll()
.map(categories -> {
Map<String, Category> categoryMap = new HashMap<>();
Expand All @@ -133,7 +83,8 @@ public void onCancelled(DatabaseError databaseError) {
}
return categoryMap;
}).switchMap(categoryMap ->
listObservable.flatMap(expenses -> Observable.from(expenses))
getListObservable(startDate, endDate, categoryId)
.flatMap(expenses -> Observable.from(expenses))
.map(expense -> {
String currentCatId = expense.getCategory().getId();
return expense.setCategory(categoryMap.get(currentCatId));
Expand All @@ -143,6 +94,51 @@ public void onCancelled(DatabaseError databaseError) {
);
}

@NonNull
private Observable<List<Expense>> getListObservable(final Date startDate, final Date endDate, final String categoryId) {
return Observable.create(subscriber ->
getCurrentUserExpenses()
.orderByKey()
.startAt(DateUtils.toYearMonthString(startDate))
.endAt(DateUtils.toYearMonthString(endDate))
.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
List<Expense> expenses = new ArrayList<>();
populateExpenses(expenses, dataSnapshot, categoryId);
removeExpensesOutsidePeriod(expenses, startDate, endDate);
subscriber.onNext(expenses);
subscriber.onCompleted();
}

@Override
public void onCancelled(DatabaseError databaseError) {
subscriber.onError(databaseError.toException());
}
}));
}

private void populateExpenses(List<Expense> expenses, DataSnapshot dataSnapshot, String categoryId) {
for (DataSnapshot monthSnapshot : dataSnapshot.getChildren()) {
for (DataSnapshot expensesSnapshot : monthSnapshot.getChildren()) {
ExpenseDto expenseDto = expensesSnapshot.getValue(ExpenseDto.class);
if (TextUtils.isEmpty(categoryId) || expenseDto.getCategoryId().equals(categoryId)) {
expenses.add(adapter.toExpense(expenseDto));
}
}
}
}

private void removeExpensesOutsidePeriod(List<Expense> expenses, Date startDate, Date endDate) {
Iterator<Expense> expenseIterator = expenses.iterator();
while (expenseIterator.hasNext()) {
Expense e = expenseIterator.next();
if (!DateUtils.isInPeriod(e.getReportedWhen(), startDate, endDate)) {
expenseIterator.remove();
}
}
}

@Override
public Observable<List<Expense>> getExpenses(Date startDate, Date endDate) {
return getExpenses(startDate, endDate, null);
Expand All @@ -151,9 +147,7 @@ public Observable<List<Expense>> getExpenses(Date startDate, Date endDate) {
@Override
public Observable<Expense> findExpense(String expenseId, Date date) {
Observable<Expense> expenseObservable = Observable.create(subscriber -> {
mDatabase.child("users")
.child(currentUser.getId())
.child("expenses")
getCurrentUserExpenses()
.child(DateUtils.toYearMonthString(date))
.child(expenseId)
.addListenerForSingleValueEvent(new ValueEventListener() {
Expand All @@ -179,13 +173,17 @@ public void onCancelled(DatabaseError databaseError) {
);
}

private DatabaseReference getCurrentUserExpenses() {
return mDatabase.child("users")
.child(currentUser.getId())
.child("expenses");
}

@Override
public Observable<Expense> remove(Expense expense) {
return Observable.create(subscriber -> {

DatabaseReference expenseRef = mDatabase.child("users")
.child(currentUser.getId())
.child("expenses")
DatabaseReference expenseRef = getCurrentUserExpenses()
.child(DateUtils.toYearMonthString(expense.getReportedWhen()))
.child(expense.getId());
expenseRef.addValueEventListener(new ValueEventListener() {
Expand All @@ -203,4 +201,5 @@ public void onCancelled(DatabaseError databaseError) {
expenseRef.removeValue();
});
}

}
10 changes: 2 additions & 8 deletions outlay/app/src/main/java/app/outlay/utils/ResourceUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import android.content.Context;
import android.graphics.drawable.Drawable;

import com.github.johnkil.print.PrintDrawable;

import java.util.Random;
Expand All @@ -11,13 +10,8 @@
* Created by Bogdan Melnychuk on 1/17/16.
*/
public final class ResourceUtils {
public static int getResourceId(Context context, String pVariableName, String pResourcename) {
try {
return context.getResources().getIdentifier(pVariableName, pResourcename, context.getPackageName());
} catch (Exception e) {
e.printStackTrace();
return -1;
}
private static int getResourceId(Context context, String pVariableName, String pResourcename) {
return context.getResources().getIdentifier(pVariableName, pResourcename, context.getPackageName());
}

public static int getStringResource(Context context, String stringResName) {
Expand Down
Loading