Added setup more options

pull/194/merge
M66B 3 years ago
parent 9836329852
commit 811c543fa2

@ -142,6 +142,7 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
static final int REQUEST_IMPORT_CERTIFICATE = 7;
static final int REQUEST_OAUTH = 8;
static final int REQUEST_STILL = 9;
static final int REQUEST_DELETE_ACCOUNT = 10;
static final int PI_MISC = 1;

@ -43,8 +43,12 @@ public class FragmentDialogSelectAccount extends FragmentDialogBase {
new SimpleTask<List<EntityAccount>>() {
@Override
protected List<EntityAccount> onExecute(Context context, Bundle args) {
boolean all = (args != null && args.getBoolean("all"));
DB db = DB.getInstance(context);
return db.account().getSynchronizingAccounts(null);
return (all
? db.account().getAccounts()
: db.account().getSynchronizingAccounts(null));
}
@Override
@ -56,7 +60,7 @@ public class FragmentDialogSelectAccount extends FragmentDialogBase {
protected void onException(Bundle args, Throwable ex) {
Log.unexpectedError(getParentFragmentManager(), ex);
}
}.execute(this, new Bundle(), "messages:accounts");
}.execute(this, getArguments(), "messages:accounts");
return new AlertDialog.Builder(getContext())
.setIcon(R.drawable.twotone_account_circle_24)
@ -65,7 +69,9 @@ public class FragmentDialogSelectAccount extends FragmentDialogBase {
@Override
public void onClick(DialogInterface dialog, int which) {
EntityAccount account = adapter.getItem(which);
getArguments().putLong("account", account.id);
Bundle args = getArguments();
args.putLong("account", account.id);
args.putString("name", account.name);
sendResult(RESULT_OK);
}
})

@ -19,6 +19,8 @@ package eu.faircode.email;
Copyright 2018-2022 by Marcel Bokhorst (M66B)
*/
import static android.app.Activity.RESULT_OK;
import android.Manifest;
import android.app.ActivityManager;
import android.app.Dialog;
@ -110,6 +112,7 @@ public class FragmentSetup extends FragmentBase {
private TextView tvSyncStopped;
private Button btnApp;
private Button btnDelete;
private Group grpInexactAlarms;
private Group grpBackgroundRestricted;
@ -178,6 +181,7 @@ public class FragmentSetup extends FragmentBase {
tvSyncStopped = view.findViewById(R.id.tvSyncStopped);
btnApp = view.findViewById(R.id.btnApp);
btnDelete = view.findViewById(R.id.btnDelete);
grpInexactAlarms = view.findViewById(R.id.grpInexactAlarms);
grpBackgroundRestricted = view.findViewById(R.id.grpBackgroundRestricted);
@ -579,6 +583,19 @@ public class FragmentSetup extends FragmentBase {
}
});
btnDelete.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Bundle args = new Bundle();
args.putBoolean("all", true);
FragmentDialogSelectAccount fragment = new FragmentDialogSelectAccount();
fragment.setArguments(args);
fragment.setTargetFragment(FragmentSetup.this, ActivitySetup.REQUEST_DELETE_ACCOUNT);
fragment.show(getParentFragmentManager(), "setup:delete");
}
});
// Initialize
FragmentDialogTheme.setBackground(getContext(), view, false);
@ -772,6 +789,22 @@ public class FragmentSetup extends FragmentBase {
cardManual.setVisibility(manual ? View.VISIBLE : View.GONE);
}
@Override
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
try {
switch (requestCode) {
case ActivitySetup.REQUEST_DELETE_ACCOUNT:
if (resultCode == RESULT_OK && data != null)
onDeleteAccount(data.getBundleExtra("args"));
break;
}
} catch (Throwable ex) {
Log.e(ex);
}
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
for (int i = 0; i < permissions.length; i++)
@ -790,6 +823,48 @@ public class FragmentSetup extends FragmentBase {
btnPermissions.setEnabled(!granted);
}
private void onDeleteAccount(Bundle args) {
long account = args.getLong("account");
String name = args.getString("name");
new AlertDialog.Builder(view.getContext())
.setIcon(R.drawable.twotone_warning_24)
.setTitle(name)
.setMessage(R.string.title_account_delete)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Bundle args = new Bundle();
args.putLong("id", account);
new SimpleTask<Void>() {
@Override
protected Void onExecute(Context context, Bundle args) throws Throwable {
long id = args.getLong("id");
DB db = DB.getInstance(context);
db.account().deleteAccount(id);
return null;
}
@Override
protected void onException(Bundle args, Throwable ex) {
Log.unexpectedError(getParentFragmentManager(), ex);
}
}.execute(FragmentSetup.this, args, "setup:delete");
}
})
.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// Do nothing
}
})
.show();
}
private ConnectivityManager.NetworkCallback networkCallback = new ConnectivityManager.NetworkCallback() {
@Override
public void onAvailable(Network network) {

@ -875,18 +875,6 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvBatteryUsage" />
<Button
android:id="@+id/btnApp"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:drawableEnd="@drawable/twotone_android_24"
android:drawablePadding="6dp"
android:text="@string/title_advanced_app"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvSyncStopped" />
<androidx.constraintlayout.widget.Group
android:id="@+id/grpInexactAlarms"
android:layout_width="0dp"
@ -906,5 +894,62 @@
app:constraint_referenced_ids="tvDataSaver,btnDataSaver" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:id="@+id/cardExtra"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="3dp"
android:layout_marginTop="12dp"
app:cardBackgroundColor="?attr/colorCardBackground"
app:cardCornerRadius="6dp"
app:cardElevation="0dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cardDoze">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingHorizontal="6dp"
android:paddingVertical="12dp">
<eu.faircode.email.FixedTextView
android:id="@+id/tvExtra"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="@string/title_advanced_more"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/btnApp"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:drawableEnd="@drawable/twotone_android_24"
android:drawablePadding="6dp"
android:text="@string/title_advanced_app"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvExtra" />
<Button
android:id="@+id/btnDelete"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:drawableEnd="@drawable/twotone_delete_forever_24"
android:drawablePadding="6dp"
android:text="@string/title_delete_account"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/btnApp" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
</androidx.constraintlayout.widget.ConstraintLayout>
</eu.faircode.email.ScrollViewEx>

@ -935,6 +935,7 @@
<string name="title_drafts_select">Sending emails requires a drafts folder to be selected in the account settings</string>
<string name="title_account_auth_update">Update authorization</string>
<string name="title_account_auth_password">Switch to password authentication</string>
<string name="title_delete_account">Delete account</string>
<string name="title_account_delete">Delete this account permanently?</string>
<string name="title_identity_delete">Delete this identity permanently?</string>
<string name="title_edit_html">Edit as HTML</string>

Loading…
Cancel
Save