Dark theme WIP

This commit is contained in:
Grishka 2022-02-17 21:06:18 +03:00
parent 6f74315b7f
commit 2dcd3c765f
16 changed files with 90 additions and 37 deletions

View File

@ -9,7 +9,7 @@
android:allowBackup="true" android:allowBackup="true"
android:label="@string/app_name" android:label="@string/app_name"
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/Theme.Mastodon" android:theme="@style/Theme.Mastodon.AutoLightDark"
android:largeHeap="true"> android:largeHeap="true">
<activity android:name=".MainActivity" android:exported="true" android:configChanges="orientation|screenSize" android:windowSoftInputMode="adjustResize"> <activity android:name=".MainActivity" android:exported="true" android:configChanges="orientation|screenSize" android:windowSoftInputMode="adjustResize">

View File

@ -2,6 +2,7 @@ package org.joinmastodon.android.fragments;
import android.app.Activity; import android.app.Activity;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.content.res.TypedArray;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Paint; import android.graphics.Paint;
import android.graphics.Rect; import android.graphics.Rect;
@ -9,11 +10,9 @@ import android.graphics.drawable.Drawable;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.ViewTreeObserver; import android.view.ViewTreeObserver;
import android.widget.ImageView;
import android.widget.Toolbar; import android.widget.Toolbar;
import org.joinmastodon.android.R; 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.FooterStatusDisplayItem;
import org.joinmastodon.android.ui.displayitems.HeaderStatusDisplayItem; import org.joinmastodon.android.ui.displayitems.HeaderStatusDisplayItem;
import org.joinmastodon.android.ui.displayitems.ImageStatusDisplayItem; 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.PollFooterStatusDisplayItem;
import org.joinmastodon.android.ui.displayitems.PollOptionStatusDisplayItem; import org.joinmastodon.android.ui.displayitems.PollOptionStatusDisplayItem;
import org.joinmastodon.android.ui.displayitems.StatusDisplayItem; import org.joinmastodon.android.ui.displayitems.StatusDisplayItem;
import org.joinmastodon.android.ui.displayitems.TextStatusDisplayItem; import org.joinmastodon.android.ui.displayitems.TextStatusDisplayItem;
import org.joinmastodon.android.ui.photoviewer.PhotoViewer; import org.joinmastodon.android.ui.photoviewer.PhotoViewer;
import org.joinmastodon.android.ui.photoviewer.PhotoViewerHost; import org.joinmastodon.android.ui.photoviewer.PhotoViewerHost;
import org.joinmastodon.android.ui.utils.UiUtils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
@ -249,7 +247,7 @@ public abstract class BaseStatusListFragment<T extends DisplayItemsParent> exten
list.addItemDecoration(new RecyclerView.ItemDecoration(){ list.addItemDecoration(new RecyclerView.ItemDecoration(){
private Paint paint=new Paint(); private Paint paint=new Paint();
{ {
paint.setColor(0xFFD0D5DD); paint.setColor(UiUtils.getThemeColor(getActivity(), R.attr.colorPollVoted));
paint.setStyle(Paint.Style.STROKE); paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(V.dp(1)); paint.setStrokeWidth(V.dp(1));
} }

View File

@ -1,6 +1,7 @@
package org.joinmastodon.android.fragments; package org.joinmastodon.android.fragments;
import android.app.Fragment; import android.app.Fragment;
import android.content.res.Configuration;
import android.graphics.Outline; import android.graphics.Outline;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
@ -13,6 +14,7 @@ import android.widget.FrameLayout;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import org.joinmastodon.android.MastodonApp;
import org.joinmastodon.android.R; import org.joinmastodon.android.R;
import org.joinmastodon.android.api.session.AccountSessionManager; import org.joinmastodon.android.api.session.AccountSessionManager;
import org.joinmastodon.android.model.Account; import org.joinmastodon.android.model.Account;
@ -117,12 +119,12 @@ public class HomeFragment extends AppKitFragment implements OnBackPressedListene
@Override @Override
public boolean wantsLightStatusBar(){ 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 @Override
public boolean wantsLightNavigationBar(){ public boolean wantsLightNavigationBar(){
return true; return (MastodonApp.context.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK)!=Configuration.UI_MODE_NIGHT_YES;
} }
@Override @Override

View File

@ -1,6 +1,7 @@
package org.joinmastodon.android.fragments; package org.joinmastodon.android.fragments;
import android.app.Activity; import android.app.Activity;
import android.content.res.ColorStateList;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.os.Bundle; import android.os.Bundle;
import android.view.Gravity; 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.api.session.AccountSessionManager;
import org.joinmastodon.android.events.StatusCreatedEvent; import org.joinmastodon.android.events.StatusCreatedEvent;
import org.joinmastodon.android.model.Status; import org.joinmastodon.android.model.Status;
import org.joinmastodon.android.ui.utils.UiUtils;
import org.parceler.Parcels; import org.parceler.Parcels;
import java.util.Collections; import java.util.Collections;
@ -70,17 +72,6 @@ public class HomeTimelineFragment extends StatusListFragment{
@Override @Override
public boolean onOptionsItemSelected(MenuItem item){ 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; return true;
} }
@ -112,6 +103,7 @@ public class HomeTimelineFragment extends StatusListFragment{
ImageView logo=new ImageView(getActivity()); ImageView logo=new ImageView(getActivity());
logo.setScaleType(ImageView.ScaleType.CENTER); logo.setScaleType(ImageView.ScaleType.CENTER);
logo.setImageResource(R.drawable.logo); logo.setImageResource(R.drawable.logo);
logo.setImageTintList(ColorStateList.valueOf(UiUtils.getThemeColor(getActivity(), android.R.attr.textColorPrimary)));
Toolbar toolbar=getToolbar(); Toolbar toolbar=getToolbar();
toolbar.addView(logo, new Toolbar.LayoutParams(Gravity.CENTER)); toolbar.addView(logo, new Toolbar.LayoutParams(Gravity.CENTER));
} }

View File

@ -9,7 +9,7 @@ import org.joinmastodon.android.ui.utils.UiUtils;
public class LinkSpan extends CharacterStyle { public class LinkSpan extends CharacterStyle {
private int color=0xFF569ace; private int color=0xFF00FF00;
private OnLinkClickListener listener; private OnLinkClickListener listener;
private String link; private String link;
private Type type; private Type type;
@ -22,17 +22,13 @@ public class LinkSpan extends CharacterStyle {
this.accountID=accountID; this.accountID=accountID;
} }
public void setColor(int c){
color=c;
}
public int getColor(){ public int getColor(){
return color; return color;
} }
@Override @Override
public void updateDrawState(TextPaint tp) { public void updateDrawState(TextPaint tp) {
tp.setColor(color); tp.setColor(color=tp.linkColor);
} }
public void onClick(Context context){ public void onClick(Context context){

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/gray_800" android:alpha="0.3" android:state_enabled="false"/> <item android:color="?android:textColorPrimary" android:alpha="0.3" android:state_enabled="false"/>
<item android:color="@color/gray_800"/> <item android:color="?android:textColorPrimary"/>
</selector> </selector>

View File

@ -4,7 +4,7 @@
<ripple android:color="@color/highlight_over_dark"> <ripple android:color="@color/highlight_over_dark">
<item> <item>
<shape> <shape>
<solid android:color="@color/button_bg_primary_dark_on_light"/> <solid android:color="@color/button_bg_primary_light_on_dark"/>
<corners android:radius="10dp"/> <corners android:radius="10dp"/>
</shape> </shape>
</item> </item>

View File

@ -4,7 +4,7 @@
<layer-list> <layer-list>
<item android:gravity="center" android:width="29dp" android:height="29dp"> <item android:gravity="center" android:width="29dp" android:height="29dp">
<shape android:shape="oval"> <shape android:shape="oval">
<stroke android:color="@color/gray_800" android:width="2dp"/> <stroke android:color="?android:colorPrimary" android:width="2dp"/>
</shape> </shape>
</item> </item>
</layer-list> </layer-list>

View File

@ -18,6 +18,7 @@
android:layout_width="24dp" android:layout_width="24dp"
android:layout_height="24dp" android:layout_height="24dp"
android:layout_margin="16dp" android:layout_margin="16dp"
android:tint="?colorDarkIcon"
android:src="@drawable/ic_fluent_circle_24_regular"/> android:src="@drawable/ic_fluent_circle_24_regular"/>
<EditText <EditText
android:id="@+id/edit" android:id="@+id/edit"
@ -38,6 +39,7 @@
android:layout_width="56dp" android:layout_width="56dp"
android:layout_height="56dp" android:layout_height="56dp"
android:scaleType="center" android:scaleType="center"
android:tint="?colorDarkIcon"
android:src="@drawable/ic_fluent_re_order_dots_vertical_24_regular"/> android:src="@drawable/ic_fluent_re_order_dots_vertical_24_regular"/>
</LinearLayout> </LinearLayout>

View File

@ -15,6 +15,7 @@
android:layout_alignParentEnd="true" android:layout_alignParentEnd="true"
android:background="?android:selectableItemBackgroundBorderless" android:background="?android:selectableItemBackgroundBorderless"
android:scaleType="center" android:scaleType="center"
android:tint="?android:textColorSecondary"
android:src="@drawable/ic_post_more" /> android:src="@drawable/ic_post_more" />
<ImageView <ImageView

View File

@ -26,6 +26,7 @@
android:layout_marginStart="12dp" android:layout_marginStart="12dp"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
android:duplicateParentState="true" android:duplicateParentState="true"
android:tint="?colorDarkIcon"
android:src="@drawable/ic_poll_option_button"/> android:src="@drawable/ic_poll_option_button"/>
<TextView <TextView

View File

@ -107,6 +107,7 @@
android:layout_width="24dp" android:layout_width="24dp"
android:layout_height="24dp" android:layout_height="24dp"
android:layout_margin="16dp" android:layout_margin="16dp"
android:tint="?colorDarkIcon"
android:src="@drawable/ic_fluent_add_circle_24_regular"/> android:src="@drawable/ic_fluent_add_circle_24_regular"/>
</LinearLayout> </LinearLayout>
<TextView <TextView

View File

@ -3,7 +3,7 @@
android:id="@+id/tabbar_wrap" android:id="@+id/tabbar_wrap"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="@color/actionbar_bg" android:background="?android:statusBarColor"
android:elevation="3dp" android:elevation="3dp"
android:outlineProvider="bounds" android:outlineProvider="bounds"
android:clipChildren="false"> android:clipChildren="false">
@ -20,6 +20,7 @@
android:layout_height="52dp" android:layout_height="52dp"
android:scaleType="center" android:scaleType="center"
android:background="?android:selectableItemBackgroundBorderless" android:background="?android:selectableItemBackgroundBorderless"
android:tint="?android:colorPrimary"
android:src="@drawable/ic_fluent_home_28_selector"/> android:src="@drawable/ic_fluent_home_28_selector"/>
<Space <Space
@ -33,6 +34,7 @@
android:layout_height="52dp" android:layout_height="52dp"
android:scaleType="center" android:scaleType="center"
android:background="?android:selectableItemBackgroundBorderless" android:background="?android:selectableItemBackgroundBorderless"
android:tint="?android:colorPrimary"
android:src="@drawable/ic_fluent_search_28_selector"/> android:src="@drawable/ic_fluent_search_28_selector"/>
<Space <Space
@ -46,6 +48,7 @@
android:layout_height="52dp" android:layout_height="52dp"
android:scaleType="center" android:scaleType="center"
android:background="?android:selectableItemBackgroundBorderless" android:background="?android:selectableItemBackgroundBorderless"
android:tint="?android:colorPrimary"
android:src="@drawable/ic_fluent_alert_28_selector"/> android:src="@drawable/ic_fluent_alert_28_selector"/>
<Space <Space

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.Mastodon.AutoLightDark" parent="Theme.Mastodon.Dark"/>
</resources>

View File

@ -3,7 +3,7 @@
<color name="black">#FF000000</color> <color name="black">#FF000000</color>
<color name="white">#FFFFFFFF</color> <color name="white">#FFFFFFFF</color>
<color name="fluent_default_icon_tint">@color/gray_800</color> <color name="fluent_default_icon_tint">?android:textColorPrimary</color>
<color name="gray_25">#FCFCFD</color> <color name="gray_25">#FCFCFD</color>
<color name="gray_50t">#CCF9FAFB</color> <color name="gray_50t">#CCF9FAFB</color>
@ -88,6 +88,7 @@
<color name="fab_icon">#282C37</color> <color name="fab_icon">#282C37</color>
<color name="actionbar_bg">#FAFBFC</color> <color name="actionbar_bg">#FAFBFC</color>
<color name="actionbar_bg_dark">#4C4F58</color>
<color name="navigation_bar_bg">#282C37</color> <color name="navigation_bar_bg">#282C37</color>
<color name="highlight_over_dark">#80FFFFFF</color> <color name="highlight_over_dark">#80FFFFFF</color>

View File

@ -1,14 +1,12 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools"> <resources xmlns:tools="http://schemas.android.com/tools">
<style name="Theme.Mastodon" parent="Theme.AppKit.Light"> <style name="Theme.Mastodon.Light" parent="Theme.AppKit.Light">
<!-- needed to disable scrim on API 29+ --> <!-- needed to disable scrim on API 29+ -->
<item name="android:enforceNavigationBarContrast" tools:ignore="NewApi">false</item> <item name="android:enforceNavigationBarContrast" tools:ignore="NewApi">false</item>
<item name="android:enforceStatusBarContrast" tools:ignore="NewApi">false</item> <item name="android:enforceStatusBarContrast" tools:ignore="NewApi">false</item>
<item name="appkitBackDrawable">@drawable/ic_fluent_arrow_left_24_regular</item> <item name="appkitBackDrawable">@drawable/ic_fluent_arrow_left_24_regular</item>
<item name="android:splitMotionEvents">false</item> <item name="android:splitMotionEvents">false</item>
<!-- below depends on light/dark theme -->
<item name="android:buttonStyle">@style/Widget.Mastodon.Button.Primary_DarkOnLight</item> <item name="android:buttonStyle">@style/Widget.Mastodon.Button.Primary_DarkOnLight</item>
<item name="secondaryButtonStyle">@style/Widget.Mastodon.Button.Secondary_DarkOnLight</item> <item name="secondaryButtonStyle">@style/Widget.Mastodon.Button.Secondary_DarkOnLight</item>
<item name="android:colorAccent">@color/primary_700</item> <item name="android:colorAccent">@color/primary_700</item>
@ -24,25 +22,65 @@
<item name="android:windowBackground">@color/white</item> <item name="android:windowBackground">@color/white</item>
<item name="android:statusBarColor">@color/actionbar_bg</item> <item name="android:statusBarColor">@color/actionbar_bg</item>
<item name="android:navigationBarColor">@color/navigation_bar_bg</item> <item name="android:navigationBarColor">@color/navigation_bar_bg</item>
<item name="android:windowLightStatusBar">true</item>
<item name="android:windowLightNavigationBar" tools:ignore="NewApi">true</item>
<item name="android:actionBarTheme">@style/Theme.Mastodon.Toolbar</item> <item name="android:actionBarTheme">@style/Theme.Mastodon.Toolbar</item>
<item name="android:alertDialogTheme">@style/Theme.Mastodon.Dialog.Alert</item> <item name="android:alertDialogTheme">@style/Theme.Mastodon.Dialog.Alert</item>
<item name="colorPollMostVoted">@color/primary_500</item> <item name="colorPollMostVoted">@color/primary_500</item>
<item name="colorPollVoted">@color/gray_300</item> <item name="colorPollVoted">@color/gray_300</item>
<item name="android:windowLightStatusBar">true</item>
<item name="android:windowLightNavigationBar" tools:ignore="NewApi">true</item>
</style> </style>
<style name="Theme.Mastodon.Dark" parent="Theme.AppKit">
<!-- needed to disable scrim on API 29+ -->
<item name="android:enforceNavigationBarContrast" tools:ignore="NewApi">false</item>
<item name="android:enforceStatusBarContrast" tools:ignore="NewApi">false</item>
<item name="appkitBackDrawable">@drawable/ic_fluent_arrow_left_24_regular</item>
<item name="android:splitMotionEvents">false</item>
<item name="android:buttonStyle">@style/Widget.Mastodon.Button.Primary_LightOnDark</item>
<item name="secondaryButtonStyle">@style/Widget.Mastodon.Button.Secondary_LightOnDark</item>
<item name="android:colorAccent">@color/primary_600</item>
<item name="android:colorPrimary">@color/gray_50</item>
<item name="android:colorBackground">@color/gray_700</item>
<item name="android:textColorPrimary">@color/gray_50</item>
<item name="android:textColorSecondary">@color/gray_400</item>
<item name="colorButtonText">@color/gray_800</item>
<item name="colorSecondary">#E9EDF2</item>
<item name="colorBackgroundLight">@color/gray_700</item>
<item name="colorBackgroundLightest">@color/gray_700</item>
<item name="colorDarkIcon">@color/gray_25</item>
<item name="android:windowBackground">@color/gray_800</item>
<item name="android:statusBarColor">@color/actionbar_bg_dark</item>
<item name="android:navigationBarColor">@color/actionbar_bg_dark</item>
<item name="android:actionBarTheme">@style/Theme.Mastodon.Toolbar.Dark</item>
<item name="android:alertDialogTheme">@style/Theme.Mastodon.Dialog.Alert.Dark</item>
<item name="colorPollMostVoted">@color/primary_700</item>
<item name="colorPollVoted">@color/gray_600</item>
<item name="android:windowLightStatusBar">false</item>
<item name="android:windowLightNavigationBar" tools:ignore="NewApi">false</item>
</style>
<style name="Theme.Mastodon.AutoLightDark" parent="Theme.Mastodon.Light"/>
<style name="Theme.Mastodon.Toolbar" parent="android:ThemeOverlay.Material.ActionBar"> <style name="Theme.Mastodon.Toolbar" parent="android:ThemeOverlay.Material.ActionBar">
<item name="android:colorPrimary">@color/actionbar_bg</item> <item name="android:colorPrimary">@color/actionbar_bg</item>
<item name="android:textColorPrimary">@color/gray_800</item> <item name="android:textColorPrimary">@color/gray_800</item>
<item name="android:textColorSecondary">@color/gray_800</item> <item name="android:textColorSecondary">@color/gray_800</item>
</style> </style>
<style name="Theme.Mastodon.Toolbar.Dark" parent="android:ThemeOverlay.Material.Dark.ActionBar">
<item name="android:colorPrimary">@color/actionbar_bg_dark</item>
<item name="android:textColorPrimary">@color/gray_50</item>
<item name="android:textColorSecondary">@color/gray_50</item>
</style>
<style name="Theme.Mastodon.Toolbar.Profile"> <style name="Theme.Mastodon.Toolbar.Profile">
<item name="android:textColorPrimary">@color/gray_50</item> <item name="android:textColorPrimary">@color/gray_50</item>
<item name="android:textColorSecondary">@color/gray_50</item> <item name="android:textColorSecondary">@color/gray_50</item>
<item name="android:drawableTint">@color/gray_50</item> <item name="android:drawableTint">@color/gray_50</item>
<item name="android:popupTheme">@style/Theme.Mastodon</item> <item name="android:popupTheme">@style/Theme.Mastodon.AutoLightDark</item>
<item name="android:titleTextAppearance">@style/m3_title_medium</item> <item name="android:titleTextAppearance">@style/m3_title_medium</item>
<item name="android:titleTextColor">@color/gray_50</item> <item name="android:titleTextColor">@color/gray_50</item>
<item name="android:subtitleTextAppearance">@style/m3_body_medium</item> <item name="android:subtitleTextAppearance">@style/m3_body_medium</item>
@ -92,6 +130,20 @@
<item name="android:textColorSecondary">@color/gray_500</item> <item name="android:textColorSecondary">@color/gray_500</item>
</style> </style>
<style name="Theme.Mastodon.Dialog.Alert.Dark" parent="android:Theme.Material.Dialog.Alert">
<item name="android:windowTitleStyle">@style/alert_title</item>
<item name="android:dialogPreferredPadding">24dp</item>
<item name="android:windowBackground">@drawable/bg_alert</item>
<item name="android:buttonBarButtonStyle">@style/Widget.Mastodon.ButtonBarButton</item>
<!-- colors -->
<item name="android:colorAccent">@color/primary_600</item>
<item name="android:colorPrimary">@color/gray_50</item>
<item name="android:colorBackground">@color/gray_700</item>
<item name="android:textColorPrimary">@color/gray_50</item>
<item name="android:textColorSecondary">@color/gray_400</item>
</style>
<style name="Widget.Mastodon.ButtonBarButton" parent="android:Widget.Material.Button.Borderless"> <style name="Widget.Mastodon.ButtonBarButton" parent="android:Widget.Material.Button.Borderless">
<item name="android:textAllCaps">false</item> <item name="android:textAllCaps">false</item>
<item name="android:layout_marginEnd">8dp</item> <item name="android:layout_marginEnd">8dp</item>