Merge pull request #1322 from TacoTheDank/ktxExtensions

Utilize KTX extensions
This commit is contained in:
Prathamesh More 2022-04-08 20:15:10 +05:30 committed by GitHub
commit 8b100b4a17
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
56 changed files with 241 additions and 364 deletions

View file

@ -18,12 +18,12 @@ import android.Manifest
import android.content.Intent
import android.content.pm.PackageManager
import android.content.res.ColorStateList
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.provider.Settings
import androidx.annotation.RequiresApi
import androidx.core.text.HtmlCompat
import androidx.core.net.toUri
import androidx.core.text.parseAsHtml
import androidx.core.view.isVisible
import code.name.monkey.appthemehelper.ThemeStore
import code.name.monkey.appthemehelper.util.VersionUtils
@ -54,7 +54,7 @@ class PermissionActivity : AbsMusicServiceActivity() {
binding.audioPermission.setButtonClick {
if (RingtoneManager.requiresDialog(this@PermissionActivity)) {
val intent = Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS)
intent.data = Uri.parse("package:" + applicationContext.packageName)
intent.data = ("package:" + applicationContext.packageName).toUri()
startActivity(intent)
}
}
@ -77,10 +77,8 @@ class PermissionActivity : AbsMusicServiceActivity() {
private fun setupTitle() {
val color = ThemeStore.accentColor(this)
val hexColor = String.format("#%06X", 0xFFFFFF and color)
val appName = HtmlCompat.fromHtml(
"Hello there! <br>Welcome to <b>Retro <span style='color:$hexColor';>Music</span></b>",
HtmlCompat.FROM_HTML_MODE_COMPACT
)
val appName = "Hello there! <br>Welcome to <b>Retro <span style='color:$hexColor';>Music</span></b>"
.parseAsHtml()
binding.appNameText.text = appName
}

View file

@ -18,10 +18,10 @@ import android.content.res.ColorStateList
import android.graphics.Bitmap
import android.graphics.Color
import android.graphics.drawable.GradientDrawable
import android.net.Uri
import android.os.Bundle
import android.provider.MediaStore.Images.Media
import android.view.MenuItem
import androidx.core.net.toUri
import androidx.core.view.drawToBitmap
import code.name.monkey.appthemehelper.ThemeStore
import code.name.monkey.appthemehelper.util.ColorUtil
@ -87,10 +87,9 @@ class ShareInstagramStory : AbsBaseActivity() {
binding.mainContent.drawToBitmap(Bitmap.Config.ARGB_8888),
"Design", null
)
val uri = Uri.parse(path)
Share.shareStoryToSocial(
this@ShareInstagramStory,
uri
path.toUri()
)
}
}

View file

