Added folder poll factor

pull/175/head 1.984
M66B 6 years ago
parent d014f18d20
commit 5b992b3166

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 // https://developer.android.com/topic/libraries/architecture/room.html
@Database( @Database(
version = 144, version = 145,
entities = { entities = {
EntityIdentity.class, EntityIdentity.class,
EntityAccount.class, EntityAccount.class,
@ -1386,6 +1386,14 @@ public abstract class DB extends RoomDatabase {
Log.i("DB migration from version " + startVersion + " to " + endVersion); Log.i("DB migration from version " + startVersion + " to " + endVersion);
db.execSQL("ALTER TABLE `folder` ADD COLUMN `inferiors` INTEGER NOT NULL DEFAULT 1"); 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" + ", hide = :hide" +
", synchronize = :synchronize" + ", synchronize = :synchronize" +
", poll = :poll" + ", poll = :poll" +
", poll_factor = :poll_factor" +
", download = :download" + ", download = :download" +
", `sync_days` = :sync_days" + ", `sync_days` = :sync_days" +
", `keep_days` = :keep_days" + ", `keep_days` = :keep_days" +
@ -273,7 +274,7 @@ public interface DaoFolder {
int setFolderProperties( int setFolderProperties(
long id, String rename, long id, String rename,
String display, Integer color, boolean unified, boolean navigation, boolean notify, boolean hide, 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); int sync_days, int keep_days, boolean auto_delete);
@Query("UPDATE folder" + @Query("UPDATE folder" +
@ -315,6 +316,9 @@ public interface DaoFolder {
@Query("UPDATE folder SET tbd = 1 WHERE id = :id") @Query("UPDATE folder SET tbd = 1 WHERE id = :id")
int setFolderTbd(long 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") @Query("DELETE FROM folder WHERE id = :id")
void deleteFolder(long id); void deleteFolder(long id);

@ -78,6 +78,10 @@ public class EntityFolder extends EntityOrder implements Serializable {
@NonNull @NonNull
public Boolean poll = false; public Boolean poll = false;
@NonNull @NonNull
public Integer poll_factor = 1;
@NonNull
public Integer poll_count = 0;
@NonNull
public Boolean download = true; public Boolean download = true;
public Boolean subscribed; public Boolean subscribed;
@NonNull @NonNull

@ -64,6 +64,8 @@ public class FragmentFolder extends FragmentBase {
private CheckBox cbNotify; private CheckBox cbNotify;
private CheckBox cbSynchronize; private CheckBox cbSynchronize;
private CheckBox cbPoll; private CheckBox cbPoll;
private EditText etPoll;
private TextView tvPoll;
private CheckBox cbDownload; private CheckBox cbDownload;
private Button btnInfo; private Button btnInfo;
private EditText etSyncDays; private EditText etSyncDays;
@ -74,6 +76,7 @@ public class FragmentFolder extends FragmentBase {
private ContentLoadingProgressBar pbSave; private ContentLoadingProgressBar pbSave;
private ContentLoadingProgressBar pbWait; private ContentLoadingProgressBar pbWait;
private Group grpParent; private Group grpParent;
private Group grpPoll;
private long id = -1; private long id = -1;
private long account = -1; private long account = -1;
@ -116,6 +119,8 @@ public class FragmentFolder extends FragmentBase {
cbNotify = view.findViewById(R.id.cbNotify); cbNotify = view.findViewById(R.id.cbNotify);
cbSynchronize = view.findViewById(R.id.cbSynchronize); cbSynchronize = view.findViewById(R.id.cbSynchronize);
cbPoll = view.findViewById(R.id.cbPoll); cbPoll = view.findViewById(R.id.cbPoll);
etPoll = view.findViewById(R.id.etPoll);
tvPoll = view.findViewById(R.id.tvPoll);
cbDownload = view.findViewById(R.id.cbDownload); cbDownload = view.findViewById(R.id.cbDownload);
btnInfo = view.findViewById(R.id.btnInfo); btnInfo = view.findViewById(R.id.btnInfo);
etSyncDays = view.findViewById(R.id.etSyncDays); etSyncDays = view.findViewById(R.id.etSyncDays);
@ -126,6 +131,7 @@ public class FragmentFolder extends FragmentBase {
pbSave = view.findViewById(R.id.pbSave); pbSave = view.findViewById(R.id.pbSave);
pbWait = view.findViewById(R.id.pbWait); pbWait = view.findViewById(R.id.pbWait);
grpParent = view.findViewById(R.id.grpParent); grpParent = view.findViewById(R.id.grpParent);
grpPoll = view.findViewById(R.id.grpPoll);
btnColor.setOnClickListener(new View.OnClickListener() { btnColor.setOnClickListener(new View.OnClickListener() {
@Override @Override
@ -146,10 +152,19 @@ public class FragmentFolder extends FragmentBase {
@Override @Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
cbPoll.setEnabled(isChecked); cbPoll.setEnabled(isChecked);
etPoll.setEnabled(isChecked);
tvPoll.setEnabled(isChecked);
cbDownload.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() { btnInfo.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
@ -208,12 +223,23 @@ public class FragmentFolder extends FragmentBase {
@Override @Override
protected EntityFolder onExecute(Context context, Bundle args) { protected EntityFolder onExecute(Context context, Bundle args) {
long id = args.getLong("id"); 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 @Override
protected void onExecuted(Bundle args, EntityFolder folder) { protected void onExecuted(Bundle args, EntityFolder folder) {
if (savedInstanceState == null) { if (savedInstanceState == null) {
int interval = args.getInt("interval", EntityAccount.DEFAULT_KEEP_ALIVE_INTERVAL);
etName.setText(folder == null ? null : folder.name); etName.setText(folder == null ? null : folder.name);
etDisplay.setText(folder == null ? null : folder.display); etDisplay.setText(folder == null ? null : folder.display);
etDisplay.setHint(folder == null ? null : Helper.localizeFolderName(getContext(), folder.name)); 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); cbNotify.setChecked(folder == null ? false : folder.notify);
cbSynchronize.setChecked(folder == null || folder.synchronize); cbSynchronize.setChecked(folder == null || folder.synchronize);
cbPoll.setChecked(folder == null ? false : folder.poll); 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); cbDownload.setChecked(folder == null ? true : folder.download);
etSyncDays.setText(Integer.toString(folder == null ? EntityFolder.DEFAULT_SYNC : folder.sync_days)); etSyncDays.setText(Integer.toString(folder == null ? EntityFolder.DEFAULT_SYNC : folder.sync_days));
if (folder != null && folder.keep_days == Integer.MAX_VALUE) 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)); etName.setEnabled(folder == null || EntityFolder.USER.equals(folder.type));
cbPoll.setEnabled(cbSynchronize.isChecked()); cbPoll.setEnabled(cbSynchronize.isChecked());
etPoll.setEnabled(cbSynchronize.isChecked());
tvPoll.setEnabled(cbSynchronize.isChecked());
cbDownload.setEnabled(cbSynchronize.isChecked()); cbDownload.setEnabled(cbSynchronize.isChecked());
etKeepDays.setEnabled(!cbKeepAll.isChecked()); etKeepDays.setEnabled(!cbKeepAll.isChecked());
cbAutoDelete.setEnabled(!cbKeepAll.isChecked()); cbAutoDelete.setEnabled(!cbKeepAll.isChecked());
@ -349,6 +381,7 @@ public class FragmentFolder extends FragmentBase {
args.putBoolean("notify", cbNotify.isChecked()); args.putBoolean("notify", cbNotify.isChecked());
args.putBoolean("synchronize", cbSynchronize.isChecked()); args.putBoolean("synchronize", cbSynchronize.isChecked());
args.putBoolean("poll", cbPoll.isChecked()); args.putBoolean("poll", cbPoll.isChecked());
args.putString("factor", etPoll.getText().toString());
args.putBoolean("download", cbDownload.isChecked()); args.putBoolean("download", cbDownload.isChecked());
args.putString("sync", etSyncDays.getText().toString()); args.putString("sync", etSyncDays.getText().toString());
args.putString("keep", cbKeepAll.isChecked() args.putString("keep", cbKeepAll.isChecked()
@ -389,6 +422,7 @@ public class FragmentFolder extends FragmentBase {
boolean notify = args.getBoolean("notify"); boolean notify = args.getBoolean("notify");
boolean synchronize = args.getBoolean("synchronize"); boolean synchronize = args.getBoolean("synchronize");
boolean poll = args.getBoolean("poll"); boolean poll = args.getBoolean("poll");
String factor = args.getString("factor");
boolean download = args.getBoolean("download"); boolean download = args.getBoolean("download");
String sync = args.getString("sync"); String sync = args.getString("sync");
String keep = args.getString("keep"); 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)); int keep_days = (TextUtils.isEmpty(keep) ? EntityFolder.DEFAULT_KEEP : Integer.parseInt(keep));
if (keep_days < sync_days) if (keep_days < sync_days)
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; boolean reload;
DB db = DB.getInstance(context); DB db = DB.getInstance(context);
@ -436,6 +473,8 @@ public class FragmentFolder extends FragmentBase {
return true; return true;
if (!Objects.equals(folder.poll, poll)) if (!Objects.equals(folder.poll, poll))
return true; return true;
if (!Objects.equals(folder.poll_factor, poll_factor))
return true;
if (!Objects.equals(folder.download, download)) if (!Objects.equals(folder.download, download))
return true; return true;
if (!Objects.equals(folder.sync_days, sync_days)) if (!Objects.equals(folder.sync_days, sync_days))
@ -478,6 +517,7 @@ public class FragmentFolder extends FragmentBase {
create.hide = hide; create.hide = hide;
create.synchronize = synchronize; create.synchronize = synchronize;
create.poll = poll; create.poll = poll;
create.poll_factor = poll_factor;
create.download = download; create.download = download;
create.sync_days = sync_days; create.sync_days = sync_days;
create.keep_days = keep_days; create.keep_days = keep_days;
@ -498,7 +538,7 @@ public class FragmentFolder extends FragmentBase {
db.folder().setFolderProperties(id, db.folder().setFolderProperties(id,
folder.name.equals(name) ? null : name, folder.name.equals(name) ? null : name,
display, color, unified, navigation, notify, hide, display, color, unified, navigation, notify, hide,
synchronize, poll, download, synchronize, poll, poll_factor, download,
sync_days, keep_days, auto_delete); sync_days, keep_days, auto_delete);
db.folder().setFolderError(id, null); db.folder().setFolderError(id, null);

@ -1366,8 +1366,13 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
// Sends folder NOOP // Sends folder NOOP
if (!mapFolders.get(folder).isOpen()) if (!mapFolders.get(folder).isOpen())
throw new StoreClosedException(iservice.getStore(), folder.name); throw new StoreClosedException(iservice.getStore(), folder.name);
} else } else {
if (folder.poll_count == 0)
EntityOperation.sync(this, folder.id, false); 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) { } catch (Throwable ex) {
if (BuildConfig.DEBUG && if (BuildConfig.DEBUG &&
!first && !account.keep_alive_ok && !first && !account.keep_alive_ok &&

@ -152,6 +152,25 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbSynchronize" /> 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 <CheckBox
android:id="@+id/cbDownload" android:id="@+id/cbDownload"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -159,7 +178,7 @@
android:layout_marginTop="12dp" android:layout_marginTop="12dp"
android:text="@string/title_download_folder" android:text="@string/title_download_folder"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbPoll" /> app:layout_constraintTop_toBottomOf="@id/etPoll" />
<!-- after --> <!-- after -->
@ -297,5 +316,11 @@
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="0dp" android:layout_height="0dp"
app:constraint_referenced_ids="tvParentTitle,tvParent" /> 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> </androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView> </ScrollView>

@ -99,6 +99,7 @@
<string name="title_notification_alert">\'%1$s\' server alert</string> <string name="title_notification_alert">\'%1$s\' server alert</string>
<string name="title_name_count">%1$s (%2$s)</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_exit">Exit</string>
<string name="menu_answers">Templates</string> <string name="menu_answers">Templates</string>

Loading…
Cancel
Save