Shortcut has accounts

This commit is contained in:
M66B 2019-06-09 11:22:50 +02:00
parent 16b1552bc2
commit 794f1840a7
2 changed files with 24 additions and 8 deletions

View File

@ -50,21 +50,32 @@ public class ActivityMain extends AppCompatActivity implements FragmentManager.O
if (prefs.getBoolean("eula", false)) {
super.onCreate(savedInstanceState);
new SimpleTask<List<EntityAccount>>() {
new SimpleTask<Boolean>() {
@Override
protected List<EntityAccount> onExecute(Context context, Bundle args) {
return DB.getInstance(context).account().getSynchronizingAccounts();
protected Boolean onExecute(Context context, Bundle args) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
if (prefs.getBoolean("has_accounts", false))
return true;
DB db = DB.getInstance(context);
List<EntityAccount> accounts = db.account().getSynchronizingAccounts();
boolean hasAccounts = (accounts != null && accounts.size() > 0);
prefs.edit().putBoolean("has_accounts", hasAccounts).apply();
return hasAccounts;
}
@Override
protected void onExecuted(Bundle args, List<EntityAccount> accounts) {
if (accounts == null || accounts.size() == 0)
startActivity(new Intent(ActivityMain.this, ActivitySetup.class));
else {
protected void onExecuted(Bundle args, Boolean hasAccounts) {
if (hasAccounts) {
startActivity(new Intent(ActivityMain.this, ActivityView.class));
ServiceSynchronize.boot(ActivityMain.this);
ServiceSend.boot(ActivityMain.this);
}
} else
startActivity(new Intent(ActivityMain.this, ActivitySetup.class));
finish();
}

View File

@ -25,6 +25,7 @@ import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.graphics.drawable.Drawable;
import android.net.ConnectivityManager;
@ -47,6 +48,7 @@ import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.FragmentTransaction;
import androidx.lifecycle.Observer;
import androidx.preference.PreferenceManager;
import java.util.List;
@ -270,6 +272,7 @@ public class FragmentSetup extends FragmentBase {
super.onActivityCreated(savedInstanceState);
final DB db = DB.getInstance(getContext());
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
db.account().liveSynchronizingAccounts().observe(getViewLifecycleOwner(), new Observer<List<EntityAccount>>() {
private boolean done = false;
@ -286,6 +289,8 @@ public class FragmentSetup extends FragmentBase {
btnIdentity.setEnabled(done);
btnInbox.setEnabled(done);
prefs.edit().putBoolean("has_accounts", done).apply();
}
});