Skip to content

Commit

Permalink
New transaction auto complete WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
mvarnagiris committed Dec 13, 2014
1 parent 595b867 commit 129c29b
Show file tree
Hide file tree
Showing 30 changed files with 368 additions and 73 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.code44.finance.backend.endpoint.body;

import com.code44.finance.common.utils.StringUtils;
import com.code44.finance.common.utils.Strings;
import com.google.api.server.spi.response.BadRequestException;
import com.google.gson.annotations.SerializedName;

Expand All @@ -21,11 +21,11 @@ public class RegisterBody implements Body {
private String coverUrl;

public void verifyRequiredFields() throws BadRequestException {
if (StringUtils.isEmpty(googleId)) {
if (Strings.isEmpty(googleId)) {
throw new BadRequestException("google_id cannot be empty.");
}

if (StringUtils.isEmpty(firstName)) {
if (Strings.isEmpty(firstName)) {
throw new BadRequestException("first_name cannot be empty.");
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.code44.finance.backend.endpoint.body;

import com.code44.finance.common.utils.StringUtils;
import com.code44.finance.common.utils.Strings;
import com.google.api.server.spi.response.BadRequestException;
import com.google.gson.annotations.SerializedName;

Expand All @@ -9,7 +9,7 @@ public class RegisterDeviceBody implements Body {
private String regId;

public void verifyRequiredFields() throws BadRequestException {
if (StringUtils.isEmpty(regId)) {
if (Strings.isEmpty(regId)) {
throw new BadRequestException("registration_id cannot be empty.");
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.code44.finance.backend.entity;

import com.code44.finance.common.model.ModelState;
import com.code44.finance.common.utils.StringUtils;
import com.code44.finance.common.utils.Strings;
import com.google.api.server.spi.config.ApiResourceProperty;
import com.googlecode.objectify.annotation.Id;
import com.googlecode.objectify.annotation.Index;
Expand All @@ -28,7 +28,7 @@ protected BaseEntity() {
}

public void onCreate() {
if (StringUtils.isEmpty(getId())) {
if (Strings.isEmpty(getId())) {
setId(UUID.randomUUID().toString());
}
final long timestamp = System.currentTimeMillis();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.code44.finance.backend.endpoint.body.Body;
import com.code44.finance.backend.entity.DeviceEntity;
import com.code44.finance.backend.entity.UserAccount;
import com.code44.finance.common.utils.StringUtils;
import com.code44.finance.common.utils.Strings;
import com.google.android.gcm.server.Constants;
import com.google.android.gcm.server.Message;
import com.google.android.gcm.server.Result;
Expand Down Expand Up @@ -36,7 +36,7 @@ public static void verifyBodyNotNull(Body body) throws BadRequestException {
}

public static void verifyIdNotEmpty(String id) throws BadRequestException {
if (StringUtils.isEmpty(id)) {
if (Strings.isEmpty(id)) {
throw new BadRequestException("Id cannot be empty.");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static <T> T isNull(T object, String message) throws IllegalStateExceptio
}

public static String notEmpty(String str, String message) throws IllegalArgumentException {
if (StringUtils.isEmpty(str)) {
if (Strings.isEmpty(str)) {
throw new IllegalArgumentException(message);
}
return str;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.code44.finance.common.utils;

public final class StringUtils {
private StringUtils() {
public final class Strings {
private Strings() {
}

public static boolean isEmpty(String str) {
Expand Down
8 changes: 4 additions & 4 deletions financius/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ apply plugin: 'hugo'

android {
compileSdkVersion 21
buildToolsVersion '21.1.1'
buildToolsVersion '21.1.2'
defaultConfig {
applicationId 'com.code44.finance'
targetSdkVersion 21
Expand Down Expand Up @@ -63,13 +63,13 @@ dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(path: ':backend', configuration: 'android-endpoints')
compile project(path: ':common')
compile 'com.android.support:support-v4:21.0.2'
compile 'com.android.support:support-v4:21.0.3'
compile 'com.android.support:support-v13:20.0.0'
compile 'com.android.support:recyclerview-v7:21.0.0'
compile 'com.android.support:cardview-v7:21.0.0'
compile 'com.android.support:appcompat-v7:21.0.2'
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.android.support:multidex:1.0.0'
compile 'com.google.android.gms:play-services:6.1.71'
compile 'com.google.android.gms:play-services:6.1.+'
compile 'com.github.castorflex.smoothprogressbar:library:1.0.0'
compile 'com.github.castorflex.smoothprogressbar:library-circular:1.0.0'
compile 'com.squareup.okhttp:okhttp-urlconnection:2.0.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import com.code44.finance.api.Request;
import com.code44.finance.common.utils.Preconditions;
import com.code44.finance.common.utils.StringUtils;
import com.code44.finance.common.utils.Strings;
import com.code44.finance.data.DataStore;
import com.code44.finance.data.db.Tables;
import com.code44.finance.data.model.Currency;
Expand Down Expand Up @@ -57,7 +57,7 @@ public ExchangeRateRequest(EventBus eventBus, Context context, CurrenciesRequest
IOUtils.closeQuietly(cursor);

boolean currencyExists = true;
if (currency == null || StringUtils.isEmpty(currency.getId())) {
if (currency == null || Strings.isEmpty(currency.getId())) {
currencyExists = false;
currency = new Currency();
currency.setId(UUID.randomUUID().toString());
Expand Down
6 changes: 3 additions & 3 deletions financius/src/main/java/com/code44/finance/data/Query.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import android.support.v4.content.CursorLoader;
import android.text.TextUtils;

import com.code44.finance.common.utils.StringUtils;
import com.code44.finance.common.utils.Strings;
import com.code44.finance.data.db.Column;

import java.util.ArrayList;
Expand Down Expand Up @@ -35,7 +35,7 @@ public static Query create() {
private static String getSelectionWithGroupBy(Query query) {
final String groupBy = query.getGroupBy();
final String selection;
if (StringUtils.isEmpty(groupBy)) {
if (Strings.isEmpty(groupBy)) {
selection = query.getSelection();
} else {
selection = query.getSelection() + ") group by (" + groupBy;
Expand All @@ -47,7 +47,7 @@ private static String getSortOrderWithLimit(Query query) {
final int limit = query.getLimit();
String sortOrder = query.getSortOrder();
if (limit >= 0) {
sortOrder = StringUtils.isEmpty(sortOrder) ? "1" : sortOrder + " limit " + limit;
sortOrder = Strings.isEmpty(sortOrder) ? "1" : sortOrder + " limit " + limit;
}
return sortOrder;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.code44.finance.data.db;

import com.code44.finance.common.utils.StringUtils;
import com.code44.finance.common.utils.Strings;

public final class Column {
private final String tableName;
Expand Down Expand Up @@ -49,7 +49,7 @@ public String getName() {
* same as using {@link #getName()}.
*/
public String getName(String prefix) {
if (StringUtils.isEmpty(prefix)) {
if (Strings.isEmpty(prefix)) {
return getName();
} else {
return prefix + "_" + name;
Expand Down Expand Up @@ -80,7 +80,7 @@ public String getNameWithAs(String tableName) {
}

public String getCreateScript() {
return name + " " + dataType + (StringUtils.isEmpty(defaultValue) ? "" : " default " + defaultValue);
return name + " " + dataType + (Strings.isEmpty(defaultValue) ? "" : " default " + defaultValue);
}

public static enum DataType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import com.code44.finance.common.model.ModelState;
import com.code44.finance.common.utils.Preconditions;
import com.code44.finance.common.utils.StringUtils;
import com.code44.finance.common.utils.Strings;
import com.code44.finance.data.db.Column;

import java.util.UUID;
Expand Down Expand Up @@ -52,7 +52,7 @@ protected Model(Parcel parcel) {
// We are only checking id, because otherwise some parts of the app might misbehave
// For example BaseModelAdapter contains Set<BaseModel> selectedItems
// noinspection RedundantIfStatement
return !(StringUtils.isEmpty(id) || StringUtils.isEmpty(model.id)) && id.equals(model.id);
return !(Strings.isEmpty(id) || Strings.isEmpty(model.id)) && id.equals(model.id);

}

Expand All @@ -70,7 +70,7 @@ protected Model(Parcel parcel) {
protected abstract Column getSyncStateColumn();

public void prepareForDb() {
if (StringUtils.isEmpty(id)) {
if (Strings.isEmpty(id)) {
id = UUID.randomUUID().toString();
}

Expand Down Expand Up @@ -159,6 +159,6 @@ public void updateFrom(Cursor cursor, String columnPrefixTable) {
}

public boolean hasId() {
return !StringUtils.isEmpty(id);
return !Strings.isEmpty(id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import com.code44.finance.common.model.TransactionState;
import com.code44.finance.common.model.TransactionType;
import com.code44.finance.common.utils.Preconditions;
import com.code44.finance.common.utils.StringUtils;
import com.code44.finance.common.utils.Strings;
import com.code44.finance.data.db.Column;
import com.code44.finance.data.db.Tables;
import com.crashlytics.android.Crashlytics;
Expand Down Expand Up @@ -243,7 +243,7 @@ public static Transaction from(Cursor cursor) {

// Account from
index = cursor.getColumnIndex(Tables.Transactions.ACCOUNT_FROM_ID.getName(columnPrefixTable));
if (index >= 0 && !StringUtils.isEmpty(cursor.getString(index)) && !cursor.getString(index).equals("null")) {
if (index >= 0 && !Strings.isEmpty(cursor.getString(index)) && !cursor.getString(index).equals("null")) {
final Account accountFrom = Account.fromAccountFrom(cursor);
accountFrom.setId(cursor.getString(index));
setAccountFrom(accountFrom);
Expand All @@ -253,7 +253,7 @@ public static Transaction from(Cursor cursor) {

// Account to
index = cursor.getColumnIndex(Tables.Transactions.ACCOUNT_TO_ID.getName(columnPrefixTable));
if (index >= 0 && !StringUtils.isEmpty(cursor.getString(index)) && !cursor.getString(index).equals("null")) {
if (index >= 0 && !Strings.isEmpty(cursor.getString(index)) && !cursor.getString(index).equals("null")) {
final Account accountTo = Account.fromAccountTo(cursor);
accountTo.setId(cursor.getString(index));
setAccountTo(accountTo);
Expand All @@ -263,7 +263,7 @@ public static Transaction from(Cursor cursor) {

// Category
index = cursor.getColumnIndex(Tables.Transactions.CATEGORY_ID.getName(columnPrefixTable));
if (index >= 0 && !StringUtils.isEmpty(cursor.getString(index)) && !cursor.getString(index).equals("null")) {
if (index >= 0 && !Strings.isEmpty(cursor.getString(index)) && !cursor.getString(index).equals("null")) {
final Category category = Category.from(cursor);
category.setId(cursor.getString(index));
setCategory(category);
Expand All @@ -278,7 +278,7 @@ public static Transaction from(Cursor cursor) {
index = cursor.getColumnIndex(Tables.Tags.ID.getName(columnPrefixTable));
if (index >= 0) {
final String str = cursor.getString(index);
if (!StringUtils.isEmpty(str)) {
if (!Strings.isEmpty(str)) {
tagIds = TextUtils.split(str, Tables.CONCAT_SEPARATOR);
} else {
tagIds = null;
Expand All @@ -290,7 +290,7 @@ public static Transaction from(Cursor cursor) {
index = cursor.getColumnIndex(Tables.Tags.TITLE.getName(columnPrefixTable));
if (index >= 0) {
final String str = cursor.getString(index);
if (!StringUtils.isEmpty(str)) {
if (!Strings.isEmpty(str)) {
tagTitles = TextUtils.split(str, Tables.CONCAT_SEPARATOR);
} else {
tagTitles = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import com.code44.finance.common.model.ModelState;
import com.code44.finance.common.model.TransactionState;
import com.code44.finance.common.model.TransactionType;
import com.code44.finance.common.utils.StringUtils;
import com.code44.finance.common.utils.Strings;
import com.code44.finance.data.DataStore;
import com.code44.finance.data.Query;
import com.code44.finance.data.db.Column;
Expand Down Expand Up @@ -96,7 +96,7 @@ public static Uri uriAccount(String accountServerId) {

private long getCurrentBalance(ContentValues values) {
final String accountId = values.getAsString(Tables.Accounts.ID.getName());
if (StringUtils.isEmpty(accountId)) {
if (Strings.isEmpty(accountId)) {
return 0;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import com.code44.finance.api.Api;
import com.code44.finance.common.model.ModelState;
import com.code44.finance.common.utils.StringUtils;
import com.code44.finance.common.utils.Strings;
import com.code44.finance.data.Query;
import com.code44.finance.data.db.Column;
import com.code44.finance.data.db.Tables;
Expand Down Expand Up @@ -91,7 +91,7 @@ public static Uri uriModel(Class<? extends BaseModelProvider> providerClass, Str

@Override public Uri insert(Uri uri, ContentValues values) {
final String serverId = values.getAsString(getIdColumn().getName());
if (StringUtils.isEmpty(serverId)) {
if (Strings.isEmpty(serverId)) {
throw new IllegalArgumentException("Server Id cannot be empty.");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import android.content.Context;
import android.content.Intent;

import com.code44.finance.common.utils.StringUtils;
import com.code44.finance.common.utils.Strings;

import java.io.File;

Expand All @@ -24,7 +24,7 @@ private static Intent makeIntent(Context context, boolean allowCreateDir, int mo
intent.putExtra(EXTRA_ALLOW_CREATE_DIR, allowCreateDir);
intent.putExtra(EXTRA_ALLOW_MULTIPLE, false);
intent.putExtra(EXTRA_MODE, mode);
if (!StringUtils.isEmpty(startPath) && new File(startPath).exists()) {
if (!Strings.isEmpty(startPath) && new File(startPath).exists()) {
intent.putExtra(EXTRA_START_PATH, startPath);
}
return intent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

import com.code44.finance.R;
import com.code44.finance.common.model.TransactionType;
import com.code44.finance.common.utils.StringUtils;
import com.code44.finance.common.utils.Strings;
import com.code44.finance.data.DataStore;
import com.code44.finance.data.db.Tables;
import com.code44.finance.data.model.Category;
Expand Down Expand Up @@ -88,7 +88,7 @@ public static void start(Context context, String categoryId) {

@Override protected Category getModelFrom(Cursor cursor) {
final Category category = Category.from(cursor);
if (StringUtils.isEmpty(category.getId())) {
if (Strings.isEmpty(category.getId())) {
category.setColor(0xff607d8b);
}
return category;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import android.view.MenuItem;

import com.code44.finance.R;
import com.code44.finance.common.utils.StringUtils;
import com.code44.finance.common.utils.Strings;
import com.code44.finance.data.model.Model;
import com.code44.finance.ui.DrawerActivity;
import com.code44.finance.ui.ModelFragment;
Expand Down Expand Up @@ -115,7 +115,7 @@ protected static Intent makeIntent(Context context, Class<? extends ModelActivit

protected void onExtras(Intent extras) {
modelId = extras.getStringExtra(EXTRA_MODEL_ID);
if (StringUtils.isEmpty(modelId)) {
if (Strings.isEmpty(modelId)) {
modelId = "0";
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import android.widget.TextView;

import com.code44.finance.R;
import com.code44.finance.common.utils.StringUtils;
import com.code44.finance.common.utils.Strings;
import com.code44.finance.data.DataStore;
import com.code44.finance.data.model.Account;
import com.code44.finance.data.model.Currency;
Expand All @@ -39,7 +39,7 @@ public CurrencyAccountsAdapter(Context context) {
}

@Override public int getCount() {
return currency == null || StringUtils.isEmpty(currency.getCode()) ? 0 : super.getCount();
return currency == null || Strings.isEmpty(currency.getCode()) ? 0 : super.getCount();
}

@Override public View newView(Context context, Cursor cursor, ViewGroup parent) {
Expand Down
Loading

0 comments on commit 129c29b

Please sign in to comment.