Cloud sync: switches for send/receive

pull/212/head
M66B 2 years ago
parent d667ce0272
commit 3acb8500c8

@ -215,6 +215,12 @@ public class CloudSync {
throws JSONException, GeneralSecurityException, IOException {
DB db = DB.getInstance(context);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean cloud_send = prefs.getBoolean("cloud_send", true);
if (!cloud_send) {
Log.w("Cloud skip send");
return;
}
List<EntityAccount> accounts = db.account().getSynchronizingAccounts(null);
Log.i("Cloud accounts=" + (accounts == null ? null : accounts.size()));
@ -299,6 +305,12 @@ public class CloudSync {
throws JSONException, GeneralSecurityException, IOException {
DB db = DB.getInstance(context);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean cloud_receive = prefs.getBoolean("cloud_receive", true);
if (!cloud_receive) {
Log.w("Cloud skip receive");
return;
}
// New revision
boolean updates = false;
@ -416,10 +428,12 @@ public class CloudSync {
db.account().resetPrimary();
db.account().setAccountPrimary(raccount.id, true);
}
db.account().setLastModified(raccount.id, rrevision);
db.account().setAccountLastModified(raccount.id, rrevision);
}
db.setTransactionSuccessful();
updates = true;
} finally {
db.endTransaction();
}
@ -474,6 +488,14 @@ public class CloudSync {
db.identity().updateIdentity(ridentity);
}
if (ridentity.id != null) {
if (ridentity.primary) {
db.identity().resetPrimary(ridentity.account);
db.identity().setIdentityPrimary(ridentity.id, true);
}
db.identity().setIdentityLastModified(ridentity.id, rrevision);
}
db.setTransactionSuccessful();
} finally {
db.endTransaction();

@ -288,11 +288,6 @@ public interface DaoAccount {
" AND (NOT (swipe_left IS :left) OR NOT (swipe_right IS :right))")
int setAccountSwipes(long id, Long left, Long right);
@Query("UPDATE account" +
" SET last_modified = :last_modified" +
" WHERE id = :id")
int setLastModified(long id, Long last_modified);
@Query("UPDATE account SET `primary` = 0 WHERE NOT (`primary` IS 0)")
void resetPrimary();
@ -305,6 +300,11 @@ public interface DaoAccount {
@Query("UPDATE account SET capability_uidl = :uidl WHERE id = :id AND NOT (capability_uidl IS :uidl)")
int setAccountUidl(long id, Boolean uidl);
@Query("UPDATE account" +
" SET last_modified = :last_modified" +
" WHERE id = :id")
int setAccountLastModified(long id, Long last_modified);
@Query("DELETE FROM account WHERE id = :id")
int deleteAccount(long id);
}

@ -153,6 +153,11 @@ public interface DaoIdentity {
@Query("UPDATE identity SET `primary` = 0 WHERE account = :account AND NOT (`primary` IS 0)")
void resetPrimary(long account);
@Query("UPDATE identity" +
" SET last_modified = :last_modified" +
" WHERE id = :id")
int setIdentityLastModified(long id, Long last_modified);
@Query("DELETE FROM identity WHERE id = :id")
int deleteIdentity(long id);
}

@ -119,6 +119,8 @@ public class FragmentOptionsBackup extends FragmentBase implements SharedPrefere
private TextInputLayout tilPassword;
private Button btnLogin;
private TextView tvLogin;
private CheckBox cbSend;
private CheckBox cbReceive;
private ImageButton ibSync;
private TextView tvLastSync;
private Button btnLogout;
@ -159,6 +161,8 @@ public class FragmentOptionsBackup extends FragmentBase implements SharedPrefere
tilPassword = view.findViewById(R.id.tilPassword);
btnLogin = view.findViewById(R.id.btnLogin);
tvLogin = view.findViewById(R.id.tvLogin);
cbSend = view.findViewById(R.id.cbSend);
cbReceive = view.findViewById(R.id.cbReceive);
ibSync = view.findViewById(R.id.ibSync);
tvLastSync = view.findViewById(R.id.tvLastSync);
btnLogout = view.findViewById(R.id.btnLogout);
@ -212,6 +216,20 @@ public class FragmentOptionsBackup extends FragmentBase implements SharedPrefere
}
});
cbSend.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
prefs.edit().putBoolean("cloud_send", isChecked).apply();
}
});
cbReceive.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
prefs.edit().putBoolean("cloud_receive", isChecked).apply();
}
});
btnLogout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -229,6 +247,9 @@ public class FragmentOptionsBackup extends FragmentBase implements SharedPrefere
? View.VISIBLE : View.GONE);
Helper.linkPro(tvCloudPro);
cbSend.setChecked(prefs.getBoolean("cloud_send", true));
cbReceive.setChecked(prefs.getBoolean("cloud_receive", true));
prefs.registerOnSharedPreferenceChangeListener(this);
onSharedPreferenceChanged(prefs, null);

