Code Cleanup
This commit is contained in:
parent
8b5b6d0e64
commit
608c265390
5 changed files with 38 additions and 35 deletions
|
@ -61,7 +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)
|
||||||
}
|
}
|
||||||
WhatsNewFragment.showChangeLog(this )
|
WhatsNewFragment.showChangeLog(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupNavigationController() {
|
private fun setupNavigationController() {
|
||||||
|
|
|
@ -132,7 +132,7 @@ class WhatsNewFragment : BottomSheetDialogFragment() {
|
||||||
fun showChangeLog(activity: FragmentActivity) {
|
fun showChangeLog(activity: FragmentActivity) {
|
||||||
val pInfo = activity.packageManager.getPackageInfo(activity.packageName, 0)
|
val pInfo = activity.packageManager.getPackageInfo(activity.packageName, 0)
|
||||||
val currentVersion = PackageInfoCompat.getLongVersionCode(pInfo)
|
val currentVersion = PackageInfoCompat.getLongVersionCode(pInfo)
|
||||||
if (currentVersion > lastVersion && BuildConfig.DEBUG) {
|
if (currentVersion > lastVersion && !BuildConfig.DEBUG) {
|
||||||
val changelogBottomSheet = WhatsNewFragment()
|
val changelogBottomSheet = WhatsNewFragment()
|
||||||
changelogBottomSheet.show(activity.supportFragmentManager, TAG)
|
changelogBottomSheet.show(activity.supportFragmentManager, TAG)
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,6 +82,11 @@ class SearchFragment : AbsMainActivityFragment(R.layout.fragment_search),
|
||||||
doAfterTextChanged {
|
doAfterTextChanged {
|
||||||
if (!it.isNullOrEmpty())
|
if (!it.isNullOrEmpty())
|
||||||
search(it.toString())
|
search(it.toString())
|
||||||
|
else {
|
||||||
|
TransitionManager.beginDelayedTransition(binding.appBarLayout)
|
||||||
|
binding.voiceSearch.isVisible = true
|
||||||
|
binding.clearText.isGone = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
focusAndShowKeyboard()
|
focusAndShowKeyboard()
|
||||||
}
|
}
|
||||||
|
@ -210,13 +215,14 @@ class SearchFragment : AbsMainActivityFragment(R.layout.fragment_search),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private val speechInputLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result->
|
private val speechInputLauncher =
|
||||||
if (result.resultCode == RESULT_OK) {
|
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
|
||||||
val spokenText: String? =
|
if (result.resultCode == RESULT_OK) {
|
||||||
result?.data?.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS)?.get(0)
|
val spokenText: String? =
|
||||||
binding.searchView.setText(spokenText)
|
result?.data?.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS)?.get(0)
|
||||||
|
binding.searchView.setText(spokenText)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
override fun onDestroyView() {
|
override fun onDestroyView() {
|
||||||
hideKeyboard(view)
|
hideKeyboard(view)
|
||||||
|
|
|
@ -58,6 +58,7 @@ import code.name.monkey.retromusic.auto.AutoMusicProvider
|
||||||
import code.name.monkey.retromusic.extensions.showToast
|
import code.name.monkey.retromusic.extensions.showToast
|
||||||
import code.name.monkey.retromusic.glide.BlurTransformation
|
import code.name.monkey.retromusic.glide.BlurTransformation
|
||||||
import code.name.monkey.retromusic.glide.GlideApp
|
import code.name.monkey.retromusic.glide.GlideApp
|
||||||
|
import code.name.monkey.retromusic.glide.RetroGlideExtension.getDefaultTransition
|
||||||
import code.name.monkey.retromusic.glide.RetroGlideExtension.getSongModel
|
import code.name.monkey.retromusic.glide.RetroGlideExtension.getSongModel
|
||||||
import code.name.monkey.retromusic.helper.MusicPlayerRemote.isCasting
|
import code.name.monkey.retromusic.helper.MusicPlayerRemote.isCasting
|
||||||
import code.name.monkey.retromusic.helper.ShuffleHelper.makeShuffleList
|
import code.name.monkey.retromusic.helper.ShuffleHelper.makeShuffleList
|
||||||
|
@ -91,7 +92,6 @@ import code.name.monkey.retromusic.util.PreferenceUtil.unregisterOnSharedPrefere
|
||||||
import code.name.monkey.retromusic.volume.AudioVolumeObserver
|
import code.name.monkey.retromusic.volume.AudioVolumeObserver
|
||||||
import code.name.monkey.retromusic.volume.OnAudioVolumeChangedListener
|
import code.name.monkey.retromusic.volume.OnAudioVolumeChangedListener
|
||||||
import com.bumptech.glide.request.target.CustomTarget
|
import com.bumptech.glide.request.target.CustomTarget
|
||||||
import com.bumptech.glide.request.target.Target
|
|
||||||
import com.bumptech.glide.request.transition.Transition
|
import com.bumptech.glide.request.transition.Transition
|
||||||
import org.koin.java.KoinJavaComponent.get
|
import org.koin.java.KoinJavaComponent.get
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
@ -642,7 +642,7 @@ class MusicService : MediaBrowserServiceCompat(),
|
||||||
override fun onGetRoot(
|
override fun onGetRoot(
|
||||||
clientPackageName: String,
|
clientPackageName: String,
|
||||||
clientUid: Int,
|
clientUid: Int,
|
||||||
rootHints: Bundle?
|
rootHints: Bundle?,
|
||||||
): BrowserRoot {
|
): BrowserRoot {
|
||||||
|
|
||||||
|
|
||||||
|
@ -671,7 +671,7 @@ class MusicService : MediaBrowserServiceCompat(),
|
||||||
|
|
||||||
override fun onLoadChildren(
|
override fun onLoadChildren(
|
||||||
parentId: String,
|
parentId: String,
|
||||||
result: Result<List<MediaBrowserCompat.MediaItem>>
|
result: Result<List<MediaBrowserCompat.MediaItem>>,
|
||||||
) {
|
) {
|
||||||
if (parentId == AutoMediaIDHelper.RECENT_ROOT) {
|
if (parentId == AutoMediaIDHelper.RECENT_ROOT) {
|
||||||
val song = currentSong
|
val song = currentSong
|
||||||
|
@ -690,7 +690,7 @@ class MusicService : MediaBrowserServiceCompat(),
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onSharedPreferenceChanged(
|
override fun onSharedPreferenceChanged(
|
||||||
sharedPreferences: SharedPreferences, key: String
|
sharedPreferences: SharedPreferences, key: String,
|
||||||
) {
|
) {
|
||||||
when (key) {
|
when (key) {
|
||||||
CROSS_FADE_DURATION -> {
|
CROSS_FADE_DURATION -> {
|
||||||
|
@ -799,7 +799,7 @@ class MusicService : MediaBrowserServiceCompat(),
|
||||||
fun openQueue(
|
fun openQueue(
|
||||||
playingQueue: List<Song>?,
|
playingQueue: List<Song>?,
|
||||||
startPosition: Int,
|
startPosition: Int,
|
||||||
startPlaying: Boolean
|
startPlaying: Boolean,
|
||||||
) {
|
) {
|
||||||
if (playingQueue != null && playingQueue.isNotEmpty()
|
if (playingQueue != null && playingQueue.isNotEmpty()
|
||||||
&& startPosition >= 0 && startPosition < playingQueue.size
|
&& startPosition >= 0 && startPosition < playingQueue.size
|
||||||
|
@ -1141,10 +1141,13 @@ class MusicService : MediaBrowserServiceCompat(),
|
||||||
.putLong(MediaMetadataCompat.METADATA_KEY_NUM_TRACKS, playingQueue.size.toLong())
|
.putLong(MediaMetadataCompat.METADATA_KEY_NUM_TRACKS, playingQueue.size.toLong())
|
||||||
|
|
||||||
if (isAlbumArtOnLockScreen) {
|
if (isAlbumArtOnLockScreen) {
|
||||||
val request = GlideApp.with(this@MusicService)
|
// val screenSize: Point = RetroUtil.getScreenSize(this)
|
||||||
|
val request = GlideApp.with(this)
|
||||||
.asBitmap()
|
.asBitmap()
|
||||||
.songCoverOptions(song)
|
.songCoverOptions(song)
|
||||||
.load(getSongModel(song))
|
.load(getSongModel(song))
|
||||||
|
.transition(getDefaultTransition())
|
||||||
|
|
||||||
if (isBlurredAlbumArt) {
|
if (isBlurredAlbumArt) {
|
||||||
request.transform(BlurTransformation.Builder(this@MusicService).build())
|
request.transform(BlurTransformation.Builder(this@MusicService).build())
|
||||||
}
|
}
|
||||||
|
@ -1158,7 +1161,7 @@ class MusicService : MediaBrowserServiceCompat(),
|
||||||
|
|
||||||
override fun onResourceReady(
|
override fun onResourceReady(
|
||||||
resource: Bitmap,
|
resource: Bitmap,
|
||||||
transition: Transition<in Bitmap?>?
|
transition: Transition<in Bitmap?>?,
|
||||||
) {
|
) {
|
||||||
metaData.putBitmap(
|
metaData.putBitmap(
|
||||||
MediaMetadataCompat.METADATA_KEY_ALBUM_ART,
|
MediaMetadataCompat.METADATA_KEY_ALBUM_ART,
|
||||||
|
|
|
@ -16,18 +16,14 @@ package code.name.monkey.retromusic.util
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.res.Configuration
|
import android.content.res.Configuration
|
||||||
import android.content.res.Resources
|
import android.content.res.Resources
|
||||||
import code.name.monkey.retromusic.App.Companion.getContext
|
|
||||||
import android.view.WindowManager
|
|
||||||
import androidx.annotation.DrawableRes
|
|
||||||
import androidx.annotation.ColorInt
|
|
||||||
import android.graphics.drawable.Drawable
|
|
||||||
import code.name.monkey.appthemehelper.util.TintHelper
|
|
||||||
import android.content.res.Resources.Theme
|
import android.content.res.Resources.Theme
|
||||||
import android.graphics.Point
|
import android.graphics.Point
|
||||||
import android.view.Display
|
import android.graphics.drawable.Drawable
|
||||||
|
import androidx.annotation.ColorInt
|
||||||
|
import androidx.annotation.DrawableRes
|
||||||
import androidx.core.content.res.ResourcesCompat
|
import androidx.core.content.res.ResourcesCompat
|
||||||
import androidx.core.view.DisplayCompat
|
import code.name.monkey.appthemehelper.util.TintHelper
|
||||||
import java.lang.Exception
|
import code.name.monkey.retromusic.App.Companion.getContext
|
||||||
import java.net.InetAddress
|
import java.net.InetAddress
|
||||||
import java.net.NetworkInterface
|
import java.net.NetworkInterface
|
||||||
import java.text.DecimalFormat
|
import java.text.DecimalFormat
|
||||||
|
@ -50,14 +46,10 @@ object RetroUtil {
|
||||||
return (frequency / 1000.0).toFloat()
|
return (frequency / 1000.0).toFloat()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getScreenSize(c: Context): Point {
|
fun getScreenSize(context: Context): Point {
|
||||||
var display: Display? = null
|
val x: Int = context.resources.displayMetrics.widthPixels
|
||||||
if (c.getSystemService(Context.WINDOW_SERVICE) != null) {
|
val y: Int = context.resources.displayMetrics.heightPixels
|
||||||
display = (c.getSystemService(Context.WINDOW_SERVICE) as WindowManager).defaultDisplay
|
return Point(x, y)
|
||||||
}
|
|
||||||
val size = Point()
|
|
||||||
display?.getSize(size)
|
|
||||||
return size
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val statusBarHeight: Int
|
val statusBarHeight: Int
|
||||||
|
@ -85,7 +77,9 @@ object RetroUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getTintedVectorDrawable(
|
fun getTintedVectorDrawable(
|
||||||
context: Context, @DrawableRes id: Int, @ColorInt color: Int
|
context: Context,
|
||||||
|
@DrawableRes id: Int,
|
||||||
|
@ColorInt color: Int,
|
||||||
): Drawable {
|
): Drawable {
|
||||||
return TintHelper.createTintedDrawable(
|
return TintHelper.createTintedDrawable(
|
||||||
getVectorDrawable(context.resources, id, context.theme), color)
|
getVectorDrawable(context.resources, id, context.theme), color)
|
||||||
|
@ -95,13 +89,13 @@ object RetroUtil {
|
||||||
res: Resources,
|
res: Resources,
|
||||||
@DrawableRes resId: Int,
|
@DrawableRes resId: Int,
|
||||||
theme: Theme?,
|
theme: Theme?,
|
||||||
@ColorInt color: Int
|
@ColorInt color: Int,
|
||||||
): Drawable {
|
): Drawable {
|
||||||
return TintHelper.createTintedDrawable(getVectorDrawable(res, resId, theme), color)
|
return TintHelper.createTintedDrawable(getVectorDrawable(res, resId, theme), color)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getVectorDrawable(
|
private fun getVectorDrawable(
|
||||||
res: Resources, @DrawableRes resId: Int, theme: Theme?
|
res: Resources, @DrawableRes resId: Int, theme: Theme?,
|
||||||
): Drawable? {
|
): Drawable? {
|
||||||
return ResourcesCompat.getDrawable(res, resId, theme)
|
return ResourcesCompat.getDrawable(res, resId, theme)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue