Added account/identity delete

pull/30/head
M66B 6 years ago
parent 847db6be1f
commit d3ed9271ab

@ -70,5 +70,8 @@ public interface DaoAccount {
@Query("UPDATE account SET `primary` = 0")
void resetPrimary();
@Query("DELETE FROM account WHERE id = :id")
void deleteAccount(long id);
}

@ -53,4 +53,7 @@ public interface DaoIdentity {
@Query("UPDATE identity SET `primary` = 0")
void resetPrimary();
@Query("DELETE FROM identity WHERE id = :id")
void deleteIdentity(long id);
}

@ -21,6 +21,7 @@ package eu.faircode.email;
import android.arch.lifecycle.Observer;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
@ -28,6 +29,7 @@ import android.support.design.widget.TextInputLayout;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.AsyncTaskLoader;
import android.support.v4.content.Loader;
import android.support.v7.app.AlertDialog;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
@ -39,6 +41,7 @@ import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ProgressBar;
import android.widget.Spinner;
import android.widget.Toast;
@ -48,6 +51,8 @@ import com.sun.mail.imap.IMAPStore;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import javax.mail.Folder;
import javax.mail.MessagingException;
@ -66,8 +71,11 @@ public class FragmentAccount extends FragmentEx {
private CheckBox cbPrimary;
private Button btnSave;
private ProgressBar pbCheck;
private ImageButton ibDelete;
// TODO: loading spinner
private ExecutorService executor = Executors.newCachedThreadPool();
@Override
@Nullable
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
@ -94,6 +102,7 @@ public class FragmentAccount extends FragmentEx {
cbPrimary = view.findViewById(R.id.cbPrimary);
btnSave = view.findViewById(R.id.btnSave);
pbCheck = view.findViewById(R.id.pbCheck);
ibDelete = view.findViewById(R.id.ibDelete);
// Wire controls
@ -144,9 +153,40 @@ public class FragmentAccount extends FragmentEx {
}
});
ibDelete.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder
.setMessage(R.string.title_account_delete)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
getFragmentManager().popBackStack();
// TODO: spinner
executor.submit(new Runnable() {
@Override
public void run() {
try {
// To prevent foreign key constraints from triggering
ServiceSynchronize.stop(getContext(), "delete account");
DB.getInstance(getContext()).account().deleteAccount(id);
ServiceSynchronize.start(getContext());
} catch (Throwable ex) {
Log.e(Helper.TAG, ex + "\n" + Log.getStackTraceString(ex));
}
}
});
}
})
.setNegativeButton(android.R.string.cancel, null).show();
}
});
// Initialize
tilPassword.setPasswordVisibilityToggleEnabled(id < 0);
pbCheck.setVisibility(View.GONE);
ibDelete.setVisibility(id < 0 ? View.GONE : View.VISIBLE);
// Observe
DB.getInstance(getContext()).account().liveAccount(id).observe(this, new Observer<EntityAccount>() {

@ -21,6 +21,7 @@ package eu.faircode.email;
import android.arch.lifecycle.Observer;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
@ -28,6 +29,7 @@ import android.support.design.widget.TextInputLayout;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.AsyncTaskLoader;
import android.support.v4.content.Loader;
import android.support.v7.app.AlertDialog;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
@ -41,6 +43,7 @@ import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ProgressBar;
import android.widget.Spinner;
import android.widget.Toast;
@ -48,6 +51,8 @@ import android.widget.Toast;
import java.util.List;
import java.util.Objects;
import java.util.Properties;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import javax.mail.Session;
import javax.mail.Transport;
@ -68,8 +73,11 @@ public class FragmentIdentity extends FragmentEx {
private CheckBox cbPrimary;
private Button btnSave;
private ProgressBar pbCheck;
private ImageButton ibDelete;
// TODO: loading spinner
private ExecutorService executor = Executors.newCachedThreadPool();
@Override
@Nullable
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
@ -99,6 +107,7 @@ public class FragmentIdentity extends FragmentEx {
cbPrimary = view.findViewById(R.id.cbPrimary);
btnSave = view.findViewById(R.id.btnSave);
pbCheck = view.findViewById(R.id.pbCheck);
ibDelete = view.findViewById(R.id.ibDelete);
// Wire controls
@ -174,10 +183,38 @@ public class FragmentIdentity extends FragmentEx {
}
});
ibDelete.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder
.setMessage(R.string.title_identity_delete)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
getFragmentManager().popBackStack();
// TODO: spinner
executor.submit(new Runnable() {
@Override
public void run() {
try {
DB.getInstance(getContext()).identity().deleteIdentity(id);
} catch (Throwable ex) {
Log.e(Helper.TAG, ex + "\n" + Log.getStackTraceString(ex));
}
}
});
}
})
.setNegativeButton(android.R.string.cancel, null).show();
}
});
// Initialize
etName.requestFocus();
tilPassword.setPasswordVisibilityToggleEnabled(id < 0);
pbCheck.setVisibility(View.GONE);
ibDelete.setVisibility(id < 0 ? View.GONE : View.VISIBLE);
// Observer
DB.getInstance(getContext()).identity().liveIdentity(id).observe(this, new Observer<EntityIdentity>() {

@ -1254,6 +1254,11 @@ public class ServiceSynchronize extends LifecycleService {
ContextCompat.startForegroundService(context, new Intent(context, ServiceSynchronize.class));
}
public static void stop(Context context, String reason) {
Log.i(Helper.TAG, "Stop because of '" + reason + "'");
context.stopService(new Intent(context, ServiceSynchronize.class));
}
public static void restart(Context context, String reason) {
Log.i(Helper.TAG, "Restart because of '" + reason + "'");
context.stopService(new Intent(context, ServiceSynchronize.class));

@ -196,6 +196,14 @@
app:layout_constraintStart_toEndOf="@id/btnSave"
app:layout_constraintTop_toTopOf="@id/btnSave" />
<ImageButton
android:id="@+id/ibDelete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/baseline_delete_24"
app:layout_constraintBottom_toBottomOf="@id/btnSave"
app:layout_constraintEnd_toEndOf="parent" />
<android.support.constraint.Group
android:id="@+id/grpReady"
android:layout_width="0dp"

@ -248,6 +248,14 @@
app:layout_constraintStart_toEndOf="@id/btnSave"
app:layout_constraintTop_toTopOf="@id/btnSave" />
<ImageButton
android:id="@+id/ibDelete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/baseline_delete_24"
app:layout_constraintBottom_toBottomOf="@id/btnSave"
app:layout_constraintEnd_toEndOf="parent" />
<android.support.constraint.Group
android:id="@+id/grpReady"
android:layout_width="0dp"

@ -67,6 +67,8 @@
<string name="title_no_password">Password missing</string>
<string name="title_no_idle">IDLE not supported</string>
<string name="title_local_drafts">Local drafts</string>
<string name="title_account_delete">Delete this account permanently?</string>
<string name="title_identity_delete">Delete this identity permanently?</string>
<string name="title_folder_unseen" translatable="false">%1$s (%2$d)</string>
<string name="title_synchronize_folder">Synchronize (receive messages)</string>

Loading…
Cancel
Save