mirror of
https://github.com/M66B/FairEmail.git
synced 2026-04-09 02:23:38 +02:00
Added Gmail label colors
This commit is contained in:
@@ -1306,10 +1306,9 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
||||
|
||||
tvFolder.setVisibility(compact && viewType != ViewType.THREAD ? View.GONE : View.VISIBLE);
|
||||
|
||||
tvLabels.setText(message.labels == null ? null : TextUtils.join(", ", message.labels));
|
||||
tvLabels.setVisibility(
|
||||
labels_header && message.labels != null && message.labels.length > 0
|
||||
? View.VISIBLE : View.GONE);
|
||||
Spanned labels = getLabels(message);
|
||||
tvLabels.setText(labels);
|
||||
tvLabels.setVisibility(labels == null ? View.GONE : View.VISIBLE);
|
||||
|
||||
boolean selected = properties.getValue("selected", message.id);
|
||||
if (viewType == ViewType.THREAD || (!threading && !selected)) {
|
||||
@@ -5631,6 +5630,33 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
||||
fragmentTransaction.commit();
|
||||
}
|
||||
|
||||
private Spanned getLabels(TupleMessageEx message) {
|
||||
if (!labels_header)
|
||||
return null;
|
||||
if (message.labels == null || message.labels.length == 0)
|
||||
return null;
|
||||
|
||||
SpannableStringBuilder ssb = new SpannableStringBuilderEx();
|
||||
for (int i = 0; i < message.labels.length; i++) {
|
||||
if (ssb.length() > 0)
|
||||
ssb.append(' ');
|
||||
|
||||
String label = message.labels[i];
|
||||
ssb.append(label);
|
||||
|
||||
if (message.label_colors == null)
|
||||
continue;
|
||||
if (i >= message.label_colors.length)
|
||||
continue;
|
||||
|
||||
int len = ssb.length();
|
||||
ssb.setSpan(new ForegroundColorSpan(message.label_colors[i]),
|
||||
len - label.length(), len, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
}
|
||||
|
||||
return ssb;
|
||||
}
|
||||
|
||||
private SpannableStringBuilder getKeywords(TupleMessageEx message) {
|
||||
SpannableStringBuilder ssb = new SpannableStringBuilderEx();
|
||||
|
||||
@@ -6552,6 +6578,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
||||
if (message != null) {
|
||||
keyPosition.put(message.id, i);
|
||||
positionKey.put(i, message.id);
|
||||
message.resolveLabelColors(context);
|
||||
message.resolveKeywordColors(context);
|
||||
}
|
||||
}
|
||||
@@ -6708,6 +6735,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
||||
keyPosition.put(message.id, position);
|
||||
positionKey.put(position, message.id);
|
||||
|
||||
message.resolveLabelColors(context);
|
||||
message.resolveKeywordColors(context);
|
||||
|
||||
if (viewType == ViewType.THREAD && cards && threading && indentation) {
|
||||
|
||||
@@ -1978,7 +1978,7 @@ class Core {
|
||||
boolean drafts = false;
|
||||
Map<String, EntityFolder> local = new HashMap<>();
|
||||
List<EntityFolder> folders = db.folder().getFolders(account.id, false, false);
|
||||
for (EntityFolder folder : folders)
|
||||
for (EntityFolder folder : folders) {
|
||||
if (folder.tbc != null) {
|
||||
try {
|
||||
Log.i(folder.name + " creating");
|
||||
@@ -2053,6 +2053,13 @@ class Core {
|
||||
sync_folders = true;
|
||||
}
|
||||
}
|
||||
|
||||
String key = "label.color." + folder.name;
|
||||
if (folder.color == null)
|
||||
prefs.edit().remove(key).apply();
|
||||
else
|
||||
prefs.edit().putInt(key, folder.color).apply();
|
||||
}
|
||||
Log.i("Local folder count=" + local.size() + " drafts=" + drafts);
|
||||
|
||||
if (!drafts) {
|
||||
|
||||
@@ -21,6 +21,7 @@ package eu.faircode.email;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.database.sqlite.SQLiteConstraintException;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
@@ -44,6 +45,7 @@ import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.constraintlayout.widget.Group;
|
||||
import androidx.lifecycle.Lifecycle;
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
|
||||
@@ -658,8 +660,19 @@ public class FragmentFolder extends FragmentBase {
|
||||
ask.setArguments(aargs);
|
||||
ask.setTargetFragment(FragmentFolder.this, REQUEST_SAVE_CHANGES);
|
||||
ask.show(getParentFragmentManager(), "folder:save");
|
||||
} else if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED))
|
||||
} else if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED)) {
|
||||
String name = args.getString("name");
|
||||
Integer color = args.getInt("color");
|
||||
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||
String key = "label.color." + name;
|
||||
if (color == Color.TRANSPARENT)
|
||||
prefs.edit().remove(key).apply();
|
||||
else
|
||||
prefs.edit().putInt(key, color).apply();
|
||||
|
||||
getParentFragmentManager().popBackStack();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -68,6 +68,9 @@ public class TupleMessageEx extends EntityMessage {
|
||||
@Ignore
|
||||
boolean duplicate;
|
||||
|
||||
@Ignore
|
||||
public Integer[] label_colors;
|
||||
|
||||
@Ignore
|
||||
public Integer[] keyword_colors;
|
||||
@Ignore
|
||||
@@ -79,6 +82,22 @@ public class TupleMessageEx extends EntityMessage {
|
||||
: folderDisplay);
|
||||
}
|
||||
|
||||
void resolveLabelColors(Context context) {
|
||||
List<Integer> color = new ArrayList<>();
|
||||
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
if (this.labels != null)
|
||||
for (int i = 0; i < this.labels.length; i++) {
|
||||
String key = "label.color." + this.labels[i];
|
||||
if (prefs.contains(key))
|
||||
color.add(prefs.getInt(key, Color.GRAY));
|
||||
else
|
||||
color.add(null);
|
||||
}
|
||||
|
||||
this.label_colors = color.toArray(new Integer[0]);
|
||||
}
|
||||
|
||||
void resolveKeywordColors(Context context) {
|
||||
List<Integer> color = new ArrayList<>();
|
||||
List<String> titles = new ArrayList<>();
|
||||
|
||||
Reference in New Issue
Block a user