Merge branch 'dev' of https://github.com/h4h13/RetroMusicPlayer into google-san

This commit is contained in:
Hemanth S 2020-05-26 04:17:37 +05:30
commit e534e6ce75
92 changed files with 887 additions and 1127 deletions

View file

@ -137,11 +137,9 @@ dependencies {
implementation "com.squareup.retrofit2:retrofit:$retrofit_version" implementation "com.squareup.retrofit2:retrofit:$retrofit_version"
implementation "com.squareup.retrofit2:converter-gson:$retrofit_version" implementation "com.squareup.retrofit2:converter-gson:$retrofit_version"
def material_dialog_version = "3.1.1" def material_dialog_version = "0.9.6.0"
implementation "com.afollestad.material-dialogs:core:$material_dialog_version" implementation "com.afollestad.material-dialogs:core:$material_dialog_version"
implementation "com.afollestad.material-dialogs:input:$material_dialog_version" implementation "com.afollestad.material-dialogs:commons:$material_dialog_version"
implementation "com.afollestad.material-dialogs:color:$material_dialog_version"
implementation "com.afollestad.material-dialogs:bottomsheets:$material_dialog_version"
implementation 'com.afollestad:material-cab:0.1.12' implementation 'com.afollestad:material-cab:0.1.12'
implementation 'com.github.bumptech.glide:glide:3.8.0' implementation 'com.github.bumptech.glide:glide:3.8.0'

View file

@ -105,7 +105,7 @@
<data android:mimeType="vnd.android.cursor.dir/audio" /> <data android:mimeType="vnd.android.cursor.dir/audio" />
</intent-filter> </intent-filter>
</activity> </activity>
<activity android:name=".activities.AlbumDetailsActivity" /> <activity android:name=".activities.albums.AlbumDetailsActivity" />
<activity android:name=".activities.ArtistDetailActivity" /> <activity android:name=".activities.ArtistDetailActivity" />
<activity android:name=".activities.PlaylistDetailActivity" /> <activity android:name=".activities.PlaylistDetailActivity" />
<activity android:name=".activities.PlayingQueueActivity" /> <activity android:name=".activities.PlayingQueueActivity" />

View file

@ -22,6 +22,7 @@ import code.name.monkey.retromusic.activities.base.AbsSlidingMusicPanelActivity
import code.name.monkey.retromusic.adapter.album.HorizontalAlbumAdapter import code.name.monkey.retromusic.adapter.album.HorizontalAlbumAdapter
import code.name.monkey.retromusic.adapter.song.SimpleSongAdapter import code.name.monkey.retromusic.adapter.song.SimpleSongAdapter
import code.name.monkey.retromusic.dialogs.AddToPlaylistDialog import code.name.monkey.retromusic.dialogs.AddToPlaylistDialog
import code.name.monkey.retromusic.extensions.extraNotNull
import code.name.monkey.retromusic.extensions.ripAlpha import code.name.monkey.retromusic.extensions.ripAlpha
import code.name.monkey.retromusic.extensions.show import code.name.monkey.retromusic.extensions.show
import code.name.monkey.retromusic.extensions.surfaceColor import code.name.monkey.retromusic.extensions.surfaceColor
@ -95,21 +96,13 @@ class ArtistDetailActivity : AbsSlidingMusicPanelActivity(), ArtistDetailsView,
setLightNavigationBar(true) setLightNavigationBar(true)
setBottomBarVisibility(View.GONE) setBottomBarVisibility(View.GONE)
window.sharedElementsUseOverlay = true window.sharedElementsUseOverlay = true
windowEnterTransition()
App.musicComponent.inject(this) App.musicComponent.inject(this)
artistDetailsPresenter.attachView(this) artistDetailsPresenter.attachView(this)
val artistId = extraNotNull<Int>(EXTRA_ARTIST_ID).value
artistDetailsPresenter.loadArtist(artistId)
if (intent.extras!!.containsKey(EXTRA_ARTIST_ID)) {
intent.extras?.getInt(EXTRA_ARTIST_ID)?.let {
artistDetailsPresenter.loadArtist(it)
val name = "${getString(R.string.transition_artist_image)}_$it"
artistCoverContainer?.transitionName = name
}
} else {
finish()
}
windowEnterTransition()
ActivityCompat.postponeEnterTransition(this) ActivityCompat.postponeEnterTransition(this)
setupRecyclerView() setupRecyclerView()

View file

@ -6,7 +6,6 @@ import android.content.res.ColorStateList
import android.os.AsyncTask import android.os.AsyncTask
import android.os.Build import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.text.InputType
import android.text.TextUtils import android.text.TextUtils
import android.view.* import android.view.*
import androidx.annotation.StringRes import androidx.annotation.StringRes
@ -16,12 +15,14 @@ import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentStatePagerAdapter import androidx.fragment.app.FragmentStatePagerAdapter
import androidx.viewpager.widget.ViewPager import androidx.viewpager.widget.ViewPager
import code.name.monkey.appthemehelper.ThemeStore import code.name.monkey.appthemehelper.ThemeStore
import code.name.monkey.appthemehelper.util.*
import code.name.monkey.appthemehelper.util.ATHUtil.resolveColor import code.name.monkey.appthemehelper.util.ATHUtil.resolveColor
import code.name.monkey.appthemehelper.util.ColorUtil
import code.name.monkey.appthemehelper.util.MaterialValueHelper
import code.name.monkey.appthemehelper.util.TintHelper
import code.name.monkey.appthemehelper.util.ToolbarContentTintHelper
import code.name.monkey.retromusic.App import code.name.monkey.retromusic.App
import code.name.monkey.retromusic.R import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.activities.base.AbsMusicServiceActivity import code.name.monkey.retromusic.activities.base.AbsMusicServiceActivity
import code.name.monkey.retromusic.activities.tageditor.WriteTagsAsyncTask
import code.name.monkey.retromusic.extensions.surfaceColor import code.name.monkey.retromusic.extensions.surfaceColor
import code.name.monkey.retromusic.extensions.textColorSecondary import code.name.monkey.retromusic.extensions.textColorSecondary
import code.name.monkey.retromusic.fragments.base.AbsMusicServiceFragment import code.name.monkey.retromusic.fragments.base.AbsMusicServiceFragment
@ -34,18 +35,10 @@ import code.name.monkey.retromusic.model.lyrics.Lyrics
import code.name.monkey.retromusic.util.LyricUtil import code.name.monkey.retromusic.util.LyricUtil
import code.name.monkey.retromusic.util.MusicUtil import code.name.monkey.retromusic.util.MusicUtil
import code.name.monkey.retromusic.util.PreferenceUtilKT import code.name.monkey.retromusic.util.PreferenceUtilKT
import code.name.monkey.retromusic.util.RetroUtil
import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.input.getInputLayout
import com.afollestad.materialdialogs.input.input
import kotlinx.android.synthetic.main.activity_lyrics.* import kotlinx.android.synthetic.main.activity_lyrics.*
import kotlinx.android.synthetic.main.fragment_lyrics.* import kotlinx.android.synthetic.main.fragment_lyrics.*
import kotlinx.android.synthetic.main.fragment_synced.* import kotlinx.android.synthetic.main.fragment_synced.*
import org.jaudiotagger.tag.FieldKey
import java.io.File import java.io.File
import java.util.*
import kotlin.collections.ArrayList
import kotlin.collections.set
class LyricsActivity : AbsMusicServiceActivity(), View.OnClickListener, class LyricsActivity : AbsMusicServiceActivity(), View.OnClickListener,
ViewPager.OnPageChangeListener { ViewPager.OnPageChangeListener {
@ -170,7 +163,7 @@ class LyricsActivity : AbsMusicServiceActivity(), View.OnClickListener,
e.printStackTrace() e.printStackTrace()
} }
val materialDialog = MaterialDialog(this) /*val materialDialog = MaterialDialog(this)
.show { .show {
title(R.string.add_time_framed_lryics) title(R.string.add_time_framed_lryics)
negativeButton(R.string.action_search) { negativeButton(R.string.action_search) {
@ -188,7 +181,7 @@ class LyricsActivity : AbsMusicServiceActivity(), View.OnClickListener,
} }
} }
MaterialUtil.setTint(materialDialog.getInputLayout(), false) MaterialUtil.setTint(materialDialog.getInputLayout(), false)*/
} }
private fun updateSong() { private fun updateSong() {
@ -206,7 +199,7 @@ class LyricsActivity : AbsMusicServiceActivity(), View.OnClickListener,
lyricsString!! lyricsString!!
} }
val materialDialog = MaterialDialog( /*val materialDialog = MaterialDialog(
this this
).show { ).show {
@ -231,7 +224,7 @@ class LyricsActivity : AbsMusicServiceActivity(), View.OnClickListener,
updateSong() updateSong()
} }
} }
MaterialUtil.setTint(materialDialog.getInputLayout(), false) MaterialUtil.setTint(materialDialog.getInputLayout(), false)*/
} }
private fun getSongPaths(song: Song): ArrayList<String> { private fun getSongPaths(song: Song): ArrayList<String> {

View file

@ -228,6 +228,12 @@ class MainActivity : AbsSlidingMusicPanelActivity(),
menu.add(0, R.id.action_search, 0, getString(R.string.action_search)) menu.add(0, R.id.action_search, 0, getString(R.string.action_search))
.setIcon(R.drawable.ic_search_white_24dp) .setIcon(R.drawable.ic_search_white_24dp)
.setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_ALWAYS) .setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_ALWAYS)
ToolbarContentTintHelper.handleOnCreateOptionsMenu(
this,
toolbar,
menu,
getToolbarBackgroundColor(toolbar)
)
return super.onCreateOptionsMenu(menu) return super.onCreateOptionsMenu(menu)
} }

View file

