mirror of
https://github.com/M66B/FairEmail.git
synced 2025-03-15 08:29:24 +00:00
Check for primary account / drafts / archive
This commit is contained in:
parent
8dd3d1ef85
commit
a96e9d07fb
4 changed files with 87 additions and 17 deletions
|
@ -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 + "'")
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -54,14 +54,38 @@
|
|||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvAccount" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvNoPrimaryDrafts"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/title_no_primary_drafts"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||
android:textColor="?attr/colorWarning"
|
||||
android:textIsSelectable="true"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvAccountDone" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvNoPrimaryArchive"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/title_no_primary_archive"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||
android:textColor="?attr/colorWarning"
|
||||
android:textIsSelectable="true"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvNoPrimaryDrafts" />
|
||||
|
||||
<View
|
||||
android:id="@+id/vSeparatorAccount"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:layout_marginTop="9dp"
|
||||
android:layout_marginTop="12dp"
|
||||
android:background="?attr/colorSeparator"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvAccountDone" />
|
||||
app:layout_constraintTop_toBottomOf="@id/tvNoPrimaryArchive" />
|
||||
|
||||
<!-- identity -->
|
||||
|
||||
|
@ -69,7 +93,7 @@
|
|||
android:id="@+id/btnIdentity"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="9dp"
|
||||
android:layout_marginTop="12dp"
|
||||
android:text="@string/title_setup_identity"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
|
@ -101,7 +125,7 @@
|
|||
android:id="@+id/vSeparatorIdentity"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:layout_marginTop="9dp"
|
||||
android:layout_marginTop="12dp"
|
||||
android:background="?attr/colorSeparator"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvIdentityDone" />
|
||||
|
@ -112,7 +136,7 @@
|
|||
android:id="@+id/btnPermissions"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="9dp"
|
||||
android:layout_marginTop="12dp"
|
||||
android:text="@string/title_setup_permissions"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
|
@ -144,7 +168,7 @@
|
|||
android:id="@+id/vSeparatorPermissions"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:layout_marginTop="9dp"
|
||||
android:layout_marginTop="12dp"
|
||||
android:background="?attr/colorSeparator"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvPermissionsDone" />
|
||||
|
@ -155,7 +179,7 @@
|
|||
android:id="@+id/btnDoze"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="9dp"
|
||||
android:layout_marginTop="12dp"
|
||||
android:text="@string/title_setup_doze"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
|
@ -190,7 +214,7 @@
|
|||
style="?android:attr/buttonStyleSmall"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="9dp"
|
||||
android:layout_marginTop="12dp"
|
||||
android:minWidth="0dp"
|
||||
android:minHeight="0dp"
|
||||
android:text="@string/title_setup_data"
|
||||
|
@ -202,7 +226,7 @@
|
|||
android:id="@+id/vSeparatorDoze"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:layout_marginTop="9dp"
|
||||
android:layout_marginTop="12dp"
|
||||
android:background="?attr/colorSeparator"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/btnData" />
|
||||
|
@ -211,7 +235,7 @@
|
|||
android:id="@+id/btnNotifications"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="9dp"
|
||||
android:layout_marginTop="12dp"
|
||||
android:text="@string/title_setup_notifications"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
|
@ -221,7 +245,7 @@
|
|||
android:id="@+id/tbDarkTheme"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="18dp"
|
||||
android:layout_marginTop="12dp"
|
||||
android:textOff="@string/title_setup_dark_theme"
|
||||
android:textOn="@string/title_setup_light_theme"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
|
@ -232,7 +256,7 @@
|
|||
android:id="@+id/cbBlackTheme"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="9dp"
|
||||
android:layout_marginTop="6dp"
|
||||
android:text="@string/title_setup_black_background"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
|
@ -243,7 +267,7 @@
|
|||
style="?android:attr/buttonStyleSmall"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="18dp"
|
||||
android:layout_marginTop="12dp"
|
||||
android:minWidth="0dp"
|
||||
android:minHeight="0dp"
|
||||
android:text="@string/title_advanced"
|
||||
|
|
Loading…
Add table
Reference in a new issue