Check for primary account / drafts / archive

This commit is contained in:
M66B
2018-12-13 10:43:30 +01:00
parent 8dd3d1ef85
commit a96e9d07fb
4 changed files with 87 additions and 17 deletions

View File

@@ -83,6 +83,16 @@ public interface DaoFolder {
" GROUP BY folder.id")
LiveData<List<TupleFolderEx>> liveUnified();
@Query("SELECT folder.* FROM folder" +
" JOIN account ON account.id = folder.account" +
" WHERE `primary` AND type = '" + EntityFolder.DRAFTS + "'")
LiveData<EntityFolder> livePrimaryDrafts();
@Query("SELECT folder.* FROM folder" +
" JOIN account ON account.id = folder.account" +
" WHERE `primary` AND type = '" + EntityFolder.ARCHIVE + "'")
LiveData<EntityFolder> livePrimaryArchive();
@Query("SELECT folder.* FROM folder" +
" JOIN account ON account.id = folder.account" +
" WHERE folder.type = '" + EntityFolder.DRAFTS + "'" +
@@ -117,7 +127,6 @@ public interface DaoFolder {
" WHERE account = :account AND type = :type")
EntityFolder getFolderByType(long account, String type);
// For debug/crash info
@Query("SELECT folder.* FROM folder" +
" JOIN account ON account.id = folder.account" +
" WHERE `primary` AND type = '" + EntityFolder.DRAFTS + "'")

View File

@@ -962,7 +962,8 @@ public class FragmentAccount extends FragmentEx {
@Override
protected void onLoaded(Bundle args, EntityAccount primary) {
cbPrimary.setChecked(primary == null);
if (primary == null)
cbPrimary.setChecked(true);
}
@Override

View File

@@ -81,6 +81,7 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.FragmentTransaction;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.Observer;
import static android.app.Activity.RESULT_OK;
@@ -92,6 +93,8 @@ public class FragmentSetup extends FragmentEx {
private Button btnAccount;
private TextView tvAccountDone;
private TextView tvNoPrimaryDrafts;
private TextView tvNoPrimaryArchive;
private Button btnIdentity;
private TextView tvIdentityDone;
@@ -135,6 +138,8 @@ public class FragmentSetup extends FragmentEx {
btnAccount = view.findViewById(R.id.btnAccount);
tvAccountDone = view.findViewById(R.id.tvAccountDone);
tvNoPrimaryDrafts = view.findViewById(R.id.tvNoPrimaryDrafts);
tvNoPrimaryArchive = view.findViewById(R.id.tvNoPrimaryArchive);
btnIdentity = view.findViewById(R.id.btnIdentity);
tvIdentityDone = view.findViewById(R.id.tvIdentityDone);
@@ -281,6 +286,8 @@ public class FragmentSetup extends FragmentEx {
tvAccountDone.setText(null);
tvAccountDone.setCompoundDrawables(null, null, null, null);
tvNoPrimaryDrafts.setVisibility(View.GONE);
tvNoPrimaryArchive.setVisibility(View.GONE);
btnIdentity.setEnabled(false);
tvIdentityDone.setText(null);
@@ -345,15 +352,44 @@ public class FragmentSetup extends FragmentEx {
PackageManager pm = getContext().getPackageManager();
ibHelp.setVisibility(getIntentHelp().resolveActivity(pm) == null ? View.GONE : View.VISIBLE);
DB db = DB.getInstance(getContext());
final DB db = DB.getInstance(getContext());
db.account().liveAccounts(true).observe(getViewLifecycleOwner(), new Observer<List<EntityAccount>>() {
private boolean done = false;
private LiveData<EntityFolder> livePrimaryDrafts = null;
private LiveData<EntityFolder> livePrimaryArchive = null;
@Override
public void onChanged(@Nullable List<EntityAccount> accounts) {
boolean done = (accounts != null && accounts.size() > 0);
done = (accounts != null && accounts.size() > 0);
btnIdentity.setEnabled(done);
tvAccountDone.setText(done ? R.string.title_setup_done : R.string.title_setup_to_do);
tvAccountDone.setCompoundDrawablesWithIntrinsicBounds(done ? check : null, null, null, null);
if (livePrimaryDrafts == null)
livePrimaryDrafts = db.folder().livePrimaryDrafts();
else
livePrimaryDrafts.removeObservers(getViewLifecycleOwner());
if (livePrimaryArchive == null)
livePrimaryArchive = db.folder().livePrimaryDrafts();
else
livePrimaryArchive.removeObservers(getViewLifecycleOwner());
livePrimaryDrafts.observe(getViewLifecycleOwner(), new Observer<EntityFolder>() {
@Override
public void onChanged(EntityFolder drafts) {
tvNoPrimaryDrafts.setVisibility(done && drafts == null ? View.VISIBLE : View.GONE);
}
});
livePrimaryArchive.observe(getViewLifecycleOwner(), new Observer<EntityFolder>() {
@Override
public void onChanged(EntityFolder archive) {
tvNoPrimaryArchive.setVisibility(done && archive == null ? View.VISIBLE : View.GONE);
}
});
}
});