Added folder repair button

This commit is contained in:
M66B
2021-10-04 14:08:34 +02:00
parent 064f3e0c0c
commit a41a264099
3 changed files with 72 additions and 1 deletions

View File

@@ -125,6 +125,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
private SwitchCompat swLogInfo;
private SwitchCompat swDebug;
private Button btnRepair;
private TextView tvRoomQueryThreads;
private SeekBar sbRoomQueryThreads;
private ImageButton ibRoom;
@@ -246,6 +247,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
swLogInfo = view.findViewById(R.id.swLogInfo);
swDebug = view.findViewById(R.id.swDebug);
btnRepair = view.findViewById(R.id.btnRepair);
tvRoomQueryThreads = view.findViewById(R.id.tvRoomQueryThreads);
sbRoomQueryThreads = view.findViewById(R.id.sbRoomQueryThreads);
ibRoom = view.findViewById(R.id.ibRoom);
@@ -1144,6 +1146,62 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
swLogInfo.setChecked(prefs.getInt("log_level", Log.getDefaultLogLevel()) <= android.util.Log.INFO);
swDebug.setChecked(prefs.getBoolean("debug", false));
btnRepair.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new SimpleTask<Void>() {
@Override
protected void onPostExecute(Bundle args) {
ToastEx.makeText(v.getContext(), R.string.title_completed, Toast.LENGTH_LONG).show();
}
@Override
protected Void onExecute(Context context, Bundle args) throws Throwable {
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;
}
@Override
protected void onExecuted(Bundle args, Void data) {
ServiceSynchronize.reload(v.getContext(), null, true, "repair");
}
@Override
protected void onException(Bundle args, Throwable ex) {
Log.unexpectedError(getParentFragmentManager(), ex);
}
}.execute(FragmentOptionsMisc.this, new Bundle(), "repair");
}
});
int query_threads = prefs.getInt("query_threads", DB.DEFAULT_QUERY_THREADS);
tvRoomQueryThreads.setText(getString(R.string.title_advanced_room_query_threads, NF.format(query_threads)));
sbRoomQueryThreads.setProgress(query_threads);