Skip to content
This repository was archived by the owner on Jun 27, 2020. It is now read-only.

Commit 5aac364

Browse files
author
Evgenii Kanivets
committed
Merge branch 'master' of github.com:evgenii-kanivets/Money-Tracker
2 parents b33a3b9 + a251030 commit 5aac364

File tree

21 files changed

+329
-38
lines changed

21 files changed

+329
-38
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,20 @@
8181
android:label="@string/backup_data"
8282
android:screenOrientation="portrait"
8383
android:theme="@style/Theme.Default" />
84+
<activity
85+
android:name=".activity.AboutActivity"
86+
android:label="@string/title_activity_about"
87+
android:screenOrientation="portrait"
88+
android:theme="@style/Theme.Default" />
89+
8490
<activity
8591
android:name="com.dropbox.client2.android.AuthActivity"
8692
android:configChanges="orientation|keyboard"
8793
android:launchMode="singleTask"
8894
android:theme="@android:style/Theme.Translucent.NoTitleBar">
8995
<intent-filter>
9096
<data android:scheme="db-5lqugcckdy9y6lj" />
97+
9198
<action android:name="android.intent.action.VIEW" />
9299

93100
<category android:name="android.intent.category.BROWSABLE" />
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.blogspot.e_kanivets.moneytracker.activity;
2+
3+
import android.text.method.LinkMovementMethod;
4+
import android.widget.TextView;
5+
6+
import com.blogspot.e_kanivets.moneytracker.R;
7+
import com.blogspot.e_kanivets.moneytracker.activity.base.BaseBackActivity;
8+
9+
import butterknife.Bind;
10+
11+
public class AboutActivity extends BaseBackActivity {
12+
@Bind(R.id.tv_about)
13+
TextView tvAbout;
14+
15+
@Override
16+
protected int getContentViewId() {
17+
return R.layout.activity_about;
18+
}
19+
20+
@Override
21+
protected void initViews() {
22+
super.initViews();
23+
tvAbout.setMovementMethod(LinkMovementMethod.getInstance());
24+
}
25+
}

app/src/main/java/com/blogspot/e_kanivets/moneytracker/activity/SettingsActivity.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package com.blogspot.e_kanivets.moneytracker.activity;
22

3+
import android.os.Build;
34
import android.os.Bundle;
45
import android.preference.ListPreference;
56
import android.preference.Preference;
67
import android.preference.PreferenceFragment;
78

9+
import com.blogspot.e_kanivets.moneytracker.BuildConfig;
810
import com.blogspot.e_kanivets.moneytracker.MtApp;
911
import com.blogspot.e_kanivets.moneytracker.R;
1012
import com.blogspot.e_kanivets.moneytracker.activity.base.BaseBackActivity;
@@ -58,6 +60,13 @@ public void onCreate(Bundle savedInstanceState) {
5860
setupDefaultAccountPref();
5961
setupDefaultCurrencyPref();
6062
setupDisplayPrecision();
63+
setupAboutPref();
64+
}
65+
66+
private void setupAboutPref() {
67+
Preference preference = findPreference(getString(R.string.pref_about));
68+
preference.setSummary(getString(R.string.about_summary, BuildConfig.VERSION_NAME,
69+
Build.VERSION.RELEASE));
6170
}
6271

