From 7c294281c2d3d0f7cf346e493cc8d5a94980d772 Mon Sep 17 00:00:00 2001 From: M66B Date: Sat, 11 Aug 2018 16:50:30 +0000 Subject: [PATCH] Navigate from setup to messages when account set --- .../java/eu/faircode/email/ActivitySetup.java | 2 + .../java/eu/faircode/email/ActivityView.java | 15 +++++--- .../eu/faircode/email/FragmentCompose.java | 4 +- .../eu/faircode/email/FragmentMessage.java | 36 +++++++++--------- .../java/eu/faircode/email/FragmentSetup.java | 38 +++++++++---------- app/src/main/res/layout/fragment_setup.xml | 15 +------- app/src/main/res/values/strings.xml | 1 - 7 files changed, 49 insertions(+), 62 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/ActivitySetup.java b/app/src/main/java/eu/faircode/email/ActivitySetup.java index 6e046470..2e0cfa85 100644 --- a/app/src/main/java/eu/faircode/email/ActivitySetup.java +++ b/app/src/main/java/eu/faircode/email/ActivitySetup.java @@ -31,6 +31,8 @@ import androidx.fragment.app.FragmentTransaction; import androidx.localbroadcastmanager.content.LocalBroadcastManager; public class ActivitySetup extends ActivityBase implements FragmentManager.OnBackStackChangedListener { + static final int LOADER_CREATE_OUTBOX = 1; + static final String ACTION_EDIT_ACCOUNT = BuildConfig.APPLICATION_ID + ".EDIT_ACCOUNT"; static final String ACTION_EDIT_IDENTITY = BuildConfig.APPLICATION_ID + ".EDIT_IDENTITY"; diff --git a/app/src/main/java/eu/faircode/email/ActivityView.java b/app/src/main/java/eu/faircode/email/ActivityView.java index d4838f7a..da86f2f3 100644 --- a/app/src/main/java/eu/faircode/email/ActivityView.java +++ b/app/src/main/java/eu/faircode/email/ActivityView.java @@ -260,7 +260,10 @@ public class ActivityView extends ActivityBase implements FragmentManager.OnBack @Override protected void onNewIntent(Intent intent) { - getSupportFragmentManager().popBackStack("unified", 0); + if (intent.getBooleanExtra("setup", false)) + intent.getExtras().remove("setup"); + else + getSupportFragmentManager().popBackStack("unified", 0); checkIntent(intent); super.onNewIntent(intent); } @@ -336,9 +339,9 @@ public class ActivityView extends ActivityBase implements FragmentManager.OnBack Bundle args = new Bundle(); args.putLong("time", new Date().getTime()); - new SimpleLoader() { + new SimpleLoader() { @Override - public Object onLoad(Bundle args) { + public Void onLoad(Bundle args) { long time = args.getLong("time"); DaoAccount dao = DB.getInstance(getContext()).account(); for (EntityAccount account : dao.getAccounts(true)) { @@ -458,9 +461,9 @@ public class ActivityView extends ActivityBase implements FragmentManager.OnBack } else if (ACTION_VIEW_MESSAGE.equals(intent.getAction())) { - new SimpleLoader() { + new SimpleLoader() { @Override - public Object onLoad(Bundle args) { + public Void onLoad(Bundle args) { long id = args.getLong("id"); DB db = DB.getInstance(ActivityView.this); EntityMessage message = db.message().getMessage(id); @@ -490,7 +493,7 @@ public class ActivityView extends ActivityBase implements FragmentManager.OnBack } @Override - public void onLoaded(Bundle args, Object result) { + public void onLoaded(Bundle args, Void result) { FragmentMessage fragment = new FragmentMessage(); fragment.setArguments(args); FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction(); diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index 72ef7b4b..fa771d0b 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -413,9 +413,9 @@ public class FragmentCompose extends FragmentEx { args.putLong("id", id); args.putParcelable("uri", data.getData()); - new SimpleLoader() { + new SimpleLoader() { @Override - public Object onLoad(Bundle args) throws IOException { + public Void onLoad(Bundle args) throws IOException { Cursor cursor = null; try { Uri uri = args.getParcelable("uri"); diff --git a/app/src/main/java/eu/faircode/email/FragmentMessage.java b/app/src/main/java/eu/faircode/email/FragmentMessage.java index 85d2db04..5065517e 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessage.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessage.java @@ -402,9 +402,9 @@ public class FragmentMessage extends FragmentEx { Bundle args = new Bundle(); args.putLong("id", id); - new SimpleLoader() { + new SimpleLoader() { @Override - public Object onLoad(Bundle args) { + public Void onLoad(Bundle args) { long id = args.getLong("id"); DB db = DB.getInstance(getContext()); try { @@ -428,7 +428,7 @@ public class FragmentMessage extends FragmentEx { } @Override - public void onLoaded(Bundle args, Object data) { + public void onLoaded(Bundle args, Void data) { item.setEnabled(true); item.setIcon(icon); } @@ -513,9 +513,9 @@ public class FragmentMessage extends FragmentEx { Bundle args = new Bundle(); args.putLong("id", id); - new SimpleLoader() { + new SimpleLoader() { @Override - public Object onLoad(Bundle args) { + public Void onLoad(Bundle args) { long id = args.getLong("id"); DB db = DB.getInstance(getContext()); try { @@ -539,7 +539,7 @@ public class FragmentMessage extends FragmentEx { } @Override - public void onLoaded(Bundle args, Object result) { + public void onLoaded(Bundle args, Void result) { item.setEnabled(true); item.setIcon(icon); } @@ -575,9 +575,9 @@ public class FragmentMessage extends FragmentEx { Bundle args = new Bundle(); args.putLong("id", id); - new SimpleLoader() { + new SimpleLoader() { @Override - public Object onLoad(Bundle args) { + public Void onLoad(Bundle args) { long id = args.getLong("id"); DB db = DB.getInstance(getContext()); try { @@ -599,7 +599,7 @@ public class FragmentMessage extends FragmentEx { } @Override - public void onLoaded(Bundle args, Object result) { + public void onLoaded(Bundle args, Void result) { item.setEnabled(true); item.setIcon(icon); } @@ -624,9 +624,9 @@ public class FragmentMessage extends FragmentEx { Bundle args = new Bundle(); args.putLong("id", id); - new SimpleLoader() { + new SimpleLoader() { @Override - public Object onLoad(Bundle args) { + public Void onLoad(Bundle args) { long id = args.getLong("id"); DB db = DB.getInstance(getContext()); try { @@ -650,7 +650,7 @@ public class FragmentMessage extends FragmentEx { } @Override - public void onLoaded(Bundle args, Object result) { + public void onLoaded(Bundle args, Void result) { item.setEnabled(true); item.setIcon(icon); } @@ -682,9 +682,9 @@ public class FragmentMessage extends FragmentEx { Bundle args = new Bundle(); args.putLong("id", id); - new SimpleLoader() { + new SimpleLoader() { @Override - public Object onLoad(Bundle args) { + public Void onLoad(Bundle args) { long id = args.getLong("id"); DB db = DB.getInstance(getContext()); try { @@ -708,7 +708,7 @@ public class FragmentMessage extends FragmentEx { } @Override - public void onLoaded(Bundle args, Object result) { + public void onLoaded(Bundle args, Void result) { item.setEnabled(true); item.setIcon(icon); } @@ -801,9 +801,9 @@ public class FragmentMessage extends FragmentEx { Bundle args = ((MoveLoader) loader).args; args.putLong("target", target.getItemId()); - new SimpleLoader() { + new SimpleLoader() { @Override - public Object onLoad(Bundle args) { + public Void onLoad(Bundle args) { long id = args.getLong("id"); long target = args.getLong("target"); DB db = DB.getInstance(getContext()); @@ -827,7 +827,7 @@ public class FragmentMessage extends FragmentEx { } @Override - public void onLoaded(Bundle args, Object result) { + public void onLoaded(Bundle args, Void result) { item.setEnabled(true); item.setIcon(icon); } diff --git a/app/src/main/java/eu/faircode/email/FragmentSetup.java b/app/src/main/java/eu/faircode/email/FragmentSetup.java index 7ef95a02..92ee3659 100644 --- a/app/src/main/java/eu/faircode/email/FragmentSetup.java +++ b/app/src/main/java/eu/faircode/email/FragmentSetup.java @@ -33,10 +33,9 @@ import android.widget.CheckBox; import android.widget.CompoundButton; import android.widget.ProgressBar; import android.widget.TextView; +import android.widget.Toast; import java.util.List; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -56,13 +55,9 @@ public class FragmentSetup extends FragmentEx { private Button btnPermissions; private TextView tvPermissionsDone; - private Button btnMessages; - private CheckBox cbDarkTheme; private CheckBox cbDebug; - private ExecutorService executor = Executors.newCachedThreadPool(); - private static final String[] permissions = new String[]{ Manifest.permission.READ_CONTACTS }; @@ -86,8 +81,6 @@ public class FragmentSetup extends FragmentEx { btnPermissions = view.findViewById(R.id.btnPermissions); tvPermissionsDone = view.findViewById(R.id.tvPermissionsDone); - btnMessages = view.findViewById(R.id.btnMessages); - cbDarkTheme = view.findViewById(R.id.cbDarkTheme); cbDebug = view.findViewById(R.id.cbDebug); @@ -119,14 +112,6 @@ public class FragmentSetup extends FragmentEx { } }); - btnMessages.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - startActivity(new Intent(getContext(), ActivityView.class)); - getFragmentManager().popBackStack(); - } - }); - final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); String theme = prefs.getString("theme", "light"); @@ -159,7 +144,6 @@ public class FragmentSetup extends FragmentEx { tvAccountDone.setVisibility(View.INVISIBLE); tvIdentityDone.setVisibility(View.INVISIBLE); tvPermissionsDone.setVisibility(View.INVISIBLE); - btnMessages.setEnabled(false); int[] grantResults = new int[permissions.length]; for (int i = 0; i < permissions.length; i++) @@ -168,9 +152,9 @@ public class FragmentSetup extends FragmentEx { onRequestPermissionsResult(0, permissions, grantResults); // Create outbox - executor.submit(new Runnable() { + new SimpleLoader() { @Override - public void run() { + public Void onLoad(Bundle args) throws Throwable { DB db = DB.getInstance(getContext()); EntityFolder outbox = db.folder().getOutbox(); if (outbox == null) { @@ -181,8 +165,14 @@ public class FragmentSetup extends FragmentEx { outbox.after = 0; outbox.id = db.folder().insertFolder(outbox); } + return null; } - }); + + @Override + public void onException(Bundle args, Throwable ex) { + Toast.makeText(getContext(), ex.toString(), Toast.LENGTH_LONG).show(); + } + }.load(this, ActivitySetup.LOADER_CREATE_OUTBOX, new Bundle()); return view; } @@ -197,7 +187,6 @@ public class FragmentSetup extends FragmentEx { @Override public void onChanged(@Nullable List accounts) { tvAccountDone.setVisibility(accounts.size() > 0 ? View.VISIBLE : View.INVISIBLE); - btnMessages.setEnabled(accounts.size() > 0); } }); @@ -209,6 +198,13 @@ public class FragmentSetup extends FragmentEx { }); } + @Override + public void onDestroy() { + if (tvAccountDone.getVisibility() == View.VISIBLE) + startActivity(new Intent(getContext(), ActivityView.class).putExtra("setup", true)); + super.onDestroy(); + } + @Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { boolean has = (grantResults.length > 0); diff --git a/app/src/main/res/layout/fragment_setup.xml b/app/src/main/res/layout/fragment_setup.xml index 4227e9b6..0da69b19 100644 --- a/app/src/main/res/layout/fragment_setup.xml +++ b/app/src/main/res/layout/fragment_setup.xml @@ -132,19 +132,6 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/tvPermissions" /> - - -