Converted WhatsNewActivity to BottomSheetDialogFragment

This commit is contained in:
Prathamesh More 2022-04-21 17:07:57 +05:30
parent dabdcc1d31
commit c5a25c200c
9 changed files with 73 additions and 63 deletions

View file

@ -19,7 +19,7 @@
tools:ignore="ProtectedPermissions" /> tools:ignore="ProtectedPermissions" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="com.android.vending.BILLING" /> <uses-permission android:name="com.android.vending.BILLING" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT"/>
<application <application
android:name=".App" android:name=".App"
@ -116,7 +116,6 @@
<activity android:name=".activities.SupportDevelopmentActivity" /> <activity android:name=".activities.SupportDevelopmentActivity" />
<activity android:name=".activities.LicenseActivity" /> <activity android:name=".activities.LicenseActivity" />
<activity android:name=".activities.PurchaseActivity" /> <activity android:name=".activities.PurchaseActivity" />
<activity android:name=".activities.WhatsNewActivity" />
<activity android:name=".activities.bugreport.BugReportActivity" /> <activity android:name=".activities.bugreport.BugReportActivity" />
<activity android:name=".activities.ShareInstagramStory" /> <activity android:name=".activities.ShareInstagramStory" />
<activity android:name=".activities.DriveModeActivity" /> <activity android:name=".activities.DriveModeActivity" />

View file

