Added long press to set account/identity primary

pull/178/head
M66B 5 years ago
parent d853e30953
commit 7ae261e20a

@ -241,6 +241,8 @@ public class AdapterAccount extends RecyclerView.Adapter<AdapterAccount.ViewHold
popupMenu.getMenu().add(Menu.NONE, R.string.title_enabled, 1, R.string.title_enabled)
.setCheckable(true).setChecked(account.synchronize);
popupMenu.getMenu().add(Menu.NONE, R.string.title_primary, 2, R.string.title_primary)
.setCheckable(true).setChecked(account.primary);
if (account.notify &&
Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
@ -248,11 +250,11 @@ public class AdapterAccount extends RecyclerView.Adapter<AdapterAccount.ViewHold
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
NotificationChannel channel = nm.getNotificationChannel(channelId);
if (channel != null)
popupMenu.getMenu().add(Menu.NONE, R.string.title_edit_channel, 2, R.string.title_edit_channel);
popupMenu.getMenu().add(Menu.NONE, R.string.title_edit_channel, 3, R.string.title_edit_channel);
}
if (account.protocol == EntityAccount.TYPE_IMAP && settings)
popupMenu.getMenu().add(Menu.NONE, R.string.title_copy, 3, R.string.title_copy);
popupMenu.getMenu().add(Menu.NONE, R.string.title_copy, 4, R.string.title_copy);
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
@ -262,6 +264,10 @@ public class AdapterAccount extends RecyclerView.Adapter<AdapterAccount.ViewHold
onActionSync(!item.isChecked());
return true;
case R.string.title_primary:
onActionPrimary(!item.isChecked());
return true;
case R.string.title_edit_channel:
onActionEditChannel();
return true;
@ -308,6 +314,40 @@ public class AdapterAccount extends RecyclerView.Adapter<AdapterAccount.ViewHold
}.execute(context, owner, args, "account:enable");
}
private void onActionPrimary(boolean primary) {
Bundle args = new Bundle();
args.putLong("id", account.id);
args.putBoolean("primary", primary);
new SimpleTask<Void>() {
@Override
protected Void onExecute(Context context, Bundle args) {
long id = args.getLong("id");
boolean primary = args.getBoolean("primary");
DB db = DB.getInstance(context);
try {
db.beginTransaction();
if (primary)
db.account().resetPrimary();
db.account().setAccountPrimary(id, primary);
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
return null;
}
@Override
protected void onException(Bundle args, Throwable ex) {
Log.unexpectedError(parentFragment.getParentFragmentManager(), ex);
}
}.execute(context, owner, args, "account:primary");
}
@TargetApi(Build.VERSION_CODES.O)
private void onActionEditChannel() {
Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS)

@ -187,11 +187,13 @@ public class AdapterIdentity extends RecyclerView.Adapter<AdapterIdentity.ViewHo
popupMenu.getMenu().add(Menu.NONE, R.string.title_enabled, 1, R.string.title_enabled)
.setCheckable(true).setChecked(identity.synchronize);
popupMenu.getMenu().add(Menu.NONE, R.string.title_primary, 2, R.string.title_primary)
.setCheckable(true).setChecked(identity.primary);
if (identity.sign_key != null)
popupMenu.getMenu().add(Menu.NONE, R.string.title_reset_sign_key, 2, R.string.title_reset_sign_key);
popupMenu.getMenu().add(Menu.NONE, R.string.title_reset_sign_key, 3, R.string.title_reset_sign_key);
popupMenu.getMenu().add(Menu.NONE, R.string.title_copy, 3, R.string.title_copy);
popupMenu.getMenu().add(Menu.NONE, R.string.title_copy, 4, R.string.title_copy);
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
@ -201,6 +203,10 @@ public class AdapterIdentity extends RecyclerView.Adapter<AdapterIdentity.ViewHo
onActionSync(!item.isChecked());
return true;
case R.string.title_primary:
onActionPrimary(!item.isChecked());
return true;
case R.string.title_reset_sign_key:
onActionClearSignKey();
return true;
@ -237,7 +243,45 @@ public class AdapterIdentity extends RecyclerView.Adapter<AdapterIdentity.ViewHo
protected void onException(Bundle args, Throwable ex) {
Log.unexpectedError(parentFragment.getParentFragmentManager(), ex);
}
}.execute(context, owner, args, "identitty:enable");
}.execute(context, owner, args, "identity:enable");
}
private void onActionPrimary(boolean primary) {
Bundle args = new Bundle();
args.putLong("id", identity.id);
args.putLong("account", identity.account);
args.putBoolean("primary", primary);
new SimpleTask<Void>() {
@Override
protected Void onExecute(Context context, Bundle args) {
long id = args.getLong("id");
long account = args.getLong("account");
boolean primary = args.getBoolean("primary");
DB db = DB.getInstance(context);
try {
db.beginTransaction();
if (identity.primary)
db.identity().resetPrimary(account);
db.identity().setIdentityPrimary(id, primary);
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
return null;
}
@Override
protected void onException(Bundle args, Throwable ex) {
Log.unexpectedError(parentFragment.getParentFragmentManager(), ex);
}
}.execute(context, owner, args, "identity:primary");
}
private void onActionClearSignKey() {

@ -122,6 +122,9 @@ public interface DaoAccount {
@Query("UPDATE account SET synchronize = :synchronize WHERE id = :id")
int setAccountSynchronize(long id, boolean synchronize);
@Query("UPDATE account SET `primary` = :primary WHERE id = :id")
int setAccountPrimary(long id, boolean primary);
@Query("UPDATE account SET thread = :thread WHERE id = :id")
int setAccountThread(long id, Long thread);

@ -85,6 +85,9 @@ public interface DaoIdentity {
@Query("UPDATE identity SET synchronize = :synchronize WHERE id = :id")
int setIdentitySynchronize(long id, boolean synchronize);
@Query("UPDATE identity SET `primary` = :primary WHERE id = :id")
int setIdentityPrimary(long id, boolean primary);
@Query("UPDATE identity SET state = :state WHERE id = :id")
int setIdentityState(long id, String state);

@ -561,6 +561,7 @@
<string name="title_client_certificate">Client certificate</string>
<string name="title_realm">Realm</string>
<string name="title_use_ip">Use local IP address instead of host name</string>
<string name="title_primary">Primary</string>
<string name="title_primary_account">Primary (default account)</string>
<string name="title_primary_identity">Primary (default identity)</string>
<string name="title_leave_on_server">Leave messages on server</string>

Loading…
Cancel
Save