@ -184,7 +184,18 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:layout_marginEnd="12dp"
android:text="@string/title_advanced_cloud_info"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textStyle="italic"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvCloud" />
<TextView
android:id="@+id/tvCloudSecurity"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:drawableEnd="@drawable/twotone_info_24"
android:drawablePadding="6dp"
android:text="@string/title_advanced_cloud_security"
@ -192,7 +203,7 @@
android:textStyle="italic"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvCloud" />
app:layout_constraintTop_toBottomOf="@id/tvCloudInfo" />
<TextView
android:id="@+id/tvCloudPro"
@ -203,7 +214,7 @@
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="?android:attr/textColorLink"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvCloudInfo" />
app:layout_constraintTop_toBottomOf="@id/tvCloudSecurity" />
<TextView
android:id="@+id/tvCloudExperimental"
@ -315,13 +326,33 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvLogin" />
<CheckBox
android:id="@+id/cbSend"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:tag="disable"
android:text="@string/title_advanced_cloud_send"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvAccountRemark" />
<CheckBox
android:id="@+id/cbReceive"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:tag="disable"
android:text="@string/title_advanced_cloud_receive"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbSend" />
<ImageButton
android:id="@+id/ibSync"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvAccountRemark"
app:layout_constraintTop_toBottomOf="@id/cbReceive"
app:srcCompat="@drawable/twotone_compare_arrows_24" />
<TextView

@ -979,11 +979,18 @@
<string name="title_experimental" translatable="false">This is an experimental feature!</string>
<string name="title_advanced_cloud_info" translatable="false">This feature is for synchronizing data between devices</string>
<string name="title_advanced_cloud_security" translatable="false">All data is encrypted end-to-end and the cloud server will never see the username, password and data</string>
<string name="title_advanced_cloud_login" translatable="false">Login</string>
<string name="title_advanced_cloud_register" translatable="false">Logging in for the first time will automatically create an account</string>
<string name="title_advanced_cloud_invalid" translatable="false">Invalid username or password</string>
<string name="title_advanced_cloud_account_remark" translatable="false">Only the data of enabled accounts will be synced and existing accounts on the device will never be deleted.</string>
<string name="title_advanced_cloud_account_remark" translatable="false">
Only enabled accounts and identities will be synchronized.
Folder properties will not be synchronized.
Existing accounts on the device will never be deleted.
</string>
<string name="title_advanced_cloud_receive" translatable="false">Receive data</string>
<string name="title_advanced_cloud_send" translatable="false">Send data</string>
<string name="title_advanced_cloud_last_sync" translatable="false">Last sync: %1$s</string>
<string name="title_advanced_cloud_logout" translatable="false">Logout</string>
<string name="title_advanced_cloud_wipe" translatable="false">Wipe cloud data on logout</string>

Loading…
Cancel
Save