]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java
profiles: ensure single instance per profile, fix havoc on add/removal of a profile
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / ui / activity / MainActivity.java
index e079399eb641e80f9a8bd149f662974d9fa6a5f2..fbb99989ebd6de9b91c3528d3388ad5a15e51497 100644 (file)
@@ -37,6 +37,7 @@ import android.view.View;
 import android.widget.LinearLayout;
 import android.widget.ProgressBar;
 import android.widget.TextView;
+import android.widget.Toast;
 
 import net.ktnx.mobileledger.R;
 import net.ktnx.mobileledger.async.RefreshDescriptionsTask;
@@ -109,7 +110,7 @@ public class MainActivity extends AppCompatActivity {
         drawer.addDrawerListener(toggle);
         toggle.syncState();
 
-        android.widget.TextView ver = drawer.findViewById(R.id.drawer_version_text);
+        TextView ver = drawer.findViewById(R.id.drawer_version_text);
 
         try {
             PackageInfo pi =
@@ -169,10 +170,9 @@ public class MainActivity extends AppCompatActivity {
         });
     }
     private void setupProfile() {
-        Data.profiles.setList(MobileLedgerProfile.loadAllFromDB());
-        MobileLedgerProfile profile = null;
-
         String profileUUID = MLDB.getOption(MLDB.OPT_PROFILE_UUID, null);
+        MobileLedgerProfile profile;
+
         if (profileUUID == null) {
             if (Data.profiles.isEmpty()) {
                 Data.profiles.setList(MobileLedgerProfile.createInitialProfileList());
@@ -195,9 +195,10 @@ public class MainActivity extends AppCompatActivity {
                 editor.clear();
                 editor.apply();
             }
+            else profile = Data.profiles.get(0);
         }
         else {
-            profile = MobileLedgerProfile.loadUUIDFromDB(profileUUID);
+            profile = MobileLedgerProfile.loadAllFromDB(profileUUID);
         }
 
         if (profile == null) profile = Data.profiles.get(0);
@@ -220,12 +221,6 @@ public class MainActivity extends AppCompatActivity {
         startActivity(intent);
         overridePendingTransition(R.anim.slide_in_right, R.anim.dummy);
     }
-
-    public void navExitClicked(View view) {
-        Log.w("app", "exiting");
-        finish();
-    }
-
     public void navSettingsClicked(View view) {
         Intent intent = new Intent(this, SettingsActivity.class);
         startActivity(intent);
@@ -333,11 +328,15 @@ public class MainActivity extends AppCompatActivity {
         if (retrieveTransactionsTask != null) retrieveTransactionsTask.cancel(false);
         bTransactionListCancelDownload.setEnabled(false);
     }
-    public void onRetrieveDone(boolean success) {
+    public void onRetrieveDone(String error) {
         progressLayout.setVisibility(View.GONE);
-        updateLastUpdateTextFromDB();
 
-        new RefreshDescriptionsTask().execute();
+        if (error == null) {
+            updateLastUpdateTextFromDB();
+
+            new RefreshDescriptionsTask().execute();
+        }
+        else Toast.makeText(this, error, Toast.LENGTH_LONG).show();
     }
     public void onRetrieveStart() {
         progressBar.setIndeterminate(true);