This commit is contained in:
Muntashir Al-Islam 2020-07-14 13:54:52 +06:00
commit 51cdc2e9eb
50 changed files with 1754 additions and 1472 deletions

View file

@ -8,23 +8,24 @@ import androidx.recyclerview.widget.DefaultItemAnimator
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import code.name.monkey.appthemehelper.util.ATHUtil
import io.github.muntashirakon.music.App
import io.github.muntashirakon.music.R
import io.github.muntashirakon.music.activities.base.AbsSlidingMusicPanelActivity
import io.github.muntashirakon.music.adapter.song.ShuffleButtonSongAdapter
import io.github.muntashirakon.music.extensions.applyToolbar
import io.github.muntashirakon.music.extensions.extraNotNull
import io.github.muntashirakon.music.helper.menu.GenreMenuHelper
import io.github.muntashirakon.music.interfaces.CabHolder
import io.github.muntashirakon.music.model.Genre
import io.github.muntashirakon.music.model.Song
import io.github.muntashirakon.music.mvp.presenter.GenreDetailsPresenter
import io.github.muntashirakon.music.mvp.presenter.GenreDetailsPresenter.GenreDetailsPresenterImpl
import io.github.muntashirakon.music.mvp.presenter.GenreDetailsView
import io.github.muntashirakon.music.providers.RepositoryImpl
import io.github.muntashirakon.music.util.DensityUtil
import io.github.muntashirakon.music.util.RetroColorUtil
import com.afollestad.materialcab.MaterialCab
import kotlinx.android.synthetic.main.activity_playlist_detail.*
import java.util.*
import javax.inject.Inject
/**
* @author Hemanth S (h4h13).
@ -32,9 +33,8 @@ import javax.inject.Inject
class GenreDetailsActivity : AbsSlidingMusicPanelActivity(), CabHolder, GenreDetailsView {
@Inject
lateinit var genreDetailsPresenter: GenreDetailsPresenter
private lateinit var genreDetailsPresenter: GenreDetailsPresenter
private lateinit var genre: Genre
private lateinit var songAdapter: ShuffleButtonSongAdapter
private var cab: MaterialCab? = null
@ -62,16 +62,14 @@ class GenreDetailsActivity : AbsSlidingMusicPanelActivity(), CabHolder, GenreDet
setTaskDescriptionColorAuto()
setLightNavigationBar(true)
setBottomBarVisibility(View.GONE)
if (intent.extras != null) {
genre = intent?.extras?.getParcelable(EXTRA_GENRE_ID)!!
} else {
finish()
}
genre = extraNotNull<Genre>(EXTRA_GENRE_ID).value
setUpToolBar()
setupRecyclerView()
App.musicComponent.inject(this)
genreDetailsPresenter =
GenreDetailsPresenterImpl(RepositoryImpl(this))
genreDetailsPresenter.attachView(this)
}

View file

@ -1,72 +1,27 @@
package io.github.muntashirakon.music.activities
import android.R.attr
import android.annotation.SuppressLint
import android.content.res.ColorStateList
import android.os.AsyncTask
import android.os.Build
import android.os.Bundle
import android.text.TextUtils
import android.view.*
import androidx.annotation.StringRes
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentStatePagerAdapter
import androidx.viewpager.widget.ViewPager
import android.view.Menu
import android.view.MenuItem
import android.view.WindowManager
import code.name.monkey.appthemehelper.ThemeStore
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 io.github.muntashirakon.music.App
import io.github.muntashirakon.music.R
import io.github.muntashirakon.music.activities.base.AbsMusicServiceActivity
import io.github.muntashirakon.music.extensions.surfaceColor
import io.github.muntashirakon.music.extensions.textColorSecondary
import io.github.muntashirakon.music.fragments.base.AbsMusicServiceFragment
import io.github.muntashirakon.music.helper.MusicPlayerRemote
import io.github.muntashirakon.music.helper.MusicProgressViewUpdateHelper
import io.github.muntashirakon.music.lyrics.LrcHelper
import io.github.muntashirakon.music.lyrics.LrcView
import io.github.muntashirakon.music.model.Song
import io.github.muntashirakon.music.model.lyrics.Lyrics
import io.github.muntashirakon.music.util.LyricUtil
import io.github.muntashirakon.music.util.MusicUtil
import io.github.muntashirakon.music.util.PreferenceUtil
import io.github.muntashirakon.music.util.RetroUtil
import kotlinx.android.synthetic.main.activity_lyrics.*
import kotlinx.android.synthetic.main.fragment_lyrics.*
import kotlinx.android.synthetic.main.fragment_synced.*
import java.io.File
class LyricsActivity : AbsMusicServiceActivity(), View.OnClickListener,
ViewPager.OnPageChangeListener {
override fun onPageScrollStateChanged(state: Int) {
when (state) {
ViewPager.SCROLL_STATE_IDLE -> fab.show()
ViewPager.SCROLL_STATE_DRAGGING,
ViewPager.SCROLL_STATE_SETTLING -> fab.hide()
}
}
class LyricsActivity : AbsMusicServiceActivity(), MusicProgressViewUpdateHelper.Callback {
private lateinit var updateHelper: MusicProgressViewUpdateHelper
override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {
}
override fun onPageSelected(position: Int) {
PreferenceUtil.lyricsOption = position
if (position == 0) fab.text = getString(R.string.synced_lyrics)
else if (position == 1) fab.text = getString(R.string.lyrics)
}
override fun onClick(v: View?) {
when (viewPager.currentItem) {
0 -> showSyncedLyrics()
1 -> showLyricsSaveDialog()
}
}
private lateinit var song: Song
private var lyricsString: String? = null
private val googleSearchLrcUrl: String
get() {
@ -84,56 +39,63 @@ class LyricsActivity : AbsMusicServiceActivity(), View.OnClickListener,
setTaskDescriptionColorAuto()
setNavigationbarColorAuto()
fab.backgroundTintList = ColorStateList.valueOf(ThemeStore.accentColor(this))
ColorStateList.valueOf(
MaterialValueHelper.getPrimaryTextColor(
this,
ColorUtil.isColorLight(ThemeStore.accentColor(this))
)
)
.apply {
fab.setTextColor(this)
fab.iconTint = this
}
setupWakelock()
viewPager.apply {
adapter = PagerAdapter(supportFragmentManager)
currentItem = PreferenceUtil.lyricsOption
addOnPageChangeListener(this@LyricsActivity)
}
toolbar.setBackgroundColor(surfaceColor())
tabs.setBackgroundColor(surfaceColor())
ToolbarContentTintHelper.colorBackButton(toolbar)
setSupportActionBar(toolbar)
tabs.setupWithViewPager(viewPager)
tabs.setSelectedTabIndicator(
TintHelper.createTintedDrawable(
ContextCompat.getDrawable(
this,
R.drawable.tab_indicator
), ThemeStore.accentColor(this)
)
)
tabs.setTabTextColors(
textColorSecondary(),
ThemeStore.accentColor(this)
)
tabs.setSelectedTabIndicatorColor(ThemeStore.accentColor(this))
fab.setOnClickListener(this)
updateHelper = MusicProgressViewUpdateHelper(this, 500, 1000)
setupLyricsView()
}
private fun setupLyricsView() {
lyricsView.apply {
setCurrentColor(ThemeStore.accentColor(context))
setTimeTextColor(ThemeStore.accentColor(context))
setTimelineColor(ThemeStore.accentColor(context))
setTimelineTextColor(ThemeStore.accentColor(context))
setDraggable(true, LrcView.OnPlayClickListener {
MusicPlayerRemote.seekTo(it.toInt())
return@OnPlayClickListener true
})
}
}
override fun onResume() {
super.onResume()
updateHelper.start()
}
override fun onPause() {
super.onPause()
updateHelper.stop()
}
override fun onUpdateProgressViews(progress: Int, total: Int) {
lyricsView.updateTime(progress.toLong())
}
private fun loadLRCLyrics() {
lyricsView.setLabel("Empty")
val song = MusicPlayerRemote.currentSong
if (LyricUtil.isLrcOriginalFileExist(song.data)) {
lyricsView.loadLrc(LyricUtil.getLocalLyricOriginalFile(song.data))
} else if (LyricUtil.isLrcFileExist(song.title, song.artistName)) {
lyricsView.loadLrc(LyricUtil.getLocalLyricFile(song.title, song.artistName))
}
}
override fun onPlayingMetaChanged() {
super.onPlayingMetaChanged()
updateTitleSong()
loadLRCLyrics()
}
override fun onServiceConnected() {
super.onServiceConnected()
updateTitleSong()
loadLRCLyrics()
}
private fun updateTitleSong() {
@ -146,269 +108,19 @@ class LyricsActivity : AbsMusicServiceActivity(), View.OnClickListener,
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
}
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
menuInflater.inflate(R.menu.menu_search, menu)
return super.onCreateOptionsMenu(menu)
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
if (item.itemId == android.R.id.home) {
finish()
return true
}
if (item.itemId == R.id.action_search) {
RetroUtil.openUrl(this, googleSearchLrcUrl)
}
return super.onOptionsItemSelected(item)
}
private fun showSyncedLyrics() {
var content = ""
try {
content = LyricUtil.getStringFromFile(song.title, song.artistName)
} catch (e: Exception) {
e.printStackTrace()
}
/*val materialDialog = MaterialDialog(this)
.show {
title(R.string.add_time_framed_lryics)
negativeButton(R.string.action_search) {
RetroUtil.openUrl(this@LyricsActivity, googleSearchLrcUrl)
}
input(
hint = getString(R.string.paste_lyrics_here),
prefill = content,
inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_FLAG_MULTI_LINE
) { _, input ->
LyricUtil.writeLrcToLoc(song.title, song.artistName, input.toString())
}
positiveButton(android.R.string.ok) {
updateSong()
}
}
MaterialUtil.setTint(materialDialog.getInputLayout(), false)*/
}
private fun updateSong() {
val page =
supportFragmentManager.findFragmentByTag("android:switcher:" + R.id.viewPager + ":" + viewPager.currentItem)
if (viewPager.currentItem == 0 && page != null) {
(page as BaseLyricsFragment).upDateSong()
}
}
private fun showLyricsSaveDialog() {
val content: String = if (lyricsString == null) {
""
} else {
lyricsString!!
}
/*val materialDialog = MaterialDialog(
this
).show {
title(R.string.add_lyrics)
negativeButton(R.string.action_search) {
RetroUtil.openUrl(this@LyricsActivity, getGoogleSearchUrl())
}
input(
hint = getString(R.string.paste_lyrics_here),
prefill = content,
inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_FLAG_MULTI_LINE
) { _, input ->
val fieldKeyValueMap = EnumMap<FieldKey, String>(FieldKey::class.java)
fieldKeyValueMap[FieldKey.LYRICS] = input.toString()
WriteTagsAsyncTask(this@LyricsActivity).execute(
WriteTagsAsyncTask.LoadingInfo(
getSongPaths(song), fieldKeyValueMap, null
)
)
}
positiveButton(android.R.string.ok) {
updateSong()
}
}
MaterialUtil.setTint(materialDialog.getInputLayout(), false)*/
}
private fun getSongPaths(song: Song): ArrayList<String> {
val paths = ArrayList<String>(1)
paths.add(song.data)
return paths
}
private fun getGoogleSearchUrl(): String {
var baseUrl = "http://www.google.com/search?"
var query = song.title + "+" + song.artistName
query = "q=" + query.replace(" ", "+") + " lyrics"
baseUrl += query
return baseUrl
}
class PagerAdapter(fm: FragmentManager) : FragmentStatePagerAdapter(
fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT
) {
class Tabs(
@StringRes val title: Int, val fragment: Fragment
)
private var tabs = ArrayList<Tabs>()
init {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
tabs.add(Tabs(R.string.synced_lyrics, SyncedLyricsFragment()))
}
tabs.add(Tabs(R.string.normal_lyrics, OfflineLyricsFragment()))
}
override fun getItem(position: Int): Fragment {
return tabs[position].fragment
}
override fun getPageTitle(position: Int): CharSequence? {
return App.getContext().getString(tabs[position].title)
}
override fun getCount(): Int {
return tabs.size
}
}
abstract class BaseLyricsFragment : AbsMusicServiceFragment() {
abstract fun upDateSong()
override fun onPlayingMetaChanged() {
super.onPlayingMetaChanged()
upDateSong()
}
override fun onServiceConnected() {
super.onServiceConnected()
upDateSong()
}
}
class OfflineLyricsFragment : BaseLyricsFragment() {
override fun upDateSong() {
loadSongLyrics()
}
private var updateLyricsAsyncTask: AsyncTask<*, *, *>? = null
private var lyrics: Lyrics? = null
@SuppressLint("StaticFieldLeak")
private fun loadSongLyrics() {
if (updateLyricsAsyncTask != null) {
updateLyricsAsyncTask!!.cancel(false)
}
val song = MusicPlayerRemote.currentSong
updateLyricsAsyncTask = object : AsyncTask<Void?, Void?, Lyrics?>() {
override fun doInBackground(vararg params: Void?): Lyrics? {
val data = MusicUtil.getLyrics(song)
return if (TextUtils.isEmpty(data)) {
null
} else Lyrics.parse(song, data!!)
}
override fun onPreExecute() {
super.onPreExecute()
lyrics = null
}
override fun onPostExecute(l: Lyrics?) {
lyrics = l
offlineLyrics?.visibility = View.VISIBLE
if (l == null) {
offlineLyrics?.setText(R.string.no_lyrics_found)
return
}
(activity as LyricsActivity).lyricsString = l.text
offlineLyrics?.text = l.text
}
override fun onCancelled(s: Lyrics?) {
onPostExecute(null)
}
}.execute()
}
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
loadSongLyrics()
}
override fun onDestroyView() {
super.onDestroyView()
if (updateLyricsAsyncTask != null && !updateLyricsAsyncTask!!.isCancelled) {
updateLyricsAsyncTask?.cancel(true)
}
}
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
): View? {
return inflater.inflate(R.layout.fragment_lyrics, container, false)
}
}
class SyncedLyricsFragment : BaseLyricsFragment(), MusicProgressViewUpdateHelper.Callback {
override fun upDateSong() {
loadLRCLyrics()
}
private lateinit var updateHelper: MusicProgressViewUpdateHelper
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
): View? {
return inflater.inflate(R.layout.fragment_synced, container, false)
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
updateHelper = MusicProgressViewUpdateHelper(this, 500, 1000)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
setupLyricsView()
}
private fun setupLyricsView() {
lyricsView.apply {
setCurrentPlayLineColor(ThemeStore.accentColor(requireContext()))
setIndicatorTextColor(ThemeStore.accentColor(requireContext()))
setCurrentIndicateLineTextColor(
resolveColor(
requireContext(),
attr.textColorPrimary
)
)
setNoLrcTextColor(resolveColor(requireContext(), attr.textColorPrimary))
setOnPlayIndicatorLineListener { time, _ -> MusicPlayerRemote.seekTo(time.toInt()) }
}
}
override fun onResume() {
super.onResume()
updateHelper.start()
}
override fun onPause() {
super.onPause()
updateHelper.stop()
}
override fun onUpdateProgressViews(progress: Int, total: Int) {
lyricsView.updateTime(progress.toLong())
}
private fun loadLRCLyrics() {
lyricsView.resetView("Empty")
val song = MusicPlayerRemote.currentSong
if (LyricUtil.isLrcFileExist(song.title, song.artistName)) {
showLyricsLocal(LyricUtil.getLocalLyricFile(song.title, song.artistName))
}
}
private fun showLyricsLocal(file: File?) {
if (file != null) {
lyricsView.setLrcData(LrcHelper.parseLrcFromFile(file))
}
}
}
}
}

