Skip to content
This repository was archived by the owner on Jun 27, 2020. It is now read-only.
Merged
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
17 changes: 7 additions & 10 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -63,22 +63,19 @@ apply plugin: 'com.getkeepsafe.dexcount'
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])

// View annotation bindings
// Dependency injection tool
// Charts
// Advanced logging tool


compile('com.crashlytics.sdk.android:crashlytics:2.6.5@aar') {
transitive = true;
}

compile 'com.android.support:support-v4:25.1.0'
compile 'com.android.support:appcompat-v7:25.1.0'
compile 'com.android.support:design:25.1.0'
compile 'com.jakewharton:butterknife:7.0.1'
compile 'com.google.dagger:dagger:2.0.1'
compile 'com.github.PhilJay:MPAndroidChart:v2.2.4'
compile 'com.jakewharton.timber:timber:4.1.2'

compile 'com.jakewharton:butterknife:7.0.1' // View annotation bindings
compile 'com.google.dagger:dagger:2.0.1' // Dependency injection tool
compile 'com.github.PhilJay:MPAndroidChart:v2.2.4' // Charts
compile 'com.jakewharton.timber:timber:4.1.2' // Advanced logging tool

testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:2.0.43-beta'
androidTestCompile 'com.crittercism.dexmaker:dexmaker:1.4'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.blogspot.e_kanivets.moneytracker.adapter.ExpandableListReportAdapter;
import com.blogspot.e_kanivets.moneytracker.controller.CurrencyController;
import com.blogspot.e_kanivets.moneytracker.controller.data.ExchangeRateController;
import com.blogspot.e_kanivets.moneytracker.controller.data.RecordController;
import com.blogspot.e_kanivets.moneytracker.entity.Period;
import com.blogspot.e_kanivets.moneytracker.entity.data.Record;
import com.blogspot.e_kanivets.moneytracker.report.record.RecordReportConverter;
Expand All @@ -29,8 +30,9 @@ public class ReportActivity extends BaseBackActivity {
private static final String TAG = "ReportActivity";

public static final String KEY_PERIOD = "key_period";
public static final String KEY_RECORD_LIST = "key_record_list";

@Inject
RecordController recordController;
@Inject
ExchangeRateController rateController;
@Inject
Expand All @@ -57,12 +59,11 @@ protected boolean initData() {
super.initData();
getAppComponent().inject(ReportActivity.this);

recordList = getIntent().getParcelableArrayListExtra(KEY_RECORD_LIST);
if (recordList == null) return false;

period = getIntent().getParcelableExtra(KEY_PERIOD);
if (period == null) return false;

recordList = recordController.getRecordsForPeriod(period);

return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.view.MenuItem;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.EditText;

import com.blogspot.e_kanivets.moneytracker.R;
import com.blogspot.e_kanivets.moneytracker.activity.base.BaseBackActivity;
Expand Down Expand Up @@ -34,6 +35,10 @@ public class AddAccountActivity extends BaseBackActivity {

@Bind(R.id.content)
View contentView;
@Bind(R.id.et_title)
EditText etTitle;
@Bind(R.id.et_init_sum)
EditText etInitSum;
@Bind(R.id.spinner)
AppCompatSpinner spinner;

Expand Down Expand Up @@ -88,8 +93,13 @@ private void tryAddAccount() {

@SuppressWarnings("SimplifiableIfStatement")
private boolean addAccount() {
Account account = accountValidator.validate();
if (account == null) return false;
else return accountController.create(account) != null;
if (accountValidator.validate()) {
String title = etTitle.getText().toString().trim();
double initSum = Double.parseDouble(etInitSum.getText().toString().trim());
String currency = (String) spinner.getSelectedItem();
return accountController.create(new Account(title, initSum, currency)) != null;
} else {
return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.view.MenuItem;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.EditText;

import com.blogspot.e_kanivets.moneytracker.R;
import com.blogspot.e_kanivets.moneytracker.activity.base.BaseBackActivity;
Expand Down Expand Up @@ -42,6 +43,10 @@ public class TransferActivity extends BaseBackActivity {
AppCompatSpinner spinnerFrom;
@Bind(R.id.spinner_to)
AppCompatSpinner spinnerTo;
@Bind(R.id.et_from_amount)
EditText etFromAmount;
@Bind(R.id.et_to_amount)
EditText etToAmount;

@Override
protected int getContentViewId() {
Expand All @@ -65,7 +70,7 @@ protected void initViews() {
accounts.add(account.getTitle());
}

transferValidator = new TransferValidator(TransferActivity.this, contentView, accountList);
transferValidator = new TransferValidator(TransferActivity.this, contentView);

if (accounts.size() == 0) {
accounts.add(getString(R.string.none));
Expand Down Expand Up @@ -109,8 +114,16 @@ private void tryTransfer() {

@SuppressWarnings("SimplifiableIfStatement")
private boolean doTransfer() {
Transfer transfer = transferValidator.validate();
if (transfer == null) return false;
else return transferController.create(transfer) != null;
if (transferValidator.validate()) {
Account fromAccount = accountList.get(spinnerFrom.getSelectedItemPosition());
Account toAccount = accountList.get(spinnerTo.getSelectedItemPosition());
double fromAmount = Double.parseDouble(etFromAmount.getText().toString());
double toAmount = Double.parseDouble(etToAmount.getText().toString());

return transferController.create(new Transfer(System.currentTimeMillis(),
fromAccount.getId(), toAccount.getId(), fromAmount, toAmount)) != null;
} else {
return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,16 @@ private void tryAddExchangeRate() {

@SuppressWarnings("SimplifiableIfStatement")
private boolean addExchangeRate() {
ExchangeRatePair pair = exchangeRatePairValidator.validate();
if (pair == null) return false;
else return exchangeRateController.createExchangeRatePair(pair) != null;
if (exchangeRatePairValidator.validate()) {
String fromCurrency = (String) spinnerFromCurrency.getSelectedItem();
String toCurrency = (String) spinnerToCurrency.getSelectedItem();
double amountBuy = Double.parseDouble(etBuy.getText().toString().trim());
double amountSell = Double.parseDouble(etSell.getText().toString().trim());

return exchangeRateController.createExchangeRatePair(
new ExchangeRatePair(fromCurrency, toCurrency, amountBuy, amountSell)) != null;
} else {
return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@
import com.blogspot.e_kanivets.moneytracker.activity.base.BaseBackActivity;
import com.blogspot.e_kanivets.moneytracker.adapter.CategoryAutoCompleteAdapter;
import com.blogspot.e_kanivets.moneytracker.controller.FormatController;
import com.blogspot.e_kanivets.moneytracker.controller.PreferenceController;
import com.blogspot.e_kanivets.moneytracker.controller.data.AccountController;
import com.blogspot.e_kanivets.moneytracker.controller.data.CategoryController;
import com.blogspot.e_kanivets.moneytracker.controller.data.RecordController;
import com.blogspot.e_kanivets.moneytracker.entity.data.Account;
import com.blogspot.e_kanivets.moneytracker.entity.data.Category;
import com.blogspot.e_kanivets.moneytracker.entity.data.Record;
import com.blogspot.e_kanivets.moneytracker.ui.AddRecordUiDecorator;
import com.blogspot.e_kanivets.moneytracker.util.AnswersProxy;
Expand Down Expand Up @@ -75,9 +77,12 @@ public class AddRecordActivity extends BaseBackActivity {
AccountController accountController;
@Inject
FormatController formatController;
@Inject
PreferenceController preferenceController;

private IValidator<Record> recordValidator;
private AddRecordUiDecorator uiDecorator;
private CategoryAutoCompleter autoCompleter;

@Bind(R.id.content)
View contentView;
Expand Down Expand Up @@ -124,9 +129,8 @@ record = getIntent().getParcelableExtra(KEY_RECORD);
protected void initViews() {
super.initViews();

long recordId = record == null ? -1 : record.getId();
recordValidator = new RecordValidator(AddRecordActivity.this, contentView, mode,
accountList, timestamp, type, recordId);
recordValidator = new RecordValidator(AddRecordActivity.this, contentView);
autoCompleter = new CategoryAutoCompleter(categoryController, preferenceController);

// Add texts to dialog if it's edit dialog
if (mode == Mode.MODE_EDIT) {
Expand All @@ -138,8 +142,10 @@ protected void initViews() {
uiDecorator.decorateActionBar(getSupportActionBar(), mode, type);
presentSpinnerAccount();

etCategory.setAdapter(new CategoryAutoCompleteAdapter(AddRecordActivity.this,
R.layout.view_category_item, new CategoryAutoCompleter(categoryController)));

final CategoryAutoCompleteAdapter categoryAutoCompleteAdapter = new CategoryAutoCompleteAdapter(
AddRecordActivity.this, R.layout.view_category_item, autoCompleter);
etCategory.setAdapter(categoryAutoCompleteAdapter);
etCategory.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Expand All @@ -154,6 +160,21 @@ public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
return false;
}
});
etCategory.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View view, boolean hasFocus) {
if (hasFocus && etCategory.getText().toString().trim().isEmpty()) {
String title = etTitle.getText().toString().trim();
String prediction = autoCompleter.completeByRecordTitle(title);
if (prediction != null) {
etCategory.setAdapter(null);
etCategory.setText(prediction);
etCategory.selectAll();
etCategory.setAdapter(categoryAutoCompleteAdapter);
}
}
}
});

// Restrict ';' for input, because it's used as delimiter when exporting
etTitle.setFilters(new InputFilter[]{new SemicolonInputFilter()});
Expand Down Expand Up @@ -306,14 +327,41 @@ private void tryRecord() {

@SuppressWarnings("SimplifiableIfStatement")
private boolean addRecord() {
Record newRecord = recordValidator.validate();
if (newRecord == null) return false;
else {
if (recordValidator.validate()) {
long now = new Date().getTime();
if (timestamp > now) {
showToast(R.string.record_in_future);
return false;
}

String title = etTitle.getText().toString().trim();
String category = etCategory.getText().toString().trim();
double price = Double.parseDouble(etPrice.getText().toString());
Account account = accountList.get(spinnerAccount.getSelectedItemPosition());

if (title.isEmpty()) {
title = category;
}

Record newRecord = null;

if (mode == Mode.MODE_ADD) {
return recordController.create(newRecord) != null;
newRecord = recordController.create(new Record(timestamp, type, title,
new Category(category), price, account, account.getCurrency()));
} else if (mode == Mode.MODE_EDIT) {
return recordController.update(newRecord) != null;
} else return false;
long recordId = record == null ? -1 : record.getId();
newRecord = recordController.update(new Record(recordId, timestamp, type, title,
new Category(category), price, account, account.getCurrency()));
}

if (newRecord == null) {
return false;
} else {
autoCompleter.addRecordTitleCategoryPair(title, category);
return true;
}
} else {
return false;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ public void showReport() {
AnswersProxy.get().logButton("Show Report");
Intent intent = new Intent(MainActivity.this, ReportActivity.class);
intent.putExtra(ReportActivity.KEY_PERIOD, period);
intent.putExtra(ReportActivity.KEY_RECORD_LIST, (ArrayList<Record>) recordList);
startActivity(intent);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
import com.blogspot.e_kanivets.moneytracker.R;

import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;

/**
* Controller class to encapsulate Shared Preferences handling logic.
Expand All @@ -26,6 +29,7 @@ public class PreferenceController {
private static final String KEY_PERIOD_TYPE = "key_period_type";
private static final String KEY_DROPBOX_ACCESS_TOKEN = "key_dropbox_access_token";
private static final String KEY_FILTERED_CATEGORIES = "key_filtered_categories";
private static final String KEY_RECORD_TITLE_CATEGORY_PAIRS = "key_record_title_category_pairs";

private static final int RATE_PERIOD = 5;

Expand Down Expand Up @@ -91,6 +95,17 @@ public void writeFilteredCategories(@Nullable Set<String> categorySet) {
editor.apply();
}

public void writeRecordTitleCategoryPairs(@NonNull Map<String, String> map) {
Set<String> set = new TreeSet<>();
for (String key : map.keySet()) {
set.add(key + ";" + map.get(key));
}

SharedPreferences.Editor editor = getEditor();
editor.putStringSet(KEY_RECORD_TITLE_CATEGORY_PAIRS, set);
editor.apply();
}

public long readDefaultAccountId() {
String defaultAccountPref = context.getString(R.string.pref_default_account);
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
Expand Down Expand Up @@ -138,6 +153,22 @@ public Set<String> readFilteredCategories() {
return new HashSet<>(getDefaultPrefs().getStringSet(KEY_FILTERED_CATEGORIES, new HashSet<String>()));
}

@NonNull
public Map<String, String> readRecordTitleCategoryPairs() {
Map<String, String> map = new TreeMap<>();

Set<String> set = getDefaultPrefs().getStringSet(KEY_RECORD_TITLE_CATEGORY_PAIRS,
new HashSet<String>());
for (String entry : set) {
String[] words = entry.split(";");
if (words.length == 2) {
map.put(words[0], words[1]);
}
}

return map;
}

@NonNull
private SharedPreferences getDefaultPrefs() {
return context.getSharedPreferences(context.getPackageName(), Context.MODE_PRIVATE);
Expand Down
Loading