@ -4,13 +4,17 @@ import android.os.Bundle
import android.view.MenuItem import android.view.MenuItem
import androidx.annotation.StringRes import androidx.annotation.StringRes
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import code.name.monkey.appthemehelper.ThemeStore
import code.name.monkey.appthemehelper.util.VersionUtils
import code.name.monkey.retromusic.R import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.activities.base.AbsBaseActivity import code.name.monkey.retromusic.activities.base.AbsBaseActivity
import code.name.monkey.retromusic.appshortcuts.DynamicShortcutManager
import code.name.monkey.retromusic.extensions.applyToolbar import code.name.monkey.retromusic.extensions.applyToolbar
import code.name.monkey.retromusic.fragments.settings.MainSettingsFragment import code.name.monkey.retromusic.fragments.settings.MainSettingsFragment
import com.afollestad.materialdialogs.color.ColorChooserDialog
import kotlinx.android.synthetic.main.activity_settings.* import kotlinx.android.synthetic.main.activity_settings.*
class SettingsActivity : AbsBaseActivity() { class SettingsActivity : AbsBaseActivity(), ColorChooserDialog.ColorCallback {
private val fragmentManager = supportFragmentManager private val fragmentManager = supportFragmentManager
@ -69,4 +73,19 @@ class SettingsActivity : AbsBaseActivity() {
companion object { companion object {
const val TAG: String = "SettingsActivity" const val TAG: String = "SettingsActivity"
} }
override fun onColorSelection(dialog: ColorChooserDialog, selectedColor: Int) {
when (dialog.title) {
R.string.accent_color -> {
ThemeStore.editTheme(this).accentColor(selectedColor).commit()
if (VersionUtils.hasNougatMR())
DynamicShortcutManager(this).updateDynamicShortcuts()
}
}
recreate()
}
override fun onColorChooserDismissed(dialog: ColorChooserDialog) {
}
} }

View file

@ -1,4 +1,4 @@
package code.name.monkey.retromusic.activities package code.name.monkey.retromusic.activities.albums
import android.app.ActivityOptions import android.app.ActivityOptions
import android.content.Intent import android.content.Intent
@ -10,13 +10,13 @@ import android.view.SubMenu
import android.view.View import android.view.View
import android.widget.ImageView import android.widget.ImageView
import androidx.core.app.ActivityCompat import androidx.core.app.ActivityCompat
import androidx.lifecycle.ViewModelProvider
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
import code.name.monkey.appthemehelper.util.ATHUtil import code.name.monkey.appthemehelper.util.ATHUtil
import code.name.monkey.appthemehelper.util.MaterialUtil import code.name.monkey.appthemehelper.util.MaterialUtil
import code.name.monkey.appthemehelper.util.ToolbarContentTintHelper import code.name.monkey.appthemehelper.util.ToolbarContentTintHelper
import code.name.monkey.retromusic.App
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.activities.tageditor.AbsTagEditorActivity import code.name.monkey.retromusic.activities.tageditor.AbsTagEditorActivity
@ -25,6 +25,7 @@ import code.name.monkey.retromusic.adapter.album.HorizontalAlbumAdapter
import code.name.monkey.retromusic.adapter.song.SimpleSongAdapter import code.name.monkey.retromusic.adapter.song.SimpleSongAdapter
import code.name.monkey.retromusic.dialogs.AddToPlaylistDialog import code.name.monkey.retromusic.dialogs.AddToPlaylistDialog
import code.name.monkey.retromusic.dialogs.DeleteSongsDialog import code.name.monkey.retromusic.dialogs.DeleteSongsDialog
import code.name.monkey.retromusic.extensions.extraNotNull
import code.name.monkey.retromusic.extensions.ripAlpha import code.name.monkey.retromusic.extensions.ripAlpha
import code.name.monkey.retromusic.extensions.show import code.name.monkey.retromusic.extensions.show
import code.name.monkey.retromusic.extensions.surfaceColor import code.name.monkey.retromusic.extensions.surfaceColor
@ -36,7 +37,6 @@ import code.name.monkey.retromusic.helper.SortOrder.AlbumSongSortOrder
import code.name.monkey.retromusic.interfaces.CabHolder import code.name.monkey.retromusic.interfaces.CabHolder
import code.name.monkey.retromusic.model.Album import code.name.monkey.retromusic.model.Album
import code.name.monkey.retromusic.model.Artist import code.name.monkey.retromusic.model.Artist
import code.name.monkey.retromusic.mvp.presenter.AlbumDetailsPresenter
import code.name.monkey.retromusic.mvp.presenter.AlbumDetailsView import code.name.monkey.retromusic.mvp.presenter.AlbumDetailsView
import code.name.monkey.retromusic.rest.model.LastFmAlbum import code.name.monkey.retromusic.rest.model.LastFmAlbum
import code.name.monkey.retromusic.util.* import code.name.monkey.retromusic.util.*
@ -46,7 +46,6 @@ import com.bumptech.glide.Glide
import kotlinx.android.synthetic.main.activity_album.* import kotlinx.android.synthetic.main.activity_album.*
import kotlinx.android.synthetic.main.activity_album_content.* import kotlinx.android.synthetic.main.activity_album_content.*
import java.util.* import java.util.*
import javax.inject.Inject
import android.util.Pair as UtilPair import android.util.Pair as UtilPair
class AlbumDetailsActivity : AbsSlidingMusicPanelActivity(), AlbumDetailsView, CabHolder { class AlbumDetailsActivity : AbsSlidingMusicPanelActivity(), AlbumDetailsView, CabHolder {
@ -69,6 +68,7 @@ class AlbumDetailsActivity : AbsSlidingMusicPanelActivity(), AlbumDetailsView, C
return cab as MaterialCab return cab as MaterialCab
} }
private lateinit var viewModel: AlbumDetailsViewModel
private lateinit var simpleSongAdapter: SimpleSongAdapter private lateinit var simpleSongAdapter: SimpleSongAdapter
private lateinit var album: Album private lateinit var album: Album
private lateinit var artistImage: ImageView private lateinit var artistImage: ImageView
@ -80,9 +80,6 @@ class AlbumDetailsActivity : AbsSlidingMusicPanelActivity(), AlbumDetailsView, C
return wrapSlidingMusicPanel(R.layout.activity_album) return wrapSlidingMusicPanel(R.layout.activity_album)
} }
@Inject
lateinit var albumDetailsPresenter: AlbumDetailsPresenter
private fun windowEnterTransition() { private fun windowEnterTransition() {
val slide = Slide() val slide = Slide()
slide.excludeTarget(R.id.appBarLayout, true) slide.excludeTarget(R.id.appBarLayout, true)
@ -101,34 +98,30 @@ class AlbumDetailsActivity : AbsSlidingMusicPanelActivity(), AlbumDetailsView, C
setLightNavigationBar(true) setLightNavigationBar(true)
setBottomBarVisibility(View.GONE) setBottomBarVisibility(View.GONE)
window.sharedElementsUseOverlay = true window.sharedElementsUseOverlay = true
App.musicComponent.inject(this)
albumDetailsPresenter.attachView(this)
if (intent.extras!!.containsKey(EXTRA_ALBUM_ID)) {
intent.extras?.getInt(EXTRA_ALBUM_ID)?.let {
albumDetailsPresenter.loadAlbum(it)
albumCoverContainer?.transitionName =
"${getString(R.string.transition_album_art)}_$it"
}
} else {
finish()
}
windowEnterTransition() windowEnterTransition()
val albumId = extraNotNull<Int>(EXTRA_ALBUM_ID).value
ActivityCompat.postponeEnterTransition(this) ActivityCompat.postponeEnterTransition(this)
val viewModelFactory = AlbumDetailsViewModelFactory(application, albumId)
viewModel = ViewModelProvider(this, viewModelFactory).get(AlbumDetailsViewModel::class.java)
artistImage = findViewById(R.id.artistImage) viewModel.getAlbum().observe(this, androidx.lifecycle.Observer {
ActivityCompat.startPostponedEnterTransition(this@AlbumDetailsActivity)
album(it)
})
viewModel.getArtist().observe(this, androidx.lifecycle.Observer {
loadArtistImage(it)
})
viewModel.getAlbumInfo().observe(this, androidx.lifecycle.Observer {
aboutAlbum(it)
})
setupRecyclerView() setupRecyclerView()
artistImage = findViewById(R.id.artistImage)
artistImage.setOnClickListener { artistImage.setOnClickListener {
val artistPairs = ActivityOptions.makeSceneTransitionAnimation( val artistPairs = ActivityOptions.makeSceneTransitionAnimation(
this, this,
UtilPair.create( UtilPair.create(
artistImage, artistImage,
"${getString(R.string.transition_artist_image)}_${album.artistId}" getString(R.string.transition_artist_image)
) )
) )
NavigationUtil.goToArtistOptions(this, album.artistId, artistPairs) NavigationUtil.goToArtistOptions(this, album.artistId, artistPairs)
@ -159,11 +152,6 @@ class AlbumDetailsActivity : AbsSlidingMusicPanelActivity(), AlbumDetailsView, C
} }
} }
override fun onDestroy() {
super.onDestroy()
albumDetailsPresenter.detachView()
}
override fun complete() { override fun complete() {
ActivityCompat.startPostponedEnterTransition(this) ActivityCompat.startPostponedEnterTransition(this)
} }
@ -201,8 +189,8 @@ class AlbumDetailsActivity : AbsSlidingMusicPanelActivity(), AlbumDetailsView, C
} }
loadAlbumCover() loadAlbumCover()
simpleSongAdapter.swapDataSet(album.songs) simpleSongAdapter.swapDataSet(album.songs)
albumDetailsPresenter.loadMore(album.artistId) viewModel.loadArtistAsync(album.artistId)
albumDetailsPresenter.aboutAlbum(album.artistName ?: "-", album.title ?: "-") viewModel.loadAlbumInfoAsync(album)
} }
override fun moreAlbums(albums: List<Album>) { override fun moreAlbums(albums: List<Album>) {
@ -277,7 +265,6 @@ class AlbumDetailsActivity : AbsSlidingMusicPanelActivity(), AlbumDetailsView, C
MaterialUtil.setTint(button = shuffleAction, color = buttonColor) MaterialUtil.setTint(button = shuffleAction, color = buttonColor)
MaterialUtil.setTint(button = playAction, color = buttonColor) MaterialUtil.setTint(button = playAction, color = buttonColor)
toolbar.setBackgroundColor(surfaceColor()) toolbar.setBackgroundColor(surfaceColor())
setSupportActionBar(toolbar) setSupportActionBar(toolbar)
supportActionBar?.title = null supportActionBar?.title = null
@ -332,7 +319,10 @@ class AlbumDetailsActivity : AbsSlidingMusicPanelActivity(), AlbumDetailsView, C
albumCoverContainer, albumCoverContainer,
"${getString(R.string.transition_album_art)}_${album.id}" "${getString(R.string.transition_album_art)}_${album.id}"
) )
startActivityForResult(intent, TAG_EDITOR_REQUEST, options.toBundle()) startActivityForResult(
intent,
TAG_EDITOR_REQUEST, options.toBundle()
)
return true return true
} }
/*Sort*/ /*Sort*/
@ -389,18 +379,6 @@ class AlbumDetailsActivity : AbsSlidingMusicPanelActivity(), AlbumDetailsView, C
album.songs?.let { simpleSongAdapter.swapDataSet(it) } album.songs?.let { simpleSongAdapter.swapDataSet(it) }
} }
override fun onMediaStoreChanged() {
super.onMediaStoreChanged()
reload()
}
private fun reload() {
if (intent.extras!!.containsKey(EXTRA_ALBUM_ID)) {
intent.extras?.getInt(EXTRA_ALBUM_ID)?.let { albumDetailsPresenter.loadAlbum(it) }
} else {
finish()
}
}
override fun onBackPressed() { override fun onBackPressed() {
if (cab != null && cab!!.isActive) { if (cab != null && cab!!.isActive) {

View file

@ -0,0 +1,54 @@
package code.name.monkey.retromusic.activities.albums
import android.app.Application
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import code.name.monkey.retromusic.model.Album
import code.name.monkey.retromusic.model.Artist
import code.name.monkey.retromusic.providers.RepositoryImpl
import code.name.monkey.retromusic.rest.model.LastFmAlbum
import kotlinx.coroutines.Deferred
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async
import kotlinx.coroutines.launch
class AlbumDetailsViewModel(
application: Application,
private val albumId: Int
) : AndroidViewModel(application) {
private val _repository = RepositoryImpl(application.applicationContext)
private val _album = MutableLiveData<Album>()
private val _artist = MutableLiveData<Artist>()
private val _lastFmAlbum = MutableLiveData<LastFmAlbum>()
fun getAlbum(): LiveData<Album> = _album
fun getArtist(): LiveData<Artist> = _artist
fun getAlbumInfo(): LiveData<LastFmAlbum> = _lastFmAlbum
init {
loadDetails()
}
private fun loadDetails() = viewModelScope.launch {
_album.postValue(
loadAlbumAsync.await() ?: throw NullPointerException("Album couldn't found")
)
}
fun loadAlbumInfoAsync(album: Album) = viewModelScope.launch(Dispatchers.IO) {
val lastFmAlbum = _repository.albumInfo(album.artistName ?: "-", album.title ?: "-")
_lastFmAlbum.postValue(lastFmAlbum)
}
fun loadArtistAsync(artistId: Int) = viewModelScope.launch(Dispatchers.IO) {
val artist = _repository.artistById(artistId)
_artist.postValue(artist)
}
private val loadAlbumAsync: Deferred<Album?>
get() = viewModelScope.async(Dispatchers.IO) {
_repository.albumById(albumId)
}
}

View file

@ -0,0 +1,19 @@
package code.name.monkey.retromusic.activities.albums
import android.app.Application
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
class AlbumDetailsViewModelFactory(
private val application: Application,
private val albumId: Int
) :
ViewModelProvider.AndroidViewModelFactory(application) {
override fun <T : ViewModel?> create(modelClass: Class<T>): T {
return if (modelClass.isAssignableFrom(AlbumDetailsViewModel::class.java)) {
AlbumDetailsViewModel(application, albumId) as T
} else {
throw IllegalArgumentException("ViewModel Not Found")
}
}
}

View file

@ -14,6 +14,7 @@ import code.name.monkey.appthemehelper.ThemeStore
import code.name.monkey.appthemehelper.common.ATHToolbarActivity import code.name.monkey.appthemehelper.common.ATHToolbarActivity
import code.name.monkey.appthemehelper.util.ATHUtil import code.name.monkey.appthemehelper.util.ATHUtil
import code.name.monkey.appthemehelper.util.ColorUtil import code.name.monkey.appthemehelper.util.ColorUtil
import code.name.monkey.appthemehelper.util.MaterialDialogsUtil
import code.name.monkey.appthemehelper.util.VersionUtils import code.name.monkey.appthemehelper.util.VersionUtils
import code.name.monkey.retromusic.LanguageContextWrapper import code.name.monkey.retromusic.LanguageContextWrapper
import code.name.monkey.retromusic.R import code.name.monkey.retromusic.R
@ -33,6 +34,7 @@ abstract class AbsThemeActivity : ATHToolbarActivity(), Runnable {
setImmersiveFullscreen() setImmersiveFullscreen()
registerSystemUiVisibility() registerSystemUiVisibility()
toggleScreenOn() toggleScreenOn()
MaterialDialogsUtil.updateMaterialDialogsThemeSingleton(this)
} }

View file

@ -28,8 +28,7 @@ import code.name.monkey.retromusic.activities.bugreport.model.github.ExtraInfo
import code.name.monkey.retromusic.activities.bugreport.model.github.GithubLogin import code.name.monkey.retromusic.activities.bugreport.model.github.GithubLogin
import code.name.monkey.retromusic.activities.bugreport.model.github.GithubTarget import code.name.monkey.retromusic.activities.bugreport.model.github.GithubTarget
import code.name.monkey.retromusic.misc.DialogAsyncTask import code.name.monkey.retromusic.misc.DialogAsyncTask
import com.afollestad.materialdialogs.MaterialDialog import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.afollestad.materialdialogs.callbacks.onCancel
import com.google.android.material.floatingactionbutton.FloatingActionButton import com.google.android.material.floatingactionbutton.FloatingActionButton
import com.google.android.material.textfield.TextInputLayout import com.google.android.material.textfield.TextInputLayout
import kotlinx.android.synthetic.main.activity_bug_report.* import kotlinx.android.synthetic.main.activity_bug_report.*
@ -278,27 +277,25 @@ open class BugReportActivity : AbsThemeActivity() {
when (result) { when (result) {
RESULT_SUCCESS -> tryToFinishActivity() RESULT_SUCCESS -> tryToFinishActivity()
RESULT_BAD_CREDENTIALS -> MaterialDialog(context).show { RESULT_BAD_CREDENTIALS -> MaterialAlertDialogBuilder(context)
title(R.string.bug_report_failed) .setTitle(R.string.bug_report_failed)
message(R.string.bug_report_failed_wrong_credentials) .setMessage(R.string.bug_report_failed_wrong_credentials)
positiveButton(android.R.string.ok) .setPositiveButton(android.R.string.ok, null)
} .show()
RESULT_INVALID_TOKEN -> MaterialDialog(context).show { RESULT_INVALID_TOKEN -> MaterialAlertDialogBuilder(context)
title(R.string.bug_report_failed) .setTitle(R.string.bug_report_failed)
message(R.string.bug_report_failed_invalid_token) .setMessage(R.string.bug_report_failed_invalid_token)
positiveButton(android.R.string.ok) .setPositiveButton(android.R.string.ok, null).show()
} RESULT_ISSUES_NOT_ENABLED -> MaterialAlertDialogBuilder(context)
RESULT_ISSUES_NOT_ENABLED -> MaterialDialog(context).show { .setTitle(R.string.bug_report_failed)
title(R.string.bug_report_failed) .setMessage(R.string.bug_report_failed_issues_not_available)
message(R.string.bug_report_failed_issues_not_available) .setPositiveButton(android.R.string.ok, null)
positiveButton(android.R.string.ok)
} else -> MaterialAlertDialogBuilder(context)
else -> MaterialDialog(context).show { .setTitle(R.string.bug_report_failed)
title(R.string.bug_report_failed) .setMessage(R.string.bug_report_failed_unknown)
message(R.string.bug_report_failed_unknown) .setPositiveButton(android.R.string.ok) { _, _ -> tryToFinishActivity() }
positiveButton(android.R.string.ok) { tryToFinishActivity() } .setNegativeButton(android.R.string.cancel) { _, _ -> { tryToFinishActivity() } }
onCancel { tryToFinishActivity() }
}
} }
} }
@ -309,6 +306,7 @@ open class BugReportActivity : AbsThemeActivity() {
} }
} }
companion object { companion object {
fun report( fun report(

View file

@ -13,6 +13,7 @@ import android.util.Log
import android.view.MenuItem import android.view.MenuItem
import android.view.View import android.view.View
import android.view.animation.OvershootInterpolator import android.view.animation.OvershootInterpolator
import androidx.appcompat.app.AlertDialog
import code.name.monkey.appthemehelper.ThemeStore import code.name.monkey.appthemehelper.ThemeStore
import code.name.monkey.appthemehelper.util.ATHUtil import code.name.monkey.appthemehelper.util.ATHUtil
import code.name.monkey.appthemehelper.util.ColorUtil import code.name.monkey.appthemehelper.util.ColorUtil
@ -24,9 +25,8 @@ import code.name.monkey.retromusic.activities.base.AbsBaseActivity
import code.name.monkey.retromusic.activities.saf.SAFGuideActivity import code.name.monkey.retromusic.activities.saf.SAFGuideActivity
import code.name.monkey.retromusic.util.RetroUtil import code.name.monkey.retromusic.util.RetroUtil
import code.name.monkey.retromusic.util.SAFUtil import code.name.monkey.retromusic.util.SAFUtil
import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.list.listItems
import com.google.android.material.button.MaterialButton import com.google.android.material.button.MaterialButton
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import kotlinx.android.synthetic.main.activity_album_tag_editor.* import kotlinx.android.synthetic.main.activity_album_tag_editor.*
import org.jaudiotagger.audio.AudioFile import org.jaudiotagger.audio.AudioFile
import org.jaudiotagger.audio.AudioFileIO import org.jaudiotagger.audio.AudioFileIO
@ -48,17 +48,18 @@ abstract class AbsTagEditorActivity : AbsBaseActivity() {
private var savedTags: Map<FieldKey, String>? = null private var savedTags: Map<FieldKey, String>? = null
private var savedArtworkInfo: ArtworkInfo? = null private var savedArtworkInfo: ArtworkInfo? = null
protected val show: MaterialDialog protected val show: AlertDialog
get() = MaterialDialog(this).show { get() =
title(R.string.update_image) MaterialAlertDialogBuilder(this)
listItems(items = items) { _, position, _ -> .setTitle(R.string.update_image)
when (position) { .setItems(items.toTypedArray()) { _, position ->
0 -> startImagePicker() when (position) {
1 -> searchImageOnWeb() 0 -> startImagePicker()
2 -> deleteImage() 1 -> searchImageOnWeb()
2 -> deleteImage()
}
} }
} .show()
}
protected abstract val contentViewLayout: Int protected abstract val contentViewLayout: Int
internal val albumArtist: String? internal val albumArtist: String?

View file

@ -91,7 +91,7 @@ class AlbumTagEditorActivity : AbsTagEditorActivity(), TextWatcher {
setDrawUnderStatusBar() setDrawUnderStatusBar()
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
window.sharedElementsUseOverlay = true window.sharedElementsUseOverlay = true
imageContainer?.transitionName = "${getString(R.string.transition_album_art)}_$id" imageContainer?.transitionName = getString(R.string.transition_album_art)
windowEnterTransition() windowEnterTransition()
setUpViews() setUpViews()
setupToolbar() setupToolbar()
@ -162,7 +162,7 @@ class AlbumTagEditorActivity : AbsTagEditorActivity(), TextWatcher {
writeValuesToFiles( writeValuesToFiles(
fieldKeyValueMap, fieldKeyValueMap,
if (deleteAlbumArt) ArtworkInfo(id, null) if (deleteAlbumArt) AbsTagEditorActivity.ArtworkInfo(id, null)
else if (albumArtBitmap == null) null else ArtworkInfo(id, albumArtBitmap!!) else if (albumArtBitmap == null) null else ArtworkInfo(id, albumArtBitmap!!)
) )
} }

View file

@ -180,7 +180,7 @@ open class AlbumAdapter(
val activityOptions = ActivityOptions.makeSceneTransitionAnimation( val activityOptions = ActivityOptions.makeSceneTransitionAnimation(
activity, activity,
imageContainerCard ?: image, imageContainerCard ?: image,
"${activity.getString(R.string.transition_album_art)}_${dataSet[layoutPosition].id}" activity.getString(R.string.transition_album_art)
) )
NavigationUtil.goToAlbumOptions( NavigationUtil.goToAlbumOptions(
activity, activity,

View file

@ -100,7 +100,7 @@ class AlbumFullWidthAdapter(
val activityOptions = ActivityOptions.makeSceneTransitionAnimation( val activityOptions = ActivityOptions.makeSceneTransitionAnimation(
activity, activity,
imageContainerCard ?: image, imageContainerCard ?: image,
"${activity.getString(R.string.transition_album_art)}_${dataSet[layoutPosition].id}" activity.getString(R.string.transition_album_art)
) )
NavigationUtil.goToAlbumOptions(activity, dataSet[layoutPosition].id, activityOptions) NavigationUtil.goToAlbumOptions(activity, dataSet[layoutPosition].id, activityOptions)
} }

View file

@ -142,7 +142,7 @@ class ArtistAdapter(
val activityOptions = ActivityOptions.makeSceneTransitionAnimation( val activityOptions = ActivityOptions.makeSceneTransitionAnimation(
activity, activity,
imageContainerCard ?: image, imageContainerCard ?: image,
"${activity.getString(R.string.transition_artist_image)}_${dataSet[layoutPosition].id}" activity.getString(R.string.transition_artist_image)
) )
NavigationUtil.goToArtistOptions( NavigationUtil.goToArtistOptions(
activity, dataSet[layoutPosition].id, activityOptions activity, dataSet[layoutPosition].id, activityOptions

View file

@ -60,7 +60,7 @@ open class PlaylistSongAdapter(
val activityOptions = ActivityOptions.makeSceneTransitionAnimation( val activityOptions = ActivityOptions.makeSceneTransitionAnimation(
activity, activity,
imageContainerCard ?: image, imageContainerCard ?: image,
"${activity.getString(R.string.transition_album_art)}_${song.albumId}" activity.getString(R.string.transition_album_art)
) )
NavigationUtil.goToAlbumOptions(activity, song.albumId, activityOptions) NavigationUtil.goToAlbumOptions(activity, song.albumId, activityOptions)
return true return true

View file

@ -186,7 +186,7 @@ open class SongAdapter(
val activityOptions = ActivityOptions.makeSceneTransitionAnimation( val activityOptions = ActivityOptions.makeSceneTransitionAnimation(
activity, activity,
imageContainerCard ?: image, imageContainerCard ?: image,
"${activity.getString(R.string.transition_album_art)}_${song.albumId}" activity.getString(R.string.transition_album_art)
) )
NavigationUtil.goToAlbumOptions(activity, song.albumId, activityOptions) NavigationUtil.goToAlbumOptions(activity, song.albumId, activityOptions)
return true return true

View file

@ -14,7 +14,10 @@
package code.name.monkey.retromusic.dagger package code.name.monkey.retromusic.dagger
import code.name.monkey.retromusic.activities.* import code.name.monkey.retromusic.activities.ArtistDetailActivity
import code.name.monkey.retromusic.activities.GenreDetailsActivity
import code.name.monkey.retromusic.activities.PlaylistDetailActivity
import code.name.monkey.retromusic.activities.SearchActivity
import code.name.monkey.retromusic.dagger.module.AppModule import code.name.monkey.retromusic.dagger.module.AppModule
import code.name.monkey.retromusic.dagger.module.PresenterModule import code.name.monkey.retromusic.dagger.module.PresenterModule
import code.name.monkey.retromusic.fragments.albums.AlbumsFragment import code.name.monkey.retromusic.fragments.albums.AlbumsFragment
@ -50,8 +53,6 @@ interface MusicComponent {
fun inject(artistDetailActivity: ArtistDetailActivity) fun inject(artistDetailActivity: ArtistDetailActivity)
fun inject(albumDetailsActivity: AlbumDetailsActivity)
fun inject(playlistDetailActivity: PlaylistDetailActivity) fun inject(playlistDetailActivity: PlaylistDetailActivity)
fun inject(genreDetailsActivity: GenreDetailsActivity) fun inject(genreDetailsActivity: GenreDetailsActivity)

View file

@ -0,0 +1,157 @@
package code.name.monkey.retromusic.dialogs;
import android.Manifest;
import android.app.Dialog;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.core.app.ActivityCompat;
import androidx.fragment.app.DialogFragment;
import com.afollestad.materialdialogs.MaterialDialog;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import code.name.monkey.retromusic.R;
public class BlacklistFolderChooserDialog extends DialogFragment implements MaterialDialog.ListCallback {
String initialPath = Environment.getExternalStorageDirectory().getAbsolutePath();
private File parentFolder;
private File[] parentContents;
private boolean canGoUp = false;
private FolderCallback callback;
public static BlacklistFolderChooserDialog create() {
return new BlacklistFolderChooserDialog();
}
private String[] getContentsArray() {
if (parentContents == null) {
if (canGoUp) {
return new String[]{".."};
}
return new String[]{};
}
String[] results = new String[parentContents.length + (canGoUp ? 1 : 0)];
if (canGoUp) {
results[0] = "..";
}
for (int i = 0; i < parentContents.length; i++) {
results[canGoUp ? i + 1 : i] = parentContents[i].getName();
}
return results;
}
private File[] listFiles() {
File[] contents = parentFolder.listFiles();
List<File> results = new ArrayList<>();
if (contents != null) {
for (File fi : contents) {
if (fi.isDirectory()) {
results.add(fi);
}
}
Collections.sort(results, new FolderSorter());
return results.toArray(new File[results.size()]);
}
return null;
}
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
&& ActivityCompat.checkSelfPermission(
getActivity(), Manifest.permission.READ_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) {
return new MaterialDialog.Builder(getActivity())
.title(R.string.md_error_label)
.content(R.string.md_storage_perm_error)
.positiveText(android.R.string.ok)
.build();
}
if (savedInstanceState == null) {
savedInstanceState = new Bundle();
}
if (!savedInstanceState.containsKey("current_path")) {
savedInstanceState.putString("current_path", initialPath);
}
parentFolder = new File(savedInstanceState.getString("current_path", File.pathSeparator));
checkIfCanGoUp();
parentContents = listFiles();
MaterialDialog.Builder builder =
new MaterialDialog.Builder(getActivity())
.title(parentFolder.getAbsolutePath())
.items((CharSequence[]) getContentsArray())
.itemsCallback(this)
.autoDismiss(false)
.onPositive((dialog, which) -> {
dismiss();
callback.onFolderSelection(BlacklistFolderChooserDialog.this, parentFolder);
})
.onNegative((materialDialog, dialogAction) -> dismiss())
.positiveText(R.string.add_action)
.negativeText(android.R.string.cancel);
return builder.build();
}
@Override
public void onSelection(MaterialDialog materialDialog, View view, int i, CharSequence s) {
if (canGoUp && i == 0) {
parentFolder = parentFolder.getParentFile();
if (parentFolder.getAbsolutePath().equals("/storage/emulated")) {
parentFolder = parentFolder.getParentFile();
}
checkIfCanGoUp();
} else {
parentFolder = parentContents[canGoUp ? i - 1 : i];
canGoUp = true;
if (parentFolder.getAbsolutePath().equals("/storage/emulated")) {
parentFolder = Environment.getExternalStorageDirectory();
}
}
reload();
}
private void checkIfCanGoUp() {
canGoUp = parentFolder.getParent() != null;
}
private void reload() {
parentContents = listFiles();
MaterialDialog dialog = (MaterialDialog) getDialog();
dialog.setTitle(parentFolder.getAbsolutePath());
dialog.setItems((CharSequence[]) getContentsArray());
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putString("current_path", parentFolder.getAbsolutePath());
}
public void setCallback(FolderCallback callback) {
this.callback = callback;
}
public interface FolderCallback {
void onFolderSelection(@NonNull BlacklistFolderChooserDialog dialog, @NonNull File folder);
}
private static class FolderSorter implements Comparator<File> {
@Override
public int compare(File lhs, File rhs) {
return lhs.getName().compareTo(rhs.getName());
}
}
}

View file

@ -1,180 +0,0 @@
/*
* Copyright (c) 2019 Hemanth Savarala.
*
* Licensed under the GNU General Public License v3
*
* This is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by
* the Free Software Foundation either version 3 of the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*/
package code.name.monkey.retromusic.dialogs
import android.Manifest
import android.app.Dialog
import android.content.pm.PackageManager
import android.os.Build
import android.os.Bundle
import android.os.Environment
import androidx.core.app.ActivityCompat
import androidx.fragment.app.DialogFragment
import code.name.monkey.retromusic.R
import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.list.listItems
import java.io.File
import java.util.*
import kotlin.collections.ArrayList
class BlacklistFolderChooserDialog : DialogFragment() {
private val initialPath = Environment.getExternalStorageDirectory().absolutePath
private var parentFolder: File? = null
private var parentContents: Array<File>? = null
private var canGoUp = false
private var callback: FolderCallback? = null
private fun contentsArray(): List<String> {
if (parentContents == null) {
return if (canGoUp) {
return listOf("..")
} else listOf()
}
val results = arrayOfNulls<String>(parentContents!!.size + if (canGoUp) 1 else 0)
if (canGoUp) {
results[0] = ".."
}
for (i in parentContents!!.indices) {
results[if (canGoUp) i + 1 else i] = parentContents!![i].name
}
val data = ArrayList<String>()
for (i in results) {
data.add(i!!)
}
return data
}
private fun listFiles(): Array<File>? {
val contents = parentFolder!!.listFiles()
val results = ArrayList<File>()
if (contents != null) {
for (fi in contents) {
if (fi.isDirectory) {
results.add(fi)
}
}
Collections.sort(results, FolderSorter())
return results.toTypedArray()
}
return null
}
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
var savedInstanceStateFinal = savedInstanceState
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M &&
ActivityCompat.checkSelfPermission(
requireActivity(),
Manifest.permission.READ_EXTERNAL_STORAGE
) != PackageManager.PERMISSION_GRANTED
) {
return MaterialDialog(requireActivity()).show {
title(R.string.md_error_label)
message(R.string.md_storage_perm_error)
positiveButton(android.R.string.ok)
}
}
if (savedInstanceStateFinal == null) {
savedInstanceStateFinal = Bundle()
}
if (!savedInstanceStateFinal.containsKey("current_path")) {
savedInstanceStateFinal.putString("current_path", initialPath)
}
parentFolder = File(savedInstanceStateFinal.getString("current_path", File.pathSeparator))
checkIfCanGoUp()
parentContents = listFiles()
return MaterialDialog(requireContext()).show {
title(text = parentFolder!!.absolutePath)
listItems(items = contentsArray(), waitForPositiveButton = false) { _, index, _ ->
onSelection(index)
}
noAutoDismiss()
positiveButton(R.string.add_action) {
dismiss()
callback!!.onFolderSelection(this@BlacklistFolderChooserDialog, parentFolder!!)
}
negativeButton(android.R.string.cancel) {
dismiss()
}
}
}
private fun onSelection(i: Int) {
if (canGoUp && i == 0) {
parentFolder = parentFolder!!.parentFile
if (parentFolder!!.absolutePath == "/storage/emulated") {
parentFolder = parentFolder!!.parentFile
}
checkIfCanGoUp()
} else {
parentFolder = parentContents!![if (canGoUp) i - 1 else i]
canGoUp = true
if (parentFolder!!.absolutePath == "/storage/emulated") {
parentFolder = Environment.getExternalStorageDirectory()
}
}
reload()
}
private fun checkIfCanGoUp() {
canGoUp = parentFolder!!.parent != null
}
private fun reload() {
parentContents = listFiles()
val dialog = dialog as MaterialDialog?
dialog?.apply {
setTitle(parentFolder!!.absolutePath)
listItems(items = contentsArray()) { _, index, _ ->
onSelection(index)
}
}
}
override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
outState.putString("current_path", parentFolder!!.absolutePath)
}
fun setCallback(callback: FolderCallback) {
this.callback = callback
}
interface FolderCallback {
fun onFolderSelection(dialog: BlacklistFolderChooserDialog, folder: File)
}
private class FolderSorter : Comparator<File> {
override fun compare(lhs: File, rhs: File): Int {
return lhs.name.compareTo(rhs.name)
}
}
companion object {
fun create(): BlacklistFolderChooserDialog {
return BlacklistFolderChooserDialog()
}
}
}

View file

@ -36,9 +36,8 @@ import code.name.monkey.retromusic.service.MusicService
import code.name.monkey.retromusic.service.MusicService.ACTION_PENDING_QUIT import code.name.monkey.retromusic.service.MusicService.ACTION_PENDING_QUIT
import code.name.monkey.retromusic.service.MusicService.ACTION_QUIT import code.name.monkey.retromusic.service.MusicService.ACTION_QUIT
import code.name.monkey.retromusic.util.PreferenceUtilKT import code.name.monkey.retromusic.util.PreferenceUtilKT
import com.afollestad.materialdialogs.DialogAction
import com.afollestad.materialdialogs.MaterialDialog import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.WhichButton
import com.afollestad.materialdialogs.actions.getActionButton
import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.dialog.MaterialAlertDialogBuilder
class SleepTimerDialog : DialogFragment() { class SleepTimerDialog : DialogFragment() {
@ -153,10 +152,10 @@ class SleepTimerDialog : DialogFragment() {
private fun updateCancelButton() { private fun updateCancelButton() {
val musicService = MusicPlayerRemote.musicService val musicService = MusicPlayerRemote.musicService
if (musicService != null && musicService.pendingQuit) { if (musicService != null && musicService.pendingQuit) {
materialDialog.getActionButton(WhichButton.NEGATIVE).text = materialDialog.getActionButton(DialogAction.NEUTRAL).text =
materialDialog.context.getString(R.string.cancel_current_timer) materialDialog.context.getString(R.string.cancel_current_timer)
} else { } else {
materialDialog.getActionButton(WhichButton.NEGATIVE).text = null materialDialog.getActionButton(DialogAction.NEUTRAL).text = null
} }
} }

View file

@ -5,8 +5,6 @@ import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.LiveData import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
import code.name.monkey.retromusic.Result.Error
import code.name.monkey.retromusic.Result.Success
import code.name.monkey.retromusic.fragments.ReloadType.* import code.name.monkey.retromusic.fragments.ReloadType.*
import code.name.monkey.retromusic.interfaces.MusicServiceEventListener import code.name.monkey.retromusic.interfaces.MusicServiceEventListener
import code.name.monkey.retromusic.model.* import code.name.monkey.retromusic.model.*
@ -60,8 +58,8 @@ class LibraryViewModel(application: Application) :
_repository.favoritePlaylist() _repository.favoritePlaylist()
) )
for (r in result) { for (r in result) {
if (r is Success) { if (r != null) {
list.add(r.data) list.add(r)
} }
} }
_homeSections.value = list _homeSections.value = list
@ -69,41 +67,27 @@ class LibraryViewModel(application: Application) :
private val loadSongs: Deferred<List<Song>> private val loadSongs: Deferred<List<Song>>
get() = viewModelScope.async(IO) { get() = viewModelScope.async(IO) {
when (val result = _repository.allSongs()) { _repository.allSongs()
is Success -> result.data
is Error -> arrayListOf()
}
} }
private val loadAlbums: Deferred<List<Album>> private val loadAlbums: Deferred<List<Album>>
get() = viewModelScope.async(IO) { get() = viewModelScope.async(IO) {
when (val result = _repository.allAlbums()) { _repository.allAlbums()
is Success -> result.data
is Error -> arrayListOf()
}
} }
private val loadArtists: Deferred<List<Artist>> private val loadArtists: Deferred<List<Artist>>
get() = viewModelScope.async(IO) { get() = viewModelScope.async(IO) {
when (val result = _repository.allArtists()) { _repository.allArtists()
is Success -> result.data
is Error -> arrayListOf()
}
} }
private val loadPlaylists: Deferred<List<Playlist>> private val loadPlaylists: Deferred<List<Playlist>>
get() = viewModelScope.async(IO) { get() = viewModelScope.async(IO) {
when (val result = _repository.allPlaylists()) { _repository.allPlaylists()
is Success -> result.data
is Error -> arrayListOf()
}
} }
private val loadGenres: Deferred<List<Genre>> private val loadGenres: Deferred<List<Genre>>
get() = viewModelScope.async(IO) { get() = viewModelScope.async(IO) {
when (val result = _repository.allGenres()) { _repository.allGenres()
is Success -> result.data
is Error -> arrayListOf()
}
} }
fun forceReload(reloadType: ReloadType) = viewModelScope.launch { fun forceReload(reloadType: ReloadType) = viewModelScope.launch {

View file

@ -307,10 +307,10 @@ public class FoldersFragment extends AbsMainActivityFragment implements
String.format(getString(R.string.not_listed_in_media_store), file1.getName())), String.format(getString(R.string.not_listed_in_media_store), file1.getName())),
Snackbar.LENGTH_LONG) Snackbar.LENGTH_LONG)
.setAction(R.string.action_scan, .setAction(R.string.action_scan,
v -> new ListPathsAsyncTask(getActivity(), this::scanPaths) v -> new ListPathsAsyncTask(requireActivity(), this::scanPaths)
.execute( .execute(
new ListPathsAsyncTask.LoadingInfo(finalFile, AUDIO_FILE_FILTER))) new ListPathsAsyncTask.LoadingInfo(finalFile, AUDIO_FILE_FILTER)))
.setActionTextColor(ThemeStore.Companion.accentColor(getActivity())) .setActionTextColor(ThemeStore.Companion.accentColor(requireActivity()))
.show(); .show();
} }
}).execute(new ListSongsAsyncTask.LoadingInfo(toList(file.getParentFile()), fileFilter, }).execute(new ListSongsAsyncTask.LoadingInfo(toList(file.getParentFile()), fileFilter,

View file

@ -21,8 +21,8 @@ import android.view.View
import android.widget.Toast import android.widget.Toast
import androidx.preference.ListPreference import androidx.preference.ListPreference
import androidx.preference.Preference import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import androidx.preference.PreferenceManager import androidx.preference.PreferenceManager
import code.name.monkey.appthemehelper.common.prefs.supportv7.ATEPreferenceFragmentCompat
import code.name.monkey.appthemehelper.util.ATHUtil import code.name.monkey.appthemehelper.util.ATHUtil
import code.name.monkey.retromusic.R import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.preferences.* import code.name.monkey.retromusic.preferences.*
@ -32,7 +32,7 @@ import code.name.monkey.retromusic.util.NavigationUtil
* @author Hemanth S (h4h13). * @author Hemanth S (h4h13).
*/ */
abstract class AbsSettingsFragment : PreferenceFragmentCompat() { abstract class AbsSettingsFragment : ATEPreferenceFragmentCompat() {
internal fun showProToastAndNavigate(message: String) { internal fun showProToastAndNavigate(message: String) {
Toast.makeText(requireContext(), "$message is Pro version feature.", Toast.LENGTH_SHORT) Toast.makeText(requireContext(), "$message is Pro version feature.", Toast.LENGTH_SHORT)

View file

@ -31,7 +31,6 @@ class ImageSettingFragment : AbsSettingsFragment() {
setSummary(autoDownloadImagesPolicy, o) setSummary(autoDownloadImagesPolicy, o)
true true
} }
} }
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {

View file

@ -48,20 +48,23 @@ class NowPlayingSettingsFragment : AbsSettingsFragment(),
} }
private fun updateAlbumCoverStyleSummary() { private fun updateAlbumCoverStyleSummary() {
val preference: Preference = findPreference(ALBUM_COVER_STYLE)!! val preference: Preference? = findPreference(ALBUM_COVER_STYLE)
preference.setSummary(PreferenceUtilKT.albumCoverStyle.titleRes) preference?.setSummary(PreferenceUtilKT.albumCoverStyle.titleRes)
} }
private fun updateNowPlayingScreenSummary() { private fun updateNowPlayingScreenSummary() {
val preference: Preference = findPreference(NOW_PLAYING_SCREEN_ID)!! val preference: Preference? = findPreference(NOW_PLAYING_SCREEN_ID)
preference.setSummary(PreferenceUtilKT.nowPlayingScreen.titleRes) preference?.setSummary(PreferenceUtilKT.nowPlayingScreen.titleRes)
} }
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
PreferenceUtilKT.registerOnSharedPreferenceChangedListener(this) PreferenceUtilKT.registerOnSharedPreferenceChangedListener(this)
val preference: Preference = findPreference("album_cover_transform")!! val preference: Preference? = findPreference("album_cover_transform")
setSummary(preference) preference?.setOnPreferenceChangeListener { albumPrefs, newValue ->
setSummary(albumPrefs, newValue)
true
}
} }
override fun onDestroyView() { override fun onDestroyView() {

View file

@ -17,9 +17,8 @@ package code.name.monkey.retromusic.fragments.settings
import android.os.Bundle import android.os.Bundle
import android.view.View import android.view.View
import androidx.preference.Preference import androidx.preference.Preference
import code.name.monkey.appthemehelper.common.prefs.supportv7.ATEListPreference
import code.name.monkey.retromusic.R import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.preferences.MaterialListPreference
/** /**
* @author Hemanth S (h4h13). * @author Hemanth S (h4h13).
@ -27,8 +26,8 @@ import code.name.monkey.retromusic.preferences.MaterialListPreference
class OtherSettingsFragment : AbsSettingsFragment() { class OtherSettingsFragment : AbsSettingsFragment() {
override fun invalidateSettings() { override fun invalidateSettings() {
val languagePreference: MaterialListPreference = findPreference("language_name")!! val languagePreference: ATEListPreference? = findPreference("language_name")
languagePreference.setOnPreferenceChangeListener { _, _ -> languagePreference?.setOnPreferenceChangeListener { _, _ ->
requireActivity().recreate() requireActivity().recreate()
return@setOnPreferenceChangeListener true return@setOnPreferenceChangeListener true
} }
@ -40,9 +39,15 @@ class OtherSettingsFragment : AbsSettingsFragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
val preference: Preference = findPreference("last_added_interval")!! val preference: Preference? = findPreference("last_added_interval")
setSummary(preference) preference?.setOnPreferenceChangeListener { lastAdded, newValue ->
val languagePreference: Preference = findPreference("language_name")!! setSummary(lastAdded, newValue)
setSummary(languagePreference) true
}
val languagePreference: Preference? = findPreference("language_name")
languagePreference?.setOnPreferenceChangeListener { prefs, newValue ->
setSummary(prefs, newValue)
true
}
} }
} }

View file

@ -14,21 +14,15 @@
package code.name.monkey.retromusic.fragments.settings package code.name.monkey.retromusic.fragments.settings
import android.content.SharedPreferences
import android.os.Bundle import android.os.Bundle
import android.view.View import android.view.View
import androidx.preference.Preference
import androidx.preference.TwoStatePreference import androidx.preference.TwoStatePreference
import code.name.monkey.retromusic.CAROUSEL_EFFECT import code.name.monkey.appthemehelper.common.prefs.supportv7.ATEListPreference
import code.name.monkey.retromusic.R import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.util.PreferenceUtilKT class PersonalizeSettingsFragment : AbsSettingsFragment() {
class PersonalizeSettingsFragment : AbsSettingsFragment(),
SharedPreferences.OnSharedPreferenceChangeListener {
override fun invalidateSettings() { override fun invalidateSettings() {
val toggleFullScreen: TwoStatePreference = findPreference("toggle_full_screen")!! val toggleFullScreen: TwoStatePreference = findPreference("toggle_full_screen")!!
toggleFullScreen.setOnPreferenceChangeListener { _, _ -> toggleFullScreen.setOnPreferenceChangeListener { _, _ ->
requireActivity().recreate() requireActivity().recreate()
@ -42,22 +36,15 @@ class PersonalizeSettingsFragment : AbsSettingsFragment(),
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
PreferenceUtilKT.registerOnSharedPreferenceChangedListener(this) val homeArtistStyle: ATEListPreference? = findPreference("home_artist_grid_style")
homeArtistStyle?.setOnPreferenceChangeListener { preference, newValue ->
var preference: Preference? = findPreference("home_artist_grid_style") setSummary(preference, newValue)
setSummary(preference!!) true
preference = findPreference("tab_text_mode") }
setSummary(preference!!) val tabTextMode: ATEListPreference? = findPreference("tab_text_mode")
} tabTextMode?.setOnPreferenceChangeListener { prefs, newValue ->
setSummary(prefs, newValue)
override fun onDestroyView() { true
super.onDestroyView()
PreferenceUtilKT.unregisterOnSharedPreferenceChangedListener(this)
}
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences, key: String) {
when (key) {
CAROUSEL_EFFECT -> invalidateSettings()
} }
} }
} }

View file

@ -18,8 +18,6 @@ import android.os.Build
import android.os.Bundle import android.os.Bundle
import androidx.preference.Preference import androidx.preference.Preference
import androidx.preference.TwoStatePreference import androidx.preference.TwoStatePreference
import code.name.monkey.appthemehelper.ACCENT_COLORS
import code.name.monkey.appthemehelper.ACCENT_COLORS_SUB
import code.name.monkey.appthemehelper.ThemeStore import code.name.monkey.appthemehelper.ThemeStore
import code.name.monkey.appthemehelper.common.prefs.supportv7.ATEColorPreference import code.name.monkey.appthemehelper.common.prefs.supportv7.ATEColorPreference
import code.name.monkey.appthemehelper.common.prefs.supportv7.ATESwitchPreference import code.name.monkey.appthemehelper.common.prefs.supportv7.ATESwitchPreference
@ -30,9 +28,7 @@ import code.name.monkey.retromusic.DESATURATED_COLOR
import code.name.monkey.retromusic.R import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.appshortcuts.DynamicShortcutManager import code.name.monkey.retromusic.appshortcuts.DynamicShortcutManager
import code.name.monkey.retromusic.util.PreferenceUtilKT import code.name.monkey.retromusic.util.PreferenceUtilKT
import com.afollestad.materialdialogs.MaterialDialog import com.afollestad.materialdialogs.color.ColorChooserDialog
import com.afollestad.materialdialogs.color.colorChooser
/** /**
* @author Hemanth S (h4h13). * @author Hemanth S (h4h13).
@ -62,21 +58,12 @@ class ThemeSettingsFragment : AbsSettingsFragment() {
accentColorPref.setColor(accentColor, ColorUtil.darkenColor(accentColor)) accentColorPref.setColor(accentColor, ColorUtil.darkenColor(accentColor))
accentColorPref.setOnPreferenceClickListener { accentColorPref.setOnPreferenceClickListener {
MaterialDialog(requireActivity()).show { ColorChooserDialog.Builder(requireContext(), R.string.accent_color)
title(R.string.accent_color) .accentMode(true)
positiveButton(R.string.set) .allowUserColorInput(true)
colorChooser( .allowUserColorInputAlpha(false)
colors = ACCENT_COLORS, .preselect(accentColor)
allowCustomArgb = true, .show(requireActivity())
subColors = ACCENT_COLORS_SUB
) { _, color ->
ThemeStore.editTheme(requireContext()).accentColor(color).commit()
if (VersionUtils.hasNougatMR())
DynamicShortcutManager(requireContext()).updateDynamicShortcuts()
requireActivity().recreate()
}
}
return@setOnPreferenceClickListener true return@setOnPreferenceClickListener true
} }
val blackTheme: ATESwitchPreference? = findPreference("black_theme") val blackTheme: ATESwitchPreference? = findPreference("black_theme")

View file

@ -14,14 +14,16 @@
package code.name.monkey.retromusic.mvp.presenter package code.name.monkey.retromusic.mvp.presenter
import code.name.monkey.retromusic.Result.Success
import code.name.monkey.retromusic.model.Album import code.name.monkey.retromusic.model.Album
import code.name.monkey.retromusic.model.Artist import code.name.monkey.retromusic.model.Artist
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 code.name.monkey.retromusic.rest.model.LastFmAlbum import code.name.monkey.retromusic.rest.model.LastFmAlbum
import kotlinx.coroutines.* import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import javax.inject.Inject import javax.inject.Inject
import kotlin.coroutines.CoroutineContext import kotlin.coroutines.CoroutineContext
@ -57,19 +59,15 @@ interface AlbumDetailsPresenter : Presenter<AlbumDetailsView> {
override fun loadMore(artistId: Int) { override fun loadMore(artistId: Int) {
launch { launch {
when (val result = repository.artistById(artistId)) { val result = repository.artistById(artistId)
is Success -> withContext(Dispatchers.Main) { showArtistImage(result.data) } showArtistImage(result)
is Error -> withContext(Dispatchers.Main) {}
}
} }
} }
override fun aboutAlbum(artist: String, album: String) { override fun aboutAlbum(artist: String, album: String) {
launch { launch {
when (val result = repository.albumInfo(artist, album)) { val result = repository.albumInfo(artist, album)
is Success -> withContext(Dispatchers.Main) { view.aboutAlbum(result.data) } view.aboutAlbum(result)
is Error -> withContext(Dispatchers.Main) {}
}
} }
} }
@ -83,13 +81,10 @@ interface AlbumDetailsPresenter : Presenter<AlbumDetailsView> {
override fun loadAlbum(albumId: Int) { override fun loadAlbum(albumId: Int) {
launch { launch {
when (val result = repository.albumById(albumId)) { val result = repository.albumById(albumId)
is Success -> withContext(Dispatchers.Main) { album = result
album = result.data view?.album(result)
view?.album(result.data)
}
is Error -> withContext(Dispatchers.Main) { view?.complete() }
}
} }
} }

View file

@ -14,14 +14,15 @@
package code.name.monkey.retromusic.mvp.presenter package code.name.monkey.retromusic.mvp.presenter
import code.name.monkey.retromusic.Result.Error
import code.name.monkey.retromusic.Result.Success
import code.name.monkey.retromusic.model.Album import code.name.monkey.retromusic.model.Album
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 kotlinx.coroutines.* import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import javax.inject.Inject import javax.inject.Inject
import kotlin.coroutines.CoroutineContext import kotlin.coroutines.CoroutineContext
@ -53,10 +54,8 @@ interface AlbumsPresenter : Presenter<AlbumsView> {
override fun loadAlbums() { override fun loadAlbums() {
launch { launch {
when (val result = repository.allAlbums()) { val result = repository.allAlbums()
is Success -> withContext(Dispatchers.Main) { view?.albums(result.data) } view?.albums(result)
is Error -> withContext(Dispatchers.Main) { view?.showEmptyView() }
}
} }
} }
} }

View file

@ -14,15 +14,16 @@
package code.name.monkey.retromusic.mvp.presenter package code.name.monkey.retromusic.mvp.presenter
import code.name.monkey.retromusic.Result.Error
import code.name.monkey.retromusic.Result.Success
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 code.name.monkey.retromusic.rest.model.LastFmArtist import code.name.monkey.retromusic.rest.model.LastFmArtist
import kotlinx.coroutines.* import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import java.util.* import java.util.*
import javax.inject.Inject import javax.inject.Inject
import kotlin.coroutines.CoroutineContext import kotlin.coroutines.CoroutineContext
@ -60,19 +61,15 @@ interface ArtistDetailsPresenter : Presenter<ArtistDetailsView> {
override fun loadBiography(name: String, lang: String?, cache: String?) { override fun loadBiography(name: String, lang: String?, cache: String?) {
launch { launch {
when (val result = repository.artistInfo(name, lang, cache)) { val result = repository.artistInfo(name, lang, cache)
is Success -> withContext(Dispatchers.Main) { view?.artistInfo(result.data) } view?.artistInfo(result)
is Error -> withContext(Dispatchers.Main) {}
}
} }
} }
override fun loadArtist(artistId: Int) { override fun loadArtist(artistId: Int) {
launch { launch {
when (val result = repository.artistById(artistId)) { val result = repository.artistById(artistId)
is Success -> withContext(Dispatchers.Main) { view?.artist(result.data) } view?.artist(result)
is Error -> withContext(Dispatchers.Main) { view?.showEmptyView() }
}
} }
} }

View file

@ -14,14 +14,15 @@
package code.name.monkey.retromusic.mvp.presenter package code.name.monkey.retromusic.mvp.presenter
import code.name.monkey.retromusic.Result.Error
import code.name.monkey.retromusic.Result.Success
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 kotlinx.coroutines.* import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import javax.inject.Inject import javax.inject.Inject
import kotlin.coroutines.CoroutineContext import kotlin.coroutines.CoroutineContext
@ -49,10 +50,8 @@ interface ArtistsPresenter : Presenter<ArtistsView> {
override fun loadArtists() { override fun loadArtists() {
launch { launch {
when (val result = repository.allArtists()) { val result = repository.allArtists()
is Success -> withContext(Dispatchers.Main) { view?.artists(result.data) } view?.artists(result)
is Error -> withContext(Dispatchers.Main) { view?.showEmptyView() }
}
} }
} }
} }

View file

@ -14,14 +14,15 @@
package code.name.monkey.retromusic.mvp.presenter package code.name.monkey.retromusic.mvp.presenter
import code.name.monkey.retromusic.Result.Error
import code.name.monkey.retromusic.Result.Success
import code.name.monkey.retromusic.model.Song import code.name.monkey.retromusic.model.Song
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 kotlinx.coroutines.* import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import javax.inject.Inject import javax.inject.Inject
import kotlin.coroutines.CoroutineContext import kotlin.coroutines.CoroutineContext
@ -53,10 +54,8 @@ interface GenreDetailsPresenter : Presenter<GenreDetailsView> {
override fun loadGenreSongs(genreId: Int) { override fun loadGenreSongs(genreId: Int) {
launch { launch {
when (val result = repository.getGenre(genreId)) { val result = repository.getGenre(genreId)
is Success -> withContext(Dispatchers.Main) { view?.songs(result.data) } view?.songs(result)
is Error -> withContext(Dispatchers.Main) { view?.showEmptyView() }
}
} }
} }
} }

View file

@ -14,14 +14,15 @@
package code.name.monkey.retromusic.mvp.presenter package code.name.monkey.retromusic.mvp.presenter
import code.name.monkey.retromusic.Result.Error
import code.name.monkey.retromusic.Result.Success
import code.name.monkey.retromusic.model.Genre import code.name.monkey.retromusic.model.Genre
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 kotlinx.coroutines.* import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import javax.inject.Inject import javax.inject.Inject
import kotlin.coroutines.CoroutineContext import kotlin.coroutines.CoroutineContext
@ -52,10 +53,8 @@ interface GenresPresenter : Presenter<GenresView> {
override fun loadGenres() { override fun loadGenres() {
launch { launch {
when (val result = repository.allGenres()) { val result = repository.allGenres()
is Success -> withContext(Dispatchers.Main) { view?.genres(result.data) } view?.genres(result)
is Error -> withContext(Dispatchers.Main) { view?.showEmptyView() }
}
} }
} }
} }

View file

@ -14,7 +14,6 @@
package code.name.monkey.retromusic.mvp.presenter package code.name.monkey.retromusic.mvp.presenter
import code.name.monkey.retromusic.Result
import code.name.monkey.retromusic.model.Home import code.name.monkey.retromusic.model.Home
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
@ -56,9 +55,7 @@ interface HomePresenter : Presenter<HomeView> {
repository.favoritePlaylist() repository.favoritePlaylist()
) )
for (r in recentArtistResult) { for (r in recentArtistResult) {
when (r) { r?.let { list.add(it) }
is Result.Success -> list.add(r.data)
}
} }
withContext(Dispatchers.Main) { withContext(Dispatchers.Main) {
if (list.isNotEmpty()) view?.sections(list) else view?.showEmptyView() if (list.isNotEmpty()) view?.sections(list) else view?.showEmptyView()

View file

@ -14,13 +14,15 @@
package code.name.monkey.retromusic.mvp.presenter package code.name.monkey.retromusic.mvp.presenter
import code.name.monkey.retromusic.Result
import code.name.monkey.retromusic.model.Playlist import code.name.monkey.retromusic.model.Playlist
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 kotlinx.coroutines.* import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import javax.inject.Inject import javax.inject.Inject
import kotlin.coroutines.CoroutineContext import kotlin.coroutines.CoroutineContext
@ -53,10 +55,8 @@ interface PlaylistsPresenter : Presenter<PlaylistView> {
override fun playlists() { override fun playlists() {
launch { launch {
when (val result = repository.allPlaylists()) { val result = repository.allPlaylists()
is Result.Success -> withContext(Dispatchers.Main) { view?.playlists(result.data) } view?.playlists(result)
is Result.Error -> withContext(Dispatchers.Main) { view?.showEmptyView() }
}
} }
} }
} }

View file

@ -14,15 +14,16 @@
package code.name.monkey.retromusic.mvp.presenter package code.name.monkey.retromusic.mvp.presenter
import code.name.monkey.retromusic.Result.Error
import code.name.monkey.retromusic.Result.Success
import code.name.monkey.retromusic.model.Playlist import code.name.monkey.retromusic.model.Playlist
import code.name.monkey.retromusic.model.Song import code.name.monkey.retromusic.model.Song
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 kotlinx.coroutines.* import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import javax.inject.Inject import javax.inject.Inject
import kotlin.coroutines.CoroutineContext import kotlin.coroutines.CoroutineContext
@ -48,10 +49,8 @@ interface PlaylistSongsPresenter : Presenter<PlaylistSongsView> {
override fun loadPlaylistSongs(playlist: Playlist) { override fun loadPlaylistSongs(playlist: Playlist) {
launch { launch {
when (val songs = repository.getPlaylistSongs(playlist)) { val songs = repository.getPlaylistSongs(playlist)
is Success -> withContext(Dispatchers.Main) { view?.songs(songs.data) } view?.songs(songs)
is Error -> withContext(Dispatchers.Main) { view?.showEmptyView() }
}
} }
} }

View file

@ -14,13 +14,14 @@
package code.name.monkey.retromusic.mvp.presenter package code.name.monkey.retromusic.mvp.presenter
import code.name.monkey.retromusic.Result.Error
import code.name.monkey.retromusic.Result.Success
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 kotlinx.coroutines.* import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import javax.inject.Inject import javax.inject.Inject
import kotlin.coroutines.CoroutineContext import kotlin.coroutines.CoroutineContext
@ -53,10 +54,8 @@ interface SearchPresenter : Presenter<SearchView> {
override fun search(query: String?) { override fun search(query: String?) {
launch { launch {
when (val result = repository.search(query)) { val result = repository.search(query)
is Success -> withContext(Dispatchers.Main) { view?.showData(result.data) } view?.showData(result)
is Error -> withContext(Dispatchers.Main) { view?.showEmptyView() }
}
} }
} }
} }

View file

@ -14,12 +14,14 @@
package code.name.monkey.retromusic.mvp.presenter package code.name.monkey.retromusic.mvp.presenter
import code.name.monkey.retromusic.Result
import code.name.monkey.retromusic.model.Song import code.name.monkey.retromusic.model.Song
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 kotlinx.coroutines.* import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import javax.inject.Inject import javax.inject.Inject
import kotlin.coroutines.CoroutineContext import kotlin.coroutines.CoroutineContext
@ -48,10 +50,8 @@ interface SongPresenter : Presenter<SongView> {
override fun loadSongs() { override fun loadSongs() {
launch { launch {
when (val songs = repository.allSongs()) { val songs = repository.allSongs()
is Result.Success -> withContext(Dispatchers.Main) { view?.songs(songs.data) } view?.songs(songs)
is Result.Error -> withContext(Dispatchers.Main) { view?.showEmptyView() }
}
} }
} }

View file

@ -16,7 +16,6 @@ package code.name.monkey.retromusic.preferences
import android.app.Dialog import android.app.Dialog
import android.content.Context import android.content.Context
import android.content.DialogInterface
import android.os.Bundle import android.os.Bundle
import android.util.AttributeSet import android.util.AttributeSet
import androidx.core.graphics.BlendModeColorFilterCompat import androidx.core.graphics.BlendModeColorFilterCompat

View file

@ -23,13 +23,10 @@ import androidx.core.graphics.BlendModeColorFilterCompat
import androidx.core.graphics.BlendModeCompat.SRC_IN import androidx.core.graphics.BlendModeCompat.SRC_IN
import androidx.preference.ListPreference import androidx.preference.ListPreference
import androidx.preference.PreferenceDialogFragmentCompat import androidx.preference.PreferenceDialogFragmentCompat
import code.name.monkey.appthemehelper.ThemeStore
import code.name.monkey.retromusic.R import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.extensions.colorControlNormal import code.name.monkey.retromusic.extensions.colorControlNormal
import com.afollestad.materialdialogs.MaterialDialog import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.WhichButton import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.afollestad.materialdialogs.actions.getActionButton
import com.afollestad.materialdialogs.list.listItemsSingleChoice
class MaterialListPreference @JvmOverloads constructor( class MaterialListPreference @JvmOverloads constructor(
context: Context, context: Context,
@ -72,30 +69,31 @@ class MaterialListPreferenceDialog : PreferenceDialogFragmentCompat() {
val entries = arguments?.getStringArrayList(EXTRA_ENTRIES) val entries = arguments?.getStringArrayList(EXTRA_ENTRIES)
val entriesValues = arguments?.getStringArrayList(EXTRA_ENTRIES_VALUES) val entriesValues = arguments?.getStringArrayList(EXTRA_ENTRIES_VALUES)
val position: Int = arguments?.getInt(EXTRA_POSITION) ?: 0 val position: Int = arguments?.getInt(EXTRA_POSITION) ?: 0
materialDialog = MaterialDialog(requireContext()) /* materialDialog = MaterialDialog(requireContext())
.title(text = materialListPreference.title.toString()) .title(text = materialListPreference.title.toString())
.positiveButton(R.string.set) .positiveButton(R.string.set)
.listItemsSingleChoice( .listItemsSingleChoice(
items = entries, items = entries,
initialSelection = position, initialSelection = position,
waitForPositiveButton = true waitForPositiveButton = true
) { _, index, _ -> ) { _, index, _ ->
entriesValues?.let { entriesValues?.let {
materialListPreference.callChangeListener(it[index]) materialListPreference.callChangeListener(it[index])
materialListPreference.setCustomValue(it[index]) materialListPreference.setCustomValue(it[index])
} }
entries?.let { entries?.let {
materialListPreference.summary = it[index] materialListPreference.summary = it[index]
val value = materialListPreference.entryValues[index].toString() val value = materialListPreference.entryValues[index].toString()
if (materialListPreference.callChangeListener(value)) { if (materialListPreference.callChangeListener(value)) {
materialListPreference.value = value materialListPreference.value = value
} }
} }
dismiss() dismiss()
} }
materialDialog.getActionButton(WhichButton.POSITIVE) materialDialog.getActionButton(WhichButton.POSITIVE)
.updateTextColor(ThemeStore.accentColor(requireContext())) .updateTextColor(ThemeStore.accentColor(requireContext()))
return materialDialog return materialDialog*/
return MaterialAlertDialogBuilder(requireContext()).create()
} }
override fun onDestroyView() { override fun onDestroyView() {

View file

@ -16,9 +16,6 @@ package code.name.monkey.retromusic.providers
import android.content.Context import android.content.Context
import code.name.monkey.retromusic.R import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.Result
import code.name.monkey.retromusic.Result.Error
import code.name.monkey.retromusic.Result.Success
import code.name.monkey.retromusic.adapter.HomeAdapter import code.name.monkey.retromusic.adapter.HomeAdapter
import code.name.monkey.retromusic.loaders.* import code.name.monkey.retromusic.loaders.*
import code.name.monkey.retromusic.model.* import code.name.monkey.retromusic.model.*
@ -26,268 +23,114 @@ import code.name.monkey.retromusic.providers.interfaces.Repository
import code.name.monkey.retromusic.rest.LastFmClient import code.name.monkey.retromusic.rest.LastFmClient
import code.name.monkey.retromusic.rest.model.LastFmAlbum import code.name.monkey.retromusic.rest.model.LastFmAlbum
import code.name.monkey.retromusic.rest.model.LastFmArtist import code.name.monkey.retromusic.rest.model.LastFmArtist
import java.io.IOException
import javax.inject.Inject import javax.inject.Inject
class RepositoryImpl @Inject constructor(private val context: Context) : Repository { class RepositoryImpl @Inject constructor(private val context: Context) : Repository {
override suspend fun allAlbums(): Result<ArrayList<Album>> { override suspend fun allAlbums(): List<Album> = AlbumLoader.getAllAlbums(context)
return try {
val albums = AlbumLoader.getAllAlbums(context) override suspend fun allArtists(): List<Artist> = ArtistLoader.getAllArtists(context)
if (albums.isNotEmpty()) {
Success(albums) override suspend fun allPlaylists(): List<Playlist> = PlaylistLoader.getAllPlaylists(context)
} else {
Error(Throwable("No items found")) override suspend fun allGenres(): List<Genre> = GenreLoader.getAllGenres(context)
}
} catch (e: Exception) { override suspend fun allSongs(): List<Song> = SongLoader.getAllSongs(context)
Error(e)
override suspend fun albumById(albumId: Int): Album = AlbumLoader.getAlbum(context, albumId)
override suspend fun artistById(artistId: Int): Artist =
ArtistLoader.getArtist(context, artistId)
override suspend fun search(query: String?): MutableList<Any> =
SearchLoader.searchAll(context, query)
override suspend fun getPlaylistSongs(playlist: Playlist): ArrayList<Song> {
return if (playlist is AbsCustomPlaylist) {
playlist.getSongs(context)
} else {
PlaylistSongsLoader.getPlaylistSongList(context, playlist.id)
} }
} }
override suspend fun albumById(albumId: Int): Result<Album> { override suspend fun getGenre(genreId: Int): ArrayList<Song> =
return try { GenreLoader.getSongs(context, genreId)
val album = AlbumLoader.getAlbum(context, albumId)
if (album != null) { override suspend fun recentArtists(): Home? {
Success(album) val artists = LastAddedSongsLoader.getLastAddedArtists(context)
} else { return if (artists.isNotEmpty()) Home(
Error(Throwable("No album")) 0,
} R.string.recent_artists,
} catch (e: Exception) { artists,
Error(e) HomeAdapter.RECENT_ARTISTS,
} R.drawable.ic_artist_white_24dp
) else null
} }
override suspend fun allArtists(): Result<ArrayList<Artist>> { override suspend fun recentAlbums(): Home? {
return try { val albums = LastAddedSongsLoader.getLastAddedAlbums(context)
val artists = ArtistLoader.getAllArtists(context) return if (albums.isNotEmpty()) {
if (artists.isNotEmpty()) { Home(
Success(artists) 1,
} else { R.string.recent_albums,
Error(Throwable("No items found")) albums,
} HomeAdapter.RECENT_ALBUMS,
} catch (e: Exception) { R.drawable.ic_album_white_24dp
Error(e) )
} } else null
} }
override suspend fun allPlaylists(): Result<ArrayList<Playlist>> { override suspend fun topAlbums(): Home? {
return try { val albums = TopAndRecentlyPlayedTracksLoader.getTopAlbums(context)
val playlists = PlaylistLoader.getAllPlaylists(context) return if (albums.isNotEmpty()) {
if (playlists.isNotEmpty()) { Home(
Success(playlists) 3,
} else { R.string.top_albums,
Error(Throwable("No items found")) albums,
} HomeAdapter.TOP_ALBUMS,
} catch (e: Exception) { R.drawable.ic_album_white_24dp
Error(e) )
} } else null
} }
override suspend fun allGenres(): Result<ArrayList<Genre>> { override suspend fun topArtists(): Home? {
return try {
val genres = GenreLoader.getAllGenres(context) val artists = TopAndRecentlyPlayedTracksLoader.getTopArtists(context)
if (genres.isNotEmpty()) { return if (artists.isNotEmpty()) {
Success(genres) Home(
} else { 2,
Error(Throwable("No items found")) R.string.top_artists,
} artists,
} catch (e: Exception) { HomeAdapter.TOP_ARTISTS,
Error(e) R.drawable.ic_artist_white_24dp
} )
} else null
} }
override suspend fun search(query: String?): Result<MutableList<Any>> { override suspend fun favoritePlaylist(): Home? {
return try { val playlists = PlaylistLoader.getFavoritePlaylist(context)
val result = SearchLoader.searchAll(context, query) return if (playlists.isNotEmpty()) {
if (result.isNotEmpty()) { Home(
Success(result) 4,
} else { R.string.favorites,
Error(Throwable("No items found")) playlists,
} HomeAdapter.PLAYLISTS,
} catch (e: Exception) { R.drawable.ic_favorite_white_24dp
Error(e) )
} } else null
}
override suspend fun allSongs(): Result<ArrayList<Song>> {
return try {
val songs = SongLoader.getAllSongs(context)
if (songs.isEmpty()) {
Error(Throwable("No items found"))
} else {
Success(songs)
}
} catch (e: Exception) {
Error(e)
}
}
override suspend fun getPlaylistSongs(playlist: Playlist): Result<ArrayList<Song>> {
return try {
val songs: ArrayList<Song> = if (playlist is AbsCustomPlaylist) {
playlist.getSongs(context)
} else {
PlaylistSongsLoader.getPlaylistSongList(context, playlist.id)
}
Success(songs)
} catch (e: Exception) {
Error(e)
}
}
override suspend fun getGenre(genreId: Int): Result<ArrayList<Song>> {
return try {
val songs = GenreLoader.getSongs(context, genreId)
if (songs.isEmpty()) {
Error(Throwable("No items found"))
} else {
Success(songs)
}
} catch (e: Exception) {
Error(e)
}
}
override suspend fun recentArtists(): Result<Home> {
return try {
val artists = LastAddedSongsLoader.getLastAddedArtists(context)
if (artists.isEmpty()) {
Error(Throwable("No items found"))
} else {
Success(
Home(
0,
R.string.recent_artists,
artists,
HomeAdapter.RECENT_ARTISTS,
R.drawable.ic_artist_white_24dp
)
)
}
} catch (e: Exception) {
Error(e)
}
}
override suspend fun recentAlbums(): Result<Home> {
return try {
val albums = LastAddedSongsLoader.getLastAddedAlbums(context)
if (albums.isEmpty()) {
Error(Throwable("No items found"))
} else {
Success(
Home(
1,
R.string.recent_albums,
albums,
HomeAdapter.RECENT_ALBUMS,
R.drawable.ic_album_white_24dp
)
)
}
} catch (e: Exception) {
Error(e)
}
}
override suspend fun topAlbums(): Result<Home> {
return try {
val albums = TopAndRecentlyPlayedTracksLoader.getTopAlbums(context)
if (albums.isEmpty()) {
Error(Throwable("No items found"))
} else {
Success(
Home(
3,
R.string.top_albums,
albums,
HomeAdapter.TOP_ALBUMS,
R.drawable.ic_album_white_24dp
)
)
}
} catch (e: Exception) {
Error(e)
}
}
override suspend fun topArtists(): Result<Home> {
return try {
val artists = TopAndRecentlyPlayedTracksLoader.getTopArtists(context)
if (artists.isEmpty()) {
Error(Throwable("No items found"))
} else {
Success(
Home(
2,
R.string.top_artists,
artists,
HomeAdapter.TOP_ARTISTS,
R.drawable.ic_artist_white_24dp
)
)
}
} catch (e: Exception) {
Error(e)
}
}
override suspend fun favoritePlaylist(): Result<Home> {
return try {
val playlists = PlaylistLoader.getFavoritePlaylist(context)
if (playlists.isEmpty()) {
Error(Throwable("No items found"))
} else {
Success(
Home(
4,
R.string.favorites,
playlists,
HomeAdapter.PLAYLISTS,
R.drawable.ic_favorite_white_24dp
)
)
}
} catch (e: Exception) {
Error(e)
}
} }
override suspend fun artistInfo( override suspend fun artistInfo(
name: String, name: String,
lang: String?, lang: String?,
cache: String? cache: String?
): Result<LastFmArtist> = safeApiCall( ): LastFmArtist = LastFmClient.getApiService().artistInfo(name, lang, cache)
call = {
Success(LastFmClient.getApiService().artistInfo(name, lang, cache))
},
errorMessage = "Error"
)
override suspend fun albumInfo( override suspend fun albumInfo(
artist: String, artist: String,
album: String album: String
): Result<LastFmAlbum> = safeApiCall( ): LastFmAlbum = LastFmClient.getApiService().albumInfo(artist, album)
call = {
Success(LastFmClient.getApiService().albumInfo(artist, album))
},
errorMessage = "Error"
)
override suspend fun artistById(artistId: Int): Result<Artist> { }
return try {
val artist = ArtistLoader.getArtist(context, artistId)
return Success(artist)
} catch (e: Exception) {
Error(Throwable("Error loading artist"))
}
}
}
suspend fun <T : Any> safeApiCall(call: suspend () -> Result<T>, errorMessage: String): Result<T> =
try {
call.invoke()
} catch (e: Exception) {
Error(IOException(errorMessage, e))
}

View file

@ -14,7 +14,6 @@
package code.name.monkey.retromusic.providers.interfaces package code.name.monkey.retromusic.providers.interfaces
import code.name.monkey.retromusic.Result
import code.name.monkey.retromusic.model.* import code.name.monkey.retromusic.model.*
import code.name.monkey.retromusic.rest.model.LastFmAlbum import code.name.monkey.retromusic.rest.model.LastFmAlbum
import code.name.monkey.retromusic.rest.model.LastFmArtist import code.name.monkey.retromusic.rest.model.LastFmArtist
@ -25,37 +24,37 @@ import code.name.monkey.retromusic.rest.model.LastFmArtist
interface Repository { interface Repository {
suspend fun allAlbums(): Result<ArrayList<Album>> suspend fun allAlbums(): List<Album>
suspend fun albumById(albumId: Int): Result<Album> suspend fun albumById(albumId: Int): Album
suspend fun allSongs(): Result<ArrayList<Song>> suspend fun allSongs(): List<Song>
suspend fun allArtists(): Result<ArrayList<Artist>> suspend fun allArtists(): List<Artist>
suspend fun allPlaylists(): Result<ArrayList<Playlist>> suspend fun allPlaylists(): List<Playlist>
suspend fun allGenres(): Result<ArrayList<Genre>> suspend fun allGenres(): List<Genre>
suspend fun search(query: String?): Result<MutableList<Any>> suspend fun search(query: String?): MutableList<Any>
suspend fun getPlaylistSongs(playlist: Playlist): Result<ArrayList<Song>> suspend fun getPlaylistSongs(playlist: Playlist): ArrayList<Song>
suspend fun getGenre(genreId: Int): Result<ArrayList<Song>> suspend fun getGenre(genreId: Int): ArrayList<Song>
suspend fun recentArtists(): Result<Home> suspend fun recentArtists(): Home?
suspend fun topArtists(): Result<Home> suspend fun topArtists(): Home?
suspend fun topAlbums(): Result<Home> suspend fun topAlbums(): Home?
suspend fun recentAlbums(): Result<Home> suspend fun recentAlbums(): Home?
suspend fun favoritePlaylist(): Result<Home> suspend fun favoritePlaylist(): Home?
suspend fun artistInfo(name: String, lang: String?, cache: String?): Result<LastFmArtist> suspend fun artistInfo(name: String, lang: String?, cache: String?): LastFmArtist
suspend fun albumInfo(artist: String, album: String): Result<LastFmAlbum> suspend fun albumInfo(artist: String, album: String): LastFmAlbum
suspend fun artistById(artistId: Int): Result<Artist> suspend fun artistById(artistId: Int): Artist
} }

View file

@ -17,12 +17,9 @@ package code.name.monkey.retromusic.util
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.content.SharedPreferences import android.content.SharedPreferences
import android.graphics.Color
import android.net.Uri import android.net.Uri
import code.name.monkey.retromusic.R import code.name.monkey.retromusic.R
import com.afollestad.materialdialogs.MaterialDialog import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.afollestad.materialdialogs.WhichButton
import com.afollestad.materialdialogs.actions.getActionButton
object AppRater { object AppRater {
private const val DO_NOT_SHOW_AGAIN = "do_not_show_again"// Package Name private const val DO_NOT_SHOW_AGAIN = "do_not_show_again"// Package Name
@ -64,30 +61,24 @@ object AppRater {
} }
private fun showRateDialog(context: Context, editor: SharedPreferences.Editor) { private fun showRateDialog(context: Context, editor: SharedPreferences.Editor) {
MaterialDialog(context) MaterialAlertDialogBuilder(context)
.show { .setTitle("Rate this App")
title(text = "Rate this App") .setMessage("If you enjoy using Retro Music, please take a moment to rate it. Thanks for your support!")
message(text = "If you enjoy using Retro Music, please take a moment to rate it. Thanks for your support!") .setPositiveButton(R.string.app_name) { _, _ ->
positiveButton(R.string.app_name) { context.startActivity(
context.startActivity( Intent(
Intent( Intent.ACTION_VIEW,
Intent.ACTION_VIEW, Uri.parse("market://details?id=${context.packageName}")
Uri.parse("market://details?id=${context.packageName}")
)
) )
editor.putBoolean(DO_NOT_SHOW_AGAIN, true) )
editor.commit() editor.putBoolean(DO_NOT_SHOW_AGAIN, true)
dismiss() editor.commit()
}
negativeButton(text = "Later") {
dismiss()
}
neutralButton(text = " No thanks") {
editor.putBoolean(DO_NOT_SHOW_AGAIN, true)
editor.commit()
dismiss()
}
getActionButton(WhichButton.POSITIVE).updateTextColor(Color.RED)
} }
.setNeutralButton("Not now", null)
.setNegativeButton("No thanks") { _, _ ->
editor.putBoolean(DO_NOT_SHOW_AGAIN, true)
editor.commit()
}
.show()
} }
} }

View file

@ -29,7 +29,7 @@ import org.jetbrains.annotations.NotNull;
import code.name.monkey.retromusic.R; import code.name.monkey.retromusic.R;
import code.name.monkey.retromusic.activities.AboutActivity; import code.name.monkey.retromusic.activities.AboutActivity;
import code.name.monkey.retromusic.activities.AlbumDetailsActivity; import code.name.monkey.retromusic.activities.albums.AlbumDetailsActivity;
import code.name.monkey.retromusic.activities.ArtistDetailActivity; import code.name.monkey.retromusic.activities.ArtistDetailActivity;
import code.name.monkey.retromusic.activities.DriveModeActivity; import code.name.monkey.retromusic.activities.DriveModeActivity;
import code.name.monkey.retromusic.activities.GenreDetailsActivity; import code.name.monkey.retromusic.activities.GenreDetailsActivity;

View file

@ -23,10 +23,11 @@ import android.provider.BaseColumns
import android.provider.MediaStore import android.provider.MediaStore
import android.provider.Settings import android.provider.Settings
import android.widget.Toast import android.widget.Toast
import androidx.appcompat.app.AlertDialog
import code.name.monkey.retromusic.R import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.model.Song import code.name.monkey.retromusic.model.Song
import code.name.monkey.retromusic.util.MusicUtil.getSongFileUri import code.name.monkey.retromusic.util.MusicUtil.getSongFileUri
import com.afollestad.materialdialogs.MaterialDialog import com.google.android.material.dialog.MaterialAlertDialogBuilder
class RingtoneManager(val context: Context) { class RingtoneManager(val context: Context) {
fun setRingtone(song: Song) { fun setRingtone(song: Song) {
@ -72,17 +73,17 @@ class RingtoneManager(val context: Context) {
return false return false
} }
fun getDialog(context: Context): MaterialDialog { fun getDialog(context: Context): AlertDialog {
return MaterialDialog(context).show { return MaterialAlertDialogBuilder(context)
title(R.string.dialog_title_set_ringtone) .setTitle(R.string.dialog_title_set_ringtone)
message(R.string.dialog_message_set_ringtone) .setMessage(R.string.dialog_message_set_ringtone)
positiveButton(android.R.string.ok) { .setPositiveButton(android.R.string.ok) { _, _ ->
val intent = Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS) val intent = Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS)
intent.data = Uri.parse("package:" + context.applicationContext.packageName) intent.data = Uri.parse("package:" + context.applicationContext.packageName)
context.startActivity(intent) context.startActivity(intent)
} }
negativeButton(android.R.string.cancel) .setNegativeButton(android.R.string.cancel, null)
} .create()
} }
} }
} }

View file

@ -1,17 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="511.999"
android:viewportHeight="511.999">
<path
android:fillColor="@color/md_white_1000"
android:pathData="M276.503 421.573c5.687-26.889 21.401-49.915 44.245-64.834 19.137-12.495 30.74-29.04 33.555-47.846 3.149-21.04-4.592-44.418-23.022-69.629l64.952-64.949-58.682-58.682-65.311 65.315c-24.124-16.967-46.712-24.068-67.286-21.117-18.947 2.72-35.843 14.104-48.864 32.926-15.481 22.39-38.441 37.471-64.657 42.467-25.764 4.921-43.684 12.515-54.784 23.212-23.097 22.258-36.062 54.037-36.506 89.484-0.53 42.25 16.932 85.486 46.71 115.656 29.794 30.185 72.705 48.286 114.787 48.421 0.162 0.001 0.318 0 0.48 0 35.187-0.001 67.001-12.443 89.616-35.062 11.137-11.137 19.239-29.245 24.767-55.362zm-127.857 1.924c-3.839 0-7.678-1.464-10.607-4.393l-45.276-45.276c-5.858-5.858-5.858-15.355 0-21.213 5.857-5.858 15.355-5.858 21.213 0l45.276 45.276c5.858 5.858 5.858 15.355 0 21.213-2.929 2.929-6.768 4.393-10.606 4.393zm64.261-74.466c-12.827 0-25.653-4.88-35.422-14.641-19.529-19.544-19.527-51.322-0.004-70.847 8.539-8.539 19.875-13.705 31.921-14.547 14.474-1.02 28.658 4.281 38.923 14.547 10.266 10.265 15.567 24.455 14.546 38.932-0.834 12.032-5.999 23.364-14.547 31.911-9.762 9.763-22.59 14.645-35.417 14.645z" />
<path
android:fillColor="@color/md_white_1000"
android:pathData="M359.067 40.306c-5.858 5.858-5.858 15.355 0 21.213l15.16 15.16-15.485 17.719 58.728 58.728 17.719-15.485 15.159 15.159c2.929 2.929 6.768 4.394 10.607 4.393 3.839 0 7.678-1.464 10.606-4.393 5.858-5.858 5.858-15.355 0-21.213l-13.732-13.732 11.057-9.663 13.036 13.036c2.929 2.929 6.768 4.394 10.607 4.393 3.839 0 7.678-1.464 10.606-4.393 5.858-5.858 5.858-15.355 0-21.213l-11.609-11.609 15.213-13.295c3.127-2.733 4.981-6.64 5.121-10.79 0.139 -4.151-1.448-8.174-4.385-11.11l-48.818-48.818c-2.936-2.937-6.943-4.52-11.11-4.385-4.15 0.14 -8.057 1.994-10.79 5.121l-13.295 15.213-11.609-11.609c-5.858-5.858-15.356-5.858-21.213 0-5.858 5.858-5.858 15.355 0 21.213l13.036 13.036-9.663 11.057-13.733-13.733c-5.858-5.859-15.356-5.859-21.213 0z" />
<path
android:fillColor="@color/md_white_1000"
android:pathData="M232.945 300.364c0.332-4.714-1.009-9.354-3.732-13.136-0.628-0.873-1.33-1.7-2.102-2.472-3.781-3.782-8.89-5.884-14.193-5.884-0.47 0-0.941 0.017 -1.414 0.05 -4.84 0.338 -9.386 2.41-12.81 5.833-7.831 7.832-7.829 20.582 0.004 28.421 7.832 7.826 20.581 7.828 28.413-0.004 3.431-3.43 5.502-7.969 5.832-12.782 0.001 -0.008 0.002 -0.017 0.002 -0.026z" />
</vector>

View file

@ -15,13 +15,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android" <vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp" android:width="24dp"
android:height="24dp" android:height="24dp"
android:viewportWidth="512" android:viewportWidth="24"
android:viewportHeight="512"> android:viewportHeight="24">
<path <path
android:fillColor="@color/md_white_1000" android:fillColor="@color/md_white_1000"
android:pathData="M511.861 64.321c0.139-4.151-1.448-8.174-4.385-11.11l-48.817-48.818c-2.936-2.937-6.943-4.521-11.11-4.385-4.15 0.14 -8.058 1.994-10.791 5.121l-13.295 15.213-11.608-11.609c-5.857-5.858-15.355-5.858-21.213 0s-5.858 15.355 0 21.213l13.036 13.036-9.663 11.057-13.733-13.733c-5.857-5.858-15.355-5.858-21.213 0s-5.858 15.355 0 21.213l15.16 15.16-102.024 104.305c-22.898-16.082-44.302-23.315-63.925-21.541-20.337 1.838-38.384 13.358-52.188 33.316-15.486 22.389-38.447 37.472-64.653 42.47-25.751 4.912-43.671 12.503-54.782 23.208-23.1 22.254-36.067 54.03-36.514 89.476-0.533 42.25 16.928 85.488 46.708 115.66 29.792 30.185 72.7 48.289 114.779 48.426 0.165 0 0.327 0.001 0.49 0.001 35.188 0 66.999-12.441 89.618-35.06 11.143-11.143 19.245-29.252 24.77-55.363 5.69-26.892 21.404-49.917 44.248-64.835 20.106-13.129 31.83-30.629 33.904-50.607 2.139-20.603-5.537-42.685-23.346-66.899l103.876-101.595 15.16 15.159c2.929 2.929 6.768 4.394 10.606 4.394s7.678-1.464 10.606-4.394c5.858-5.858 5.858-15.355 0-21.213l-13.732-13.732 11.057-9.663 13.036 13.036c2.929 2.929 6.768 4.394 10.606 4.394s7.678-1.464 10.606-4.394c5.858-5.858 5.858-15.355 0-21.213l-11.609-11.609 15.213-13.295c3.128-2.733 4.982-6.64 5.122-10.79zm-187.042 238.716c-1.125 10.834-8.011 20.452-20.468 28.587-29.538 19.289-49.85 49.029-57.195 83.743-5.54 26.185-12.798 36.526-16.632 40.359-17.032 17.032-41.486 26.318-68.797 26.273-34.262-0.113-69.225-14.879-93.526-39.5-24.267-24.587-38.495-59.805-38.062-94.209 0.345 -27.364 10.051-51.602 27.331-68.249 3.767-3.629 13.918-10.448 39.588-15.344 33.986-6.481 63.713-25.969 83.705-54.872 8.701-12.58 18.868-19.479 30.216-20.504 1.046-0.094 2.111-0.142 3.193-0.142 10.609 0 22.904 4.54 36.463 13.373l-47.245 47.245c-9.497 1.824-18.565 6.404-25.904 13.742-19.531 19.531-19.531 51.311 0 70.841 9.766 9.766 22.593 14.648 35.421 14.648s25.655-4.883 35.421-14.648c7.338-7.339 11.918-16.406 13.742-25.904l47.701-47.701c11.128 16.162 16.272 30.472 15.048 42.262zm-97.704-18.283c7.834 7.834 7.834 20.582 0 28.416-7.835 7.834-20.581 7.834-28.416 0-7.834-7.834-7.834-20.581 0-28.416 3.918-3.917 9.062-5.875 14.208-5.875 5.145-0.001 10.291 1.958 14.208 5.875zm28.388-12.135c-1.996-3.227-4.378-6.282-7.175-9.078-2.797-2.797-5.851-5.179-9.079-7.175l130.124-130.124 16.254 16.254zm152.027-150.647-17.633-17.633 58.893-67.389 26.129 26.129z" /> android:pathData="M19.59,3H22V5H20.41L16.17,9.24C15.8,8.68 15.32,8.2 14.76,7.83L19.59,3M12,8A4,4 0 0,1 16,12C16,13.82 14.77,15.42 13,15.87V16A5,5 0 0,1 8,21A5,5 0 0,1 3,16A5,5 0 0,1 8,11H8.13C8.58,9.24 10.17,8 12,8M12,10.5A1.5,1.5 0 0,0 10.5,12A1.5,1.5 0 0,0 12,13.5A1.5,1.5 0 0,0 13.5,12A1.5,1.5 0 0,0 12,10.5M6.94,14.24L6.23,14.94L9.06,17.77L9.77,17.06L6.94,14.24Z" />
<path
android:fillColor="@color/md_white_1000"
android:pathData="M113.978 352.615c-5.857-5.858-15.355-5.858-21.213 0s-5.858 15.355 0 21.213l45.276 45.276c2.929 2.929 6.768 4.394 10.606 4.394s7.678-1.464 10.606-4.394c5.858-5.858 5.858-15.355 0-21.213z" />
</vector> </vector>

View file

@ -48,7 +48,7 @@
android:layout_marginEnd="16dp" android:layout_marginEnd="16dp"
android:transitionName="@string/transition_album_art" android:transitionName="@string/transition_album_art"
app:cardCornerRadius="24dp" app:cardCornerRadius="24dp"
app:cardElevation="8dp" app:cardElevation="0dp"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/container" app:layout_constraintEnd_toStartOf="@+id/container"
app:layout_constraintHorizontal_bias="0.5" app:layout_constraintHorizontal_bias="0.5"

View file

@ -48,7 +48,7 @@
android:layout_marginEnd="16dp" android:layout_marginEnd="16dp"
android:transitionName="@string/transition_artist_image" android:transitionName="@string/transition_artist_image"
app:cardCornerRadius="24dp" app:cardCornerRadius="24dp"
app:cardElevation="8dp" app:cardElevation="0dp"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/container" app:layout_constraintEnd_toStartOf="@+id/container"
app:layout_constraintHorizontal_bias="0.5" app:layout_constraintHorizontal_bias="0.5"

View file

@ -13,7 +13,8 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="156dp" android:layout_height="156dp"
android:layout_margin="8dp" android:layout_margin="8dp"
app:cardCornerRadius="16dp"> app:cardCornerRadius="16dp"
app:cardElevation="0dp">
<androidx.appcompat.widget.AppCompatImageView <androidx.appcompat.widget.AppCompatImageView
android:id="@+id/image" android:id="@+id/image"

View file

@ -13,7 +13,8 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="256dp" android:layout_height="256dp"
android:layout_margin="8dp" android:layout_margin="8dp"
app:cardCornerRadius="16dp"> app:cardCornerRadius="16dp"
app:cardElevation="0dp">
<androidx.appcompat.widget.AppCompatImageView <androidx.appcompat.widget.AppCompatImageView
android:id="@+id/image" android:id="@+id/image"

View file

@ -22,11 +22,13 @@
android:id="@+id/appBarLayout" android:id="@+id/appBarLayout"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="?attr/colorSurface"
app:liftOnScroll="true"> app:liftOnScroll="true">
<com.google.android.material.appbar.MaterialToolbar <com.google.android.material.appbar.MaterialToolbar
android:id="@+id/toolbar" android:id="@+id/toolbar"
style="@style/Toolbar" style="@style/Toolbar"
android:background="?attr/colorSurface"
app:layout_collapseMode="pin" app:layout_collapseMode="pin"
app:navigationIcon="@drawable/ic_keyboard_backspace_black_24dp" app:navigationIcon="@drawable/ic_keyboard_backspace_black_24dp"
app:title="@string/action_about" app:title="@string/action_about"
@ -36,9 +38,9 @@
<androidx.core.widget.NestedScrollView <androidx.core.widget.NestedScrollView
android:id="@+id/container" android:id="@+id/container"
android:overScrollMode="never"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:overScrollMode="never"
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior"> app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior">
<include layout="@layout/activity_about_content" /> <include layout="@layout/activity_about_content" />

View file

@ -64,7 +64,7 @@
android:layout_marginEnd="16dp" android:layout_marginEnd="16dp"
android:transitionName="@string/transition_album_art" android:transitionName="@string/transition_album_art"
app:cardCornerRadius="24dp" app:cardCornerRadius="24dp"
app:cardElevation="8dp" app:cardElevation="0dp"
app:layout_constraintDimensionRatio="1:1" app:layout_constraintDimensionRatio="1:1"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"

View file

@ -63,7 +63,7 @@
android:layout_marginEnd="16dp" android:layout_marginEnd="16dp"
android:transitionName="@string/transition_artist_image" android:transitionName="@string/transition_artist_image"
app:cardCornerRadius="24dp" app:cardCornerRadius="24dp"
app:cardElevation="8dp" app:cardElevation="0dp"
app:layout_constraintDimensionRatio="1:1" app:layout_constraintDimensionRatio="1:1"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
@ -74,7 +74,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:scaleType="centerCrop" android:scaleType="centerCrop"
tools:srcCompat="@tools:sample/backgrounds/scenic[16]" /> tools:srcCompat="@tools:sample/backgrounds/scenic" />
</com.google.android.material.card.MaterialCardView> </com.google.android.material.card.MaterialCardView>
@ -94,7 +94,7 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/artistCoverContainer" app:layout_constraintTop_toBottomOf="@id/artistCoverContainer"
tools:ignore="MissingPrefix" tools:ignore="MissingPrefix"
tools:text="Title" /> tools:text="@tools:sample/full_names" />
<code.name.monkey.retromusic.views.BaselineGridTextView <code.name.monkey.retromusic.views.BaselineGridTextView
android:id="@+id/text" android:id="@+id/text"
@ -109,7 +109,7 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/artistTitle" app:layout_constraintTop_toBottomOf="@id/artistTitle"
tools:ignore="MissingPrefix" tools:ignore="MissingPrefix"
tools:text="Title" /> tools:text="@tools:sample/full_names" />
<include <include
layout="@layout/activity_artist_content" layout="@layout/activity_artist_content"

View file

@ -1,17 +1,17 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android" <com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:cardCornerRadius="@dimen/about_card_radius" android:layout_margin="4dp"
app:cardUseCompatPadding="true"> app:cardCornerRadius="@dimen/about_card_radius">
<androidx.constraintlayout.widget.ConstraintLayout <androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical"> android:orientation="vertical">
<code.name.monkey.appthemehelper.common.views.ATEAccentTextView <code.name.monkey.appthemehelper.common.views.ATEAccentTextView
android:id="@+id/sb1" android:id="@+id/sb1"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -36,7 +36,9 @@
android:overScrollMode="never" android:overScrollMode="never"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/sb1" /> app:layout_constraintTop_toBottomOf="@+id/sb1"
tools:itemCount="3"
tools:listitem="@layout/item_contributor" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView> </com.google.android.material.card.MaterialCardView>

View file

@ -3,8 +3,8 @@
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:cardCornerRadius="@dimen/about_card_radius" android:layout_margin="4dp"
app:cardUseCompatPadding="true"> app:cardCornerRadius="@dimen/about_card_radius">
<androidx.constraintlayout.widget.ConstraintLayout <androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent" android:layout_width="match_parent"

View file

@ -3,8 +3,8 @@
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:cardCornerRadius="@dimen/about_card_radius" android:layout_margin="4dp"
app:cardUseCompatPadding="true"> app:cardCornerRadius="@dimen/about_card_radius">
<androidx.constraintlayout.widget.ConstraintLayout <androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent" android:layout_width="match_parent"

View file

@ -1,81 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingStart="16dp"
android:paddingTop="16dp"
android:paddingEnd="16dp"
android:paddingBottom="16dp">
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/nameContainer"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:hintEnabled="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:startIconDrawable="@drawable/ic_account_white_24dp">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/nameText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/my_name"
android:inputType="text|textCapWords"
android:maxLines="1" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/amountContainer"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
app:hintEnabled="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/nameContainer"
app:startIconDrawable="@drawable/ic_currency_inr_white_24dp">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/amountText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/amount"
android:inputType="numberDecimal"
android:maxLines="1" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/noteContainer"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
app:hintEnabled="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/amountContainer"
app:startIconDrawable="@drawable/ic_edit_white_24dp">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/noteText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/note"
android:inputType="text|textCapWords"
android:maxLines="1" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.button.MaterialButton
android:id="@+id/submit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="@string/start_payment"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/noteContainer" />
</androidx.constraintlayout.widget.ConstraintLayout>

View file

@ -12,8 +12,8 @@
android:layout_width="112dp" android:layout_width="112dp"
android:layout_height="156dp" android:layout_height="156dp"
android:layout_margin="8dp" android:layout_margin="8dp"
app:cardCornerRadius="8dp" app:cardCornerRadius="12dp"
app:cardElevation="4dp" app:cardElevation="0dp"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"> app:layout_constraintTop_toTopOf="parent">
@ -41,5 +41,5 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/imageContainer" app:layout_constraintTop_toBottomOf="@+id/imageContainer"
tools:ignore="MissingPrefix" tools:ignore="MissingPrefix"
tools:text="@tools:sample/lorem/random" /> tools:text="@tools:sample/full_names" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

View file

@ -17,7 +17,8 @@
android:layout_width="128dp" android:layout_width="128dp"
android:layout_height="128dp" android:layout_height="128dp"
android:layout_margin="4dp" android:layout_margin="4dp"
app:cardCornerRadius="16dp"> app:cardCornerRadius="16dp"
app:cardElevation="0dp">
<androidx.constraintlayout.widget.ConstraintLayout <androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/paletteColorContainer" android:id="@+id/paletteColorContainer"

View file

@ -8,7 +8,7 @@
android:layout_margin="8dp" android:layout_margin="8dp"
android:background="?attr/rectSelector" android:background="?attr/rectSelector"
app:cardCornerRadius="8dp" app:cardCornerRadius="8dp"
app:cardElevation="4dp"> app:cardElevation="0dp">
<androidx.constraintlayout.widget.ConstraintLayout <androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="wrap_content" android:layout_width="wrap_content"

View file

@ -32,16 +32,15 @@
android:scaleType="centerCrop" android:scaleType="centerCrop"
app:civ_border="false" app:civ_border="false"
app:civ_shadow="false" app:civ_shadow="false"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
app:retroCornerSize="21dp" app:retroCornerSize="21dp"
app:srcCompat="@drawable/ic_account_white_24dp" app:srcCompat="@drawable/ic_account_white_24dp"
tools:srcCompat="@tools:sample/backgrounds/scenic[20]" /> tools:srcCompat="@tools:sample/backgrounds/scenic" />
<com.google.android.material.textview.MaterialTextView <com.google.android.material.textview.MaterialTextView
android:id="@+id/title" android:id="@+id/title"
android:layout_width="wrap_content" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="16dp" android:layout_marginStart="16dp"
android:textAppearance="@style/TextViewSubtitle1" android:textAppearance="@style/TextViewSubtitle1"
@ -54,9 +53,11 @@
<code.name.monkey.retromusic.views.BaselineGridTextView <code.name.monkey.retromusic.views.BaselineGridTextView
android:id="@+id/text" android:id="@+id/text"
android:layout_width="wrap_content" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="16dp" android:layout_marginStart="16dp"
android:ellipsize="end"
android:maxLines="1"
android:textColor="?android:attr/textColorSecondary" android:textColor="?android:attr/textColorSecondary"
app:layout_constrainedWidth="true" app:layout_constrainedWidth="true"
app:layout_constraintBottom_toBottomOf="@+id/icon" app:layout_constraintBottom_toBottomOf="@+id/icon"
@ -64,6 +65,6 @@
app:layout_constraintHorizontal_bias="0" app:layout_constraintHorizontal_bias="0"
app:layout_constraintStart_toEndOf="@id/icon" app:layout_constraintStart_toEndOf="@id/icon"
app:lineHeightHint="24sp" app:lineHeightHint="24sp"
tools:text="@tools:sample/full_names" /> tools:text="@tools:sample/lorem/random" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

View file

@ -10,6 +10,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_margin="4dp" android:layout_margin="4dp"
app:cardCornerRadius="8dp" app:cardCornerRadius="8dp"
app:cardElevation="0dp"
app:contentPadding="12dp"> app:contentPadding="12dp">
<androidx.constraintlayout.widget.ConstraintLayout <androidx.constraintlayout.widget.ConstraintLayout

View file

@ -17,6 +17,7 @@
android:layout_height="0dp" android:layout_height="0dp"
android:scaleType="centerCrop" android:scaleType="centerCrop"
app:cardCornerRadius="8dp" app:cardCornerRadius="8dp"
app:cardElevation="0dp"
app:layout_constraintDimensionRatio="1:1" app:layout_constraintDimensionRatio="1:1"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"

View file

@ -14,7 +14,7 @@
android:layout_margin="8dp" android:layout_margin="8dp"
android:orientation="vertical" android:orientation="vertical"
app:cardCornerRadius="8dp" app:cardCornerRadius="8dp"
app:cardElevation="8dp" app:cardElevation="0dp"
app:cardPreventCornerOverlap="true" app:cardPreventCornerOverlap="true"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"

View file

@ -15,6 +15,7 @@
android:layout_margin="4dp" android:layout_margin="4dp"
android:orientation="vertical" android:orientation="vertical"
app:cardCornerRadius="8dp" app:cardCornerRadius="8dp"
app:cardElevation="0dp"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintDimensionRatio="1:1" app:layout_constraintDimensionRatio="1:1"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"

View file

@ -37,7 +37,8 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
app:cardCornerRadius="6dp"> app:cardCornerRadius="6dp"
app:cardElevation="0dp">
<androidx.appcompat.widget.AppCompatImageView <androidx.appcompat.widget.AppCompatImageView
android:id="@+id/image" android:id="@+id/image"

View file

@ -14,6 +14,7 @@
android:layout_height="0dp" android:layout_height="0dp"
android:layout_margin="8dp" android:layout_margin="8dp"
app:cardCornerRadius="16dp" app:cardCornerRadius="16dp"
app:cardElevation="0dp"
app:layout_constraintDimensionRatio="16:9" app:layout_constraintDimensionRatio="16:9"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
@ -50,8 +51,8 @@
android:paddingTop="6dp" android:paddingTop="6dp"
android:paddingEnd="8dp" android:paddingEnd="8dp"
android:paddingBottom="4dp" android:paddingBottom="4dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/imageContainer" app:layout_constraintTop_toBottomOf="@id/imageContainer"
tools:ignore="MissingPrefix" tools:ignore="MissingPrefix"
tools:text="@tools:sample/full_names" /> tools:text="@tools:sample/full_names" />
@ -63,11 +64,11 @@
android:ellipsize="end" android:ellipsize="end"
android:maxLines="1" android:maxLines="1"
android:paddingStart="16dp" android:paddingStart="16dp"
app:layout_constraintStart_toStartOf="parent"
android:paddingEnd="8dp" android:paddingEnd="8dp"
android:textAppearance="@style/TextViewSubtitle1" android:textAppearance="@style/TextViewSubtitle1"
android:textStyle="bold" android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/text" app:layout_constraintTop_toBottomOf="@id/text"
tools:ignore="MissingPrefix" tools:ignore="MissingPrefix"
tools:text="@tools:sample/full_names" /> tools:text="@tools:sample/full_names" />

View file

@ -25,5 +25,5 @@
android:paddingTop="16dp" android:paddingTop="16dp"
android:paddingEnd="16dp" android:paddingEnd="16dp"
android:textAppearance="@style/TextViewOverline" android:textAppearance="@style/TextViewOverline"
tools:text="@string/about_settings_summary" /> tools:text="@tools:sample/full_names" />
</LinearLayout> </LinearLayout>

View file

@ -32,7 +32,6 @@
</style> </style>
<style name="Theme.RetroMusic.Base" parent="Theme.MaterialComponents.NoActionBar"> <style name="Theme.RetroMusic.Base" parent="Theme.MaterialComponents.NoActionBar">
<item name="md_color_button_text">@color/md_white_1000</item>
<item name="md_background_color">@color/darkColorPrimary</item> <item name="md_background_color">@color/darkColorPrimary</item>
<item name="android:windowActionBarOverlay">true</item> <item name="android:windowActionBarOverlay">true</item>
<item name="android:windowActivityTransitions">true</item> <item name="android:windowActivityTransitions">true</item>
@ -53,7 +52,6 @@
</style> </style>
<style name="Theme.RetroMusic.Base.Light" parent="Theme.MaterialComponents.Light.NoActionBar"> <style name="Theme.RetroMusic.Base.Light" parent="Theme.MaterialComponents.Light.NoActionBar">
<item name="md_color_button_text">@color/md_black_1000</item>
<item name="android:windowActionBarOverlay">true</item> <item name="android:windowActionBarOverlay">true</item>
<item name="windowActionBarOverlay">true</item> <item name="windowActionBarOverlay">true</item>
<item name="roundSelector">@drawable/round_selector</item> <item name="roundSelector">@drawable/round_selector</item>

View file

@ -44,4 +44,11 @@
<color name="progress_gray">#FFD8D8D8</color> <color name="progress_gray">#FFD8D8D8</color>
<color name="progress_gray_dark">#FF383838</color> <color name="progress_gray_dark">#FF383838</color>
<color name="default_blue_light">#ff33b5e5</color> <color name="default_blue_light">#ff33b5e5</color>
</resources> </resources>

View file

@ -133,7 +133,9 @@
<item name="fontFamily">@font/google_san</item> <item name="fontFamily">@font/google_san</item>
</style> </style>
<style name="TextViewNormal" parent="TextAppearance.AppCompat.Body2" /> <style name="TextViewNormal" parent="">
<item name="android:textSize">14sp</item>
</style>
<style name="TextViewHeadline4" parent="TextAppearance.MaterialComponents.Headline4"> <style name="TextViewHeadline4" parent="TextAppearance.MaterialComponents.Headline4">
<item name="android:fontFamily">@font/google_san</item> <item name="android:fontFamily">@font/google_san</item>
@ -176,13 +178,11 @@
</style> </style>
<style name="TextViewBody1" parent="TextAppearance.MaterialComponents.Body1"> <style name="TextViewBody1" parent="TextAppearance.MaterialComponents.Body1">
<item name="lineHeightHint">24sp</item>
<item name="android:fontFamily">@font/google_san</item> <item name="android:fontFamily">@font/google_san</item>
<item name="fontFamily">@font/google_san</item> <item name="fontFamily">@font/google_san</item>
</style> </style>
<style name="TextViewBody2" parent="TextAppearance.MaterialComponents.Body2"> <style name="TextViewBody2" parent="TextAppearance.MaterialComponents.Body2">
<item name="lineHeightHint">24sp</item>
<item name="android:fontFamily">@font/google_san</item> <item name="android:fontFamily">@font/google_san</item>
<item name="fontFamily">@font/google_san</item> <item name="fontFamily">@font/google_san</item>
</style> </style>
@ -192,6 +192,7 @@
<item name="fontFamily">@font/google_san</item> <item name="fontFamily">@font/google_san</item>
</style> </style>
<style name="TopCornerCardView"> <style name="TopCornerCardView">
<item name="cornerFamilyTopLeft">rounded</item> <item name="cornerFamilyTopLeft">rounded</item>
<item name="cornerFamilyTopRight">rounded</item> <item name="cornerFamilyTopRight">rounded</item>

View file

@ -16,7 +16,6 @@
</style> </style>
<style name="Theme.RetroMusic.Base" parent="Theme.MaterialComponents.NoActionBar"> <style name="Theme.RetroMusic.Base" parent="Theme.MaterialComponents.NoActionBar">
<item name="md_color_button_text">@color/md_white_1000</item>
<item name="md_background_color">@color/darkColorSurface</item> <item name="md_background_color">@color/darkColorSurface</item>
<item name="android:windowActionBarOverlay">true</item> <item name="android:windowActionBarOverlay">true</item>
<item name="android:windowActivityTransitions">true</item> <item name="android:windowActivityTransitions">true</item>
@ -54,7 +53,6 @@
</style> </style>
<style name="Theme.RetroMusic.Base.Light" parent="Theme.MaterialComponents.Light.NoActionBar"> <style name="Theme.RetroMusic.Base.Light" parent="Theme.MaterialComponents.Light.NoActionBar">
<item name="md_color_button_text">@color/md_black_1000</item>
<item name="android:windowActionBarOverlay">true</item> <item name="android:windowActionBarOverlay">true</item>
<item name="windowActionBarOverlay">true</item> <item name="windowActionBarOverlay">true</item>
<item name="roundSelector">@drawable/round_selector</item> <item name="roundSelector">@drawable/round_selector</item>
@ -67,6 +65,7 @@
<item name="windowActionBar">false</item> <item name="windowActionBar">false</item>
<item name="materialAlertDialogTheme">@style/MaterialAlertDialogTheme</item> <item name="materialAlertDialogTheme">@style/MaterialAlertDialogTheme</item>
<item name="materialButtonStyle">@style/MaterialButtonTheme</item> <item name="materialButtonStyle">@style/MaterialButtonTheme</item>
</style> </style>

View file

@ -70,7 +70,7 @@
app:showSeekBarValue="true" /> app:showSeekBarValue="true" />
</code.name.monkey.appthemehelper.common.prefs.supportv7.ATEPreferenceCategory> </code.name.monkey.appthemehelper.common.prefs.supportv7.ATEPreferenceCategory>
<code.name.monkey.retromusic.preferences.MaterialListPreference <code.name.monkey.appthemehelper.common.prefs.supportv7.ATEListPreference
android:defaultValue="auto" android:defaultValue="auto"
android:entries="@array/pref_language_names" android:entries="@array/pref_language_names"
android:entryValues="@array/pref_language_codes" android:entryValues="@array/pref_language_codes"

View file

@ -5,12 +5,14 @@
android:layout="@layout/preference_category_title" android:layout="@layout/preference_category_title"
android:title="@string/pref_header_general"> android:title="@string/pref_header_general">
<code.name.monkey.retromusic.preferences.MaterialListPreference <code.name.monkey.appthemehelper.common.prefs.supportv7.ATEListPreference
android:defaultValue="auto" android:defaultValue="auto"
android:entries="@array/pref_general_theme_list_titles" android:entries="@array/pref_general_theme_list_titles"
android:entryValues="@array/pref_general_theme_list_values" android:entryValues="@array/pref_general_theme_list_values"
android:key="general_theme" android:key="general_theme"
android:layout="@layout/list_item_view" android:layout="@layout/list_item_view"
android:negativeButtonText="@null"
android:positiveButtonText="@null"
android:title="@string/pref_title_general_theme" android:title="@string/pref_title_general_theme"
app:icon="@drawable/ic_color_lens_white_24dp" /> app:icon="@drawable/ic_color_lens_white_24dp" />

View file

@ -10,7 +10,7 @@
android:title="@string/pref_title_ignore_media_store_artwork" android:title="@string/pref_title_ignore_media_store_artwork"
app:icon="@drawable/ic_image_white_24dp" /> app:icon="@drawable/ic_image_white_24dp" />
<code.name.monkey.retromusic.preferences.MaterialListPreference <code.name.monkey.appthemehelper.common.prefs.supportv7.ATEListPreference
android:defaultValue="only_wifi" android:defaultValue="only_wifi"
android:entries="@array/pref_auto_download_images_titles" android:entries="@array/pref_auto_download_images_titles"
android:entryValues="@array/pref_auto_download_images_values" android:entryValues="@array/pref_auto_download_images_values"

View file

@ -25,7 +25,7 @@
android:title="@string/pref_title_album_cover_style" android:title="@string/pref_title_album_cover_style"
app:icon="@drawable/ic_image_white_24dp" /> app:icon="@drawable/ic_image_white_24dp" />
<code.name.monkey.retromusic.preferences.MaterialListPreference <code.name.monkey.appthemehelper.common.prefs.supportv7.ATEListPreference
android:defaultValue="0" android:defaultValue="0"
android:entries="@array/pref_album_cover_transform_entities" android:entries="@array/pref_album_cover_transform_entities"
android:entryValues="@array/pref_album_cover_transform_values" android:entryValues="@array/pref_album_cover_transform_values"

View file

@ -5,7 +5,7 @@
android:layout="@layout/preference_category_title" android:layout="@layout/preference_category_title"
app:title="@string/home"> app:title="@string/home">
<code.name.monkey.retromusic.preferences.MaterialListPreference <code.name.monkey.appthemehelper.common.prefs.supportv7.ATEListPreference
android:defaultValue="0" android:defaultValue="0"
android:entries="@array/pref_home_grid_style_list_titles" android:entries="@array/pref_home_grid_style_list_titles"
android:entryValues="@array/pref_home_grid_style_list_values" android:entryValues="@array/pref_home_grid_style_list_values"
@ -36,7 +36,7 @@
android:title="@string/library_categories" android:title="@string/library_categories"
app:icon="@drawable/ic_library_music_white_24dp" /> app:icon="@drawable/ic_library_music_white_24dp" />
<code.name.monkey.retromusic.preferences.MaterialListPreference <code.name.monkey.appthemehelper.common.prefs.supportv7.ATEListPreference
android:defaultValue="0" android:defaultValue="0"
android:entries="@array/pref_tab_text_mode_titles" android:entries="@array/pref_tab_text_mode_titles"
android:entryValues="@array/pref_tab_text_mode_values" android:entryValues="@array/pref_tab_text_mode_values"

View file

@ -31,9 +31,8 @@ dependencies {
implementation 'androidx.preference:preference:1.1.0' implementation 'androidx.preference:preference:1.1.0'
implementation 'androidx.cardview:cardview:1.0.0' implementation 'androidx.cardview:cardview:1.0.0'
// Used for the list preference classes // Used for the list preference classes
implementation 'com.afollestad.material-dialogs:core:3.1.1' def material_dialog_version = "0.9.6.0"
implementation 'com.afollestad.material-dialogs:input:3.1.1' implementation "com.afollestad.material-dialogs:core:$material_dialog_version"
implementation 'com.afollestad.material-dialogs:color:3.1.1' implementation "com.afollestad.material-dialogs:commons:$material_dialog_version"
implementation 'com.afollestad.material-dialogs:bottomsheets:3.1.1'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
} }

View file

@ -4,16 +4,14 @@ import android.annotation.SuppressLint
import android.content.Context import android.content.Context
import android.content.SharedPreferences import android.content.SharedPreferences
import android.graphics.Color import android.graphics.Color
import androidx.annotation.AttrRes import androidx.annotation.*
import androidx.annotation.CheckResult
import androidx.annotation.ColorInt
import androidx.annotation.ColorRes
import androidx.annotation.IntRange import androidx.annotation.IntRange
import androidx.annotation.StyleRes
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import code.name.monkey.appthemehelper.util.ATHUtil import code.name.monkey.appthemehelper.util.ATHUtil
import code.name.monkey.appthemehelper.util.ATHUtil.resolveColor
import code.name.monkey.appthemehelper.util.ColorUtil import code.name.monkey.appthemehelper.util.ColorUtil
/** /**
* @author Aidan Follestad (afollestad), Karim Abou Zeid (kabouzeid) * @author Aidan Follestad (afollestad), Karim Abou Zeid (kabouzeid)
*/ */
@ -183,7 +181,10 @@ private constructor(private val mContext: Context) : ThemeStorePrefKeys, ThemeSt
@CheckResult @CheckResult
fun prefs(context: Context): SharedPreferences { fun prefs(context: Context): SharedPreferences {
return context.getSharedPreferences(ThemeStorePrefKeys.CONFIG_PREFS_KEY_DEFAULT, Context.MODE_PRIVATE) return context.getSharedPreferences(
ThemeStorePrefKeys.CONFIG_PREFS_KEY_DEFAULT,
Context.MODE_PRIVATE
)
} }
fun markChanged(context: Context) { fun markChanged(context: Context) {
@ -224,12 +225,18 @@ private constructor(private val mContext: Context) : ThemeStorePrefKeys, ThemeSt
fun navigationBarColor(context: Context): Int { fun navigationBarColor(context: Context): Int {
return if (!coloredNavigationBar(context)) { return if (!coloredNavigationBar(context)) {
Color.BLACK Color.BLACK
} else prefs(context).getInt(ThemeStorePrefKeys.KEY_NAVIGATION_BAR_COLOR, primaryColor(context)) } else prefs(context).getInt(
ThemeStorePrefKeys.KEY_NAVIGATION_BAR_COLOR,
primaryColor(context)
)
} }
@CheckResult @CheckResult
fun coloredStatusBar(context: Context): Boolean { fun coloredStatusBar(context: Context): Boolean {
return prefs(context).getBoolean(ThemeStorePrefKeys.KEY_APPLY_PRIMARYDARK_STATUSBAR, true) return prefs(context).getBoolean(
ThemeStorePrefKeys.KEY_APPLY_PRIMARYDARK_STATUSBAR,
true
)
} }
@CheckResult @CheckResult
@ -247,6 +254,42 @@ private constructor(private val mContext: Context) : ThemeStorePrefKeys, ThemeSt
return prefs(context).getBoolean(ThemeStorePrefKeys.IS_CONFIGURED_KEY, false) return prefs(context).getBoolean(ThemeStorePrefKeys.IS_CONFIGURED_KEY, false)
} }
@CheckResult
@ColorInt
fun textColorPrimary(context: Context): Int {
return prefs(context).getInt(
ThemeStorePrefKeys.KEY_TEXT_COLOR_PRIMARY,
resolveColor(context, android.R.attr.textColorPrimary)
)
}
@CheckResult
@ColorInt
fun textColorPrimaryInverse(context: Context): Int {
return prefs(context).getInt(
ThemeStorePrefKeys.KEY_TEXT_COLOR_PRIMARY_INVERSE,
resolveColor(context, android.R.attr.textColorPrimaryInverse)
)
}
@CheckResult
@ColorInt
fun textColorSecondary(context: Context): Int {
return prefs(context).getInt(
ThemeStorePrefKeys.KEY_TEXT_COLOR_SECONDARY,
resolveColor(context, android.R.attr.textColorSecondary)
)
}
@CheckResult
@ColorInt
fun textColorSecondaryInverse(context: Context): Int {
return prefs(context).getInt(
ThemeStorePrefKeys.KEY_TEXT_COLOR_SECONDARY_INVERSE,
resolveColor(context, android.R.attr.textColorSecondaryInverse)
)
}
@SuppressLint("CommitPrefEdits") @SuppressLint("CommitPrefEdits")
fun isConfigured( fun isConfigured(
context: Context, @IntRange( context: Context, @IntRange(

View file

@ -36,7 +36,6 @@ class ATEColorPreference @JvmOverloads constructor(
private var border: Int = 0 private var border: Int = 0
init { init {
layoutResource = R.layout.ate_preference_custom_support
widgetLayoutResource = R.layout.ate_preference_color widgetLayoutResource = R.layout.ate_preference_color
isPersistent = false isPersistent = false

View file

@ -1,32 +0,0 @@
/*
* Copyright (c) 2019 Hemanth Savarala.
*
* Licensed under the GNU General Public License v3
*
* This is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by
* the Free Software Foundation either version 3 of the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*/
package code.name.monkey.appthemehelper.common.prefs.supportv7
import android.content.Context
import android.util.AttributeSet
import androidx.preference.EditTextPreference
import code.name.monkey.appthemehelper.R
class ATEEditTextPreference @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0,
defStyleRes: Int = 0
) : EditTextPreference(context, attrs, defStyleAttr, defStyleRes) {
init {
layoutResource = R.layout.ate_preference_custom_support
}
}

View file

@ -16,7 +16,6 @@ package code.name.monkey.appthemehelper.common.prefs.supportv7
import android.content.Context import android.content.Context
import android.util.AttributeSet import android.util.AttributeSet
import androidx.preference.ListPreference import androidx.preference.ListPreference
import code.name.monkey.appthemehelper.R.layout
class ATEListPreference @JvmOverloads constructor( class ATEListPreference @JvmOverloads constructor(
context: Context, context: Context,
@ -26,7 +25,6 @@ class ATEListPreference @JvmOverloads constructor(
) : ListPreference(context, attrs, defStyleAttr, defStyleRes) { ) : ListPreference(context, attrs, defStyleAttr, defStyleRes) {
init { init {
layoutResource = layout.ate_preference_custom_support
if (summary == null || summary.toString().trim { it <= ' ' }.isEmpty()) { if (summary == null || summary.toString().trim { it <= ' ' }.isEmpty()) {
summary = "%s" summary = "%s"
} }

View file

@ -0,0 +1,51 @@
package code.name.monkey.appthemehelper.common.prefs.supportv7;
import androidx.annotation.Nullable;
import androidx.fragment.app.DialogFragment;
import androidx.preference.Preference;
import androidx.preference.PreferenceFragmentCompat;
import code.name.monkey.appthemehelper.common.prefs.supportv7.dialogs.ATEListPreferenceDialogFragmentCompat;
import code.name.monkey.appthemehelper.common.prefs.supportv7.dialogs.ATEPreferenceDialogFragment;
import static androidx.preference.PreferenceFragmentCompat.*;
/**
* @author Karim Abou Zeid (kabouzeid)
*/
public abstract class ATEPreferenceFragmentCompat extends PreferenceFragmentCompat {
@Override
public void onDisplayPreferenceDialog(Preference preference) {
if (getCallbackFragment() instanceof OnPreferenceDisplayDialogCallback) {
((OnPreferenceDisplayDialogCallback) getCallbackFragment()).onPreferenceDisplayDialog(this, preference);
return;
}
if (this.getActivity() instanceof OnPreferenceDisplayDialogCallback) {
((OnPreferenceDisplayDialogCallback) this.getActivity()).onPreferenceDisplayDialog(this, preference);
return;
}
if (getFragmentManager().findFragmentByTag("androidx.preference.PreferenceFragment.DIALOG") == null) {
DialogFragment dialogFragment = onCreatePreferenceDialog(preference);
if (dialogFragment != null) {
dialogFragment.setTargetFragment(this, 0);
dialogFragment.show(this.getFragmentManager(), "androidx.preference.PreferenceFragment.DIALOG");
return;
}
}
super.onDisplayPreferenceDialog(preference);
}
@Nullable
public DialogFragment onCreatePreferenceDialog(Preference preference) {
if (preference instanceof ATEListPreference) {
return ATEListPreferenceDialogFragmentCompat.newInstance(preference.getKey());
} else if (preference instanceof ATEDialogPreference) {
return ATEPreferenceDialogFragment.newInstance(preference.getKey());
}
return null;
}
}

View file

@ -1,60 +0,0 @@
/*
* Copyright (c) 2019 Hemanth Savarala.
*
* Licensed under the GNU General Public License v3
*
* This is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by
* the Free Software Foundation either version 3 of the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*/
package code.name.monkey.appthemehelper.common.prefs.supportv7
import androidx.fragment.app.DialogFragment
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import code.name.monkey.appthemehelper.common.prefs.supportv7.dialogs.ATEListPreferenceDialogFragmentCompat
import code.name.monkey.appthemehelper.common.prefs.supportv7.dialogs.ATEPreferenceDialogFragment
/**
* @author Karim Abou Zeid (kabouzeid)
*/
abstract class ATEPreferenceFragmentCompat : PreferenceFragmentCompat() {
override fun onDisplayPreferenceDialog(preference: Preference) {
if (callbackFragment is OnPreferenceDisplayDialogCallback) {
(callbackFragment as OnPreferenceDisplayDialogCallback).onPreferenceDisplayDialog(this, preference)
return
}
if (activity is OnPreferenceDisplayDialogCallback) {
(activity as OnPreferenceDisplayDialogCallback).onPreferenceDisplayDialog(this, preference)
return
}
if (fragmentManager?.findFragmentByTag("android.support.v7.preference.PreferenceFragment.DIALOG") == null) {
val dialogFragment = onCreatePreferenceDialog(preference)
if (dialogFragment != null) {
dialogFragment.setTargetFragment(this, 0)
dialogFragment.show(fragmentManager!!, "android.support.v7.preference.PreferenceFragment.DIALOG")
return
}
}
super.onDisplayPreferenceDialog(preference)
}
open fun onCreatePreferenceDialog(preference: Preference): DialogFragment? {
if (preference is ATEListPreference) {
return ATEListPreferenceDialogFragmentCompat.newInstance(preference.getKey())
} else if (preference is ATEDialogPreference) {
return ATEPreferenceDialogFragment.newInstance(preference.getKey())
}
return null
}
}

View file

@ -14,10 +14,10 @@
package code.name.monkey.appthemehelper.common.prefs.supportv7.dialogs; package code.name.monkey.appthemehelper.common.prefs.supportv7.dialogs;
import android.content.DialogInterface;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.preference.ListPreference; import androidx.preference.ListPreference;
import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.google.android.material.dialog.MaterialAlertDialogBuilder;
@ -25,13 +25,13 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import code.name.monkey.appthemehelper.common.prefs.supportv7.ATEListPreference; import code.name.monkey.appthemehelper.common.prefs.supportv7.ATEListPreference;
/** /**
* Created by hemanths on 2019-09-03. * @author Karim Abou Zeid (kabouzeid)
*/ */
public class ATEListPreferenceDialogFragmentCompat extends ATEPreferenceDialogFragment { public class ATEListPreferenceDialogFragmentCompat extends ATEPreferenceDialogFragment {
private static final String TAG = "ATEPreferenceDialog";
private int mClickedDialogEntryIndex; private int mClickedDialogEntryIndex;
@NonNull public static ATEListPreferenceDialogFragmentCompat newInstance(String key) {
public static ATEListPreferenceDialogFragmentCompat newInstance(@NonNull String key) {
final ATEListPreferenceDialogFragmentCompat fragment = new ATEListPreferenceDialogFragmentCompat(); final ATEListPreferenceDialogFragmentCompat fragment = new ATEListPreferenceDialogFragmentCompat();
final Bundle b = new Bundle(1); final Bundle b = new Bundle(1);
b.putString(ARG_KEY, key); b.putString(ARG_KEY, key);
@ -44,7 +44,7 @@ public class ATEListPreferenceDialogFragmentCompat extends ATEPreferenceDialogFr
} }
@Override @Override
protected void onPrepareDialogBuilder(@NonNull MaterialAlertDialogBuilder builder) { protected void onPrepareDialogBuilder(MaterialAlertDialogBuilder builder) {
super.onPrepareDialogBuilder(builder); super.onPrepareDialogBuilder(builder);
final ListPreference preference = getListPreference(); final ListPreference preference = getListPreference();
@ -55,24 +55,41 @@ public class ATEListPreferenceDialogFragmentCompat extends ATEPreferenceDialogFr
} }
mClickedDialogEntryIndex = preference.findIndexOfValue(preference.getValue()); mClickedDialogEntryIndex = preference.findIndexOfValue(preference.getValue());
builder.setSingleChoiceItems(preference.getEntries(), mClickedDialogEntryIndex, (dialogInterface, i) -> { builder.setSingleChoiceItems(preference.getEntries(), mClickedDialogEntryIndex, (dialog, which) -> {
mClickedDialogEntryIndex = i; mClickedDialogEntryIndex = which;
onClick(dialog, which);
dismiss();
}); });
builder.setPositiveButton("Ok", null); /*
builder.setNegativeButton("", null); * The typical interaction for list-based dialogs is to have
builder.setNeutralButton("", null); * click-on-an-item dismiss the dialog instead of the user having to
* press 'Ok'.
*/
builder.setPositiveButton(null, null);
builder.setNegativeButton(null, null);
builder.setNeutralButton(null, null);
} }
@Override @Override
public void onDialogClosed(boolean positiveResult) { public void onDialogClosed(boolean positiveResult) {
final ListPreference preference = getListPreference(); final ListPreference preference = getListPreference();
Log.i(TAG, "onDialogClosed: " + positiveResult);
if (positiveResult && mClickedDialogEntryIndex >= 0 && if (positiveResult && mClickedDialogEntryIndex >= 0 &&
preference.getEntryValues() != null) { preference.getEntryValues() != null) {
String value = preference.getEntryValues()[mClickedDialogEntryIndex].toString(); String value = preference.getEntryValues()[mClickedDialogEntryIndex].toString();
Log.i(TAG, "onDialogClosed: value " + value);
if (preference.callChangeListener(value)) { if (preference.callChangeListener(value)) {
preference.setValue(value); preference.setValue(value);
Log.i(TAG, "onDialogClosed: set value ");
} }
} }
} }
@Override
public void onClick(DialogInterface dialog, int which) {
Log.i(TAG, "onClick: " + which);
mClickedDialogEntryIndex = which;
super.onClick(dialog, DialogInterface.BUTTON_POSITIVE);
}
} }

View file

@ -14,16 +14,17 @@
package code.name.monkey.appthemehelper.common.prefs.supportv7.dialogs; package code.name.monkey.appthemehelper.common.prefs.supportv7.dialogs;
import android.app.Dialog; import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log;
import android.view.Window; import android.view.Window;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.DialogFragment; import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.preference.DialogPreference; import androidx.preference.DialogPreference;
import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.google.android.material.dialog.MaterialAlertDialogBuilder;
@ -33,10 +34,10 @@ import code.name.monkey.appthemehelper.R;
/** /**
* @author Karim Abou Zeid (kabouzeid) * @author Karim Abou Zeid (kabouzeid)
*/ */
public class ATEPreferenceDialogFragment extends DialogFragment { public class ATEPreferenceDialogFragment extends DialogFragment implements DialogInterface.OnClickListener {
protected static final String ARG_KEY = "key";
static final String ARG_KEY = "key"; private static final String TAG = "ATEPreferenceDialog";
private int mWhichButtonClicked;
private DialogPreference mPreference; private DialogPreference mPreference;
public static ATEPreferenceDialogFragment newInstance(String key) { public static ATEPreferenceDialogFragment newInstance(String key) {
@ -59,34 +60,27 @@ public class ATEPreferenceDialogFragment extends DialogFragment {
} }
} }
public DialogPreference getPreference() {
return this.mPreference;
}
@NonNull @NonNull
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) { public Dialog onCreateDialog(Bundle savedInstanceState) {
MaterialAlertDialogBuilder materialDialog = new MaterialAlertDialogBuilder(requireActivity(), FragmentActivity context = this.getActivity();
MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(context,
R.style.ThemeOverlay_MaterialComponents_Dialog_Alert) R.style.ThemeOverlay_MaterialComponents_Dialog_Alert)
.setTitle(mPreference.getTitle()) .setTitle(this.mPreference.getDialogTitle())
.setIcon(mPreference.getIcon()) .setIcon(this.mPreference.getDialogIcon())
.setMessage(mPreference.getDialogMessage()) .setMessage(this.mPreference.getDialogMessage())
.setPositiveButton(mPreference.getPositiveButtonText(), (dialogInterface, i) -> { .setPositiveButton(this.mPreference.getPositiveButtonText(), this)
onDialogClosed(true); .setNegativeButton(this.mPreference.getNegativeButtonText(), this);
})
.setNegativeButton(mPreference.getNegativeButtonText(), (dialogInterface, i) -> {
onDialogClosed(false);
});
//this.onPrepareDialogBuilder(materialDialog); this.onPrepareDialogBuilder(builder);
AlertDialog dialog = materialDialog.create(); AlertDialog dialog = builder.create();
if (this.needInputMethod()) { if (this.needInputMethod()) {
this.requestInputMethod(dialog); this.requestInputMethod(dialog);
} }
return dialog; return dialog;
} }
public void onDialogClosed(boolean positiveResult) { public DialogPreference getPreference() {
return this.mPreference;
} }
protected void onPrepareDialogBuilder(MaterialAlertDialogBuilder builder) { protected void onPrepareDialogBuilder(MaterialAlertDialogBuilder builder) {
@ -100,4 +94,22 @@ public class ATEPreferenceDialogFragment extends DialogFragment {
Window window = dialog.getWindow(); Window window = dialog.getWindow();
window.setSoftInputMode(5); window.setSoftInputMode(5);
} }
@Override
public void onDismiss(DialogInterface dialog) {
super.onDismiss(dialog);
Log.i(TAG, "onDismiss: " + mWhichButtonClicked);
onDialogClosed(mWhichButtonClicked == DialogInterface.BUTTON_POSITIVE);
}
public void onDialogClosed(boolean positiveResult) {
}
@Override
public void onClick(DialogInterface dialog, int which) {
Log.i(TAG, "onClick: " + which);
mWhichButtonClicked = which;
onDialogClosed(which == DialogInterface.BUTTON_POSITIVE);
}
} }

View file

@ -0,0 +1,25 @@
package code.name.monkey.appthemehelper.util
import android.content.Context
import android.content.res.ColorStateList
import code.name.monkey.appthemehelper.ThemeStore
import code.name.monkey.appthemehelper.util.ATHUtil.isWindowBackgroundDark
import com.afollestad.materialdialogs.internal.ThemeSingleton
/**
* @author Karim Abou Zeid (kabouzeid)
*/
object MaterialDialogsUtil {
fun updateMaterialDialogsThemeSingleton(context: Context) {
val md = ThemeSingleton.get()
md.titleColor = ThemeStore.textColorPrimary(context)
md.contentColor = ThemeStore.textColorSecondary(context)
md.itemColor = md.titleColor
md.widgetColor = ThemeStore.accentColor(context)
md.linkColor = ColorStateList.valueOf(md.widgetColor)
md.positiveColor = ColorStateList.valueOf(md.widgetColor)
md.neutralColor = ColorStateList.valueOf(md.widgetColor)
md.negativeColor = ColorStateList.valueOf(md.widgetColor)
md.darkTheme = isWindowBackgroundDark(context)
}
}

View file

@ -1,9 +1,7 @@
package code.name.monkey.appthemehelper.util package code.name.monkey.appthemehelper.util
import android.content.res.ColorStateList import android.content.res.ColorStateList
import androidx.appcompat.widget.AppCompatButton
import code.name.monkey.appthemehelper.ThemeStore import code.name.monkey.appthemehelper.ThemeStore
import com.afollestad.materialdialogs.internal.button.DialogActionButton
import com.google.android.material.button.MaterialButton import com.google.android.material.button.MaterialButton
import com.google.android.material.textfield.TextInputLayout import com.google.android.material.textfield.TextInputLayout
@ -54,30 +52,4 @@ object MaterialUtil {
textInputLayout.isHintAnimationEnabled = true textInputLayout.isHintAnimationEnabled = true
} }
} }
@JvmOverloads
@JvmStatic
fun setTint(
button: DialogActionButton,
color: Int = ThemeStore.accentColor(button.context),
background: Boolean = true
) {
val temp = button as AppCompatButton
val context = temp.context
val colorState = ColorStateList.valueOf(color)
val textColor =
ColorStateList.valueOf(
MaterialValueHelper.getPrimaryTextColor(
context,
ColorUtil.isColorLight(color)
)
)
if (background) {
temp.backgroundTintList = colorState
temp.setTextColor(textColor)
} else {
temp.setTextColor(colorState)
}
}
} }