Skip to content

Commit

Permalink
Release 0.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
z-huang committed Jun 9, 2022
2 parents 561be17 + 1c4b6f8 commit 0fcdcaf
Show file tree
Hide file tree
Showing 50 changed files with 189 additions and 190 deletions.
6 changes: 4 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ android {
applicationId = "com.zionhuang.music"
minSdk = 26
targetSdk = 31
versionCode = 7
versionName = "0.3.0"
versionCode = 8
versionName = "0.3.1"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
applicationVariants.all {
Expand Down Expand Up @@ -89,7 +89,9 @@ materialThemeBuilder {
)) {
create("Material$name") {
lightThemeFormat = "ThemeOverlay.Light.%s"
lightThemeParent = "AppTheme"
darkThemeFormat = "ThemeOverlay.Dark.%s"
darkThemeParent = "AppTheme"
primaryColor = "#$color"
}
}
Expand Down
5 changes: 5 additions & 0 deletions app/src/debug/res/values/constants.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- App Name -->
<string name="app_name" translatable="false">Music Debug</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -148,17 +148,17 @@ class MainActivity : ThemedBindingActivity<ActivityMainBinding>(), NavController
private inner class BottomSheetCallback : BottomSheetBehavior.BottomSheetCallback() {
override fun onStateChanged(bottomSheet: View, @State newState: Int) {
bottomSheetCallback?.onStateChanged(bottomSheet, newState)
if (newState == STATE_COLLAPSED) {
if (newState == STATE_COLLAPSED && binding.mainContent.paddingBottom != dip(R.dimen.bottom_controls_sheet_peek_height)) {
ValueAnimator.ofInt(0, dip(R.dimen.bottom_controls_sheet_peek_height)).apply {
duration = 300L
duration = resources.getInteger(R.integer.motion_duration_medium).toLong()
interpolator = FastOutSlowInInterpolator()
addUpdateListener {
binding.mainContent.updatePadding(bottom = it.animatedValue as Int)
}
}.start()
} else if (newState == STATE_HIDDEN) {
} else if (newState == STATE_HIDDEN && binding.mainContent.paddingBottom != 0) {
ValueAnimator.ofInt(dip(R.dimen.bottom_controls_sheet_peek_height), 0).apply {
duration = 300L
duration = resources.getInteger(R.integer.motion_duration_medium).toLong()
interpolator = FastOutSlowInInterpolator()
addUpdateListener {
binding.mainContent.updatePadding(bottom = it.animatedValue as Int)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,31 @@
package com.zionhuang.music.ui.activities.base

import android.os.Bundle
import androidx.appcompat.app.AppCompatDelegate
import androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
import androidx.viewbinding.ViewBinding
import com.google.android.material.color.DynamicColors
import com.zionhuang.music.R
import com.zionhuang.music.extensions.preference
import com.zionhuang.music.extensions.sharedPreferences
import com.zionhuang.music.utils.livedata.ThemeUtil
import com.zionhuang.music.utils.livedata.ThemeUtil.DEFAULT_THEME

abstract class ThemedBindingActivity<T : ViewBinding> : BindingActivity<T>() {
override fun onCreate(savedInstanceState: Bundle?) {
// Fix preference type mismatch in 0.3.0
try {
sharedPreferences.getString(getString(R.string.pref_dark_theme), "MODE_FOLLOW_SYSTEM")!!.toInt()
} catch (e: Exception) {
sharedPreferences.edit()
.putString(getString(R.string.pref_dark_theme), MODE_NIGHT_FOLLOW_SYSTEM.toString())
.commit()
}

AppCompatDelegate.setDefaultNightMode(sharedPreferences.getString(getString(R.string.pref_dark_theme), MODE_NIGHT_FOLLOW_SYSTEM.toString())!!.toInt())
if (DynamicColors.isDynamicColorAvailable() && sharedPreferences.getBoolean(getString(R.string.pref_follow_system_accent), true)) {
DynamicColors.applyToActivityIfAvailable(this)
} else {
val colorTheme: String by preference(R.string.pref_theme_color, DEFAULT_THEME)
val darkTheme: String by preference(R.string.pref_dark_theme, getString(R.string.mode_night_follow_system))
setTheme(ThemeUtil.getColorThemeStyleRes(colorTheme, darkTheme))
setTheme(ThemeUtil.getColorThemeStyleRes(sharedPreferences.getString(getString(R.string.pref_theme_color), DEFAULT_THEME)!!))
}
super.onCreate(savedInstanceState)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ class ArtistsFragment : BindingFragment<LayoutRecyclerviewBinding>() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enterTransition = MaterialFadeThrough().apply { duration = 300L }
exitTransition = MaterialFadeThrough().apply { duration = 300L }
enterTransition = MaterialFadeThrough().setDuration(resources.getInteger(R.integer.motion_duration_large).toLong())
exitTransition = MaterialFadeThrough().setDuration(resources.getInteger(R.integer.motion_duration_large).toLong())
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
Expand All @@ -47,8 +47,8 @@ class ArtistsFragment : BindingFragment<LayoutRecyclerviewBinding>() {
layoutManager = LinearLayoutManager(requireContext())
adapter = artistsAdapter
addOnClickListener { position, view ->
exitTransition = MaterialElevationScale(false).apply { duration = 300L }
reenterTransition = MaterialElevationScale(true).apply { duration = 300L }
exitTransition = MaterialElevationScale(false).setDuration(resources.getInteger(R.integer.motion_duration_large).toLong())
reenterTransition = MaterialElevationScale(true).setDuration(resources.getInteger(R.integer.motion_duration_large).toLong())
val transitionName = getString(R.string.artist_songs_transition_name)
val extras = FragmentNavigatorExtras(view to transitionName)
val directions = ArtistsFragmentDirections.actionArtistsFragmentToArtistSongsFragment(artistsAdapter.getItemByPosition(position)!!.id!!)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.zionhuang.music.ui.fragments

import android.content.Intent
import android.os.Bundle
import android.support.v4.media.session.MediaControllerCompat
import android.support.v4.media.session.PlaybackStateCompat.STATE_NONE
import android.support.v4.media.session.PlaybackStateCompat.STATE_STOPPED
import android.view.LayoutInflater
Expand Down Expand Up @@ -105,7 +104,9 @@ class BottomControlsFragment : Fragment(), BottomSheetListener, MotionLayout.Tra

override fun onResume() {
super.onResume()
viewModel.mediaController.observe(viewLifecycleOwner, { mediaController: MediaControllerCompat? -> mediaWidgetsController.setMediaController(mediaController) })
viewModel.mediaController.observe(viewLifecycleOwner) {
mediaWidgetsController.setMediaController(it)
}
}

override fun onStop() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ class ExploreFragment : BindingFragment<FragmentExploreBinding>() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enterTransition = MaterialFadeThrough().apply { duration = 300L }
exitTransition = MaterialFadeThrough().apply { duration = 300L }
enterTransition = MaterialFadeThrough().setDuration(resources.getInteger(R.integer.motion_duration_large).toLong())
exitTransition = MaterialFadeThrough().setDuration(resources.getInteger(R.integer.motion_duration_large).toLong())
}

override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ class PlaylistsFragment : BindingFragment<LayoutRecyclerviewBinding>() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enterTransition = MaterialFadeThrough().apply { duration = 300L }
exitTransition = MaterialFadeThrough().apply { duration = 300L }
enterTransition = MaterialFadeThrough().setDuration(resources.getInteger(R.integer.motion_duration_large).toLong())
exitTransition = MaterialFadeThrough().setDuration(resources.getInteger(R.integer.motion_duration_large).toLong())
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
Expand All @@ -54,8 +54,8 @@ class PlaylistsFragment : BindingFragment<LayoutRecyclerviewBinding>() {
layoutManager = LinearLayoutManager(requireContext())
adapter = playlistsAdapter
addOnClickListener { position, view ->
exitTransition = MaterialElevationScale(false).apply { duration = 300L }
reenterTransition = MaterialElevationScale(true).apply { duration = 300L }
exitTransition = MaterialElevationScale(false).setDuration(resources.getInteger(R.integer.motion_duration_large).toLong())
reenterTransition = MaterialElevationScale(true).setDuration(resources.getInteger(R.integer.motion_duration_large).toLong())
val transitionName = getString(R.string.playlist_songs_transition_name)
val extras = FragmentNavigatorExtras(view to transitionName)
val directions = PlaylistsFragmentDirections.actionPlaylistsFragmentToPlaylistSongsFragment(playlistsAdapter.getItemByPosition(position)!!.playlistId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ class QueueFragment : BindingFragment<LayoutRecyclerviewBinding>() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enterTransition = MaterialFadeThrough().apply { duration = 300L }
exitTransition = MaterialFadeThrough().apply { duration = 300L }
enterTransition = MaterialFadeThrough().setDuration(resources.getInteger(R.integer.motion_duration_large).toLong())
exitTransition = MaterialFadeThrough().setDuration(resources.getInteger(R.integer.motion_duration_large).toLong())
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import android.content.Intent
import android.content.Intent.ACTION_VIEW
import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AppCompatDelegate.*
import androidx.appcompat.app.AppCompatDelegate.setDefaultNightMode
import androidx.core.net.toUri
import androidx.fragment.app.activityViewModels
import androidx.navigation.fragment.findNavController
Expand Down Expand Up @@ -49,12 +49,7 @@ class SettingsFragment : PreferenceFragmentCompat() {
}
}
findPreference<ListPreference>(getString(R.string.pref_dark_theme))?.setOnPreferenceChangeListener { _, newValue ->
setDefaultNightMode(when (newValue) {
getString(R.string.mode_night_no) -> MODE_NIGHT_NO
getString(R.string.mode_night_yes) -> MODE_NIGHT_YES
getString(R.string.mode_night_follow_system) -> MODE_NIGHT_FOLLOW_SYSTEM
else -> throw IllegalArgumentException()
})
setDefaultNightMode((newValue as String).toInt())
true
}

Expand Down Expand Up @@ -96,8 +91,8 @@ class SettingsFragment : PreferenceFragmentCompat() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enterTransition = MaterialFadeThrough().apply { duration = 300L }
exitTransition = MaterialFadeThrough().apply { duration = 300L }
enterTransition = MaterialFadeThrough().setDuration(resources.getInteger(R.integer.motion_duration_large).toLong())
exitTransition = MaterialFadeThrough().setDuration(resources.getInteger(R.integer.motion_duration_large).toLong())
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ class SongsFragment : BindingFragment<LayoutRecyclerviewBinding>() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enterTransition = MaterialFadeThrough().apply { duration = 300L }
exitTransition = MaterialFadeThrough().apply { duration = 300L }
enterTransition = MaterialFadeThrough().setDuration(resources.getInteger(R.integer.motion_duration_large).toLong())
exitTransition = MaterialFadeThrough().setDuration(resources.getInteger(R.integer.motion_duration_large).toLong())
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class YouTubeChannelFragment : BindingFragment<LayoutRecyclerviewBinding>() {
super.onCreate(savedInstanceState)
sharedElementEnterTransition = MaterialContainerTransform().apply {
drawingViewId = R.id.nav_host_fragment
duration = 300L
duration = resources.getInteger(R.integer.motion_duration_large).toLong()
scrimColor = Color.TRANSPARENT
setAllContainerColors(requireContext().resolveColor(R.attr.colorSurface))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class YouTubePlaylistFragment : BindingFragment<LayoutRecyclerviewBinding>() {
super.onCreate(savedInstanceState)
sharedElementEnterTransition = MaterialContainerTransform().apply {
drawingViewId = R.id.nav_host_fragment
duration = 300L
duration = resources.getInteger(R.integer.motion_duration_large).toLong()
scrimColor = Color.TRANSPARENT
setAllContainerColors(requireContext().resolveColor(R.attr.colorSurface))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class EditArtistDialog : AppCompatDialogFragment() {
val name = binding.textInput.editText?.text.toString()
GlobalScope.launch {
val existedArtist = SongRepository.getArtistByName(name)
if (existedArtist != null) {
if (existedArtist != null && existedArtist.id != artist.id) {
// name exists
withContext(Dispatchers.Main) {
MaterialAlertDialogBuilder(requireContext(), R.style.Dialog)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ class YouTubeSearchFragment : BindingFragment<FragmentSearchBinding>() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enterTransition = MaterialFadeThrough().apply { duration = 300L }
exitTransition = MaterialFadeThrough().apply { duration = 300L }
enterTransition = MaterialFadeThrough().setDuration(resources.getInteger(R.integer.motion_duration_large).toLong())
exitTransition = MaterialFadeThrough().setDuration(resources.getInteger(R.integer.motion_duration_large).toLong())
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
Expand Down Expand Up @@ -91,16 +91,16 @@ class YouTubeSearchFragment : BindingFragment<FragmentSearchBinding>() {
)
}
is PlaylistInfoItem -> {
exitTransition = MaterialElevationScale(false).apply { duration = 300L }
reenterTransition = MaterialElevationScale(true).apply { duration = 300L }
exitTransition = MaterialElevationScale(false).setDuration(resources.getInteger(R.integer.motion_duration_large).toLong())
reenterTransition = MaterialElevationScale(true).setDuration(resources.getInteger(R.integer.motion_duration_large).toLong())
val transitionName = getString(R.string.youtube_playlist_transition_name)
val extras = FragmentNavigatorExtras(view to transitionName)
val directions = YouTubeSearchFragmentDirections.actionSearchResultFragmentToYouTubePlaylistFragment(extractPlaylistId(item.url)!!)
findNavController().navigate(directions, extras)
}
is ChannelInfoItem -> {
exitTransition = MaterialElevationScale(false).apply { duration = 300L }
reenterTransition = MaterialElevationScale(true).apply { duration = 300L }
exitTransition = MaterialElevationScale(false).setDuration(resources.getInteger(R.integer.motion_duration_large).toLong())
reenterTransition = MaterialElevationScale(true).setDuration(resources.getInteger(R.integer.motion_duration_large).toLong())
val transitionName = getString(R.string.youtube_channel_transition_name)
val extras = FragmentNavigatorExtras(view to transitionName)
val directions = YouTubeSearchFragmentDirections.actionSearchResultFragmentToYouTubeChannelFragment(extractChannelId(item.url)!!)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ class YouTubeSuggestionFragment : BindingFragment<LayoutRecyclerviewBinding>() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enterTransition = MaterialFadeThrough().apply { duration = 300L }
exitTransition = MaterialFadeThrough().apply { duration = 300L }
enterTransition = MaterialFadeThrough().setDuration(resources.getInteger(R.integer.motion_duration_large).toLong())
exitTransition = MaterialFadeThrough().setDuration(resources.getInteger(R.integer.motion_duration_large).toLong())
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
Expand All @@ -53,9 +53,15 @@ class YouTubeSuggestionFragment : BindingFragment<LayoutRecyclerviewBinding>() {
}
}
viewModel.apply {
onFillQuery.observe(viewLifecycleOwner, { query -> searchView.setQuery(query, false) })
query.observe(viewLifecycleOwner, { query -> viewModel.fetchSuggestions(query) })
suggestions.observe(viewLifecycleOwner, { dataSet -> suggestionAdapter.setDataSet(dataSet) })
onFillQuery.observe(viewLifecycleOwner) { query ->
searchView.setQuery(query, false)
}
query.observe(viewLifecycleOwner) { query ->
viewModel.fetchSuggestions(query)
}
suggestions.observe(viewLifecycleOwner) { dataSet ->
suggestionAdapter.setDataSet(dataSet)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class ArtistSongsFragment : BindingFragment<LayoutRecyclerviewBinding>() {
super.onCreate(savedInstanceState)
sharedElementEnterTransition = MaterialContainerTransform().apply {
drawingViewId = R.id.nav_host_fragment
duration = 300L
duration = resources.getInteger(R.integer.motion_duration_large).toLong()
scrimColor = Color.TRANSPARENT
setAllContainerColors(requireContext().resolveColor(R.attr.colorSurface))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class PlaylistSongsEditFragment : BindingFragment<LayoutRecyclerviewBinding>() {
super.onCreate(savedInstanceState)
sharedElementEnterTransition = MaterialContainerTransform().apply {
drawingViewId = R.id.nav_host_fragment
duration = 300L
duration = resources.getInteger(R.integer.motion_duration_large).toLong()
scrimColor = Color.TRANSPARENT
setAllContainerColors(requireContext().resolveColor(R.attr.colorSurface))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class PlaylistSongsFragment : BindingFragment<LayoutRecyclerviewBinding>() {
super.onCreate(savedInstanceState)
sharedElementEnterTransition = MaterialContainerTransform().apply {
drawingViewId = R.id.nav_host_fragment
duration = 300L
duration = resources.getInteger(R.integer.motion_duration_large).toLong()
scrimColor = Color.TRANSPARENT
setAllContainerColors(requireContext().resolveColor(R.attr.colorSurface))
}
Expand Down
Loading

0 comments on commit 0fcdcaf

Please sign in to comment.