Added notes color

pull/197/head
M66B 4 years ago
parent a7ec00e6ea
commit 4497fb060c

File diff suppressed because it is too large Load Diff

@ -216,6 +216,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
private int colorAccent; private int colorAccent;
private int textColorPrimary; private int textColorPrimary;
private int textColorSecondary; private int textColorSecondary;
private int textColorTertiary;
private int textColorLink; private int textColorLink;
private int colorUnread; private int colorUnread;
private int colorRead; private int colorRead;
@ -1146,6 +1147,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
tvPreview.setVisibility(preview && !TextUtils.isEmpty(message.preview) ? View.VISIBLE : View.GONE); tvPreview.setVisibility(preview && !TextUtils.isEmpty(message.preview) ? View.VISIBLE : View.GONE);
tvNotes.setText(message.notes); tvNotes.setText(message.notes);
tvNotes.setTextColor(message.notes_color == null ? textColorTertiary : message.notes_color);
tvNotes.setVisibility(TextUtils.isEmpty(message.notes) ? View.GONE : View.VISIBLE); tvNotes.setVisibility(TextUtils.isEmpty(message.notes) ? View.GONE : View.VISIBLE);
// Error / warning // Error / warning
@ -4639,6 +4641,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putLong("id", message.id); args.putLong("id", message.id);
args.putString("notes", message.notes); args.putString("notes", message.notes);
args.putInt("color", message.notes_color == null ? Color.TRANSPARENT : message.notes_color);
FragmentDialogNotes fragment = new FragmentDialogNotes(); FragmentDialogNotes fragment = new FragmentDialogNotes();
fragment.setArguments(args); fragment.setArguments(args);
@ -5331,6 +5334,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
this.colorAccent = Helper.resolveColor(context, R.attr.colorAccent); this.colorAccent = Helper.resolveColor(context, R.attr.colorAccent);
this.textColorPrimary = Helper.resolveColor(context, android.R.attr.textColorPrimary); this.textColorPrimary = Helper.resolveColor(context, android.R.attr.textColorPrimary);
this.textColorSecondary = Helper.resolveColor(context, android.R.attr.textColorSecondary); this.textColorSecondary = Helper.resolveColor(context, android.R.attr.textColorSecondary);
this.textColorTertiary = Helper.resolveColor(context, android.R.attr.textColorTertiary);
this.textColorLink = Helper.resolveColor(context, android.R.attr.textColorLink); this.textColorLink = Helper.resolveColor(context, android.R.attr.textColorLink);
boolean highlight_unread = prefs.getBoolean("highlight_unread", true); boolean highlight_unread = prefs.getBoolean("highlight_unread", true);
@ -5573,9 +5577,10 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
same = false; same = false;
log("preview changed", next.id); log("preview changed", next.id);
} }
if (!Objects.equals(prev.notes, next.notes)) { if (!Objects.equals(prev.notes, next.notes) ||
!Objects.equals(prev.notes_color, next.notes_color)) {
same = false; same = false;
log("notes changed", next.id); log("notes/color changed", next.id);
} }
if (!Objects.equals(prev.sent, next.sent)) { if (!Objects.equals(prev.sent, next.sent)) {
same = false; same = false;
@ -6377,22 +6382,49 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
} }
public static class FragmentDialogNotes extends FragmentDialogBase { public static class FragmentDialogNotes extends FragmentDialogBase {
private ViewButtonColor btnColor;
@NonNull @NonNull
@Override @Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) { public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
final long id = getArguments().getLong("id"); final Bundle args = getArguments();
final String notes = getArguments().getString("notes"); final long id = args.getLong("id");
final String notes = args.getString("notes");
final Integer color = args.getInt("color");
final Context context = getContext(); final Context context = getContext();
final InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); final InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
View view = LayoutInflater.from(context).inflate(R.layout.dialog_notes, null); View view = LayoutInflater.from(context).inflate(R.layout.dialog_notes, null);
final EditText etNotes = view.findViewById(R.id.etNotes); final EditText etNotes = view.findViewById(R.id.etNotes);
btnColor = view.findViewById(R.id.btnColor);
etNotes.setText(notes); etNotes.setText(notes);
etNotes.selectAll(); btnColor.setColor(color);
etNotes.selectAll();
etNotes.requestFocus(); etNotes.requestFocus();
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); if (imm != null)
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
btnColor.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (imm != null)
imm.hideSoftInputFromWindow(etNotes.getWindowToken(), 0);
Bundle args = new Bundle();
args.putInt("color", btnColor.getColor());
args.putString("title", getString(R.string.title_color));
args.putBoolean("reset", true);
FragmentDialogColor fragment = new FragmentDialogColor();
fragment.setArguments(args);
fragment.setTargetFragment(FragmentDialogNotes.this, 1);
fragment.show(getParentFragmentManager(), "identity:color");
}
});
return new AlertDialog.Builder(context) return new AlertDialog.Builder(context)
.setView(view) .setView(view)
@ -6402,16 +6434,21 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putLong("id", id); args.putLong("id", id);
args.putString("notes", etNotes.getText().toString()); args.putString("notes", etNotes.getText().toString());
args.putInt("color", btnColor.getColor());
new SimpleTask<Void>() { new SimpleTask<Void>() {
@Override @Override
protected Void onExecute(Context context, Bundle args) { protected Void onExecute(Context context, Bundle args) {
long id = args.getLong("id"); long id = args.getLong("id");
String notes = args.getString("notes"); String notes = args.getString("notes");
Integer color = args.getInt("color");
if ("".equals(notes.trim())) if ("".equals(notes.trim()))
notes = null; notes = null;
if (color == Color.TRANSPARENT)
color = null;
DB db = DB.getInstance(context); DB db = DB.getInstance(context);
try { try {
db.beginTransaction(); db.beginTransaction();
@ -6420,7 +6457,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
if (message == null) if (message == null)
return null; return null;
db.message().setMessageNotes(message.id, notes); db.message().setMessageNotes(message.id, notes, color);
if (TextUtils.isEmpty(message.msgid)) if (TextUtils.isEmpty(message.msgid))
return null; return null;
@ -6430,7 +6467,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
return null; return null;
for (EntityMessage m : messages) for (EntityMessage m : messages)
db.message().setMessageNotes(m.id, notes); db.message().setMessageNotes(m.id, notes, color);
db.setTransactionSuccessful(); db.setTransactionSuccessful();
} finally { } finally {
@ -6450,6 +6487,16 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
.setNegativeButton(android.R.string.cancel, null) .setNegativeButton(android.R.string.cancel, null)
.create(); .create();
} }
@Override
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK && data != null) {
Bundle args = data.getBundleExtra("args");
btnColor.setColor(args.getInt("color"));
}
}
} }
public static class FragmentDialogKeywordManage extends FragmentDialogBase { public static class FragmentDialogKeywordManage extends FragmentDialogBase {
@ -6519,7 +6566,8 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
etKeyword.setText(null); etKeyword.setText(null);
etKeyword.requestFocus(); etKeyword.requestFocus();
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); if (imm != null)
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
return new AlertDialog.Builder(context) return new AlertDialog.Builder(context)
.setView(view) .setView(view)

@ -3051,6 +3051,7 @@ class Core {
// - messages in archive have same id as original // - messages in archive have same id as original
Integer color = null; Integer color = null;
String notes = null; String notes = null;
Integer notes_color = null;
if (message == null) { if (message == null) {
String msgid = helper.getMessageID(); String msgid = helper.getMessageID();
Log.i(folder.name + " searching for " + msgid); Log.i(folder.name + " searching for " + msgid);
@ -3093,8 +3094,10 @@ class Core {
if (dup.flagged && dup.color != null) if (dup.flagged && dup.color != null)
color = dup.color; color = dup.color;
if (dup.notes != null) if (dup.notes != null) {
notes = dup.notes; notes = dup.notes;
notes_color = dup.notes_color;
}
} }
} }
@ -3164,6 +3167,7 @@ class Core {
message.ui_encrypt = message.encrypt; message.ui_encrypt = message.encrypt;
message.received = received; message.received = received;
message.notes = notes; message.notes = notes;
message.notes_color = notes_color;
message.sent = sent; message.sent = sent;
message.seen = seen; message.seen = seen;
message.answered = answered; message.answered = answered;

@ -65,7 +65,7 @@ import static eu.faircode.email.ServiceAuthenticator.AUTH_TYPE_PASSWORD;
// https://developer.android.com/topic/libraries/architecture/room.html // https://developer.android.com/topic/libraries/architecture/room.html
@Database( @Database(
version = 192, version = 193,
entities = { entities = {
EntityIdentity.class, EntityIdentity.class,
EntityAccount.class, EntityAccount.class,
@ -1974,6 +1974,13 @@ public abstract class DB extends RoomDatabase {
Log.i("DB migration from version " + startVersion + " to " + endVersion); Log.i("DB migration from version " + startVersion + " to " + endVersion);
db.execSQL("ALTER TABLE `folder` ADD COLUMN `modseq` INTEGER"); db.execSQL("ALTER TABLE `folder` ADD COLUMN `modseq` INTEGER");
} }
})
.addMigrations(new Migration(192, 193) {
@Override
public void migrate(@NonNull SupportSQLiteDatabase db) {
Log.i("DB migration from version " + startVersion + " to " + endVersion);
db.execSQL("ALTER TABLE `message` ADD COLUMN `notes_color` INTEGER");
}
}); });
} }

