Fix error background
This commit is contained in:
parent
19d30f247e
commit
58bd6ad447
3 changed files with 348 additions and 334 deletions
|
@ -2,40 +2,28 @@ package code.name.monkey.retromusic.activities
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.content.res.ColorStateList
|
import android.content.res.ColorStateList
|
||||||
import android.os.AsyncTask
|
import android.os.*
|
||||||
import android.os.Build
|
import android.text.*
|
||||||
import android.os.Bundle
|
|
||||||
import android.text.InputType
|
|
||||||
import android.text.TextUtils
|
|
||||||
import android.view.*
|
import android.view.*
|
||||||
import androidx.annotation.StringRes
|
import androidx.annotation.StringRes
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.*
|
||||||
import androidx.fragment.app.FragmentManager
|
|
||||||
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.*
|
||||||
import code.name.monkey.retromusic.App
|
import code.name.monkey.retromusic.*
|
||||||
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.activities.tageditor.WriteTagsAsyncTask
|
||||||
import code.name.monkey.retromusic.fragments.base.AbsMusicServiceFragment
|
import code.name.monkey.retromusic.fragments.base.AbsMusicServiceFragment
|
||||||
import code.name.monkey.retromusic.helper.MusicPlayerRemote
|
import code.name.monkey.retromusic.helper.*
|
||||||
import code.name.monkey.retromusic.helper.MusicProgressViewUpdateHelper
|
import code.name.monkey.retromusic.lyrics.*
|
||||||
import code.name.monkey.retromusic.lyrics.LrcHelper
|
|
||||||
import code.name.monkey.retromusic.lyrics.LrcView
|
|
||||||
import code.name.monkey.retromusic.model.Song
|
import code.name.monkey.retromusic.model.Song
|
||||||
import code.name.monkey.retromusic.model.lyrics.Lyrics
|
import code.name.monkey.retromusic.model.lyrics.Lyrics
|
||||||
import code.name.monkey.retromusic.util.LyricUtil
|
import code.name.monkey.retromusic.util.*
|
||||||
import code.name.monkey.retromusic.util.MusicUtil
|
import com.afollestad.materialdialogs.*
|
||||||
import code.name.monkey.retromusic.util.PreferenceUtil
|
|
||||||
import code.name.monkey.retromusic.util.RetroUtil
|
|
||||||
import com.afollestad.materialdialogs.LayoutMode
|
|
||||||
import com.afollestad.materialdialogs.MaterialDialog
|
|
||||||
import com.afollestad.materialdialogs.bottomsheets.BottomSheet
|
import com.afollestad.materialdialogs.bottomsheets.BottomSheet
|
||||||
import com.afollestad.materialdialogs.input.getInputLayout
|
import com.afollestad.materialdialogs.input.*
|
||||||
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.*
|
||||||
|
@ -45,365 +33,393 @@ import java.util.*
|
||||||
import kotlin.collections.ArrayList
|
import kotlin.collections.ArrayList
|
||||||
|
|
||||||
class LyricsActivity : AbsMusicServiceActivity(), View.OnClickListener, ViewPager.OnPageChangeListener {
|
class LyricsActivity : AbsMusicServiceActivity(), View.OnClickListener, ViewPager.OnPageChangeListener {
|
||||||
override fun onPageScrollStateChanged(state: Int) {
|
override fun onPageScrollStateChanged(state: Int) {
|
||||||
when (state) {
|
when (state) {
|
||||||
ViewPager.SCROLL_STATE_IDLE ->
|
ViewPager.SCROLL_STATE_IDLE -> fab.show()
|
||||||
fab.show()
|
ViewPager.SCROLL_STATE_DRAGGING, ViewPager.SCROLL_STATE_SETTLING -> fab.hide()
|
||||||
ViewPager.SCROLL_STATE_DRAGGING,
|
}
|
||||||
ViewPager.SCROLL_STATE_SETTLING ->
|
}
|
||||||
fab.hide()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {
|
override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPageSelected(position: Int) {
|
override fun onPageSelected(position: Int) {
|
||||||
PreferenceUtil.getInstance(this).lyricsOptions = position
|
PreferenceUtil.getInstance(this).lyricsOptions = position
|
||||||
if (position == 0) fab.text = getString(R.string.synced_lyrics)
|
if (position == 0) fab.text = getString(R.string.synced_lyrics)
|
||||||
else if (position == 1) fab.text = getString(R.string.lyrics)
|
else if (position == 1) fab.text = getString(R.string.lyrics)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onClick(v: View?) {
|
override fun onClick(v: View?) {
|
||||||
when (viewPager.currentItem) {
|
when (viewPager.currentItem) {
|
||||||
0 -> showSyncedLyrics()
|
0 -> showSyncedLyrics()
|
||||||
1 -> showLyricsSaveDialog()
|
1 -> showLyricsSaveDialog()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private lateinit var song: Song
|
private lateinit var song: Song
|
||||||
private var lyricsString: String? = null
|
private var lyricsString: String? = null
|
||||||
|
|
||||||
private val googleSearchLrcUrl: String
|
private val googleSearchLrcUrl: String
|
||||||
get() {
|
get() {
|
||||||
var baseUrl = "http://www.google.com/search?"
|
var baseUrl = "http://www.google.com/search?"
|
||||||
var query = song.title + "+" + song.artistName
|
var query = song.title + "+" + song.artistName
|
||||||
query = "q=" + query.replace(" ", "+") + " .lrc"
|
query = "q=" + query.replace(" ", "+") + " .lrc"
|
||||||
baseUrl += query
|
baseUrl += query
|
||||||
return baseUrl
|
return baseUrl
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContentView(R.layout.activity_lyrics)
|
setContentView(R.layout.activity_lyrics)
|
||||||
|
|
||||||
setStatusbarColorAuto()
|
setStatusbarColorAuto()
|
||||||
setTaskDescriptionColorAuto()
|
setTaskDescriptionColorAuto()
|
||||||
setNavigationBarColorPrimary()
|
setNavigationBarColorPrimary()
|
||||||
|
|
||||||
val primaryColor = ATHUtil.resolveColor(this, R.attr.colorPrimary)
|
val primaryColor = ATHUtil.resolveColor(this, R.attr.colorPrimary)
|
||||||
appBarLayout.setBackgroundColor(primaryColor)
|
appBarLayout.setBackgroundColor(primaryColor)
|
||||||
toolbar.apply {
|
toolbar.apply {
|
||||||
setBackgroundColor(primaryColor)
|
setBackgroundColor(primaryColor)
|
||||||
navigationIcon = TintHelper.createTintedDrawable(
|
navigationIcon = TintHelper.createTintedDrawable(
|
||||||
ContextCompat.getDrawable(
|
ContextCompat.getDrawable(
|
||||||
this@LyricsActivity,
|
this@LyricsActivity, R.drawable.ic_keyboard_backspace_black_24dp
|
||||||
R.drawable.ic_keyboard_backspace_black_24dp
|
), ThemeStore.textColorSecondary(this@LyricsActivity)
|
||||||
),
|
)
|
||||||
ThemeStore.textColorSecondary(this@LyricsActivity)
|
setSupportActionBar(toolbar)
|
||||||
)
|
}
|
||||||
setSupportActionBar(toolbar)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
fab.backgroundTintList = ColorStateList.valueOf(ThemeStore.accentColor(this))
|
fab.backgroundTintList = ColorStateList.valueOf(ThemeStore.accentColor(this))
|
||||||
ColorStateList.valueOf(MaterialValueHelper.getPrimaryTextColor(this, ColorUtil.isColorLight(ThemeStore.accentColor(this)))).apply {
|
ColorStateList.valueOf(
|
||||||
fab.setTextColor(this)
|
MaterialValueHelper.getPrimaryTextColor(
|
||||||
fab.iconTint = this
|
this, ColorUtil.isColorLight(
|
||||||
}
|
ThemeStore.accentColor(
|
||||||
setupWakelock()
|
this
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
).apply {
|
||||||
|
fab.setTextColor(this)
|
||||||
|
fab.iconTint = this
|
||||||
|
}
|
||||||
|
setupWakelock()
|
||||||
|
|
||||||
viewPager.apply {
|
viewPager.apply {
|
||||||
adapter = PagerAdapter(supportFragmentManager)
|
adapter = PagerAdapter(supportFragmentManager)
|
||||||
currentItem = PreferenceUtil.getInstance(this@LyricsActivity).lyricsOptions
|
currentItem = PreferenceUtil.getInstance(this@LyricsActivity).lyricsOptions
|
||||||
addOnPageChangeListener(this@LyricsActivity)
|
addOnPageChangeListener(this@LyricsActivity)
|
||||||
}
|
}
|
||||||
|
|
||||||
tabs.apply {
|
tabs.apply {
|
||||||
setupWithViewPager(viewPager)
|
setupWithViewPager(viewPager)
|
||||||
setSelectedTabIndicator(TintHelper.createTintedDrawable(ContextCompat.getDrawable(this@LyricsActivity, R.drawable.tab_indicator), ThemeStore.accentColor(this@LyricsActivity)))
|
setSelectedTabIndicator(
|
||||||
setTabTextColors(ThemeStore.textColorSecondary(this@LyricsActivity), ThemeStore.accentColor(this@LyricsActivity))
|
TintHelper.createTintedDrawable(
|
||||||
setSelectedTabIndicatorColor(ThemeStore.accentColor(context))
|
ContextCompat.getDrawable(
|
||||||
}
|
this@LyricsActivity, R.drawable.tab_indicator
|
||||||
fab.setOnClickListener(this)
|
), ThemeStore.accentColor(this@LyricsActivity)
|
||||||
}
|
)
|
||||||
|
)
|
||||||
|
setTabTextColors(
|
||||||
|
ThemeStore.textColorSecondary(this@LyricsActivity),
|
||||||
|
ThemeStore.accentColor(this@LyricsActivity)
|
||||||
|
)
|
||||||
|
setSelectedTabIndicatorColor(ThemeStore.accentColor(context))
|
||||||
|
}
|
||||||
|
fab.setOnClickListener(this)
|
||||||
|
}
|
||||||
|
|
||||||
override fun onPlayingMetaChanged() {
|
override fun onPlayingMetaChanged() {
|
||||||
super.onPlayingMetaChanged()
|
super.onPlayingMetaChanged()
|
||||||
song = MusicPlayerRemote.currentSong
|
song = MusicPlayerRemote.currentSong
|
||||||
toolbar.title = song.title
|
toolbar.title = song.title
|
||||||
toolbar.subtitle = song.artistName
|
toolbar.subtitle = song.artistName
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onServiceConnected() {
|
override fun onServiceConnected() {
|
||||||
super.onServiceConnected()
|
super.onServiceConnected()
|
||||||
song = MusicPlayerRemote.currentSong
|
song = MusicPlayerRemote.currentSong
|
||||||
toolbar.title = song.title
|
toolbar.title = song.title
|
||||||
toolbar.subtitle = song.artistName
|
toolbar.subtitle = song.artistName
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupWakelock() {
|
private fun setupWakelock() {
|
||||||
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||||
if (item.itemId == android.R.id.home) {
|
if (item.itemId == android.R.id.home) {
|
||||||
onBackPressed()
|
onBackPressed()
|
||||||
}
|
}
|
||||||
return super.onOptionsItemSelected(item)
|
return super.onOptionsItemSelected(item)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun showSyncedLyrics() {
|
private fun showSyncedLyrics() {
|
||||||
var content = ""
|
var content = ""
|
||||||
try {
|
try {
|
||||||
content = LyricUtil.getStringFromFile(song.data, song.artistName)
|
content = LyricUtil.getStringFromFile(song.data, song.artistName)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
try {
|
try {
|
||||||
content = LyricUtil.getStringFromFile(song.title, song.artistName)
|
content = LyricUtil.getStringFromFile(song.title, song.artistName)
|
||||||
} catch (e2: Exception) {
|
} catch (e2: Exception) {
|
||||||
|
|
||||||
}
|
}
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
}
|
}
|
||||||
|
|
||||||
val materialDialog = MaterialDialog(
|
val materialDialog = MaterialDialog(
|
||||||
this,
|
this, BottomSheet(LayoutMode.WRAP_CONTENT)
|
||||||
BottomSheet(LayoutMode.WRAP_CONTENT)
|
).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) { RetroUtil.openUrl(this@LyricsActivity, googleSearchLrcUrl) }
|
RetroUtil.openUrl(
|
||||||
input(
|
this@LyricsActivity, googleSearchLrcUrl
|
||||||
hint = getString(R.string.paste_lyrics_here),
|
)
|
||||||
prefill = content,
|
}
|
||||||
inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_FLAG_MULTI_LINE
|
input(
|
||||||
) { _, input ->
|
hint = getString(R.string.paste_lyrics_here),
|
||||||
LyricUtil.writeLrcToLoc(song.data, song.artistName, input.toString())
|
prefill = content,
|
||||||
}
|
inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_FLAG_MULTI_LINE
|
||||||
positiveButton(android.R.string.ok) {
|
) { _, input ->
|
||||||
updateSong()
|
LyricUtil.writeLrcToLoc(song.data, song.artistName, input.toString())
|
||||||
}
|
}
|
||||||
}
|
positiveButton(android.R.string.ok) {
|
||||||
MaterialUtil.setTint(materialDialog.getInputLayout(), false)
|
updateSong()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
MaterialUtil.setTint(materialDialog.getInputLayout(), false)
|
||||||
|
}
|
||||||
|
|
||||||
private fun updateSong() {
|
private fun updateSong() {
|
||||||
val page = supportFragmentManager.findFragmentByTag("android:switcher:" + R.id.viewPager + ":" + viewPager.currentItem)
|
val page = supportFragmentManager.findFragmentByTag("android:switcher:" + R.id.viewPager + ":" + viewPager.currentItem)
|
||||||
if (viewPager.currentItem == 0 && page != null) {
|
if (viewPager.currentItem == 0 && page != null) {
|
||||||
(page as BaseLyricsFragment).upDateSong()
|
(page as BaseLyricsFragment).upDateSong()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun showLyricsSaveDialog() {
|
private fun showLyricsSaveDialog() {
|
||||||
val content: String = if (lyricsString == null) {
|
val content: String = if (lyricsString == null) {
|
||||||
""
|
""
|
||||||
} else {
|
} else {
|
||||||
lyricsString!!
|
lyricsString!!
|
||||||
}
|
}
|
||||||
|
|
||||||
val materialDialog = MaterialDialog(
|
val materialDialog = MaterialDialog(
|
||||||
this, BottomSheet(LayoutMode.WRAP_CONTENT)
|
this, BottomSheet(LayoutMode.WRAP_CONTENT)
|
||||||
).show {
|
).show {
|
||||||
title(R.string.add_lyrics)
|
title(R.string.add_lyrics)
|
||||||
negativeButton(R.string.action_search) { RetroUtil.openUrl(this@LyricsActivity, getGoogleSearchUrl()) }
|
negativeButton(R.string.action_search) {
|
||||||
input(
|
RetroUtil.openUrl(
|
||||||
hint = getString(R.string.paste_lyrics_here),
|
this@LyricsActivity, getGoogleSearchUrl()
|
||||||
prefill = content,
|
)
|
||||||
inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_FLAG_MULTI_LINE
|
}
|
||||||
) { _, input ->
|
input(
|
||||||
val fieldKeyValueMap = EnumMap<FieldKey, String>(FieldKey::class.java)
|
hint = getString(R.string.paste_lyrics_here),
|
||||||
fieldKeyValueMap[FieldKey.LYRICS] = input.toString()
|
prefill = content,
|
||||||
WriteTagsAsyncTask(this@LyricsActivity).execute(WriteTagsAsyncTask.LoadingInfo(getSongPaths(song), fieldKeyValueMap, null))
|
inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_FLAG_MULTI_LINE
|
||||||
}
|
) { _, input ->
|
||||||
positiveButton(android.R.string.ok) {
|
val fieldKeyValueMap = EnumMap<FieldKey, String>(FieldKey::class.java)
|
||||||
updateSong()
|
fieldKeyValueMap[FieldKey.LYRICS] = input.toString()
|
||||||
}
|
WriteTagsAsyncTask(this@LyricsActivity).execute(
|
||||||
}
|
WriteTagsAsyncTask.LoadingInfo(
|
||||||
MaterialUtil.setTint(materialDialog.getInputLayout(), false)
|
getSongPaths(song), fieldKeyValueMap, null
|
||||||
}
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
positiveButton(android.R.string.ok) {
|
||||||
|
updateSong()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
MaterialUtil.setTint(materialDialog.getInputLayout(), false)
|
||||||
|
}
|
||||||
|
|
||||||
private fun getSongPaths(song: Song): ArrayList<String> {
|
private fun getSongPaths(song: Song): ArrayList<String> {
|
||||||
val paths = ArrayList<String>(1)
|
val paths = ArrayList<String>(1)
|
||||||
paths.add(song.data)
|
paths.add(song.data)
|
||||||
return paths
|
return paths
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getGoogleSearchUrl(): String {
|
private fun getGoogleSearchUrl(): String {
|
||||||
var baseUrl = "http://www.google.com/search?"
|
var baseUrl = "http://www.google.com/search?"
|
||||||
var query = song.title + "+" + song.artistName
|
var query = song.title + "+" + song.artistName
|
||||||
query = "q=" + query.replace(" ", "+") + " lyrics"
|
query = "q=" + query.replace(" ", "+") + " lyrics"
|
||||||
baseUrl += query
|
baseUrl += query
|
||||||
return baseUrl
|
return baseUrl
|
||||||
}
|
}
|
||||||
|
|
||||||
class PagerAdapter(fm: FragmentManager) : FragmentStatePagerAdapter(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) {
|
class PagerAdapter(fm: FragmentManager) : FragmentStatePagerAdapter(
|
||||||
class Tabs(
|
fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT
|
||||||
@StringRes val title: Int,
|
) {
|
||||||
val fragment: Fragment
|
class Tabs(
|
||||||
)
|
@StringRes val title: Int, val fragment: Fragment
|
||||||
|
)
|
||||||
|
|
||||||
private var tabs = ArrayList<Tabs>()
|
private var tabs = ArrayList<Tabs>()
|
||||||
|
|
||||||
init {
|
init {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
|
||||||
tabs.add(Tabs(R.string.synced_lyrics, SyncedLyricsFragment()))
|
tabs.add(Tabs(R.string.synced_lyrics, SyncedLyricsFragment()))
|
||||||
}
|
}
|
||||||
tabs.add(Tabs(R.string.normal_lyrics, OfflineLyricsFragment()))
|
tabs.add(Tabs(R.string.normal_lyrics, OfflineLyricsFragment()))
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getItem(position: Int): Fragment {
|
override fun getItem(position: Int): Fragment {
|
||||||
return tabs[position].fragment
|
return tabs[position].fragment
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getPageTitle(position: Int): CharSequence? {
|
override fun getPageTitle(position: Int): CharSequence? {
|
||||||
return App.getContext().getString(tabs[position].title)
|
return App.getContext().getString(tabs[position].title)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getCount(): Int {
|
override fun getCount(): Int {
|
||||||
return tabs.size
|
return tabs.size
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class BaseLyricsFragment : AbsMusicServiceFragment() {
|
abstract class BaseLyricsFragment : AbsMusicServiceFragment() {
|
||||||
abstract fun upDateSong()
|
abstract fun upDateSong()
|
||||||
|
|
||||||
override fun onPlayingMetaChanged() {
|
override fun onPlayingMetaChanged() {
|
||||||
super.onPlayingMetaChanged()
|
super.onPlayingMetaChanged()
|
||||||
upDateSong()
|
upDateSong()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onServiceConnected() {
|
override fun onServiceConnected() {
|
||||||
super.onServiceConnected()
|
super.onServiceConnected()
|
||||||
upDateSong()
|
upDateSong()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class OfflineLyricsFragment : BaseLyricsFragment() {
|
class OfflineLyricsFragment : BaseLyricsFragment() {
|
||||||
override fun upDateSong() {
|
override fun upDateSong() {
|
||||||
loadSongLyrics()
|
loadSongLyrics()
|
||||||
}
|
}
|
||||||
|
|
||||||
private var updateLyricsAsyncTask: AsyncTask<*, *, *>? = null
|
private var updateLyricsAsyncTask: AsyncTask<*, *, *>? = null
|
||||||
private var lyrics: Lyrics? = null
|
private var lyrics: Lyrics? = null
|
||||||
|
|
||||||
@SuppressLint("StaticFieldLeak")
|
@SuppressLint("StaticFieldLeak")
|
||||||
private fun loadSongLyrics() {
|
private fun loadSongLyrics() {
|
||||||
if (updateLyricsAsyncTask != null) {
|
if (updateLyricsAsyncTask != null) {
|
||||||
updateLyricsAsyncTask!!.cancel(false)
|
updateLyricsAsyncTask!!.cancel(false)
|
||||||
}
|
}
|
||||||
val song = MusicPlayerRemote.currentSong
|
val song = MusicPlayerRemote.currentSong
|
||||||
updateLyricsAsyncTask = object : AsyncTask<Void?, Void?, Lyrics?>() {
|
updateLyricsAsyncTask = object : AsyncTask<Void?, Void?, Lyrics?>() {
|
||||||
override fun doInBackground(vararg params: Void?): Lyrics? {
|
override fun doInBackground(vararg params: Void?): Lyrics? {
|
||||||
val data = MusicUtil.getLyrics(song)
|
val data = MusicUtil.getLyrics(song)
|
||||||
return if (TextUtils.isEmpty(data)) {
|
return if (TextUtils.isEmpty(data)) {
|
||||||
null
|
null
|
||||||
} else Lyrics.parse(song, data!!)
|
} else Lyrics.parse(song, data!!)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPreExecute() {
|
override fun onPreExecute() {
|
||||||
super.onPreExecute()
|
super.onPreExecute()
|
||||||
lyrics = null
|
lyrics = null
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPostExecute(l: Lyrics?) {
|
override fun onPostExecute(l: Lyrics?) {
|
||||||
lyrics = l
|
lyrics = l
|
||||||
offlineLyrics?.visibility = View.VISIBLE
|
offlineLyrics?.visibility = View.VISIBLE
|
||||||
if (l == null) {
|
if (l == null) {
|
||||||
offlineLyrics?.setText(R.string.no_lyrics_found)
|
offlineLyrics?.setText(R.string.no_lyrics_found)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
(activity as LyricsActivity).lyricsString = l.text
|
(activity as LyricsActivity).lyricsString = l.text
|
||||||
offlineLyrics?.text = l.text
|
offlineLyrics?.text = l.text
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCancelled(s: Lyrics?) {
|
override fun onCancelled(s: Lyrics?) {
|
||||||
onPostExecute(null)
|
onPostExecute(null)
|
||||||
}
|
}
|
||||||
}.execute()
|
}.execute()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
||||||
super.onActivityCreated(savedInstanceState)
|
super.onActivityCreated(savedInstanceState)
|
||||||
loadSongLyrics()
|
loadSongLyrics()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroyView() {
|
override fun onDestroyView() {
|
||||||
super.onDestroyView()
|
super.onDestroyView()
|
||||||
if (updateLyricsAsyncTask != null && !updateLyricsAsyncTask!!.isCancelled) {
|
if (updateLyricsAsyncTask != null && !updateLyricsAsyncTask!!.isCancelled) {
|
||||||
updateLyricsAsyncTask!!.cancel(true)
|
updateLyricsAsyncTask?.cancel(true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
override fun onCreateView(
|
||||||
return inflater.inflate(R.layout.fragment_lyrics, container, false)
|
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
|
||||||
}
|
): View? {
|
||||||
}
|
return inflater.inflate(R.layout.fragment_lyrics, container, false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class SyncedLyricsFragment : BaseLyricsFragment(), MusicProgressViewUpdateHelper.Callback {
|
class SyncedLyricsFragment : BaseLyricsFragment(), MusicProgressViewUpdateHelper.Callback {
|
||||||
override fun upDateSong() {
|
override fun upDateSong() {
|
||||||
loadLRCLyrics()
|
loadLRCLyrics()
|
||||||
}
|
}
|
||||||
|
|
||||||
private lateinit var updateHelper: MusicProgressViewUpdateHelper
|
private lateinit var updateHelper: MusicProgressViewUpdateHelper
|
||||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
override fun onCreateView(
|
||||||
return inflater.inflate(R.layout.fragment_synced, container, false)
|
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
|
||||||
}
|
): View? {
|
||||||
|
return inflater.inflate(R.layout.fragment_synced, container, false)
|
||||||
|
}
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
updateHelper = MusicProgressViewUpdateHelper(this, 500, 1000)
|
updateHelper = MusicProgressViewUpdateHelper(this, 500, 1000)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
setupLyricsView()
|
setupLyricsView()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupLyricsView() {
|
private fun setupLyricsView() {
|
||||||
lyricsView.apply {
|
lyricsView.apply {
|
||||||
val context = activity!!
|
val context = activity!!
|
||||||
setCurrentPlayLineColor(ThemeStore.accentColor(context))
|
setCurrentPlayLineColor(ThemeStore.accentColor(context))
|
||||||
setIndicatorTextColor(ThemeStore.accentColor(context))
|
setIndicatorTextColor(ThemeStore.accentColor(context))
|
||||||
setCurrentIndicateLineTextColor(ThemeStore.textColorPrimary(context))
|
setCurrentIndicateLineTextColor(ThemeStore.textColorPrimary(context))
|
||||||
setNoLrcTextColor(ThemeStore.textColorPrimary(context))
|
setNoLrcTextColor(ThemeStore.textColorPrimary(context))
|
||||||
setOnPlayIndicatorLineListener(object : LrcView.OnPlayIndicatorLineListener {
|
setOnPlayIndicatorLineListener(object : LrcView.OnPlayIndicatorLineListener {
|
||||||
override fun onPlay(time: Long, content: String) {
|
override fun onPlay(time: Long, content: String) {
|
||||||
MusicPlayerRemote.seekTo(time.toInt())
|
MusicPlayerRemote.seekTo(time.toInt())
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
updateHelper.start()
|
updateHelper.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPause() {
|
override fun onPause() {
|
||||||
super.onPause()
|
super.onPause()
|
||||||
updateHelper.stop()
|
updateHelper.stop()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onUpdateProgressViews(progress: Int, total: Int) {
|
override fun onUpdateProgressViews(progress: Int, total: Int) {
|
||||||
lyricsView.updateTime(progress.toLong())
|
lyricsView.updateTime(progress.toLong())
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun loadLRCLyrics() {
|
private fun loadLRCLyrics() {
|
||||||
val song = MusicPlayerRemote.currentSong
|
val song = MusicPlayerRemote.currentSong
|
||||||
if (LyricUtil.isLrcFile2Exist(song.data, song.artistName)) {
|
if (LyricUtil.isLrcFile2Exist(song.data, song.artistName)) {
|
||||||
showLyricsLocal(LyricUtil.getLocalLyricFile(song.data, song.artistName))
|
showLyricsLocal(LyricUtil.getLocalLyricFile(song.data, song.artistName))
|
||||||
} else {
|
} else {
|
||||||
if (LyricUtil.isLrcFileExist(song.title, song.artistName)) {
|
if (LyricUtil.isLrcFileExist(song.title, song.artistName)) {
|
||||||
showLyricsLocal(LyricUtil.getLocalLyricFile(song.title, song.artistName))
|
showLyricsLocal(LyricUtil.getLocalLyricFile(song.title, song.artistName))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun showLyricsLocal(file: File?) {
|
private fun showLyricsLocal(file: File?) {
|
||||||
if (file != null) {
|
if (file != null) {
|
||||||
lyricsView.setLrcData(LrcHelper.parseLrcFromFile(file))
|
lyricsView.setLrcData(LrcHelper.parseLrcFromFile(file))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,6 @@ package code.name.monkey.retromusic.util;
|
||||||
|
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Base64;
|
import android.util.Base64;
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
|
@ -101,7 +100,6 @@ public class LyricUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getLrcPath2(String title, String artist) {
|
public static String getLrcPath2(String title, String artist) {
|
||||||
Log.i("HEM", "getLrcPath2: " + title);
|
|
||||||
if (!TextUtils.isEmpty(title)) {
|
if (!TextUtils.isEmpty(title)) {
|
||||||
String x2;
|
String x2;
|
||||||
if (title.endsWith(".flac") || title.endsWith(".mogg") || title.endsWith(".alac") || title.endsWith(".aiff") || title.endsWith(".webv")) {
|
if (title.endsWith(".flac") || title.endsWith(".mogg") || title.endsWith(".alac") || title.endsWith(".aiff") || title.endsWith(".webv")) {
|
||||||
|
|
|
@ -26,8 +26,7 @@
|
||||||
|
|
||||||
<item name="toolbarPopupTheme">@style/ThemeOverlay.AppCompat</item>
|
<item name="toolbarPopupTheme">@style/ThemeOverlay.AppCompat</item>
|
||||||
|
|
||||||
<!-- just in case-->
|
|
||||||
<item name="android:windowBackground">@color/md_red_500</item>
|
|
||||||
|
|
||||||
<!-- necessary to find the overflow button later in the layout-->
|
<!-- necessary to find the overflow button later in the layout-->
|
||||||
<item name="android:actionOverflowButtonStyle">@style/Widget.ActionButton.Overflow</item>
|
<item name="android:actionOverflowButtonStyle">@style/Widget.ActionButton.Overflow</item>
|
||||||
|
@ -49,8 +48,9 @@
|
||||||
<item name="colorOnSecondary">@color/mi_text_color_secondary_dark</item>
|
<item name="colorOnSecondary">@color/mi_text_color_secondary_dark</item>
|
||||||
|
|
||||||
<item name="colorAccent">@color/md_deep_purple_A200</item>
|
<item name="colorAccent">@color/md_deep_purple_A200</item>
|
||||||
|
<!-- just in case-->
|
||||||
<item name="android:colorBackground">@color/md_red_500</item>
|
<item name="android:windowBackground">@color/darkColorBackground</item>
|
||||||
|
<item name="android:colorBackground">@color/darkColorBackground</item>
|
||||||
<item name="colorSurface">@color/darkColorSurface</item>
|
<item name="colorSurface">@color/darkColorSurface</item>
|
||||||
<item name="colorOnSurface">@color/mi_text_color_primary_dark</item>
|
<item name="colorOnSurface">@color/mi_text_color_primary_dark</item>
|
||||||
<item name="colorOnBackground">@color/mi_text_color_secondary_dark</item>
|
<item name="colorOnBackground">@color/mi_text_color_secondary_dark</item>
|
||||||
|
|
Loading…
Reference in a new issue