From 6966351113957321af67f052228de536080bd7f0 Mon Sep 17 00:00:00 2001 From: h4h13 Date: Sun, 1 Mar 2020 17:35:43 +0530 Subject: [PATCH] Fix depricated issues --- .../activities/ArtistDetailActivity.kt | 8 ++--- .../retromusic/activities/MainActivity.java | 14 --------- .../retromusic/appwidgets/AppWidgetCard.kt | 2 +- .../dialogs/RemoveFromPlaylistDialog.kt | 17 +++++++--- .../dialogs/RenamePlaylistDialog.kt | 2 +- .../retromusic/dialogs/SleepTimerDialog.kt | 31 ++++++++++--------- .../retromusic/dialogs/SongDetailDialog.kt | 9 ++++-- .../retromusic/dialogs/SongShareDialog.kt | 2 +- .../fragments/base/AbsMainActivityFragment.kt | 4 --- .../fragments/base/AbsPlayerFragment.kt | 2 +- .../preferences/BlacklistPreferenceDialog.kt | 7 +++-- .../retromusic/util/PreferenceUtil.java | 4 --- .../name/monkey/retromusic/util/ViewUtil.kt | 4 +-- 13 files changed, 46 insertions(+), 60 deletions(-) diff --git a/app/src/main/java/code/name/monkey/retromusic/activities/ArtistDetailActivity.kt b/app/src/main/java/code/name/monkey/retromusic/activities/ArtistDetailActivity.kt index 8575ce82..e0fdbe4a 100755 --- a/app/src/main/java/code/name/monkey/retromusic/activities/ArtistDetailActivity.kt +++ b/app/src/main/java/code/name/monkey/retromusic/activities/ArtistDetailActivity.kt @@ -12,6 +12,7 @@ import android.view.MenuItem import android.view.View import android.widget.Toast import androidx.core.app.ActivityCompat +import androidx.core.text.HtmlCompat import androidx.recyclerview.widget.DefaultItemAnimator import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.LinearLayoutManager @@ -207,13 +208,8 @@ class ArtistDetailActivity : AbsSlidingMusicPanelActivity(), ArtistDetailsView, if (bioContent != null && bioContent.trim { it <= ' ' }.isNotEmpty()) { biographyText.visibility = View.VISIBLE biographyTitle.visibility = View.VISIBLE - biography = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - Html.fromHtml(bioContent, Html.FROM_HTML_MODE_LEGACY) - } else { - Html.fromHtml(bioContent) - } + biography = HtmlCompat.fromHtml(bioContent,HtmlCompat.FROM_HTML_MODE_LEGACY) biographyText.text = biography - if (lastFmArtist.artist.stats.listeners.isNotEmpty()) { listeners.show() listenersLabel.show() diff --git a/app/src/main/java/code/name/monkey/retromusic/activities/MainActivity.java b/app/src/main/java/code/name/monkey/retromusic/activities/MainActivity.java index aacdfd1d..16d56e64 100644 --- a/app/src/main/java/code/name/monkey/retromusic/activities/MainActivity.java +++ b/app/src/main/java/code/name/monkey/retromusic/activities/MainActivity.java @@ -57,7 +57,6 @@ import code.name.monkey.appthemehelper.util.ToolbarContentTintHelper; import code.name.monkey.retromusic.R; import code.name.monkey.retromusic.activities.base.AbsSlidingMusicPanelActivity; import code.name.monkey.retromusic.dialogs.CreatePlaylistDialog; -import code.name.monkey.retromusic.dialogs.OptionsSheetDialogFragment; import code.name.monkey.retromusic.fragments.base.AbsLibraryPagerRecyclerViewCustomGridSizeFragment; import code.name.monkey.retromusic.fragments.mainactivity.AlbumsFragment; import code.name.monkey.retromusic.fragments.mainactivity.ArtistsFragment; @@ -763,19 +762,6 @@ public class MainActivity extends AbsSlidingMusicPanelActivity .makeSceneTransitionAnimation(this, mToolbarContainer, getString(R.string.transition_toolbar)); NavigationUtil.goToSearch(this, options); }); - - mToolbar.setNavigationOnClickListener( - v -> { - Fragment fragment = getCurrentFragment(); - if (fragment instanceof FoldersFragment) { - OptionsSheetDialogFragment.newInstance(OptionsSheetDialogFragment.FOLDER) - .show(getSupportFragmentManager(), "Main_Menu"); - } else { - OptionsSheetDialogFragment.newInstance(OptionsSheetDialogFragment.LIBRARY) - .show(getSupportFragmentManager(), "Main_Menu"); - } - }); - new Handler().postDelayed(new Runnable() { @Override public void run() { diff --git a/app/src/main/java/code/name/monkey/retromusic/appwidgets/AppWidgetCard.kt b/app/src/main/java/code/name/monkey/retromusic/appwidgets/AppWidgetCard.kt index 38b73698..69ab64f8 100644 --- a/app/src/main/java/code/name/monkey/retromusic/appwidgets/AppWidgetCard.kt +++ b/app/src/main/java/code/name/monkey/retromusic/appwidgets/AppWidgetCard.kt @@ -150,7 +150,7 @@ class AppWidgetCard : BaseAppWidget() { cardRadius = service.resources.getDimension(code.name.monkey.retromusic.R.dimen.app_widget_card_radius) } - val appContext = service.applicationContext + // Load the album cover async and push the update on completion service.runOnUiThread { if (target != null) { diff --git a/app/src/main/java/code/name/monkey/retromusic/dialogs/RemoveFromPlaylistDialog.kt b/app/src/main/java/code/name/monkey/retromusic/dialogs/RemoveFromPlaylistDialog.kt index c22e2f2a..66a0c45f 100644 --- a/app/src/main/java/code/name/monkey/retromusic/dialogs/RemoveFromPlaylistDialog.kt +++ b/app/src/main/java/code/name/monkey/retromusic/dialogs/RemoveFromPlaylistDialog.kt @@ -16,7 +16,7 @@ package code.name.monkey.retromusic.dialogs import android.app.Dialog import android.os.Bundle -import android.text.Html +import androidx.core.text.HtmlCompat import androidx.fragment.app.DialogFragment import code.name.monkey.retromusic.R import code.name.monkey.retromusic.R.string @@ -37,14 +37,18 @@ class RemoveFromPlaylistDialog : DialogFragment() { if (songs != null) { if (songs.size > 1) { title = R.string.remove_songs_from_playlist_title - content = Html.fromHtml(getString(string.remove_x_songs_from_playlist, songs.size)) + content = HtmlCompat.fromHtml( + getString(string.remove_x_songs_from_playlist, songs.size), + HtmlCompat.FROM_HTML_MODE_LEGACY + ) } else { title = R.string.remove_song_from_playlist_title - content = Html.fromHtml( + content = HtmlCompat.fromHtml( getString( code.name.monkey.retromusic.R.string.remove_song_x_from_playlist, songs[0].title - ) + ), + HtmlCompat.FROM_HTML_MODE_LEGACY ) } } @@ -58,7 +62,10 @@ class RemoveFromPlaylistDialog : DialogFragment() { positiveButton(R.string.remove_action) { if (activity == null) return@positiveButton - PlaylistsUtil.removeFromPlaylist(activity!!, songs as MutableList) + PlaylistsUtil.removeFromPlaylist( + requireContext(), + songs as MutableList + ) } cornerRadius(PreferenceUtil.getInstance(requireContext()).dialogCorner) } diff --git a/app/src/main/java/code/name/monkey/retromusic/dialogs/RenamePlaylistDialog.kt b/app/src/main/java/code/name/monkey/retromusic/dialogs/RenamePlaylistDialog.kt index ca123feb..c8a85059 100644 --- a/app/src/main/java/code/name/monkey/retromusic/dialogs/RenamePlaylistDialog.kt +++ b/app/src/main/java/code/name/monkey/retromusic/dialogs/RenamePlaylistDialog.kt @@ -47,7 +47,7 @@ class RenamePlaylistDialog : DialogFragment() { negativeButton(android.R.string.cancel) positiveButton(string.action_rename) { if (playlistView.toString().trim { it <= ' ' } != "") { - val playlistId = arguments!!.getLong(PLAYLIST_ID) + val playlistId = requireArguments().getLong(PLAYLIST_ID) PlaylistsUtil.renamePlaylist( context, playlistId, diff --git a/app/src/main/java/code/name/monkey/retromusic/dialogs/SleepTimerDialog.kt b/app/src/main/java/code/name/monkey/retromusic/dialogs/SleepTimerDialog.kt index d469bf0c..520500ba 100755 --- a/app/src/main/java/code/name/monkey/retromusic/dialogs/SleepTimerDialog.kt +++ b/app/src/main/java/code/name/monkey/retromusic/dialogs/SleepTimerDialog.kt @@ -72,12 +72,12 @@ class SleepTimerDialog : DialogFragment() { val nextSleepTimerElapsedTime = SystemClock.elapsedRealtime() + minutes * 60 * 1000 PreferenceUtil.getInstance(requireContext()) .setNextSleepTimerElapsedRealtime(nextSleepTimerElapsedTime) - val am = activity!!.getSystemService(Context.ALARM_SERVICE) as AlarmManager + val am = requireContext().getSystemService(Context.ALARM_SERVICE) as AlarmManager am.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, nextSleepTimerElapsedTime, pi) Toast.makeText( - activity, - activity!!.resources.getString(R.string.sleep_timer_set, minutes), + requireContext(), + requireContext().resources.getString(R.string.sleep_timer_set, minutes), Toast.LENGTH_SHORT ).show() } @@ -87,12 +87,13 @@ class SleepTimerDialog : DialogFragment() { } val previous = makeTimerPendingIntent(PendingIntent.FLAG_NO_CREATE) if (previous != null) { - val am = activity!!.getSystemService(Context.ALARM_SERVICE) as AlarmManager + val am = + requireContext().getSystemService(Context.ALARM_SERVICE) as AlarmManager am.cancel(previous) previous.cancel() Toast.makeText( - activity, - activity!!.resources.getString(R.string.sleep_timer_canceled), + requireContext(), + requireContext().resources.getString(R.string.sleep_timer_canceled), Toast.LENGTH_SHORT ).show() } @@ -101,8 +102,8 @@ class SleepTimerDialog : DialogFragment() { if (musicService != null && musicService.pendingQuit) { musicService.pendingQuit = false Toast.makeText( - activity, - activity!!.resources.getString(R.string.sleep_timer_canceled), + requireContext(), + requireContext().resources.getString(R.string.sleep_timer_canceled), Toast.LENGTH_SHORT ).show() } @@ -166,11 +167,11 @@ class SleepTimerDialog : DialogFragment() { } private fun makeTimerPendingIntent(flag: Int): PendingIntent? { - return PendingIntent.getService(activity, 0, makeTimerIntent(), flag) + return PendingIntent.getService(requireActivity(), 0, makeTimerIntent(), flag) } private fun makeTimerIntent(): Intent { - val intent = Intent(activity, MusicService::class.java) + val intent = Intent(requireActivity(), MusicService::class.java) return if (shouldFinishLastSong.isChecked) { intent.setAction(ACTION_PENDING_QUIT) } else intent.setAction(ACTION_QUIT) @@ -192,11 +193,11 @@ class SleepTimerDialog : DialogFragment() { ) { override fun onTick(millisUntilFinished: Long) { - materialDialog.getActionButton(WhichButton.NEGATIVE).text = - String.format( - "%s %s", materialDialog.context.getString(R.string.cancel_current_timer), - " (" + MusicUtil.getReadableDurationString(millisUntilFinished) + ")" - ) + materialDialog.getActionButton(WhichButton.NEGATIVE).text = String.format( + "%s %s", + materialDialog.context.getString(R.string.cancel_current_timer), + " (" + MusicUtil.getReadableDurationString(millisUntilFinished) + ")" + ) } override fun onFinish() { diff --git a/app/src/main/java/code/name/monkey/retromusic/dialogs/SongDetailDialog.kt b/app/src/main/java/code/name/monkey/retromusic/dialogs/SongDetailDialog.kt index 4db8bb86..e6201a82 100644 --- a/app/src/main/java/code/name/monkey/retromusic/dialogs/SongDetailDialog.kt +++ b/app/src/main/java/code/name/monkey/retromusic/dialogs/SongDetailDialog.kt @@ -17,13 +17,13 @@ package code.name.monkey.retromusic.dialogs import android.app.Dialog import android.content.Context import android.os.Bundle -import android.text.Html import android.text.Spanned import android.util.Log import android.view.View import android.view.ViewGroup import android.widget.TextView import androidx.annotation.NonNull +import androidx.core.text.HtmlCompat import androidx.fragment.app.DialogFragment import code.name.monkey.retromusic.R import code.name.monkey.retromusic.R.string @@ -53,7 +53,7 @@ class SongDetailDialog : DialogFragment() { override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { val context: Context = requireContext() - val song = arguments!!.getParcelable("song") + val song = requireArguments().getParcelable("song") val materialDialog = MaterialDialog(requireContext(), BottomSheet(LayoutMode.WRAP_CONTENT)) .show { @@ -180,7 +180,10 @@ class SongDetailDialog : DialogFragment() { } private fun makeTextWithTitle(context: Context, titleResId: Int, text: String?): Spanned { - return Html.fromHtml("" + context.resources.getString(titleResId) + ": " + "" + text) + return HtmlCompat.fromHtml( + "" + context.resources.getString(titleResId) + ": " + "" + text, + HtmlCompat.FROM_HTML_MODE_LEGACY + ) } private fun getFileSizeString(sizeInBytes: Long): String { diff --git a/app/src/main/java/code/name/monkey/retromusic/dialogs/SongShareDialog.kt b/app/src/main/java/code/name/monkey/retromusic/dialogs/SongShareDialog.kt index dc26f98a..ddd6ba86 100644 --- a/app/src/main/java/code/name/monkey/retromusic/dialogs/SongShareDialog.kt +++ b/app/src/main/java/code/name/monkey/retromusic/dialogs/SongShareDialog.kt @@ -30,7 +30,7 @@ import com.afollestad.materialdialogs.list.listItems class SongShareDialog : DialogFragment() { override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { - val song: Song? = arguments?.getParcelable("song") + val song: Song? = requireArguments().getParcelable("song") val currentlyListening: String = getString(R.string.currently_listening_to_x_by_x, song?.title, song?.artistName) diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/base/AbsMainActivityFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/base/AbsMainActivityFragment.kt index 6d3e5488..09aae32c 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/base/AbsMainActivityFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/base/AbsMainActivityFragment.kt @@ -45,8 +45,4 @@ abstract class AbsMainActivityFragment : AbsMusicServiceFragment() { setStatusBarColor(view, ColorUtil.darkenColor(colorPrimary)) } } - - protected fun showMainMenu(option: Int) { - OptionsSheetDialogFragment.newInstance(option).show(childFragmentManager, "Main_Menu") - } } diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/base/AbsPlayerFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/base/AbsPlayerFragment.kt index a442fb32..c846af64 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/base/AbsPlayerFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/base/AbsPlayerFragment.kt @@ -121,7 +121,7 @@ abstract class AbsPlayerFragment : AbsMusicServiceFragment(), return true } R.id.action_sleep_timer -> { - SleepTimerDialog().show(requireFragmentManager(), TAG) + SleepTimerDialog().show(parentFragmentManager, TAG) return true } R.id.action_set_as_ringtone -> { diff --git a/app/src/main/java/code/name/monkey/retromusic/preferences/BlacklistPreferenceDialog.kt b/app/src/main/java/code/name/monkey/retromusic/preferences/BlacklistPreferenceDialog.kt index e0681d61..7ebe4f64 100644 --- a/app/src/main/java/code/name/monkey/retromusic/preferences/BlacklistPreferenceDialog.kt +++ b/app/src/main/java/code/name/monkey/retromusic/preferences/BlacklistPreferenceDialog.kt @@ -17,10 +17,10 @@ package code.name.monkey.retromusic.preferences import android.app.Dialog import android.content.Context import android.os.Bundle -import android.text.Html import android.util.AttributeSet import androidx.core.graphics.BlendModeColorFilterCompat import androidx.core.graphics.BlendModeCompat.SRC_IN +import androidx.core.text.HtmlCompat import androidx.fragment.app.DialogFragment import code.name.monkey.appthemehelper.common.prefs.supportv7.ATEDialogPreference import code.name.monkey.retromusic.R @@ -91,11 +91,12 @@ class BlacklistPreferenceDialog : DialogFragment(), BlacklistFolderChooserDialog cornerRadius(PreferenceUtil.getInstance(requireContext()).dialogCorner) title(code.name.monkey.retromusic.R.string.remove_from_blacklist) message( - text = Html.fromHtml( + text = HtmlCompat.fromHtml( getString( code.name.monkey.retromusic.R.string.do_you_want_to_remove_from_the_blacklist, text - ) + ), + HtmlCompat.FROM_HTML_MODE_LEGACY ) ) positiveButton(code.name.monkey.retromusic.R.string.remove_action) { diff --git a/app/src/main/java/code/name/monkey/retromusic/util/PreferenceUtil.java b/app/src/main/java/code/name/monkey/retromusic/util/PreferenceUtil.java index d54dfaeb..db892f6f 100644 --- a/app/src/main/java/code/name/monkey/retromusic/util/PreferenceUtil.java +++ b/app/src/main/java/code/name/monkey/retromusic/util/PreferenceUtil.java @@ -43,7 +43,6 @@ import java.util.List; import java.util.Objects; import code.name.monkey.retromusic.R; -import code.name.monkey.retromusic.dialogs.OptionsSheetDialogFragment; import code.name.monkey.retromusic.fragments.AlbumCoverStyle; import code.name.monkey.retromusic.fragments.NowPlayingScreen; import code.name.monkey.retromusic.fragments.mainactivity.FoldersFragment; @@ -587,9 +586,6 @@ public final class PreferenceUtil { return mPreferences.getInt(LAST_CHANGELOG_VERSION, -1); } - public final int getLastMusicChooser() { - return mPreferences.getInt(LAST_MUSIC_CHOOSER, OptionsSheetDialogFragment.LIBRARY); - } public void setLastMusicChooser(int value) { mPreferences.edit().putInt(LAST_MUSIC_CHOOSER, value).apply(); diff --git a/app/src/main/java/code/name/monkey/retromusic/util/ViewUtil.kt b/app/src/main/java/code/name/monkey/retromusic/util/ViewUtil.kt index dcc75ba7..76fcc5d0 100644 --- a/app/src/main/java/code/name/monkey/retromusic/util/ViewUtil.kt +++ b/app/src/main/java/code/name/monkey/retromusic/util/ViewUtil.kt @@ -16,7 +16,6 @@ package code.name.monkey.retromusic.util import android.content.res.ColorStateList import android.content.res.Resources -import android.graphics.PorterDuff import android.graphics.drawable.LayerDrawable import android.os.Build import android.view.View @@ -42,7 +41,8 @@ object ViewUtil { if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP_MR1) { val layerDrawable = progressSlider.progressDrawable as LayerDrawable val progressDrawable = layerDrawable.findDrawableByLayerId(android.R.id.progress) - progressDrawable.setColorFilter(newColor, PorterDuff.Mode.SRC_IN) + progressDrawable.colorFilter = + BlendModeColorFilterCompat.createBlendModeColorFilterCompat(newColor, SRC_IN) } else { progressSlider.progressTintList = ColorStateList.valueOf(newColor) }