mirror of
https://github.com/M66B/FairEmail.git
synced 2025-03-15 08:29:24 +00:00
Replace executors by simple loader
This commit is contained in:
parent
850397c4fa
commit
ab6e8ed6dd
3 changed files with 29 additions and 29 deletions
|
@ -32,6 +32,8 @@ import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
|||
|
||||
public class ActivitySetup extends ActivityBase implements FragmentManager.OnBackStackChangedListener {
|
||||
static final int LOADER_CREATE_OUTBOX = 1;
|
||||
static final int LOADER_DELETE_ACCOUNT = 2;
|
||||
static final int LOADER_DELETE_IDENTITY = 3;
|
||||
|
||||
static final String ACTION_EDIT_ACCOUNT = BuildConfig.APPLICATION_ID + ".EDIT_ACCOUNT";
|
||||
static final String ACTION_EDIT_IDENTITY = BuildConfig.APPLICATION_ID + ".EDIT_IDENTITY";
|
||||
|
|
|
@ -51,8 +51,6 @@ import java.util.Comparator;
|
|||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import javax.mail.Folder;
|
||||
import javax.mail.MessagingException;
|
||||
|
@ -92,8 +90,6 @@ public class FragmentAccount extends FragmentEx {
|
|||
private ProgressBar pbWait;
|
||||
private Group grpFolders;
|
||||
|
||||
private ExecutorService executor = Executors.newCachedThreadPool();
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
|
@ -240,20 +236,23 @@ public class FragmentAccount extends FragmentEx {
|
|||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
getFragmentManager().popBackStack();
|
||||
|
||||
// TODO: spinner
|
||||
executor.submit(new Runnable() {
|
||||
new SimpleLoader<Void>() {
|
||||
@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));
|
||||
}
|
||||
public Void onLoad(Bundle args) {
|
||||
// To prevent foreign key constraints from triggering
|
||||
ServiceSynchronize.stop(getContext(), "delete account");
|
||||
DB.getInstance(getContext()).account().deleteAccount(id);
|
||||
ServiceSynchronize.start(getContext());
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
@Override
|
||||
public void onException(Bundle args, Throwable ex) {
|
||||
Toast.makeText(getContext(), ex.toString(), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}.load(FragmentAccount.this, ActivitySetup.LOADER_DELETE_ACCOUNT, new Bundle());
|
||||
}
|
||||
})
|
||||
.setNegativeButton(android.R.string.cancel, null).show();
|
||||
|
@ -436,8 +435,9 @@ public class FragmentAccount extends FragmentEx {
|
|||
Collections.sort(data.folders, new Comparator<EntityFolder>() {
|
||||
@Override
|
||||
public int compare(EntityFolder f1, EntityFolder f2) {
|
||||
int s = ((Integer) EntityFolder.FOLDER_SORT_ORDER.indexOf(f1.type))
|
||||
.compareTo(EntityFolder.FOLDER_SORT_ORDER.indexOf(f2.type));
|
||||
int s = Integer.compare(
|
||||
EntityFolder.FOLDER_SORT_ORDER.indexOf(f1.type),
|
||||
EntityFolder.FOLDER_SORT_ORDER.indexOf(f2.type));
|
||||
if (s != 0)
|
||||
return s;
|
||||
int c = -f1.synchronize.compareTo(f2.synchronize);
|
||||
|
|
|
@ -45,8 +45,6 @@ import com.google.android.material.textfield.TextInputLayout;
|
|||
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;
|
||||
|
@ -80,8 +78,6 @@ public class FragmentIdentity extends FragmentEx {
|
|||
private ImageButton ibDelete;
|
||||
private ProgressBar pbWait;
|
||||
|
||||
private ExecutorService executor = Executors.newCachedThreadPool();
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
|
@ -220,16 +216,18 @@ public class FragmentIdentity extends FragmentEx {
|
|||
public void onClick(DialogInterface dialog, int which) {
|
||||
getFragmentManager().popBackStack();
|
||||
// TODO: spinner
|
||||
executor.submit(new Runnable() {
|
||||
new SimpleLoader<Void>() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
DB.getInstance(getContext()).identity().deleteIdentity(id);
|
||||
} catch (Throwable ex) {
|
||||
Log.e(Helper.TAG, ex + "\n" + Log.getStackTraceString(ex));
|
||||
}
|
||||
public Void onLoad(Bundle args) throws Throwable {
|
||||
DB.getInstance(getContext()).identity().deleteIdentity(id);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
@Override
|
||||
public void onException(Bundle args, Throwable ex) {
|
||||
Toast.makeText(getContext(), ex.toString(), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}.load(FragmentIdentity.this, ActivitySetup.LOADER_DELETE_IDENTITY, new Bundle());
|
||||
}
|
||||
})
|
||||
.setNegativeButton(android.R.string.cancel, null).show();
|
||||
|
|
Loading…
Add table
Reference in a new issue