Fix depricated issues

This commit is contained in:
h4h13 2020-03-01 17:35:43 +05:30
parent 98ead185d5
commit 6966351113
13 changed files with 46 additions and 60 deletions

View file

@ -12,6 +12,7 @@ import android.view.MenuItem
import android.view.View import android.view.View
import android.widget.Toast import android.widget.Toast
import androidx.core.app.ActivityCompat import androidx.core.app.ActivityCompat
import androidx.core.text.HtmlCompat
import androidx.recyclerview.widget.DefaultItemAnimator import androidx.recyclerview.widget.DefaultItemAnimator
import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
@ -207,13 +208,8 @@ class ArtistDetailActivity : AbsSlidingMusicPanelActivity(), ArtistDetailsView,
if (bioContent != null && bioContent.trim { it <= ' ' }.isNotEmpty()) { if (bioContent != null && bioContent.trim { it <= ' ' }.isNotEmpty()) {
biographyText.visibility = View.VISIBLE biographyText.visibility = View.VISIBLE
biographyTitle.visibility = View.VISIBLE biographyTitle.visibility = View.VISIBLE
biography = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { biography = HtmlCompat.fromHtml(bioContent,HtmlCompat.FROM_HTML_MODE_LEGACY)
Html.fromHtml(bioContent, Html.FROM_HTML_MODE_LEGACY)
} else {
Html.fromHtml(bioContent)
}
biographyText.text = biography biographyText.text = biography
if (lastFmArtist.artist.stats.listeners.isNotEmpty()) { if (lastFmArtist.artist.stats.listeners.isNotEmpty()) {
listeners.show() listeners.show()
listenersLabel.show() listenersLabel.show()

View file

@ -57,7 +57,6 @@ import code.name.monkey.appthemehelper.util.ToolbarContentTintHelper;
import code.name.monkey.retromusic.R; import code.name.monkey.retromusic.R;
import code.name.monkey.retromusic.activities.base.AbsSlidingMusicPanelActivity; import code.name.monkey.retromusic.activities.base.AbsSlidingMusicPanelActivity;
import code.name.monkey.retromusic.dialogs.CreatePlaylistDialog; 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.base.AbsLibraryPagerRecyclerViewCustomGridSizeFragment;
import code.name.monkey.retromusic.fragments.mainactivity.AlbumsFragment; import code.name.monkey.retromusic.fragments.mainactivity.AlbumsFragment;
import code.name.monkey.retromusic.fragments.mainactivity.ArtistsFragment; 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)); .makeSceneTransitionAnimation(this, mToolbarContainer, getString(R.string.transition_toolbar));
NavigationUtil.goToSearch(this, options); 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() { new Handler().postDelayed(new Runnable() {
@Override @Override
public void run() { public void run() {

View file

@ -150,7 +150,7 @@ class AppWidgetCard : BaseAppWidget() {
cardRadius = cardRadius =
service.resources.getDimension(code.name.monkey.retromusic.R.dimen.app_widget_card_radius) 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 // Load the album cover async and push the update on completion
service.runOnUiThread { service.runOnUiThread {
if (target != null) { if (target != null) {

View file

@ -16,7 +16,7 @@ package code.name.monkey.retromusic.dialogs
import android.app.Dialog import android.app.Dialog
import android.os.Bundle import android.os.Bundle
import android.text.Html import androidx.core.text.HtmlCompat
import androidx.fragment.app.DialogFragment import androidx.fragment.app.DialogFragment
import code.name.monkey.retromusic.R import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.R.string import code.name.monkey.retromusic.R.string
@ -37,14 +37,18 @@ class RemoveFromPlaylistDialog : DialogFragment() {
if (songs != null) { if (songs != null) {
if (songs.size > 1) { if (songs.size > 1) {
title = R.string.remove_songs_from_playlist_title 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 { } else {
title = R.string.remove_song_from_playlist_title title = R.string.remove_song_from_playlist_title
content = Html.fromHtml( content = HtmlCompat.fromHtml(
getString( getString(
code.name.monkey.retromusic.R.string.remove_song_x_from_playlist, code.name.monkey.retromusic.R.string.remove_song_x_from_playlist,
songs[0].title songs[0].title
) ),
HtmlCompat.FROM_HTML_MODE_LEGACY
) )
} }
} }
@ -58,7 +62,10 @@ class RemoveFromPlaylistDialog : DialogFragment() {
positiveButton(R.string.remove_action) { positiveButton(R.string.remove_action) {
if (activity == null) if (activity == null)
return@positiveButton return@positiveButton
PlaylistsUtil.removeFromPlaylist(activity!!, songs as MutableList<PlaylistSong>) PlaylistsUtil.removeFromPlaylist(
requireContext(),
songs as MutableList<PlaylistSong>
)
} }
cornerRadius(PreferenceUtil.getInstance(requireContext()).dialogCorner) cornerRadius(PreferenceUtil.getInstance(requireContext()).dialogCorner)
} }

View file

@ -47,7 +47,7 @@ class RenamePlaylistDialog : DialogFragment() {
negativeButton(android.R.string.cancel) negativeButton(android.R.string.cancel)
positiveButton(string.action_rename) { positiveButton(string.action_rename) {
if (playlistView.toString().trim { it <= ' ' } != "") { if (playlistView.toString().trim { it <= ' ' } != "") {
val playlistId = arguments!!.getLong(PLAYLIST_ID) val playlistId = requireArguments().getLong(PLAYLIST_ID)
PlaylistsUtil.renamePlaylist( PlaylistsUtil.renamePlaylist(
context, context,
playlistId, playlistId,

View file

@ -72,12 +72,12 @@ class SleepTimerDialog : DialogFragment() {
val nextSleepTimerElapsedTime = SystemClock.elapsedRealtime() + minutes * 60 * 1000 val nextSleepTimerElapsedTime = SystemClock.elapsedRealtime() + minutes * 60 * 1000
PreferenceUtil.getInstance(requireContext()) PreferenceUtil.getInstance(requireContext())
.setNextSleepTimerElapsedRealtime(nextSleepTimerElapsedTime) .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) am.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, nextSleepTimerElapsedTime, pi)
Toast.makeText( Toast.makeText(
activity, requireContext(),
activity!!.resources.getString(R.string.sleep_timer_set, minutes), requireContext().resources.getString(R.string.sleep_timer_set, minutes),
Toast.LENGTH_SHORT Toast.LENGTH_SHORT
).show() ).show()
} }
@ -87,12 +87,13 @@ class SleepTimerDialog : DialogFragment() {
} }
val previous = makeTimerPendingIntent(PendingIntent.FLAG_NO_CREATE) val previous = makeTimerPendingIntent(PendingIntent.FLAG_NO_CREATE)
if (previous != null) { if (previous != null) {
val am = activity!!.getSystemService(Context.ALARM_SERVICE) as AlarmManager val am =
requireContext().getSystemService(Context.ALARM_SERVICE) as AlarmManager
am.cancel(previous) am.cancel(previous)
previous.cancel() previous.cancel()
Toast.makeText( Toast.makeText(
activity, requireContext(),
activity!!.resources.getString(R.string.sleep_timer_canceled), requireContext().resources.getString(R.string.sleep_timer_canceled),
Toast.LENGTH_SHORT Toast.LENGTH_SHORT
).show() ).show()
} }
@ -101,8 +102,8 @@ class SleepTimerDialog : DialogFragment() {
if (musicService != null && musicService.pendingQuit) { if (musicService != null && musicService.pendingQuit) {
musicService.pendingQuit = false musicService.pendingQuit = false
Toast.makeText( Toast.makeText(
activity, requireContext(),
activity!!.resources.getString(R.string.sleep_timer_canceled), requireContext().resources.getString(R.string.sleep_timer_canceled),
Toast.LENGTH_SHORT Toast.LENGTH_SHORT
).show() ).show()
} }
@ -166,11 +167,11 @@ class SleepTimerDialog : DialogFragment() {
} }
private fun makeTimerPendingIntent(flag: Int): PendingIntent? { private fun makeTimerPendingIntent(flag: Int): PendingIntent? {
return PendingIntent.getService(activity, 0, makeTimerIntent(), flag) return PendingIntent.getService(requireActivity(), 0, makeTimerIntent(), flag)
} }
private fun makeTimerIntent(): Intent { private fun makeTimerIntent(): Intent {
val intent = Intent(activity, MusicService::class.java) val intent = Intent(requireActivity(), MusicService::class.java)
return if (shouldFinishLastSong.isChecked) { return if (shouldFinishLastSong.isChecked) {
intent.setAction(ACTION_PENDING_QUIT) intent.setAction(ACTION_PENDING_QUIT)
} else intent.setAction(ACTION_QUIT) } else intent.setAction(ACTION_QUIT)
@ -192,11 +193,11 @@ class SleepTimerDialog : DialogFragment() {
) { ) {
override fun onTick(millisUntilFinished: Long) { override fun onTick(millisUntilFinished: Long) {
materialDialog.getActionButton(WhichButton.NEGATIVE).text = materialDialog.getActionButton(WhichButton.NEGATIVE).text = String.format(
String.format( "%s %s",
"%s %s", materialDialog.context.getString(R.string.cancel_current_timer), materialDialog.context.getString(R.string.cancel_current_timer),
" (" + MusicUtil.getReadableDurationString(millisUntilFinished) + ")" " (" + MusicUtil.getReadableDurationString(millisUntilFinished) + ")"
) )
} }
override fun onFinish() { override fun onFinish() {

View file

@ -17,13 +17,13 @@ package code.name.monkey.retromusic.dialogs
import android.app.Dialog import android.app.Dialog
import android.content.Context import android.content.Context
import android.os.Bundle import android.os.Bundle
import android.text.Html
import android.text.Spanned import android.text.Spanned
import android.util.Log import android.util.Log
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.TextView import android.widget.TextView
import androidx.annotation.NonNull import androidx.annotation.NonNull
import androidx.core.text.HtmlCompat
import androidx.fragment.app.DialogFragment import androidx.fragment.app.DialogFragment
import code.name.monkey.retromusic.R import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.R.string import code.name.monkey.retromusic.R.string
@ -53,7 +53,7 @@ class SongDetailDialog : DialogFragment() {
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val context: Context = requireContext() val context: Context = requireContext()
val song = arguments!!.getParcelable<Song>("song") val song = requireArguments().getParcelable<Song>("song")
val materialDialog = MaterialDialog(requireContext(), BottomSheet(LayoutMode.WRAP_CONTENT)) val materialDialog = MaterialDialog(requireContext(), BottomSheet(LayoutMode.WRAP_CONTENT))
.show { .show {
@ -180,7 +180,10 @@ class SongDetailDialog : DialogFragment() {
} }
private fun makeTextWithTitle(context: Context, titleResId: Int, text: String?): Spanned { private fun makeTextWithTitle(context: Context, titleResId: Int, text: String?): Spanned {
return Html.fromHtml("<b>" + context.resources.getString(titleResId) + ": " + "</b>" + text) return HtmlCompat.fromHtml(
"<b>" + context.resources.getString(titleResId) + ": " + "</b>" + text,
HtmlCompat.FROM_HTML_MODE_LEGACY
)
} }
private fun getFileSizeString(sizeInBytes: Long): String { private fun getFileSizeString(sizeInBytes: Long): String {

View file

@ -30,7 +30,7 @@ import com.afollestad.materialdialogs.list.listItems
class SongShareDialog : DialogFragment() { class SongShareDialog : DialogFragment() {
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val song: Song? = arguments?.getParcelable("song") val song: Song? = requireArguments().getParcelable("song")
val currentlyListening: String = val currentlyListening: String =
getString(R.string.currently_listening_to_x_by_x, song?.title, song?.artistName) getString(R.string.currently_listening_to_x_by_x, song?.title, song?.artistName)

View file

@ -45,8 +45,4 @@ abstract class AbsMainActivityFragment : AbsMusicServiceFragment() {
setStatusBarColor(view, ColorUtil.darkenColor(colorPrimary)) setStatusBarColor(view, ColorUtil.darkenColor(colorPrimary))
} }
} }
protected fun showMainMenu(option: Int) {
OptionsSheetDialogFragment.newInstance(option).show(childFragmentManager, "Main_Menu")
}
} }

View file

@ -121,7 +121,7 @@ abstract class AbsPlayerFragment : AbsMusicServiceFragment(),
return true return true
} }
R.id.action_sleep_timer -> { R.id.action_sleep_timer -> {
SleepTimerDialog().show(requireFragmentManager(), TAG) SleepTimerDialog().show(parentFragmentManager, TAG)
return true return true
} }
R.id.action_set_as_ringtone -> { R.id.action_set_as_ringtone -> {

View file

@ -17,10 +17,10 @@ package code.name.monkey.retromusic.preferences
import android.app.Dialog import android.app.Dialog
import android.content.Context import android.content.Context
import android.os.Bundle import android.os.Bundle
import android.text.Html
import android.util.AttributeSet import android.util.AttributeSet
import androidx.core.graphics.BlendModeColorFilterCompat import androidx.core.graphics.BlendModeColorFilterCompat
import androidx.core.graphics.BlendModeCompat.SRC_IN import androidx.core.graphics.BlendModeCompat.SRC_IN
import androidx.core.text.HtmlCompat
import androidx.fragment.app.DialogFragment import androidx.fragment.app.DialogFragment
import code.name.monkey.appthemehelper.common.prefs.supportv7.ATEDialogPreference import code.name.monkey.appthemehelper.common.prefs.supportv7.ATEDialogPreference
import code.name.monkey.retromusic.R import code.name.monkey.retromusic.R
@ -91,11 +91,12 @@ class BlacklistPreferenceDialog : DialogFragment(), BlacklistFolderChooserDialog
cornerRadius(PreferenceUtil.getInstance(requireContext()).dialogCorner) cornerRadius(PreferenceUtil.getInstance(requireContext()).dialogCorner)
title(code.name.monkey.retromusic.R.string.remove_from_blacklist) title(code.name.monkey.retromusic.R.string.remove_from_blacklist)
message( message(
text = Html.fromHtml( text = HtmlCompat.fromHtml(
getString( getString(
code.name.monkey.retromusic.R.string.do_you_want_to_remove_from_the_blacklist, code.name.monkey.retromusic.R.string.do_you_want_to_remove_from_the_blacklist,
text text
) ),
HtmlCompat.FROM_HTML_MODE_LEGACY
) )
) )
positiveButton(code.name.monkey.retromusic.R.string.remove_action) { positiveButton(code.name.monkey.retromusic.R.string.remove_action) {

View file

@ -43,7 +43,6 @@ import java.util.List;
import java.util.Objects; import java.util.Objects;
import code.name.monkey.retromusic.R; 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.AlbumCoverStyle;
import code.name.monkey.retromusic.fragments.NowPlayingScreen; import code.name.monkey.retromusic.fragments.NowPlayingScreen;
import code.name.monkey.retromusic.fragments.mainactivity.FoldersFragment; import code.name.monkey.retromusic.fragments.mainactivity.FoldersFragment;
@ -587,9 +586,6 @@ public final class PreferenceUtil {
return mPreferences.getInt(LAST_CHANGELOG_VERSION, -1); return mPreferences.getInt(LAST_CHANGELOG_VERSION, -1);
} }
public final int getLastMusicChooser() {
return mPreferences.getInt(LAST_MUSIC_CHOOSER, OptionsSheetDialogFragment.LIBRARY);
}
public void setLastMusicChooser(int value) { public void setLastMusicChooser(int value) {
mPreferences.edit().putInt(LAST_MUSIC_CHOOSER, value).apply(); mPreferences.edit().putInt(LAST_MUSIC_CHOOSER, value).apply();

View file

@ -16,7 +16,6 @@ package code.name.monkey.retromusic.util
import android.content.res.ColorStateList import android.content.res.ColorStateList
import android.content.res.Resources import android.content.res.Resources
import android.graphics.PorterDuff
import android.graphics.drawable.LayerDrawable import android.graphics.drawable.LayerDrawable
import android.os.Build import android.os.Build
import android.view.View import android.view.View
@ -42,7 +41,8 @@ object ViewUtil {
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP_MR1) { if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP_MR1) {
val layerDrawable = progressSlider.progressDrawable as LayerDrawable val layerDrawable = progressSlider.progressDrawable as LayerDrawable
val progressDrawable = layerDrawable.findDrawableByLayerId(android.R.id.progress) val progressDrawable = layerDrawable.findDrawableByLayerId(android.R.id.progress)
progressDrawable.setColorFilter(newColor, PorterDuff.Mode.SRC_IN) progressDrawable.colorFilter =
BlendModeColorFilterCompat.createBlendModeColorFilterCompat(newColor, SRC_IN)
} else { } else {
progressSlider.progressTintList = ColorStateList.valueOf(newColor) progressSlider.progressTintList = ColorStateList.valueOf(newColor)
} }