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 6 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
03f4b26
Raise gradle version.
Sep 5, 2018
602d875
Update all dependencies.
Sep 5, 2018
857ff38
#95. Kotlinify EditAccountActivity.
Sep 5, 2018
bba8d27
#95. Move EditAccountActivity to activity.account.edit package.
Sep 5, 2018
a942879
#95. Partly move logic from EditAccountActivity to EditAccountFragment.
Sep 5, 2018
ababa1e
#95. Completely move all logic to EditAccountFragment.
Sep 6, 2018
bc6c4c0
#95. Ongoing refactoring.
Sep 6, 2018
b49d2b1
#95. Add AccountRecordFragment.
Sep 6, 2018
05c19ab
#95. Display account records.
Sep 6, 2018
bd7615d
#95. Rename FragmentAccountRecords to FragmentAccountOperations.
Sep 6, 2018
85e09ab
#95. Kotlinify TransferController.
Sep 10, 2018
710f433
#95. Display transfers as records in account operations.
Sep 10, 2018
3c75b2c
#95. Refactor AccountOperationsFragment.
Sep 10, 2018
7cc5dae
#95. Add tabs to EditAccountActivity.
Sep 10, 2018
db929b8
#95. Add localization.
Sep 10, 2018
6b4b778
#95. Hide FAB when going to Operations tab.
Sep 11, 2018
b622cbd
#95. Updated .travis.yml.
Sep 11, 2018
84e3b7f
Merge pull request #156 from evgenii-kanivets/feature-95_account_oper…
Sep 11, 2018
3e76c15
#150. Add 'Delete' button to backup item view.
Sep 11, 2018
01e5fb2
#150. Implement delete backup listener.
Sep 12, 2018
b4af995
#150. Extract async tasks from BackupController.
Sep 12, 2018
64cae2d
#150. Refactore BackupListener.
Sep 12, 2018
e9c945e
#150. Consolidate OnBackupListener.
Sep 12, 2018
953ca7e
#150. Implement Dropbox backup removal.
Sep 15, 2018
3e396b0
Merge pull request #157 from evgenii-kanivets/feature-150_dropbox_del…
Sep 15, 2018
3bb5ab2
Add 'Removing backup' message.
Sep 15, 2018
24fbc63
#134. Add account goal to EditAccountFragment.
Sep 16, 2018
ea19a2c
#134. Formatting.
Sep 16, 2018
1be7fed
Merge pull request #158 from evgenii-kanivets/feature-134_account_goal
Sep 16, 2018
9fb0339
#153. Add 'NON susbstitution currency' setting.
Sep 16, 2018
1898059
#153. Substitute NON currency in RecordController.
Sep 17, 2018
8015367
#153. Substitute NON currency in AccountController.
Sep 17, 2018
b6924c7
#153. Fine tune CurrencyController.
Sep 17, 2018
1dd6dd4
#153. Fix RecordControllerTest.
Sep 17, 2018
69aab3f
Merge pull request #159 from evgenii-kanivets/feature-153_non_substit…
Sep 17, 2018
69e2186
#155. Fix record layout.
Sep 17, 2018
e824ff1
Merge pull request #160 from evgenii-kanivets/bugfix-155
Sep 17, 2018
6e9450a
Fix tests.
Sep 17, 2018
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
Original file line number Diff line number Diff line change
Expand Up @@ -22,34 +22,25 @@
import javax.inject.Inject;

