Skip to content
This repository was archived by the owner on Jun 27, 2020. It is now read-only.
7 changes: 7 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,20 @@
android:label="@string/backup_data"
android:screenOrientation="portrait"
android:theme="@style/Theme.Default" />
<activity
android:name=".activity.AboutActivity"
android:label="@string/title_activity_about"
android:screenOrientation="portrait"
android:theme="@style/Theme.Default" />

<activity
android:name="com.dropbox.client2.android.AuthActivity"
android:configChanges="orientation|keyboard"
android:launchMode="singleTask"
android:theme="@android:style/Theme.Translucent.NoTitleBar">
<intent-filter>
<data android:scheme="db-5lqugcckdy9y6lj" />

<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.BROWSABLE" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.blogspot.e_kanivets.moneytracker.activity;

import android.text.method.LinkMovementMethod;
import android.widget.TextView;

import com.blogspot.e_kanivets.moneytracker.R;
import com.blogspot.e_kanivets.moneytracker.activity.base.BaseBackActivity;

import butterknife.Bind;

public class AboutActivity extends BaseBackActivity {
@Bind(R.id.tv_about)
TextView tvAbout;

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

@Override
protected void initViews() {
super.initViews();
tvAbout.setMovementMethod(LinkMovementMethod.getInstance());
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.blogspot.e_kanivets.moneytracker.activity;

import android.os.Build;
import android.os.Bundle;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceFragment;

import com.blogspot.e_kanivets.moneytracker.BuildConfig;
import com.blogspot.e_kanivets.moneytracker.MtApp;
import com.blogspot.e_kanivets.moneytracker.R;
import com.blogspot.e_kanivets.moneytracker.activity.base.BaseBackActivity;
Expand Down Expand Up @@ -58,6 +60,13 @@ public void onCreate(Bundle savedInstanceState) {
setupDefaultAccountPref();
setupDefaultCurrencyPref();
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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,16 @@ protected void showToast(@StringRes int messageId) {
Toast.makeText(BaseActivity.this, messageId, Toast.LENGTH_SHORT).show();
}

public void startProgress() {
if (getProgressBar() == null) return;
getProgressBar().show();
public void startProgress(@Nullable String message) {
ProgressDialog progressDialog = getProgressDialog();
if (progressDialog == null) return;
if (message != null) progressDialog.setMessage(message);
progressDialog.show();
}

public void stopProgress() {
if (getProgressBar() == null) return;
getProgressBar().dismiss();
if (getProgressDialog() == null) return;
getProgressDialog().dismiss();
}

public void showAlert(@Nullable String title, @Nullable String message) {
Expand All @@ -90,7 +92,7 @@ public void showAlert(@Nullable String title, @Nullable String message) {
dialog.show();
}

private ProgressDialog getProgressBar() {
private ProgressDialog getProgressDialog() {
if (progressDialog == null) progressDialog = new ProgressDialog(this);
return progressDialog;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ protected void onResume() {

@OnClick(R.id.btn_backup_now)
public void backupNow() {
startProgress();
startProgress(getString(R.string.making_backup));
backupController.makeBackup(dbApi, new BackupController.OnBackupListener() {
@Override
public void onBackupSuccess() {
Expand Down Expand Up @@ -131,7 +131,7 @@ public void onClick(DialogInterface dialog, int which) {
}

private void restoreBackup(final String backupName) {
startProgress();
startProgress(getString(R.string.restoring_backup));
backupController.restoreBackup(dbApi, backupName, new BackupController.OnRestoreBackupListener() {
@Override
public void onRestoreSuccess() {
Expand Down Expand Up @@ -170,7 +170,7 @@ public void onRestoreFailure(String reason) {
}

private void fetchBackups() {
startProgress();
startProgress(getString(R.string.fetching_backups));
backupController.fetchBackups(dbApi, new BackupController.OnFetchBackupListListener() {
@Override
public void onBackupsFetched(@NonNull List<String> backupList) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void importRecords() {
@Override
protected void onPreExecute() {
super.onPreExecute();
startProgress();
startProgress(getString(R.string.importing_records));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ protected void initViews() {
if (getSupportActionBar() != null) {
switch (type) {
case Record.TYPE_EXPENSE:
getSupportActionBar().setTitle(R.string.title_add_expense);
if (mode == Mode.MODE_ADD) getSupportActionBar().setTitle(R.string.title_add_expense);
else getSupportActionBar().setTitle(R.string.title_edit_expense);
getSupportActionBar().setBackgroundDrawable(
new ColorDrawable(getResources().getColor(R.color.red_light)));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Expand All @@ -144,7 +145,8 @@ protected void initViews() {
break;

case Record.TYPE_INCOME:
getSupportActionBar().setTitle(R.string.title_add_income);
if (mode == Mode.MODE_ADD) getSupportActionBar().setTitle(R.string.title_add_income);
else getSupportActionBar().setTitle(R.string.title_edit_income);
getSupportActionBar().setBackgroundDrawable(
new ColorDrawable(getResources().getColor(R.color.green_light)));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
package com.blogspot.e_kanivets.moneytracker.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Filter;
import android.widget.Filterable;
import android.widget.TextView;

import com.blogspot.e_kanivets.moneytracker.R;
import com.blogspot.e_kanivets.moneytracker.util.CategoryAutoCompleter;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
* Custom adapter to autocomplete categories.
* Created on 3/18/16.
Expand All @@ -25,6 +33,31 @@ public CategoryAutoCompleteAdapter(Context context, int resource, CategoryAutoCo
this.autoCompleter = autoCompleter;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder viewHolder;

if (convertView == null) {
convertView = LayoutInflater.from(getContext()).inflate(R.layout.view_category_item, parent, false);
viewHolder = new ViewHolder(convertView);
convertView.setTag(viewHolder);
} else viewHolder = (ViewHolder) convertView.getTag();

final String category = resultList.get(position);

viewHolder.tvCategory.setText(category);
viewHolder.ivCancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
autoCompleter.removeFromAutoComplete(category);
resultList.remove(category);
notifyDataSetChanged();
}
});

return convertView;
}

@Override
public int getCount() {
return resultList.size();
Expand Down Expand Up @@ -63,4 +96,15 @@ protected void publishResults(CharSequence constraint, FilterResults results) {
}
};
}

public static class ViewHolder {
@Bind(R.id.tv_category)
TextView tvCategory;
@Bind(R.id.iv_cancel)
View ivCancel;

public ViewHolder(View view) {
ButterKnife.bind(this, view);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

import com.blogspot.e_kanivets.moneytracker.R;

import java.util.HashSet;
import java.util.Set;

/**
* Controller class to encapsulate Shared Preferences handling logic.
* Not deal with {@link com.blogspot.e_kanivets.moneytracker.repo.base.IRepo} instances as others.
Expand All @@ -22,6 +25,7 @@ public class PreferenceController {
private static final String KEY_LAST_TS = "key_last_ts";
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 int RATE_PERIOD = 5;

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

public void addLaunchCount() {
SharedPreferences preferences = getDefaultPrefs();
SharedPreferences.Editor editor = preferences.edit();
SharedPreferences.Editor editor = getEditor();
editor.putInt(LAUNCH_COUNT, preferences.getInt(LAUNCH_COUNT, 0) + 1);
editor.apply();
}
Expand All @@ -50,16 +54,13 @@ public boolean checkRateDialog() {
}

public void appRated() {
SharedPreferences preferences = getDefaultPrefs();
SharedPreferences.Editor editor = preferences.edit();
SharedPreferences.Editor editor = getEditor();
editor.putBoolean(APP_RATED, true);
editor.apply();
}

public void writeFirstTs(long firstTs) {
SharedPreferences preferences = getDefaultPrefs();
SharedPreferences.Editor editor = preferences.edit();

SharedPreferences.Editor editor = getEditor();
editor.putLong(KEY_FIRST_TS, firstTs);
editor.apply();
}
Expand All @@ -73,21 +74,23 @@ public void writeLastTs(long lastTs) {
}

public void writePeriodType(String periodType) {
SharedPreferences preferences = getDefaultPrefs();
SharedPreferences.Editor editor = preferences.edit();

SharedPreferences.Editor editor = getEditor();
editor.putString(KEY_PERIOD_TYPE, periodType);
editor.apply();
}

public void writeDropboxAccessToken(String accessToken) {
SharedPreferences preferences = getDefaultPrefs();
SharedPreferences.Editor editor = preferences.edit();

SharedPreferences.Editor editor = getEditor();
editor.putString(KEY_DROPBOX_ACCESS_TOKEN, accessToken);
editor.apply();
}

public void writeFilteredCategories(@Nullable Set<String> categorySet) {
SharedPreferences.Editor editor = getEditor();
editor.putStringSet(KEY_FILTERED_CATEGORIES, categorySet);
editor.apply();
}

public long readDefaultAccountId() {
String defaultAccountPref = context.getString(R.string.pref_default_account);
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
Expand Down Expand Up @@ -129,7 +132,19 @@ public String readDropboxAccessToken() {
return getDefaultPrefs().getString(KEY_DROPBOX_ACCESS_TOKEN, null);
}

@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
private SharedPreferences getDefaultPrefs() {
return context.getSharedPreferences(context.getPackageName(), Context.MODE_PRIVATE);
}

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