|
|
@ -19,6 +19,8 @@ package eu.faircode.email;
|
|
|
|
Copyright 2018-2022 by Marcel Bokhorst (M66B)
|
|
|
|
Copyright 2018-2022 by Marcel Bokhorst (M66B)
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import static android.app.Activity.RESULT_OK;
|
|
|
|
|
|
|
|
|
|
|
|
import android.Manifest;
|
|
|
|
import android.Manifest;
|
|
|
|
import android.app.ActivityManager;
|
|
|
|
import android.app.ActivityManager;
|
|
|
|
import android.app.Dialog;
|
|
|
|
import android.app.Dialog;
|
|
|
@ -110,6 +112,7 @@ public class FragmentSetup extends FragmentBase {
|
|
|
|
private TextView tvSyncStopped;
|
|
|
|
private TextView tvSyncStopped;
|
|
|
|
|
|
|
|
|
|
|
|
private Button btnApp;
|
|
|
|
private Button btnApp;
|
|
|
|
|
|
|
|
private Button btnDelete;
|
|
|
|
|
|
|
|
|
|
|
|
private Group grpInexactAlarms;
|
|
|
|
private Group grpInexactAlarms;
|
|
|
|
private Group grpBackgroundRestricted;
|
|
|
|
private Group grpBackgroundRestricted;
|
|
|
@ -178,6 +181,7 @@ public class FragmentSetup extends FragmentBase {
|
|
|
|
tvSyncStopped = view.findViewById(R.id.tvSyncStopped);
|
|
|
|
tvSyncStopped = view.findViewById(R.id.tvSyncStopped);
|
|
|
|
|
|
|
|
|
|
|
|
btnApp = view.findViewById(R.id.btnApp);
|
|
|
|
btnApp = view.findViewById(R.id.btnApp);
|
|
|
|
|
|
|
|
btnDelete = view.findViewById(R.id.btnDelete);
|
|
|
|
|
|
|
|
|
|
|
|
grpInexactAlarms = view.findViewById(R.id.grpInexactAlarms);
|
|
|
|
grpInexactAlarms = view.findViewById(R.id.grpInexactAlarms);
|
|
|
|
grpBackgroundRestricted = view.findViewById(R.id.grpBackgroundRestricted);
|
|
|
|
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
|
|
|
|
// Initialize
|
|
|
|
FragmentDialogTheme.setBackground(getContext(), view, false);
|
|
|
|
FragmentDialogTheme.setBackground(getContext(), view, false);
|
|
|
|
|
|
|
|
|
|
|
@ -772,6 +789,22 @@ public class FragmentSetup extends FragmentBase {
|
|
|
|
cardManual.setVisibility(manual ? View.VISIBLE : View.GONE);
|
|
|
|
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
|
|
|
|
@Override
|
|
|
|
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
|
|
|
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
|
|
|
for (int i = 0; i < permissions.length; i++)
|
|
|
|
for (int i = 0; i < permissions.length; i++)
|
|
|
@ -790,6 +823,48 @@ public class FragmentSetup extends FragmentBase {
|
|
|
|
btnPermissions.setEnabled(!granted);
|
|
|
|
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() {
|
|
|
|
private ConnectivityManager.NetworkCallback networkCallback = new ConnectivityManager.NetworkCallback() {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onAvailable(Network network) {
|
|
|
|
public void onAvailable(Network network) {
|
|
|
|