]> git.ktnx.net Git - mobile-ledger.git/commitdiff
Account summary: menu item for manually refreshing the data
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Thu, 6 Dec 2018 21:28:45 +0000 (21:28 +0000)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Thu, 6 Dec 2018 21:28:45 +0000 (21:28 +0000)
app/src/main/java/net/ktnx/mobileledger/AccountSummary.java
app/src/main/res/drawable/ic_refresh_white_24dp.xml [new file with mode: 0644]
app/src/main/res/menu/account_summary.xml [new file with mode: 0644]
app/src/main/res/values/strings.xml

index e8cf0398b559c77cc07c36011e4bd5cf561777e1..bd73cd075aafbef4ee46b273645ffffdb30daa8d 100644 (file)
@@ -33,6 +33,7 @@ public class AccountSummary extends AppCompatActivity {
     public static void preferences_changed() {
         account_list_needs_update = true;
     }
+    MenuItem mRefresh;
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
@@ -88,7 +89,9 @@ public class AccountSummary extends AppCompatActivity {
     @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);
+        getMenuInflater().inflate(R.menu.account_summary, menu);
+        mRefresh = (MenuItem) menu.findItem(R.id.menu_acc_summary_refresh);
+        assert mRefresh != null;
         return true;
     }
 
@@ -107,6 +110,10 @@ public class AccountSummary extends AppCompatActivity {
         return super.onOptionsItemSelected(item);
     }
 
+    public void onRefreshAccountSummaryClicked(MenuItem mi) {
+        update_accounts(true);
+    }
+
     private void prepare_db() {
         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
             MobileLedgerDB.setDb_filename(this.getApplicationInfo().deviceProtectedDataDir + "/" + MobileLedgerDB.DATABASE_NAME);
@@ -129,6 +136,7 @@ public class AccountSummary extends AppCompatActivity {
     }
 
     private void update_accounts() {
+        mRefresh.setVisible(false);
         Resources rm = getResources();
 
         ProgressBar pb = findViewById(R.id.progressBar);
@@ -150,6 +158,7 @@ public class AccountSummary extends AppCompatActivity {
             protected void onPostExecute(Void result) {
                 pb.setVisibility(GONE);
                 pt.setVisibility(GONE);
+                mRefresh.setVisible(true);
                 if (this.error != 0)
                     Snackbar.make(drawer, rm.getString(this.error), Snackbar.LENGTH_LONG );
                 else
diff --git a/app/src/main/res/drawable/ic_refresh_white_24dp.xml b/app/src/main/res/drawable/ic_refresh_white_24dp.xml
new file mode 100644 (file)
index 0000000..0d6368f
--- /dev/null
@@ -0,0 +1,5 @@
+<vector android:height="24dp" android:tint="#EEEEEE"
+    android:viewportHeight="24.0" android:viewportWidth="24.0"
+    android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
+    <path android:fillColor="#FF000000" android:pathData="M17.65,6.35C16.2,4.9 14.21,4 12,4c-4.42,0 -7.99,3.58 -7.99,8s3.57,8 7.99,8c3.73,0 6.84,-2.55 7.73,-6h-2.08c-0.82,2.33 -3.04,4 -5.65,4 -3.31,0 -6,-2.69 -6,-6s2.69,-6 6,-6c1.66,0 3.14,0.69 4.22,1.78L13,11h7V4l-2.35,2.35z"/>
+</vector>
diff --git a/app/src/main/res/menu/account_summary.xml b/app/src/main/res/menu/account_summary.xml
new file mode 100644 (file)
index 0000000..f416b53
--- /dev/null
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="utf-8"?>
+<menu xmlns:app="http://schemas.android.com/apk/res-auto"
+    xmlns:android="http://schemas.android.com/apk/res/android">
+
+    <item
+        android:id="@+id/menu_acc_summary_refresh"
+        android:icon="@drawable/ic_refresh_white_24dp"
+        android:title="@string/menu_acc_summary_refresh_title"
+        android:onClick="onRefreshAccountSummaryClicked"
+        app:showAsAction="ifRoom" />
+</menu>
\ No newline at end of file
index 75e444d46195ee369c71c7fbc2beb764bc73e8da..813ccf059681b928d6ffa3e7bdd6e834c295f974 100644 (file)
@@ -69,4 +69,5 @@
     <string name="new_transaction_description_hint">Description</string>
     <string name="action_submit_transaction_title">Save</string>
     <string name="account_summary_title">Account Summary</string>
+    <string name="menu_acc_summary_refresh_title">Refresh</string>
 </resources>