Added long press identity to edit identity color

This commit is contained in:
M66B 2024-05-21 19:57:51 +02:00
parent c744fc9904
commit a95b5cc886
4 changed files with 72 additions and 3 deletions

View File

@ -92,9 +92,10 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
static final int REQUEST_CHANGE_PASSWORD = 10;
static final int REQUEST_EDIT_ACCOUNT_COLOR = 11;
static final int REQUEST_DELETE_ACCOUNT = 12;
static final int REQUEST_IMPORT_PROVIDERS = 13;
static final int REQUEST_GRAPH_CONTACTS = 14;
static final int REQUEST_GRAPH_CONTACTS_OAUTH = 15;
static final int REQUEST_EDIT_IDENITY_COLOR = 13;
static final int REQUEST_IMPORT_PROVIDERS = 14;
static final int REQUEST_GRAPH_CONTACTS = 15;
static final int REQUEST_GRAPH_CONTACTS_OAUTH = 16;
static final int REQUEST_DEBUG_INFO = 7000;
static final int PI_CONNECTION = 1;

View File

@ -238,6 +238,9 @@ public class AdapterIdentity extends RecyclerView.Adapter<AdapterIdentity.ViewHo
popupMenu.getMenu().add(Menu.NONE, R.string.title_primary, order++, R.string.title_primary)
.setCheckable(true).setChecked(identity.primary);
if (parentFragment instanceof FragmentIdentities)
popupMenu.getMenu().add(Menu.NONE, R.string.title_color, order++, R.string.title_color);
if (identity.sign_key != null || identity.sign_key_alias != null)
popupMenu.getMenu().add(Menu.NONE, R.string.title_reset_sign_key, order++, R.string.title_reset_sign_key);
@ -257,6 +260,9 @@ public class AdapterIdentity extends RecyclerView.Adapter<AdapterIdentity.ViewHo
} else if (itemId == R.string.title_primary) {
onActionPrimary(!item.isChecked());
return true;
} else if (itemId == R.string.title_color) {
onActionEditColor();
return true;
} else if (itemId == R.string.title_reset_sign_key) {
onActionClearSignKey();
return true;
@ -340,6 +346,19 @@ public class AdapterIdentity extends RecyclerView.Adapter<AdapterIdentity.ViewHo
}.execute(context, owner, args, "identity:primary");
}
private void onActionEditColor() {
Bundle args = new Bundle();
args.putLong("id", identity.id);
args.putInt("color", identity.color == null ? Color.TRANSPARENT : identity.color);
args.putString("title", context.getString(R.string.title_color));
args.putBoolean("reset", true);
FragmentDialogColor fragment = new FragmentDialogColor();
fragment.setArguments(args);
fragment.setTargetFragment(parentFragment, ActivitySetup.REQUEST_EDIT_IDENITY_COLOR);
fragment.show(parentFragment.getParentFragmentManager(), "edit:color");
}
private void onActionClearSignKey() {
Bundle args = new Bundle();
args.putLong("id", identity.id);

View File

@ -114,6 +114,9 @@ public interface DaoIdentity {
@Query("UPDATE identity SET `primary` = :primary WHERE id = :id AND NOT (`primary` IS :primary)")
int setIdentityPrimary(long id, boolean primary);
@Query("UPDATE identity SET color = :color WHERE id = :id AND NOT (color IS :color)")
int setIdentityColor(long id, Integer color);
@Query("UPDATE identity SET state = :state WHERE id = :id AND NOT (state IS :state)")
int setIdentityState(long id, String state);

View File

@ -19,12 +19,15 @@ package eu.faircode.email;
Copyright 2018-2024 by Marcel Bokhorst (M66B)
*/
import static android.app.Activity.RESULT_OK;
import static androidx.recyclerview.widget.RecyclerView.NO_POSITION;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Rect;
import android.os.Bundle;
import android.view.LayoutInflater;
@ -220,4 +223,47 @@ public class FragmentIdentities extends FragmentBase {
}
});
}
@Override
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
try {
switch (requestCode) {
case ActivitySetup.REQUEST_EDIT_IDENITY_COLOR:
if (resultCode == RESULT_OK && data != null)
onEditIdentityColor(data.getBundleExtra("args"));
break;
}
} catch (Throwable ex) {
Log.e(ex);
}
}
private void onEditIdentityColor(Bundle args) {
if (!ActivityBilling.isPro(getContext())) {
startActivity(new Intent(getContext(), ActivityBilling.class));
return;
}
new SimpleTask<Void>() {
@Override
protected Void onExecute(Context context, Bundle args) {
long id = args.getLong("id");
Integer color = args.getInt("color");
if (color == Color.TRANSPARENT)
color = null;
DB db = DB.getInstance(context);
db.identity().setIdentityColor(id, color);
return null;
}
@Override
protected void onException(Bundle args, Throwable ex) {
Log.unexpectedError(getParentFragmentManager(), ex);
}
}.execute(this, args, "edit:color");
}
}