Cloud sync: added activate button

This commit is contained in:
M66B 2023-01-22 11:45:30 +01:00
parent 77ae4c42e4
commit 904d6e82f3
5 changed files with 52 additions and 2 deletions

View File

@ -21,6 +21,7 @@ package eu.faircode.email;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.OperationCanceledException;
import android.text.TextUtils;
import android.util.Base64;
import android.util.Pair;
@ -652,6 +653,8 @@ public class CloudSync {
JSONObject jerror = new JSONObject(detail);
if (status == HttpsURLConnection.HTTP_FORBIDDEN)
throw new SecurityException(jerror.optString("error"));
else if (status == HttpsURLConnection.HTTP_PAYMENT_REQUIRED)
throw new OperationCanceledException(jerror.optString("error"));
else
throw new IOException(error + " " + jerror);
}

View File

@ -37,6 +37,7 @@ import android.graphics.Typeface;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.OperationCanceledException;
import android.text.Editable;
import android.text.SpannableStringBuilder;
import android.text.TextUtils;
@ -119,6 +120,7 @@ public class FragmentOptionsBackup extends FragmentBase implements SharedPrefere
private TextInputLayout tilPassword;
private Button btnLogin;
private TextView tvLogin;
private Button btnActivate;
private CheckBox cbSend;
private CheckBox cbReceive;
private ImageButton ibSync;
@ -161,6 +163,7 @@ 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);
btnActivate = view.findViewById(R.id.btnActivate);
cbSend = view.findViewById(R.id.cbSend);
cbReceive = view.findViewById(R.id.cbReceive);
ibSync = view.findViewById(R.id.ibSync);
@ -209,6 +212,13 @@ public class FragmentOptionsBackup extends FragmentBase implements SharedPrefere
}
});
btnActivate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO
}
});
ibSync.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -246,6 +256,7 @@ public class FragmentOptionsBackup extends FragmentBase implements SharedPrefere
!TextUtils.isEmpty(BuildConfig.CLOUD_URI)
? View.VISIBLE : View.GONE);
Helper.linkPro(tvCloudPro);
btnActivate.setVisibility(View.GONE);
cbSend.setChecked(prefs.getBoolean("cloud_send", true));
cbReceive.setChecked(prefs.getBoolean("cloud_receive", false));
@ -1555,6 +1566,7 @@ public class FragmentOptionsBackup extends FragmentBase implements SharedPrefere
@Override
protected void onExecuted(Bundle args, Void data) {
btnActivate.setVisibility(View.GONE);
view.post(new Runnable() {
@Override
public void run() {
@ -1565,6 +1577,7 @@ public class FragmentOptionsBackup extends FragmentBase implements SharedPrefere
@Override
protected void onException(Bundle args, Throwable ex) {
btnActivate.setVisibility(ex instanceof OperationCanceledException ? View.VISIBLE : View.GONE);
if (ex instanceof SecurityException) {
AlertDialog.Builder builder = new AlertDialog.Builder(getContext())
.setIcon(R.drawable.twotone_warning_24)
@ -1574,7 +1587,7 @@ public class FragmentOptionsBackup extends FragmentBase implements SharedPrefere
if (!TextUtils.isEmpty(message))
builder.setMessage(message);
builder.show();
} else
} else if (!(ex instanceof OperationCanceledException))
Log.unexpectedError(getParentFragmentManager(), ex);
}
}.execute(FragmentOptionsBackup.this, args, "cloud");

View File

@ -0,0 +1,15 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M4,17h16v2L4,19zM17,10.83L15.38,12 13,8.76 12,7.4l-1,1.36L8.62,12 7,10.83 9.08,8L4,8v6h16L20,8h-5.08z"
android:strokeAlpha="0.3"
android:fillAlpha="0.3"/>
<path
android:fillColor="@android:color/white"
android:pathData="M20,6h-2.18c0.11,-0.31 0.18,-0.65 0.18,-1 0,-1.66 -1.34,-3 -3,-3 -1.05,0 -1.96,0.54 -2.5,1.35l-0.5,0.67 -0.5,-0.68C10.96,2.54 10.05,2 9,2 7.34,2 6,3.34 6,5c0,0.35 0.07,0.69 0.18,1L4,6c-1.11,0 -1.99,0.89 -1.99,2L2,19c0,1.11 0.89,2 2,2h16c1.11,0 2,-0.89 2,-2L22,8c0,-1.11 -0.89,-2 -2,-2zM15,4c0.55,0 1,0.45 1,1s-0.45,1 -1,1 -1,-0.45 -1,-1 0.45,-1 1,-1zM9,4c0.55,0 1,0.45 1,1s-0.45,1 -1,1 -1,-0.45 -1,-1 0.45,-1 1,-1zM20,19L4,19v-2h16v2zM20,14L4,14L4,8h5.08L7,10.83 8.62,12 11,8.76l1,-1.36 1,1.36L15.38,12 17,10.83 14.92,8L20,8v6z"/>
</vector>

View File

@ -324,6 +324,24 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/btnLogin" />
<Button
android:id="@+id/btnActivate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:backgroundTint="?attr/colorInfoBackground"
android:drawableEnd="@drawable/twotone_redeem_24"
android:drawablePadding="6dp"
android:paddingHorizontal="24dp"
android:paddingVertical="12dp"
android:tag="disable"
android:text="@string/title_advanced_cloud_activate"
android:textColor="?attr/colorInfoForeground"
android:textStyle="bold"
app:drawableTint="?attr/colorInfoForeground"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvRegister" />
<TextView
android:id="@+id/tvLogin"
android:layout_width="wrap_content"
@ -333,7 +351,7 @@
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvRegister" />
app:layout_constraintTop_toBottomOf="@id/btnActivate" />
<TextView
android:id="@+id/tvAccountRemark"

View File

@ -988,6 +988,7 @@
<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_password_remark" translatable="false">You can change the password by wiping the data and logging in again</string>
<string name="title_advanced_cloud_invalid" translatable="false">Invalid username or password</string>
<string name="title_advanced_cloud_activate" translatable="false">Activate</string>
<string name="title_advanced_cloud_account_remark" translatable="false">
Only enabled accounts and identities will be synchronized.
Folder properties will not be synchronized.