From 2dcd3c765f02b44d562ba6056408c908e28a527e Mon Sep 17 00:00:00 2001 From: Grishka Date: Thu, 17 Feb 2022 21:06:18 +0300 Subject: [PATCH] Dark theme WIP --- mastodon/src/main/AndroidManifest.xml | 2 +- .../fragments/BaseStatusListFragment.java | 8 +-- .../android/fragments/HomeFragment.java | 6 +- .../fragments/HomeTimelineFragment.java | 14 +--- .../android/ui/text/LinkSpan.java | 8 +-- .../src/main/res/color/compose_button.xml | 4 +- .../bg_button_primary_light_on_dark.xml | 2 +- .../src/main/res/drawable/bg_tab_profile.xml | 2 +- .../main/res/layout/compose_poll_option.xml | 2 + .../main/res/layout/display_item_header.xml | 1 + .../res/layout/display_item_poll_option.xml | 1 + .../src/main/res/layout/fragment_compose.xml | 1 + mastodon/src/main/res/layout/tab_bar.xml | 5 +- mastodon/src/main/res/values-night/styles.xml | 4 ++ mastodon/src/main/res/values/colors.xml | 3 +- mastodon/src/main/res/values/styles.xml | 64 +++++++++++++++++-- 16 files changed, 90 insertions(+), 37 deletions(-) create mode 100644 mastodon/src/main/res/values-night/styles.xml diff --git a/mastodon/src/main/AndroidManifest.xml b/mastodon/src/main/AndroidManifest.xml index ad647361..d6ef7361 100644 --- a/mastodon/src/main/AndroidManifest.xml +++ b/mastodon/src/main/AndroidManifest.xml @@ -9,7 +9,7 @@ android:allowBackup="true" android:label="@string/app_name" android:supportsRtl="true" - android:theme="@style/Theme.Mastodon" + android:theme="@style/Theme.Mastodon.AutoLightDark" android:largeHeap="true"> diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/BaseStatusListFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/BaseStatusListFragment.java index a86d0f4e..f95ba5fa 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/BaseStatusListFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/BaseStatusListFragment.java @@ -2,6 +2,7 @@ package org.joinmastodon.android.fragments; import android.app.Activity; import android.content.res.Configuration; +import android.content.res.TypedArray; import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.Rect; @@ -9,11 +10,9 @@ import android.graphics.drawable.Drawable; import android.os.Build; import android.os.Bundle; import android.text.TextUtils; -import android.util.Log; import android.view.View; import android.view.ViewGroup; import android.view.ViewTreeObserver; -import android.widget.ImageView; import android.widget.Toolbar; import org.joinmastodon.android.R; @@ -26,19 +25,18 @@ import org.joinmastodon.android.ui.BetterItemAnimator; import org.joinmastodon.android.ui.displayitems.FooterStatusDisplayItem; import org.joinmastodon.android.ui.displayitems.HeaderStatusDisplayItem; import org.joinmastodon.android.ui.displayitems.ImageStatusDisplayItem; -import org.joinmastodon.android.ui.displayitems.PhotoStatusDisplayItem; import org.joinmastodon.android.ui.displayitems.PollFooterStatusDisplayItem; import org.joinmastodon.android.ui.displayitems.PollOptionStatusDisplayItem; import org.joinmastodon.android.ui.displayitems.StatusDisplayItem; import org.joinmastodon.android.ui.displayitems.TextStatusDisplayItem; import org.joinmastodon.android.ui.photoviewer.PhotoViewer; import org.joinmastodon.android.ui.photoviewer.PhotoViewerHost; +import org.joinmastodon.android.ui.utils.UiUtils; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; -import java.util.Objects; import java.util.stream.Collectors; import androidx.annotation.NonNull; @@ -249,7 +247,7 @@ public abstract class BaseStatusListFragment exten list.addItemDecoration(new RecyclerView.ItemDecoration(){ private Paint paint=new Paint(); { - paint.setColor(0xFFD0D5DD); + paint.setColor(UiUtils.getThemeColor(getActivity(), R.attr.colorPollVoted)); paint.setStyle(Paint.Style.STROKE); paint.setStrokeWidth(V.dp(1)); } diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeFragment.java index e0e3ade9..b18d5279 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeFragment.java @@ -1,6 +1,7 @@ package org.joinmastodon.android.fragments; import android.app.Fragment; +import android.content.res.Configuration; import android.graphics.Outline; import android.os.Build; import android.os.Bundle; @@ -13,6 +14,7 @@ import android.widget.FrameLayout; import android.widget.ImageView; import android.widget.LinearLayout; +import org.joinmastodon.android.MastodonApp; import org.joinmastodon.android.R; import org.joinmastodon.android.api.session.AccountSessionManager; import org.joinmastodon.android.model.Account; @@ -117,12 +119,12 @@ public class HomeFragment extends AppKitFragment implements OnBackPressedListene @Override public boolean wantsLightStatusBar(){ - return currentTab!=R.id.tab_profile; + return currentTab!=R.id.tab_profile && (MastodonApp.context.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK)!=Configuration.UI_MODE_NIGHT_YES; } @Override public boolean wantsLightNavigationBar(){ - return true; + return (MastodonApp.context.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK)!=Configuration.UI_MODE_NIGHT_YES; } @Override diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeTimelineFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeTimelineFragment.java index f554c5e5..8ae782e2 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeTimelineFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeTimelineFragment.java @@ -1,6 +1,7 @@ package org.joinmastodon.android.fragments; import android.app.Activity; +import android.content.res.ColorStateList; import android.content.res.Configuration; import android.os.Bundle; import android.view.Gravity; @@ -21,6 +22,7 @@ import org.joinmastodon.android.api.requests.timelines.GetHomeTimeline; import org.joinmastodon.android.api.session.AccountSessionManager; import org.joinmastodon.android.events.StatusCreatedEvent; import org.joinmastodon.android.model.Status; +import org.joinmastodon.android.ui.utils.UiUtils; import org.parceler.Parcels; import java.util.Collections; @@ -70,17 +72,6 @@ public class HomeTimelineFragment extends StatusListFragment{ @Override public boolean onOptionsItemSelected(MenuItem item){ -// Bundle args=new Bundle(); -// args.putString("account", accountID); -// int id=item.getItemId(); -// if(id==R.id.new_toot){ -// Nav.go(getActivity(), ComposeFragment.class, args); -// }else if(id==R.id.notifications){ -// Nav.go(getActivity(), NotificationsFragment.class, args); -// }else if(id==R.id.my_profile){ -// args.putParcelable("profileAccount", Parcels.wrap(AccountSessionManager.getInstance().getAccount(accountID).self)); -// Nav.go(getActivity(), ProfileFragment.class, args); -// } return true; } @@ -112,6 +103,7 @@ public class HomeTimelineFragment extends StatusListFragment{ ImageView logo=new ImageView(getActivity()); logo.setScaleType(ImageView.ScaleType.CENTER); logo.setImageResource(R.drawable.logo); + logo.setImageTintList(ColorStateList.valueOf(UiUtils.getThemeColor(getActivity(), android.R.attr.textColorPrimary))); Toolbar toolbar=getToolbar(); toolbar.addView(logo, new Toolbar.LayoutParams(Gravity.CENTER)); } diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/text/LinkSpan.java b/mastodon/src/main/java/org/joinmastodon/android/ui/text/LinkSpan.java index e0ff34ff..efd9aabf 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/text/LinkSpan.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/text/LinkSpan.java @@ -9,7 +9,7 @@ import org.joinmastodon.android.ui.utils.UiUtils; public class LinkSpan extends CharacterStyle { - private int color=0xFF569ace; + private int color=0xFF00FF00; private OnLinkClickListener listener; private String link; private Type type; @@ -22,17 +22,13 @@ public class LinkSpan extends CharacterStyle { this.accountID=accountID; } - public void setColor(int c){ - color=c; - } - public int getColor(){ return color; } @Override public void updateDrawState(TextPaint tp) { - tp.setColor(color); + tp.setColor(color=tp.linkColor); } public void onClick(Context context){ diff --git a/mastodon/src/main/res/color/compose_button.xml b/mastodon/src/main/res/color/compose_button.xml index 89a4604b..07ea752b 100644 --- a/mastodon/src/main/res/color/compose_button.xml +++ b/mastodon/src/main/res/color/compose_button.xml @@ -1,5 +1,5 @@ - - + + \ No newline at end of file diff --git a/mastodon/src/main/res/drawable/bg_button_primary_light_on_dark.xml b/mastodon/src/main/res/drawable/bg_button_primary_light_on_dark.xml index 337068d2..d5622755 100644 --- a/mastodon/src/main/res/drawable/bg_button_primary_light_on_dark.xml +++ b/mastodon/src/main/res/drawable/bg_button_primary_light_on_dark.xml @@ -4,7 +4,7 @@ - + diff --git a/mastodon/src/main/res/drawable/bg_tab_profile.xml b/mastodon/src/main/res/drawable/bg_tab_profile.xml index 4c026d0d..ba59849c 100644 --- a/mastodon/src/main/res/drawable/bg_tab_profile.xml +++ b/mastodon/src/main/res/drawable/bg_tab_profile.xml @@ -4,7 +4,7 @@ - + diff --git a/mastodon/src/main/res/layout/compose_poll_option.xml b/mastodon/src/main/res/layout/compose_poll_option.xml index f7dc468f..d806da36 100644 --- a/mastodon/src/main/res/layout/compose_poll_option.xml +++ b/mastodon/src/main/res/layout/compose_poll_option.xml @@ -18,6 +18,7 @@ android:layout_width="24dp" android:layout_height="24dp" android:layout_margin="16dp" + android:tint="?colorDarkIcon" android:src="@drawable/ic_fluent_circle_24_regular"/> \ No newline at end of file diff --git a/mastodon/src/main/res/layout/display_item_header.xml b/mastodon/src/main/res/layout/display_item_header.xml index ff67f352..69f3ca56 100644 --- a/mastodon/src/main/res/layout/display_item_header.xml +++ b/mastodon/src/main/res/layout/display_item_header.xml @@ -15,6 +15,7 @@ android:layout_alignParentEnd="true" android:background="?android:selectableItemBackgroundBorderless" android:scaleType="center" + android:tint="?android:textColorSecondary" android:src="@drawable/ic_post_more" /> @@ -20,6 +20,7 @@ android:layout_height="52dp" android:scaleType="center" android:background="?android:selectableItemBackgroundBorderless" + android:tint="?android:colorPrimary" android:src="@drawable/ic_fluent_home_28_selector"/> + + + + + + + + +