mirror of
https://github.com/M66B/FairEmail.git
synced 2025-03-04 10:39:25 +00:00
Added menu item to folder list to edit the account name
This commit is contained in:
parent
a6e7054343
commit
8516de0491
4 changed files with 74 additions and 0 deletions
|
@ -197,6 +197,9 @@ public interface DaoAccount {
|
|||
@Query("UPDATE account SET state = :state WHERE id = :id AND NOT (state IS :state)")
|
||||
int setAccountState(long id, String state);
|
||||
|
||||
@Query("UPDATE account SET name = :name WHERE id = :id AND NOT (name IS :name)")
|
||||
int setAccountName(long id, String name);
|
||||
|
||||
@Query("UPDATE account SET password = :password WHERE id = :id AND NOT (password IS :password)")
|
||||
int setAccountPassword(long id, String password);
|
||||
|
||||
|
|
|
@ -119,6 +119,7 @@ public class FragmentFolders extends FragmentBase {
|
|||
static final int REQUEST_DELETE_FOLDER = 3;
|
||||
static final int REQUEST_EXECUTE_RULES = 4;
|
||||
static final int REQUEST_EXPORT_MESSAGES = 5;
|
||||
static final int REQUEST_EDIT_ACCOUNT_NAME = 6;
|
||||
|
||||
private static final long EXPORT_PROGRESS_INTERVAL = 5000L; // milliseconds
|
||||
|
||||
|
@ -571,6 +572,7 @@ public class FragmentFolders extends FragmentBase {
|
|||
menu.findItem(R.id.menu_subscribed_only).setVisible(subscriptions);
|
||||
menu.findItem(R.id.menu_sort_unread_atop).setChecked(sort_unread_atop);
|
||||
menu.findItem(R.id.menu_apply_all).setVisible(account >= 0 && imap);
|
||||
menu.findItem(R.id.menu_edit_account_name).setVisible(account >= 0);
|
||||
|
||||
super.onPrepareOptionsMenu(menu);
|
||||
}
|
||||
|
@ -608,6 +610,9 @@ public class FragmentFolders extends FragmentBase {
|
|||
} else if (itemId == R.id.menu_apply_all) {
|
||||
onMenuApplyToAll();
|
||||
return true;
|
||||
} else if (itemId == R.id.menu_edit_account_name) {
|
||||
onMenuEditAccount();
|
||||
return true;
|
||||
} else if (itemId == R.id.menu_force_sync) {
|
||||
onMenuForceSync();
|
||||
return true;
|
||||
|
@ -719,6 +724,38 @@ public class FragmentFolders extends FragmentBase {
|
|||
fragment.show(getParentFragmentManager(), "folders:apply");
|
||||
}
|
||||
|
||||
private void onMenuEditAccount() {
|
||||
Bundle args = new Bundle();
|
||||
args.putLong("id", account);
|
||||
|
||||
new SimpleTask<EntityAccount>() {
|
||||
@Override
|
||||
protected EntityAccount onExecute(Context context, Bundle args) throws Throwable {
|
||||
long id = args.getLong("id");
|
||||
DB db = DB.getInstance(context);
|
||||
return db.account().getAccount(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onExecuted(Bundle args, EntityAccount account) {
|
||||
if (account == null)
|
||||
return;
|
||||
|
||||
args.putString("name", account.name);
|
||||
|
||||
FragmentDialogEditName fragment = new FragmentDialogEditName();
|
||||
fragment.setArguments(args);
|
||||
fragment.setTargetFragment(FragmentFolders.this, REQUEST_EDIT_ACCOUNT_NAME);
|
||||
fragment.show(getParentFragmentManager(), "account:name");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onException(Bundle args, Throwable ex) {
|
||||
Log.unexpectedError(getParentFragmentManager(), ex);
|
||||
}
|
||||
}.execute(this, args, "account:name");
|
||||
}
|
||||
|
||||
private void onMenuForceSync() {
|
||||
refresh(true);
|
||||
ToastEx.makeText(getContext(), R.string.title_executing, Toast.LENGTH_LONG).show();
|
||||
|
@ -750,6 +787,10 @@ public class FragmentFolders extends FragmentBase {
|
|||
if (resultCode == RESULT_OK && data != null)
|
||||
onExportMessages(data.getData());
|
||||
break;
|
||||
case REQUEST_EDIT_ACCOUNT_NAME:
|
||||
if (resultCode == RESULT_OK && data != null)
|
||||
onEditAccountName(data.getBundleExtra("args"));
|
||||
break;
|
||||
}
|
||||
} catch (Throwable ex) {
|
||||
Log.e(ex);
|
||||
|
@ -1130,6 +1171,29 @@ public class FragmentFolders extends FragmentBase {
|
|||
}.execute(this, args, "folder:export");
|
||||
}
|
||||
|
||||
private void onEditAccountName(Bundle args) {
|
||||
new SimpleTask<Void>() {
|
||||
@Override
|
||||
protected Void onExecute(Context context, Bundle args) {
|
||||
long id = args.getLong("id");
|
||||
String name = args.getString("name");
|
||||
|
||||
if (TextUtils.isEmpty(name))
|
||||
return null;
|
||||
|
||||
DB db = DB.getInstance(context);
|
||||
db.account().setAccountName(id, name);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onException(Bundle args, Throwable ex) {
|
||||
Log.unexpectedError(getParentFragmentManager(), ex);
|
||||
}
|
||||
}.execute(this, args, "edit:name");
|
||||
}
|
||||
|
||||
public static class FragmentDialogApply extends FragmentDialogBase {
|
||||
@NonNull
|
||||
@Override
|
||||
|
|
|
@ -69,6 +69,12 @@
|
|||
<menu />
|
||||
</item>
|
||||
|
||||
<item
|
||||
android:id="@+id/menu_edit_account_name"
|
||||
android:title="@string/title_edit_account_name">
|
||||
<menu />
|
||||
</item>
|
||||
|
||||
<item
|
||||
android:id="@+id/menu_force_sync"
|
||||
android:title="@string/title_force_sync"
|
||||
|
|
|
@ -936,6 +936,7 @@
|
|||
<string name="title_sort_unread_atop">Sort unread on top</string>
|
||||
<string name="title_search_folder">Search for folder</string>
|
||||
<string name="title_apply_to_all">Apply to all</string>
|
||||
<string name="title_edit_account_name">Edit account name</string>
|
||||
<string name="title_hide_folder">Hide folder</string>
|
||||
<string name="title_unified_folder">Show in unified inbox</string>
|
||||
<string name="title_navigation_folder">Show in navigation menu</string>
|
||||
|
|
Loading…
Add table
Reference in a new issue