6372
private void setupDefaultAccountPref() {

app/src/main/java/com/blogspot/e_kanivets/moneytracker/activity/base/BaseActivity.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,16 @@ protected void showToast(@StringRes int messageId) {
6868
Toast.makeText(BaseActivity.this, messageId, Toast.LENGTH_SHORT).show();
6969
}
7070

71-
public void startProgress() {
72-
if (getProgressBar() == null) return;
73-
getProgressBar().show();
71+
public void startProgress(@Nullable String message) {
72+
ProgressDialog progressDialog = getProgressDialog();
73+
if (progressDialog == null) return;
74+
if (message != null) progressDialog.setMessage(message);
75+
progressDialog.show();
7476
}
7577

7678
public void stopProgress() {
77-
if (getProgressBar() == null) return;
78-
getProgressBar().dismiss();
79+
if (getProgressDialog() == null) return;
80+
getProgressDialog().dismiss();
7981
}
8082

8183
public void showAlert(@Nullable String title, @Nullable String message) {
@@ -90,7 +92,7 @@ public void showAlert(@Nullable String title, @Nullable String message) {
9092
dialog.show();
9193
}
9294

93-
private ProgressDialog getProgressBar() {
95+
private ProgressDialog getProgressDialog() {
9496
if (progressDialog == null) progressDialog = new ProgressDialog(this);
9597
return progressDialog;
9698
}

app/src/main/java/com/blogspot/e_kanivets/moneytracker/activity/external/BackupActivity.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ protected void onResume() {
8989

9090
@OnClick(R.id.btn_backup_now)
9191
public void backupNow() {
92-
startProgress();
92+
startProgress(getString(R.string.making_backup));
9393
backupController.makeBackup(dbApi, new BackupController.OnBackupListener() {
9494
@Override
9595
public void onBackupSuccess() {
@@ -131,7 +131,7 @@ public void onClick(DialogInterface dialog, int which) {
131131
}
132132

133133
private void restoreBackup(final String backupName) {
134-
startProgress();
134+
startProgress(getString(R.string.restoring_backup));
135135
backupController.restoreBackup(dbApi, backupName, new BackupController.OnRestoreBackupListener() {
136136
@Override
137137
public void onRestoreSuccess() {
@@ -170,7 +170,7 @@ public void onRestoreFailure(String reason) {
170170
}
171171

172172
private void fetchBackups() {
173-
startProgress();
173+
startProgress(getString(R.string.fetching_backups));
174174
backupController.fetchBackups(dbApi, new BackupController.OnFetchBackupListListener() {
175175
@Override
176176
public void onBackupsFetched(@NonNull List<String> backupList) {

app/src/main/java/com/blogspot/e_kanivets/moneytracker/activity/external/ImportExportActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public void importRecords() {
8080
@Override
8181
protected void onPreExecute() {
8282
super.onPreExecute();
83-
startProgress();
83+
startProgress(getString(R.string.importing_records));
8484
}
8585

8686
@Override

app/src/main/java/com/blogspot/e_kanivets/moneytracker/activity/record/AddRecordActivity.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ protected void initViews() {
132132
if (getSupportActionBar() != null) {
133133
switch (type) {
134134
case Record.TYPE_EXPENSE:
135-
getSupportActionBar().setTitle(R.string.title_add_expense);
135+
if (mode == Mode.MODE_ADD) getSupportActionBar().setTitle(R.string.title_add_expense);
136+
else getSupportActionBar().setTitle(R.string.title_edit_expense);
136137
getSupportActionBar().setBackgroundDrawable(
137138
new ColorDrawable(getResources().getColor(R.color.red_light)));
138139
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
@@ -144,7 +145,8 @@ protected void initViews() {
144145
break;
145146

146147
case Record.TYPE_INCOME:
147-
getSupportActionBar().setTitle(R.string.title_add_income);
148+
if (mode == Mode.MODE_ADD) getSupportActionBar().setTitle(R.string.title_add_income);
149+
else getSupportActionBar().setTitle(R.string.title_edit_income);
148150
getSupportActionBar().setBackgroundDrawable(
149151
new ColorDrawable(getResources().getColor(R.color.green_light)));
150152
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {

app/src/main/java/com/blogspot/e_kanivets/moneytracker/adapter/CategoryAutoCompleteAdapter.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
11
package com.blogspot.e_kanivets.moneytracker.adapter;
22

33
import android.content.Context;
4+
import android.view.LayoutInflater;
5+
import android.view.View;
6+
import android.view.ViewGroup;
47
import android.widget.ArrayAdapter;
58
import android.widget.Filter;
69
import android.widget.Filterable;
10+
import android.widget.TextView;
711

12+
import com.blogspot.e_kanivets.moneytracker.R;
813
import com.blogspot.e_kanivets.moneytracker.util.CategoryAutoCompleter;
914

1015
import java.util.ArrayList;
1116
import java.util.List;
1217

18+
import butterknife.Bind;
19+
import butterknife.ButterKnife;
20+
1321
/**
1422
* Custom adapter to autocomplete categories.
1523
* Created on 3/18/16.
@@ -25,6 +33,31 @@ public CategoryAutoCompleteAdapter(Context context, int resource, CategoryAutoCo
2533
this.autoCompleter = autoCompleter;
2634
}
2735

36+
@Override
37+
public View getView(int position, View convertView, ViewGroup parent) {
38+
ViewHolder viewHolder;
39+
40+
if (convertView == null) {
41+
convertView = LayoutInflater.from(getContext()).inflate(R.layout.view_category_item, parent, false);
42+
viewHolder = new ViewHolder(convertView);
43+
convertView.setTag(viewHolder);
44+
} else viewHolder = (ViewHolder) convertView.getTag();
45+
46+
final String category = resultList.get(position);
47+
48+
viewHolder.tvCategory.setText(category);
49+
viewHolder.ivCancel.setOnClickListener(new View.OnClickListener() {
50+
@Override
51+
public void onClick(View v) {
52+
autoCompleter.removeFromAutoComplete(category);
53+
resultList.remove(category);
54+
notifyDataSetChanged();
55+
}
56+
});
57+
58+
return convertView;
59+
}
60+
2861
@Override
2962
public int getCount() {
3063
return resultList.size();
@@ -63,4 +96,15 @@ protected void publishResults(CharSequence constraint, FilterResults results) {
6396
}
6497
};
6598
}
99+
100+
public static class ViewHolder {
101+
@Bind(R.id.tv_category)
102+
TextView tvCategory;
103+
@Bind(R.id.iv_cancel)
104+
View ivCancel;
105+
106+
public ViewHolder(View view) {
107+
ButterKnife.bind(this, view);
108+
}
109+
}
66110
}

app/src/main/java/com/blogspot/e_kanivets/moneytracker/controller/PreferenceController.java

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
import com.blogspot.e_kanivets.moneytracker.R;
1010

11+
import java.util.HashSet;
12+
import java.util.Set;
13+
1114
/**
1215
* Controller class to encapsulate Shared Preferences handling logic.
1316
* Not deal with {@link com.blogspot.e_kanivets.moneytracker.repo.base.IRepo} instances as others.
@@ -22,6 +25,7 @@ public class PreferenceController {
2225
private static final String KEY_LAST_TS = "key_last_ts";
2326
private static final String KEY_PERIOD_TYPE = "key_period_type";
2427
private static final String KEY_DROPBOX_ACCESS_TOKEN = "key_dropbox_access_token";
28+
private static final String KEY_FILTERED_CATEGORIES = "key_filtered_categories";
2529

2630
private static final int RATE_PERIOD = 5;
2731

@@ -34,7 +38,7 @@ public PreferenceController(@NonNull Context context) {
3438

3539
public void addLaunchCount() {
3640
SharedPreferences preferences = getDefaultPrefs();
37-
SharedPreferences.Editor editor = preferences.edit();
41+
SharedPreferences.Editor editor = getEditor();
3842
editor.putInt(LAUNCH_COUNT, preferences.getInt(LAUNCH_COUNT, 0) + 1);
3943
editor.apply();
4044
}
@@ -50,16 +54,13 @@ public boolean checkRateDialog() {
5054
}
5155

5256
public void appRated() {
53-
SharedPreferences preferences = getDefaultPrefs();
54-
SharedPreferences.Editor editor = preferences.edit();
57+
SharedPreferences.Editor editor = getEditor();
5558
editor.putBoolean(APP_RATED, true);
5659
editor.apply();
5760
}
5861

5962
public void writeFirstTs(long firstTs) {
60-
SharedPreferences preferences = getDefaultPrefs();
61-
SharedPreferences.Editor editor = preferences.edit();
62-
63+
SharedPreferences.Editor editor = getEditor();
6364
editor.putLong(KEY_FIRST_TS, firstTs);
6465
editor.apply();
6566
}
@@ -73,21 +74,23 @@ public void writeLastTs(long lastTs) {
7374
}
7475

7576
public void writePeriodType(String periodType) {
76-
SharedPreferences preferences = getDefaultPrefs();
77-
SharedPreferences.Editor editor = preferences.edit();
78-
77+
SharedPreferences.Editor editor = getEditor();
7978
editor.putString(KEY_PERIOD_TYPE, periodType);
8079
editor.apply();
8180
}
8281

8382
public void writeDropboxAccessToken(String accessToken) {
84-
SharedPreferences preferences = getDefaultPrefs();
85-
SharedPreferences.Editor editor = preferences.edit();
86-
83+
SharedPreferences.Editor editor = getEditor();
8784
editor.putString(KEY_DROPBOX_ACCESS_TOKEN, accessToken);
8885
editor.apply();
8986
}
9087

88+
public void writeFilteredCategories(@Nullable Set<String> categorySet) {
89+
SharedPreferences.Editor editor = getEditor();
90+
editor.putStringSet(KEY_FILTERED_CATEGORIES, categorySet);
91+
editor.apply();
92+
}
93+
9194
public long readDefaultAccountId() {
9295
String defaultAccountPref = context.getString(R.string.pref_default_account);
9396
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
@@ -129,7 +132,19 @@ public String readDropboxAccessToken() {
129132
return getDefaultPrefs().getString(KEY_DROPBOX_ACCESS_TOKEN, null);
130133
}
131134

135+
@NonNull
136+
public Set<String> readFilteredCategories() {
137+
// http://stackoverflow.com/questions/14034803/misbehavior-when-trying-to-store-a-string-set-using-sharedpreferences/14034804#14034804
138+
return new HashSet<>(getDefaultPrefs().getStringSet(KEY_FILTERED_CATEGORIES, new HashSet<String>()));
139+
}
140+
141+
@NonNull
132142
private SharedPreferences getDefaultPrefs() {
133143
return context.getSharedPreferences(context.getPackageName(), Context.MODE_PRIVATE);
134144
}
145+
146+
@NonNull
147+
private SharedPreferences.Editor getEditor() {
148+
return getDefaultPrefs().edit();
149+
}
135150
}

0 commit comments

Comments
 (0)