mirror of
https://github.com/M66B/FairEmail.git
synced 2026-01-06 12:54:11 +01:00
Added folder poll factor
This commit is contained in:
2169
app/schemas/eu.faircode.email.DB/145.json
Normal file
2169
app/schemas/eu.faircode.email.DB/145.json
Normal file
File diff suppressed because it is too large
Load Diff
@@ -60,7 +60,7 @@ import io.requery.android.database.sqlite.SQLiteDatabase;
|
||||
// https://developer.android.com/topic/libraries/architecture/room.html
|
||||
|
||||
@Database(
|
||||
version = 144,
|
||||
version = 145,
|
||||
entities = {
|
||||
EntityIdentity.class,
|
||||
EntityAccount.class,
|
||||
@@ -1386,6 +1386,14 @@ public abstract class DB extends RoomDatabase {
|
||||
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
||||
db.execSQL("ALTER TABLE `folder` ADD COLUMN `inferiors` INTEGER NOT NULL DEFAULT 1");
|
||||
}
|
||||
})
|
||||
.addMigrations(new Migration(144, 145) {
|
||||
@Override
|
||||
public void migrate(@NonNull SupportSQLiteDatabase db) {
|
||||
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
||||
db.execSQL("ALTER TABLE `folder` ADD COLUMN `poll_factor` INTEGER NOT NULL DEFAULT 1");
|
||||
db.execSQL("ALTER TABLE `folder` ADD COLUMN `poll_count` INTEGER NOT NULL DEFAULT 0");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -265,6 +265,7 @@ public interface DaoFolder {
|
||||
", hide = :hide" +
|
||||
", synchronize = :synchronize" +
|
||||
", poll = :poll" +
|
||||
", poll_factor = :poll_factor" +
|
||||
", download = :download" +
|
||||
", `sync_days` = :sync_days" +
|
||||
", `keep_days` = :keep_days" +
|
||||
@@ -273,7 +274,7 @@ public interface DaoFolder {
|
||||
int setFolderProperties(
|
||||
long id, String rename,
|
||||
String display, Integer color, boolean unified, boolean navigation, boolean notify, boolean hide,
|
||||
boolean synchronize, boolean poll, boolean download,
|
||||
boolean synchronize, boolean poll, int poll_factor, boolean download,
|
||||
int sync_days, int keep_days, boolean auto_delete);
|
||||
|
||||
@Query("UPDATE folder" +
|
||||
@@ -315,6 +316,9 @@ public interface DaoFolder {
|
||||
@Query("UPDATE folder SET tbd = 1 WHERE id = :id")
|
||||
int setFolderTbd(long id);
|
||||
|
||||
@Query("UPDATE folder SET poll_count = :count WHERE id = :id")
|
||||
int setFolderPollCount(long id, int count);
|
||||
|
||||
@Query("DELETE FROM folder WHERE id = :id")
|
||||
void deleteFolder(long id);
|
||||
|
||||
|
||||
@@ -78,6 +78,10 @@ public class EntityFolder extends EntityOrder implements Serializable {
|
||||
@NonNull
|
||||
public Boolean poll = false;
|
||||
@NonNull
|
||||
public Integer poll_factor = 1;
|
||||
@NonNull
|
||||
public Integer poll_count = 0;
|
||||
@NonNull
|
||||
public Boolean download = true;
|
||||
public Boolean subscribed;
|
||||
@NonNull
|
||||
|
||||
@@ -64,6 +64,8 @@ public class FragmentFolder extends FragmentBase {
|
||||
private CheckBox cbNotify;
|
||||
private CheckBox cbSynchronize;
|
||||
private CheckBox cbPoll;
|
||||
private EditText etPoll;
|
||||
private TextView tvPoll;
|
||||
private CheckBox cbDownload;
|
||||
private Button btnInfo;
|
||||
private EditText etSyncDays;
|
||||
@@ -74,6 +76,7 @@ public class FragmentFolder extends FragmentBase {
|
||||
private ContentLoadingProgressBar pbSave;
|
||||
private ContentLoadingProgressBar pbWait;
|
||||
private Group grpParent;
|
||||
private Group grpPoll;
|
||||
|
||||
private long id = -1;
|
||||
private long account = -1;
|
||||
@@ -116,6 +119,8 @@ public class FragmentFolder extends FragmentBase {
|
||||
cbNotify = view.findViewById(R.id.cbNotify);
|
||||
cbSynchronize = view.findViewById(R.id.cbSynchronize);
|
||||
cbPoll = view.findViewById(R.id.cbPoll);
|
||||
etPoll = view.findViewById(R.id.etPoll);
|
||||
tvPoll = view.findViewById(R.id.tvPoll);
|
||||
cbDownload = view.findViewById(R.id.cbDownload);
|
||||
btnInfo = view.findViewById(R.id.btnInfo);
|
||||
etSyncDays = view.findViewById(R.id.etSyncDays);
|
||||
@@ -126,6 +131,7 @@ public class FragmentFolder extends FragmentBase {
|
||||
pbSave = view.findViewById(R.id.pbSave);
|
||||
pbWait = view.findViewById(R.id.pbWait);
|
||||
grpParent = view.findViewById(R.id.grpParent);
|
||||
grpPoll = view.findViewById(R.id.grpPoll);
|
||||
|
||||
btnColor.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
@@ -146,10 +152,19 @@ public class FragmentFolder extends FragmentBase {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
cbPoll.setEnabled(isChecked);
|
||||
etPoll.setEnabled(isChecked);
|
||||
tvPoll.setEnabled(isChecked);
|
||||
cbDownload.setEnabled(isChecked);
|
||||
}
|
||||
});
|
||||
|
||||
cbPoll.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
grpPoll.setVisibility(isChecked ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
});
|
||||
|
||||
btnInfo.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
@@ -208,12 +223,23 @@ public class FragmentFolder extends FragmentBase {
|
||||
@Override
|
||||
protected EntityFolder onExecute(Context context, Bundle args) {
|
||||
long id = args.getLong("id");
|
||||
return DB.getInstance(context).folder().getFolder(id);
|
||||
|
||||
DB db = DB.getInstance(context);
|
||||
EntityFolder folder = db.folder().getFolder(id);
|
||||
|
||||
if (folder != null) {
|
||||
EntityAccount account = db.account().getAccount(folder.account);
|
||||
if (account != null)
|
||||
args.putInt("interval", account.poll_interval);
|
||||
}
|
||||
|
||||
return folder;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onExecuted(Bundle args, EntityFolder folder) {
|
||||
if (savedInstanceState == null) {
|
||||
int interval = args.getInt("interval", EntityAccount.DEFAULT_KEEP_ALIVE_INTERVAL);
|
||||
etName.setText(folder == null ? null : folder.name);
|
||||
etDisplay.setText(folder == null ? null : folder.display);
|
||||
etDisplay.setHint(folder == null ? null : Helper.localizeFolderName(getContext(), folder.name));
|
||||
@@ -224,6 +250,10 @@ public class FragmentFolder extends FragmentBase {
|
||||
cbNotify.setChecked(folder == null ? false : folder.notify);
|
||||
cbSynchronize.setChecked(folder == null || folder.synchronize);
|
||||
cbPoll.setChecked(folder == null ? false : folder.poll);
|
||||
etPoll.setText(folder == null ? null : Integer.toString(folder.poll_factor));
|
||||
etPoll.setHint(Integer.toString(EntityAccount.DEFAULT_POLL_INTERVAL));
|
||||
tvPoll.setText(getString(R.string.title_factor_minutes, interval));
|
||||
grpPoll.setVisibility(cbPoll.isChecked() ? View.VISIBLE : View.GONE);
|
||||
cbDownload.setChecked(folder == null ? true : folder.download);
|
||||
etSyncDays.setText(Integer.toString(folder == null ? EntityFolder.DEFAULT_SYNC : folder.sync_days));
|
||||
if (folder != null && folder.keep_days == Integer.MAX_VALUE)
|
||||
@@ -248,6 +278,8 @@ public class FragmentFolder extends FragmentBase {
|
||||
|
||||
etName.setEnabled(folder == null || EntityFolder.USER.equals(folder.type));
|
||||
cbPoll.setEnabled(cbSynchronize.isChecked());
|
||||
etPoll.setEnabled(cbSynchronize.isChecked());
|
||||
tvPoll.setEnabled(cbSynchronize.isChecked());
|
||||
cbDownload.setEnabled(cbSynchronize.isChecked());
|
||||
etKeepDays.setEnabled(!cbKeepAll.isChecked());
|
||||
cbAutoDelete.setEnabled(!cbKeepAll.isChecked());
|
||||
@@ -349,6 +381,7 @@ public class FragmentFolder extends FragmentBase {
|
||||
args.putBoolean("notify", cbNotify.isChecked());
|
||||
args.putBoolean("synchronize", cbSynchronize.isChecked());
|
||||
args.putBoolean("poll", cbPoll.isChecked());
|
||||
args.putString("factor", etPoll.getText().toString());
|
||||
args.putBoolean("download", cbDownload.isChecked());
|
||||
args.putString("sync", etSyncDays.getText().toString());
|
||||
args.putString("keep", cbKeepAll.isChecked()
|
||||
@@ -389,6 +422,7 @@ public class FragmentFolder extends FragmentBase {
|
||||
boolean notify = args.getBoolean("notify");
|
||||
boolean synchronize = args.getBoolean("synchronize");
|
||||
boolean poll = args.getBoolean("poll");
|
||||
String factor = args.getString("factor");
|
||||
boolean download = args.getBoolean("download");
|
||||
String sync = args.getString("sync");
|
||||
String keep = args.getString("keep");
|
||||
@@ -406,6 +440,9 @@ public class FragmentFolder extends FragmentBase {
|
||||
int keep_days = (TextUtils.isEmpty(keep) ? EntityFolder.DEFAULT_KEEP : Integer.parseInt(keep));
|
||||
if (keep_days < sync_days)
|
||||
keep_days = sync_days;
|
||||
int poll_factor = (TextUtils.isEmpty(factor) ? EntityAccount.DEFAULT_POLL_INTERVAL : Integer.parseInt(factor));
|
||||
if (poll_factor < 1)
|
||||
poll_factor = 1;
|
||||
|
||||
boolean reload;
|
||||
DB db = DB.getInstance(context);
|
||||
@@ -436,6 +473,8 @@ public class FragmentFolder extends FragmentBase {
|
||||
return true;
|
||||
if (!Objects.equals(folder.poll, poll))
|
||||
return true;
|
||||
if (!Objects.equals(folder.poll_factor, poll_factor))
|
||||
return true;
|
||||
if (!Objects.equals(folder.download, download))
|
||||
return true;
|
||||
if (!Objects.equals(folder.sync_days, sync_days))
|
||||
@@ -478,6 +517,7 @@ public class FragmentFolder extends FragmentBase {
|
||||
create.hide = hide;
|
||||
create.synchronize = synchronize;
|
||||
create.poll = poll;
|
||||
create.poll_factor = poll_factor;
|
||||
create.download = download;
|
||||
create.sync_days = sync_days;
|
||||
create.keep_days = keep_days;
|
||||
@@ -498,7 +538,7 @@ public class FragmentFolder extends FragmentBase {
|
||||
db.folder().setFolderProperties(id,
|
||||
folder.name.equals(name) ? null : name,
|
||||
display, color, unified, navigation, notify, hide,
|
||||
synchronize, poll, download,
|
||||
synchronize, poll, poll_factor, download,
|
||||
sync_days, keep_days, auto_delete);
|
||||
db.folder().setFolderError(id, null);
|
||||
|
||||
|
||||
@@ -1366,8 +1366,13 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
||||
// Sends folder NOOP
|
||||
if (!mapFolders.get(folder).isOpen())
|
||||
throw new StoreClosedException(iservice.getStore(), folder.name);
|
||||
} else
|
||||
EntityOperation.sync(this, folder.id, false);
|
||||
} else {
|
||||
if (folder.poll_count == 0)
|
||||
EntityOperation.sync(this, folder.id, false);
|
||||
folder.poll_count = (folder.poll_count + 1) % folder.poll_factor;
|
||||
db.folder().setFolderPollCount(folder.id, folder.poll_count);
|
||||
Log.i(folder.name + " poll count=" + folder.poll_count);
|
||||
}
|
||||
} catch (Throwable ex) {
|
||||
if (BuildConfig.DEBUG &&
|
||||
!first && !account.keep_alive_ok &&
|
||||
|
||||
@@ -152,6 +152,25 @@
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/cbSynchronize" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/etPoll"
|
||||
android:layout_width="100dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="24dp"
|
||||
android:inputType="number"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/cbPoll" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvPoll"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="6dp"
|
||||
android:text="x 15 min"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/etPoll"
|
||||
app:layout_constraintStart_toEndOf="@+id/etPoll"
|
||||
app:layout_constraintTop_toTopOf="@+id/etPoll" />
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/cbDownload"
|
||||
android:layout_width="wrap_content"
|
||||
@@ -159,7 +178,7 @@
|
||||
android:layout_marginTop="12dp"
|
||||
android:text="@string/title_download_folder"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/cbPoll" />
|
||||
app:layout_constraintTop_toBottomOf="@id/etPoll" />
|
||||
|
||||
<!-- after -->
|
||||
|
||||
@@ -297,5 +316,11 @@
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
app:constraint_referenced_ids="tvParentTitle,tvParent" />
|
||||
|
||||
<androidx.constraintlayout.widget.Group
|
||||
android:id="@+id/grpPoll"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
app:constraint_referenced_ids="etPoll,tvPoll" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</ScrollView>
|
||||
|
||||
@@ -99,6 +99,7 @@
|
||||
<string name="title_notification_alert">\'%1$s\' server alert</string>
|
||||
|
||||
<string name="title_name_count">%1$s (%2$s)</string>
|
||||
<string name="title_factor_minutes" translatable="false">X %1$d minutes</string>
|
||||
|
||||
<string name="menu_exit">Exit</string>
|
||||
<string name="menu_answers">Templates</string>
|
||||
|
||||
Reference in New Issue
Block a user