public class SettingsActivity extends BaseBackActivity {
@SuppressWarnings("unused")
private static final String TAG = "SettingsActivity";
@SuppressWarnings("unused") private static final String TAG = "SettingsActivity";

@Override
protected int getContentViewId() {
@Override protected int getContentViewId() {
return R.layout.activity_settings;
}

@Override
protected void initViews() {
@Override protected void initViews() {
super.initViews();

// Display the fragment as the main content.
getFragmentManager().beginTransaction()
.replace(R.id.content, new SettingsFragment())
.commit();
getFragmentManager().beginTransaction().replace(R.id.content, new SettingsFragment()).commit();
}

public static class SettingsFragment extends PreferenceFragment {
@Inject
AccountController accountController;
@Inject
CurrencyController currencyController;
@Inject
PreferenceController preferenceController;

@Override
public void onCreate(Bundle savedInstanceState) {
@Inject AccountController accountController;
@Inject CurrencyController currencyController;
@Inject PreferenceController preferenceController;

@Override public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

MtApp.get().getAppComponent().inject(SettingsFragment.this);
Expand All @@ -59,18 +50,14 @@ public void onCreate(Bundle savedInstanceState) {

setupDefaultAccountPref();
setupDefaultCurrencyPref();
setupNonSubstitutionCurrencyPref();
setupDisplayPrecision();
setupAboutPref();
}

private void setupAboutPref() {
Preference preference = findPreference(getString(R.string.pref_about));
preference.setSummary(getString(R.string.about_summary, BuildConfig.VERSION_NAME,
Build.VERSION.RELEASE));
}

private void setupDefaultAccountPref() {
ListPreference defaultAccountPref = (ListPreference) findPreference(getString(R.string.pref_default_account));
ListPreference defaultAccountPref =
(ListPreference) findPreference(getString(R.string.pref_default_account));
defaultAccountPref.setOnPreferenceChangeListener(preferenceChangeListener);

List<Account> accountList = accountController.readActiveAccounts();
Expand All @@ -87,9 +74,9 @@ private void setupDefaultAccountPref() {
}
}

@SuppressWarnings("ToArrayCallWithZeroLengthArrayArgument")
private void setupDefaultCurrencyPref() {
ListPreference defaultCurrencyPref = (ListPreference) findPreference(getString(R.string.pref_default_currency));
@SuppressWarnings("ToArrayCallWithZeroLengthArrayArgument") private void setupDefaultCurrencyPref() {
ListPreference defaultCurrencyPref =
(ListPreference) findPreference(getString(R.string.pref_default_currency));
defaultCurrencyPref.setOnPreferenceChangeListener(preferenceChangeListener);

List<String> currencyList = currencyController.readAll();
Expand All @@ -101,9 +88,23 @@ private void setupDefaultCurrencyPref() {
defaultCurrencyPref.setSummary(defaultCurrency);
}

@SuppressWarnings("ToArrayCallWithZeroLengthArrayArgument")
private void setupDisplayPrecision() {
ListPreference displayPrecisionPref = (ListPreference) findPreference(getString(R.string.pref_display_precision));
@SuppressWarnings("ToArrayCallWithZeroLengthArrayArgument") private void setupNonSubstitutionCurrencyPref() {
ListPreference nonSubstitutionCurrencyPref =
(ListPreference) findPreference(getString(R.string.pref_non_substitution_currency));
nonSubstitutionCurrencyPref.setOnPreferenceChangeListener(preferenceChangeListener);

List<String> currencyList = currencyController.readAll();
nonSubstitutionCurrencyPref.setEntries(currencyList.toArray(new String[0]));
nonSubstitutionCurrencyPref.setEntryValues(currencyList.toArray(new String[0]));

String nonSubstitutionCurrency = preferenceController.readNonSubstitutionCurrency();
nonSubstitutionCurrencyPref.setDefaultValue(nonSubstitutionCurrency);
nonSubstitutionCurrencyPref.setSummary(nonSubstitutionCurrency);
}

@SuppressWarnings("ToArrayCallWithZeroLengthArrayArgument") private void setupDisplayPrecision() {
ListPreference displayPrecisionPref =
(ListPreference) findPreference(getString(R.string.pref_display_precision));
displayPrecisionPref.setOnPreferenceChangeListener(preferenceChangeListener);

List<String> precisionListValues = new ArrayList<>();
Expand All @@ -124,6 +125,11 @@ private void setupDisplayPrecision() {
}
}

private void setupAboutPref() {
Preference preference = findPreference(getString(R.string.pref_about));
preference.setSummary(getString(R.string.about_summary, BuildConfig.VERSION_NAME, Build.VERSION.RELEASE));
}

@SuppressWarnings("ToArrayCallWithZeroLengthArrayArgument")
private String[] getEntries(List<Account> accountList) {
List<String> result = new ArrayList<>();
Expand All @@ -146,16 +152,15 @@ private String[] getEntryValues(List<Account> accountList) {
return result.toArray(new String[0]);
}

private Preference.OnPreferenceChangeListener preferenceChangeListener
= new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
// Previously we could set summary to default value,
// but now it's needed to display selected entry
preference.setSummary("%s");
getActivity().setResult(RESULT_OK);
return true;
}
};
private Preference.OnPreferenceChangeListener preferenceChangeListener =
new Preference.OnPreferenceChangeListener() {
@Override public boolean onPreferenceChange(Preference preference, Object newValue) {
// Previously we could set summary to default value,
// but now it's needed to display selected entry
preference.setSummary("%s");
getActivity().setResult(RESULT_OK);
return true;
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,19 @@ public class CurrencyController {
private AccountController accountController;
private PreferenceController preferenceController;

@NonNull
private List<String> currencyList;
@NonNull private List<String> currencyList;

public CurrencyController(AccountController accountController, PreferenceController preferenceController) {
this.accountController = accountController;
this.preferenceController = preferenceController;
currencyList = fetchCurrencies();
}

@NonNull
public List<String> readAll() {
@NonNull public List<String> readAll() {
return currencyList;
}

@NonNull
public String readDefaultCurrency() {
@NonNull public String readDefaultCurrency() {
// First of all read from Prefs
String currency = preferenceController.readDefaultCurrency();

Expand All @@ -54,8 +51,7 @@ public String readDefaultCurrency() {
return currency;
}

@NonNull
private List<String> fetchCurrencies() {
@NonNull private List<String> fetchCurrencies() {
Set<Currency> toret = new HashSet<>();
Locale[] locs = Locale.getAvailableLocales();

Expand All @@ -67,13 +63,15 @@ private List<String> fetchCurrencies() {
}
}

List<String> currencyList = new ArrayList<>();
List<String> currencySet = new ArrayList<>();
for (Currency currency : toret) {
currencyList.add(currency.getCurrencyCode());
currencySet.add(currency.getCurrencyCode());
}

currencyList.add(DbHelper.DEFAULT_ACCOUNT_CURRENCY);
currencyList.add("BYN"); // New belorussian ruble
currencySet.add(DbHelper.DEFAULT_ACCOUNT_CURRENCY);
currencySet.add("BYN"); // New belorussian ruble

currencyList = new ArrayList<>(currencySet);

Collections.sort(currencyList);

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

import com.blogspot.e_kanivets.moneytracker.R;

import com.blogspot.e_kanivets.moneytracker.repo.DbHelper;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
Expand All @@ -33,8 +34,7 @@ public class PreferenceController {

private static final int RATE_PERIOD = 5;

@NonNull
private Context context;
@NonNull private Context context;

public PreferenceController(@NonNull Context context) {
this.context = context;
Expand Down Expand Up @@ -113,22 +113,27 @@ public long readDefaultAccountId() {
return Long.parseLong(preferences.getString(defaultAccountPref, "-1"));
}

@Nullable
public String readDefaultCurrency() {
@Nullable public String readDefaultCurrency() {
String defaultCurrencyPref = context.getString(R.string.pref_default_currency);
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);

return preferences.getString(defaultCurrencyPref, null);
}

@NonNull
public String readDisplayPrecision() {
@NonNull public String readDisplayPrecision() {
String displayPrecisionPref = context.getString(R.string.pref_display_precision);
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);

return preferences.getString(displayPrecisionPref, FormatController.PRECISION_MATH);
}

@Nullable public String readNonSubstitutionCurrency() {
String nonSubstitutionCurrencyPref = context.getString(R.string.pref_non_substitution_currency);
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);

return preferences.getString(nonSubstitutionCurrencyPref, DbHelper.DEFAULT_ACCOUNT_CURRENCY);
}

public long readFirstTs() {
return getDefaultPrefs().getLong(KEY_FIRST_TS, -1);
}
Expand All @@ -137,28 +142,23 @@ public long readLastTs() {
return getDefaultPrefs().getLong(KEY_LAST_TS, -1);
}

@Nullable
public String readPeriodType() {
@Nullable public String readPeriodType() {
return getDefaultPrefs().getString(KEY_PERIOD_TYPE, null);
}

@Nullable
public String readDropboxAccessToken() {
@Nullable public String readDropboxAccessToken() {
return getDefaultPrefs().getString(KEY_DROPBOX_ACCESS_TOKEN, null);
}

@NonNull
public Set<String> readFilteredCategories() {
@NonNull public Set<String> readFilteredCategories() {
// http://stackoverflow.com/questions/14034803/misbehavior-when-trying-to-store-a-string-set-using-sharedpreferences/14034804#14034804
return new HashSet<>(getDefaultPrefs().getStringSet(KEY_FILTERED_CATEGORIES, new HashSet<String>()));
}

@NonNull
public Map<String, String> readRecordTitleCategoryPairs() {
@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>());
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) {
Expand All @@ -169,13 +169,11 @@ public Map<String, String> readRecordTitleCategoryPairs() {
return map;
}

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

@NonNull
private SharedPreferences.Editor getEditor() {
@NonNull private SharedPreferences.Editor getEditor() {
return getDefaultPrefs().edit();
}
}
Loading