From fa371849cbcef2fd04e69919eadb23c236201528 Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Sun, 21 Sep 2025 11:22:31 +0530 Subject: [PATCH 1/8] Migrate app themes to Material 3 --- .../newpipe/fragments/MainFragment.java | 16 - .../components/common/ScaffoldWithToolbar.kt | 10 - .../schabi/newpipe/ui/screens/AboutScreen.kt | 5 +- .../activity_player_queue_control.xml | 5 +- .../layout/activity_player_queue_control.xml | 5 +- app/src/main/res/layout/fragment_channel.xml | 17 +- app/src/main/res/layout/fragment_main.xml | 5 - app/src/main/res/layout/toolbar_layout.xml | 5 +- .../main/res/layout/toolbar_search_layout.xml | 4 - app/src/main/res/values-night/colors.xml | 5 - app/src/main/res/values-night/styles.xml | 9 - app/src/main/res/values-v27/styles.xml | 28 -- app/src/main/res/values-v29/styles.xml | 27 -- app/src/main/res/values-v35/styles.xml | 27 -- app/src/main/res/values/m3_colors.xml | 79 +++++ app/src/main/res/values/styles.xml | 275 +++++++++++------- app/src/main/res/values/styles_misc.xml | 24 +- 17 files changed, 269 insertions(+), 277 deletions(-) delete mode 100644 app/src/main/res/values-night/colors.xml delete mode 100644 app/src/main/res/values-night/styles.xml delete mode 100644 app/src/main/res/values-v27/styles.xml delete mode 100644 app/src/main/res/values-v29/styles.xml delete mode 100644 app/src/main/res/values-v35/styles.xml create mode 100644 app/src/main/res/values/m3_colors.xml diff --git a/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java index 1a5e5aa45..ee50f9665 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java @@ -9,8 +9,6 @@ import static com.google.android.material.tabs.TabLayout.INDICATOR_GRAVITY_TOP; import android.content.Context; import android.content.SharedPreferences; -import android.content.res.ColorStateList; -import android.graphics.Color; import android.os.Bundle; import android.util.Log; import android.view.LayoutInflater; @@ -21,7 +19,6 @@ import android.view.View; import android.view.ViewGroup; import android.widget.RelativeLayout; -import androidx.annotation.ColorInt; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.ActionBar; @@ -44,7 +41,6 @@ import org.schabi.newpipe.settings.tabs.Tab; import org.schabi.newpipe.settings.tabs.TabsManager; import org.schabi.newpipe.util.NavigationHelper; import org.schabi.newpipe.util.ServiceHelper; -import org.schabi.newpipe.util.ThemeHelper; import org.schabi.newpipe.views.ScrollableTabLayout; import java.util.ArrayList; @@ -242,18 +238,6 @@ public class MainFragment extends BaseFragment implements TabLayout.OnTabSelecte tabLayout.setLayoutParams(tabParams); viewPager.setLayoutParams(pagerParams); - - // change the background and icon color of the tab layout: - // service-colored at the top, app-background-colored at the bottom - tabLayout.setBackgroundColor(ThemeHelper.resolveColorFromAttr(requireContext(), - bottom ? android.R.attr.windowBackground : R.attr.colorPrimary)); - - @ColorInt final int iconColor = bottom - ? ThemeHelper.resolveColorFromAttr(requireContext(), android.R.attr.colorAccent) - : Color.WHITE; - tabLayout.setTabRippleColor(ColorStateList.valueOf(iconColor).withAlpha(32)); - tabLayout.setTabIconTint(ColorStateList.valueOf(iconColor)); - tabLayout.setSelectedTabIndicatorColor(iconColor); } @Override diff --git a/app/src/main/java/org/schabi/newpipe/ui/components/common/ScaffoldWithToolbar.kt b/app/src/main/java/org/schabi/newpipe/ui/components/common/ScaffoldWithToolbar.kt index 18139c7a6..acdcc867d 100644 --- a/app/src/main/java/org/schabi/newpipe/ui/components/common/ScaffoldWithToolbar.kt +++ b/app/src/main/java/org/schabi/newpipe/ui/components/common/ScaffoldWithToolbar.kt @@ -8,11 +8,9 @@ import androidx.compose.material.icons.automirrored.filled.ArrowBack import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.Icon import androidx.compose.material3.IconButton -import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Scaffold import androidx.compose.material3.Text import androidx.compose.material3.TopAppBar -import androidx.compose.material3.TopAppBarDefaults import androidx.compose.runtime.Composable import androidx.compose.ui.tooling.preview.Preview @@ -28,14 +26,6 @@ fun ScaffoldWithToolbar( topBar = { TopAppBar( title = { Text(text = title) }, - // TODO decide whether to use default colors instead - colors = TopAppBarDefaults.topAppBarColors( - containerColor = MaterialTheme.colorScheme.primaryContainer, - scrolledContainerColor = MaterialTheme.colorScheme.primaryContainer, - navigationIconContentColor = MaterialTheme.colorScheme.onPrimaryContainer, - titleContentColor = MaterialTheme.colorScheme.onPrimaryContainer, - actionIconContentColor = MaterialTheme.colorScheme.onPrimaryContainer, - ), navigationIcon = { IconButton(onClick = onBackClick) { Icon( diff --git a/app/src/main/java/org/schabi/newpipe/ui/screens/AboutScreen.kt b/app/src/main/java/org/schabi/newpipe/ui/screens/AboutScreen.kt index 673a22892..c5d906c34 100644 --- a/app/src/main/java/org/schabi/newpipe/ui/screens/AboutScreen.kt +++ b/app/src/main/java/org/schabi/newpipe/ui/screens/AboutScreen.kt @@ -44,10 +44,7 @@ fun AboutScreen(padding: PaddingValues) { tabIndex = pagerState.currentPage } - TabRow( - selectedTabIndex = tabIndex, - containerColor = MaterialTheme.colorScheme.primaryContainer - ) { + TabRow(selectedTabIndex = tabIndex) { TITLES.forEachIndexed { index, titleId -> Tab( text = { Text(text = stringResource(titleId)) }, diff --git a/app/src/main/res/layout-land/activity_player_queue_control.xml b/app/src/main/res/layout-land/activity_player_queue_control.xml index a5df5e566..a4bd30035 100644 --- a/app/src/main/res/layout-land/activity_player_queue_control.xml +++ b/app/src/main/res/layout-land/activity_player_queue_control.xml @@ -12,8 +12,8 @@ android:id="@+id/appbar" android:layout_width="match_parent" android:layout_height="wrap_content" - android:theme="@style/ThemeOverlay.AppCompat.DayNight.ActionBar" - app:popupTheme="@style/ThemeOverlay.AppCompat.DayNight.ActionBar"> + android:theme="@style/ThemeOverlay.Material3.ActionBar" + app:popupTheme="@style/ThemeOverlay.Material3.ActionBar"> diff --git a/app/src/main/res/layout/activity_player_queue_control.xml b/app/src/main/res/layout/activity_player_queue_control.xml index 29efa36f9..96e4bf3e7 100644 --- a/app/src/main/res/layout/activity_player_queue_control.xml +++ b/app/src/main/res/layout/activity_player_queue_control.xml @@ -12,8 +12,8 @@ android:id="@+id/appbar" android:layout_width="match_parent" android:layout_height="wrap_content" - android:theme="@style/ThemeOverlay.AppCompat.DayNight.ActionBar" - app:popupTheme="@style/ThemeOverlay.AppCompat.DayNight.ActionBar"> + android:theme="@style/ThemeOverlay.Material3.ActionBar" + app:popupTheme="@style/ThemeOverlay.Material3.ActionBar"> diff --git a/app/src/main/res/layout/fragment_channel.xml b/app/src/main/res/layout/fragment_channel.xml index 3f6f98eb8..9f456ba6b 100644 --- a/app/src/main/res/layout/fragment_channel.xml +++ b/app/src/main/res/layout/fragment_channel.xml @@ -5,13 +5,10 @@ android:layout_width="match_parent" android:layout_height="match_parent"> - + app:strokeWidth="2dp" /> + app:tabMode="scrollable" /> + tools:visibility="visible" /> - diff --git a/app/src/main/res/layout/toolbar_layout.xml b/app/src/main/res/layout/toolbar_layout.xml index d4e172978..3de5f68b0 100644 --- a/app/src/main/res/layout/toolbar_layout.xml +++ b/app/src/main/res/layout/toolbar_layout.xml @@ -1,6 +1,5 @@ + android:minHeight="?attr/actionBarSize"> diff --git a/app/src/main/res/values-night/colors.xml b/app/src/main/res/values-night/colors.xml deleted file mode 100644 index 99026e70b..000000000 --- a/app/src/main/res/values-night/colors.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - @color/white - @color/white - diff --git a/app/src/main/res/values-night/styles.xml b/app/src/main/res/values-night/styles.xml deleted file mode 100644 index 7327ac145..000000000 --- a/app/src/main/res/values-night/styles.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - diff --git a/app/src/main/res/values-v27/styles.xml b/app/src/main/res/values-v27/styles.xml deleted file mode 100644 index 64697a897..000000000 --- a/app/src/main/res/values-v27/styles.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - + - + - + + - - - - - diff --git a/app/src/main/res/values/styles_misc.xml b/app/src/main/res/values/styles_misc.xml index 06ee2a300..4b2605594 100644 --- a/app/src/main/res/values/styles_misc.xml +++ b/app/src/main/res/values/styles_misc.xml @@ -2,7 +2,7 @@ - - - - - @@ -66,19 +66,19 @@ ?attr/actionColor - - - - - From 089c6b8d99ddd968977b9dee3e33cc396cf8b721 Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Sun, 21 Sep 2025 16:45:03 +0530 Subject: [PATCH 6/8] Fix AboutActivity crash, remove unused themes --- .../org/schabi/newpipe/about/AboutActivity.kt | 2 + .../newpipe/settings/SettingsActivity.java | 4 +- .../org/schabi/newpipe/util/ThemeHelper.java | 16 ++++--- app/src/main/res/values/styles.xml | 42 +++---------------- 4 files changed, 16 insertions(+), 48 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/about/AboutActivity.kt b/app/src/main/java/org/schabi/newpipe/about/AboutActivity.kt index 13e100c0a..26538e32a 100644 --- a/app/src/main/java/org/schabi/newpipe/about/AboutActivity.kt +++ b/app/src/main/java/org/schabi/newpipe/about/AboutActivity.kt @@ -9,9 +9,11 @@ import org.schabi.newpipe.R import org.schabi.newpipe.ui.components.common.ScaffoldWithToolbar import org.schabi.newpipe.ui.screens.AboutScreen import org.schabi.newpipe.ui.theme.AppTheme +import org.schabi.newpipe.util.ThemeHelper class AboutActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { + setTheme(ThemeHelper.getTheme(this)) enableEdgeToEdge() super.onCreate(savedInstanceState) diff --git a/app/src/main/java/org/schabi/newpipe/settings/SettingsActivity.java b/app/src/main/java/org/schabi/newpipe/settings/SettingsActivity.java index d5089cb7d..0e86939f8 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/SettingsActivity.java +++ b/app/src/main/java/org/schabi/newpipe/settings/SettingsActivity.java @@ -86,9 +86,9 @@ public class SettingsActivity extends AppCompatActivity implements @Override protected void onCreate(final Bundle savedInstanceBundle) { - setTheme(ThemeHelper.getSettingsThemeStyle(this)); - + setTheme(ThemeHelper.getTheme(this)); super.onCreate(savedInstanceBundle); + Bridge.restoreInstanceState(this, savedInstanceBundle); final boolean restored = savedInstanceBundle != null; diff --git a/app/src/main/java/org/schabi/newpipe/util/ThemeHelper.java b/app/src/main/java/org/schabi/newpipe/util/ThemeHelper.java index f6c9c4c3f..109f8354b 100644 --- a/app/src/main/java/org/schabi/newpipe/util/ThemeHelper.java +++ b/app/src/main/java/org/schabi/newpipe/util/ThemeHelper.java @@ -158,35 +158,33 @@ public final class ThemeHelper { } @StyleRes - public static int getSettingsThemeStyle(final Context context) { + public static int getTheme(@NonNull final Context context) { final Resources res = context.getResources(); final String lightTheme = res.getString(R.string.light_theme_key); final String blackTheme = res.getString(R.string.black_theme_key); final String automaticDeviceTheme = res.getString(R.string.auto_device_theme_key); - - final String selectedTheme = getSelectedThemeKey(context); if (selectedTheme.equals(lightTheme)) { - return R.style.LightSettingsTheme; + return R.style.LightTheme; } else if (selectedTheme.equals(blackTheme)) { - return R.style.BlackSettingsTheme; + return R.style.BlackTheme; } else if (selectedTheme.equals(automaticDeviceTheme)) { if (isDeviceDarkThemeEnabled(context)) { // use the dark theme variant preferred by the user final String selectedNightTheme = getSelectedNightThemeKey(context); if (selectedNightTheme.equals(blackTheme)) { - return R.style.BlackSettingsTheme; + return R.style.BlackTheme; } else { - return R.style.DarkSettingsTheme; + return R.style.DarkTheme; } } else { // there is only one day theme - return R.style.LightSettingsTheme; + return R.style.LightTheme; } } else { // default to dark theme - return R.style.DarkSettingsTheme; + return R.style.DarkTheme; } } diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index e8b6cdbbf..3269a690f 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -127,21 +127,14 @@ true - - @@ -177,31 +170,6 @@ ?attr/colorSurfaceContainerHigh - - - - - - - -