@ -732,8 +732,11 @@ public interface DaoMessage {
" OR NOT (warning IS :warning))") " OR NOT (warning IS :warning))")
int setMessageContent(long id, boolean content, String language, Boolean plain_only, String preview, String warning); int setMessageContent(long id, boolean content, String language, Boolean plain_only, String preview, String warning);
@Query("UPDATE message SET notes = :notes WHERE id = :id AND NOT (notes IS :notes)") @Query("UPDATE message" +
int setMessageNotes(long id, String notes); " SET notes = :notes, notes_color = :color" +
" WHERE id = :id" +
" AND NOT (notes IS :notes AND notes_color IS :color)")
int setMessageNotes(long id, String notes, Integer color);
@Query("UPDATE message" + @Query("UPDATE message" +
" SET size = :size, total = :total" + " SET size = :size, total = :total" +

@ -175,6 +175,7 @@ public class EntityMessage implements Serializable {
public Boolean verified = false; public Boolean verified = false;
public String preview; public String preview;
public String notes; public String notes;
public Integer notes_color;
@NonNull @NonNull
public Boolean signature = true; public Boolean signature = true;
public Long sent; // compose = null public Long sent; // compose = null
@ -534,6 +535,7 @@ public class EntityMessage implements Serializable {
this.verified == other.verified && this.verified == other.verified &&
Objects.equals(this.preview, other.preview) && Objects.equals(this.preview, other.preview) &&
Objects.equals(this.notes, other.notes) && Objects.equals(this.notes, other.notes) &&
Objects.equals(this.notes_color, other.notes_color) &&
this.signature.equals(other.signature) && this.signature.equals(other.signature) &&
Objects.equals(this.sent, other.sent) && Objects.equals(this.sent, other.sent) &&
this.received.equals(other.received) && this.received.equals(other.received) &&

@ -320,10 +320,10 @@ public class FragmentBase extends Fragment {
super.onDetach(); super.onDetach();
try { try {
InputMethodManager im = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE); InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
View focused = getActivity().getCurrentFocus(); View focused = getActivity().getCurrentFocus();
if (focused != null) if (imm != null && focused != null)
im.hideSoftInputFromWindow(focused.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); imm.hideSoftInputFromWindow(focused.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
} catch (Throwable ex) { } catch (Throwable ex) {
Log.w(ex); Log.w(ex);
/* /*

@ -280,7 +280,8 @@ public class FragmentDialogSearch extends FragmentDialogBase {
} }
etQuery.requestFocus(); etQuery.requestFocus();
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); if (imm != null)
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
final AlertDialog dialog = new AlertDialog.Builder(context) final AlertDialog dialog = new AlertDialog.Builder(context)
.setView(dview) .setView(dview)

@ -1,33 +1,60 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" <eu.faircode.email.ScrollViewEx xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:padding="24dp"> android:padding="24dp"
android:scrollbarStyle="outsideOverlay">
<eu.faircode.email.FixedTextView <androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/tvNotes" android:layout_width="match_parent"
android:layout_width="wrap_content" android:layout_height="wrap_content">
android:layout_height="wrap_content"
android:labelFor="@+id/etKeyword"
android:text="@string/title_edit_notes"
android:textAppearance="@style/TextAppearance.AppCompat.Large"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<eu.faircode.email.EditTextPlain <eu.faircode.email.FixedTextView
android:id="@+id/etNotes" android:id="@+id/tvNotes"
android:layout_width="0dp" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="24dp" android:labelFor="@+id/etKeyword"
android:imeOptions="actionDone" android:text="@string/title_edit_notes"
android:inputType="textCapSentences|textMultiLine|textAutoCorrect" android:textAppearance="@style/TextAppearance.AppCompat.Large"
android:text="Notes" app:layout_constraintStart_toStartOf="parent"
android:textAppearance="@style/TextAppearance.AppCompat.Medium" app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvNotes">
<requestFocus /> <eu.faircode.email.EditTextPlain
</eu.faircode.email.EditTextPlain> android:id="@+id/etNotes"
</androidx.constraintlayout.widget.ConstraintLayout> android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:imeOptions="actionDone"
android:inputType="textCapSentences|textMultiLine|textAutoCorrect"
android:text="Notes"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvNotes">
<requestFocus />
</eu.faircode.email.EditTextPlain>
<eu.faircode.email.FixedTextView
android:id="@+id/tvColor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_color"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/etNotes" />
<eu.faircode.email.ViewButtonColor
android:id="@+id/btnColor"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:paddingHorizontal="6dp"
android:text="@string/title_select"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvColor" />
</androidx.constraintlayout.widget.ConstraintLayout>
</eu.faircode.email.ScrollViewEx>
Loading…
Cancel
Save