Fix crashing when switching between tabs fast
This commit is contained in:
parent
7c95fe2e69
commit
cf402a27c2
15 changed files with 27 additions and 159 deletions
|
@ -13,8 +13,8 @@ android {
|
||||||
vectorDrawables.useSupportLibrary = true
|
vectorDrawables.useSupportLibrary = true
|
||||||
|
|
||||||
applicationId "code.name.monkey.retromusic"
|
applicationId "code.name.monkey.retromusic"
|
||||||
versionCode 381
|
versionCode 382
|
||||||
versionName '3.4.400-beta07'
|
versionName '3.4.400-beta08'
|
||||||
|
|
||||||
multiDexEnabled true
|
multiDexEnabled true
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,6 @@ import android.os.Bundle
|
||||||
import android.provider.MediaStore
|
import android.provider.MediaStore
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import androidx.fragment.app.DialogFragment
|
import androidx.fragment.app.DialogFragment
|
||||||
import code.name.monkey.appthemehelper.ThemeStore
|
|
||||||
import code.name.monkey.appthemehelper.util.MaterialUtil
|
import code.name.monkey.appthemehelper.util.MaterialUtil
|
||||||
import code.name.monkey.retromusic.R
|
import code.name.monkey.retromusic.R
|
||||||
import code.name.monkey.retromusic.R.layout
|
import code.name.monkey.retromusic.R.layout
|
||||||
|
@ -30,8 +29,6 @@ import code.name.monkey.retromusic.util.PlaylistsUtil
|
||||||
import code.name.monkey.retromusic.util.PreferenceUtil
|
import code.name.monkey.retromusic.util.PreferenceUtil
|
||||||
import com.afollestad.materialdialogs.LayoutMode
|
import com.afollestad.materialdialogs.LayoutMode
|
||||||
import com.afollestad.materialdialogs.MaterialDialog
|
import com.afollestad.materialdialogs.MaterialDialog
|
||||||
import com.afollestad.materialdialogs.WhichButton
|
|
||||||
import com.afollestad.materialdialogs.actions.getActionButton
|
|
||||||
import com.afollestad.materialdialogs.bottomsheets.BottomSheet
|
import com.afollestad.materialdialogs.bottomsheets.BottomSheet
|
||||||
import com.afollestad.materialdialogs.customview.customView
|
import com.afollestad.materialdialogs.customview.customView
|
||||||
import com.afollestad.materialdialogs.customview.getCustomView
|
import com.afollestad.materialdialogs.customview.getCustomView
|
||||||
|
@ -67,7 +64,6 @@ class CreatePlaylistDialog : DialogFragment() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
getActionButton(WhichButton.POSITIVE).updateTextColor(ThemeStore.accentColor(context))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val dialogView = materialDialog.getCustomView()
|
val dialogView = materialDialog.getCustomView()
|
||||||
|
@ -77,12 +73,11 @@ class CreatePlaylistDialog : DialogFragment() {
|
||||||
MaterialUtil.setTint(actionNewPlaylistContainer, false)
|
MaterialUtil.setTint(actionNewPlaylistContainer, false)
|
||||||
|
|
||||||
val playlistId = arguments!!.getLong(MediaStore.Audio.Playlists.Members.PLAYLIST_ID)
|
val playlistId = arguments!!.getLong(MediaStore.Audio.Playlists.Members.PLAYLIST_ID)
|
||||||
playlistView.appHandleColor().setText(PlaylistsUtil.getNameForPlaylist(context!!, playlistId), TextView.BufferType.EDITABLE)
|
playlistView.appHandleColor().setText(PlaylistsUtil.getNameForPlaylist(requireContext(), playlistId), TextView.BufferType.EDITABLE)
|
||||||
return materialDialog
|
return materialDialog
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private const val SONGS = "songs"
|
|
||||||
@JvmOverloads
|
@JvmOverloads
|
||||||
fun create(song: Song? = null): CreatePlaylistDialog {
|
fun create(song: Song? = null): CreatePlaylistDialog {
|
||||||
val list = ArrayList<Song>()
|
val list = ArrayList<Song>()
|
||||||
|
|
|
@ -19,7 +19,6 @@ import android.os.Bundle
|
||||||
import android.provider.MediaStore.Audio.Playlists.Members.PLAYLIST_ID
|
import android.provider.MediaStore.Audio.Playlists.Members.PLAYLIST_ID
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import androidx.fragment.app.DialogFragment
|
import androidx.fragment.app.DialogFragment
|
||||||
import code.name.monkey.appthemehelper.ThemeStore
|
|
||||||
import code.name.monkey.appthemehelper.util.MaterialUtil
|
import code.name.monkey.appthemehelper.util.MaterialUtil
|
||||||
import code.name.monkey.retromusic.R
|
import code.name.monkey.retromusic.R
|
||||||
import code.name.monkey.retromusic.R.layout
|
import code.name.monkey.retromusic.R.layout
|
||||||
|
@ -29,8 +28,6 @@ import code.name.monkey.retromusic.util.PlaylistsUtil
|
||||||
import code.name.monkey.retromusic.util.PreferenceUtil
|
import code.name.monkey.retromusic.util.PreferenceUtil
|
||||||
import com.afollestad.materialdialogs.LayoutMode
|
import com.afollestad.materialdialogs.LayoutMode
|
||||||
import com.afollestad.materialdialogs.MaterialDialog
|
import com.afollestad.materialdialogs.MaterialDialog
|
||||||
import com.afollestad.materialdialogs.WhichButton
|
|
||||||
import com.afollestad.materialdialogs.actions.getActionButton
|
|
||||||
import com.afollestad.materialdialogs.bottomsheets.BottomSheet
|
import com.afollestad.materialdialogs.bottomsheets.BottomSheet
|
||||||
import com.afollestad.materialdialogs.customview.customView
|
import com.afollestad.materialdialogs.customview.customView
|
||||||
import com.afollestad.materialdialogs.customview.getCustomView
|
import com.afollestad.materialdialogs.customview.getCustomView
|
||||||
|
@ -55,7 +52,6 @@ class RenamePlaylistDialog : DialogFragment() {
|
||||||
PlaylistsUtil.renamePlaylist(context, playlistId, playlistView.text!!.toString())
|
PlaylistsUtil.renamePlaylist(context, playlistId, playlistView.text!!.toString())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
getActionButton(WhichButton.POSITIVE).updateTextColor(ThemeStore.accentColor(context))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val dialogView = materialDialog.getCustomView()
|
val dialogView = materialDialog.getCustomView()
|
||||||
|
|
|
@ -181,78 +181,7 @@ class SleepTimerDialog : DialogFragment() {
|
||||||
updateCancelButton()
|
updateCancelButton()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
|
||||||
return inflater.inflate(R.layout.dialog_sleep_timer, container, false)
|
|
||||||
}*/
|
|
||||||
|
|
||||||
private fun setProgressBarColor(dark: Int) {
|
private fun setProgressBarColor(dark: Int) {
|
||||||
ViewUtil.setProgressDrawable(progressSlider = seekBar, newColor = dark)
|
ViewUtil.setProgressDrawable(progressSlider = seekBar, newColor = dark)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
|
||||||
super.onViewCreated(view, savedInstanceState)
|
|
||||||
|
|
||||||
MaterialUtil.setTint(actionCancel, false)
|
|
||||||
|
|
||||||
title.setTextColor(ThemeStore.textColorPrimary(context!!))
|
|
||||||
timerDisplay!!.setTextColor(ThemeStore.textColorSecondary(context!!))
|
|
||||||
|
|
||||||
timerUpdater = TimerUpdater()
|
|
||||||
|
|
||||||
seekArcProgress = PreferenceUtil.getInstance().lastSleepTimerValue
|
|
||||||
updateTimeDisplayTime()
|
|
||||||
seekBar.progress = seekArcProgress
|
|
||||||
|
|
||||||
setProgressBarColor(ThemeStore.accentColor(context!!))
|
|
||||||
|
|
||||||
seekBar.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
|
|
||||||
override fun onProgressChanged(seekBar: SeekBar, i: Int, b: Boolean) {
|
|
||||||
if (i < 1) {
|
|
||||||
seekBar.progress = 1
|
|
||||||
return
|
|
||||||
}
|
|
||||||
seekArcProgress = i
|
|
||||||
updateTimeDisplayTime()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onStartTrackingTouch(seekBar: SeekBar) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onStopTrackingTouch(seekBar: SeekBar) {
|
|
||||||
PreferenceUtil.getInstance().lastSleepTimerValue = seekArcProgress
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
actionCancel.apply {
|
|
||||||
icon = ContextCompat.getDrawable(context, R.drawable.ic_close_white_24dp)
|
|
||||||
setOnClickListener {
|
|
||||||
val previous = makeTimerPendingIntent(PendingIntent.FLAG_NO_CREATE)
|
|
||||||
if (previous != null) {
|
|
||||||
val am = activity!!.getSystemService(Context.ALARM_SERVICE) as AlarmManager
|
|
||||||
am.cancel(previous)
|
|
||||||
previous.cancel()
|
|
||||||
Toast.makeText(activity, activity!!.resources.getString(R.string.sleep_timer_canceled), Toast.LENGTH_SHORT).show()
|
|
||||||
}
|
|
||||||
dismiss()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
actionSet.apply {
|
|
||||||
icon = ContextCompat.getDrawable(context, R.drawable.ic_time_lapse_white_24dp)
|
|
||||||
MaterialUtil.setTint(actionSet)
|
|
||||||
setOnClickListener {
|
|
||||||
val minutes = seekArcProgress
|
|
||||||
val pi = makeTimerPendingIntent(PendingIntent.FLAG_CANCEL_CURRENT)
|
|
||||||
val nextSleepTimerElapsedTime = SystemClock.elapsedRealtime() + minutes * 60 * 1000
|
|
||||||
PreferenceUtil.getInstance().setNextSleepTimerElapsedRealtime(nextSleepTimerElapsedTime)
|
|
||||||
val am = activity!!.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), Toast.LENGTH_SHORT).show()
|
|
||||||
dismiss()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -50,8 +50,8 @@ class PlaylistsFragment : AbsLibraryPagerRecyclerViewFragment<PlaylistAdapter, L
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroyView() {
|
override fun onDestroyView() {
|
||||||
super.onDestroyView()
|
|
||||||
playlistsPresenter.detachView()
|
playlistsPresenter.detachView()
|
||||||
|
super.onDestroyView()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onMediaStoreChanged() {
|
override fun onMediaStoreChanged() {
|
||||||
|
|
|
@ -50,30 +50,30 @@ interface AlbumDetailsPresenter : Presenter<AlbumDetailsView> {
|
||||||
override fun loadMore(artistId: Int) {
|
override fun loadMore(artistId: Int) {
|
||||||
disposable += repository.getArtistByIdFlowable(artistId)
|
disposable += repository.getArtistByIdFlowable(artistId)
|
||||||
.map {
|
.map {
|
||||||
view.loadArtistImage(it)
|
view?.loadArtistImage(it)
|
||||||
return@map it.albums
|
return@map it.albums
|
||||||
}
|
}
|
||||||
.map {
|
.map {
|
||||||
it.filter { filterAlbum -> album.id != filterAlbum.id }
|
it.filter { filterAlbum -> album.id != filterAlbum.id }
|
||||||
}
|
}
|
||||||
.subscribe {
|
.subscribe({
|
||||||
if (it.isEmpty()) {
|
if (it.isEmpty()) {
|
||||||
return@subscribe
|
return@subscribe
|
||||||
}
|
}
|
||||||
view.moreAlbums(ArrayList(it))
|
view?.moreAlbums(ArrayList(it))
|
||||||
}
|
}, { t -> println(t) })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
override fun loadAlbum(albumId: Int) {
|
override fun loadAlbum(albumId: Int) {
|
||||||
disposable += repository.getAlbumFlowable(albumId)
|
disposable += repository.getAlbumFlowable(albumId)
|
||||||
.doOnComplete {
|
.doOnComplete {
|
||||||
view.complete()
|
view?.complete()
|
||||||
}
|
}
|
||||||
.subscribe {
|
.subscribe({
|
||||||
album = it
|
album = it
|
||||||
view.album(it)
|
view?.album(it)
|
||||||
}
|
}, { t -> println(t) })
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun detachView() {
|
override fun detachView() {
|
||||||
|
|
|
@ -42,16 +42,17 @@ interface AlbumsPresenter : Presenter<AlbumsView> {
|
||||||
private var disposable: Disposable? = null
|
private var disposable: Disposable? = null
|
||||||
|
|
||||||
private fun showList(albums: ArrayList<Album>) {
|
private fun showList(albums: ArrayList<Album>) {
|
||||||
if (albums.isNotEmpty()) view.albums(albums) else view.showEmptyView()
|
view?.albums(albums)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun detachView() {
|
override fun detachView() {
|
||||||
super.detachView()
|
super.detachView()
|
||||||
disposable?.dispose()
|
disposable?.dispose()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun loadAlbums() {
|
override fun loadAlbums() {
|
||||||
disposable = repository.allAlbumsFlowable
|
disposable = repository.allAlbumsFlowable
|
||||||
.subscribe { this.showList(it) }
|
.subscribe({ view?.albums(it) }, { t -> println(t) })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -51,7 +51,7 @@ interface ArtistDetailsPresenter : Presenter<ArtistDetailsView> {
|
||||||
cache: String?) {
|
cache: String?) {
|
||||||
disposable += repository.artistInfoFloable(name, lang, cache)
|
disposable += repository.artistInfoFloable(name, lang, cache)
|
||||||
.subscribe {
|
.subscribe {
|
||||||
view.artistInfo(it)
|
view?.artistInfo(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,20 +60,16 @@ interface ArtistDetailsPresenter : Presenter<ArtistDetailsView> {
|
||||||
override fun loadArtist(artistId: Int) {
|
override fun loadArtist(artistId: Int) {
|
||||||
disposable += repository.getArtistByIdFlowable(artistId)
|
disposable += repository.getArtistByIdFlowable(artistId)
|
||||||
.doOnComplete {
|
.doOnComplete {
|
||||||
view.complete()
|
view?.complete()
|
||||||
}
|
|
||||||
.subscribe {
|
|
||||||
this.showArtist(it)
|
|
||||||
}
|
}
|
||||||
|
.subscribe({
|
||||||
|
view?.artist(it)
|
||||||
|
}, { t -> println(t) })
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun detachView() {
|
override fun detachView() {
|
||||||
super.detachView()
|
super.detachView()
|
||||||
disposable.dispose()
|
disposable.dispose()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun showArtist(artist: Artist) {
|
|
||||||
view.artist(artist)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -14,14 +14,12 @@
|
||||||
|
|
||||||
package code.name.monkey.retromusic.mvp.presenter
|
package code.name.monkey.retromusic.mvp.presenter
|
||||||
|
|
||||||
import code.name.monkey.retromusic.helper.SearchQueryHelper.songs
|
|
||||||
import code.name.monkey.retromusic.model.Artist
|
import code.name.monkey.retromusic.model.Artist
|
||||||
import code.name.monkey.retromusic.mvp.BaseView
|
import code.name.monkey.retromusic.mvp.BaseView
|
||||||
import code.name.monkey.retromusic.mvp.Presenter
|
import code.name.monkey.retromusic.mvp.Presenter
|
||||||
import code.name.monkey.retromusic.mvp.PresenterImpl
|
import code.name.monkey.retromusic.mvp.PresenterImpl
|
||||||
import code.name.monkey.retromusic.providers.interfaces.Repository
|
import code.name.monkey.retromusic.providers.interfaces.Repository
|
||||||
import io.reactivex.disposables.Disposable
|
import io.reactivex.disposables.Disposable
|
||||||
import io.reactivex.functions.Consumer
|
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
interface ArtistsView : BaseView {
|
interface ArtistsView : BaseView {
|
||||||
|
@ -38,13 +36,6 @@ interface ArtistsPresenter : Presenter<ArtistsView> {
|
||||||
|
|
||||||
private var disposable: Disposable? = null
|
private var disposable: Disposable? = null
|
||||||
|
|
||||||
private fun showList(artists: ArrayList<Artist>) {
|
|
||||||
if (songs.isNotEmpty())
|
|
||||||
view.artists(artists)
|
|
||||||
else
|
|
||||||
view.showEmptyView()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun detachView() {
|
override fun detachView() {
|
||||||
super.detachView()
|
super.detachView()
|
||||||
disposable?.dispose()
|
disposable?.dispose()
|
||||||
|
@ -52,11 +43,7 @@ interface ArtistsPresenter : Presenter<ArtistsView> {
|
||||||
|
|
||||||
override fun loadArtists() {
|
override fun loadArtists() {
|
||||||
disposable = repository.allArtistsFlowable
|
disposable = repository.allArtistsFlowable
|
||||||
.subscribe({
|
.subscribe({ view?.artists(it) }, { t -> println(t) })
|
||||||
view.artists(it)
|
|
||||||
}, {
|
|
||||||
println(it)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,18 +48,7 @@ interface GenreDetailsPresenter : Presenter<GenreDetailsView> {
|
||||||
|
|
||||||
override fun loadGenreSongs(genreId: Int) {
|
override fun loadGenreSongs(genreId: Int) {
|
||||||
disposable = repository.getGenreFlowable(genreId)
|
disposable = repository.getGenreFlowable(genreId)
|
||||||
.subscribe {
|
.subscribe({ view?.songs(it) }, { t -> println(t) })
|
||||||
showGenre(it)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun showGenre(songs: ArrayList<Song>) {
|
|
||||||
if (songs.isNotEmpty()) {
|
|
||||||
view.songs(songs)
|
|
||||||
} else {
|
|
||||||
view.showEmptyView()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,15 +41,7 @@ interface GenresPresenter : Presenter<GenresView> {
|
||||||
|
|
||||||
override fun loadGenres() {
|
override fun loadGenres() {
|
||||||
disposable = repository.allGenresFlowable
|
disposable = repository.allGenresFlowable
|
||||||
.subscribe { this.showList(it) }
|
.subscribe({ view.genres(it) }, { t -> println(t) })
|
||||||
}
|
|
||||||
|
|
||||||
private fun showList(genres: ArrayList<Genre>) {
|
|
||||||
if (genres.isNotEmpty()) {
|
|
||||||
view.genres(genres)
|
|
||||||
} else {
|
|
||||||
view.showEmptyView()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,15 +43,7 @@ interface PlaylistsPresenter : Presenter<PlaylistView> {
|
||||||
|
|
||||||
override fun playlists() {
|
override fun playlists() {
|
||||||
disposable = repository.allPlaylistsFlowable
|
disposable = repository.allPlaylistsFlowable
|
||||||
.subscribe { this.showList(it) }
|
.subscribe({ view?.playlists(it) }, { t -> println(t) })
|
||||||
}
|
|
||||||
|
|
||||||
private fun showList(arrayList: ArrayList<Playlist>) {
|
|
||||||
if (arrayList.isEmpty()) {
|
|
||||||
view.showEmptyView()
|
|
||||||
} else {
|
|
||||||
view.playlists(arrayList)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,19 +41,12 @@ interface PlaylistSongsPresenter : Presenter<PlaylistSongsView> {
|
||||||
|
|
||||||
override fun loadPlaylistSongs(playlist: Playlist) {
|
override fun loadPlaylistSongs(playlist: Playlist) {
|
||||||
disposable = repository.getPlaylistSongsFlowable(playlist)
|
disposable = repository.getPlaylistSongsFlowable(playlist)
|
||||||
.subscribe {
|
.subscribe({ view?.songs(it) }, { t -> println(t) })
|
||||||
view.songs(it)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun detachView() {
|
override fun detachView() {
|
||||||
super.detachView()
|
super.detachView()
|
||||||
disposable?.dispose()
|
disposable?.dispose()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun attachView(view: PlaylistSongsView) {
|
|
||||||
super.attachView(view)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -46,7 +46,7 @@ interface SearchPresenter : Presenter<SearchView> {
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun search(query: String?) {
|
override fun search(query: String?) {
|
||||||
view.showData(repository.search(query))
|
view?.showData(repository.search(query))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,9 +42,7 @@ interface SongPresenter : Presenter<SongView> {
|
||||||
|
|
||||||
override fun loadSongs() {
|
override fun loadSongs() {
|
||||||
disposable = repository.allSongsFlowable
|
disposable = repository.allSongsFlowable
|
||||||
.subscribe({
|
.subscribe({ view?.songs(it) }, { t -> print(t) })
|
||||||
view?.songs(it)
|
|
||||||
}, { t -> print(t) })
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun detachView() {
|
override fun detachView() {
|
||||||
|
|
Loading…
Reference in a new issue