diff --git a/app/src/main/java/code/name/monkey/retromusic/activities/LicenseActivity.java b/app/src/main/java/code/name/monkey/retromusic/activities/LicenseActivity.java deleted file mode 100644 index f9ada218..00000000 --- a/app/src/main/java/code/name/monkey/retromusic/activities/LicenseActivity.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright (c) 2019 Hemanth Savarala. - * - * Licensed under the GNU General Public License v3 - * - * This is free software: you can redistribute it and/or modify it under - * the terms of the GNU General Public License as published by - * the Free Software Foundation either version 3 of the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU General Public License for more details. - */ - -package code.name.monkey.retromusic.activities; - -import android.graphics.Color; -import android.os.Bundle; -import android.view.MenuItem; -import android.webkit.WebView; - -import androidx.annotation.NonNull; -import androidx.appcompat.widget.Toolbar; - -import org.jetbrains.annotations.Nullable; - -import java.io.BufferedReader; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.nio.charset.StandardCharsets; - -import code.name.monkey.appthemehelper.ThemeStore; -import code.name.monkey.appthemehelper.util.ATHUtil; -import code.name.monkey.appthemehelper.util.ColorUtil; -import code.name.monkey.appthemehelper.util.ToolbarContentTintHelper; -import code.name.monkey.retromusic.R; -import code.name.monkey.retromusic.activities.base.AbsBaseActivity; - -/** Created by hemanths on 2019-09-27. */ -public class LicenseActivity extends AbsBaseActivity { - - @Override - protected void onCreate(@Nullable Bundle savedInstanceState) { - setDrawUnderStatusBar(); - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_license); - setStatusbarColorAuto(); - setNavigationbarColorAuto(); - setLightNavigationBar(true); - Toolbar toolbar = findViewById(R.id.toolbar); - setSupportActionBar(toolbar); - ToolbarContentTintHelper.colorBackButton(toolbar); - toolbar.setBackgroundColor(ATHUtil.INSTANCE.resolveColor(this, R.attr.colorSurface)); - WebView webView = findViewById(R.id.license); - try { - StringBuilder buf = new StringBuilder(); - InputStream json = getAssets().open("oldindex.html"); - BufferedReader in = new BufferedReader(new InputStreamReader(json, StandardCharsets.UTF_8)); - String str; - while ((str = in.readLine()) != null) { - buf.append(str); - } - in.close(); - - // Inject color values for WebView body background and links - final boolean isDark = ATHUtil.INSTANCE.isWindowBackgroundDark(this); - final String backgroundColor = - colorToCSS( - ATHUtil.INSTANCE.resolveColor( - this, R.attr.colorSurface, Color.parseColor(isDark ? "#424242" : "#ffffff"))); - final String contentColor = colorToCSS(Color.parseColor(isDark ? "#ffffff" : "#000000")); - final String changeLog = - buf.toString() - .replace( - "{style-placeholder}", - String.format( - "body { background-color: %s; color: %s; }", backgroundColor, contentColor)) - .replace("{link-color}", colorToCSS(ThemeStore.Companion.accentColor(this))) - .replace( - "{link-color-active}", - colorToCSS( - ColorUtil.INSTANCE.lightenColor(ThemeStore.Companion.accentColor(this)))); - - webView.loadData(changeLog, "text/html", "UTF-8"); - } catch (Throwable e) { - webView.loadData( - "
" + e.getLocalizedMessage() + "
", "text/html", "UTF-8"); - } - } - - @Override - public boolean onOptionsItemSelected(@NonNull MenuItem item) { - if (item.getItemId() == android.R.id.home) { - onBackPressed(); - return true; - } - return super.onOptionsItemSelected(item); - } - - private String colorToCSS(int color) { - return String.format( - "rgb(%d, %d, %d)", - Color.red(color), - Color.green(color), - Color.blue(color)); // on API 29, WebView doesn't load with hex colors - } -} diff --git a/app/src/main/java/code/name/monkey/retromusic/activities/LicenseActivity.kt b/app/src/main/java/code/name/monkey/retromusic/activities/LicenseActivity.kt new file mode 100644 index 00000000..daa02537 --- /dev/null +++ b/app/src/main/java/code/name/monkey/retromusic/activities/LicenseActivity.kt @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2019 Hemanth Savarala. + * + * Licensed under the GNU General Public License v3 + * + * This is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by + * the Free Software Foundation either version 3 of the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + */ +package code.name.monkey.retromusic.activities + +import android.graphics.Color +import android.os.Bundle +import android.view.MenuItem +import android.webkit.WebView +import androidx.appcompat.widget.Toolbar +import code.name.monkey.appthemehelper.ThemeStore.Companion.accentColor +import code.name.monkey.appthemehelper.util.ATHUtil.isWindowBackgroundDark +import code.name.monkey.appthemehelper.util.ATHUtil.resolveColor +import code.name.monkey.appthemehelper.util.ColorUtil.lightenColor +import code.name.monkey.appthemehelper.util.ToolbarContentTintHelper +import code.name.monkey.retromusic.R +import code.name.monkey.retromusic.activities.base.AbsBaseActivity +import java.io.BufferedReader +import java.io.InputStreamReader +import java.nio.charset.StandardCharsets + +/** Created by hemanths on 2019-09-27. */ +class LicenseActivity : AbsBaseActivity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_license) + val toolbar = findViewById" + e.localizedMessage + "
", "text/html", "UTF-8" + ) + } + } + + override fun onOptionsItemSelected(item: MenuItem): Boolean { + if (item.itemId == android.R.id.home) { + onBackPressed() + return true + } + return super.onOptionsItemSelected(item) + } + + private fun colorToCSS(color: Int): String { + return String.format( + "rgb(%d, %d, %d)", + Color.red(color), + Color.green(color), + Color.blue(color) + ) // on API 29, WebView doesn't load with hex colors + } +} \ No newline at end of file diff --git a/app/src/main/java/code/name/monkey/retromusic/activities/LockScreenActivity.kt b/app/src/main/java/code/name/monkey/retromusic/activities/LockScreenActivity.kt index 792c8365..621bc177 100644 --- a/app/src/main/java/code/name/monkey/retromusic/activities/LockScreenActivity.kt +++ b/app/src/main/java/code/name/monkey/retromusic/activities/LockScreenActivity.kt @@ -48,9 +48,7 @@ class LockScreenActivity : AbsMusicServiceActivity() { setContentView(binding.root) hideStatusBar() setStatusbarColorAuto() - setNavigationbarColorAuto() setTaskDescriptionColorAuto() - setLightNavigationBar(true) val config = SlidrConfig.Builder().listener(object : SlidrListener { override fun onSlideStateChanged(state: Int) { diff --git a/app/src/main/java/code/name/monkey/retromusic/activities/LyricsActivity.kt b/app/src/main/java/code/name/monkey/retromusic/activities/LyricsActivity.kt index 5b72c24a..a0263db6 100644 --- a/app/src/main/java/code/name/monkey/retromusic/activities/LyricsActivity.kt +++ b/app/src/main/java/code/name/monkey/retromusic/activities/LyricsActivity.kt @@ -94,7 +94,6 @@ class LyricsActivity : AbsMusicServiceActivity() { ViewCompat.setTransitionName(binding.container, "lyrics") setStatusbarColorAuto() setTaskDescriptionColorAuto() - setNavigationbarColorAuto() setupWakelock() diff --git a/app/src/main/java/code/name/monkey/retromusic/activities/MainActivity.kt b/app/src/main/java/code/name/monkey/retromusic/activities/MainActivity.kt index 4f96a696..ade445e6 100644 --- a/app/src/main/java/code/name/monkey/retromusic/activities/MainActivity.kt +++ b/app/src/main/java/code/name/monkey/retromusic/activities/MainActivity.kt @@ -37,6 +37,7 @@ import code.name.monkey.retromusic.repository.PlaylistSongsLoader import code.name.monkey.retromusic.service.MusicService import code.name.monkey.retromusic.util.AppRater import code.name.monkey.retromusic.util.PreferenceUtil +import code.name.monkey.retromusic.util.RetroUtil import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.launch import org.koin.android.ext.android.get @@ -55,8 +56,6 @@ class MainActivity : AbsCastActivity(), OnSharedPreferenceChangeListener { setDrawUnderStatusBar() super.onCreate(savedInstanceState) setStatusbarColorAuto() - setNavigationbarColorAuto() - setLightNavigationBar(true) setTaskDescriptionColorAuto() hideStatusBar() updateTabs() diff --git a/app/src/main/java/code/name/monkey/retromusic/activities/PermissionActivity.kt b/app/src/main/java/code/name/monkey/retromusic/activities/PermissionActivity.kt index f61eb518..34d4a50c 100644 --- a/app/src/main/java/code/name/monkey/retromusic/activities/PermissionActivity.kt +++ b/app/src/main/java/code/name/monkey/retromusic/activities/PermissionActivity.kt @@ -41,8 +41,6 @@ class PermissionActivity : AbsMusicServiceActivity() { binding = ActivityPermissionBinding.inflate(layoutInflater) setContentView(binding.root) setStatusbarColorAuto() - setNavigationbarColorAuto() - setLightNavigationBar(true) setTaskDescriptionColorAuto() setupTitle() diff --git a/app/src/main/java/code/name/monkey/retromusic/activities/PlayingQueueActivity.kt b/app/src/main/java/code/name/monkey/retromusic/activities/PlayingQueueActivity.kt index 70b45c24..8adb96bc 100644 --- a/app/src/main/java/code/name/monkey/retromusic/activities/PlayingQueueActivity.kt +++ b/app/src/main/java/code/name/monkey/retromusic/activities/PlayingQueueActivity.kt @@ -19,6 +19,7 @@ import android.os.Bundle import android.view.MenuItem import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView +import code.name.monkey.appthemehelper.util.ATHUtil import code.name.monkey.appthemehelper.util.ColorUtil import code.name.monkey.appthemehelper.util.MaterialValueHelper import code.name.monkey.retromusic.R @@ -26,7 +27,6 @@ import code.name.monkey.retromusic.activities.base.AbsMusicServiceActivity import code.name.monkey.retromusic.adapter.song.PlayingQueueAdapter import code.name.monkey.retromusic.databinding.ActivityPlayingQueueBinding import code.name.monkey.retromusic.extensions.accentColor -import code.name.monkey.retromusic.extensions.surfaceColor import code.name.monkey.retromusic.helper.MusicPlayerRemote import code.name.monkey.retromusic.util.MusicUtil import code.name.monkey.retromusic.util.ThemedFastScroller @@ -59,10 +59,8 @@ open class PlayingQueueActivity : AbsMusicServiceActivity() { super.onCreate(savedInstanceState) binding = ActivityPlayingQueueBinding.inflate(layoutInflater) setContentView(binding.root) - setStatusbarColorAuto() - setNavigationbarColorAuto() + setLightStatusbarAuto(ATHUtil.resolveColor(this, R.attr.colorSurface)) setTaskDescriptionColorAuto() - setLightNavigationBar(true) setupToolbar() setUpRecyclerView() @@ -191,7 +189,7 @@ open class PlayingQueueActivity : AbsMusicServiceActivity() { private fun setupToolbar() { binding.toolbar.subtitle = getUpNextAndQueueTime() - binding.toolbar.setBackgroundColor(surfaceColor()) + //binding.toolbar.setBackgroundColor(surfaceColor()) setSupportActionBar(binding.toolbar) binding.clearQueue.backgroundTintList = ColorStateList.valueOf(accentColor()) ColorStateList.valueOf( diff --git a/app/src/main/java/code/name/monkey/retromusic/activities/PurchaseActivity.kt b/app/src/main/java/code/name/monkey/retromusic/activities/PurchaseActivity.kt index c611d2f2..2bd7ce42 100644 --- a/app/src/main/java/code/name/monkey/retromusic/activities/PurchaseActivity.kt +++ b/app/src/main/java/code/name/monkey/retromusic/activities/PurchaseActivity.kt @@ -47,8 +47,6 @@ class PurchaseActivity : AbsBaseActivity(), BillingProcessor.IBillingHandler { setContentView(binding.root) setStatusbarColor(Color.TRANSPARENT) setLightStatusbar(false) - setNavigationbarColor(Color.BLACK) - setLightNavigationBar(false) binding.toolbar.navigationIcon?.setTint(Color.WHITE) binding.toolbar.setNavigationOnClickListener { onBackPressed() } diff --git a/app/src/main/java/code/name/monkey/retromusic/activities/SettingsActivity.kt b/app/src/main/java/code/name/monkey/retromusic/activities/SettingsActivity.kt index 54d31bb4..9b314a48 100644 --- a/app/src/main/java/code/name/monkey/retromusic/activities/SettingsActivity.kt +++ b/app/src/main/java/code/name/monkey/retromusic/activities/SettingsActivity.kt @@ -19,6 +19,7 @@ import android.view.MenuItem import androidx.navigation.NavController import androidx.navigation.NavDestination import code.name.monkey.appthemehelper.ThemeStore +import code.name.monkey.appthemehelper.util.ATHUtil import code.name.monkey.appthemehelper.util.VersionUtils import code.name.monkey.retromusic.R import code.name.monkey.retromusic.activities.base.AbsBaseActivity @@ -36,9 +37,7 @@ class SettingsActivity : AbsBaseActivity(), ColorCallback { super.onCreate(savedInstanceState) binding = ActivitySettingsBinding.inflate(layoutInflater) setContentView(binding.root) - setStatusbarColorAuto() - setNavigationbarColorAuto() - setLightNavigationBar(true) + setLightStatusbarAuto(ATHUtil.resolveColor(this, R.attr.colorSurface)) setupToolbar() } diff --git a/app/src/main/java/code/name/monkey/retromusic/activities/ShareInstagramStory.kt b/app/src/main/java/code/name/monkey/retromusic/activities/ShareInstagramStory.kt index b3d31052..a0a71973 100644 --- a/app/src/main/java/code/name/monkey/retromusic/activities/ShareInstagramStory.kt +++ b/app/src/main/java/code/name/monkey/retromusic/activities/ShareInstagramStory.kt @@ -61,7 +61,6 @@ class ShareInstagramStory : AbsBaseActivity() { binding = ActivityShareInstagramBinding.inflate(layoutInflater) setContentView(binding.root) setStatusbarColor(Color.TRANSPARENT) - setNavigationbarColor(Color.BLACK) binding.toolbar.setBackgroundColor(Color.TRANSPARENT) setSupportActionBar(binding.toolbar) diff --git a/app/src/main/java/code/name/monkey/retromusic/activities/SupportDevelopmentActivity.kt b/app/src/main/java/code/name/monkey/retromusic/activities/SupportDevelopmentActivity.kt index 58cddd71..42531086 100644 --- a/app/src/main/java/code/name/monkey/retromusic/activities/SupportDevelopmentActivity.kt +++ b/app/src/main/java/code/name/monkey/retromusic/activities/SupportDevelopmentActivity.kt @@ -78,9 +78,7 @@ class SupportDevelopmentActivity : AbsBaseActivity(), BillingProcessor.IBillingH setContentView(R.layout.activity_donation) setStatusbarColorAuto() - setNavigationbarColorAuto() setTaskDescriptionColorAuto() - setLightNavigationBar(true) setupToolbar() diff --git a/app/src/main/java/code/name/monkey/retromusic/activities/UserInfoActivity.kt b/app/src/main/java/code/name/monkey/retromusic/activities/UserInfoActivity.kt index 1394cc93..6288b14b 100644 --- a/app/src/main/java/code/name/monkey/retromusic/activities/UserInfoActivity.kt +++ b/app/src/main/java/code/name/monkey/retromusic/activities/UserInfoActivity.kt @@ -61,9 +61,7 @@ class UserInfoActivity : AbsBaseActivity() { binding = ActivityUserInfoBinding.inflate(layoutInflater) setContentView(binding.root) setStatusbarColorAuto() - setNavigationbarColorAuto() setTaskDescriptionColorAuto() - setLightNavigationBar(true) applyToolbar(binding.toolbar) binding.nameContainer.accentColor() diff --git a/app/src/main/java/code/name/monkey/retromusic/activities/WhatsNewActivity.java b/app/src/main/java/code/name/monkey/retromusic/activities/WhatsNewActivity.java deleted file mode 100644 index 9e37a8ee..00000000 --- a/app/src/main/java/code/name/monkey/retromusic/activities/WhatsNewActivity.java +++ /dev/null @@ -1,128 +0,0 @@ -package code.name.monkey.retromusic.activities; - -import android.content.Context; -import android.content.pm.PackageInfo; -import android.content.pm.PackageManager; -import android.graphics.Color; -import android.os.Bundle; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.core.widget.NestedScrollView; - -import java.io.BufferedReader; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.nio.charset.StandardCharsets; -import java.util.Locale; - -import code.name.monkey.appthemehelper.ThemeStore; -import code.name.monkey.appthemehelper.util.ATHUtil; -import code.name.monkey.appthemehelper.util.ColorUtil; -import code.name.monkey.appthemehelper.util.MaterialValueHelper; -import code.name.monkey.appthemehelper.util.ToolbarContentTintHelper; -import code.name.monkey.retromusic.Constants; -import code.name.monkey.retromusic.R; -import code.name.monkey.retromusic.activities.base.AbsBaseActivity; -import code.name.monkey.retromusic.databinding.ActivityWhatsNewBinding; -import code.name.monkey.retromusic.extensions.ColorExtKt; -import code.name.monkey.retromusic.util.PreferenceUtil; -import code.name.monkey.retromusic.util.RetroUtil; - -public class WhatsNewActivity extends AbsBaseActivity { - - private static String colorToCSS(int color) { - return String.format( - Locale.getDefault(), - "rgba(%d, %d, %d, %d)", - Color.red(color), - Color.green(color), - Color.blue(color), - Color.alpha(color)); // on API 29, WebView doesn't load with hex colors - } - - private static void setChangelogRead(@NonNull Context context) { - try { - PackageInfo pInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); - int currentVersion = pInfo.versionCode; - PreferenceUtil.INSTANCE.setLastVersion(currentVersion); - } catch (PackageManager.NameNotFoundException e) { - e.printStackTrace(); - } - } - - @Override - protected void onCreate(@Nullable Bundle savedInstanceState) { - setDrawUnderStatusBar(); - super.onCreate(savedInstanceState); - ActivityWhatsNewBinding binding = ActivityWhatsNewBinding.inflate(getLayoutInflater()); - setContentView(binding.getRoot()); - setStatusbarColorAuto(); - setNavigationbarColorAuto(); - setTaskDescriptionColorAuto(); - - binding.toolbar.setBackgroundColor(ATHUtil.INSTANCE.resolveColor(this, R.attr.colorSurface)); - binding.toolbar.setNavigationOnClickListener(v -> onBackPressed()); - ToolbarContentTintHelper.colorBackButton(binding.toolbar); - - try { - StringBuilder buf = new StringBuilder(); - InputStream json = getAssets().open("retro-changelog.html"); - BufferedReader in = new BufferedReader(new InputStreamReader(json, StandardCharsets.UTF_8)); - String str; - while ((str = in.readLine()) != null) { - buf.append(str); - } - in.close(); - - // Inject color values for WebView body background and links - final boolean isDark = ATHUtil.INSTANCE.isWindowBackgroundDark(this); - final int accentColor = ThemeStore.Companion.accentColor(this); - final String backgroundColor = - colorToCSS( - ATHUtil.INSTANCE.resolveColor( - this, R.attr.colorSurface, Color.parseColor(isDark ? "#424242" : "#ffffff"))); - final String contentColor = colorToCSS(Color.parseColor(isDark ? "#ffffff" : "#000000")); - final String textColor = colorToCSS(Color.parseColor(isDark ? "#60FFFFFF" : "#80000000")); - final String accentColorString = colorToCSS(ThemeStore.Companion.accentColor(this)); - final String cardBackgroundColor = colorToCSS(Color.parseColor(isDark ? "#353535" : "#ffffff")); - final String accentTextColor = - colorToCSS( - MaterialValueHelper.getPrimaryTextColor( - this, ColorUtil.INSTANCE.isColorLight(accentColor))); - final String changeLog = - buf.toString() - .replace( - "{style-placeholder}", - String.format( - "body { background-color: %s; color: %s; } li {color: %s;} h3 {color: %s;} .tag {color: %s;} div{background-color: %s;}", - backgroundColor, - contentColor, - textColor, - accentColorString, - accentColorString, - cardBackgroundColor)) - .replace("{link-color}", colorToCSS(ThemeStore.Companion.accentColor(this))) - .replace( - "{link-color-active}", - colorToCSS( - ColorUtil.INSTANCE.lightenColor(ThemeStore.Companion.accentColor(this)))); - binding.webView.loadData(changeLog, "text/html", "UTF-8"); - } catch (Throwable e) { - binding.webView.loadData( - "" + e.getLocalizedMessage() + "
", "text/html", "UTF-8"); - } - setChangelogRead(this); - binding.tgFab.setOnClickListener(v -> RetroUtil.openUrl(this, Constants.TELEGRAM_CHANGE_LOG)); - ColorExtKt.accentColor(binding.tgFab); - binding.tgFab.shrink(); - binding.container.setOnScrollChangeListener((NestedScrollView.OnScrollChangeListener) (v, scrollX, scrollY, oldScrollX, oldScrollY) -> { - int dy = scrollY - oldScrollY; - if (dy > 0) { - binding.tgFab.shrink(); - } else if (dy < 0) { - binding.tgFab.extend(); - } - }); - } -} diff --git a/app/src/main/java/code/name/monkey/retromusic/activities/WhatsNewActivity.kt b/app/src/main/java/code/name/monkey/retromusic/activities/WhatsNewActivity.kt new file mode 100644 index 00000000..e4e59888 --- /dev/null +++ b/app/src/main/java/code/name/monkey/retromusic/activities/WhatsNewActivity.kt @@ -0,0 +1,132 @@ +package code.name.monkey.retromusic.activities + +import android.content.Context +import android.content.pm.PackageManager +import android.graphics.Color +import android.os.Bundle +import androidx.core.widget.NestedScrollView +import code.name.monkey.appthemehelper.ThemeStore.Companion.accentColor +import code.name.monkey.appthemehelper.util.ATHUtil.isWindowBackgroundDark +import code.name.monkey.appthemehelper.util.ATHUtil.resolveColor +import code.name.monkey.appthemehelper.util.ColorUtil.isColorLight +import code.name.monkey.appthemehelper.util.ColorUtil.lightenColor +import code.name.monkey.appthemehelper.util.MaterialValueHelper.getPrimaryTextColor +import code.name.monkey.appthemehelper.util.ToolbarContentTintHelper +import code.name.monkey.retromusic.Constants +import code.name.monkey.retromusic.R +import code.name.monkey.retromusic.activities.base.AbsBaseActivity +import code.name.monkey.retromusic.databinding.ActivityWhatsNewBinding +import code.name.monkey.retromusic.extensions.accentColor +import code.name.monkey.retromusic.util.PreferenceUtil.lastVersion +import code.name.monkey.retromusic.util.RetroUtil +import java.io.BufferedReader +import java.io.InputStreamReader +import java.nio.charset.StandardCharsets +import java.util.* + +class WhatsNewActivity : AbsBaseActivity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + val binding = ActivityWhatsNewBinding.inflate(layoutInflater) + setContentView(binding.root) + setLightStatusbarAuto(resolveColor(this, R.attr.colorSurface)) + setTaskDescriptionColorAuto() + binding.toolbar.setNavigationOnClickListener { onBackPressed() } + ToolbarContentTintHelper.colorBackButton(binding.toolbar) + try { + val buf = StringBuilder() + val json = assets.open("retro-changelog.html") + val br = BufferedReader(InputStreamReader(json, StandardCharsets.UTF_8)) + var str: String? + while (br.readLine().also { str = it } != null) { + buf.append(str) + } + br.close() + + // Inject color values for WebView body background and links + val isDark = isWindowBackgroundDark(this) + val accentColor = accentColor(this) + val backgroundColor = colorToCSS( + resolveColor( + this, + R.attr.colorSurface, + Color.parseColor(if (isDark) "#424242" else "#ffffff") + ) + ) + val contentColor = colorToCSS(Color.parseColor(if (isDark) "#ffffff" else "#000000")) + val textColor = colorToCSS(Color.parseColor(if (isDark) "#60FFFFFF" else "#80000000")) + val accentColorString = colorToCSS(accentColor(this)) + val cardBackgroundColor = + colorToCSS(Color.parseColor(if (isDark) "#353535" else "#ffffff")) + val accentTextColor = colorToCSS( + getPrimaryTextColor( + this, isColorLight(accentColor) + ) + ) + val changeLog = buf.toString() + .replace( + "{style-placeholder}", String.format( + "body { background-color: %s; color: %s; } li {color: %s;} h3 {color: %s;} .tag {color: %s;} div{background-color: %s;}", + backgroundColor, + contentColor, + textColor, + accentColorString, + accentColorString, + cardBackgroundColor + ) + ) + .replace("{link-color}", colorToCSS(accentColor(this))) + .replace( + "{link-color-active}", + colorToCSS( + lightenColor(accentColor(this)) + ) + ) + binding.webView.loadData(changeLog, "text/html", "UTF-8") + } catch (e: Throwable) { + binding.webView.loadData( + "" + e.localizedMessage + "
", "text/html", "UTF-8" + ) + } + setChangelogRead(this) + binding.tgFab.setOnClickListener { + RetroUtil.openUrl( + this, + Constants.TELEGRAM_CHANGE_LOG + ) + } + binding.tgFab.accentColor() + binding.tgFab.shrink() + binding.container.setOnScrollChangeListener { _: NestedScrollView?, _: Int, scrollY: Int, _: Int, oldScrollY: Int -> + val dy = scrollY - oldScrollY + if (dy > 0) { + binding.tgFab.shrink() + } else if (dy < 0) { + binding.tgFab.extend() + } + } + } + + companion object { + private fun colorToCSS(color: Int): String { + return String.format( + Locale.getDefault(), + "rgba(%d, %d, %d, %d)", + Color.red(color), + Color.green(color), + Color.blue(color), + Color.alpha(color) + ) // on API 29, WebView doesn't load with hex colors + } + + private fun setChangelogRead(context: Context) { + try { + val pInfo = context.packageManager.getPackageInfo(context.packageName, 0) + val currentVersion = pInfo.versionCode + lastVersion = currentVersion + } catch (e: PackageManager.NameNotFoundException) { + e.printStackTrace() + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/code/name/monkey/retromusic/activities/base/AbsSlidingMusicPanelActivity.kt b/app/src/main/java/code/name/monkey/retromusic/activities/base/AbsSlidingMusicPanelActivity.kt index a6cfe26a..44dd8d8d 100644 --- a/app/src/main/java/code/name/monkey/retromusic/activities/base/AbsSlidingMusicPanelActivity.kt +++ b/app/src/main/java/code/name/monkey/retromusic/activities/base/AbsSlidingMusicPanelActivity.kt @@ -22,9 +22,10 @@ import android.view.ViewTreeObserver import android.widget.FrameLayout import androidx.core.view.ViewCompat import androidx.core.view.isVisible +import androidx.core.view.updateLayoutParams +import androidx.core.view.updatePadding import androidx.fragment.app.Fragment import androidx.fragment.app.commit -import code.name.monkey.appthemehelper.util.ATHUtil import code.name.monkey.appthemehelper.util.ColorUtil import code.name.monkey.retromusic.R import code.name.monkey.retromusic.RetroBottomSheetBehavior @@ -56,7 +57,8 @@ import code.name.monkey.retromusic.fragments.player.tiny.TinyPlayerFragment import code.name.monkey.retromusic.helper.MusicPlayerRemote import code.name.monkey.retromusic.model.CategoryInfo import code.name.monkey.retromusic.util.PreferenceUtil -import code.name.monkey.retromusic.views.BottomNavigationBarTinted +import code.name.monkey.retromusic.util.RetroUtil +import com.google.android.material.bottomnavigation.BottomNavigationView import com.google.android.material.bottomsheet.BottomSheetBehavior.* import org.koin.androidx.viewmodel.ext.android.viewModel @@ -71,18 +73,14 @@ abstract class AbsSlidingMusicPanelActivity : AbsMusicServiceActivity() { private var playerFragment: AbsPlayerFragment? = null private var miniPlayerFragment: MiniPlayerFragment? = null private var nowPlayingScreen: NowPlayingScreen? = null - private var navigationBarColor: Int = 0 private var taskColor: Int = 0 private var lightStatusBar: Boolean = false - private var lightNavigationBar: Boolean = false - private var paletteColor: Int = Color.WHITE protected abstract fun createContentView(): SlidingMusicPanelLayoutBinding private val panelState: Int get() = bottomSheetBehavior.state private lateinit var binding: SlidingMusicPanelLayoutBinding private val bottomSheetCallbackList = object : BottomSheetCallback() { - override fun onSlide(bottomSheet: View, slideOffset: Float) { setMiniPlayerAlphaProgress(slideOffset) binding.dimBackground.show() @@ -123,7 +121,6 @@ abstract class AbsSlidingMusicPanelActivity : AbsMusicServiceActivity() { chooseFragmentForTheme() setupSlidingUpPanel() setupBottomSheet() - updateColor() val themeColor = resolveColor(android.R.attr.windowBackground, Color.GRAY) binding.dimBackground.setBackgroundColor(ColorUtil.withAlpha(themeColor, 0.5f)) @@ -131,12 +128,18 @@ abstract class AbsSlidingMusicPanelActivity : AbsMusicServiceActivity() { println("dimBackground") collapsePanel() } + binding.bottomNavigationView.apply { + val navbarHeight = RetroUtil.getNavigationBarHeight() + updatePadding(bottom = navbarHeight) + binding.bottomNavigationView.updateLayoutParams { + height = dip(R.dimen.mini_player_height) + navbarHeight + } + } } private fun setupBottomSheet() { bottomSheetBehavior = from(binding.slidingPanel) as RetroBottomSheetBehavior bottomSheetBehavior.addBottomSheetCallback(bottomSheetCallbackList) - bottomSheetBehavior.maxWidth = resources.displayMetrics.widthPixels } override fun onResume() { @@ -179,18 +182,16 @@ abstract class AbsSlidingMusicPanelActivity : AbsMusicServiceActivity() { miniPlayerFragment?.view?.visibility = if (alpha == 0f) View.GONE else View.VISIBLE binding.bottomNavigationView.translationY = progress * 500 binding.bottomNavigationView.alpha = alpha + binding.playerFragmentContainer.alpha = (progress - 0.2F) / 0.2F } open fun onPanelCollapsed() { // restore values super.setLightStatusbar(lightStatusBar) super.setTaskDescriptionColor(taskColor) - super.setNavigationbarColor(navigationBarColor) - super.setLightNavigationBar(lightNavigationBar) } open fun onPanelExpanded() { - onPaletteColorChanged() } private fun setupSlidingUpPanel() { @@ -214,7 +215,7 @@ abstract class AbsSlidingMusicPanelActivity : AbsMusicServiceActivity() { }) } - fun getBottomNavigationView(): BottomNavigationBarTinted { + fun getBottomNavigationView(): BottomNavigationView { return binding.bottomNavigationView } @@ -250,43 +251,6 @@ abstract class AbsSlidingMusicPanelActivity : AbsMusicServiceActivity() { return false } - private fun onPaletteColorChanged() { - if (panelState == STATE_EXPANDED) { - super.setTaskDescriptionColor(paletteColor) - val isColorLight = ColorUtil.isColorLight(paletteColor) - if (PreferenceUtil.isAdaptiveColor && (nowPlayingScreen == Normal || nowPlayingScreen == Flat)) { - super.setLightNavigationBar(true) - super.setLightStatusbar(isColorLight) - } else if (nowPlayingScreen == Card || nowPlayingScreen == Blur || nowPlayingScreen == BlurCard) { - super.setLightStatusbar(false) - super.setLightNavigationBar(true) - super.setNavigationbarColor(Color.BLACK) - } else if (nowPlayingScreen == Color || nowPlayingScreen == Tiny || nowPlayingScreen == Gradient) { - super.setNavigationbarColor(paletteColor) - super.setLightNavigationBar(isColorLight) - super.setLightStatusbar(isColorLight) - } else if (nowPlayingScreen == Full) { - super.setNavigationbarColor(paletteColor) - super.setLightNavigationBar(isColorLight) - super.setLightStatusbar(false) - } else if (nowPlayingScreen == Classic) { - super.setLightStatusbar(false) - } else if (nowPlayingScreen == Fit) { - super.setLightStatusbar(false) - } else { - super.setLightStatusbar( - ColorUtil.isColorLight( - ATHUtil.resolveColor( - this, - android.R.attr.windowBackground - ) - ) - ) - super.setLightNavigationBar(true) - } - } - } - override fun setLightStatusbar(enabled: Boolean) { lightStatusBar = enabled if (panelState == STATE_COLLAPSED) { @@ -294,20 +258,6 @@ abstract class AbsSlidingMusicPanelActivity : AbsMusicServiceActivity() { } } - override fun setLightNavigationBar(enabled: Boolean) { - lightNavigationBar = enabled - if (panelState == STATE_COLLAPSED) { - super.setLightNavigationBar(enabled) - } - } - - override fun setNavigationbarColor(color: Int) { - navigationBarColor = color - if (panelState == STATE_COLLAPSED) { - super.setNavigationbarColor(color) - } - } - override fun setTaskDescriptionColor(color: Int) { taskColor = color if (panelState == STATE_COLLAPSED) { @@ -330,25 +280,18 @@ abstract class AbsSlidingMusicPanelActivity : AbsMusicServiceActivity() { } } - private fun updateColor() { - libraryViewModel.paletteColor.observe(this, { color -> - this.paletteColor = color - onPaletteColorChanged() - }) - } - fun setBottomBarVisibility(visible: Boolean) { binding.bottomNavigationView.isVisible = visible hideBottomBar(MusicPlayerRemote.playingQueue.isEmpty()) } private fun hideBottomBar(hide: Boolean) { - val heightOfBar = - if (MusicPlayerRemote.isCasting) dip(R.dimen.cast_mini_player_height) else dip(R.dimen.mini_player_height) - val heightOfBarWithTabs = - if (MusicPlayerRemote.isCasting) dip(R.dimen.mini_cast_player_height_expanded) else dip( - R.dimen.mini_player_height_expanded - ) + val heightOfBar = RetroUtil.getNavigationBarHeight() + + if (MusicPlayerRemote.isCasting) dip(R.dimen.cast_mini_player_height) else dip(R.dimen.mini_player_height) + val heightOfBarWithTabs = RetroUtil.getNavigationBarHeight() + + if (MusicPlayerRemote.isCasting) dip(R.dimen.mini_cast_player_height_expanded) else dip( + R.dimen.mini_player_height_expanded + ) val isVisible = binding.bottomNavigationView.isVisible if (hide) { bottomSheetBehavior.isHideable = true diff --git a/app/src/main/java/code/name/monkey/retromusic/activities/base/AbsThemeActivity.kt b/app/src/main/java/code/name/monkey/retromusic/activities/base/AbsThemeActivity.kt index 8d437159..45cf0c0b 100644 --- a/app/src/main/java/code/name/monkey/retromusic/activities/base/AbsThemeActivity.kt +++ b/app/src/main/java/code/name/monkey/retromusic/activities/base/AbsThemeActivity.kt @@ -49,6 +49,7 @@ abstract class AbsThemeActivity : ATHToolbarActivity(), Runnable { setImmersiveFullscreen() registerSystemUiVisibility() toggleScreenOn() + setDrawUnderNavigationBar() //MaterialDialogsUtil.updateMaterialDialogsThemeSingleton(this) } @@ -91,7 +92,7 @@ abstract class AbsThemeActivity : ATHToolbarActivity(), Runnable { RetroUtil.setAllowDrawUnderStatusBar(window) } - fun setDrawUnderNavigationBar() { + private fun setDrawUnderNavigationBar() { RetroUtil.setAllowDrawUnderNavigationBar(window) } diff --git a/app/src/main/java/code/name/monkey/retromusic/activities/bugreport/BugReportActivity.kt b/app/src/main/java/code/name/monkey/retromusic/activities/bugreport/BugReportActivity.kt index 3780834d..a65b135e 100644 --- a/app/src/main/java/code/name/monkey/retromusic/activities/bugreport/BugReportActivity.kt +++ b/app/src/main/java/code/name/monkey/retromusic/activities/bugreport/BugReportActivity.kt @@ -74,12 +74,10 @@ open class BugReportActivity : AbsThemeActivity() { private var deviceInfo: DeviceInfo? = null override fun onCreate(savedInstanceState: Bundle?) { - setDrawUnderStatusBar() super.onCreate(savedInstanceState) binding = ActivityBugReportBinding.inflate(layoutInflater) setContentView(binding.root) setStatusbarColorAuto() - setNavigationbarColorAuto() setTaskDescriptionColorAuto() initViews() diff --git a/app/src/main/java/code/name/monkey/retromusic/activities/tageditor/AbsTagEditorActivity.kt b/app/src/main/java/code/name/monkey/retromusic/activities/tageditor/AbsTagEditorActivity.kt index 536dea62..361555bb 100755 --- a/app/src/main/java/code/name/monkey/retromusic/activities/tageditor/AbsTagEditorActivity.kt +++ b/app/src/main/java/code/name/monkey/retromusic/activities/tageditor/AbsTagEditorActivity.kt @@ -196,7 +196,6 @@ abstract class AbsTagEditorActivity