@ -35,7 +35,6 @@ import code.name.monkey.retromusic.model.Song
import code.name.monkey.retromusic.repository.PlaylistSongsLoader import code.name.monkey.retromusic.repository.PlaylistSongsLoader
import code.name.monkey.retromusic.service.MusicService import code.name.monkey.retromusic.service.MusicService
import code.name.monkey.retromusic.util.AppRater import code.name.monkey.retromusic.util.AppRater
import code.name.monkey.retromusic.util.NavigationUtil
import code.name.monkey.retromusic.util.PreferenceUtil import code.name.monkey.retromusic.util.PreferenceUtil
import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
@ -62,9 +61,7 @@ class MainActivity : AbsCastActivity(), OnSharedPreferenceChangeListener {
if (!hasPermissions()) { if (!hasPermissions()) {
findNavController(R.id.fragment_container).navigate(R.id.permissionFragment) findNavController(R.id.fragment_container).navigate(R.id.permissionFragment)
} }
if (BuildConfig.VERSION_CODE > PreferenceUtil.lastVersion && !BuildConfig.DEBUG) { WhatsNewFragment.showChangeLog(this )
NavigationUtil.gotoWhatNews(this)
}
} }
private fun setupNavigationController() { private fun setupNavigationController() {

View file

@ -4,34 +4,46 @@ import android.content.Context
import android.content.pm.PackageManager import android.content.pm.PackageManager
import android.graphics.Color import android.graphics.Color
import android.os.Bundle import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.content.pm.PackageInfoCompat
import androidx.core.widget.NestedScrollView import androidx.core.widget.NestedScrollView
import androidx.fragment.app.FragmentActivity
import code.name.monkey.appthemehelper.util.ATHUtil.isWindowBackgroundDark import code.name.monkey.appthemehelper.util.ATHUtil.isWindowBackgroundDark
import code.name.monkey.appthemehelper.util.ColorUtil.isColorLight import code.name.monkey.appthemehelper.util.ColorUtil.isColorLight
import code.name.monkey.appthemehelper.util.ColorUtil.lightenColor import code.name.monkey.appthemehelper.util.ColorUtil.lightenColor
import code.name.monkey.appthemehelper.util.MaterialValueHelper.getPrimaryTextColor import code.name.monkey.appthemehelper.util.MaterialValueHelper.getPrimaryTextColor
import code.name.monkey.appthemehelper.util.ToolbarContentTintHelper import code.name.monkey.retromusic.BuildConfig
import code.name.monkey.retromusic.Constants import code.name.monkey.retromusic.Constants
import code.name.monkey.retromusic.activities.base.AbsThemeActivity import code.name.monkey.retromusic.databinding.FragmentWhatsNewBinding
import code.name.monkey.retromusic.databinding.ActivityWhatsNewBinding import code.name.monkey.retromusic.extensions.accentColor
import code.name.monkey.retromusic.extensions.* import code.name.monkey.retromusic.extensions.openUrl
import code.name.monkey.retromusic.extensions.surfaceColor
import code.name.monkey.retromusic.util.PreferenceUtil.lastVersion import code.name.monkey.retromusic.util.PreferenceUtil.lastVersion
import java.io.BufferedReader import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import java.io.InputStreamReader
import java.nio.charset.StandardCharsets import java.nio.charset.StandardCharsets
import java.util.* import java.util.*
class WhatsNewActivity : AbsThemeActivity() { class WhatsNewFragment : BottomSheetDialogFragment() {
override fun onCreate(savedInstanceState: Bundle?) { private var _binding: FragmentWhatsNewBinding? = null
super.onCreate(savedInstanceState) val binding get() = _binding!!
val binding = ActivityWhatsNewBinding.inflate(layoutInflater)
setContentView(binding.root) override fun onCreateView(
setTaskDescriptionColorAuto() inflater: LayoutInflater,
binding.toolbar.setNavigationOnClickListener { onBackPressed() } container: ViewGroup?,
ToolbarContentTintHelper.colorBackButton(binding.toolbar) savedInstanceState: Bundle?
): View {
_binding = FragmentWhatsNewBinding.inflate(inflater, container, false)
return binding.root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
try { try {
val buf = StringBuilder() val buf = StringBuilder()
val json = assets.open("retro-changelog.html") val stream= requireContext().assets.open("retro-changelog.html")
BufferedReader(InputStreamReader(json, StandardCharsets.UTF_8)).use { br -> stream.reader(StandardCharsets.UTF_8).buffered().use { br ->
var str: String? var str: String?
while (br.readLine().also { str = it } != null) { while (br.readLine().also { str = it } != null) {
buf.append(str) buf.append(str)
@ -39,7 +51,7 @@ class WhatsNewActivity : AbsThemeActivity() {
} }
// Inject color values for WebView body background and links // Inject color values for WebView body background and links
val isDark = isWindowBackgroundDark(this) val isDark = isWindowBackgroundDark(requireContext())
val accentColor = accentColor() val accentColor = accentColor()
val backgroundColor = colorToCSS( val backgroundColor = colorToCSS(
surfaceColor(Color.parseColor(if (isDark) "#424242" else "#ffffff")) surfaceColor(Color.parseColor(if (isDark) "#424242" else "#ffffff"))
@ -51,7 +63,7 @@ class WhatsNewActivity : AbsThemeActivity() {
colorToCSS(Color.parseColor(if (isDark) "#353535" else "#ffffff")) colorToCSS(Color.parseColor(if (isDark) "#353535" else "#ffffff"))
val accentTextColor = colorToCSS( val accentTextColor = colorToCSS(
getPrimaryTextColor( getPrimaryTextColor(
this, isColorLight(accentColor) requireContext(), isColorLight(accentColor)
) )
) )
val changeLog = buf.toString() val changeLog = buf.toString()
@ -72,7 +84,7 @@ class WhatsNewActivity : AbsThemeActivity() {
"<h1>Unable to load</h1><p>" + e.localizedMessage + "</p>", "text/html", "UTF-8" "<h1>Unable to load</h1><p>" + e.localizedMessage + "</p>", "text/html", "UTF-8"
) )
} }
setChangelogRead(this) setChangelogRead(requireContext())
binding.tgFab.setOnClickListener { binding.tgFab.setOnClickListener {
openUrl(Constants.TELEGRAM_CHANGE_LOG) openUrl(Constants.TELEGRAM_CHANGE_LOG)
} }
@ -86,10 +98,16 @@ class WhatsNewActivity : AbsThemeActivity() {
binding.tgFab.extend() binding.tgFab.extend()
} }
} }
binding.webView.drawAboveSystemBars() }
override fun onDestroy() {
super.onDestroy()
_binding = null
} }
companion object { companion object {
const val TAG = "WhatsNewFragment"
private fun colorToCSS(color: Int): String { private fun colorToCSS(color: Int): String {
return String.format( return String.format(
Locale.getDefault(), Locale.getDefault(),
@ -104,11 +122,20 @@ class WhatsNewActivity : AbsThemeActivity() {
private fun setChangelogRead(context: Context) { private fun setChangelogRead(context: Context) {
try { try {
val pInfo = context.packageManager.getPackageInfo(context.packageName, 0) val pInfo = context.packageManager.getPackageInfo(context.packageName, 0)
val currentVersion = pInfo.versionCode val currentVersion = PackageInfoCompat.getLongVersionCode(pInfo)
lastVersion = currentVersion lastVersion = currentVersion
} catch (e: PackageManager.NameNotFoundException) { } catch (e: PackageManager.NameNotFoundException) {
e.printStackTrace() e.printStackTrace()
} }
} }
fun showChangeLog(activity: FragmentActivity) {
val pInfo = activity.packageManager.getPackageInfo(activity.packageName, 0)
val currentVersion = PackageInfoCompat.getLongVersionCode(pInfo)
if (currentVersion > lastVersion && BuildConfig.DEBUG) {
val changelogBottomSheet = WhatsNewFragment()
changelogBottomSheet.show(activity.supportFragmentManager, TAG)
}
}
} }
} }

View file

@ -2,9 +2,11 @@ package code.name.monkey.retromusic.activities.bugreport.model
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.content.Context import android.content.Context
import android.content.pm.PackageInfo
import android.content.pm.PackageManager import android.content.pm.PackageManager
import android.os.Build import android.os.Build
import androidx.annotation.IntRange import androidx.annotation.IntRange
import androidx.core.content.pm.PackageInfoCompat
import code.name.monkey.retromusic.util.PreferenceUtil import code.name.monkey.retromusic.util.PreferenceUtil
import code.name.monkey.retromusic.util.PreferenceUtil.isAdaptiveColor import code.name.monkey.retromusic.util.PreferenceUtil.isAdaptiveColor
import code.name.monkey.retromusic.util.PreferenceUtil.languageCode import code.name.monkey.retromusic.util.PreferenceUtil.languageCode
@ -35,7 +37,7 @@ class DeviceInfo(context: Context) {
@IntRange(from = 0) @IntRange(from = 0)
private val sdkVersion = Build.VERSION.SDK_INT private val sdkVersion = Build.VERSION.SDK_INT
private var versionCode = 0 private var versionCode = 0L
private var versionName: String? = null private var versionName: String? = null
private val selectedLang: String private val selectedLang: String
fun toMarkdown(): String { fun toMarkdown(): String {
@ -96,7 +98,7 @@ class DeviceInfo(context: Context) {
null null
} }
if (packageInfo != null) { if (packageInfo != null) {
versionCode = packageInfo.versionCode versionCode = PackageInfoCompat.getLongVersionCode(packageInfo)
versionName = packageInfo.versionName versionName = packageInfo.versionName
} else { } else {
versionCode = -1 versionCode = -1

View file

@ -239,14 +239,12 @@ abstract class AbsPlayerFragment(@LayoutRes layout: Int) : AbsMainActivityFragme
protected open fun toggleFavorite(song: Song) { protected open fun toggleFavorite(song: Song) {
lifecycleScope.launch(IO) { lifecycleScope.launch(IO) {
val playlist: PlaylistEntity = libraryViewModel.favoritePlaylist() val playlist: PlaylistEntity = libraryViewModel.favoritePlaylist()
if (playlist != null) { val songEntity = song.toSongEntity(playlist.playListId)
val songEntity = song.toSongEntity(playlist.playListId) val isFavorite = libraryViewModel.isSongFavorite(song.id)
val isFavorite = libraryViewModel.isSongFavorite(song.id) if (isFavorite) {
if (isFavorite) { libraryViewModel.removeSongFromPlaylist(songEntity)
libraryViewModel.removeSongFromPlaylist(songEntity) } else {
} else { libraryViewModel.insertSongs(listOf(song.toSongEntity(playlist.playListId)))
libraryViewModel.insertSongs(listOf(song.toSongEntity(playlist.playListId)))
}
} }
libraryViewModel.forceReload(ReloadType.Playlists) libraryViewModel.forceReload(ReloadType.Playlists)
requireContext().sendBroadcast(Intent(MusicService.FAVORITE_STATE_CHANGED)) requireContext().sendBroadcast(Intent(MusicService.FAVORITE_STATE_CHANGED))

View file

@ -14,6 +14,7 @@ import com.bumptech.glide.load.resource.bitmap.BitmapTransformation
import java.security.MessageDigest import java.security.MessageDigest
@Suppress("Deprecation")
class BlurTransformation : BitmapTransformation { class BlurTransformation : BitmapTransformation {
private var context: Context? = null private var context: Context? = null

View file

@ -19,6 +19,7 @@ import android.content.Context
import android.content.Intent import android.content.Intent
import android.media.audiofx.AudioEffect import android.media.audiofx.AudioEffect
import android.widget.Toast import android.widget.Toast
import androidx.fragment.app.FragmentActivity
import code.name.monkey.retromusic.R import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.activities.* import code.name.monkey.retromusic.activities.*
import code.name.monkey.retromusic.activities.bugreport.BugReportActivity import code.name.monkey.retromusic.activities.bugreport.BugReportActivity
@ -56,10 +57,9 @@ object NavigationUtil {
) )
} }
fun gotoWhatNews(activity: Activity) { fun gotoWhatNews(activity: FragmentActivity) {
activity.startActivity( val changelogBottomSheet = WhatsNewFragment()
Intent(activity, WhatsNewActivity::class.java), null changelogBottomSheet.show(activity.supportFragmentManager, WhatsNewFragment.TAG)
)
} }
fun openEqualizer(activity: Activity) { fun openEqualizer(activity: Activity) {

View file

@ -389,9 +389,15 @@ object PreferenceUtil {
val filterLength get() = sharedPreferences.getInt(FILTER_SONG, 20) val filterLength get() = sharedPreferences.getInt(FILTER_SONG, 20)
var lastVersion var lastVersion
get() = sharedPreferences.getInt(LAST_CHANGELOG_VERSION, 0) // This was stored as an integer before now it's a long, so avoid a ClassCastException
get() = try {
sharedPreferences.getLong(LAST_CHANGELOG_VERSION, 0)
} catch (e: ClassCastException) {
sharedPreferences.edit { remove(LAST_CHANGELOG_VERSION) }
0
}
set(value) = sharedPreferences.edit { set(value) = sharedPreferences.edit {
putInt(LAST_CHANGELOG_VERSION, value) putLong(LAST_CHANGELOG_VERSION, value)
} }
var lastSleepTimerValue var lastSleepTimerValue

View file

@ -5,24 +5,6 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:fitsSystemWindows="true"> android:fitsSystemWindows="true">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="0dp"
app:liftOnScroll="true"
android:fitsSystemWindows="true">
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/toolbar"
style="@style/Toolbar"
app:layout_collapseMode="pin"
app:navigationIcon="@drawable/ic_keyboard_backspace_black"
app:title="@string/whats_new"
app:titleTextAppearance="@style/ToolbarTextAppearanceNormal" />
</com.google.android.material.appbar.AppBarLayout>
<androidx.core.widget.NestedScrollView <androidx.core.widget.NestedScrollView
android:id="@+id/container" android:id="@+id/container"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -42,8 +24,6 @@
android:id="@+id/tgFab" android:id="@+id/tgFab"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_gravity="bottom|end" android:layout_gravity="bottom|end"
android:layout_margin="16dp" android:layout_margin="16dp"
android:text="@string/view_on_telegram" android:text="@string/view_on_telegram"