Confirm repair

pull/206/head
M66B 4 years ago
parent 09406ecac8
commit c468068603

@ -632,58 +632,73 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
btnRepair.setOnClickListener(new View.OnClickListener() { btnRepair.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
new SimpleTask<Void>() { new AlertDialog.Builder(view.getContext())
@Override .setTitle(R.string.title_advanced_repair)
protected void onPostExecute(Bundle args) { .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
prefs.edit().remove("debug").apply(); @Override
ToastEx.makeText(v.getContext(), R.string.title_completed, Toast.LENGTH_LONG).show(); public void onClick(DialogInterface dialog, int which) {
} new SimpleTask<Void>() {
@Override
protected void onPostExecute(Bundle args) {
prefs.edit().remove("debug").apply();
ToastEx.makeText(v.getContext(), R.string.title_completed, Toast.LENGTH_LONG).show();
}
@Override @Override
protected Void onExecute(Context context, Bundle args) throws Throwable { protected Void onExecute(Context context, Bundle args) throws Throwable {
DB db = DB.getInstance(context); DB db = DB.getInstance(context);
List<EntityAccount> accounts = db.account().getAccounts();
if (accounts == null)
return null;
for (EntityAccount account : accounts) {
if (account.protocol != EntityAccount.TYPE_IMAP)
continue;
List<EntityFolder> folders = db.folder().getFolders(account.id, false, false);
if (folders == null)
continue;
EntityFolder inbox = db.folder().getFolderByType(account.id, EntityFolder.INBOX);
for (EntityFolder folder : folders) {
if (inbox == null && "inbox".equalsIgnoreCase(folder.name))
folder.type = EntityFolder.INBOX;
if (!EntityFolder.USER.equals(folder.type) &&
!EntityFolder.SYSTEM.equals(folder.type)) {
EntityLog.log(context, "Repairing " + account.name + ":" + folder.type);
folder.setProperties();
folder.setSpecials(account);
db.folder().updateFolder(folder);
}
}
}
return null;
}
List<EntityAccount> accounts = db.account().getAccounts(); @Override
if (accounts == null) protected void onExecuted(Bundle args, Void data) {
return null; ServiceSynchronize.reload(v.getContext(), null, true, "repair");
}
for (EntityAccount account : accounts) { @Override
if (account.protocol != EntityAccount.TYPE_IMAP) protected void onException(Bundle args, Throwable ex) {
continue; Log.unexpectedError(getParentFragmentManager(), ex);
}
List<EntityFolder> folders = db.folder().getFolders(account.id, false, false); }.execute(FragmentOptionsMisc.this, new Bundle(), "repair");
if (folders == null)
continue;
EntityFolder inbox = db.folder().getFolderByType(account.id, EntityFolder.INBOX);
for (EntityFolder folder : folders) {
if (inbox == null && "inbox".equalsIgnoreCase(folder.name))
folder.type = EntityFolder.INBOX;
if (!EntityFolder.USER.equals(folder.type) &&
!EntityFolder.SYSTEM.equals(folder.type)) {
EntityLog.log(context, "Repairing " + account.name + ":" + folder.type);
folder.setProperties();
folder.setSpecials(account);
db.folder().updateFolder(folder);
}
} }
} })
.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
return null; @Override
} public void onClick(DialogInterface dialog, int which) {
// Do nothing
@Override }
protected void onExecuted(Bundle args, Void data) { })
ServiceSynchronize.reload(v.getContext(), null, true, "repair"); .show();
}
@Override
protected void onException(Bundle args, Throwable ex) {
Log.unexpectedError(getParentFragmentManager(), ex);
}
}.execute(FragmentOptionsMisc.this, new Bundle(), "repair");
} }
}); });
swAutostart.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { swAutostart.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

Loading…
Cancel
Save