Added Permission Screen
This commit is contained in:
parent
cc494edbbf
commit
10f56e9e6d
27 changed files with 334 additions and 89 deletions
|
@ -16,7 +16,7 @@ import code.name.monkey.retromusic.helper.SearchQueryHelper.getSongs
|
|||
import code.name.monkey.retromusic.model.Song
|
||||
import code.name.monkey.retromusic.repository.PlaylistSongsLoader
|
||||
import code.name.monkey.retromusic.service.MusicService
|
||||
import code.name.monkey.retromusic.util.AppRater.appLaunched
|
||||
import code.name.monkey.retromusic.util.AppRater
|
||||
import code.name.monkey.retromusic.util.PreferenceUtil
|
||||
import kotlinx.coroutines.Dispatchers.IO
|
||||
import kotlinx.coroutines.launch
|
||||
|
@ -37,12 +37,15 @@ class MainActivity : AbsSlidingMusicPanelActivity(), OnSharedPreferenceChangeLis
|
|||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
setDrawUnderStatusBar()
|
||||
super.onCreate(savedInstanceState)
|
||||
if (!hasPermissions()) {
|
||||
findNavController(R.id.fragment_container).navigate(R.id.permissionFragment)
|
||||
}
|
||||
setStatusbarColorAuto()
|
||||
setNavigationbarColorAuto()
|
||||
setLightNavigationBar(true)
|
||||
setTaskDescriptionColorAuto()
|
||||
hideStatusBar()
|
||||
appLaunched(this)
|
||||
AppRater.appLaunched(this)
|
||||
updateTabs()
|
||||
}
|
||||
|
||||
|
@ -61,21 +64,11 @@ class MainActivity : AbsSlidingMusicPanelActivity(), OnSharedPreferenceChangeLis
|
|||
}
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
PreferenceUtil.unregisterOnSharedPreferenceChangedListener(this)
|
||||
}
|
||||
|
||||
override fun requestPermissions() {
|
||||
if (!blockRequestPermissions) {
|
||||
super.requestPermissions()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
super.onActivityResult(requestCode, resultCode, data)
|
||||
if (!hasPermissions()) {
|
||||
requestPermissions()
|
||||
//requestPermissions()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,63 @@
|
|||
package code.name.monkey.retromusic.activities
|
||||
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.provider.Settings
|
||||
import androidx.core.text.HtmlCompat
|
||||
import code.name.monkey.appthemehelper.ThemeStore
|
||||
import code.name.monkey.appthemehelper.util.VersionUtils
|
||||
import code.name.monkey.retromusic.R
|
||||
import code.name.monkey.retromusic.activities.base.AbsMusicServiceActivity
|
||||
import code.name.monkey.retromusic.extensions.accentBackgroundColor
|
||||
import code.name.monkey.retromusic.extensions.show
|
||||
import code.name.monkey.retromusic.util.RingtoneManager
|
||||
import kotlinx.android.synthetic.main.activity_permission.*
|
||||
import kotlinx.android.synthetic.main.fragment_library.appNameText
|
||||
|
||||
|
||||
class PermissionActivity : AbsMusicServiceActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView((R.layout.activity_permission))
|
||||
setStatusbarColorAuto()
|
||||
setNavigationbarColorAuto()
|
||||
setLightNavigationBar(true)
|
||||
setTaskDescriptionColorAuto()
|
||||
setupTitle()
|
||||
|
||||
storagePermission.setButtonClick {
|
||||
requestPermissions()
|
||||
}
|
||||
if (VersionUtils.hasMarshmallow()) audioPermission.show()
|
||||
audioPermission.setButtonClick {
|
||||
if (RingtoneManager.requiresDialog(this@PermissionActivity)) {
|
||||
val intent = Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS)
|
||||
intent.data = Uri.parse("package:" + applicationContext.packageName)
|
||||
startActivity(intent)
|
||||
}
|
||||
}
|
||||
finish.accentBackgroundColor()
|
||||
finish.setOnClickListener {
|
||||
if (hasPermissions() && !RingtoneManager.requiresDialog(this)) {
|
||||
startActivity(
|
||||
Intent(this, MainActivity::class.java).addFlags(
|
||||
Intent.FLAG_ACTIVITY_NEW_TASK or
|
||||
Intent.FLAG_ACTIVITY_CLEAR_TASK
|
||||
)
|
||||
)
|
||||
finish()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupTitle() {
|
||||
val color = ThemeStore.accentColor(this)
|
||||
val hexColor = String.format("#%06X", 0xFFFFFF and color)
|
||||
val appName = HtmlCompat.fromHtml(
|
||||
"Hello there! <br>Welcome to <b>Retro <span style='color:$hexColor';>Music</span></b>",
|
||||
HtmlCompat.FROM_HTML_MODE_COMPACT
|
||||
)
|
||||
appNameText.text = appName
|
||||
}
|
||||
}
|
|
@ -46,7 +46,7 @@ abstract class AbsBaseActivity : AbsThemeActivity() {
|
|||
override fun onPostCreate(savedInstanceState: Bundle?) {
|
||||
super.onPostCreate(savedInstanceState)
|
||||
if (!hasPermissions()) {
|
||||
requestPermissions()
|
||||
//requestPermissions()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -178,6 +178,7 @@ abstract class AbsSlidingMusicPanelActivity : AbsMusicServiceActivity() {
|
|||
behavior.isHideable = true
|
||||
behavior.peekHeight = 0
|
||||
collapsePanel()
|
||||
ViewCompat.setElevation(slidingPanel, 0f)
|
||||
ViewCompat.setElevation(bottomNavigationView, 10f)
|
||||
} else {
|
||||
ViewCompat.setElevation(bottomNavigationView, 10f)
|
||||
|
|
|
@ -170,6 +170,7 @@ open class AlbumAdapter(
|
|||
if (isInQuickSelectMode) {
|
||||
toggleChecked(layoutPosition)
|
||||
} else {
|
||||
println(dataSet[layoutPosition].id)
|
||||
image?.let { albumClickListener?.onAlbumClick(dataSet[layoutPosition].id, it) }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,6 +49,7 @@ fun Int.ripAlpha(): Int {
|
|||
}
|
||||
|
||||
fun Dialog.colorControlNormal() = resolveColor(android.R.attr.colorControlNormal)
|
||||
|
||||
fun Toolbar.backgroundTintList() {
|
||||
val surfaceColor = ATHUtil.resolveColor(context, R.attr.colorSurface, Color.BLACK)
|
||||
val colorStateList = ColorStateList.valueOf(surfaceColor)
|
||||
|
@ -84,7 +85,6 @@ fun Fragment.resolveColor(@AttrRes attr: Int, fallBackColor: Int = 0) =
|
|||
fun Dialog.resolveColor(@AttrRes attr: Int, fallBackColor: Int = 0) =
|
||||
ATHUtil.resolveColor(context, attr, fallBackColor)
|
||||
|
||||
|
||||
fun CheckBox.addAccentColor() {
|
||||
buttonTintList = ColorStateList.valueOf(ThemeStore.accentColor(context))
|
||||
}
|
||||
|
@ -103,6 +103,19 @@ fun MaterialButton.accentTextColor() {
|
|||
setTextColor(ThemeStore.accentColor(App.getContext()))
|
||||
}
|
||||
|
||||
fun MaterialButton.accentBackgroundColor() {
|
||||
backgroundTintList = ColorStateList.valueOf(ThemeStore.accentColor(App.getContext()))
|
||||
}
|
||||
|
||||
fun MaterialButton.accentOutlineColor() {
|
||||
val color = ThemeStore.accentColor(context)
|
||||
val colorStateList = ColorStateList.valueOf(color)
|
||||
iconTint = colorStateList
|
||||
strokeColor = colorStateList
|
||||
setTextColor(colorStateList)
|
||||
rippleColor = colorStateList
|
||||
}
|
||||
|
||||
fun SeekBar.applyColor(@ColorInt color: Int) {
|
||||
thumbTintList = ColorStateList.valueOf(color)
|
||||
progressTintList = ColorStateList.valueOf(color)
|
||||
|
|
|
@ -74,6 +74,7 @@ class LibraryViewModel(
|
|||
}
|
||||
|
||||
fun getHome(): LiveData<List<Home>> {
|
||||
fetchHomeSections()
|
||||
return home
|
||||
}
|
||||
|
||||
|
|
|
@ -79,6 +79,7 @@ class AlbumDetailsFragment : AbsMainActivityFragment(R.layout.fragment_album_det
|
|||
toolbar.title = " "
|
||||
postponeEnterTransition()
|
||||
detailsViewModel.getAlbum().observe(viewLifecycleOwner, Observer {
|
||||
println(Thread.currentThread().name)
|
||||
startPostponedEnterTransition()
|
||||
showAlbum(it)
|
||||
})
|
||||
|
|
|
@ -12,23 +12,23 @@ import code.name.monkey.retromusic.repository.RealRepository
|
|||
import kotlinx.coroutines.Dispatchers.IO
|
||||
|
||||
class AlbumDetailsViewModel(
|
||||
private val realRepository: RealRepository,
|
||||
private val repository: RealRepository,
|
||||
private val albumId: Int
|
||||
) : ViewModel(), MusicServiceEventListener {
|
||||
|
||||
fun getAlbum(): LiveData<Album> = liveData(IO) {
|
||||
val album = realRepository.albumByIdAsync(albumId)
|
||||
val album = repository.albumByIdAsync(albumId)
|
||||
emit(album)
|
||||
}
|
||||
|
||||
fun getArtist(artistId: Int): LiveData<Artist> = liveData(IO) {
|
||||
val artist = realRepository.artistById(artistId)
|
||||
val artist = repository.artistById(artistId)
|
||||
emit(artist)
|
||||
}
|
||||
|
||||
fun getAlbumInfo(album: Album): LiveData<Result<LastFmAlbum>> = liveData {
|
||||
emit(Result.Loading)
|
||||
emit( realRepository.albumInfo(album.artistName ?: "-", album.title ?: "-"))
|
||||
emit(repository.albumInfo(album.artistName ?: "-", album.title ?: "-"))
|
||||
}
|
||||
|
||||
fun getMoreAlbums(artist: Artist): LiveData<List<Album>> = liveData(IO) {
|
||||
|
|
|
@ -78,8 +78,7 @@ abstract class AbsRecyclerViewFragment<A : RecyclerView.Adapter<*>, LM : Recycle
|
|||
return String(Character.toChars(unicode))
|
||||
}
|
||||
|
||||
private fun checkIsEmpty() {
|
||||
emptyEmoji.text = getEmojiByUnicode(0x1F631)
|
||||
private fun checkIsEmpty() {
|
||||
emptyText.setText(emptyMessage)
|
||||
empty.visibility = if (adapter!!.itemCount == 0) View.VISIBLE else View.GONE
|
||||
}
|
||||
|
|
|
@ -114,15 +114,10 @@ class PlaylistDetailsFragment : AbsMainActivityFragment(R.layout.fragment_playli
|
|||
|
||||
private fun checkIsEmpty() {
|
||||
checkForPadding()
|
||||
emptyEmoji.text = getEmojiByUnicode(0x1F631)
|
||||
empty.visibility = if (adapter.itemCount == 0) View.VISIBLE else View.GONE
|
||||
emptyText.visibility = if (adapter.itemCount == 0) View.VISIBLE else View.GONE
|
||||
}
|
||||
|
||||
private fun getEmojiByUnicode(unicode: Int): String {
|
||||
return String(Character.toChars(unicode))
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
if (recyclerViewDragDropManager != null) {
|
||||
recyclerViewDragDropManager!!.cancelDrag()
|
||||
|
|
|
@ -60,13 +60,12 @@ class RealAlbumRepository(private val songRepository: RealSongRepository) :
|
|||
}
|
||||
|
||||
override fun album(albumId: Int): Album {
|
||||
val songs = songRepository.songs(
|
||||
songRepository.makeSongCursor(
|
||||
AudioColumns.ALBUM_ID + "=?",
|
||||
arrayOf(albumId.toString()),
|
||||
getSongLoaderSortOrder()
|
||||
)
|
||||
val cursor = songRepository.makeSongCursor(
|
||||
AudioColumns.ALBUM_ID + "=?",
|
||||
arrayOf(albumId.toString()),
|
||||
getSongLoaderSortOrder()
|
||||
)
|
||||
val songs = songRepository.songs(cursor)
|
||||
val album = Album(ArrayList(songs))
|
||||
sortAlbumSongs(album)
|
||||
return album
|
||||
|
|
|
@ -18,12 +18,10 @@ import android.content.Context
|
|||
import android.database.Cursor
|
||||
import android.provider.MediaStore
|
||||
import android.provider.MediaStore.Audio.AudioColumns
|
||||
import code.name.monkey.appthemehelper.util.VersionUtils
|
||||
import code.name.monkey.retromusic.Constants.IS_MUSIC
|
||||
import code.name.monkey.retromusic.Constants.baseProjection
|
||||
import code.name.monkey.retromusic.model.Song
|
||||
import code.name.monkey.retromusic.providers.BlacklistStore
|
||||
|
||||
import code.name.monkey.retromusic.util.PreferenceUtil
|
||||
import java.util.*
|
||||
|
||||
|
@ -124,6 +122,7 @@ class RealSongRepository(private val context: Context) : SongRepository {
|
|||
|
||||
@JvmOverloads
|
||||
fun makeSongCursor(
|
||||
|
||||
selection: String?,
|
||||
selectionValues: Array<String>?,
|
||||
sortOrder: String = PreferenceUtil.songSortOrder
|
||||
|
@ -139,34 +138,22 @@ class RealSongRepository(private val context: Context) : SongRepository {
|
|||
// Blacklist
|
||||
val paths = BlacklistStore.getInstance(context).paths
|
||||
if (paths.isNotEmpty()) {
|
||||
selectionFinal =
|
||||
generateBlacklistSelection(
|
||||
selectionFinal,
|
||||
paths.size
|
||||
)
|
||||
selectionValuesFinal =
|
||||
addBlacklistSelectionValues(
|
||||
selectionValuesFinal,
|
||||
paths
|
||||
)
|
||||
selectionFinal = generateBlacklistSelection(selectionFinal, paths.size)
|
||||
selectionValuesFinal = addBlacklistSelectionValues(selectionValuesFinal, paths)
|
||||
}
|
||||
selectionFinal =
|
||||
selectionFinal + " AND " + MediaStore.Audio.Media.DURATION + ">= " + (PreferenceUtil.filterLength * 1000)
|
||||
|
||||
|
||||
val uri = if (VersionUtils.hasQ()) {
|
||||
MediaStore.Audio.Media.getContentUri(MediaStore.VOLUME_EXTERNAL)
|
||||
} else {
|
||||
MediaStore.Audio.Media.EXTERNAL_CONTENT_URI
|
||||
try {
|
||||
return context.contentResolver.query(
|
||||
MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
|
||||
baseProjection,
|
||||
selectionFinal,
|
||||
selectionValuesFinal,
|
||||
sortOrder
|
||||
)
|
||||
} catch (e: SecurityException) {
|
||||
return null
|
||||
}
|
||||
|
||||
return context.contentResolver.query(
|
||||
uri,
|
||||
baseProjection,
|
||||
selectionFinal,
|
||||
selectionValuesFinal,
|
||||
sortOrder
|
||||
)
|
||||
}
|
||||
|
||||
private fun generateBlacklistSelection(
|
||||
|
|
|
@ -74,7 +74,7 @@ class RingtoneManager(val context: Context) {
|
|||
}
|
||||
|
||||
fun getDialog(context: Context): AlertDialog {
|
||||
return MaterialAlertDialogBuilder(context)
|
||||
return MaterialAlertDialogBuilder(context, R.style.MaterialAlertDialogTheme)
|
||||
.setTitle(R.string.dialog_title_set_ringtone)
|
||||
.setMessage(R.string.dialog_message_set_ringtone)
|
||||
.setPositiveButton(android.R.string.ok) { _, _ ->
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
package code.name.monkey.retromusic.views
|
||||
|
||||
import android.content.Context
|
||||
import android.content.res.ColorStateList
|
||||
import android.util.AttributeSet
|
||||
import android.widget.FrameLayout
|
||||
import code.name.monkey.appthemehelper.ThemeStore
|
||||
import code.name.monkey.appthemehelper.util.ColorUtil
|
||||
import code.name.monkey.retromusic.R
|
||||
import code.name.monkey.retromusic.extensions.accentOutlineColor
|
||||
import kotlinx.android.synthetic.main.item_permission.view.*
|
||||
|
||||
class PermissionItem @JvmOverloads constructor(
|
||||
context: Context,
|
||||
attrs: AttributeSet? = null,
|
||||
defStyleAttr: Int = -1,
|
||||
defStyleRes: Int = -1
|
||||
) : FrameLayout(context, attrs, defStyleAttr, defStyleRes) {
|
||||
init {
|
||||
val attributes = context.obtainStyledAttributes(attrs, R.styleable.PermissionItem, 0, 0)
|
||||
inflate(context, R.layout.item_permission, this)
|
||||
|
||||
title.text = attributes.getText(R.styleable.PermissionItem_permissionTitle)
|
||||
summary.text = attributes.getText(R.styleable.PermissionItem_permissionTitleSubTitle)
|
||||
number.text = attributes.getText(R.styleable.PermissionItem_permissionTitleNumber)
|
||||
button.text = attributes.getText(R.styleable.PermissionItem_permissionButtonTitle)
|
||||
button.setIconResource(
|
||||
attributes.getResourceId(
|
||||
R.styleable.PermissionItem_permissionIcon,
|
||||
R.drawable.ic_album
|
||||
)
|
||||
)
|
||||
val color = ThemeStore.accentColor(context)
|
||||
number.backgroundTintList = ColorStateList.valueOf(ColorUtil.withAlpha(color, 0.22f))
|
||||
|
||||
button.accentOutlineColor()
|
||||
attributes.recycle()
|
||||
}
|
||||
|
||||
fun setButtonClick(callBack: () -> Unit) {
|
||||
button.setOnClickListener { callBack.invoke() }
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue