From 479d6dcf9bafe45e6d4456fa21495713c7ff5ed8 Mon Sep 17 00:00:00 2001 From: tom79 Date: Wed, 6 Nov 2019 14:09:38 +0100 Subject: [PATCH] Allow to change colors --- app/build.gradle | 2 +- .../android/activities/SettingsActivity.java | 10 ++- .../android/client/Entities/Status.java | 74 +++++++++---------- .../android/drawers/StatusListAdapter.java | 7 ++ .../fragments/ColorSettingsFragment.java | 30 ++++++++ .../fragments/ContentSettingsFragment.java | 4 +- app/src/main/res/values/strings.xml | 5 ++ .../main/res/xml/fragment_settings_color.xml | 18 +++++ 8 files changed, 107 insertions(+), 43 deletions(-) create mode 100644 app/src/main/java/app/fedilab/android/fragments/ColorSettingsFragment.java create mode 100644 app/src/main/res/xml/fragment_settings_color.xml diff --git a/app/build.gradle b/app/build.gradle index 7a6adeb8e..f8ef5e336 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -124,5 +124,5 @@ dependencies { implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0' implementation 'com.github.smarteist:autoimageslider:1.3.2' //debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.0-beta-2' - + implementation 'com.jaredrummler:colorpicker:1.1.0' } diff --git a/app/src/main/java/app/fedilab/android/activities/SettingsActivity.java b/app/src/main/java/app/fedilab/android/activities/SettingsActivity.java index 15a77e67b..4fd2874a5 100644 --- a/app/src/main/java/app/fedilab/android/activities/SettingsActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/SettingsActivity.java @@ -36,6 +36,7 @@ import com.google.android.material.tabs.TabLayout; import org.jetbrains.annotations.NotNull; import app.fedilab.android.R; +import app.fedilab.android.fragments.ColorSettingsFragment; import app.fedilab.android.fragments.ContentSettingsFragment; import app.fedilab.android.helper.Helper; @@ -98,6 +99,7 @@ public class SettingsActivity extends BaseActivity { tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.notifications))); tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.settings_category_label_interface))); tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.compose))); + tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.colors))); tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.hide_menu_items))); tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.administration))); tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.languages))); @@ -168,12 +170,14 @@ public class SettingsActivity extends BaseActivity { typeOfSettings = ContentSettingsFragment.type.COMPOSE; break; case 4: + return new ColorSettingsFragment(); + case 5: typeOfSettings = ContentSettingsFragment.type.MENU; break; - case 5: + case 6: typeOfSettings = ContentSettingsFragment.type.ADMIN; break; - case 6: + case 7: typeOfSettings = ContentSettingsFragment.type.LANGUAGE; break; default: @@ -189,7 +193,7 @@ public class SettingsActivity extends BaseActivity { @Override public int getCount() { - return 7; + return 8; } } diff --git a/app/src/main/java/app/fedilab/android/client/Entities/Status.java b/app/src/main/java/app/fedilab/android/client/Entities/Status.java index 83427bb66..f425d94c7 100644 --- a/app/src/main/java/app/fedilab/android/client/Entities/Status.java +++ b/app/src/main/java/app/fedilab/android/client/Entities/Status.java @@ -30,6 +30,7 @@ import android.os.Parcelable; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.core.content.ContextCompat; +import androidx.preference.PreferenceManager; import android.text.Html; import android.text.Spannable; @@ -861,6 +862,19 @@ public class Status implements Parcelable { spannableStringT.removeSpan(span); } + + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); + int l_c = prefs.getInt("theme_link_color", -1); + if( l_c == -1) { + if (theme == THEME_DARK) + l_c = ContextCompat.getColor(context, R.color.dark_link_toot); + else if (theme == THEME_BLACK) + l_c = ContextCompat.getColor(context, R.color.black_link_toot); + else if (theme == THEME_LIGHT) + l_c = ContextCompat.getColor(context, R.color.light_link_toot); + } + final int link_color = l_c; + matcher = Helper.twitterPattern.matcher(spannableStringT); while (matcher.find()) { int matchStart = matcher.start(2); @@ -888,12 +902,7 @@ public class Status implements Parcelable { public void updateDrawState(@NonNull TextPaint ds) { super.updateDrawState(ds); ds.setUnderlineText(false); - if (theme == THEME_DARK) - ds.setColor(ContextCompat.getColor(context, R.color.dark_link_toot)); - else if (theme == THEME_BLACK) - ds.setColor(ContextCompat.getColor(context, R.color.black_link_toot)); - else if (theme == THEME_LIGHT) - ds.setColor(ContextCompat.getColor(context, R.color.light_link_toot)); + ds.setColor(link_color); } }, matchStart, matchEnd, Spanned.SPAN_INCLUSIVE_EXCLUSIVE); } @@ -940,12 +949,7 @@ public class Status implements Parcelable { public void updateDrawState(@NonNull TextPaint ds) { super.updateDrawState(ds); ds.setUnderlineText(false); - if (theme == THEME_DARK) - ds.setColor(ContextCompat.getColor(context, R.color.dark_link_toot)); - else if (theme == THEME_BLACK) - ds.setColor(ContextCompat.getColor(context, R.color.black_link_toot)); - else if (theme == THEME_LIGHT) - ds.setColor(ContextCompat.getColor(context, R.color.light_link_toot)); + ds.setColor(link_color); } }, startPosition, endPosition, @@ -1022,12 +1026,7 @@ public class Status implements Parcelable { public void updateDrawState(@NonNull TextPaint ds) { super.updateDrawState(ds); ds.setUnderlineText(false); - if (theme == THEME_DARK) - ds.setColor(ContextCompat.getColor(context, R.color.dark_link_toot)); - else if (theme == THEME_BLACK) - ds.setColor(ContextCompat.getColor(context, R.color.black_link_toot)); - else if (theme == THEME_LIGHT) - ds.setColor(ContextCompat.getColor(context, R.color.light_link_toot)); + ds.setColor(link_color); } }, startPosition, endPosition, @@ -1059,12 +1058,7 @@ public class Status implements Parcelable { public void updateDrawState(@NonNull TextPaint ds) { super.updateDrawState(ds); ds.setUnderlineText(false); - if (theme == THEME_DARK) - ds.setColor(ContextCompat.getColor(context, R.color.dark_link_toot)); - else if (theme == THEME_BLACK) - ds.setColor(ContextCompat.getColor(context, R.color.black_link_toot)); - else if (theme == THEME_LIGHT) - ds.setColor(ContextCompat.getColor(context, R.color.light_link_toot)); + ds.setColor(link_color); } }, matchStart, matchEnd, Spanned.SPAN_INCLUSIVE_EXCLUSIVE); @@ -1093,12 +1087,7 @@ public class Status implements Parcelable { public void updateDrawState(@NonNull TextPaint ds) { super.updateDrawState(ds); ds.setUnderlineText(false); - if (theme == THEME_DARK) - ds.setColor(ContextCompat.getColor(context, R.color.dark_link_toot)); - else if (theme == THEME_BLACK) - ds.setColor(ContextCompat.getColor(context, R.color.black_link_toot)); - else if (theme == THEME_LIGHT) - ds.setColor(ContextCompat.getColor(context, R.color.light_link_toot)); + ds.setColor(link_color); } }, matchStart, matchEnd, Spanned.SPAN_INCLUSIVE_EXCLUSIVE); @@ -1109,6 +1098,20 @@ public class Status implements Parcelable { public static void transformTranslation(Context context, Status status) { + SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); + int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK); + int l_c = prefs.getInt("theme_link_color", -1); + if( l_c == -1) { + if (theme == THEME_DARK) + l_c = ContextCompat.getColor(context, R.color.dark_link_toot); + else if (theme == THEME_BLACK) + l_c = ContextCompat.getColor(context, R.color.black_link_toot); + else if (theme == THEME_LIGHT) + l_c = ContextCompat.getColor(context, R.color.light_link_toot); + } + final int link_color = l_c; + if (((Activity) context).isFinishing() || status == null) return; if ((status.getReblog() != null && status.getReblog().getContent() == null) || (status.getReblog() == null && status.getContent() == null)) @@ -1128,8 +1131,8 @@ public class Status implements Parcelable { } SpannableString contentSpanTranslated = status.getContentSpanTranslated(); Matcher matcherALink = Patterns.WEB_URL.matcher(contentSpanTranslated.toString()); - SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); - int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK); + + while (matcherALink.find()) { int matchStart = matcherALink.start(); int matchEnd = matcherALink.end(); @@ -1148,12 +1151,7 @@ public class Status implements Parcelable { public void updateDrawState(@NonNull TextPaint ds) { super.updateDrawState(ds); ds.setUnderlineText(false); - if (theme == THEME_DARK) - ds.setColor(ContextCompat.getColor(context, R.color.dark_link_toot)); - else if (theme == THEME_BLACK) - ds.setColor(ContextCompat.getColor(context, R.color.black_link_toot)); - else if (theme == THEME_LIGHT) - ds.setColor(ContextCompat.getColor(context, R.color.light_link_toot)); + ds.setColor(link_color); } }, matchStart, matchEnd, diff --git a/app/src/main/java/app/fedilab/android/drawers/StatusListAdapter.java b/app/src/main/java/app/fedilab/android/drawers/StatusListAdapter.java index 58ea1bce8..156b571cb 100644 --- a/app/src/main/java/app/fedilab/android/drawers/StatusListAdapter.java +++ b/app/src/main/java/app/fedilab/android/drawers/StatusListAdapter.java @@ -41,6 +41,7 @@ import androidx.constraintlayout.widget.ConstraintLayout; import androidx.core.content.ContextCompat; import androidx.appcompat.app.AlertDialog; import androidx.appcompat.widget.PopupMenu; +import androidx.preference.PreferenceManager; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; @@ -56,6 +57,7 @@ import android.text.method.LinkMovementMethod; import android.text.style.ClickableSpan; import android.text.style.ForegroundColorSpan; import android.text.style.URLSpan; +import android.util.Log; import android.util.TypedValue; import android.view.LayoutInflater; import android.view.MenuItem; @@ -2106,6 +2108,11 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct holder.status_boosted_by_info.setVisibility(View.GONE); } } + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); + int reblogColor = prefs.getInt("theme_boost_header_color", -1); + if( reblogColor != -1 ){ + holder.status_boosted_by_info.setBackgroundColor(reblogColor); + } if (type == RetrieveFeedsAsyncTask.Type.CONVERSATION && status.getConversationProfilePicture() != null) { holder.status_account_profile.setVisibility(View.GONE); holder.conversation_pp.setVisibility(View.VISIBLE); diff --git a/app/src/main/java/app/fedilab/android/fragments/ColorSettingsFragment.java b/app/src/main/java/app/fedilab/android/fragments/ColorSettingsFragment.java new file mode 100644 index 000000000..ac63a224e --- /dev/null +++ b/app/src/main/java/app/fedilab/android/fragments/ColorSettingsFragment.java @@ -0,0 +1,30 @@ +package app.fedilab.android.fragments; + +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import androidx.annotation.Nullable; +import androidx.preference.PreferenceFragmentCompat; + +import org.jetbrains.annotations.NotNull; + +import app.fedilab.android.R; + +public class ColorSettingsFragment extends PreferenceFragmentCompat { + @Override + public void onCreatePreferences(Bundle bundle, String s) { + // Load the Preferences from the XML file + addPreferencesFromResource(R.xml.fragment_settings_color); + } + + + @Override + public void onViewCreated(@NotNull View view, @Nullable Bundle savedInstanceState) + { + super.onViewCreated(view, savedInstanceState); + + + } +} \ No newline at end of file diff --git a/app/src/main/java/app/fedilab/android/fragments/ContentSettingsFragment.java b/app/src/main/java/app/fedilab/android/fragments/ContentSettingsFragment.java index e7151decf..959db1f91 100644 --- a/app/src/main/java/app/fedilab/android/fragments/ContentSettingsFragment.java +++ b/app/src/main/java/app/fedilab/android/fragments/ContentSettingsFragment.java @@ -119,6 +119,7 @@ import static app.fedilab.android.activities.BaseMainActivity.iconLauncher.FEDIV import static app.fedilab.android.activities.BaseMainActivity.iconLauncher.HERO; import static app.fedilab.android.activities.BaseMainActivity.iconLauncher.MASTALAB; import static app.fedilab.android.fragments.ContentSettingsFragment.type.ADMIN; +import static app.fedilab.android.fragments.ContentSettingsFragment.type.COLORS; import static app.fedilab.android.fragments.ContentSettingsFragment.type.COMPOSE; import static app.fedilab.android.fragments.ContentSettingsFragment.type.INTERFACE; import static app.fedilab.android.fragments.ContentSettingsFragment.type.LANGUAGE; @@ -177,7 +178,8 @@ public class ContentSettingsFragment extends Fragment implements OnRetrieveRemot INTERFACE, COMPOSE, LANGUAGE, - MENU + MENU, + COLORS } private List translators = new ArrayList<>(); private AccountSearchDevAdapter translatorManager; diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 27cfdb61d..7fb2b0870 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1247,4 +1247,9 @@ Title for the video Join Peertube I am at least 16 years old and agree to the %1$s of this instance + Colors + Links + Change the color of links (URLs, mentions, tags, etc.) in messages + Reblogs header + Change the color of the header for reblogs \ No newline at end of file diff --git a/app/src/main/res/xml/fragment_settings_color.xml b/app/src/main/res/xml/fragment_settings_color.xml new file mode 100644 index 000000000..22e74096b --- /dev/null +++ b/app/src/main/res/xml/fragment_settings_color.xml @@ -0,0 +1,18 @@ + + + + + + + \ No newline at end of file