@ -25,10 +25,7 @@ import android.view.ViewTreeObserver
import android.view.animation.PathInterpolator
import android.widget.FrameLayout
import androidx.core.animation.doOnEnd
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.isGone
import androidx.core.view.isVisible
import androidx.core.view.*
import androidx.fragment.app.Fragment
import androidx.fragment.app.commit
import code.name.monkey.appthemehelper.util.VersionUtils
@ -238,9 +235,9 @@ abstract class AbsSlidingMusicPanelActivity : AbsMusicServiceActivity() {
override fun onGlobalLayout() {
binding.slidingPanel.viewTreeObserver.removeOnGlobalLayoutListener(this)
if (nowPlayingScreen != Peek) {
val params = binding.slidingPanel.layoutParams as ViewGroup.LayoutParams
params.height = ViewGroup.LayoutParams.MATCH_PARENT
binding.slidingPanel.layoutParams = params
binding.slidingPanel.updateLayoutParams<ViewGroup.LayoutParams> {
height = ViewGroup.LayoutParams.MATCH_PARENT
}
}
when (panelState) {
STATE_EXPANDED -> onPanelExpanded()

View file

@ -17,15 +17,14 @@ package code.name.monkey.retromusic.activities.bugreport
import android.content.ClipData
import android.content.ClipboardManager
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.text.TextUtils
import android.view.MenuItem
import android.view.inputmethod.EditorInfo
import android.widget.Toast
import androidx.annotation.StringDef
import androidx.annotation.StringRes
import androidx.core.content.getSystemService
import androidx.core.net.toUri
import androidx.lifecycle.lifecycleScope
import code.name.monkey.appthemehelper.ThemeStore
import code.name.monkey.appthemehelper.util.MaterialUtil
@ -81,7 +80,7 @@ open class BugReportActivity : AbsThemeActivity() {
initViews()
if (TextUtils.isEmpty(title)) setTitle(R.string.report_an_issue)
if (title.isNullOrEmpty()) setTitle(R.string.report_an_issue)
deviceInfo = DeviceInfo(this)
binding.cardDeviceInfo.airTextDeviceInfo.text = deviceInfo.toString()
@ -154,7 +153,7 @@ open class BugReportActivity : AbsThemeActivity() {
copyDeviceInfoToClipBoard()
val i = Intent(Intent.ACTION_VIEW)
i.data = Uri.parse(ISSUE_TRACKER_LINK)
i.data = ISSUE_TRACKER_LINK.toUri()
i.flags = Intent.FLAG_ACTIVITY_NEW_TASK
startActivity(i)
}
@ -175,14 +174,14 @@ open class BugReportActivity : AbsThemeActivity() {
var hasErrors = false
if (binding.cardReport.optionUseAccount.isChecked) {
if (TextUtils.isEmpty(binding.cardReport.inputUsername.text)) {
if (binding.cardReport.inputUsername.text.isNullOrEmpty()) {
setError(binding.cardReport.inputLayoutUsername, R.string.bug_report_no_username)
hasErrors = true
} else {
removeError(binding.cardReport.inputLayoutUsername)
}
if (TextUtils.isEmpty(binding.cardReport.inputPassword.text)) {
if (binding.cardReport.inputPassword.text.isNullOrEmpty()) {
setError(binding.cardReport.inputLayoutPassword, R.string.bug_report_no_password)
hasErrors = true
} else {
@ -190,14 +189,14 @@ open class BugReportActivity : AbsThemeActivity() {
}
}
if (TextUtils.isEmpty(binding.cardReport.inputTitle.text)) {
if (binding.cardReport.inputTitle.text.isNullOrEmpty()) {
setError(binding.cardReport.inputLayoutTitle, R.string.bug_report_no_title)
hasErrors = true
} else {
removeError(binding.cardReport.inputLayoutTitle)
}
if (TextUtils.isEmpty(binding.cardReport.inputDescription.text)) {
if (binding.cardReport.inputDescription.text.isNullOrEmpty()) {
setError(binding.cardReport.inputLayoutDescription, R.string.bug_report_no_description)
hasErrors = true
} else {
@ -225,7 +224,7 @@ open class BugReportActivity : AbsThemeActivity() {
onSaveExtraInfo()
val report = Report(bugTitle, bugDescription, deviceInfo, extraInfo)
val target = GithubTarget("prathameshmm02", "RetroMusicPlayer")
val target = GithubTarget("RetroMusicPlayer", "RetroMusicPlayer")
reportIssue(report, target, login)
}
@ -315,6 +314,6 @@ open class BugReportActivity : AbsThemeActivity() {
private const val STATUS_BAD_CREDENTIALS = 401
private const val STATUS_ISSUES_NOT_ENABLED = 410
private const val ISSUE_TRACKER_LINK = "https://github.com/prathameshmm02/RetroMusicPlayer"
private const val ISSUE_TRACKER_LINK = "https://github.com/RetroMusicPlayer/RetroMusicPlayer"
}
}

View file

@ -22,12 +22,11 @@ import android.graphics.Color
import android.graphics.drawable.Drawable
import android.net.Uri
import android.os.Bundle
import android.text.Editable
import android.text.TextWatcher
import android.transition.Slide
import android.view.LayoutInflater
import android.widget.ImageView
import android.widget.Toast
import androidx.core.widget.doAfterTextChanged
import code.name.monkey.appthemehelper.util.MaterialValueHelper
import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.databinding.ActivityAlbumTagEditorBinding
@ -50,7 +49,7 @@ import com.google.android.material.shape.MaterialShapeDrawable
import org.jaudiotagger.tag.FieldKey
import java.util.*
class AlbumTagEditorActivity : AbsTagEditorActivity<ActivityAlbumTagEditorBinding>(), TextWatcher {
class AlbumTagEditorActivity : AbsTagEditorActivity<ActivityAlbumTagEditorBinding>() {
override val bindingInflater: (LayoutInflater) -> ActivityAlbumTagEditorBinding =
ActivityAlbumTagEditorBinding::inflate
@ -91,10 +90,10 @@ class AlbumTagEditorActivity : AbsTagEditorActivity<ActivityAlbumTagEditorBindin
binding.albumTitleContainer.setTint(false)
binding.albumArtistContainer.setTint(false)
binding.albumText.appHandleColor().addTextChangedListener(this)
binding.albumArtistText.appHandleColor().addTextChangedListener(this)
binding.genreTitle.appHandleColor().addTextChangedListener(this)
binding.yearTitle.appHandleColor().addTextChangedListener(this)
binding.albumText.appHandleColor().doAfterTextChanged { dataChanged() }
binding.albumArtistText.appHandleColor().doAfterTextChanged { dataChanged() }
binding.genreTitle.appHandleColor().doAfterTextChanged { dataChanged() }
binding.yearTitle.appHandleColor().doAfterTextChanged { dataChanged() }
}
private fun fillViewsWithFileTags() {
@ -198,17 +197,6 @@ class AlbumTagEditorActivity : AbsTagEditorActivity<ActivityAlbumTagEditorBindin
MusicUtil.getSongFileUri(it.id)
}
override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {
}
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
}
override fun afterTextChanged(s: Editable) {
dataChanged()
}
override fun setColors(color: Int) {
super.setColors(color)
saveFab.backgroundTintList = ColorStateList.valueOf(color)

View file

@ -23,11 +23,10 @@ import android.graphics.Color
import android.graphics.drawable.Drawable
import android.net.Uri
import android.os.Bundle
import android.text.Editable
import android.text.TextWatcher
import android.view.LayoutInflater
import android.widget.ImageView
import android.widget.Toast
import androidx.core.widget.doAfterTextChanged
import code.name.monkey.appthemehelper.util.MaterialValueHelper
import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.databinding.ActivitySongTagEditorBinding
@ -50,7 +49,7 @@ import org.jaudiotagger.tag.FieldKey
import org.koin.android.ext.android.inject
import java.util.*
class SongTagEditorActivity : AbsTagEditorActivity<ActivitySongTagEditorBinding>(), TextWatcher {
class SongTagEditorActivity : AbsTagEditorActivity<ActivitySongTagEditorBinding>() {
override val bindingInflater: (LayoutInflater) -> ActivitySongTagEditorBinding =
ActivitySongTagEditorBinding::inflate
@ -83,16 +82,16 @@ class SongTagEditorActivity : AbsTagEditorActivity<ActivitySongTagEditorBinding>
binding.discNumberContainer.setTint(false)
binding.lyricsContainer.setTint(false)
binding.songText.appHandleColor().addTextChangedListener(this)
binding.albumText.appHandleColor().addTextChangedListener(this)
binding.albumArtistText.appHandleColor().addTextChangedListener(this)
binding.artistText.appHandleColor().addTextChangedListener(this)
binding.genreText.appHandleColor().addTextChangedListener(this)
binding.yearText.appHandleColor().addTextChangedListener(this)
binding.trackNumberText.appHandleColor().addTextChangedListener(this)
binding.discNumberText.appHandleColor().addTextChangedListener(this)
binding.lyricsText.appHandleColor().addTextChangedListener(this)
binding.songComposerText.appHandleColor().addTextChangedListener(this)
binding.songText.appHandleColor().doAfterTextChanged { dataChanged() }
binding.albumText.appHandleColor().doAfterTextChanged { dataChanged() }
binding.albumArtistText.appHandleColor().doAfterTextChanged { dataChanged() }
binding.artistText.appHandleColor().doAfterTextChanged { dataChanged() }
binding.genreText.appHandleColor().doAfterTextChanged { dataChanged() }
binding.yearText.appHandleColor().doAfterTextChanged { dataChanged() }
binding.trackNumberText.appHandleColor().doAfterTextChanged { dataChanged() }
binding.discNumberText.appHandleColor().doAfterTextChanged { dataChanged() }
binding.lyricsText.appHandleColor().doAfterTextChanged { dataChanged() }
binding.songComposerText.appHandleColor().doAfterTextChanged { dataChanged() }
}
private fun fillViewsWithFileTags() {
@ -205,16 +204,6 @@ class SongTagEditorActivity : AbsTagEditorActivity<ActivitySongTagEditorBinding>
})
}
override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {
}
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
}
override fun afterTextChanged(s: Editable) {
dataChanged()
}
companion object {
val TAG: String = SongTagEditorActivity::class.java.simpleName
}

View file

@ -19,6 +19,7 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import androidx.core.os.bundleOf
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.lifecycle.lifecycleScope
@ -205,9 +206,7 @@ class AlbumCoverPagerAdapter(
fun newInstance(song: Song): AlbumCoverFragment {
val frag = AlbumCoverFragment()
val args = Bundle()
args.putParcelable(SONG_ARG, song)
frag.arguments = args
frag.arguments = bundleOf(SONG_ARG to song)
return frag
}
}

View file

@ -15,12 +15,12 @@
package code.name.monkey.retromusic.adapter.playlist
import android.graphics.Color
import android.text.TextUtils
import android.view.LayoutInflater
import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.widget.PopupMenu
import androidx.core.view.isGone
import androidx.core.view.setPadding
import androidx.fragment.app.FragmentActivity
import code.name.monkey.retromusic.R
@ -30,8 +30,6 @@ import code.name.monkey.retromusic.db.PlaylistEntity
import code.name.monkey.retromusic.db.PlaylistWithSongs
import code.name.monkey.retromusic.db.toSongs
import code.name.monkey.retromusic.extensions.dipToPix
import code.name.monkey.retromusic.extensions.hide
import code.name.monkey.retromusic.extensions.show
import code.name.monkey.retromusic.glide.GlideApp
import code.name.monkey.retromusic.glide.playlistPreview.PlaylistPreview
import code.name.monkey.retromusic.helper.SortOrder.PlaylistSortOrder
@ -79,7 +77,7 @@ class PlaylistAdapter(
}
private fun getPlaylistTitle(playlist: PlaylistEntity): String {
return if (TextUtils.isEmpty(playlist.playlistName)) "-" else playlist.playlistName
return playlist.playlistName.ifEmpty { "-" }
}
private fun getPlaylistText(playlist: PlaylistWithSongs): String {
@ -102,12 +100,7 @@ class PlaylistAdapter(
holder.itemView.isActivated = isChecked(playlist)
holder.title?.text = getPlaylistTitle(playlist.playlistEntity)
holder.text?.text = getPlaylistText(playlist)
val isChecked = isChecked(playlist)
if (isChecked) {
holder.menu?.hide()
} else {
holder.menu?.show()
}
holder.menu?.isGone = isChecked(playlist)
GlideApp.with(activity)
.load(
if (itemLayoutRes == R.layout.item_list) {

View file

@ -21,6 +21,7 @@ import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import androidx.core.os.bundleOf
import androidx.core.view.isGone
import androidx.core.view.isVisible
import androidx.fragment.app.FragmentActivity
import androidx.navigation.findNavController
@ -28,8 +29,6 @@ import code.name.monkey.retromusic.EXTRA_ALBUM_ID
import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.adapter.base.AbsMultiSelectAdapter
import code.name.monkey.retromusic.adapter.base.MediaEntryViewHolder
import code.name.monkey.retromusic.extensions.hide
import code.name.monkey.retromusic.extensions.show
import code.name.monkey.retromusic.glide.GlideApp
import code.name.monkey.retromusic.glide.RetroGlideExtension
import code.name.monkey.retromusic.glide.RetroMusicColoredTarget
@ -96,11 +95,7 @@ open class SongAdapter(
val song = dataSet[position]
val isChecked = isChecked(song)
holder.itemView.isActivated = isChecked
if (isChecked) {
holder.menu?.hide()
} else {
holder.menu?.show()
}
holder.menu?.isGone = isChecked
holder.title?.text = getSongTitle(song)
holder.text?.text = getSongText(song)
holder.text2?.text = getSongText(song)

View file

@ -16,13 +16,14 @@ package code.name.monkey.retromusic.appshortcuts
import android.content.Context
import android.graphics.Bitmap
import android.graphics.Canvas
import android.graphics.drawable.Drawable
import android.graphics.drawable.Icon
import android.graphics.drawable.LayerDrawable
import android.os.Build
import android.util.TypedValue
import androidx.annotation.RequiresApi
import androidx.core.graphics.applyCanvas
import androidx.core.graphics.createBitmap
import code.name.monkey.appthemehelper.ThemeStore
import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.util.PreferenceUtil
@ -79,12 +80,9 @@ object AppShortcutIconGenerator {
}
private fun drawableToBitmap(drawable: Drawable): Bitmap {
val bitmap = Bitmap.createBitmap(
drawable.intrinsicWidth, drawable.intrinsicHeight, Bitmap.Config.ARGB_8888
)
val canvas = Canvas(bitmap)
drawable.setBounds(0, 0, canvas.width, canvas.height)
drawable.draw(canvas)
return bitmap
return createBitmap(drawable.intrinsicWidth, drawable.intrinsicHeight).applyCanvas {
drawable.setBounds(0, 0, width, height)
drawable.draw(this)
}
}
}

View file

@ -17,6 +17,7 @@ package code.name.monkey.retromusic.appshortcuts
import android.app.Activity
import android.content.Intent
import android.os.Bundle
import androidx.core.os.bundleOf
import code.name.monkey.retromusic.appshortcuts.shortcuttype.LastAddedShortcutType
import code.name.monkey.retromusic.appshortcuts.shortcuttype.ShuffleAllShortcutType
import code.name.monkey.retromusic.appshortcuts.shortcuttype.TopTracksShortcutType
@ -63,9 +64,10 @@ class AppShortcutLauncherActivity : Activity() {
val intent = Intent(this, MusicService::class.java)
intent.action = ACTION_PLAY_PLAYLIST
val bundle = Bundle()
bundle.putParcelable(INTENT_EXTRA_PLAYLIST, playlist)
bundle.putInt(INTENT_EXTRA_SHUFFLE_MODE, shuffleMode)
val bundle = bundleOf(
INTENT_EXTRA_PLAYLIST to playlist,
INTENT_EXTRA_SHUFFLE_MODE to shuffleMode
)
intent.putExtras(bundle)

View file

@ -19,7 +19,7 @@ import android.content.Context
import android.content.Intent
import android.content.pm.ShortcutInfo
import android.os.Build
import android.os.Bundle
import androidx.core.os.bundleOf
import code.name.monkey.retromusic.appshortcuts.AppShortcutLauncherActivity
@TargetApi(Build.VERSION_CODES.N_MR1)
@ -36,8 +36,7 @@ abstract class BaseShortcutType(internal var context: Context) {
internal fun getPlaySongsIntent(shortcutType: Long): Intent {
val intent = Intent(context, AppShortcutLauncherActivity::class.java)
intent.action = Intent.ACTION_VIEW
val b = Bundle()
b.putLong(AppShortcutLauncherActivity.KEY_SHORTCUT_TYPE, shortcutType)
val b = bundleOf(AppShortcutLauncherActivity.KEY_SHORTCUT_TYPE to shortcutType)
intent.putExtras(b)
return intent
}

View file

@ -20,7 +20,6 @@ import android.content.Context
import android.content.Intent
import android.graphics.Bitmap
import android.graphics.drawable.Drawable
import android.text.TextUtils
import android.view.View
import android.widget.RemoteViews
import code.name.monkey.appthemehelper.util.MaterialValueHelper
@ -102,7 +101,7 @@ class AppWidgetBig : BaseAppWidget() {
val song = service.currentSong
// Set the titles and artwork
if (TextUtils.isEmpty(song.title) && TextUtils.isEmpty(song.artistName)) {
if (song.title.isEmpty() && song.artistName.isEmpty()) {
appWidgetView.setViewVisibility(
R.id.media_titles,
View.INVISIBLE

View file

@ -20,7 +20,6 @@ import android.content.Context
import android.content.Intent
import android.graphics.Bitmap
import android.graphics.drawable.Drawable
import android.text.TextUtils
import android.view.View
import android.widget.RemoteViews
import code.name.monkey.appthemehelper.util.MaterialValueHelper
@ -98,7 +97,7 @@ class AppWidgetCard : BaseAppWidget() {
val song = service.currentSong
// Set the titles and artwork
if (TextUtils.isEmpty(song.title) && TextUtils.isEmpty(song.artistName)) {
if (song.title.isEmpty() && song.artistName.isEmpty()) {
appWidgetView.setViewVisibility(R.id.media_titles, View.INVISIBLE)
} else {
appWidgetView.setViewVisibility(R.id.media_titles, View.VISIBLE)

View file

@ -21,7 +21,6 @@ import android.content.Intent
import android.graphics.Bitmap
import android.graphics.Color
import android.graphics.drawable.Drawable
import android.text.TextUtils
import android.view.View
import android.widget.RemoteViews
import code.name.monkey.appthemehelper.util.MaterialValueHelper
@ -101,7 +100,7 @@ class AppWidgetClassic : BaseAppWidget() {
val song = service.currentSong
// Set the titles and artwork
if (TextUtils.isEmpty(song.title) && TextUtils.isEmpty(song.artistName)) {
if (song.title.isEmpty() && song.artistName.isEmpty()) {
appWidgetView.setViewVisibility(R.id.media_titles, View.INVISIBLE)
} else {
appWidgetView.setViewVisibility(R.id.media_titles, View.VISIBLE)

View file

@ -20,7 +20,6 @@ import android.content.Context
import android.content.Intent
import android.graphics.Bitmap
import android.graphics.drawable.Drawable
import android.text.TextUtils
import android.view.View
import android.widget.RemoteViews
import code.name.monkey.appthemehelper.util.MaterialValueHelper
@ -99,7 +98,7 @@ class AppWidgetMD3 : BaseAppWidget() {
val song = service.currentSong
// Set the titles and artwork
if (TextUtils.isEmpty(song.title) && TextUtils.isEmpty(song.artistName)) {
if (song.title.isEmpty() && song.artistName.isEmpty()) {
appWidgetView.setViewVisibility(R.id.media_titles, View.INVISIBLE)
} else {
appWidgetView.setViewVisibility(R.id.media_titles, View.VISIBLE)

View file

@ -20,7 +20,6 @@ import android.content.Context
import android.content.Intent
import android.graphics.Bitmap
import android.graphics.drawable.Drawable
import android.text.TextUtils
import android.view.View
import android.widget.RemoteViews
import code.name.monkey.appthemehelper.util.MaterialValueHelper
@ -99,10 +98,10 @@ class AppWidgetSmall : BaseAppWidget() {
val song = service.currentSong
// Set the titles and artwork
if (TextUtils.isEmpty(song.title) && TextUtils.isEmpty(song.artistName)) {
if (song.title.isEmpty() && song.artistName.isEmpty()) {
appWidgetView.setViewVisibility(R.id.media_titles, View.INVISIBLE)
} else {
if (TextUtils.isEmpty(song.title) || TextUtils.isEmpty(song.artistName)) {
if (song.title.isEmpty() || song.artistName.isEmpty()) {
appWidgetView.setTextViewText(R.id.text_separator, "")
} else {
appWidgetView.setTextViewText(R.id.text_separator, "")

View file

@ -18,7 +18,6 @@ import android.app.PendingIntent
import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.text.TextUtils
import android.view.View
import android.widget.RemoteViews
import androidx.core.content.ContextCompat
@ -119,7 +118,7 @@ class AppWidgetText : BaseAppWidget() {
val song = service.currentSong
// Set the titles and artwork
if (TextUtils.isEmpty(song.title) && TextUtils.isEmpty(song.artistName)) {
if (song.title.isEmpty() && song.artistName.isEmpty()) {
appWidgetView.setViewVisibility(R.id.media_titles, View.INVISIBLE)
} else {
appWidgetView.setViewVisibility(R.id.media_titles, View.VISIBLE)

View file

@ -24,9 +24,10 @@ import android.content.res.Resources
import android.graphics.*
import android.graphics.drawable.BitmapDrawable
import android.graphics.drawable.Drawable
import android.text.TextUtils
import android.widget.RemoteViews
import androidx.core.content.ContextCompat
import androidx.core.graphics.applyCanvas
import androidx.core.graphics.createBitmap
import code.name.monkey.appthemehelper.util.VersionUtils
import code.name.monkey.retromusic.App
import code.name.monkey.retromusic.R
@ -126,7 +127,7 @@ abstract class BaseAppWidget : AppWidgetProvider() {
protected fun getSongArtistAndAlbum(song: Song): String {
val builder = StringBuilder()
builder.append(song.artistName)
if (!TextUtils.isEmpty(song.artistName) && !TextUtils.isEmpty(song.albumName)) {
if (song.artistName.isNotEmpty() && song.albumName.isNotEmpty()) {
builder.append("")
}
builder.append(song.albumName)
@ -171,15 +172,13 @@ abstract class BaseAppWidget : AppWidgetProvider() {
}
fun createBitmap(drawable: Drawable, sizeMultiplier: Float): Bitmap {
val bitmap = Bitmap.createBitmap(
return createBitmap(
(drawable.intrinsicWidth * sizeMultiplier).toInt(),
(drawable.intrinsicHeight * sizeMultiplier).toInt(),
Bitmap.Config.ARGB_8888
)
val c = Canvas(bitmap)
drawable.setBounds(0, 0, c.width, c.height)
drawable.draw(c)
return bitmap
).applyCanvas {
drawable.setBounds(0, 0, this.width, this.height)
drawable.draw(this)
}
}
protected fun composeRoundedRectPath(

View file

@ -2,9 +2,9 @@ package code.name.monkey.retromusic.auto
import android.content.Context
import android.net.Uri
import android.os.Bundle
import android.support.v4.media.MediaBrowserCompat
import android.support.v4.media.MediaDescriptionCompat
import androidx.core.os.bundleOf
import code.name.monkey.retromusic.util.ImageUtil
@ -55,15 +55,14 @@ internal object AutoMediaItem {
fun gridLayout(isGrid: Boolean): Builder {
val hints = Bundle()
hints.putBoolean(CONTENT_STYLE_SUPPORTED, true)
hints.putInt(
CONTENT_STYLE_BROWSABLE_HINT,
if (isGrid) CONTENT_STYLE_GRID_ITEM_HINT_VALUE else CONTENT_STYLE_LIST_ITEM_HINT_VALUE
)
hints.putInt(
CONTENT_STYLE_PLAYABLE_HINT,
if (isGrid) CONTENT_STYLE_GRID_ITEM_HINT_VALUE else CONTENT_STYLE_LIST_ITEM_HINT_VALUE
val hints = bundleOf(
CONTENT_STYLE_SUPPORTED to true,
CONTENT_STYLE_BROWSABLE_HINT to
if (isGrid) CONTENT_STYLE_GRID_ITEM_HINT_VALUE
else CONTENT_STYLE_LIST_ITEM_HINT_VALUE,
CONTENT_STYLE_PLAYABLE_HINT to
if (isGrid) CONTENT_STYLE_GRID_ITEM_HINT_VALUE
else CONTENT_STYLE_LIST_ITEM_HINT_VALUE
)
mBuilder?.setExtras(hints)
return this

View file

@ -17,7 +17,7 @@ package code.name.monkey.retromusic.dialogs
import android.app.Dialog
import android.os.Bundle
import androidx.core.os.bundleOf
import androidx.core.text.HtmlCompat
import androidx.core.text.parseAsHtml
import androidx.fragment.app.DialogFragment
import code.name.monkey.retromusic.EXTRA_PLAYLIST
import code.name.monkey.retromusic.R
@ -55,16 +55,10 @@ class DeletePlaylistDialog : DialogFragment() {
//noinspection ConstantConditions
if (playlists.size > 1) {
title = R.string.delete_playlists_title
message = HtmlCompat.fromHtml(
String.format(getString(R.string.delete_x_playlists), playlists.size),
HtmlCompat.FROM_HTML_MODE_LEGACY
)
message = String.format(getString(R.string.delete_x_playlists), playlists.size).parseAsHtml()
} else {
title = R.string.delete_playlist_title
message = HtmlCompat.fromHtml(
String.format(getString(R.string.delete_playlist_x), playlists[0].playlistName),
HtmlCompat.FROM_HTML_MODE_LEGACY
)
message = String.format(getString(R.string.delete_playlist_x), playlists[0].playlistName).parseAsHtml()
}
return materialDialog(title)

View file

@ -22,7 +22,7 @@ import android.provider.MediaStore
import androidx.activity.result.IntentSenderRequest
import androidx.activity.result.contract.ActivityResultContracts
import androidx.core.os.bundleOf
import androidx.core.text.HtmlCompat
import androidx.core.text.parseAsHtml
import androidx.fragment.app.DialogFragment
import code.name.monkey.appthemehelper.util.VersionUtils
import code.name.monkey.retromusic.EXTRA_SONG
@ -87,18 +87,12 @@ class DeleteSongsDialog : DialogFragment() {
val pair = if (songs.size > 1) {
Pair(
R.string.delete_songs_title,
HtmlCompat.fromHtml(
String.format(getString(R.string.delete_x_songs), songs.size),
HtmlCompat.FROM_HTML_MODE_LEGACY
)
String.format(getString(R.string.delete_x_songs), songs.size).parseAsHtml()
)
} else {
Pair(
R.string.delete_song_title,
HtmlCompat.fromHtml(
String.format(getString(R.string.delete_song_x), songs[0].title),
HtmlCompat.FROM_HTML_MODE_LEGACY
)
String.format(getString(R.string.delete_song_x), songs[0].title).parseAsHtml()
)
}

View file

@ -17,7 +17,7 @@ package code.name.monkey.retromusic.dialogs
import android.app.Dialog
import android.os.Bundle
import androidx.core.os.bundleOf
import androidx.core.text.HtmlCompat
import androidx.core.text.parseAsHtml
import androidx.fragment.app.DialogFragment
import code.name.monkey.retromusic.EXTRA_SONG
import code.name.monkey.retromusic.R
@ -52,21 +52,16 @@ class RemoveSongFromPlaylistDialog : DialogFragment() {
val pair = if (songs.size > 1) {
Pair(
R.string.remove_songs_from_playlist_title,
HtmlCompat.fromHtml(
String.format(getString(R.string.remove_x_songs_from_playlist), songs.size),
HtmlCompat.FROM_HTML_MODE_LEGACY
)
String.format(getString(R.string.remove_x_songs_from_playlist), songs.size)
.parseAsHtml()
)
} else {
Pair(
R.string.remove_song_from_playlist_title,
HtmlCompat.fromHtml(
String.format(
getString(R.string.remove_song_x_from_playlist),
songs[0].title
),
HtmlCompat.FROM_HTML_MODE_LEGACY
)
String.format(
getString(R.string.remove_song_x_from_playlist),
songs[0].title
).parseAsHtml()
)
}
return materialDialog(pair.first)

View file

@ -23,7 +23,7 @@ import android.view.LayoutInflater
import android.widget.TextView
import androidx.annotation.NonNull
import androidx.core.os.bundleOf
import androidx.core.text.HtmlCompat
import androidx.core.text.parseAsHtml
import androidx.fragment.app.DialogFragment
import code.name.monkey.retromusic.EXTRA_SONG
import code.name.monkey.retromusic.R
@ -167,10 +167,8 @@ class SongDetailDialog : DialogFragment() {
}
private fun makeTextWithTitle(context: Context, titleResId: Int, text: String?): Spanned {
return HtmlCompat.fromHtml(
"<b>" + context.resources.getString(titleResId) + ": " + "</b>" + text,
HtmlCompat.FROM_HTML_MODE_LEGACY
)
return ("<b>" + context.resources.getString(titleResId) + ": " + "</b>" + text)
.parseAsHtml()
}
private fun getFileSizeString(sizeInBytes: Long): String {

View file

@ -1,7 +1,7 @@
package code.name.monkey.retromusic.extensions
import android.net.Uri
import android.webkit.MimeTypeMap
import androidx.core.net.toUri
import code.name.monkey.retromusic.model.Song
import code.name.monkey.retromusic.util.RetroUtil
import org.jaudiotagger.audio.AudioFileIO
@ -14,7 +14,7 @@ fun getSongInfo(song: Song): String {
return try {
val audioHeader = AudioFileIO.read(File(song.data)).audioHeader
val string: StringBuilder = StringBuilder()
val uriFile = Uri.fromFile(file)
val uriFile = file.toUri()
string.append(getMimeType(uriFile.toString())).append("")
string.append(audioHeader.bitRate).append(" kb/s").append("")
string.append(RetroUtil.frequencyCount(audioHeader.sampleRate.toInt()))

View file

@ -67,11 +67,7 @@ fun View.translateYAnimate(value: Float): Animator {
bringToFront()
}
doOnEnd {
if (value != 0f) {
hide()
} else {
show()
}
isGone = (value != 0f)
}
start()
}

View file

@ -16,10 +16,10 @@ package code.name.monkey.retromusic.fragments.about
import android.content.Intent
import android.content.pm.PackageManager
import android.net.Uri
import android.os.Bundle
import android.view.View
import androidx.core.app.ShareCompat
import androidx.core.net.toUri
import androidx.core.view.updatePadding
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.DefaultItemAnimator
@ -55,7 +55,7 @@ class AboutFragment : Fragment(R.layout.fragment_about), View.OnClickListener {
private fun openUrl(url: String) {
val i = Intent(Intent.ACTION_VIEW)
i.data = Uri.parse(url)
i.data = url.toUri()
i.flags = Intent.FLAG_ACTIVITY_NEW_TASK
startActivity(i)
}

View file

@ -22,7 +22,7 @@ import android.view.*
import androidx.activity.addCallback
import androidx.appcompat.app.AppCompatActivity
import androidx.core.os.bundleOf
import androidx.core.text.HtmlCompat
import androidx.core.text.parseAsHtml
import androidx.core.view.doOnPreDraw
import androidx.lifecycle.lifecycleScope
import androidx.navigation.fragment.FragmentNavigatorExtras
@ -282,10 +282,8 @@ class AlbumDetailsFragment : AbsMainActivityFragment(R.layout.fragment_album_det
binding.fragmentAlbumContent.aboutAlbumTitle.show()
binding.fragmentAlbumContent.aboutAlbumTitle.text =
String.format(getString(R.string.about_album_label), lastFmAlbum.album.name)
binding.fragmentAlbumContent.aboutAlbumText.text = HtmlCompat.fromHtml(
lastFmAlbum.album.wiki.content,
HtmlCompat.FROM_HTML_MODE_LEGACY
)
binding.fragmentAlbumContent.aboutAlbumText.text =
lastFmAlbum.album.wiki.content.parseAsHtml()
}
if (lastFmAlbum.album.listeners.isNotEmpty()) {
binding.fragmentAlbumContent.listeners.show()

View file

@ -12,7 +12,7 @@ import android.view.View
import androidx.activity.addCallback
import androidx.appcompat.widget.PopupMenu
import androidx.core.os.bundleOf
import androidx.core.text.HtmlCompat
import androidx.core.text.parseAsHtml
import androidx.core.view.doOnPreDraw
import androidx.core.view.isVisible
import androidx.lifecycle.lifecycleScope
@ -194,7 +194,7 @@ abstract class AbsArtistDetailsFragment : AbsMainActivityFragment(R.layout.fragm
binding.fragmentArtistContent.run {
biographyText.isVisible = true
biographyTitle.isVisible = true
biography = HtmlCompat.fromHtml(bioContent, HtmlCompat.FROM_HTML_MODE_LEGACY)
biography = bioContent.parseAsHtml()
biographyText.text = biography
if (lastFmArtist.artist.stats.listeners.isNotEmpty()) {
listeners.show()

View file

@ -27,6 +27,8 @@ import android.widget.SeekBar
import android.widget.TextView
import androidx.annotation.LayoutRes
import androidx.core.view.isVisible
import androidx.fragment.app.commit
import androidx.fragment.app.replace
import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.fragments.MusicSeekSkipTouchListener
import code.name.monkey.retromusic.fragments.other.VolumeFragment
@ -217,8 +219,9 @@ abstract class AbsPlayerControlsFragment(@LayoutRes layout: Int) : AbsMusicServi
private fun hideVolumeIfAvailable() {
if (PreferenceUtil.isVolumeVisibilityMode) {
childFragmentManager.beginTransaction()
.replace(R.id.volumeFragmentContainer, VolumeFragment()).commit()
childFragmentManager.commit {
replace<VolumeFragment>(R.id.volumeFragmentContainer)
}
childFragmentManager.executePendingTransactions()
}
volumeFragment =

View file

@ -22,7 +22,7 @@ import android.view.MenuItem.SHOW_AS_ACTION_IF_ROOM
import android.view.View
import androidx.activity.addCallback
import androidx.core.os.bundleOf
import androidx.core.text.HtmlCompat
import androidx.core.text.parseAsHtml
import androidx.core.view.doOnLayout
import androidx.core.view.doOnPreDraw
import androidx.core.view.isVisible
@ -171,10 +171,7 @@ class HomeFragment :
findNavController().navigate(R.id.action_search, null, navOptions)
}
val hexColor = String.format("#%06X", 0xFFFFFF and accentColor())
val appName = HtmlCompat.fromHtml(
"Retro <span style='color:$hexColor';>Music</span>",
HtmlCompat.FROM_HTML_MODE_COMPACT
)
val appName = "Retro <span style='color:$hexColor';>Music</span>".parseAsHtml()
binding.appNameText.text = appName
}

View file

@ -19,7 +19,7 @@ import android.view.Menu
import android.view.MenuInflater
import android.view.MenuItem
import android.view.View
import androidx.core.text.HtmlCompat
import androidx.core.text.parseAsHtml
import androidx.navigation.fragment.NavHostFragment
import androidx.navigation.fragment.findNavController
import androidx.navigation.ui.NavigationUI
@ -66,10 +66,7 @@ class LibraryFragment : AbsMainActivityFragment(R.layout.fragment_library) {
private fun setupTitle() {
val color = ThemeStore.accentColor(requireContext())
val hexColor = String.format("#%06X", 0xFFFFFF and color)
val appName = HtmlCompat.fromHtml(
"Retro <span style='color:$hexColor';>Music</span>",
HtmlCompat.FROM_HTML_MODE_COMPACT
)
val appName = "Retro <span style='color:$hexColor';>Music</span>".parseAsHtml()
binding.appNameText.text = appName
}

View file

@ -2,7 +2,6 @@ package code.name.monkey.retromusic.fragments.other
import android.content.SharedPreferences
import android.os.Bundle
import android.text.TextUtils
import android.view.View
import android.widget.FrameLayout
import android.widget.TextView
@ -92,9 +91,7 @@ class CoverLyricsFragment : AbsMusicServiceFragment(R.layout.fragment_cover_lyri
val lrcFile: File? = LyricUtil.getSyncedLyricsFile(song)
val data: String = LyricUtil.getStringFromLrc(lrcFile)
Lyrics.parse(song,
if (!TextUtils.isEmpty(data)) {
data
} else {
data.ifEmpty {
// Get Embedded Lyrics
LyricUtil.getEmbeddedSyncedLyrics(song.data)
}

View file

@ -18,13 +18,14 @@ import android.animation.ObjectAnimator
import android.annotation.SuppressLint
import android.content.Context
import android.os.Bundle
import android.text.SpannableString
import android.text.SpannableStringBuilder
import android.text.style.ForegroundColorSpan
import android.view.GestureDetector
import android.view.MotionEvent
import android.view.View
import android.view.animation.DecelerateInterpolator
import androidx.core.text.toSpannable
import androidx.core.view.isVisible
import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.databinding.FragmentMiniPlayerBinding
import code.name.monkey.retromusic.extensions.accentColor
@ -70,10 +71,8 @@ open class MiniPlayerFragment : AbsMusicServiceFragment(R.layout.fragment_mini_p
binding.actionNext.show()
binding.actionPrevious.show()
} else {
binding.actionNext.visibility =
if (PreferenceUtil.isExtraControls) View.VISIBLE else View.GONE
binding.actionPrevious.visibility =
if (PreferenceUtil.isExtraControls) View.VISIBLE else View.GONE
binding.actionNext.isVisible = PreferenceUtil.isExtraControls
binding.actionPrevious.isVisible = PreferenceUtil.isExtraControls
}
binding.actionNext.setOnClickListener(this)
binding.actionPrevious.setOnClickListener(this)
@ -94,10 +93,10 @@ open class MiniPlayerFragment : AbsMusicServiceFragment(R.layout.fragment_mini_p
val builder = SpannableStringBuilder()
val title = SpannableString(song.title)
val title = song.title.toSpannable()
title.setSpan(ForegroundColorSpan(textColorPrimary()), 0, title.length, 0)
val text = SpannableString(song.artistName)
val text = song.artistName.toSpannable()
text.setSpan(ForegroundColorSpan(textColorSecondary()), 0, text.length, 0)
builder.append(title).append("").append(text)

View file

@ -20,7 +20,6 @@ import android.graphics.Bitmap
import android.graphics.Color
import android.net.Uri
import android.os.Bundle
import android.text.TextUtils
import android.view.LayoutInflater
import android.view.MenuItem
import android.view.View
@ -98,10 +97,10 @@ class UserInfoFragment : Fragment() {
binding.next.setOnClickListener {
val nameString = binding.name.text.toString().trim { it <= ' ' }
if (TextUtils.isEmpty(nameString)) {
if (nameString.isEmpty()) {
Toast.makeText(
requireContext(),
"Umm you're name can't be empty!",
"Your name can't be empty!",
Toast.LENGTH_SHORT
).show()
return@setOnClickListener

View file

@ -25,6 +25,7 @@ import android.view.animation.LinearInterpolator
import android.widget.SeekBar
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.Toolbar
import androidx.fragment.app.commit
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import code.name.monkey.appthemehelper.util.ColorUtil
@ -168,9 +169,9 @@ class ClassicPlayerFragment : AbsPlayerFragment(R.layout.fragment_classic_player
private fun hideVolumeIfAvailable() {
if (PreferenceUtil.isVolumeVisibilityMode) {
childFragmentManager.beginTransaction()
.replace(R.id.volumeFragmentContainer, VolumeFragment.newInstance())
.commit()
childFragmentManager.commit {
replace(R.id.volumeFragmentContainer, VolumeFragment.newInstance())
}
childFragmentManager.executePendingTransactions()
volumeFragment =
childFragmentManager.findFragmentById(R.id.volumeFragmentContainer) as VolumeFragment?

View file

@ -31,6 +31,7 @@ import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.updatePadding
import androidx.fragment.app.commit
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
@ -303,9 +304,9 @@ class GradientPlayerFragment : AbsPlayerFragment(R.layout.fragment_gradient_play
private fun hideVolumeIfAvailable() {
if (PreferenceUtil.isVolumeVisibilityMode) {
childFragmentManager.beginTransaction()
.replace(R.id.volumeFragmentContainer, VolumeFragment.newInstance())
.commit()
childFragmentManager.commit {
replace(R.id.volumeFragmentContainer, VolumeFragment.newInstance())
}
childFragmentManager.executePendingTransactions()
volumeFragment =
childFragmentManager.findFragmentById(R.id.volumeFragmentContainer) as VolumeFragment?

View file

@ -20,13 +20,12 @@ import android.content.Intent
import android.content.res.ColorStateList
import android.os.Bundle
import android.speech.RecognizerIntent
import android.text.Editable
import android.text.TextWatcher
import android.view.View
import android.view.ViewGroup
import android.view.inputmethod.InputMethodManager
import androidx.core.content.getSystemService
import androidx.core.view.*
import androidx.core.widget.doAfterTextChanged
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.transition.TransitionManager
@ -51,7 +50,7 @@ import net.yslibrary.android.keyboardvisibilityevent.KeyboardVisibilityEvent
import java.util.*
class SearchFragment : AbsMainActivityFragment(R.layout.fragment_search), TextWatcher,
class SearchFragment : AbsMainActivityFragment(R.layout.fragment_search),
ChipGroup.OnCheckedStateChangeListener {
companion object {
const val QUERY = "query"
@ -81,7 +80,10 @@ class SearchFragment : AbsMainActivityFragment(R.layout.fragment_search), TextWa
searchAdapter.swapDataSet(listOf())
}
binding.searchView.apply {
addTextChangedListener(this@SearchFragment)
doAfterTextChanged {
if (!it.isNullOrEmpty())
search(it.toString())
}
focusAndShowKeyboard()
}
binding.keyboardPopup.apply {
@ -171,16 +173,6 @@ class SearchFragment : AbsMainActivityFragment(R.layout.fragment_search), TextWa
}
}
override fun afterTextChanged(newText: Editable?) {
if (!newText.isNullOrEmpty()) search(newText.toString())
}
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
}
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
}
private fun search(query: String) {
this.query = query
TransitionManager.beginDelayedTransition(binding.appBarLayout)

View file

@ -19,6 +19,7 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.view.isGone
import androidx.fragment.app.Fragment
import androidx.navigation.fragment.findNavController
import code.name.monkey.appthemehelper.ThemeStore
@ -26,8 +27,6 @@ import code.name.monkey.retromusic.App
import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.databinding.FragmentMainSettingsBinding
import code.name.monkey.retromusic.extensions.drawAboveSystemBarsWithPadding
import code.name.monkey.retromusic.extensions.hide
import code.name.monkey.retromusic.extensions.show
import code.name.monkey.retromusic.util.NavigationUtil
class MainSettingsFragment : Fragment(), View.OnClickListener {
@ -76,7 +75,7 @@ class MainSettingsFragment : Fragment(), View.OnClickListener {
binding.backupRestoreSettings.setOnClickListener(this)
binding.buyProContainer.apply {
if (App.isProVersion()) hide() else show()
isGone = App.isProVersion()
setOnClickListener {
NavigationUtil.goToProVersion(requireContext())
}

View file

@ -16,6 +16,7 @@ package code.name.monkey.retromusic.fragments.settings
import android.annotation.SuppressLint
import android.os.Bundle
import androidx.core.content.edit
import androidx.preference.Preference
import androidx.preference.TwoStatePreference
import code.name.monkey.appthemehelper.ACCENT_COLORS
@ -93,10 +94,9 @@ class ThemeSettingsFragment : AbsSettingsFragment() {
val desaturatedColor: ATESwitchPreference? = findPreference(DESATURATED_COLOR)
desaturatedColor?.setOnPreferenceChangeListener { _, value ->
val desaturated = value as Boolean
ThemeStore.prefs(requireContext())
.edit()
.putBoolean("desaturated_color", desaturated)
.apply()
ThemeStore.prefs(requireContext()).edit {
putBoolean("desaturated_color", desaturated)
}
PreferenceUtil.isDesaturatedColor = desaturated
restartActivity()
true

View file

@ -24,7 +24,6 @@ import android.os.Looper
import android.text.Layout
import android.text.StaticLayout
import android.text.TextPaint
import android.text.TextUtils
import android.text.format.DateUtils
import android.util.AttributeSet
import android.view.GestureDetector
@ -34,6 +33,7 @@ import android.view.View
import android.view.animation.LinearInterpolator
import android.widget.Scroller
import androidx.core.content.ContextCompat
import androidx.core.graphics.withSave
import code.name.monkey.retromusic.R
import java.io.File
import kotlin.math.abs
@ -208,7 +208,7 @@ class CoverLrcView @JvmOverloads constructor(
)
mDefaultLabel = ta.getString(R.styleable.LrcView_lrcLabel)
mDefaultLabel =
if (TextUtils.isEmpty(mDefaultLabel)) context.getString(R.string.empty) else mDefaultLabel
if (mDefaultLabel.isNullOrEmpty()) context.getString(R.string.empty) else mDefaultLabel
mLrcPadding = ta.getDimension(R.styleable.LrcView_lrcPadding, 0f)
mTimelineColor = ta.getColor(
R.styleable.LrcView_lrcTimelineColor,
@ -522,10 +522,10 @@ class CoverLrcView @JvmOverloads constructor(
* @param y 歌词中心 Y 坐标
*/
private fun drawText(canvas: Canvas, staticLayout: StaticLayout, y: Float) {
canvas.save()
canvas.translate(mLrcPadding, y - (staticLayout.height shr 1))
staticLayout.draw(canvas)
canvas.restore()
canvas.withSave {
translate(mLrcPadding, y - (staticLayout.height shr 1))
staticLayout.draw(this)
}
}
fun animateCurrentTextSize() {

View file

@ -21,7 +21,7 @@ import android.util.AttributeSet
import androidx.appcompat.app.AlertDialog
import androidx.core.graphics.BlendModeColorFilterCompat
import androidx.core.graphics.BlendModeCompat.SRC_IN
import androidx.core.text.HtmlCompat
import androidx.core.text.parseAsHtml
import androidx.fragment.app.DialogFragment
import code.name.monkey.appthemehelper.common.prefs.supportv7.ATEDialogPreference
import code.name.monkey.retromusic.App
@ -84,15 +84,10 @@ class BlacklistPreferenceDialog : DialogFragment(), BlacklistFolderChooserDialog
.setItems(paths.toTypedArray()) { _, which ->
materialDialog(R.string.remove_from_blacklist)
.setMessage(
HtmlCompat.fromHtml(
String.format(
getString(
R.string.do_you_want_to_remove_from_the_blacklist
),
paths[which]
),
HtmlCompat.FROM_HTML_MODE_LEGACY
)
String.format(
getString(R.string.do_you_want_to_remove_from_the_blacklist),
paths[which]
).parseAsHtml()
)
.setPositiveButton(R.string.remove_action) { _, _ ->
BlacklistStore.getInstance(App.getContext())

View file

@ -7,10 +7,10 @@ import android.media.AudioAttributes
import android.media.AudioManager
import android.media.MediaPlayer
import android.media.audiofx.AudioEffect
import android.net.Uri
import android.os.PowerManager
import android.util.Log
import android.widget.Toast
import androidx.core.net.toUri
import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.helper.MusicPlayerRemote
import code.name.monkey.retromusic.service.AudioFader.Companion.createFadeAnimator
@ -160,7 +160,7 @@ class CrossFadePlayer(val context: Context) : Playback, MediaPlayer.OnCompletion
player.setOnPreparedListener(null)
try {
if (path.startsWith("content://")) {
player.setDataSource(context, Uri.parse(path))
player.setDataSource(context, path.toUri())
} else {
player.setDataSource(path)
}

View file

@ -540,10 +540,9 @@ class MusicService : MediaBrowserServiceCompat(),
}
fun setShuffleMode(shuffleMode: Int) {
PreferenceManager.getDefaultSharedPreferences(this)
.edit()
.putInt(SAVED_SHUFFLE_MODE, shuffleMode)
.apply()
PreferenceManager.getDefaultSharedPreferences(this).edit {
putInt(SAVED_SHUFFLE_MODE, shuffleMode)
}
when (shuffleMode) {
SHUFFLE_MODE_SHUFFLE -> {
this.shuffleMode = shuffleMode

View file

@ -26,7 +26,7 @@ import android.graphics.drawable.Drawable
import android.os.Build
import android.support.v4.media.session.MediaSessionCompat
import androidx.core.app.NotificationCompat
import androidx.core.text.HtmlCompat
import androidx.core.text.parseAsHtml
import androidx.media.app.NotificationCompat.MediaStyle
import code.name.monkey.appthemehelper.util.VersionUtils
import code.name.monkey.retromusic.R
@ -120,19 +120,9 @@ class PlayingNotificationImpl24(
}
override fun updateMetadata(song: Song, onUpdate: () -> Unit) {
setContentTitle(
HtmlCompat.fromHtml(
"<b>" + song.title + "</b>",
HtmlCompat.FROM_HTML_MODE_LEGACY
)
)
setContentTitle(("<b>" + song.title + "</b>").parseAsHtml())
setContentText(song.artistName)
setSubText(
HtmlCompat.fromHtml(
"<b>" + song.albumName + "</b>",
HtmlCompat.FROM_HTML_MODE_LEGACY
)
)
setSubText(("<b>" + song.albumName + "</b>").parseAsHtml())
val bigNotificationImageSize = context.resources
.getDimensionPixelSize(R.dimen.notification_big_image_size)
GlideApp.with(context).asBitmapPalette().songCoverOptions(song)

View file

@ -23,6 +23,7 @@ import android.net.Uri
import android.os.AsyncTask
import android.provider.MediaStore
import android.widget.Toast
import androidx.core.content.edit
import code.name.monkey.retromusic.App
import code.name.monkey.retromusic.model.Artist
import com.bumptech.glide.Glide
@ -79,7 +80,7 @@ class CustomArtistImageUtil private constructor(context: Context) {
}
if (succesful) {
mPreferences.edit().putBoolean(getFileName(artist), true).apply()
mPreferences.edit { putBoolean(getFileName(artist), true) }
ArtistSignatureUtil.getInstance(App.getContext())
.updateArtistSignature(artist.name)
App.getContext().contentResolver.notifyChange(
@ -99,7 +100,7 @@ class CustomArtistImageUtil private constructor(context: Context) {
object : AsyncTask<Void, Void, Void>() {
@SuppressLint("ApplySharedPref")
override fun doInBackground(vararg params: Void): Void? {
mPreferences.edit().putBoolean(getFileName(artist), false).commit()
mPreferences.edit(commit = true) { putBoolean(getFileName(artist), false) }
ArtistSignatureUtil.getInstance(App.getContext()).updateArtistSignature(artist.name)
App.getContext().contentResolver.notifyChange(
MediaStore.Audio.Artists.EXTERNAL_CONTENT_URI,

View file

@ -132,27 +132,14 @@ object LyricUtil {
}
@Throws(Exception::class)
private fun convertStreamToString(`is`: InputStream): String {
val reader = BufferedReader(InputStreamReader(`is`))
val sb = StringBuilder()
var line: String?
while (reader.readLine().also { line = it } != null) {
sb.append(line).append("\n")
}
reader.close()
return sb.toString()
private fun convertStreamToString(inputStream: InputStream): String {
return inputStream.bufferedReader().readLines().joinToString(separator = "\n")
}
fun getStringFromLrc(file: File?): String {
try {
val reader = BufferedReader(FileReader(file))
val sb = StringBuilder()
var line: String?
while (reader.readLine().also { line = it } != null) {
sb.append(line).append("\n")
}
reader.close()
return sb.toString()
return reader.readLines().joinToString(separator = "\n")
} catch (e: Exception) {
Log.i("Error", "Error Occurred")
}

View file

@ -4,6 +4,7 @@ import android.graphics.Bitmap
import android.graphics.Canvas
import android.graphics.Matrix
import android.graphics.Paint
import androidx.core.graphics.scale
import com.bumptech.glide.util.Util.assertBackgroundThread
@ -75,7 +76,7 @@ internal object MergedImageUtils {
val onePartSize = imageSize / parts
images.forEachIndexed { i, bitmap ->
val bit = Bitmap.createScaledBitmap(bitmap, onePartSize, onePartSize, true)
val bit = bitmap.scale(onePartSize, onePartSize)
canvas.drawBitmap(
bit,
(onePartSize * (i % parts)).toFloat() + (i % 3) * 50,

View file

@ -1,7 +1,6 @@
package code.name.monkey.retromusic.util
import android.content.ContentUris
import android.content.ContentValues
import android.content.Context
import android.content.Intent
import android.database.Cursor
@ -9,10 +8,11 @@ import android.net.Uri
import android.os.Environment
import android.provider.BaseColumns
import android.provider.MediaStore
import android.text.TextUtils
import android.util.Log
import android.widget.Toast
import androidx.core.content.FileProvider
import androidx.core.content.contentValuesOf
import androidx.core.net.toUri
import androidx.fragment.app.FragmentActivity
import code.name.monkey.appthemehelper.util.VersionUtils
import code.name.monkey.retromusic.R
@ -99,7 +99,7 @@ object MusicUtil : KoinComponent {
fun deleteAlbumArt(context: Context, albumId: Long) {
val contentResolver = context.contentResolver
val localUri = Uri.parse("content://media/external/audio/albumart")
val localUri = "content://media/external/audio/albumart".toUri()
contentResolver.delete(ContentUris.withAppendedId(localUri, albumId), null, null)
contentResolver.notifyChange(localUri, null)
}
@ -189,7 +189,7 @@ object MusicUtil : KoinComponent {
@JvmStatic
fun getMediaStoreAlbumCoverUri(albumId: Long): Uri {
val sArtworkUri = Uri.parse("content://media/external/audio/albumart")
val sArtworkUri = "content://media/external/audio/albumart".toUri()
return ContentUris.withAppendedId(sArtworkUri, albumId)
}
@ -238,10 +238,10 @@ object MusicUtil : KoinComponent {
fun getSectionName(mediaTitle: String?): String {
var musicMediaTitle = mediaTitle
return try {
if (TextUtils.isEmpty(musicMediaTitle)) {
if (musicMediaTitle.isNullOrEmpty()) {
return "-"
}
musicMediaTitle = musicMediaTitle!!.trim { it <= ' ' }.lowercase()
musicMediaTitle = musicMediaTitle.trim { it <= ' ' }.lowercase()
if (musicMediaTitle.startsWith("the ")) {
musicMediaTitle = musicMediaTitle.substring(4)
} else if (musicMediaTitle.startsWith("a ")) {
@ -309,28 +309,29 @@ object MusicUtil : KoinComponent {
path: String?
) {
val contentResolver = context.contentResolver
val artworkUri = Uri.parse("content://media/external/audio/albumart")
val artworkUri = "content://media/external/audio/albumart".toUri()
contentResolver.delete(ContentUris.withAppendedId(artworkUri, albumId), null, null)
val values = ContentValues()
values.put("album_id", albumId)
values.put("_data", path)
val values = contentValuesOf(
"album_id" to albumId,
"_data" to path
)
contentResolver.insert(artworkUri, values)
contentResolver.notifyChange(artworkUri, null)
}
fun isArtistNameUnknown(artistName: String?): Boolean {
if (TextUtils.isEmpty(artistName)) {
if (artistName.isNullOrEmpty()) {
return false
}
if (artistName == Artist.UNKNOWN_ARTIST_DISPLAY_NAME) {
return true
}
val tempName = artistName!!.trim { it <= ' ' }.lowercase()
val tempName = artistName.trim { it <= ' ' }.lowercase()
return tempName == "unknown" || tempName == "<unknown>"
}
fun isVariousArtists(artistName: String?): Boolean {
if (TextUtils.isEmpty(artistName)) {
if (artistName.isNullOrEmpty()) {
return false
}
if (artistName == Artist.VARIOUS_ARTISTS_DISPLAY_NAME) {
@ -454,7 +455,7 @@ object MusicUtil : KoinComponent {
} catch (ignored: SecurityException) {
}
activity.contentResolver.notifyChange(Uri.parse("content://media"), null)
activity.contentResolver.notifyChange("content://media".toUri(), null)
activity.runOnUiThread {
Toast.makeText(
activity,

View file

@ -16,11 +16,11 @@ package code.name.monkey.retromusic.util
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.provider.BaseColumns
import android.provider.MediaStore
import android.provider.Settings
import android.widget.Toast
import androidx.core.net.toUri
import code.name.monkey.appthemehelper.util.VersionUtils
import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.model.Song
@ -69,7 +69,7 @@ class RingtoneManager(val context: Context) {
.setMessage(R.string.dialog_message_set_ringtone)
.setPositiveButton(android.R.string.ok) { _, _ ->
val intent = Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS)
intent.data = Uri.parse("package:" + context.applicationContext.packageName)
intent.data = ("package:" + context.applicationContext.packageName).toUri()
context.startActivity(intent)
}
.setNegativeButton(android.R.string.cancel, null)

View file

@ -20,6 +20,7 @@ import android.graphics.Color
import android.util.AttributeSet
import androidx.appcompat.widget.AppCompatImageView
import androidx.core.content.ContextCompat
import androidx.core.content.withStyledAttributes
import code.name.monkey.appthemehelper.ThemeStore
import code.name.monkey.appthemehelper.util.ATHUtil
import code.name.monkey.appthemehelper.util.ColorUtil
@ -38,12 +39,10 @@ class ColorIconsImageView @JvmOverloads constructor(
init {
// Load the styled attributes and set their properties
val attributes =
context.obtainStyledAttributes(attrs, R.styleable.ColorIconsImageView, 0, 0)
val color =
attributes.getColor(R.styleable.ColorIconsImageView_iconBackgroundColor, Color.RED)
setIconBackgroundColor(color)
attributes.recycle()
context.withStyledAttributes(attrs, R.styleable.ColorIconsImageView, 0, 0) {
val color = getColor(R.styleable.ColorIconsImageView_iconBackgroundColor, Color.RED)
setIconBackgroundColor(color)
}
}
fun setIconBackgroundColor(color: Int) {

View file

@ -18,6 +18,7 @@ import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.FrameLayout
import androidx.core.content.withStyledAttributes
import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.databinding.ListItemViewNoCardBinding
import code.name.monkey.retromusic.extensions.hide
@ -49,20 +50,20 @@ class ListItemView : FrameLayout {
private fun init(context: Context, attrs: AttributeSet?) {
binding = ListItemViewNoCardBinding.inflate(LayoutInflater.from(context), this, true)
val typedArray = context.obtainStyledAttributes(attrs, R.styleable.ListItemView)
if (typedArray.hasValue(R.styleable.ListItemView_listItemIcon)) {
binding.icon.setImageDrawable(typedArray.getDrawable(R.styleable.ListItemView_listItemIcon))
} else {
binding.icon.hide()
}
context.withStyledAttributes(attrs, R.styleable.ListItemView) {
if (hasValue(R.styleable.ListItemView_listItemIcon)) {
binding.icon.setImageDrawable(getDrawable(R.styleable.ListItemView_listItemIcon))
} else {
binding.icon.hide()
}
binding.title.text = typedArray.getText(R.styleable.ListItemView_listItemTitle)
if (typedArray.hasValue(R.styleable.ListItemView_listItemSummary)) {
binding.summary.text = typedArray.getText(R.styleable.ListItemView_listItemSummary)
} else {
binding.summary.hide()
binding.title.text = getText(R.styleable.ListItemView_listItemTitle)
if (hasValue(R.styleable.ListItemView_listItemSummary)) {
binding.summary.text = getText(R.styleable.ListItemView_listItemSummary)
} else {
binding.summary.hide()
}
}
typedArray.recycle()
}
fun setSummary(appVersion: String) {

View file

@ -5,6 +5,7 @@ import android.content.res.ColorStateList
import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.FrameLayout
import androidx.core.content.withStyledAttributes
import code.name.monkey.appthemehelper.ThemeStore
import code.name.monkey.appthemehelper.util.ColorUtil
import code.name.monkey.retromusic.R
@ -21,26 +22,25 @@ class PermissionItem @JvmOverloads constructor(
val checkImage get() = binding.checkImage
init {
val attributes = context.obtainStyledAttributes(attrs, R.styleable.PermissionItem, 0, 0)
binding = ItemPermissionBinding.inflate(LayoutInflater.from(context), this, true)
binding.title.text = attributes.getText(R.styleable.PermissionItem_permissionTitle)
binding.summary.text =
attributes.getText(R.styleable.PermissionItem_permissionTitleSubTitle)
binding.number.text = attributes.getText(R.styleable.PermissionItem_permissionTitleNumber)
binding.button.text = attributes.getText(R.styleable.PermissionItem_permissionButtonTitle)
binding.button.setIconResource(
attributes.getResourceId(
R.styleable.PermissionItem_permissionIcon,
R.drawable.ic_album
context.withStyledAttributes(attrs, R.styleable.PermissionItem, 0, 0) {
binding.title.text = getText(R.styleable.PermissionItem_permissionTitle)
binding.summary.text = getText(R.styleable.PermissionItem_permissionTitleSubTitle)
binding.number.text = getText(R.styleable.PermissionItem_permissionTitleNumber)
binding.button.text = getText(R.styleable.PermissionItem_permissionButtonTitle)
binding.button.setIconResource(
getResourceId(
R.styleable.PermissionItem_permissionIcon,
R.drawable.ic_album
)
)
)
val color = ThemeStore.accentColor(context)
binding.number.backgroundTintList =
ColorStateList.valueOf(ColorUtil.withAlpha(color, 0.22f))
val color = ThemeStore.accentColor(context)
binding.number.backgroundTintList =
ColorStateList.valueOf(ColorUtil.withAlpha(color, 0.22f))
binding.button.accentOutlineColor()
attributes.recycle()
binding.button.accentOutlineColor()
}
}
fun setButtonClick(callBack: () -> Unit) {

View file

@ -18,6 +18,7 @@ import android.graphics.Color
import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.FrameLayout
import androidx.core.content.withStyledAttributes
import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.databinding.ListSettingItemViewBinding
@ -33,21 +34,15 @@ class SettingListItemView @JvmOverloads constructor(
init {
val binding: ListSettingItemViewBinding =
ListSettingItemViewBinding.inflate(LayoutInflater.from(context), this, true)
val typedArray =
context.obtainStyledAttributes(attrs, R.styleable.SettingListItemView)
binding.icon
if (typedArray.hasValue(R.styleable.SettingListItemView_settingListItemIcon)) {
binding.icon.setImageDrawable(typedArray.getDrawable(R.styleable.SettingListItemView_settingListItemIcon))
}
binding.icon.setIconBackgroundColor(
typedArray.getColor(
R.styleable.SettingListItemView_settingListItemIconColor,
Color.WHITE
context.withStyledAttributes(attrs, R.styleable.SettingListItemView) {
if (hasValue(R.styleable.SettingListItemView_settingListItemIcon)) {
binding.icon.setImageDrawable(getDrawable(R.styleable.SettingListItemView_settingListItemIcon))
}
binding.icon.setIconBackgroundColor(
getColor(R.styleable.SettingListItemView_settingListItemIconColor, Color.WHITE)
)
)
binding.title.text =
typedArray.getText(R.styleable.SettingListItemView_settingListItemTitle)
binding.text.text = typedArray.getText(R.styleable.SettingListItemView_settingListItemText)
typedArray.recycle()
binding.title.text = getText(R.styleable.SettingListItemView_settingListItemTitle)
binding.text.text = getText(R.styleable.SettingListItemView_settingListItemText)
}
}
}

View file

@ -6,6 +6,7 @@ import android.graphics.Color
import androidx.annotation.*
import androidx.annotation.IntRange
import androidx.core.content.ContextCompat
import androidx.core.content.edit
import androidx.preference.PreferenceManager
import code.name.monkey.appthemehelper.util.ATHUtil.isWindowBackgroundDark
import code.name.monkey.appthemehelper.util.ATHUtil.resolveColor
@ -336,7 +337,7 @@ private constructor(private val mContext: Context) : ThemeStorePrefKeys, ThemeSt
val prefs = prefs(context)
val lastVersion = prefs.getInt(ThemeStorePrefKeys.IS_CONFIGURED_VERSION_KEY, -1)
if (version > lastVersion) {
prefs.edit().putInt(ThemeStorePrefKeys.IS_CONFIGURED_VERSION_KEY, version).apply()
prefs.edit { putInt(ThemeStorePrefKeys.IS_CONFIGURED_VERSION_KEY, version) }
return false
}
return true

View file

@ -5,6 +5,7 @@ import android.text.Editable
import android.util.AttributeSet
import android.widget.SeekBar
import android.widget.TextView
import androidx.core.content.withStyledAttributes
import androidx.core.graphics.BlendModeColorFilterCompat
import androidx.core.graphics.BlendModeCompat
import androidx.core.widget.doAfterTextChanged
@ -26,13 +27,11 @@ class ATESeekBarPreference @JvmOverloads constructor(
var unit: String = ""
init {
val attributes =
context.obtainStyledAttributes(attrs, R.styleable.ATESeekBarPreference, 0, 0)
attributes.getString(R.styleable.ATESeekBarPreference_ateKey_pref_unit)?.let {
unit = it
context.withStyledAttributes(attrs, R.styleable.ATESeekBarPreference, 0, 0) {
getString(R.styleable.ATESeekBarPreference_ateKey_pref_unit)?.let {
unit = it
}
}
attributes.recycle()
icon?.colorFilter = BlendModeColorFilterCompat.createBlendModeColorFilterCompat(
ATHUtil.resolveColor(
context,