Browse Source

Added account/identity delete

main
M66B 6 years ago
parent
commit
d3ed9271ab
8 changed files with 106 additions and 0 deletions
  1. +3
    -0
      app/src/main/java/eu/faircode/email/DaoAccount.java
  2. +3
    -0
      app/src/main/java/eu/faircode/email/DaoIdentity.java
  3. +40
    -0
      app/src/main/java/eu/faircode/email/FragmentAccount.java
  4. +37
    -0
      app/src/main/java/eu/faircode/email/FragmentIdentity.java
  5. +5
    -0
      app/src/main/java/eu/faircode/email/ServiceSynchronize.java
  6. +8
    -0
      app/src/main/res/layout/fragment_account.xml
  7. +8
    -0
      app/src/main/res/layout/fragment_identity.xml
  8. +2
    -0
      app/src/main/res/values/strings.xml

+ 3
- 0
app/src/main/java/eu/faircode/email/DaoAccount.java View File

@ -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);
}

+ 3
- 0
app/src/main/java/eu/faircode/email/DaoIdentity.java View File

@ -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);
}

+ 40
- 0
app/src/main/java/eu/faircode/email/FragmentAccount.java View File

@ -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>() {


+ 37
- 0
app/src/main/java/eu/faircode/email/FragmentIdentity.java View File

@ -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>() {


+ 5
- 0
app/src/main/java/eu/faircode/email/ServiceSynchronize.java View File

@ -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));


+ 8
- 0
app/src/main/res/layout/fragment_account.xml View File

@ -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"


+ 8
- 0
app/src/main/res/layout/fragment_identity.xml View File

@ -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"


+ 2
- 0
app/src/main/res/values/strings.xml View File

@ -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