View file

@ -7,13 +7,13 @@ import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import code.name.monkey.appthemehelper.util.ATHUtil
import io.github.muntashirakon.music.App
import io.github.muntashirakon.music.R
import io.github.muntashirakon.music.activities.base.AbsSlidingMusicPanelActivity
import io.github.muntashirakon.music.adapter.song.OrderablePlaylistSongAdapter
import io.github.muntashirakon.music.adapter.song.PlaylistSongAdapter
import io.github.muntashirakon.music.adapter.song.SongAdapter
import io.github.muntashirakon.music.extensions.applyToolbar
import io.github.muntashirakon.music.extensions.extraNotNull
import io.github.muntashirakon.music.helper.menu.PlaylistMenuHelper
import io.github.muntashirakon.music.interfaces.CabHolder
import io.github.muntashirakon.music.loaders.PlaylistLoader
@ -21,7 +21,9 @@ import io.github.muntashirakon.music.model.AbsCustomPlaylist
import io.github.muntashirakon.music.model.Playlist
import io.github.muntashirakon.music.model.Song
import io.github.muntashirakon.music.mvp.presenter.PlaylistSongsPresenter
import io.github.muntashirakon.music.mvp.presenter.PlaylistSongsPresenter.PlaylistSongsPresenterImpl
import io.github.muntashirakon.music.mvp.presenter.PlaylistSongsView
import io.github.muntashirakon.music.providers.RepositoryImpl
import io.github.muntashirakon.music.util.DensityUtil
import io.github.muntashirakon.music.util.PlaylistsUtil
import io.github.muntashirakon.music.util.RetroColorUtil
@ -30,13 +32,11 @@ import com.h6ah4i.android.widget.advrecyclerview.animator.RefactoredDefaultItemA
import com.h6ah4i.android.widget.advrecyclerview.draggable.RecyclerViewDragDropManager
import com.h6ah4i.android.widget.advrecyclerview.utils.WrapperAdapterUtils
import kotlinx.android.synthetic.main.activity_playlist_detail.*
import javax.inject.Inject
class PlaylistDetailActivity : AbsSlidingMusicPanelActivity(), CabHolder, PlaylistSongsView {
@Inject
lateinit var playlistSongsPresenter: PlaylistSongsPresenter
private lateinit var presenter: PlaylistSongsPresenter
private lateinit var playlist: Playlist
private var cab: MaterialCab? = null
private lateinit var adapter: SongAdapter
@ -52,14 +52,10 @@ class PlaylistDetailActivity : AbsSlidingMusicPanelActivity(), CabHolder, Playli
setLightNavigationBar(true)
setBottomBarVisibility(View.GONE)
App.musicComponent.inject(this)
playlistSongsPresenter.attachView(this)
presenter = PlaylistSongsPresenterImpl(RepositoryImpl(this))
presenter.attachView(this)
if (intent.extras != null) {
playlist = intent.extras!!.getParcelable(EXTRA_PLAYLIST)!!
} else {
finish()
}
playlist = extraNotNull<Playlist>(EXTRA_PLAYLIST).value
setUpToolBar()
setUpRecyclerView()
@ -114,7 +110,7 @@ class PlaylistDetailActivity : AbsSlidingMusicPanelActivity(), CabHolder, Playli
override fun onResume() {
super.onResume()
playlistSongsPresenter.loadPlaylistSongs(playlist)
presenter.loadPlaylistSongs(playlist)
}
private fun setUpToolBar() {
@ -181,7 +177,7 @@ class PlaylistDetailActivity : AbsSlidingMusicPanelActivity(), CabHolder, Playli
setToolbarTitle(playlist.name)
}
}
playlistSongsPresenter.loadPlaylistSongs(playlist)
presenter.loadPlaylistSongs(playlist)
}
private fun setToolbarTitle(title: String) {
@ -227,7 +223,7 @@ class PlaylistDetailActivity : AbsSlidingMusicPanelActivity(), CabHolder, Playli
wrappedAdapter = null
}
super.onDestroy()
playlistSongsPresenter.detachView()
presenter.detachView()
}
override fun showEmptyView() {

View file

@ -21,23 +21,22 @@ import code.name.monkey.appthemehelper.ThemeStore
import code.name.monkey.appthemehelper.util.ATHUtil
import code.name.monkey.appthemehelper.util.ColorUtil
import code.name.monkey.appthemehelper.util.MaterialValueHelper
import io.github.muntashirakon.music.App
import io.github.muntashirakon.music.R
import io.github.muntashirakon.music.activities.base.AbsMusicServiceActivity
import io.github.muntashirakon.music.adapter.SearchAdapter
import io.github.muntashirakon.music.mvp.presenter.SearchPresenter
import io.github.muntashirakon.music.mvp.presenter.SearchPresenter.SearchPresenterImpl
import io.github.muntashirakon.music.mvp.presenter.SearchView
import io.github.muntashirakon.music.providers.RepositoryImpl
import io.github.muntashirakon.music.util.RetroUtil
import com.google.android.material.textfield.TextInputEditText
import kotlinx.android.synthetic.main.activity_search.*
import java.util.*
import javax.inject.Inject
import kotlin.collections.ArrayList
class SearchActivity : AbsMusicServiceActivity(), OnQueryTextListener, TextWatcher, SearchView {
@Inject
lateinit var searchPresenter: SearchPresenter
private lateinit var presenter: SearchPresenter
private var searchAdapter: SearchAdapter? = null
private var query: String? = null
@ -50,8 +49,8 @@ class SearchActivity : AbsMusicServiceActivity(), OnQueryTextListener, TextWatch
setTaskDescriptionColorAuto()
setLightNavigationBar(true)
App.musicComponent.inject(this)
searchPresenter.attachView(this)
presenter = SearchPresenterImpl(RepositoryImpl(this))
presenter.attachView(this)
setupRecyclerView()
setUpToolBar()
@ -117,7 +116,7 @@ class SearchActivity : AbsMusicServiceActivity(), OnQueryTextListener, TextWatch
override fun onDestroy() {
super.onDestroy()
searchPresenter.detachView()
presenter.detachView()
}
override fun onSaveInstanceState(outState: Bundle) {
@ -134,7 +133,7 @@ class SearchActivity : AbsMusicServiceActivity(), OnQueryTextListener, TextWatch
TransitionManager.beginDelayedTransition(appBarLayout)
voiceSearch.visibility = if (query.isNotEmpty()) View.GONE else View.VISIBLE
clearText.visibility = if (query.isNotEmpty()) View.VISIBLE else View.GONE
searchPresenter.search(query)
presenter.search(query)
}
override fun onMediaStoreChanged() {
@ -176,7 +175,7 @@ class SearchActivity : AbsMusicServiceActivity(), OnQueryTextListener, TextWatch
data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS)
query = result?.get(0)
searchView.setText(query, BufferType.EDITABLE)
searchPresenter.search(query!!)
presenter.search(query!!)
}
}
}

View file

@ -63,7 +63,7 @@ class UserInfoActivity : AbsBaseActivity() {
next.setOnClickListener {
val nameString = name.text.toString().trim { it <= ' ' }
if (TextUtils.isEmpty(nameString)) {
Toast.makeText(this, "Umm name is empty", Toast.LENGTH_SHORT).show()
Toast.makeText(this, "Umm you're name can't be empty!", Toast.LENGTH_SHORT).show()
return@setOnClickListener
}
PreferenceUtil.userName = nameString