Added synchronize on demand setting

This commit is contained in:
M66B 2019-02-17 18:29:00 +00:00
parent 3dda075978
commit d597366f17
12 changed files with 1569 additions and 12 deletions

File diff suppressed because it is too large Load Diff

View File

@ -49,7 +49,7 @@ public class ActivityMain extends AppCompatActivity implements FragmentManager.O
new SimpleTask<List<EntityAccount>>() {
@Override
protected List<EntityAccount> onExecute(Context context, Bundle args) {
return DB.getInstance(context).account().getAccounts(true);
return DB.getInstance(context).account().getSynchronizingAccounts(true);
}
@Override

View File

@ -241,7 +241,7 @@ public class ActivitySetup extends ActivityBilling implements FragmentManager.On
if (savedInstanceState != null)
drawerToggle.setDrawerIndicatorEnabled(savedInstanceState.getBoolean("toggle"));
DB.getInstance(this).account().liveAccounts(true).observe(this, new Observer<List<EntityAccount>>() {
DB.getInstance(this).account().liveSynchronizingAccounts().observe(this, new Observer<List<EntityAccount>>() {
@Override
public void onChanged(List<EntityAccount> accounts) {
hasAccount = (accounts != null && accounts.size() > 0);

View File

@ -49,7 +49,7 @@ import io.requery.android.database.sqlite.RequerySQLiteOpenHelperFactory;
// https://developer.android.com/topic/libraries/architecture/room.html
@Database(
version = 44,
version = 45,
entities = {
EntityIdentity.class,
EntityAccount.class,
@ -512,6 +512,13 @@ public abstract class DB extends RoomDatabase {
db.execSQL("CREATE INDEX `index_contact_name_type` ON `contact` (`name`, `type`)");
}
})
.addMigrations(new Migration(44, 45) {
@Override
public void migrate(SupportSQLiteDatabase db) {
Log.i("DB migration from version " + startVersion + " to " + endVersion);
db.execSQL("ALTER TABLE `account` ADD COLUMN `ondemand` INTEGER NOT NULL DEFAULT 0");
}
})
.build();
}

View File

@ -32,8 +32,10 @@ public interface DaoAccount {
@Query("SELECT * FROM account")
List<EntityAccount> getAccounts();
@Query("SELECT * FROM account WHERE synchronize = :synchronize")
List<EntityAccount> getAccounts(boolean synchronize);
@Query("SELECT * FROM account" +
" WHERE synchronize" +
" AND (:all OR NOT ondemand)")
List<EntityAccount> getSynchronizingAccounts(boolean all);
@Query("SELECT * FROM account WHERE tbd = 1")
List<EntityAccount> getAccountsTbd();
@ -41,8 +43,10 @@ public interface DaoAccount {
@Query("SELECT * FROM account")
LiveData<List<EntityAccount>> liveAccounts();
@Query("SELECT * FROM account WHERE synchronize = :synchronize")
LiveData<List<EntityAccount>> liveAccounts(boolean synchronize);
@Query("SELECT * FROM account" +
" WHERE synchronize")
// including on demand
LiveData<List<EntityAccount>> liveSynchronizingAccounts();
@Query("SELECT *" +
", (SELECT COUNT(message.id)" +

View File

@ -71,6 +71,8 @@ public class EntityAccount implements Serializable {
@NonNull
public Boolean synchronize;
@NonNull
public Boolean ondemand = false;
@NonNull
public Boolean primary;
@NonNull
public Boolean notify;
@ -128,6 +130,7 @@ public class EntityAccount implements Serializable {
json.put("color", color);
json.put("synchronize", synchronize);
json.put("ondemand", ondemand);
json.put("primary", primary);
json.put("notify", notify);
json.put("browse", browse);
@ -163,6 +166,8 @@ public class EntityAccount implements Serializable {
account.color = json.getInt("color");
account.synchronize = json.getBoolean("synchronize");
if (json.has("ondemand"))
account.ondemand = json.getBoolean("ondemand");
account.primary = json.getBoolean("primary");
if (json.has("notify"))
account.notify = json.getBoolean("notify");

View File

@ -107,6 +107,7 @@ public class FragmentAccount extends FragmentBase {
private Button btnAdvanced;
private CheckBox cbSynchronize;
private CheckBox cbOnDemand;
private CheckBox cbPrimary;
private CheckBox cbNotify;
private CheckBox cbBrowse;
@ -183,6 +184,7 @@ public class FragmentAccount extends FragmentBase {
btnAdvanced = view.findViewById(R.id.btnAdvanced);
cbSynchronize = view.findViewById(R.id.cbSynchronize);
cbOnDemand = view.findViewById(R.id.cbOnDemand);
cbPrimary = view.findViewById(R.id.cbPrimary);
cbNotify = view.findViewById(R.id.cbNotify);
cbBrowse = view.findViewById(R.id.cbBrowse);
@ -746,6 +748,7 @@ public class FragmentAccount extends FragmentBase {
args.putInt("color", color);
args.putBoolean("synchronize", cbSynchronize.isChecked());
args.putBoolean("ondemand", cbOnDemand.isChecked());
args.putBoolean("primary", cbPrimary.isChecked());
args.putBoolean("notify", cbNotify.isChecked());
args.putBoolean("browse", cbBrowse.isChecked());
@ -795,6 +798,7 @@ public class FragmentAccount extends FragmentBase {
Integer color = args.getInt("color");
boolean synchronize = args.getBoolean("synchronize");
boolean ondemand = args.getBoolean("ondemand");
boolean primary = args.getBoolean("primary");
boolean notify = args.getBoolean("notify");
boolean browse = args.getBoolean("browse");
@ -844,6 +848,7 @@ public class FragmentAccount extends FragmentBase {
boolean reload = (check || account == null ||
(account.prefix == null ? prefix != null : !account.prefix.equals(prefix)) ||
account.synchronize != synchronize ||
account.ondemand != ondemand ||
!account.poll_interval.equals(Integer.parseInt(interval)));
Long last_connected = null;
@ -920,6 +925,7 @@ public class FragmentAccount extends FragmentBase {
account.color = color;
account.synchronize = synchronize;
account.ondemand = ondemand;
account.primary = (account.synchronize && primary);
account.notify = notify;
account.browse = browse;
@ -1142,6 +1148,7 @@ public class FragmentAccount extends FragmentBase {
cbNotify.setChecked(account == null ? false : account.notify);
cbSynchronize.setChecked(account == null ? true : account.synchronize);
cbOnDemand.setChecked(account == null ? false : account.ondemand);
cbPrimary.setChecked(account == null ? false : account.primary);
cbBrowse.setChecked(account == null ? true : account.browse);
etInterval.setText(account == null ? "" : Long.toString(account.poll_interval));

View File

@ -970,7 +970,7 @@ public class FragmentMessages extends FragmentBase {
if (result.hasTrash == null) result.hasTrash = false;
if (result.hasJunk == null) result.hasJunk = false;
result.accounts = db.account().getAccounts(true);
result.accounts = db.account().getSynchronizingAccounts(true);
final Collator collator = Collator.getInstance(Locale.getDefault());
collator.setStrength(Collator.SECONDARY); // Case insensitive, process accents etc

View File

@ -270,7 +270,7 @@ public class FragmentSetup extends FragmentBase {
final DB db = DB.getInstance(getContext());
db.account().liveAccounts(true).observe(getViewLifecycleOwner(), new Observer<List<EntityAccount>>() {
db.account().liveSynchronizingAccounts().observe(getViewLifecycleOwner(), new Observer<List<EntityAccount>>() {
private boolean done = false;
private LiveData<EntityFolder> livePrimaryDrafts = null;
private LiveData<EntityFolder> livePrimaryArchive = null;

View File

@ -3202,7 +3202,7 @@ public class ServiceSynchronize extends LifecycleService {
}
// Start monitoring accounts
List<EntityAccount> accounts = db.account().getAccounts(true);
List<EntityAccount> accounts = db.account().getSynchronizingAccounts(false);
for (final EntityAccount account : accounts) {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O)
if (account.notify)

View File

@ -331,6 +331,15 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/btnAdvanced" />
<CheckBox
android:id="@+id/cbOnDemand"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_synchronize_ondemand"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbSynchronize" />
<CheckBox
android:id="@+id/cbPrimary"
android:layout_width="wrap_content"
@ -338,7 +347,7 @@
android:layout_marginTop="12dp"
android:text="@string/title_primary_account"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbSynchronize" />
app:layout_constraintTop_toBottomOf="@id/cbOnDemand" />
<CheckBox
android:id="@+id/cbNotify"
@ -713,7 +722,9 @@
android:layout_height="0dp"
app:constraint_referenced_ids="
tvPrefix,tvPrefixRemark,etPrefix,cbNotify,
cbSynchronize,cbPrimary,cbBrowse,tvBrowseHint,tvInterval,etInterval" />
cbSynchronize,cbOnDemand,cbPrimary,
cbBrowse,tvBrowseHint,
tvInterval,etInterval" />
<androidx.constraintlayout.widget.Group
android:id="@+id/grpFolders"

View File

@ -230,6 +230,7 @@
<string name="title_authorizing">Authorizing account &#8230;</string>
<string name="title_setup_advanced">Advanced</string>
<string name="title_synchronize_account">Synchronize (receive messages)</string>
<string name="title_synchronize_ondemand">Synchronize on demand (manual)</string>
<string name="title_synchronize_identity">Synchronize (send messages)</string>
<string name="title_primary_account">Primary (default account)</string>
<string name="title_primary_identity">Primary (default identity)</string>