WIP theme
This commit is contained in:
parent
bb72a16b84
commit
9f1e6cb98e
87 changed files with 1694 additions and 1697 deletions
|
@ -4,10 +4,12 @@ import android.content.Intent
|
|||
import android.content.pm.PackageManager
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.view.*
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import androidx.core.app.ShareCompat
|
||||
import androidx.recyclerview.widget.*
|
||||
import code.name.monkey.appthemehelper.util.*
|
||||
import androidx.recyclerview.widget.DefaultItemAnimator
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import code.name.monkey.appthemehelper.util.ToolbarContentTintHelper
|
||||
import code.name.monkey.retromusic.Constants.APP_INSTAGRAM_LINK
|
||||
import code.name.monkey.retromusic.Constants.APP_TELEGRAM_LINK
|
||||
import code.name.monkey.retromusic.Constants.APP_TWITTER_LINK
|
||||
|
@ -20,9 +22,12 @@ import code.name.monkey.retromusic.Constants.TRANSLATE
|
|||
import code.name.monkey.retromusic.R
|
||||
import code.name.monkey.retromusic.activities.base.AbsBaseActivity
|
||||
import code.name.monkey.retromusic.adapter.ContributorAdapter
|
||||
import code.name.monkey.retromusic.extensions.surfaceColor
|
||||
import code.name.monkey.retromusic.model.Contributor
|
||||
import code.name.monkey.retromusic.util.*
|
||||
import com.afollestad.materialdialogs.*
|
||||
import code.name.monkey.retromusic.util.NavigationUtil
|
||||
import code.name.monkey.retromusic.util.PreferenceUtil
|
||||
import com.afollestad.materialdialogs.LayoutMode
|
||||
import com.afollestad.materialdialogs.MaterialDialog
|
||||
import com.afollestad.materialdialogs.bottomsheets.BottomSheet
|
||||
import com.afollestad.materialdialogs.list.listItems
|
||||
import com.google.gson.Gson
|
||||
|
@ -62,11 +67,11 @@ class AboutActivity : AbsBaseActivity(), View.OnClickListener {
|
|||
setNavigationBarColorPrimary()
|
||||
setLightNavigationBar(true)
|
||||
|
||||
|
||||
loadContributors()
|
||||
setSupportActionBar(toolbar)
|
||||
toolbar.apply {
|
||||
setTitleTextColor(ATHUtil.resolveColor(this@AboutActivity, R.attr.colorOnPrimary))
|
||||
setBackgroundColor(ATHUtil.resolveColor(this@AboutActivity, R.attr.colorPrimary))
|
||||
setBackgroundColor(surfaceColor(context))
|
||||
setNavigationOnClickListener { onBackPressed() }
|
||||
ToolbarContentTintHelper.colorBackButton(toolbar)
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@ package code.name.monkey.retromusic.activities
|
|||
|
||||
import android.app.ActivityOptions
|
||||
import android.content.Intent
|
||||
import android.graphics.Color
|
||||
import android.os.Bundle
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
|
@ -15,7 +14,7 @@ import androidx.recyclerview.widget.GridLayoutManager
|
|||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
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.MaterialUtil
|
||||
import code.name.monkey.retromusic.App
|
||||
import code.name.monkey.retromusic.R
|
||||
import code.name.monkey.retromusic.activities.base.AbsSlidingMusicPanelActivity
|
||||
|
@ -44,6 +43,7 @@ import com.afollestad.materialcab.MaterialCab
|
|||
import com.bumptech.glide.Glide
|
||||
import kotlinx.android.synthetic.main.activity_album.*
|
||||
import kotlinx.android.synthetic.main.activity_album_content.*
|
||||
import kotlinx.android.synthetic.main.status_bar.*
|
||||
import java.util.*
|
||||
import javax.inject.Inject
|
||||
import android.util.Pair as UtilPair
|
||||
|
@ -80,11 +80,10 @@ class AlbumDetailsActivity : AbsSlidingMusicPanelActivity(), AlbumDetailsView, C
|
|||
setDrawUnderStatusBar()
|
||||
super.onCreate(savedInstanceState)
|
||||
toggleBottomNavigationView(true)
|
||||
setStatusbarColor(Color.TRANSPARENT)
|
||||
setStatusbarColorAuto()
|
||||
setNavigationbarColorAuto()
|
||||
setTaskDescriptionColorAuto()
|
||||
setLightNavigationBar(true)
|
||||
setLightStatusbar(ColorUtil.isColorLight(ATHUtil.resolveColor(this, R.attr.colorPrimary)))
|
||||
|
||||
ActivityCompat.postponeEnterTransition(this)
|
||||
|
||||
|
@ -191,18 +190,20 @@ class AlbumDetailsActivity : AbsSlidingMusicPanelActivity(), AlbumDetailsView, C
|
|||
val themeColor = if (PreferenceUtil.getInstance(this).adaptiveColor) color
|
||||
else ThemeStore.accentColor(this)
|
||||
|
||||
songTitle.setTextColor(ThemeStore.accentColor(this))
|
||||
moreTitle.setTextColor(ThemeStore.accentColor(this))
|
||||
songTitle.setTextColor(themeColor)
|
||||
moreTitle.setTextColor(themeColor)
|
||||
|
||||
val buttonColor = if (PreferenceUtil.getInstance(this).adaptiveColor)
|
||||
color
|
||||
else
|
||||
ATHUtil.resolveColor(this, R.attr.cardBackgroundColor)
|
||||
ATHUtil.resolveColor(this, R.attr.colorControlNormal)
|
||||
|
||||
//MaterialUtil.setTint(button = shuffleAction, color = buttonColor)
|
||||
//MaterialUtil.setTint(button = playAction, color = buttonColor)
|
||||
MaterialUtil.setTint(button = shuffleAction, color = buttonColor)
|
||||
MaterialUtil.setTint(button = playAction, color = buttonColor)
|
||||
|
||||
toolbar.setBackgroundColor(ATHUtil.resolveColor(this, R.attr.colorPrimary))
|
||||
val toolbarColor = ATHUtil.resolveColor(this, R.attr.colorSurface)
|
||||
status_bar.setBackgroundColor(toolbarColor)
|
||||
toolbar.setBackgroundColor(toolbarColor)
|
||||
setSupportActionBar(toolbar)
|
||||
supportActionBar?.title = null
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@ package code.name.monkey.retromusic.activities
|
|||
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.graphics.Color
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.text.Html
|
||||
|
@ -17,7 +16,6 @@ import androidx.recyclerview.widget.GridLayoutManager
|
|||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
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.MaterialUtil
|
||||
import code.name.monkey.retromusic.App
|
||||
import code.name.monkey.retromusic.R
|
||||
|
@ -39,6 +37,7 @@ import com.afollestad.materialcab.MaterialCab
|
|||
import com.bumptech.glide.Glide
|
||||
import kotlinx.android.synthetic.main.activity_artist_content.*
|
||||
import kotlinx.android.synthetic.main.activity_artist_details.*
|
||||
import kotlinx.android.synthetic.main.status_bar.*
|
||||
import java.util.*
|
||||
import javax.inject.Inject
|
||||
import kotlin.collections.ArrayList
|
||||
|
@ -74,11 +73,10 @@ class ArtistDetailActivity : AbsSlidingMusicPanelActivity(), ArtistDetailsView,
|
|||
setDrawUnderStatusBar()
|
||||
super.onCreate(savedInstanceState)
|
||||
toggleBottomNavigationView(true)
|
||||
setStatusbarColor(Color.TRANSPARENT)
|
||||
setStatusbarColorAuto()
|
||||
setNavigationbarColorAuto()
|
||||
setTaskDescriptionColorAuto()
|
||||
setLightNavigationBar(true)
|
||||
setLightStatusbar(ColorUtil.isColorLight(ATHUtil.resolveColor(this, R.attr.colorPrimary)))
|
||||
|
||||
ActivityCompat.postponeEnterTransition(this)
|
||||
|
||||
|
@ -240,7 +238,10 @@ class ArtistDetailActivity : AbsSlidingMusicPanelActivity(), ArtistDetailsView,
|
|||
MaterialUtil.setTint(button = shuffleAction, color = buttonColor)
|
||||
MaterialUtil.setTint(button = playAction, color = buttonColor)
|
||||
|
||||
toolbar.setBackgroundColor(ATHUtil.resolveColor(this, R.attr.colorPrimary))
|
||||
|
||||
val toolbarColor = ATHUtil.resolveColor(this, R.attr.colorSurface)
|
||||
status_bar.setBackgroundColor(toolbarColor)
|
||||
toolbar.setBackgroundColor(toolbarColor)
|
||||
setSupportActionBar(toolbar)
|
||||
supportActionBar?.title = null
|
||||
}
|
||||
|
|
|
@ -1,19 +1,25 @@
|
|||
package code.name.monkey.retromusic.activities
|
||||
|
||||
import android.graphics.Color
|
||||
import android.os.Bundle
|
||||
import android.view.*
|
||||
import androidx.recyclerview.widget.*
|
||||
import code.name.monkey.appthemehelper.util.*
|
||||
import code.name.monkey.retromusic.*
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import androidx.recyclerview.widget.DefaultItemAnimator
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import code.name.monkey.appthemehelper.util.ATHUtil
|
||||
import code.name.monkey.retromusic.App
|
||||
import code.name.monkey.retromusic.R
|
||||
import code.name.monkey.retromusic.activities.base.AbsSlidingMusicPanelActivity
|
||||
import code.name.monkey.retromusic.adapter.song.ShuffleButtonSongAdapter
|
||||
import code.name.monkey.retromusic.extensions.applyToolbar
|
||||
import code.name.monkey.retromusic.helper.menu.GenreMenuHelper
|
||||
import code.name.monkey.retromusic.interfaces.CabHolder
|
||||
import code.name.monkey.retromusic.model.*
|
||||
import code.name.monkey.retromusic.mvp.presenter.*
|
||||
import code.name.monkey.retromusic.util.*
|
||||
import code.name.monkey.retromusic.model.Genre
|
||||
import code.name.monkey.retromusic.model.Song
|
||||
import code.name.monkey.retromusic.mvp.presenter.GenreDetailsPresenter
|
||||
import code.name.monkey.retromusic.mvp.presenter.GenreDetailsView
|
||||
import code.name.monkey.retromusic.util.RetroColorUtil
|
||||
import code.name.monkey.retromusic.util.ViewUtil
|
||||
import com.afollestad.materialcab.MaterialCab
|
||||
import kotlinx.android.synthetic.main.activity_playlist_detail.*
|
||||
|
@ -26,127 +32,123 @@ import javax.inject.Inject
|
|||
|
||||
class GenreDetailsActivity : AbsSlidingMusicPanelActivity(), CabHolder, GenreDetailsView {
|
||||
|
||||
@Inject
|
||||
lateinit var genreDetailsPresenter: GenreDetailsPresenter
|
||||
@Inject
|
||||
lateinit var genreDetailsPresenter: GenreDetailsPresenter
|
||||
|
||||
private lateinit var genre: Genre
|
||||
private lateinit var songAdapter: ShuffleButtonSongAdapter
|
||||
private var cab: MaterialCab? = null
|
||||
private lateinit var genre: Genre
|
||||
private lateinit var songAdapter: ShuffleButtonSongAdapter
|
||||
private var cab: MaterialCab? = null
|
||||
|
||||
private fun checkIsEmpty() {
|
||||
empty?.visibility = if (songAdapter.itemCount == 0) View.VISIBLE else View.GONE
|
||||
}
|
||||
private fun checkIsEmpty() {
|
||||
empty?.visibility = if (songAdapter.itemCount == 0) View.VISIBLE else View.GONE
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
setDrawUnderStatusBar()
|
||||
super.onCreate(savedInstanceState)
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
setDrawUnderStatusBar()
|
||||
super.onCreate(savedInstanceState)
|
||||
setStatusbarColorAuto()
|
||||
setNavigationbarColorAuto()
|
||||
setTaskDescriptionColorAuto()
|
||||
setLightNavigationBar(true)
|
||||
toggleBottomNavigationView(true)
|
||||
|
||||
setStatusbarColor(Color.TRANSPARENT)
|
||||
setNavigationbarColorAuto()
|
||||
setTaskDescriptionColorAuto()
|
||||
setLightNavigationBar(true)
|
||||
setLightStatusbar(ColorUtil.isColorLight(ATHUtil.resolveColor(this, R.attr.colorPrimary)))
|
||||
toggleBottomNavigationView(true)
|
||||
if (intent.extras != null) {
|
||||
genre = intent?.extras?.getParcelable(EXTRA_GENRE_ID)!!
|
||||
} else {
|
||||
finish()
|
||||
}
|
||||
|
||||
if (intent.extras != null) {
|
||||
genre = intent?.extras?.getParcelable(EXTRA_GENRE_ID)!!
|
||||
} else {
|
||||
finish()
|
||||
}
|
||||
setUpToolBar()
|
||||
setupRecyclerView()
|
||||
|
||||
setUpToolBar()
|
||||
setupRecyclerView()
|
||||
App.musicComponent.inject(this)
|
||||
genreDetailsPresenter.attachView(this)
|
||||
|
||||
App.musicComponent.inject(this)
|
||||
genreDetailsPresenter.attachView(this)
|
||||
}
|
||||
|
||||
}
|
||||
private fun setUpToolBar() {
|
||||
applyToolbar(toolbar)
|
||||
title = genre.name
|
||||
}
|
||||
|
||||
private fun setUpToolBar() {
|
||||
val primaryColor = ATHUtil.resolveColor(this, R.attr.colorPrimary)
|
||||
appBarLayout.setBackgroundColor(primaryColor)
|
||||
applyToolbar(toolbar)
|
||||
title = genre.name
|
||||
}
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
genreDetailsPresenter.loadGenreSongs(genre.id)
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
genreDetailsPresenter.loadGenreSongs(genre.id)
|
||||
}
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
genreDetailsPresenter.detachView()
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
genreDetailsPresenter.detachView()
|
||||
}
|
||||
override fun createContentView(): View {
|
||||
return wrapSlidingMusicPanel(R.layout.activity_playlist_detail)
|
||||
}
|
||||
|
||||
override fun createContentView(): View {
|
||||
return wrapSlidingMusicPanel(R.layout.activity_playlist_detail)
|
||||
}
|
||||
override fun showEmptyView() {
|
||||
|
||||
override fun showEmptyView() {
|
||||
}
|
||||
|
||||
}
|
||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||
menuInflater.inflate(R.menu.menu_genre_detail, menu)
|
||||
return super.onCreateOptionsMenu(menu)
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||
menuInflater.inflate(R.menu.menu_genre_detail, menu)
|
||||
return super.onCreateOptionsMenu(menu)
|
||||
}
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
if (item.itemId == android.R.id.home) {
|
||||
onBackPressed()
|
||||
}
|
||||
return GenreMenuHelper.handleMenuClick(this, genre, item)
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
if (item.itemId == android.R.id.home) {
|
||||
onBackPressed()
|
||||
}
|
||||
return GenreMenuHelper.handleMenuClick(this, genre, item)
|
||||
}
|
||||
private fun setupRecyclerView() {
|
||||
ViewUtil.setUpFastScrollRecyclerViewColor(this, recyclerView)
|
||||
songAdapter = ShuffleButtonSongAdapter(this, ArrayList(), R.layout.item_list, false, this)
|
||||
recyclerView.apply {
|
||||
itemAnimator = DefaultItemAnimator()
|
||||
layoutManager = LinearLayoutManager(this@GenreDetailsActivity)
|
||||
adapter = songAdapter
|
||||
}
|
||||
songAdapter.registerAdapterDataObserver(object : RecyclerView.AdapterDataObserver() {
|
||||
override fun onChanged() {
|
||||
super.onChanged()
|
||||
checkIsEmpty()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private fun setupRecyclerView() {
|
||||
ViewUtil.setUpFastScrollRecyclerViewColor(this, recyclerView)
|
||||
songAdapter = ShuffleButtonSongAdapter(this, ArrayList(), R.layout.item_list, false, this)
|
||||
recyclerView.apply {
|
||||
itemAnimator = DefaultItemAnimator()
|
||||
layoutManager = LinearLayoutManager(this@GenreDetailsActivity)
|
||||
adapter = songAdapter
|
||||
}
|
||||
songAdapter.registerAdapterDataObserver(object : RecyclerView.AdapterDataObserver() {
|
||||
override fun onChanged() {
|
||||
super.onChanged()
|
||||
checkIsEmpty()
|
||||
}
|
||||
})
|
||||
}
|
||||
override fun songs(songs: ArrayList<Song>) {
|
||||
songAdapter.swapDataSet(songs)
|
||||
}
|
||||
|
||||
override fun songs(songs: ArrayList<Song>) {
|
||||
songAdapter.swapDataSet(songs)
|
||||
}
|
||||
override fun openCab(menuRes: Int, callback: MaterialCab.Callback): MaterialCab {
|
||||
if (cab != null && cab!!.isActive) cab!!.finish()
|
||||
cab = MaterialCab(this, R.id.cab_stub).setMenu(menuRes)
|
||||
.setCloseDrawableRes(R.drawable.ic_close_white_24dp).setBackgroundColor(
|
||||
RetroColorUtil.shiftBackgroundColorForLightText(
|
||||
ATHUtil.resolveColor(
|
||||
this,
|
||||
R.attr.colorPrimary
|
||||
)
|
||||
)
|
||||
).start(callback)
|
||||
return cab!!
|
||||
}
|
||||
|
||||
override fun openCab(menuRes: Int, callback: MaterialCab.Callback): MaterialCab {
|
||||
if (cab != null && cab!!.isActive) cab!!.finish()
|
||||
cab = MaterialCab(this, R.id.cab_stub).setMenu(menuRes)
|
||||
.setCloseDrawableRes(R.drawable.ic_close_white_24dp).setBackgroundColor(
|
||||
RetroColorUtil.shiftBackgroundColorForLightText(
|
||||
ATHUtil.resolveColor(
|
||||
this,
|
||||
R.attr.colorPrimary
|
||||
)
|
||||
)
|
||||
).start(callback)
|
||||
return cab!!
|
||||
}
|
||||
override fun onBackPressed() {
|
||||
if (cab != null && cab!!.isActive) cab!!.finish()
|
||||
else {
|
||||
recyclerView!!.stopScroll()
|
||||
super.onBackPressed()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onBackPressed() {
|
||||
if (cab != null && cab!!.isActive) cab!!.finish()
|
||||
else {
|
||||
recyclerView!!.stopScroll()
|
||||
super.onBackPressed()
|
||||
}
|
||||
}
|
||||
override fun onMediaStoreChanged() {
|
||||
super.onMediaStoreChanged()
|
||||
genreDetailsPresenter.loadGenreSongs(genre.id)
|
||||
}
|
||||
|
||||
override fun onMediaStoreChanged() {
|
||||
super.onMediaStoreChanged()
|
||||
genreDetailsPresenter.loadGenreSongs(genre.id)
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val EXTRA_GENRE_ID = "extra_genre_id"
|
||||
}
|
||||
companion object {
|
||||
const val EXTRA_GENRE_ID = "extra_genre_id"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -65,7 +65,7 @@ public class LicenseActivity extends AbsBaseActivity {
|
|||
Toolbar toolbar = findViewById(R.id.toolbar);
|
||||
setSupportActionBar(toolbar);
|
||||
ToolbarContentTintHelper.colorBackButton(toolbar);
|
||||
toolbar.setBackgroundColor(INSTANCE.resolveColor(this, R.attr.colorPrimary));
|
||||
toolbar.setBackgroundColor(INSTANCE.resolveColor(this, R.attr.colorSurface));
|
||||
WebView webView = findViewById(R.id.license);
|
||||
try {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
|
@ -78,7 +78,7 @@ public class LicenseActivity extends AbsBaseActivity {
|
|||
|
||||
// Inject color values for WebView body background and links
|
||||
final boolean isDark = INSTANCE.isWindowBackgroundDark(this);
|
||||
final String backgroundColor = colorToCSS(INSTANCE.resolveColor(this, R.attr.colorPrimary, Color.parseColor(isDark ? "#424242" : "#ffffff")));
|
||||
final String backgroundColor = colorToCSS(INSTANCE.resolveColor(this, android.R.attr.windowBackground, Color.parseColor(isDark ? "#424242" : "#ffffff")));
|
||||
final String contentColor = colorToCSS(Color.parseColor(isDark ? "#ffffff" : "#000000"));
|
||||
final String changeLog = buf.toString()
|
||||
.replace("{style-placeholder}",
|
||||
|
|
|
@ -2,28 +2,44 @@ package code.name.monkey.retromusic.activities
|
|||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.res.ColorStateList
|
||||
import android.os.*
|
||||
import android.text.*
|
||||
import android.os.AsyncTask
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.text.InputType
|
||||
import android.text.TextUtils
|
||||
import android.view.*
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.fragment.app.*
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.FragmentManager
|
||||
import androidx.fragment.app.FragmentStatePagerAdapter
|
||||
import androidx.viewpager.widget.ViewPager
|
||||
import code.name.monkey.appthemehelper.ThemeStore
|
||||
import code.name.monkey.appthemehelper.util.*
|
||||
import code.name.monkey.retromusic.*
|
||||
import code.name.monkey.appthemehelper.util.ColorUtil
|
||||
import code.name.monkey.appthemehelper.util.MaterialUtil
|
||||
import code.name.monkey.appthemehelper.util.MaterialValueHelper
|
||||
import code.name.monkey.appthemehelper.util.TintHelper
|
||||
import code.name.monkey.retromusic.App
|
||||
import code.name.monkey.retromusic.R
|
||||
import code.name.monkey.retromusic.activities.base.AbsMusicServiceActivity
|
||||
import code.name.monkey.retromusic.activities.tageditor.WriteTagsAsyncTask
|
||||
import code.name.monkey.retromusic.extensions.applyToolbar
|
||||
import code.name.monkey.retromusic.fragments.base.AbsMusicServiceFragment
|
||||
import code.name.monkey.retromusic.helper.*
|
||||
import code.name.monkey.retromusic.lyrics.*
|
||||
import code.name.monkey.retromusic.helper.MusicPlayerRemote
|
||||
import code.name.monkey.retromusic.helper.MusicProgressViewUpdateHelper
|
||||
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.lyrics.Lyrics
|
||||
import code.name.monkey.retromusic.util.*
|
||||
import com.afollestad.materialdialogs.*
|
||||
import code.name.monkey.retromusic.util.LyricUtil
|
||||
import code.name.monkey.retromusic.util.MusicUtil
|
||||
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.input.*
|
||||
import com.afollestad.materialdialogs.input.getInputLayout
|
||||
import com.afollestad.materialdialogs.input.input
|
||||
import kotlinx.android.synthetic.main.activity_lyrics.*
|
||||
import kotlinx.android.synthetic.main.fragment_lyrics.*
|
||||
import kotlinx.android.synthetic.main.fragment_synced.*
|
||||
|
@ -33,393 +49,373 @@ import java.util.*
|
|||
import kotlin.collections.ArrayList
|
||||
|
||||
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()
|
||||
}
|
||||
}
|
||||
override fun onPageScrollStateChanged(state: Int) {
|
||||
when (state) {
|
||||
ViewPager.SCROLL_STATE_IDLE -> fab.show()
|
||||
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) {
|
||||
PreferenceUtil.getInstance(this).lyricsOptions = position
|
||||
if (position == 0) fab.text = getString(R.string.synced_lyrics)
|
||||
else if (position == 1) fab.text = getString(R.string.lyrics)
|
||||
}
|
||||
override fun onPageSelected(position: Int) {
|
||||
PreferenceUtil.getInstance(this).lyricsOptions = 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()
|
||||
}
|
||||
}
|
||||
override fun onClick(v: View?) {
|
||||
when (viewPager.currentItem) {
|
||||
0 -> showSyncedLyrics()
|
||||
1 -> showLyricsSaveDialog()
|
||||
}
|
||||
}
|
||||
|
||||
private lateinit var song: Song
|
||||
private var lyricsString: String? = null
|
||||
private lateinit var song: Song
|
||||
private var lyricsString: String? = null
|
||||
|
||||
private val googleSearchLrcUrl: String
|
||||
get() {
|
||||
var baseUrl = "http://www.google.com/search?"
|
||||
var query = song.title + "+" + song.artistName
|
||||
query = "q=" + query.replace(" ", "+") + " .lrc"
|
||||
baseUrl += query
|
||||
return baseUrl
|
||||
}
|
||||
private val googleSearchLrcUrl: String
|
||||
get() {
|
||||
var baseUrl = "http://www.google.com/search?"
|
||||
var query = song.title + "+" + song.artistName
|
||||
query = "q=" + query.replace(" ", "+") + " .lrc"
|
||||
baseUrl += query
|
||||
return baseUrl
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_lyrics)
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_lyrics)
|
||||
setStatusbarColorAuto()
|
||||
setTaskDescriptionColorAuto()
|
||||
setNavigationBarColorPrimary()
|
||||
|
||||
setStatusbarColorAuto()
|
||||
setTaskDescriptionColorAuto()
|
||||
setNavigationBarColorPrimary()
|
||||
applyToolbar(toolbar)
|
||||
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()
|
||||
|
||||
val primaryColor = ATHUtil.resolveColor(this, R.attr.colorPrimary)
|
||||
appBarLayout.setBackgroundColor(primaryColor)
|
||||
toolbar.apply {
|
||||
setBackgroundColor(primaryColor)
|
||||
navigationIcon = TintHelper.createTintedDrawable(
|
||||
ContextCompat.getDrawable(
|
||||
this@LyricsActivity, R.drawable.ic_keyboard_backspace_black_24dp
|
||||
), ThemeStore.textColorSecondary(this@LyricsActivity)
|
||||
)
|
||||
setSupportActionBar(toolbar)
|
||||
}
|
||||
viewPager.apply {
|
||||
adapter = PagerAdapter(supportFragmentManager)
|
||||
currentItem = PreferenceUtil.getInstance(this@LyricsActivity).lyricsOptions
|
||||
addOnPageChangeListener(this@LyricsActivity)
|
||||
}
|
||||
|
||||
tabs.apply {
|
||||
setupWithViewPager(viewPager)
|
||||
setSelectedTabIndicator(
|
||||
TintHelper.createTintedDrawable(
|
||||
ContextCompat.getDrawable(
|
||||
this@LyricsActivity, R.drawable.tab_indicator
|
||||
), ThemeStore.accentColor(this@LyricsActivity)
|
||||
)
|
||||
)
|
||||
setTabTextColors(
|
||||
ThemeStore.textColorSecondary(this@LyricsActivity),
|
||||
ThemeStore.accentColor(this@LyricsActivity)
|
||||
)
|
||||
setSelectedTabIndicatorColor(ThemeStore.accentColor(context))
|
||||
}
|
||||
fab.setOnClickListener(this)
|
||||
}
|
||||
|
||||
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()
|
||||
override fun onPlayingMetaChanged() {
|
||||
super.onPlayingMetaChanged()
|
||||
song = MusicPlayerRemote.currentSong
|
||||
toolbar.title = song.title
|
||||
toolbar.subtitle = song.artistName
|
||||
}
|
||||
|
||||
viewPager.apply {
|
||||
adapter = PagerAdapter(supportFragmentManager)
|
||||
currentItem = PreferenceUtil.getInstance(this@LyricsActivity).lyricsOptions
|
||||
addOnPageChangeListener(this@LyricsActivity)
|
||||
}
|
||||
override fun onServiceConnected() {
|
||||
super.onServiceConnected()
|
||||
song = MusicPlayerRemote.currentSong
|
||||
toolbar.title = song.title
|
||||
toolbar.subtitle = song.artistName
|
||||
}
|
||||
|
||||
tabs.apply {
|
||||
setupWithViewPager(viewPager)
|
||||
setSelectedTabIndicator(
|
||||
TintHelper.createTintedDrawable(
|
||||
ContextCompat.getDrawable(
|
||||
this@LyricsActivity, R.drawable.tab_indicator
|
||||
), ThemeStore.accentColor(this@LyricsActivity)
|
||||
)
|
||||
)
|
||||
setTabTextColors(
|
||||
ThemeStore.textColorSecondary(this@LyricsActivity),
|
||||
ThemeStore.accentColor(this@LyricsActivity)
|
||||
)
|
||||
setSelectedTabIndicatorColor(ThemeStore.accentColor(context))
|
||||
}
|
||||
fab.setOnClickListener(this)
|
||||
}
|
||||
private fun setupWakelock() {
|
||||
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||
}
|
||||
|
||||
override fun onPlayingMetaChanged() {
|
||||
super.onPlayingMetaChanged()
|
||||
song = MusicPlayerRemote.currentSong
|
||||
toolbar.title = song.title
|
||||
toolbar.subtitle = song.artistName
|
||||
}
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
if (item.itemId == android.R.id.home) {
|
||||
onBackPressed()
|
||||
}
|
||||
return super.onOptionsItemSelected(item)
|
||||
}
|
||||
|
||||
override fun onServiceConnected() {
|
||||
super.onServiceConnected()
|
||||
song = MusicPlayerRemote.currentSong
|
||||
toolbar.title = song.title
|
||||
toolbar.subtitle = song.artistName
|
||||
}
|
||||
private fun showSyncedLyrics() {
|
||||
var content = ""
|
||||
try {
|
||||
content = LyricUtil.getStringFromFile(song.data, song.artistName)
|
||||
} catch (e: Exception) {
|
||||
try {
|
||||
content = LyricUtil.getStringFromFile(song.title, song.artistName)
|
||||
} catch (e2: Exception) {
|
||||
|
||||
private fun setupWakelock() {
|
||||
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||
}
|
||||
}
|
||||
e.printStackTrace()
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
if (item.itemId == android.R.id.home) {
|
||||
onBackPressed()
|
||||
}
|
||||
return super.onOptionsItemSelected(item)
|
||||
}
|
||||
val materialDialog = MaterialDialog(
|
||||
this, BottomSheet(LayoutMode.WRAP_CONTENT)
|
||||
).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.data, song.artistName, input.toString())
|
||||
}
|
||||
positiveButton(android.R.string.ok) {
|
||||
updateSong()
|
||||
}
|
||||
}
|
||||
MaterialUtil.setTint(materialDialog.getInputLayout(), false)
|
||||
}
|
||||
|
||||
private fun showSyncedLyrics() {
|
||||
var content = ""
|
||||
try {
|
||||
content = LyricUtil.getStringFromFile(song.data, song.artistName)
|
||||
} catch (e: Exception) {
|
||||
try {
|
||||
content = LyricUtil.getStringFromFile(song.title, song.artistName)
|
||||
} catch (e2: Exception) {
|
||||
private fun updateSong() {
|
||||
val page = supportFragmentManager.findFragmentByTag("android:switcher:" + R.id.viewPager + ":" + viewPager.currentItem)
|
||||
if (viewPager.currentItem == 0 && page != null) {
|
||||
(page as BaseLyricsFragment).upDateSong()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
e.printStackTrace()
|
||||
}
|
||||
private fun showLyricsSaveDialog() {
|
||||
val content: String = if (lyricsString == null) {
|
||||
""
|
||||
} else {
|
||||
lyricsString!!
|
||||
}
|
||||
|
||||
val materialDialog = MaterialDialog(
|
||||
this, BottomSheet(LayoutMode.WRAP_CONTENT)
|
||||
).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.data, song.artistName, input.toString())
|
||||
}
|
||||
positiveButton(android.R.string.ok) {
|
||||
updateSong()
|
||||
}
|
||||
}
|
||||
MaterialUtil.setTint(materialDialog.getInputLayout(), false)
|
||||
}
|
||||
val materialDialog = MaterialDialog(
|
||||
this, BottomSheet(LayoutMode.WRAP_CONTENT)
|
||||
).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 updateSong() {
|
||||
val page = supportFragmentManager.findFragmentByTag("android:switcher:" + R.id.viewPager + ":" + viewPager.currentItem)
|
||||
if (viewPager.currentItem == 0 && page != null) {
|
||||
(page as BaseLyricsFragment).upDateSong()
|
||||
}
|
||||
}
|
||||
private fun getSongPaths(song: Song): ArrayList<String> {
|
||||
val paths = ArrayList<String>(1)
|
||||
paths.add(song.data)
|
||||
return paths
|
||||
}
|
||||
|
||||
private fun showLyricsSaveDialog() {
|
||||
val content: String = if (lyricsString == null) {
|
||||
""
|
||||
} else {
|
||||
lyricsString!!
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
val materialDialog = MaterialDialog(
|
||||
this, BottomSheet(LayoutMode.WRAP_CONTENT)
|
||||
).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)
|
||||
}
|
||||
class PagerAdapter(fm: FragmentManager) : FragmentStatePagerAdapter(
|
||||
fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT
|
||||
) {
|
||||
class Tabs(
|
||||
@StringRes val title: Int, val fragment: Fragment
|
||||
)
|
||||
|
||||
private fun getSongPaths(song: Song): ArrayList<String> {
|
||||
val paths = ArrayList<String>(1)
|
||||
paths.add(song.data)
|
||||
return paths
|
||||
}
|
||||
private var tabs = ArrayList<Tabs>()
|
||||
|
||||
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
|
||||
}
|
||||
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()))
|
||||
}
|
||||
|
||||
class PagerAdapter(fm: FragmentManager) : FragmentStatePagerAdapter(
|
||||
fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT
|
||||
) {
|
||||
class Tabs(
|
||||
@StringRes val title: Int, val fragment: Fragment
|
||||
)
|
||||
override fun getItem(position: Int): Fragment {
|
||||
return tabs[position].fragment
|
||||
}
|
||||
|
||||
private var tabs = ArrayList<Tabs>()
|
||||
override fun getPageTitle(position: Int): CharSequence? {
|
||||
return App.getContext().getString(tabs[position].title)
|
||||
}
|
||||
|
||||
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 getCount(): Int {
|
||||
return tabs.size
|
||||
}
|
||||
|
||||
override fun getItem(position: Int): Fragment {
|
||||
return tabs[position].fragment
|
||||
}
|
||||
}
|
||||
|
||||
override fun getPageTitle(position: Int): CharSequence? {
|
||||
return App.getContext().getString(tabs[position].title)
|
||||
}
|
||||
abstract class BaseLyricsFragment : AbsMusicServiceFragment() {
|
||||
abstract fun upDateSong()
|
||||
|
||||
override fun getCount(): Int {
|
||||
return tabs.size
|
||||
}
|
||||
override fun onPlayingMetaChanged() {
|
||||
super.onPlayingMetaChanged()
|
||||
upDateSong()
|
||||
}
|
||||
|
||||
}
|
||||
override fun onServiceConnected() {
|
||||
super.onServiceConnected()
|
||||
upDateSong()
|
||||
}
|
||||
|
||||
abstract class BaseLyricsFragment : AbsMusicServiceFragment() {
|
||||
abstract fun upDateSong()
|
||||
}
|
||||
|
||||
override fun onPlayingMetaChanged() {
|
||||
super.onPlayingMetaChanged()
|
||||
upDateSong()
|
||||
}
|
||||
class OfflineLyricsFragment : BaseLyricsFragment() {
|
||||
override fun upDateSong() {
|
||||
loadSongLyrics()
|
||||
}
|
||||
|
||||
override fun onServiceConnected() {
|
||||
super.onServiceConnected()
|
||||
upDateSong()
|
||||
}
|
||||
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!!)
|
||||
}
|
||||
|
||||
class OfflineLyricsFragment : BaseLyricsFragment() {
|
||||
override fun upDateSong() {
|
||||
loadSongLyrics()
|
||||
}
|
||||
override fun onPreExecute() {
|
||||
super.onPreExecute()
|
||||
lyrics = null
|
||||
}
|
||||
|
||||
private var updateLyricsAsyncTask: AsyncTask<*, *, *>? = null
|
||||
private var lyrics: 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
|
||||
}
|
||||
|
||||
@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 onCancelled(s: Lyrics?) {
|
||||
onPostExecute(null)
|
||||
}
|
||||
}.execute()
|
||||
}
|
||||
|
||||
override fun onPreExecute() {
|
||||
super.onPreExecute()
|
||||
lyrics = null
|
||||
}
|
||||
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
||||
super.onActivityCreated(savedInstanceState)
|
||||
loadSongLyrics()
|
||||
}
|
||||
|
||||
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 onDestroyView() {
|
||||
super.onDestroyView()
|
||||
if (updateLyricsAsyncTask != null && !updateLyricsAsyncTask!!.isCancelled) {
|
||||
updateLyricsAsyncTask?.cancel(true)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCancelled(s: Lyrics?) {
|
||||
onPostExecute(null)
|
||||
}
|
||||
}.execute()
|
||||
}
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
|
||||
): View? {
|
||||
return inflater.inflate(R.layout.fragment_lyrics, container, false)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
||||
super.onActivityCreated(savedInstanceState)
|
||||
loadSongLyrics()
|
||||
}
|
||||
class SyncedLyricsFragment : BaseLyricsFragment(), MusicProgressViewUpdateHelper.Callback {
|
||||
override fun upDateSong() {
|
||||
loadLRCLyrics()
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
if (updateLyricsAsyncTask != null && !updateLyricsAsyncTask!!.isCancelled) {
|
||||
updateLyricsAsyncTask?.cancel(true)
|
||||
}
|
||||
}
|
||||
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 onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
|
||||
): View? {
|
||||
return inflater.inflate(R.layout.fragment_lyrics, container, false)
|
||||
}
|
||||
}
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
updateHelper = MusicProgressViewUpdateHelper(this, 500, 1000)
|
||||
}
|
||||
|
||||
class SyncedLyricsFragment : BaseLyricsFragment(), MusicProgressViewUpdateHelper.Callback {
|
||||
override fun upDateSong() {
|
||||
loadLRCLyrics()
|
||||
}
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
setupLyricsView()
|
||||
}
|
||||
|
||||
private lateinit var updateHelper: MusicProgressViewUpdateHelper
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
|
||||
): View? {
|
||||
return inflater.inflate(R.layout.fragment_synced, container, false)
|
||||
}
|
||||
private fun setupLyricsView() {
|
||||
lyricsView.apply {
|
||||
val context = activity!!
|
||||
setCurrentPlayLineColor(ThemeStore.accentColor(context))
|
||||
setIndicatorTextColor(ThemeStore.accentColor(context))
|
||||
setCurrentIndicateLineTextColor(ThemeStore.textColorPrimary(context))
|
||||
setNoLrcTextColor(ThemeStore.textColorPrimary(context))
|
||||
setOnPlayIndicatorLineListener(object : LrcView.OnPlayIndicatorLineListener {
|
||||
override fun onPlay(time: Long, content: String) {
|
||||
MusicPlayerRemote.seekTo(time.toInt())
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
updateHelper = MusicProgressViewUpdateHelper(this, 500, 1000)
|
||||
}
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
updateHelper.start()
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
setupLyricsView()
|
||||
}
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
updateHelper.stop()
|
||||
}
|
||||
|
||||
private fun setupLyricsView() {
|
||||
lyricsView.apply {
|
||||
val context = activity!!
|
||||
setCurrentPlayLineColor(ThemeStore.accentColor(context))
|
||||
setIndicatorTextColor(ThemeStore.accentColor(context))
|
||||
setCurrentIndicateLineTextColor(ThemeStore.textColorPrimary(context))
|
||||
setNoLrcTextColor(ThemeStore.textColorPrimary(context))
|
||||
setOnPlayIndicatorLineListener(object : LrcView.OnPlayIndicatorLineListener {
|
||||
override fun onPlay(time: Long, content: String) {
|
||||
MusicPlayerRemote.seekTo(time.toInt())
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
override fun onUpdateProgressViews(progress: Int, total: Int) {
|
||||
lyricsView.updateTime(progress.toLong())
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
updateHelper.start()
|
||||
}
|
||||
private fun loadLRCLyrics() {
|
||||
val song = MusicPlayerRemote.currentSong
|
||||
if (LyricUtil.isLrcFile2Exist(song.data, song.artistName)) {
|
||||
showLyricsLocal(LyricUtil.getLocalLyricFile(song.data, song.artistName))
|
||||
} else {
|
||||
if (LyricUtil.isLrcFileExist(song.title, song.artistName)) {
|
||||
showLyricsLocal(LyricUtil.getLocalLyricFile(song.title, song.artistName))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
updateHelper.stop()
|
||||
}
|
||||
|
||||
override fun onUpdateProgressViews(progress: Int, total: Int) {
|
||||
lyricsView.updateTime(progress.toLong())
|
||||
}
|
||||
|
||||
private fun loadLRCLyrics() {
|
||||
val song = MusicPlayerRemote.currentSong
|
||||
if (LyricUtil.isLrcFile2Exist(song.data, song.artistName)) {
|
||||
showLyricsLocal(LyricUtil.getLocalLyricFile(song.data, song.artistName))
|
||||
} else {
|
||||
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))
|
||||
}
|
||||
}
|
||||
}
|
||||
private fun showLyricsLocal(file: File?) {
|
||||
if (file != null) {
|
||||
lyricsView.setLrcData(LrcHelper.parseLrcFromFile(file))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,15 +3,17 @@ package code.name.monkey.retromusic.activities
|
|||
import android.content.res.ColorStateList
|
||||
import android.os.Bundle
|
||||
import android.view.MenuItem
|
||||
import androidx.recyclerview.widget.*
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import code.name.monkey.appthemehelper.ThemeStore
|
||||
import code.name.monkey.appthemehelper.util.*
|
||||
import code.name.monkey.appthemehelper.util.ColorUtil
|
||||
import code.name.monkey.appthemehelper.util.MaterialValueHelper
|
||||
import code.name.monkey.retromusic.R
|
||||
import code.name.monkey.retromusic.activities.base.AbsMusicServiceActivity
|
||||
import code.name.monkey.retromusic.adapter.song.PlayingQueueAdapter
|
||||
import code.name.monkey.retromusic.extensions.applyToolbar
|
||||
import code.name.monkey.retromusic.helper.MusicPlayerRemote
|
||||
import code.name.monkey.retromusic.util.*
|
||||
import code.name.monkey.retromusic.util.MusicUtil
|
||||
import code.name.monkey.retromusic.util.ViewUtil
|
||||
import com.h6ah4i.android.widget.advrecyclerview.animator.RefactoredDefaultItemAnimator
|
||||
import com.h6ah4i.android.widget.advrecyclerview.draggable.RecyclerViewDragDropManager
|
||||
|
@ -20,169 +22,161 @@ import kotlinx.android.synthetic.main.activity_playing_queue.*
|
|||
|
||||
open class PlayingQueueActivity : AbsMusicServiceActivity() {
|
||||
|
||||
private var wrappedAdapter: RecyclerView.Adapter<*>? = null
|
||||
private var recyclerViewDragDropManager: RecyclerViewDragDropManager? = null
|
||||
private var playingQueueAdapter: PlayingQueueAdapter? = null
|
||||
private lateinit var linearLayoutManager: LinearLayoutManager
|
||||
private var wrappedAdapter: RecyclerView.Adapter<*>? = null
|
||||
private var recyclerViewDragDropManager: RecyclerViewDragDropManager? = null
|
||||
private var playingQueueAdapter: PlayingQueueAdapter? = null
|
||||
private lateinit var linearLayoutManager: LinearLayoutManager
|
||||
|
||||
private fun getUpNextAndQueueTime(): String {
|
||||
val duration = MusicPlayerRemote.getQueueDurationMillis(MusicPlayerRemote.position)
|
||||
private fun getUpNextAndQueueTime(): String {
|
||||
val duration = MusicPlayerRemote.getQueueDurationMillis(MusicPlayerRemote.position)
|
||||
return MusicUtil.buildInfoString(resources.getString(R.string.up_next), MusicUtil.getReadableDurationString(duration))
|
||||
}
|
||||
|
||||
return MusicUtil.buildInfoString(
|
||||
resources.getString(R.string.up_next), MusicUtil.getReadableDurationString(duration)
|
||||
)
|
||||
}
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_playing_queue)
|
||||
setStatusbarColorAuto()
|
||||
setNavigationBarColorPrimary()
|
||||
setTaskDescriptionColorAuto()
|
||||
setLightNavigationBar(true)
|
||||
|
||||
override fun onCreate(
|
||||
savedInstanceState: Bundle?
|
||||
) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_playing_queue)
|
||||
setupToolbar()
|
||||
setUpRecyclerView()
|
||||
|
||||
setStatusbarColorAuto()
|
||||
setNavigationBarColorPrimary()
|
||||
setTaskDescriptionColorAuto()
|
||||
setLightNavigationBar(true)
|
||||
clearQueue.setOnClickListener {
|
||||
MusicPlayerRemote.clearQueue()
|
||||
}
|
||||
checkForPadding()
|
||||
}
|
||||
|
||||
setupToolbar()
|
||||
setUpRecyclerView()
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
return when (item.itemId) {
|
||||
android.R.id.home -> {
|
||||
onBackPressed()
|
||||
true
|
||||
}
|
||||
else -> super.onOptionsItemSelected(item)
|
||||
}
|
||||
}
|
||||
|
||||
clearQueue.setOnClickListener {
|
||||
MusicPlayerRemote.clearQueue()
|
||||
}
|
||||
checkForPadding()
|
||||
}
|
||||
private fun setUpRecyclerView() {
|
||||
recyclerViewDragDropManager = RecyclerViewDragDropManager()
|
||||
val animator = RefactoredDefaultItemAnimator()
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
return when (item.itemId) {
|
||||
android.R.id.home -> {
|
||||
onBackPressed()
|
||||
true
|
||||
}
|
||||
else -> super.onOptionsItemSelected(item)
|
||||
}
|
||||
}
|
||||
playingQueueAdapter = PlayingQueueAdapter(
|
||||
this,
|
||||
MusicPlayerRemote.playingQueue,
|
||||
MusicPlayerRemote.position,
|
||||
R.layout.item_queue
|
||||
)
|
||||
wrappedAdapter = recyclerViewDragDropManager?.createWrappedAdapter(playingQueueAdapter!!)
|
||||
|
||||
private fun setUpRecyclerView() {
|
||||
recyclerViewDragDropManager = RecyclerViewDragDropManager()
|
||||
val animator = RefactoredDefaultItemAnimator()
|
||||
linearLayoutManager = LinearLayoutManager(this)
|
||||
|
||||
playingQueueAdapter = PlayingQueueAdapter(
|
||||
this,
|
||||
MusicPlayerRemote.playingQueue,
|
||||
MusicPlayerRemote.position,
|
||||
R.layout.item_queue
|
||||
)
|
||||
wrappedAdapter = recyclerViewDragDropManager?.createWrappedAdapter(playingQueueAdapter!!)
|
||||
recyclerView.apply {
|
||||
layoutManager = linearLayoutManager
|
||||
adapter = wrappedAdapter
|
||||
itemAnimator = animator
|
||||
recyclerViewDragDropManager?.attachRecyclerView(this)
|
||||
}
|
||||
|
||||
linearLayoutManager = LinearLayoutManager(this)
|
||||
linearLayoutManager.scrollToPositionWithOffset(MusicPlayerRemote.position + 1, 0)
|
||||
|
||||
recyclerView.apply {
|
||||
layoutManager = linearLayoutManager
|
||||
adapter = wrappedAdapter
|
||||
itemAnimator = animator
|
||||
recyclerViewDragDropManager?.attachRecyclerView(this)
|
||||
}
|
||||
recyclerView.addOnScrollListener(object : RecyclerView.OnScrollListener() {
|
||||
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
|
||||
super.onScrolled(recyclerView, dx, dy)
|
||||
if (dy > 0) {
|
||||
clearQueue.shrink()
|
||||
} else if (dy < 0) {
|
||||
clearQueue.extend()
|
||||
}
|
||||
}
|
||||
})
|
||||
ViewUtil.setUpFastScrollRecyclerViewColor(this, recyclerView)
|
||||
}
|
||||
|
||||
linearLayoutManager.scrollToPositionWithOffset(MusicPlayerRemote.position + 1, 0)
|
||||
private fun checkForPadding() {
|
||||
|
||||
recyclerView.addOnScrollListener(object : RecyclerView.OnScrollListener() {
|
||||
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
|
||||
super.onScrolled(recyclerView, dx, dy)
|
||||
if (dy > 0) {
|
||||
clearQueue.shrink()
|
||||
} else if (dy < 0) {
|
||||
clearQueue.extend()
|
||||
}
|
||||
}
|
||||
})
|
||||
ViewUtil.setUpFastScrollRecyclerViewColor(this, recyclerView)
|
||||
}
|
||||
}
|
||||
|
||||
private fun checkForPadding() {
|
||||
override fun onQueueChanged() {
|
||||
if (MusicPlayerRemote.playingQueue.isEmpty()) {
|
||||
finish()
|
||||
return
|
||||
}
|
||||
checkForPadding()
|
||||
updateQueue()
|
||||
updateCurrentSong()
|
||||
}
|
||||
|
||||
}
|
||||
override fun onMediaStoreChanged() {
|
||||
updateQueue()
|
||||
updateCurrentSong()
|
||||
}
|
||||
|
||||
override fun onQueueChanged() {
|
||||
if (MusicPlayerRemote.playingQueue.isEmpty()) {
|
||||
finish()
|
||||
return
|
||||
}
|
||||
checkForPadding()
|
||||
updateQueue()
|
||||
updateCurrentSong()
|
||||
}
|
||||
private fun updateCurrentSong() {
|
||||
playerQueueSubHeader.text = getUpNextAndQueueTime()
|
||||
}
|
||||
|
||||
override fun onMediaStoreChanged() {
|
||||
updateQueue()
|
||||
updateCurrentSong()
|
||||
}
|
||||
override fun onPlayingMetaChanged() {
|
||||
updateQueuePosition()
|
||||
}
|
||||
|
||||
private fun updateCurrentSong() {
|
||||
playerQueueSubHeader.text = getUpNextAndQueueTime()
|
||||
}
|
||||
private fun updateQueuePosition() {
|
||||
playingQueueAdapter?.setCurrent(MusicPlayerRemote.position)
|
||||
resetToCurrentPosition()
|
||||
playerQueueSubHeader.text = getUpNextAndQueueTime()
|
||||
}
|
||||
|
||||
override fun onPlayingMetaChanged() {
|
||||
updateQueuePosition()
|
||||
}
|
||||
private fun updateQueue() {
|
||||
playingQueueAdapter?.swapDataSet(MusicPlayerRemote.playingQueue, MusicPlayerRemote.position)
|
||||
resetToCurrentPosition()
|
||||
}
|
||||
|
||||
private fun updateQueuePosition() {
|
||||
playingQueueAdapter?.setCurrent(MusicPlayerRemote.position)
|
||||
resetToCurrentPosition()
|
||||
playerQueueSubHeader.text = getUpNextAndQueueTime()
|
||||
}
|
||||
private fun resetToCurrentPosition() {
|
||||
recyclerView.stopScroll()
|
||||
linearLayoutManager.scrollToPositionWithOffset(MusicPlayerRemote.position + 1, 0)
|
||||
}
|
||||
|
||||
private fun updateQueue() {
|
||||
playingQueueAdapter?.swapDataSet(MusicPlayerRemote.playingQueue, MusicPlayerRemote.position)
|
||||
resetToCurrentPosition()
|
||||
}
|
||||
override fun onPause() {
|
||||
if (recyclerViewDragDropManager != null) {
|
||||
recyclerViewDragDropManager!!.cancelDrag()
|
||||
}
|
||||
super.onPause()
|
||||
}
|
||||
|
||||
private fun resetToCurrentPosition() {
|
||||
recyclerView.stopScroll()
|
||||
linearLayoutManager.scrollToPositionWithOffset(MusicPlayerRemote.position + 1, 0)
|
||||
}
|
||||
override fun onDestroy() {
|
||||
if (recyclerViewDragDropManager != null) {
|
||||
recyclerViewDragDropManager!!.release()
|
||||
recyclerViewDragDropManager = null
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
if (recyclerViewDragDropManager != null) {
|
||||
recyclerViewDragDropManager!!.cancelDrag()
|
||||
}
|
||||
super.onPause()
|
||||
}
|
||||
if (wrappedAdapter != null) {
|
||||
WrapperAdapterUtils.releaseAll(wrappedAdapter)
|
||||
wrappedAdapter = null
|
||||
}
|
||||
playingQueueAdapter = null
|
||||
super.onDestroy()
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
if (recyclerViewDragDropManager != null) {
|
||||
recyclerViewDragDropManager!!.release()
|
||||
recyclerViewDragDropManager = null
|
||||
}
|
||||
private fun setupToolbar() {
|
||||
playerQueueSubHeader.text = getUpNextAndQueueTime()
|
||||
playerQueueSubHeader.setTextColor(ThemeStore.accentColor(this))
|
||||
|
||||
if (wrappedAdapter != null) {
|
||||
WrapperAdapterUtils.releaseAll(wrappedAdapter)
|
||||
wrappedAdapter = null
|
||||
}
|
||||
playingQueueAdapter = null
|
||||
super.onDestroy()
|
||||
}
|
||||
|
||||
private fun setupToolbar() {
|
||||
playerQueueSubHeader.text = getUpNextAndQueueTime()
|
||||
playerQueueSubHeader.setTextColor(ThemeStore.accentColor(this))
|
||||
|
||||
applyToolbar(toolbar)
|
||||
appBarLayout.setBackgroundColor(ATHUtil.resolveColor(this, R.attr.colorPrimary))
|
||||
|
||||
clearQueue.backgroundTintList = ColorStateList.valueOf(ThemeStore.accentColor(this))
|
||||
ColorStateList.valueOf(
|
||||
MaterialValueHelper.getPrimaryTextColor(
|
||||
this,
|
||||
ColorUtil.isColorLight(
|
||||
ThemeStore.accentColor(
|
||||
this
|
||||
)
|
||||
)
|
||||
)
|
||||
).apply {
|
||||
clearQueue.setTextColor(this)
|
||||
clearQueue.iconTint = this
|
||||
}
|
||||
}
|
||||
applyToolbar(toolbar)
|
||||
clearQueue.backgroundTintList = ColorStateList.valueOf(ThemeStore.accentColor(this))
|
||||
ColorStateList.valueOf(
|
||||
MaterialValueHelper.getPrimaryTextColor(
|
||||
this,
|
||||
ColorUtil.isColorLight(
|
||||
ThemeStore.accentColor(
|
||||
this
|
||||
)
|
||||
)
|
||||
)
|
||||
).apply {
|
||||
clearQueue.setTextColor(this)
|
||||
clearQueue.iconTint = this
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,20 +1,29 @@
|
|||
package code.name.monkey.retromusic.activities
|
||||
|
||||
import android.graphics.Color
|
||||
import android.os.Bundle
|
||||
import android.view.*
|
||||
import androidx.recyclerview.widget.*
|
||||
import code.name.monkey.appthemehelper.util.*
|
||||
import code.name.monkey.retromusic.*
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import code.name.monkey.appthemehelper.util.ATHUtil
|
||||
import code.name.monkey.retromusic.App
|
||||
import code.name.monkey.retromusic.R
|
||||
import code.name.monkey.retromusic.activities.base.AbsSlidingMusicPanelActivity
|
||||
import code.name.monkey.retromusic.adapter.song.*
|
||||
import code.name.monkey.retromusic.extensions.applyToolbar
|
||||
import code.name.monkey.retromusic.adapter.song.OrderablePlaylistSongAdapter
|
||||
import code.name.monkey.retromusic.adapter.song.PlaylistSongAdapter
|
||||
import code.name.monkey.retromusic.adapter.song.SongAdapter
|
||||
import code.name.monkey.retromusic.helper.menu.PlaylistMenuHelper
|
||||
import code.name.monkey.retromusic.interfaces.CabHolder
|
||||
import code.name.monkey.retromusic.loaders.PlaylistLoader
|
||||
import code.name.monkey.retromusic.model.*
|
||||
import code.name.monkey.retromusic.mvp.presenter.*
|
||||
import code.name.monkey.retromusic.util.*
|
||||
import code.name.monkey.retromusic.model.AbsCustomPlaylist
|
||||
import code.name.monkey.retromusic.model.Playlist
|
||||
import code.name.monkey.retromusic.model.Song
|
||||
import code.name.monkey.retromusic.mvp.presenter.PlaylistSongsPresenter
|
||||
import code.name.monkey.retromusic.mvp.presenter.PlaylistSongsView
|
||||
import code.name.monkey.retromusic.util.DensityUtil
|
||||
import code.name.monkey.retromusic.util.PlaylistsUtil
|
||||
import code.name.monkey.retromusic.util.RetroColorUtil
|
||||
import code.name.monkey.retromusic.util.ViewUtil
|
||||
import com.afollestad.materialcab.MaterialCab
|
||||
import com.h6ah4i.android.widget.advrecyclerview.animator.RefactoredDefaultItemAnimator
|
||||
|
@ -25,217 +34,202 @@ import javax.inject.Inject
|
|||
|
||||
class PlaylistDetailActivity : AbsSlidingMusicPanelActivity(), CabHolder, PlaylistSongsView {
|
||||
|
||||
@Inject
|
||||
lateinit var playlistSongsPresenter: PlaylistSongsPresenter
|
||||
@Inject
|
||||
lateinit var playlistSongsPresenter: PlaylistSongsPresenter
|
||||
|
||||
private lateinit var playlist: Playlist
|
||||
private var cab: MaterialCab? = null
|
||||
private lateinit var adapter: SongAdapter
|
||||
private var wrappedAdapter: RecyclerView.Adapter<*>? = null
|
||||
private var recyclerViewDragDropManager: RecyclerViewDragDropManager? = null
|
||||
private lateinit var playlist: Playlist
|
||||
private var cab: MaterialCab? = null
|
||||
private lateinit var adapter: SongAdapter
|
||||
private var wrappedAdapter: RecyclerView.Adapter<*>? = null
|
||||
private var recyclerViewDragDropManager: RecyclerViewDragDropManager? = null
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
setDrawUnderStatusBar()
|
||||
super.onCreate(savedInstanceState)
|
||||
App.musicComponent.inject(this)
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
setDrawUnderStatusBar()
|
||||
super.onCreate(savedInstanceState)
|
||||
setStatusbarColorAuto()
|
||||
setNavigationbarColorAuto()
|
||||
setTaskDescriptionColorAuto()
|
||||
setLightNavigationBar(true)
|
||||
toggleBottomNavigationView(true)
|
||||
|
||||
playlistSongsPresenter.attachView(this)
|
||||
App.musicComponent.inject(this)
|
||||
playlistSongsPresenter.attachView(this)
|
||||
|
||||
setStatusbarColor(Color.TRANSPARENT)
|
||||
setNavigationbarColorAuto()
|
||||
setTaskDescriptionColorAuto()
|
||||
setLightNavigationBar(true)
|
||||
setLightStatusbar(ColorUtil.isColorLight(ATHUtil.resolveColor(this, R.attr.colorPrimary)))
|
||||
if (intent.extras != null) {
|
||||
playlist = intent.extras!!.getParcelable(EXTRA_PLAYLIST)!!
|
||||
} else {
|
||||
finish()
|
||||
}
|
||||
|
||||
toggleBottomNavigationView(true)
|
||||
setUpToolBar()
|
||||
setUpRecyclerView()
|
||||
}
|
||||
|
||||
if (intent.extras != null) {
|
||||
playlist = intent.extras!!.getParcelable(EXTRA_PLAYLIST)!!
|
||||
} else {
|
||||
finish()
|
||||
}
|
||||
override fun createContentView(): View {
|
||||
return wrapSlidingMusicPanel(R.layout.activity_playlist_detail)
|
||||
}
|
||||
|
||||
setUpToolBar()
|
||||
setUpRecyclerView()
|
||||
}
|
||||
private fun setUpRecyclerView() {
|
||||
ViewUtil.setUpFastScrollRecyclerViewColor(this, recyclerView)
|
||||
recyclerView.layoutManager = LinearLayoutManager(this)
|
||||
if (playlist is AbsCustomPlaylist) {
|
||||
adapter = PlaylistSongAdapter(this, ArrayList(), R.layout.item_list, false, this)
|
||||
recyclerView.adapter = adapter
|
||||
} else {
|
||||
recyclerViewDragDropManager = RecyclerViewDragDropManager()
|
||||
val animator = RefactoredDefaultItemAnimator()
|
||||
adapter = OrderablePlaylistSongAdapter(this,
|
||||
ArrayList(),
|
||||
R.layout.item_list,
|
||||
false,
|
||||
this,
|
||||
object : OrderablePlaylistSongAdapter.OnMoveItemListener {
|
||||
override fun onMoveItem(fromPosition: Int, toPosition: Int) {
|
||||
if (PlaylistsUtil.moveItem(this@PlaylistDetailActivity, playlist.id, fromPosition, toPosition)) {
|
||||
val song = adapter.dataSet.removeAt(fromPosition)
|
||||
adapter.dataSet.add(toPosition, song)
|
||||
adapter.notifyItemMoved(fromPosition, toPosition)
|
||||
}
|
||||
}
|
||||
})
|
||||
wrappedAdapter = recyclerViewDragDropManager!!.createWrappedAdapter(adapter)
|
||||
|
||||
override fun createContentView(): View {
|
||||
return wrapSlidingMusicPanel(R.layout.activity_playlist_detail)
|
||||
}
|
||||
recyclerView.adapter = wrappedAdapter
|
||||
recyclerView.itemAnimator = animator
|
||||
|
||||
private fun setUpRecyclerView() {
|
||||
ViewUtil.setUpFastScrollRecyclerViewColor(this, recyclerView)
|
||||
recyclerView.layoutManager = LinearLayoutManager(this)
|
||||
if (playlist is AbsCustomPlaylist) {
|
||||
adapter = PlaylistSongAdapter(this, ArrayList(), R.layout.item_list, false, this)
|
||||
recyclerView.adapter = adapter
|
||||
} else {
|
||||
recyclerViewDragDropManager = RecyclerViewDragDropManager()
|
||||
val animator = RefactoredDefaultItemAnimator()
|
||||
adapter = OrderablePlaylistSongAdapter(this,
|
||||
ArrayList(),
|
||||
R.layout.item_list,
|
||||
false,
|
||||
this,
|
||||
object : OrderablePlaylistSongAdapter.OnMoveItemListener {
|
||||
override fun onMoveItem(
|
||||
fromPosition: Int,
|
||||
toPosition: Int
|
||||
) {
|
||||
if (PlaylistsUtil.moveItem(
|
||||
this@PlaylistDetailActivity,
|
||||
playlist.id,
|
||||
fromPosition,
|
||||
toPosition
|
||||
)) {
|
||||
val song = adapter.dataSet.removeAt(
|
||||
fromPosition
|
||||
)
|
||||
adapter.dataSet.add(toPosition, song)
|
||||
adapter.notifyItemMoved(
|
||||
fromPosition,
|
||||
toPosition
|
||||
)
|
||||
}
|
||||
}
|
||||
})
|
||||
wrappedAdapter = recyclerViewDragDropManager!!.createWrappedAdapter(adapter)
|
||||
recyclerViewDragDropManager?.attachRecyclerView(recyclerView)
|
||||
}
|
||||
adapter.registerAdapterDataObserver(object : RecyclerView.AdapterDataObserver() {
|
||||
override fun onChanged() {
|
||||
super.onChanged()
|
||||
checkIsEmpty()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
recyclerView.adapter = wrappedAdapter
|
||||
recyclerView.itemAnimator = animator
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
playlistSongsPresenter.loadPlaylistSongs(playlist)
|
||||
}
|
||||
|
||||
recyclerViewDragDropManager?.attachRecyclerView(recyclerView)
|
||||
}
|
||||
adapter.registerAdapterDataObserver(object : RecyclerView.AdapterDataObserver() {
|
||||
override fun onChanged() {
|
||||
super.onChanged()
|
||||
checkIsEmpty()
|
||||
}
|
||||
})
|
||||
}
|
||||
private fun setUpToolBar() {
|
||||
toolbar.setBackgroundColor(ATHUtil.resolveColor(this, R.attr.colorSurface))
|
||||
setSupportActionBar(toolbar)
|
||||
title = playlist.name
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
playlistSongsPresenter.loadPlaylistSongs(playlist)
|
||||
}
|
||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||
menuInflater.inflate(
|
||||
if (playlist is AbsCustomPlaylist) R.menu.menu_smart_playlist_detail
|
||||
else R.menu.menu_playlist_detail, menu
|
||||
)
|
||||
return super.onCreateOptionsMenu(menu)
|
||||
}
|
||||
|
||||
private fun setUpToolBar() {
|
||||
applyToolbar(toolbar)
|
||||
title = playlist.name
|
||||
}
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
when (item.itemId) {
|
||||
android.R.id.home -> {
|
||||
onBackPressed()
|
||||
return true
|
||||
}
|
||||
}
|
||||
return PlaylistMenuHelper.handleMenuClick(this, playlist, item)
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||
menuInflater.inflate(
|
||||
if (playlist is AbsCustomPlaylist) R.menu.menu_smart_playlist_detail
|
||||
else R.menu.menu_playlist_detail, menu
|
||||
)
|
||||
return super.onCreateOptionsMenu(menu)
|
||||
}
|
||||
override fun openCab(menuRes: Int, callback: MaterialCab.Callback): MaterialCab {
|
||||
if (cab != null && cab!!.isActive) {
|
||||
cab!!.finish()
|
||||
}
|
||||
cab = MaterialCab(this, R.id.cab_stub).setMenu(menuRes)
|
||||
.setCloseDrawableRes(R.drawable.ic_close_white_24dp).setBackgroundColor(
|
||||
RetroColorUtil.shiftBackgroundColorForLightText(
|
||||
ATHUtil.resolveColor(
|
||||
this,
|
||||
R.attr.colorPrimary
|
||||
)
|
||||
)
|
||||
).start(callback)
|
||||
return cab!!
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
when (item.itemId) {
|
||||
android.R.id.home -> {
|
||||
onBackPressed()
|
||||
return true
|
||||
}
|
||||
}
|
||||
return PlaylistMenuHelper.handleMenuClick(this, playlist, item)
|
||||
}
|
||||
override fun onBackPressed() {
|
||||
if (cab != null && cab!!.isActive) {
|
||||
cab!!.finish()
|
||||
} else {
|
||||
recyclerView!!.stopScroll()
|
||||
super.onBackPressed()
|
||||
}
|
||||
}
|
||||
|
||||
override fun openCab(menuRes: Int, callback: MaterialCab.Callback): MaterialCab {
|
||||
if (cab != null && cab!!.isActive) {
|
||||
cab!!.finish()
|
||||
}
|
||||
cab = MaterialCab(this, R.id.cab_stub).setMenu(menuRes)
|
||||
.setCloseDrawableRes(R.drawable.ic_close_white_24dp).setBackgroundColor(
|
||||
RetroColorUtil.shiftBackgroundColorForLightText(
|
||||
ATHUtil.resolveColor(
|
||||
this,
|
||||
R.attr.colorPrimary
|
||||
)
|
||||
)
|
||||
).start(callback)
|
||||
return cab!!
|
||||
}
|
||||
override fun onMediaStoreChanged() {
|
||||
super.onMediaStoreChanged()
|
||||
if (playlist !is AbsCustomPlaylist) {
|
||||
// Playlist deleted
|
||||
if (!PlaylistsUtil.doesPlaylistExist(this, playlist.id)) {
|
||||
finish()
|
||||
return
|
||||
}
|
||||
// Playlist renamed
|
||||
val playlistName = PlaylistsUtil.getNameForPlaylist(this, playlist.id.toLong())
|
||||
if (playlistName != playlist.name) {
|
||||
playlist = PlaylistLoader.getPlaylist(this, playlist.id)
|
||||
setToolbarTitle(playlist.name)
|
||||
}
|
||||
}
|
||||
playlistSongsPresenter.loadPlaylistSongs(playlist)
|
||||
}
|
||||
|
||||
override fun onBackPressed() {
|
||||
if (cab != null && cab!!.isActive) {
|
||||
cab!!.finish()
|
||||
} else {
|
||||
recyclerView!!.stopScroll()
|
||||
super.onBackPressed()
|
||||
}
|
||||
}
|
||||
private fun setToolbarTitle(title: String) {
|
||||
supportActionBar!!.title = title
|
||||
}
|
||||
|
||||
override fun onMediaStoreChanged() {
|
||||
super.onMediaStoreChanged()
|
||||
if (playlist !is AbsCustomPlaylist) {
|
||||
// Playlist deleted
|
||||
if (!PlaylistsUtil.doesPlaylistExist(this, playlist.id)) {
|
||||
finish()
|
||||
return
|
||||
}
|
||||
// Playlist renamed
|
||||
val playlistName = PlaylistsUtil.getNameForPlaylist(this, playlist.id.toLong())
|
||||
if (playlistName != playlist.name) {
|
||||
playlist = PlaylistLoader.getPlaylist(this, playlist.id)
|
||||
setToolbarTitle(playlist.name)
|
||||
}
|
||||
}
|
||||
playlistSongsPresenter.loadPlaylistSongs(playlist)
|
||||
}
|
||||
private fun checkForPadding() {
|
||||
val height = DensityUtil.dip2px(this, 52f)
|
||||
recyclerView.setPadding(0, 0, 0, (height))
|
||||
}
|
||||
|
||||
private fun setToolbarTitle(title: String) {
|
||||
supportActionBar!!.title = title
|
||||
}
|
||||
private fun checkIsEmpty() {
|
||||
checkForPadding()
|
||||
empty.visibility = if (adapter.itemCount == 0) View.VISIBLE else View.GONE
|
||||
emptyText.visibility = if (adapter.itemCount == 0) View.VISIBLE else View.GONE
|
||||
}
|
||||
|
||||
private fun checkForPadding() {
|
||||
val height = DensityUtil.dip2px(this, 52f)
|
||||
recyclerView.setPadding(0, 0, 0, (height))
|
||||
}
|
||||
public override fun onPause() {
|
||||
if (recyclerViewDragDropManager != null) {
|
||||
recyclerViewDragDropManager!!.cancelDrag()
|
||||
}
|
||||
super.onPause()
|
||||
}
|
||||
|
||||
private fun checkIsEmpty() {
|
||||
checkForPadding()
|
||||
empty.visibility = if (adapter.itemCount == 0) View.VISIBLE else View.GONE
|
||||
emptyText.visibility = if (adapter.itemCount == 0) View.VISIBLE else View.GONE
|
||||
}
|
||||
override fun onDestroy() {
|
||||
if (recyclerViewDragDropManager != null) {
|
||||
recyclerViewDragDropManager!!.release()
|
||||
recyclerViewDragDropManager = null
|
||||
}
|
||||
|
||||
public override fun onPause() {
|
||||
if (recyclerViewDragDropManager != null) {
|
||||
recyclerViewDragDropManager!!.cancelDrag()
|
||||
}
|
||||
super.onPause()
|
||||
}
|
||||
if (recyclerView != null) {
|
||||
recyclerView!!.itemAnimator = null
|
||||
recyclerView!!.adapter = null
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
if (recyclerViewDragDropManager != null) {
|
||||
recyclerViewDragDropManager!!.release()
|
||||
recyclerViewDragDropManager = null
|
||||
}
|
||||
if (wrappedAdapter != null) {
|
||||
WrapperAdapterUtils.releaseAll(wrappedAdapter)
|
||||
wrappedAdapter = null
|
||||
}
|
||||
super.onDestroy()
|
||||
playlistSongsPresenter.detachView()
|
||||
}
|
||||
|
||||
if (recyclerView != null) {
|
||||
recyclerView!!.itemAnimator = null
|
||||
recyclerView!!.adapter = null
|
||||
}
|
||||
override fun showEmptyView() {
|
||||
empty.visibility = View.VISIBLE
|
||||
emptyText.visibility = View.VISIBLE
|
||||
}
|
||||
|
||||
if (wrappedAdapter != null) {
|
||||
WrapperAdapterUtils.releaseAll(wrappedAdapter)
|
||||
wrappedAdapter = null
|
||||
}
|
||||
super.onDestroy()
|
||||
playlistSongsPresenter.detachView()
|
||||
}
|
||||
override fun songs(songs: ArrayList<Song>) {
|
||||
adapter.swapDataSet(songs)
|
||||
}
|
||||
|
||||
override fun showEmptyView() {
|
||||
empty.visibility = View.VISIBLE
|
||||
emptyText.visibility = View.VISIBLE
|
||||
}
|
||||
|
||||
override fun songs(songs: ArrayList<Song>) {
|
||||
adapter.swapDataSet(songs)
|
||||
}
|
||||
|
||||
companion object {
|
||||
var EXTRA_PLAYLIST = "extra_playlist"
|
||||
}
|
||||
companion object {
|
||||
var EXTRA_PLAYLIST = "extra_playlist"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,16 +1,19 @@
|
|||
package code.name.monkey.retromusic.activities
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.*
|
||||
import android.os.AsyncTask
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.MenuItem
|
||||
import android.widget.Toast
|
||||
import code.name.monkey.appthemehelper.util.*
|
||||
import code.name.monkey.retromusic.*
|
||||
import code.name.monkey.appthemehelper.util.MaterialUtil
|
||||
import code.name.monkey.retromusic.App
|
||||
import code.name.monkey.retromusic.BuildConfig
|
||||
import code.name.monkey.retromusic.R
|
||||
import code.name.monkey.retromusic.activities.base.AbsBaseActivity
|
||||
import code.name.monkey.retromusic.extensions.applyToolbar
|
||||
import com.anjlab.android.iab.v3.*
|
||||
import com.anjlab.android.iab.v3.BillingProcessor
|
||||
import com.anjlab.android.iab.v3.TransactionDetails
|
||||
import kotlinx.android.synthetic.main.activity_pro_version.*
|
||||
import java.lang.ref.WeakReference
|
||||
|
||||
|
@ -23,16 +26,11 @@ class PurchaseActivity : AbsBaseActivity(), BillingProcessor.IBillingHandler {
|
|||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_pro_version)
|
||||
setDrawUnderStatusBar()
|
||||
|
||||
setStatusbarColorAuto()
|
||||
setNavigationBarColorPrimary()
|
||||
setTaskDescriptionColorAuto()
|
||||
setLightNavigationBar(true)
|
||||
|
||||
val primaryColor = ATHUtil.resolveColor(this, R.attr.colorPrimary)
|
||||
toolbar.setBackgroundColor(primaryColor)
|
||||
appBarLayout.setBackgroundColor(primaryColor)
|
||||
|
||||
applyToolbar(toolbar)
|
||||
|
||||
restoreButton.isEnabled = false
|
||||
|
|
|
@ -18,7 +18,6 @@ import androidx.recyclerview.widget.LinearLayoutManager
|
|||
import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.transition.TransitionManager
|
||||
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 code.name.monkey.retromusic.App
|
||||
|
@ -125,7 +124,6 @@ class SearchActivity : AbsMusicServiceActivity(), OnQueryTextListener, TextWatch
|
|||
|
||||
private fun setUpToolBar() {
|
||||
title = null
|
||||
appBarLayout.setBackgroundColor(ATHUtil.resolveColor(this, R.attr.colorPrimary))
|
||||
}
|
||||
|
||||
private fun search(query: String) {
|
||||
|
|
|
@ -5,7 +5,8 @@ import android.view.MenuItem
|
|||
import androidx.annotation.StringRes
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.transition.TransitionManager
|
||||
import code.name.monkey.appthemehelper.util.*
|
||||
import code.name.monkey.appthemehelper.util.ATHUtil
|
||||
import code.name.monkey.appthemehelper.util.ToolbarContentTintHelper
|
||||
import code.name.monkey.retromusic.R
|
||||
import code.name.monkey.retromusic.activities.base.AbsBaseActivity
|
||||
import code.name.monkey.retromusic.fragments.settings.MainSettingsFragment
|
||||
|
@ -25,8 +26,7 @@ class SettingsActivity : AbsBaseActivity() {
|
|||
setupToolbar()
|
||||
|
||||
if (savedInstanceState == null) {
|
||||
fragmentManager.beginTransaction().replace(R.id.contentFrame, MainSettingsFragment())
|
||||
.commit()
|
||||
fragmentManager.beginTransaction().replace(R.id.contentFrame, MainSettingsFragment()).commit()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -34,13 +34,10 @@ class SettingsActivity : AbsBaseActivity() {
|
|||
setSupportActionBar(toolbar)
|
||||
setTitle(R.string.action_settings)
|
||||
toolbar.apply {
|
||||
setTitleTextColor(ATHUtil.resolveColor(this@SettingsActivity, R.attr.colorOnPrimary))
|
||||
setBackgroundColor(ATHUtil.resolveColor(this@SettingsActivity, R.attr.colorPrimary))
|
||||
setBackgroundColor(ATHUtil.resolveColor(this@SettingsActivity, R.attr.colorSurface))
|
||||
setNavigationOnClickListener { onBackPressed() }
|
||||
ToolbarContentTintHelper.colorBackButton(toolbar)
|
||||
}
|
||||
appBarLayout.setBackgroundColor(ATHUtil.resolveColor(this@SettingsActivity, R.attr.colorPrimary))
|
||||
|
||||
}
|
||||
|
||||
fun setupFragment(fragment: Fragment, @StringRes titleName: Int) {
|
||||
|
|
|
@ -2,20 +2,30 @@ package code.name.monkey.retromusic.activities
|
|||
|
||||
import android.content.Intent
|
||||
import android.graphics.Paint
|
||||
import android.os.*
|
||||
import android.os.AsyncTask
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.*
|
||||
import android.widget.*
|
||||
import android.view.LayoutInflater
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.TextView
|
||||
import android.widget.Toast
|
||||
import androidx.annotation.LayoutRes
|
||||
import androidx.appcompat.widget.AppCompatImageView
|
||||
import androidx.recyclerview.widget.*
|
||||
import androidx.recyclerview.widget.DefaultItemAnimator
|
||||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import code.name.monkey.appthemehelper.ThemeStore
|
||||
import code.name.monkey.appthemehelper.util.*
|
||||
import code.name.monkey.retromusic.*
|
||||
import code.name.monkey.appthemehelper.util.ATHUtil
|
||||
import code.name.monkey.appthemehelper.util.TintHelper
|
||||
import code.name.monkey.retromusic.BuildConfig
|
||||
import code.name.monkey.retromusic.R
|
||||
import code.name.monkey.retromusic.activities.base.AbsBaseActivity
|
||||
import code.name.monkey.retromusic.extensions.applyToolbar
|
||||
import com.anjlab.android.iab.v3.*
|
||||
import com.anjlab.android.iab.v3.BillingProcessor
|
||||
import com.anjlab.android.iab.v3.SkuDetails
|
||||
import com.anjlab.android.iab.v3.TransactionDetails
|
||||
import kotlinx.android.synthetic.main.activity_donation.*
|
||||
import java.lang.ref.WeakReference
|
||||
import java.util.*
|
||||
|
@ -61,8 +71,6 @@ class SupportDevelopmentActivity : AbsBaseActivity(), BillingProcessor.IBillingH
|
|||
}
|
||||
|
||||
private fun setupToolbar() {
|
||||
val primaryColor = ATHUtil.resolveColor(this, R.attr.colorPrimary)
|
||||
appBarLayout.setBackgroundColor(primaryColor)
|
||||
applyToolbar(toolbar)
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
package code.name.monkey.retromusic.activities
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.*
|
||||
import android.content.ContentUris
|
||||
import android.content.Context
|
||||
import android.content.ContextWrapper
|
||||
import android.content.Intent
|
||||
import android.content.res.ColorStateList
|
||||
import android.graphics.Bitmap
|
||||
import android.net.Uri
|
||||
|
@ -13,298 +16,266 @@ import android.text.TextUtils
|
|||
import android.view.MenuItem
|
||||
import android.widget.Toast
|
||||
import code.name.monkey.appthemehelper.ThemeStore
|
||||
import code.name.monkey.appthemehelper.util.*
|
||||
import code.name.monkey.retromusic.*
|
||||
import code.name.monkey.appthemehelper.util.ColorUtil
|
||||
import code.name.monkey.appthemehelper.util.MaterialUtil
|
||||
import code.name.monkey.appthemehelper.util.MaterialValueHelper
|
||||
import code.name.monkey.retromusic.App
|
||||
import code.name.monkey.retromusic.Constants.USER_BANNER
|
||||
import code.name.monkey.retromusic.Constants.USER_PROFILE
|
||||
import code.name.monkey.retromusic.R
|
||||
import code.name.monkey.retromusic.activities.base.AbsBaseActivity
|
||||
import code.name.monkey.retromusic.extensions.applyToolbar
|
||||
import code.name.monkey.retromusic.util.*
|
||||
import code.name.monkey.retromusic.util.Compressor
|
||||
import code.name.monkey.retromusic.util.ImageUtil.getResizedBitmap
|
||||
import com.afollestad.materialdialogs.*
|
||||
import code.name.monkey.retromusic.util.PreferenceUtil
|
||||
import com.afollestad.materialdialogs.LayoutMode
|
||||
import com.afollestad.materialdialogs.MaterialDialog
|
||||
import com.afollestad.materialdialogs.bottomsheets.BottomSheet
|
||||
import com.afollestad.materialdialogs.list.listItems
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.disposables.CompositeDisposable
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
import kotlinx.android.synthetic.main.activity_user_info.*
|
||||
import java.io.*
|
||||
import java.io.File
|
||||
import java.io.FileOutputStream
|
||||
import java.io.IOException
|
||||
|
||||
class UserInfoActivity : AbsBaseActivity() {
|
||||
|
||||
private var disposable = CompositeDisposable()
|
||||
private var disposable = CompositeDisposable()
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_user_info)
|
||||
setStatusbarColorAuto()
|
||||
setNavigationBarColorPrimary()
|
||||
setTaskDescriptionColorAuto()
|
||||
setLightNavigationBar(true)
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_user_info)
|
||||
setStatusbarColorAuto()
|
||||
setNavigationBarColorPrimary()
|
||||
setTaskDescriptionColorAuto()
|
||||
setLightNavigationBar(true)
|
||||
|
||||
setupToolbar()
|
||||
applyToolbar(toolbar)
|
||||
|
||||
MaterialUtil.setTint(nameContainer, false)
|
||||
name.setText(PreferenceUtil.getInstance(this).userName)
|
||||
MaterialUtil.setTint(nameContainer, false)
|
||||
name.setText(PreferenceUtil.getInstance(this).userName)
|
||||
|
||||
if (PreferenceUtil.getInstance(this).profileImage.isNotEmpty()) {
|
||||
loadImageFromStorage(PreferenceUtil.getInstance(this).profileImage)
|
||||
}
|
||||
if (PreferenceUtil.getInstance(this).bannerImage.isNotEmpty()) {
|
||||
loadBannerFromStorage(PreferenceUtil.getInstance(this).bannerImage)
|
||||
}
|
||||
userImage.setOnClickListener {
|
||||
MaterialDialog(this, BottomSheet(LayoutMode.WRAP_CONTENT)).show {
|
||||
title(text = getString(R.string.set_photo))
|
||||
listItems(
|
||||
items = listOf(
|
||||
getString(R.string.new_profile_photo),
|
||||
getString(R.string.remove_profile_photo)
|
||||
)
|
||||
) { _, position, _ ->
|
||||
when (position) {
|
||||
0 -> pickNewPhoto()
|
||||
1 -> PreferenceUtil.getInstance(this@UserInfoActivity).saveProfileImage("")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
bannerSelect.setOnClickListener {
|
||||
showBannerOptions()
|
||||
}
|
||||
next.setOnClickListener {
|
||||
val nameString = name.text.toString().trim { it <= ' ' }
|
||||
if (TextUtils.isEmpty(nameString)) {
|
||||
Toast.makeText(this, "Umm name is empty", Toast.LENGTH_SHORT).show()
|
||||
return@setOnClickListener
|
||||
}
|
||||
/*val bioString = bio.text.toString().trim() { it <= ' ' }
|
||||
if (TextUtils.isEmpty(bioString)) {
|
||||
Toast.makeText(this, "Umm bio is empty", Toast.LENGTH_SHORT).show()
|
||||
return@setOnClickListener
|
||||
if (PreferenceUtil.getInstance(this).profileImage.isNotEmpty()) {
|
||||
loadImageFromStorage(PreferenceUtil.getInstance(this).profileImage)
|
||||
}
|
||||
if (PreferenceUtil.getInstance(this).bannerImage.isNotEmpty()) {
|
||||
loadBannerFromStorage(PreferenceUtil.getInstance(this).bannerImage)
|
||||
}
|
||||
userImage.setOnClickListener {
|
||||
MaterialDialog(this, BottomSheet(LayoutMode.WRAP_CONTENT)).show {
|
||||
cornerRadius(PreferenceUtil.getInstance(this@UserInfoActivity).dialogCorner)
|
||||
title(text = getString(R.string.set_photo))
|
||||
listItems(items = listOf(getString(R.string.new_profile_photo), getString(R.string.remove_profile_photo))) { _, position, _ ->
|
||||
when (position) {
|
||||
0 -> pickNewPhoto()
|
||||
1 -> PreferenceUtil.getInstance(this@UserInfoActivity).saveProfileImage("")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
bannerSelect.setOnClickListener {
|
||||
MaterialDialog(this, BottomSheet(LayoutMode.WRAP_CONTENT)).show {
|
||||
cornerRadius(PreferenceUtil.getInstance(this@UserInfoActivity).dialogCorner)
|
||||
title(R.string.select_banner_photo)
|
||||
listItems(items = listOf(getString(R.string.new_banner_photo), getString(R.string.remove_banner_photo)))
|
||||
{ _, position, _ ->
|
||||
when (position) {
|
||||
0 -> selectBannerImage()
|
||||
1 -> PreferenceUtil.getInstance(this@UserInfoActivity).setBannerImagePath("")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
next.setOnClickListener {
|
||||
val nameString = name.text.toString().trim { it <= ' ' }
|
||||
if (TextUtils.isEmpty(nameString)) {
|
||||
Toast.makeText(this, "Umm name is empty", Toast.LENGTH_SHORT).show()
|
||||
return@setOnClickListener
|
||||
}
|
||||
PreferenceUtil.getInstance(this).userName = nameString
|
||||
setResult(Activity.RESULT_OK)
|
||||
finish()
|
||||
}
|
||||
next.backgroundTintList = ColorStateList.valueOf(ThemeStore.accentColor(this))
|
||||
ColorStateList.valueOf(MaterialValueHelper.getPrimaryTextColor(this, ColorUtil.isColorLight(ThemeStore.accentColor(this))))
|
||||
.apply {
|
||||
next.setTextColor(this)
|
||||
next.iconTint = this
|
||||
}
|
||||
}
|
||||
|
||||
}*/
|
||||
PreferenceUtil.getInstance(this).userName = nameString
|
||||
//PreferenceUtil.getInstance().userBio = bioString
|
||||
setResult(Activity.RESULT_OK)
|
||||
finish()
|
||||
}
|
||||
next.backgroundTintList = ColorStateList.valueOf(ThemeStore.accentColor(this))
|
||||
ColorStateList.valueOf(
|
||||
MaterialValueHelper.getPrimaryTextColor(
|
||||
this,
|
||||
ColorUtil.isColorLight(
|
||||
ThemeStore.accentColor(
|
||||
this
|
||||
)
|
||||
)
|
||||
)
|
||||
).apply {
|
||||
next.setTextColor(this)
|
||||
next.iconTint = this
|
||||
}
|
||||
}
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
if (item.itemId == android.R.id.home) {
|
||||
onBackPressed()
|
||||
}
|
||||
return super.onOptionsItemSelected(item)
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
if (item.itemId == android.R.id.home) {
|
||||
onBackPressed()
|
||||
}
|
||||
return super.onOptionsItemSelected(item)
|
||||
}
|
||||
private fun selectBannerImage() {
|
||||
val pickImageIntent = Intent(Intent.ACTION_PICK, Media.EXTERNAL_CONTENT_URI)
|
||||
pickImageIntent.type = "image/*"
|
||||
//pickImageIntent.putExtra("crop", "true")
|
||||
pickImageIntent.putExtra("outputX", 1290)
|
||||
pickImageIntent.putExtra("outputY", 720)
|
||||
pickImageIntent.putExtra("aspectX", 16)
|
||||
pickImageIntent.putExtra("aspectY", 9)
|
||||
pickImageIntent.putExtra("scale", true)
|
||||
//intent.setAction(Intent.ACTION_GET_CONTENT);
|
||||
startActivityForResult(
|
||||
Intent.createChooser(pickImageIntent, "Select Picture"),
|
||||
PICK_BANNER_REQUEST
|
||||
)
|
||||
}
|
||||
|
||||
private fun setupToolbar() {
|
||||
val primaryColor = ATHUtil.resolveColor(this, R.attr.colorPrimary)
|
||||
applyToolbar(toolbar)
|
||||
appBarLayout.setBackgroundColor(primaryColor)
|
||||
}
|
||||
private fun pickNewPhoto() {
|
||||
val pickImageIntent = Intent(Intent.ACTION_PICK, Media.EXTERNAL_CONTENT_URI)
|
||||
pickImageIntent.type = "image/*"
|
||||
pickImageIntent.putExtra("crop", "true")
|
||||
pickImageIntent.putExtra("outputX", 512)
|
||||
pickImageIntent.putExtra("outputY", 512)
|
||||
pickImageIntent.putExtra("aspectX", 1)
|
||||
pickImageIntent.putExtra("aspectY", 1)
|
||||
pickImageIntent.putExtra("scale", true)
|
||||
startActivityForResult(
|
||||
Intent.createChooser(pickImageIntent, "Select Picture"),
|
||||
PICK_IMAGE_REQUEST
|
||||
)
|
||||
}
|
||||
|
||||
private fun showBannerOptions() {
|
||||
MaterialDialog(this, BottomSheet(LayoutMode.WRAP_CONTENT)).show {
|
||||
title(R.string.select_banner_photo)
|
||||
listItems(
|
||||
items = listOf(
|
||||
getString(R.string.new_banner_photo),
|
||||
getString(R.string.remove_banner_photo)
|
||||
)
|
||||
) { _, position, _ ->
|
||||
when (position) {
|
||||
0 -> selectBannerImage()
|
||||
1 -> PreferenceUtil.getInstance(this@UserInfoActivity).setBannerImagePath("")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
super.onActivityResult(requestCode, resultCode, data)
|
||||
if (resultCode == Activity.RESULT_OK && data != null) {
|
||||
when (requestCode) {
|
||||
PICK_IMAGE_REQUEST -> {
|
||||
try {
|
||||
data.data?.let {
|
||||
val bitmap = getResizedBitmap(
|
||||
getBitmap(contentResolver, it),
|
||||
PROFILE_ICON_SIZE
|
||||
)
|
||||
val profileImagePath = saveToInternalStorage(bitmap, USER_PROFILE)
|
||||
PreferenceUtil.getInstance(this).saveProfileImage(profileImagePath)
|
||||
loadImageFromStorage(profileImagePath)
|
||||
}
|
||||
|
||||
private fun selectBannerImage() {
|
||||
} catch (e: IOException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
PICK_BANNER_REQUEST -> {
|
||||
try {
|
||||
data.data?.let {
|
||||
val bitmap = getBitmap(contentResolver, it)
|
||||
val profileImagePath = saveToInternalStorage(bitmap, USER_BANNER)
|
||||
PreferenceUtil.getInstance(this).setBannerImagePath(profileImagePath)
|
||||
loadBannerFromStorage(profileImagePath)
|
||||
}
|
||||
} catch (e: IOException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (TextUtils.isEmpty(PreferenceUtil.getInstance(this).bannerImage)) {
|
||||
val pickImageIntent = Intent(Intent.ACTION_PICK, Media.EXTERNAL_CONTENT_URI)
|
||||
pickImageIntent.type = "image/*"
|
||||
//pickImageIntent.putExtra("crop", "true")
|
||||
pickImageIntent.putExtra("outputX", 1290)
|
||||
pickImageIntent.putExtra("outputY", 720)
|
||||
pickImageIntent.putExtra("aspectX", 16)
|
||||
pickImageIntent.putExtra("aspectY", 9)
|
||||
pickImageIntent.putExtra("scale", true)
|
||||
//intent.setAction(Intent.ACTION_GET_CONTENT);
|
||||
startActivityForResult(
|
||||
Intent.createChooser(pickImageIntent, "Select Picture"),
|
||||
PICK_BANNER_REQUEST
|
||||
)
|
||||
} else {
|
||||
PreferenceUtil.getInstance(this).setBannerImagePath("")
|
||||
bannerImage.setImageResource(android.R.color.transparent)
|
||||
}
|
||||
}
|
||||
private fun getImagePathFromUri(aUri: Uri?): String? {
|
||||
var imagePath: String? = null
|
||||
if (aUri == null) {
|
||||
return imagePath
|
||||
}
|
||||
if (DocumentsContract.isDocumentUri(App.getContext(), aUri)) {
|
||||
val documentId = DocumentsContract.getDocumentId(aUri)
|
||||
if ("com.android.providers.media.documents" == aUri.authority) {
|
||||
val id = documentId.split(":".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()[1]
|
||||
val selection = Media._ID + "=" + id
|
||||
imagePath = getImagePath(Media.EXTERNAL_CONTENT_URI, selection)
|
||||
} else if ("com.android.providers.downloads.documents" == aUri.authority) {
|
||||
val contentUri = ContentUris.withAppendedId(
|
||||
Uri.parse("content://downloads/public_downloads"),
|
||||
java.lang.Long.valueOf(documentId)
|
||||
)
|
||||
imagePath = getImagePath(contentUri, null)
|
||||
}
|
||||
} else if ("content".equals(aUri.scheme!!, ignoreCase = true)) {
|
||||
imagePath = getImagePath(aUri, null)
|
||||
} else if ("file".equals(aUri.scheme!!, ignoreCase = true)) {
|
||||
imagePath = aUri.path
|
||||
}
|
||||
return imagePath
|
||||
}
|
||||
|
||||
private fun pickNewPhoto() {
|
||||
val pickImageIntent = Intent(Intent.ACTION_PICK, Media.EXTERNAL_CONTENT_URI)
|
||||
pickImageIntent.type = "image/*"
|
||||
pickImageIntent.putExtra("crop", "true")
|
||||
pickImageIntent.putExtra("outputX", 512)
|
||||
pickImageIntent.putExtra("outputY", 512)
|
||||
pickImageIntent.putExtra("aspectX", 1)
|
||||
pickImageIntent.putExtra("aspectY", 1)
|
||||
pickImageIntent.putExtra("scale", true)
|
||||
startActivityForResult(
|
||||
Intent.createChooser(pickImageIntent, "Select Picture"),
|
||||
PICK_IMAGE_REQUEST
|
||||
)
|
||||
}
|
||||
private fun getImagePath(aUri: Uri, aSelection: String?): String? {
|
||||
var path: String? = null
|
||||
val cursor = App.getContext().contentResolver.query(aUri, null, aSelection, null, null)
|
||||
if (cursor != null) {
|
||||
if (cursor.moveToFirst()) {
|
||||
path = cursor.getString(cursor.getColumnIndex(Media.DATA))
|
||||
}
|
||||
cursor.close()
|
||||
}
|
||||
return path
|
||||
}
|
||||
|
||||
public override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
super.onActivityResult(requestCode, resultCode, data)
|
||||
if (resultCode == Activity.RESULT_OK && data != null) {
|
||||
when (requestCode) {
|
||||
PICK_IMAGE_REQUEST -> {
|
||||
try {
|
||||
data.data?.let {
|
||||
val bitmap = getResizedBitmap(
|
||||
getBitmap(contentResolver, it),
|
||||
PROFILE_ICON_SIZE
|
||||
)
|
||||
val profileImagePath = saveToInternalStorage(bitmap, USER_PROFILE)
|
||||
PreferenceUtil.getInstance(this).saveProfileImage(profileImagePath)
|
||||
loadImageFromStorage(profileImagePath)
|
||||
}
|
||||
private fun loadBannerFromStorage(profileImagePath: String) {
|
||||
disposable.add(
|
||||
Compressor(this).setQuality(100).setCompressFormat(Bitmap.CompressFormat.WEBP).compressToBitmapAsFlowable(
|
||||
File(profileImagePath, USER_BANNER)
|
||||
).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(
|
||||
{ bitmap -> bannerImage.setImageBitmap(bitmap) },
|
||||
{ t -> println() })
|
||||
)
|
||||
}
|
||||
|
||||
} catch (e: IOException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
PICK_BANNER_REQUEST -> {
|
||||
try {
|
||||
data.data?.let {
|
||||
val bitmap = getBitmap(contentResolver, it)
|
||||
val profileImagePath = saveToInternalStorage(bitmap, USER_BANNER)
|
||||
PreferenceUtil.getInstance(this).setBannerImagePath(profileImagePath)
|
||||
loadBannerFromStorage(profileImagePath)
|
||||
}
|
||||
} catch (e: IOException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
private fun loadImageFromStorage(path: String) {
|
||||
disposable.add(
|
||||
Compressor(this).setMaxHeight(300).setMaxWidth(300).setQuality(75).setCompressFormat(
|
||||
Bitmap.CompressFormat.WEBP
|
||||
).compressToBitmapAsFlowable(
|
||||
File(
|
||||
path,
|
||||
USER_PROFILE
|
||||
)
|
||||
).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(
|
||||
{ bitmap -> userImage!!.setImageBitmap(bitmap) },
|
||||
{ t -> println() })
|
||||
)
|
||||
}
|
||||
|
||||
private fun getImagePathFromUri(aUri: Uri?): String? {
|
||||
var imagePath: String? = null
|
||||
if (aUri == null) {
|
||||
return imagePath
|
||||
}
|
||||
if (DocumentsContract.isDocumentUri(App.getContext(), aUri)) {
|
||||
val documentId = DocumentsContract.getDocumentId(aUri)
|
||||
if ("com.android.providers.media.documents" == aUri.authority) {
|
||||
val id = documentId.split(":".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()[1]
|
||||
val selection = Media._ID + "=" + id
|
||||
imagePath = getImagePath(Media.EXTERNAL_CONTENT_URI, selection)
|
||||
} else if ("com.android.providers.downloads.documents" == aUri.authority) {
|
||||
val contentUri = ContentUris.withAppendedId(
|
||||
Uri.parse("content://downloads/public_downloads"),
|
||||
java.lang.Long.valueOf(documentId)
|
||||
)
|
||||
imagePath = getImagePath(contentUri, null)
|
||||
}
|
||||
} else if ("content".equals(aUri.scheme!!, ignoreCase = true)) {
|
||||
imagePath = getImagePath(aUri, null)
|
||||
} else if ("file".equals(aUri.scheme!!, ignoreCase = true)) {
|
||||
imagePath = aUri.path
|
||||
}
|
||||
return imagePath
|
||||
}
|
||||
private fun saveToInternalStorage(bitmapImage: Bitmap, userBanner: String): String {
|
||||
val cw = ContextWrapper(this)
|
||||
val directory = cw.getDir("imageDir", Context.MODE_PRIVATE)
|
||||
val myPath = File(directory, userBanner)
|
||||
var fos: FileOutputStream? = null
|
||||
try {
|
||||
fos = FileOutputStream(myPath)
|
||||
// Use the compress method on the BitMap object to write image to the OutputStream
|
||||
bitmapImage.compress(Bitmap.CompressFormat.WEBP, 100, fos)
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
} finally {
|
||||
try {
|
||||
fos?.close()
|
||||
} catch (e: IOException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
return directory.absolutePath
|
||||
}
|
||||
|
||||
private fun getImagePath(aUri: Uri, aSelection: String?): String? {
|
||||
var path: String? = null
|
||||
val cursor = App.getContext().contentResolver.query(aUri, null, aSelection, null, null)
|
||||
if (cursor != null) {
|
||||
if (cursor.moveToFirst()) {
|
||||
path = cursor.getString(cursor.getColumnIndex(Media.DATA))
|
||||
}
|
||||
cursor.close()
|
||||
}
|
||||
return path
|
||||
}
|
||||
companion object {
|
||||
|
||||
private fun loadBannerFromStorage(profileImagePath: String) {
|
||||
disposable.add(
|
||||
Compressor(this).setQuality(100).setCompressFormat(Bitmap.CompressFormat.WEBP).compressToBitmapAsFlowable(
|
||||
File(profileImagePath, USER_BANNER)
|
||||
).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(
|
||||
{ bitmap -> bannerImage.setImageBitmap(bitmap) },
|
||||
{ t -> println() })
|
||||
)
|
||||
}
|
||||
|
||||
private fun loadImageFromStorage(path: String) {
|
||||
disposable.add(
|
||||
Compressor(this).setMaxHeight(300).setMaxWidth(300).setQuality(75).setCompressFormat(
|
||||
Bitmap.CompressFormat.WEBP
|
||||
).compressToBitmapAsFlowable(
|
||||
File(
|
||||
path,
|
||||
USER_PROFILE
|
||||
)
|
||||
).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(
|
||||
{ bitmap -> userImage!!.setImageBitmap(bitmap) },
|
||||
{ t -> println() })
|
||||
)
|
||||
}
|
||||
|
||||
private fun saveToInternalStorage(bitmapImage: Bitmap, userBanner: String): String {
|
||||
val cw = ContextWrapper(this)
|
||||
val directory = cw.getDir("imageDir", Context.MODE_PRIVATE)
|
||||
val myPath = File(directory, userBanner)
|
||||
var fos: FileOutputStream? = null
|
||||
try {
|
||||
fos = FileOutputStream(myPath)
|
||||
// Use the compress method on the BitMap object to write image to the OutputStream
|
||||
bitmapImage.compress(Bitmap.CompressFormat.WEBP, 100, fos)
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
} finally {
|
||||
try {
|
||||
fos?.close()
|
||||
} catch (e: IOException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
return directory.absolutePath
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
private const val PICK_IMAGE_REQUEST = 9002
|
||||
private const val PICK_BANNER_REQUEST = 9004
|
||||
private const val PROFILE_ICON_SIZE = 400
|
||||
}
|
||||
private const val PICK_IMAGE_REQUEST = 9002
|
||||
private const val PICK_BANNER_REQUEST = 9004
|
||||
private const val PROFILE_ICON_SIZE = 400
|
||||
}
|
||||
}
|
||||
|
||||
fun Activity.pickImage(requestCode: Int) {
|
||||
Intent(Intent.ACTION_GET_CONTENT).apply {
|
||||
addCategory(Intent.CATEGORY_OPENABLE)
|
||||
type = "image/*"
|
||||
startActivityForResult(this, requestCode)
|
||||
}
|
||||
Intent(Intent.ACTION_GET_CONTENT).apply {
|
||||
addCategory(Intent.CATEGORY_OPENABLE)
|
||||
type = "image/*"
|
||||
startActivityForResult(this, requestCode)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,7 +60,7 @@ public class WhatsNewActivity extends AbsBaseActivity {
|
|||
toolbar = findViewById(R.id.toolbar);
|
||||
appBarLayout = findViewById(R.id.appBarLayout);
|
||||
|
||||
int primaryColor = INSTANCE.resolveColor(this, R.attr.colorPrimary);
|
||||
int primaryColor = INSTANCE.resolveColor(this, R.attr.colorSurface);
|
||||
toolbar.setBackgroundColor(primaryColor);
|
||||
appBarLayout.setBackgroundColor(primaryColor);
|
||||
//setSupportActionBar(toolbar);
|
||||
|
@ -79,11 +79,10 @@ public class WhatsNewActivity extends AbsBaseActivity {
|
|||
|
||||
// Inject color values for WebView body background and links
|
||||
final boolean isDark = INSTANCE.isWindowBackgroundDark(this);
|
||||
final String backgroundColor = colorToCSS(INSTANCE.resolveColor(this, R.attr.colorPrimary, Color.parseColor(isDark ? "#424242" : "#ffffff")));
|
||||
final String backgroundColor = colorToCSS(INSTANCE.resolveColor(this, android.R.attr.windowBackground, Color.parseColor(isDark ? "#424242" : "#ffffff")));
|
||||
final String contentColor = colorToCSS(Color.parseColor(isDark ? "#ffffff" : "#000000"));
|
||||
final String changeLog = buf.toString()
|
||||
.replace("{style-placeholder}",
|
||||
String.format("body { background-color: %s; color: %s; }", backgroundColor, contentColor))
|
||||
.replace("{style-placeholder}", String.format("body { background-color: %s; color: %s; }", backgroundColor, contentColor))
|
||||
.replace("{link-color}", colorToCSS(ThemeStore.Companion.accentColor(this)))
|
||||
.replace("{link-color-active}", colorToCSS(ColorUtil.INSTANCE.lightenColor(ThemeStore.Companion.accentColor(this))));
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package code.name.monkey.retromusic.activities.base
|
||||
|
||||
import android.animation.ValueAnimator
|
||||
import android.annotation.SuppressLint
|
||||
import android.graphics.Color
|
||||
import android.graphics.Rect
|
||||
import android.os.Bundle
|
||||
|
@ -35,6 +34,7 @@ import code.name.monkey.retromusic.fragments.player.plain.PlainPlayerFragment
|
|||
import code.name.monkey.retromusic.fragments.player.simple.SimplePlayerFragment
|
||||
import code.name.monkey.retromusic.fragments.player.tiny.TinyPlayerFragment
|
||||
import code.name.monkey.retromusic.helper.MusicPlayerRemote
|
||||
import code.name.monkey.retromusic.model.CategoryInfo
|
||||
import code.name.monkey.retromusic.util.DensityUtil
|
||||
import code.name.monkey.retromusic.util.PreferenceUtil
|
||||
import code.name.monkey.retromusic.views.BottomNavigationBarTinted
|
||||
|
@ -114,13 +114,11 @@ abstract class AbsSlidingMusicPanelActivity : AbsMusicServiceActivity(), AbsPlay
|
|||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
bottomSheetBehavior.removeBottomSheetCallback(bottomSheetCallbackList)
|
||||
if (navigationBarColorAnimator != null) navigationBarColorAnimator!!.cancel() // just in case
|
||||
if (navigationBarColorAnimator != null) navigationBarColorAnimator?.cancel() // just in case
|
||||
}
|
||||
|
||||
protected fun wrapSlidingMusicPanel(@LayoutRes resId: Int): View {
|
||||
@SuppressLint("InflateParams") val slidingMusicPanelLayout = layoutInflater.inflate(
|
||||
R.layout.sliding_music_panel_layout, null
|
||||
)
|
||||
val slidingMusicPanelLayout = layoutInflater.inflate(R.layout.sliding_music_panel_layout, null)
|
||||
val contentContainer = slidingMusicPanelLayout.findViewById<ViewGroup>(R.id.mainContentFrame)
|
||||
layoutInflater.inflate(resId, contentContainer)
|
||||
return slidingMusicPanelLayout
|
||||
|
@ -143,7 +141,7 @@ abstract class AbsSlidingMusicPanelActivity : AbsMusicServiceActivity(), AbsPlay
|
|||
miniPlayerFragment?.view?.visibility = if (alpha == 0f) View.GONE else View.VISIBLE
|
||||
|
||||
bottomNavigationView.translationY = progress * 500
|
||||
bottomNavigationView.alpha = alpha
|
||||
//bottomNavigationView.alpha = alpha
|
||||
}
|
||||
|
||||
open fun onPanelCollapsed() {
|
||||
|
@ -296,13 +294,7 @@ abstract class AbsSlidingMusicPanelActivity : AbsMusicServiceActivity(), AbsPlay
|
|||
super.setLightNavigationBar(isColorLight)
|
||||
super.setLightStatusbar(isColorLight)
|
||||
} else {
|
||||
super.setLightStatusbar(
|
||||
ColorUtil.isColorLight(
|
||||
ATHUtil.resolveColor(
|
||||
this, R.attr.colorPrimary
|
||||
)
|
||||
)
|
||||
)
|
||||
super.setLightStatusbar(ColorUtil.isColorLight(ATHUtil.resolveColor(this, android.R.attr.windowBackground)))
|
||||
super.setLightNavigationBar(true)
|
||||
}
|
||||
}
|
||||
|
@ -339,15 +331,16 @@ abstract class AbsSlidingMusicPanelActivity : AbsMusicServiceActivity(), AbsPlay
|
|||
|
||||
private fun updateTabs() {
|
||||
bottomNavigationView.menu.clear()
|
||||
val currentTabs = PreferenceUtil.getInstance(this).libraryCategoryInfos
|
||||
val currentTabs: List<CategoryInfo> = PreferenceUtil.getInstance(this).libraryCategoryInfos
|
||||
for (tab in currentTabs) {
|
||||
if (tab.visible) {
|
||||
val menu = tab.category
|
||||
bottomNavigationView.menu.add(
|
||||
0, menu.id, 0, menu.stringRes
|
||||
).setIcon(menu.icon)
|
||||
bottomNavigationView.menu.add(0, menu.id, 0, menu.stringRes).setIcon(menu.icon)
|
||||
}
|
||||
}
|
||||
if (currentTabs.size <= 1) {
|
||||
toggleBottomNavigationView(true)
|
||||
}
|
||||
}
|
||||
|
||||
override fun dispatchTouchEvent(ev: MotionEvent?): Boolean {
|
||||
|
|
|
@ -91,11 +91,7 @@ abstract class AbsThemeActivity : ATHToolbarActivity(), Runnable {
|
|||
if (statusBar != null) {
|
||||
when {
|
||||
VersionUtils.hasMarshmallow() -> window.statusBarColor = color
|
||||
VersionUtils.hasLollipop() -> statusBar.setBackgroundColor(
|
||||
ColorUtil.darkenColor(
|
||||
color
|
||||
)
|
||||
)
|
||||
VersionUtils.hasLollipop() -> statusBar.setBackgroundColor(ColorUtil.darkenColor(color))
|
||||
else -> statusBar.setBackgroundColor(color)
|
||||
}
|
||||
} else {
|
||||
|
@ -104,12 +100,13 @@ abstract class AbsThemeActivity : ATHToolbarActivity(), Runnable {
|
|||
else -> window.statusBarColor = ColorUtil.darkenColor(color)
|
||||
}
|
||||
}
|
||||
setLightStatusbarAuto(color)
|
||||
setLightStatusbarAuto(ATHUtil.resolveColor(this, android.R.attr.windowBackground))
|
||||
}
|
||||
|
||||
fun setStatusbarColorAuto() {
|
||||
// we don't want to use statusbar color because we are doing the color darkening on our own to support KitKat
|
||||
//setStatusbarColor(ATHUtil.resolveColor(this, android.R.attr.windowBackground))
|
||||
setLightStatusbarAuto(ATHUtil.resolveColor(this, android.R.attr.windowBackground))
|
||||
}
|
||||
|
||||
open fun setTaskDescriptionColor(@ColorInt color: Int) {
|
||||
|
@ -117,7 +114,7 @@ abstract class AbsThemeActivity : ATHToolbarActivity(), Runnable {
|
|||
}
|
||||
|
||||
fun setTaskDescriptionColorAuto() {
|
||||
setTaskDescriptionColor(ATHUtil.resolveColor(this, R.attr.colorPrimary))
|
||||
setTaskDescriptionColor(ATHUtil.resolveColor(this, android.R.attr.windowBackground))
|
||||
}
|
||||
|
||||
open fun setNavigationbarColor(color: Int) {
|
||||
|
@ -129,11 +126,11 @@ abstract class AbsThemeActivity : ATHToolbarActivity(), Runnable {
|
|||
}
|
||||
|
||||
open fun setNavigationBarColorPrimary() {
|
||||
ATH.setNavigationbarColor(this, ATHUtil.resolveColor(this, R.attr.colorPrimary))
|
||||
ATH.setNavigationbarColor(this, ATHUtil.resolveColor(this, android.R.attr.windowBackground))
|
||||
}
|
||||
|
||||
fun setNavigationbarColorAuto() {
|
||||
setNavigationbarColor(ATHUtil.resolveColor(this, R.attr.colorSecondary))
|
||||
setNavigationbarColor(ATHUtil.resolveColor(this, android.R.attr.windowBackground))
|
||||
}
|
||||
|
||||
open fun setLightStatusbar(enabled: Boolean) {
|
||||
|
|
|
@ -1,21 +1,32 @@
|
|||
package code.name.monkey.retromusic.activities.bugreport
|
||||
|
||||
import android.app.*
|
||||
import android.content.*
|
||||
import android.app.Activity
|
||||
import android.app.Dialog
|
||||
import android.content.ClipData
|
||||
import android.content.ClipboardManager
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.text.TextUtils
|
||||
import android.view.MenuItem
|
||||
import android.view.inputmethod.EditorInfo
|
||||
import android.widget.Toast
|
||||
import androidx.annotation.*
|
||||
import androidx.annotation.StringDef
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import code.name.monkey.appthemehelper.ThemeStore
|
||||
import code.name.monkey.appthemehelper.util.*
|
||||
import code.name.monkey.appthemehelper.util.ATHUtil
|
||||
import code.name.monkey.appthemehelper.util.MaterialUtil
|
||||
import code.name.monkey.appthemehelper.util.TintHelper
|
||||
import code.name.monkey.appthemehelper.util.ToolbarContentTintHelper
|
||||
import code.name.monkey.retromusic.R
|
||||
import code.name.monkey.retromusic.activities.base.AbsThemeActivity
|
||||
import code.name.monkey.retromusic.activities.bugreport.model.*
|
||||
import code.name.monkey.retromusic.activities.bugreport.model.github.*
|
||||
import code.name.monkey.retromusic.activities.bugreport.model.DeviceInfo
|
||||
import code.name.monkey.retromusic.activities.bugreport.model.Report
|
||||
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.GithubTarget
|
||||
import code.name.monkey.retromusic.misc.DialogAsyncTask
|
||||
import com.afollestad.materialdialogs.MaterialDialog
|
||||
import com.afollestad.materialdialogs.callbacks.onCancel
|
||||
|
@ -25,7 +36,8 @@ import kotlinx.android.synthetic.main.activity_bug_report.*
|
|||
import kotlinx.android.synthetic.main.bug_report_card_device_info.*
|
||||
import kotlinx.android.synthetic.main.bug_report_card_report.*
|
||||
import org.eclipse.egit.github.core.Issue
|
||||
import org.eclipse.egit.github.core.client.*
|
||||
import org.eclipse.egit.github.core.client.GitHubClient
|
||||
import org.eclipse.egit.github.core.client.RequestException
|
||||
import org.eclipse.egit.github.core.service.IssueService
|
||||
import java.io.IOException
|
||||
|
||||
|
@ -52,7 +64,6 @@ open class BugReportActivity : AbsThemeActivity() {
|
|||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_bug_report)
|
||||
|
||||
setStatusbarColorAuto()
|
||||
setNavigationbarColorAuto()
|
||||
setTaskDescriptionColorAuto()
|
||||
|
@ -67,7 +78,7 @@ open class BugReportActivity : AbsThemeActivity() {
|
|||
|
||||
private fun initViews() {
|
||||
val accentColor = ThemeStore.accentColor(this)
|
||||
val primaryColor = ATHUtil.resolveColor(this, R.attr.colorPrimary)
|
||||
val primaryColor = ATHUtil.resolveColor(this, R.attr.colorSurface)
|
||||
toolbar.setBackgroundColor(primaryColor)
|
||||
setSupportActionBar(toolbar)
|
||||
ToolbarContentTintHelper.colorBackButton(toolbar)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue