From: Damyan Ivanov Date: Thu, 6 Dec 2018 21:05:36 +0000 (+0000) Subject: home is account summary, latest transactions is a new item X-Git-Tag: v0.3~316 X-Git-Url: https://git.ktnx.net/?a=commitdiff_plain;h=60a85a18cc2074b87721173798497260dbc800e5;p=mobile-ledger.git home is account summary, latest transactions is a new item the account summary has some boilerplate views for now --- diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index b981e478..926fc763 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -13,8 +13,8 @@ android:theme="@style/AppTheme" android:fullBackupContent="@xml/backup_descriptor"> @@ -25,19 +25,19 @@ + android:parentActivityName=".AccountSummary"> + android:value="net.ktnx.mobileledger.AccountSummary" /> + android:value="net.ktnx.mobileledger.AccountSummary" /> diff --git a/app/src/main/java/net/ktnx/mobileledger/AccountSummary.java b/app/src/main/java/net/ktnx/mobileledger/AccountSummary.java new file mode 100644 index 00000000..e8cf0398 --- /dev/null +++ b/app/src/main/java/net/ktnx/mobileledger/AccountSummary.java @@ -0,0 +1,164 @@ +package net.ktnx.mobileledger; + +import android.content.Intent; +import android.content.pm.PackageInfo; +import android.content.res.Resources; +import android.os.Build; +import android.os.Bundle; +import android.preference.PreferenceManager; +import android.support.design.widget.Snackbar; +import android.support.v4.view.GravityCompat; +import android.support.v4.widget.DrawerLayout; +import android.support.v7.app.ActionBarDrawerToggle; +import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.Toolbar; +import android.util.Log; +import android.view.Menu; +import android.view.MenuItem; +import android.view.View; +import android.widget.ProgressBar; +import android.widget.TextView; + +import java.util.Date; + +import static android.view.View.GONE; +import static net.ktnx.mobileledger.MobileLedgerDB.db; +import static net.ktnx.mobileledger.MobileLedgerDB.set_option_value; + +public class AccountSummary extends AppCompatActivity { + DrawerLayout drawer; + + private static long account_list_last_updated; + private static boolean account_list_needs_update = true; + public static void preferences_changed() { + account_list_needs_update = true; + } + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_latest_transactions); + Toolbar toolbar = findViewById(R.id.toolbar); + setSupportActionBar(toolbar); + + drawer = findViewById(R.id.drawer_layout); + ActionBarDrawerToggle toggle = new ActionBarDrawerToggle( + this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); + drawer.addDrawerListener(toggle); + toggle.syncState(); + + android.widget.TextView ver = drawer.findViewById(R.id.drawer_version_text); + + try { + PackageInfo pi = getApplicationContext().getPackageManager().getPackageInfo(getPackageName(), 0); + ver.setText(pi.versionName); + } catch (Exception e) { + e.printStackTrace(); + } + + prepare_db(); + update_accounts(false); + } + + public void fab_new_transaction_clicked(View view) { + Intent intent = new Intent(this, NewTransactionActivity.class); + startActivity(intent); + } + + public void nav_exit_clicked(View view) { + Log.w("mobileledger", "exiting"); + finish(); + } + + public void nav_settings_clicked(View view) { + Intent intent = new Intent(this, SettingsActivity.class); + startActivity(intent); + } + + @Override + public void onBackPressed() { + DrawerLayout drawer = findViewById(R.id.drawer_layout); + if (drawer.isDrawerOpen(GravityCompat.START)) { + drawer.closeDrawer(GravityCompat.START); + } else { + super.onBackPressed(); + } + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + // Inflate the menu; this adds items to the action bar if it is present. + //getMenuInflater().inflate(R.menu.latest_transactions, menu); + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + // Handle action bar item clicks here. The action bar will + // automatically handle clicks on the Home/Up button, so long + // as you specify a parent activity in AndroidManifest.xml. + int id = item.getItemId(); + + //noinspection SimplifiableIfStatement + //if (id == R.id.action_settings) { + // return true; + // } + + return super.onOptionsItemSelected(item); + } + + private void prepare_db() { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + MobileLedgerDB.setDb_filename(this.getApplicationInfo().deviceProtectedDataDir + "/" + MobileLedgerDB.DATABASE_NAME); + } + else { + MobileLedgerDB.setDb_filename(MobileLedgerDB.DATABASE_NAME); + } + MobileLedgerDB.initDB(); + + account_list_last_updated = MobileLedgerDB.get_option_value("last_refresh", (long) 0); + + } + + private void update_accounts(boolean force) { + long now = new Date().getTime(); + if ((now > (account_list_last_updated + (24 * 3600*1000))) || force) { + Log.d("db", "accounts last updated at " + account_list_last_updated+" and now is " + now+". re-fetching"); + update_accounts(); + } + } + + private void update_accounts() { + Resources rm = getResources(); + + ProgressBar pb = findViewById(R.id.progressBar); + pb.setVisibility(View.VISIBLE); + TextView pt = findViewById(R.id.textProgress); + pt.setVisibility(View.VISIBLE); + pb.setIndeterminate(true); + + RetrieveAccountsTask task = new RetrieveAccountsTask() { + @Override + protected void onProgressUpdate(Integer... values) { + if ( values[0] == 0 ) + pt.setText(R.string.progress_connecting); + else + pt.setText(String.format(getResources().getString(R.string.progress_N_accounts_loaded), values[0])); + } + + @Override + protected void onPostExecute(Void result) { + pb.setVisibility(GONE); + pt.setVisibility(GONE); + if (this.error != 0) + Snackbar.make(drawer, rm.getString(this.error), Snackbar.LENGTH_LONG ); + else + set_option_value("last_refresh", new Date().getTime() ); + } + }; + + task.setPref(PreferenceManager.getDefaultSharedPreferences(this)); + task.execute(db); + + } +} diff --git a/app/src/main/java/net/ktnx/mobileledger/LatestTransactions.java b/app/src/main/java/net/ktnx/mobileledger/LatestTransactions.java deleted file mode 100644 index 27ea5cd2..00000000 --- a/app/src/main/java/net/ktnx/mobileledger/LatestTransactions.java +++ /dev/null @@ -1,164 +0,0 @@ -package net.ktnx.mobileledger; - -import android.content.Intent; -import android.content.pm.PackageInfo; -import android.content.res.Resources; -import android.os.Build; -import android.os.Bundle; -import android.preference.PreferenceManager; -import android.support.design.widget.Snackbar; -import android.support.v4.view.GravityCompat; -import android.support.v4.widget.DrawerLayout; -import android.support.v7.app.ActionBarDrawerToggle; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.Toolbar; -import android.util.Log; -import android.view.Menu; -import android.view.MenuItem; -import android.view.View; -import android.widget.ProgressBar; -import android.widget.TextView; - -import java.util.Date; - -import static android.view.View.GONE; -import static net.ktnx.mobileledger.MobileLedgerDB.db; -import static net.ktnx.mobileledger.MobileLedgerDB.set_option_value; - -public class LatestTransactions extends AppCompatActivity { - DrawerLayout drawer; - - private static long account_list_last_updated; - private static boolean account_list_needs_update = true; - public static void preferences_changed() { - account_list_needs_update = true; - } - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_latest_transactions); - Toolbar toolbar = findViewById(R.id.toolbar); - setSupportActionBar(toolbar); - - drawer = findViewById(R.id.drawer_layout); - ActionBarDrawerToggle toggle = new ActionBarDrawerToggle( - this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); - drawer.addDrawerListener(toggle); - toggle.syncState(); - - android.widget.TextView ver = drawer.findViewById(R.id.drawer_version_text); - - try { - PackageInfo pi = getApplicationContext().getPackageManager().getPackageInfo(getPackageName(), 0); - ver.setText(pi.versionName); - } catch (Exception e) { - e.printStackTrace(); - } - - prepare_db(); - update_accounts(false); - } - - public void fab_new_transaction_clicked(View view) { - Intent intent = new Intent(this, NewTransactionActivity.class); - startActivity(intent); - } - - public void nav_exit_clicked(View view) { - Log.w("mobileledger", "exiting"); - finish(); - } - - public void nav_settings_clicked(View view) { - Intent intent = new Intent(this, SettingsActivity.class); - startActivity(intent); - } - - @Override - public void onBackPressed() { - DrawerLayout drawer = findViewById(R.id.drawer_layout); - if (drawer.isDrawerOpen(GravityCompat.START)) { - drawer.closeDrawer(GravityCompat.START); - } else { - super.onBackPressed(); - } - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - // Inflate the menu; this adds items to the action bar if it is present. - //getMenuInflater().inflate(R.menu.latest_transactions, menu); - return true; - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - // Handle action bar item clicks here. The action bar will - // automatically handle clicks on the Home/Up button, so long - // as you specify a parent activity in AndroidManifest.xml. - int id = item.getItemId(); - - //noinspection SimplifiableIfStatement - //if (id == R.id.action_settings) { - // return true; - // } - - return super.onOptionsItemSelected(item); - } - - private void prepare_db() { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - MobileLedgerDB.setDb_filename(this.getApplicationInfo().deviceProtectedDataDir + "/" + MobileLedgerDB.DATABASE_NAME); - } - else { - MobileLedgerDB.setDb_filename(MobileLedgerDB.DATABASE_NAME); - } - MobileLedgerDB.initDB(); - - account_list_last_updated = MobileLedgerDB.get_option_value("last_refresh", (long) 0); - - } - - private void update_accounts(boolean force) { - long now = new Date().getTime(); - if ((now > (account_list_last_updated + (24 * 3600*1000))) || force) { - Log.d("db", "accounts last updated at " + account_list_last_updated+" and now is " + now+". re-fetching"); - update_accounts(); - } - } - - private void update_accounts() { - Resources rm = getResources(); - - ProgressBar pb = findViewById(R.id.progressBar); - pb.setVisibility(View.VISIBLE); - TextView pt = findViewById(R.id.textProgress); - pt.setVisibility(View.VISIBLE); - pb.setIndeterminate(true); - - RetrieveAccountsTask task = new RetrieveAccountsTask() { - @Override - protected void onProgressUpdate(Integer... values) { - if ( values[0] == 0 ) - pt.setText(R.string.progress_connecting); - else - pt.setText(String.format(getResources().getString(R.string.progress_N_accounts_loaded), values[0])); - } - - @Override - protected void onPostExecute(Void result) { - pb.setVisibility(GONE); - pt.setVisibility(GONE); - if (this.error != 0) - Snackbar.make(drawer, rm.getString(this.error), Snackbar.LENGTH_LONG ); - else - set_option_value("last_refresh", new Date().getTime() ); - } - }; - - task.setPref(PreferenceManager.getDefaultSharedPreferences(this)); - task.execute(db); - - } -} diff --git a/app/src/main/java/net/ktnx/mobileledger/NewTransactionActivity.java b/app/src/main/java/net/ktnx/mobileledger/NewTransactionActivity.java index dca8d463..a9d6097a 100644 --- a/app/src/main/java/net/ktnx/mobileledger/NewTransactionActivity.java +++ b/app/src/main/java/net/ktnx/mobileledger/NewTransactionActivity.java @@ -60,7 +60,7 @@ public class NewTransactionActivity extends AppCompatActivity implements TaskCal @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.activity_new_transaction); + setContentView(R.layout.activity_account_summary); Toolbar toolbar = findViewById(R.id.toolbar); setSupportActionBar(toolbar); diff --git a/app/src/main/java/net/ktnx/mobileledger/SettingsActivity.java b/app/src/main/java/net/ktnx/mobileledger/SettingsActivity.java index 9e49c46f..7d84fe0c 100644 --- a/app/src/main/java/net/ktnx/mobileledger/SettingsActivity.java +++ b/app/src/main/java/net/ktnx/mobileledger/SettingsActivity.java @@ -42,7 +42,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity { private static Preference.OnPreferenceChangeListener sBindPreferenceSummaryToValueListener = (preference, value) -> { String stringValue = value.toString(); - LatestTransactions.preferences_changed(); + AccountSummary.preferences_changed(); if (preference instanceof ListPreference) { // For list preferences, look up the correct display value in diff --git a/app/src/main/res/drawable/ic_event_note_black_24dp.xml b/app/src/main/res/drawable/ic_event_note_black_24dp.xml new file mode 100644 index 00000000..94381597 --- /dev/null +++ b/app/src/main/res/drawable/ic_event_note_black_24dp.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/layout/activity_account_summary.xml b/app/src/main/res/layout/activity_account_summary.xml new file mode 100644 index 00000000..d5f20877 --- /dev/null +++ b/app/src/main/res/layout/activity_account_summary.xml @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_new_transaction.xml b/app/src/main/res/layout/activity_new_transaction.xml deleted file mode 100644 index d5f20877..00000000 --- a/app/src/main/res/layout/activity_new_transaction.xml +++ /dev/null @@ -1,42 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/app_bar_latest_transactions.xml b/app/src/main/res/layout/app_bar_latest_transactions.xml index 45daa4e2..05591be8 100644 --- a/app/src/main/res/layout/app_bar_latest_transactions.xml +++ b/app/src/main/res/layout/app_bar_latest_transactions.xml @@ -4,7 +4,7 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" - tools:context=".LatestTransactions"> + tools:context=".AccountSummary"> - + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/content_latest_transactions.xml b/app/src/main/res/layout/content_latest_transactions.xml deleted file mode 100644 index 1eb4c385..00000000 --- a/app/src/main/res/layout/content_latest_transactions.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/content_new_transaction.xml b/app/src/main/res/layout/content_new_transaction.xml index b4b6babe..0d284493 100644 --- a/app/src/main/res/layout/content_new_transaction.xml +++ b/app/src/main/res/layout/content_new_transaction.xml @@ -6,7 +6,7 @@ android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior" tools:context=".NewTransactionActivity" - tools:showIn="@layout/activity_new_transaction"> + tools:showIn="@layout/activity_account_summary"> + + + diff --git a/app/src/main/res/values-bg/strings.xml b/app/src/main/res/values-bg/strings.xml index b6d39b1d..ab25a3fa 100644 --- a/app/src/main/res/values-bg/strings.xml +++ b/app/src/main/res/values-bg/strings.xml @@ -24,4 +24,5 @@ Описание Заредени са %d сметки Запазване + Сметките накратко \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 24bd8ecd..75e444d4 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -68,4 +68,5 @@ %d accounts loaded Description Save + Account Summary