Add about dialog
Add an about dialog with information about this app.
This commit is contained in:
@@ -19,6 +19,7 @@ import org.oxycblt.auxio.ui.toColor
|
||||
// FIXME: Fix bug where fast navigation will break the animations and
|
||||
// lead to nothing being displayed [Possibly Un-fixable]
|
||||
// FIXME: Compat issue with Versions 5 that leads to progress bar looking off
|
||||
// TODO: Try to heavily refactor edge-to-edge
|
||||
class MainActivity : AppCompatActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
@@ -90,13 +90,8 @@ class CompactPlaybackFragment : Fragment() {
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
|
||||
playbackModel.disableAnimation()
|
||||
|
||||
// Use the caveman method of getting a view as storing the binding will cause a memory
|
||||
// leak.
|
||||
val playbackControls = binding.playbackControls
|
||||
|
||||
val iconPauseToPlay = ContextCompat.getDrawable(
|
||||
requireContext(), R.drawable.ic_pause_to_play
|
||||
) as AnimatedVectorDrawable
|
||||
@@ -109,19 +104,19 @@ class CompactPlaybackFragment : Fragment() {
|
||||
if (playbackModel.canAnimate) {
|
||||
if (it) {
|
||||
// Animate the icon transition when the playing status switches
|
||||
playbackControls?.setImageDrawable(iconPlayToPause)
|
||||
binding.playbackControls.setImageDrawable(iconPlayToPause)
|
||||
iconPlayToPause.start()
|
||||
} else {
|
||||
playbackControls?.setImageDrawable(iconPauseToPlay)
|
||||
binding.playbackControls.setImageDrawable(iconPauseToPlay)
|
||||
iconPauseToPlay.start()
|
||||
}
|
||||
} else {
|
||||
// Use static icons on the first firing of this observer so that the icons
|
||||
// don't animate on startup, which looks weird.
|
||||
if (it) {
|
||||
playbackControls?.setImageResource(R.drawable.ic_pause_large)
|
||||
binding.playbackControls.setImageResource(R.drawable.ic_pause_large)
|
||||
} else {
|
||||
playbackControls?.setImageResource(R.drawable.ic_play_large)
|
||||
binding.playbackControls.setImageResource(R.drawable.ic_play_large)
|
||||
}
|
||||
|
||||
playbackModel.enableAnimation()
|
||||
|
||||
@@ -28,7 +28,9 @@ import org.oxycblt.auxio.ui.toColor
|
||||
*/
|
||||
class PlaybackFragment : Fragment(), SeekBar.OnSeekBarChangeListener {
|
||||
private val playbackModel: PlaybackViewModel by activityViewModels()
|
||||
private val binding: FragmentPlaybackBinding by memberBinding(FragmentPlaybackBinding::inflate)
|
||||
private val binding: FragmentPlaybackBinding by memberBinding(FragmentPlaybackBinding::inflate) {
|
||||
binding.playbackSong.isSelected = false
|
||||
}
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
@@ -199,12 +201,6 @@ class PlaybackFragment : Fragment(), SeekBar.OnSeekBarChangeListener {
|
||||
return binding.root
|
||||
}
|
||||
|
||||
override fun onStop() {
|
||||
super.onStop()
|
||||
|
||||
binding.playbackSong.isSelected = false
|
||||
}
|
||||
|
||||
// Seeking callbacks
|
||||
override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) {
|
||||
if (fromUser) {
|
||||
|
||||
@@ -17,7 +17,8 @@ import org.oxycblt.auxio.music.BaseModel
|
||||
import org.oxycblt.auxio.music.Header
|
||||
import org.oxycblt.auxio.playback.PlaybackViewModel
|
||||
import org.oxycblt.auxio.playback.state.PlaybackMode
|
||||
import org.oxycblt.auxio.ui.isInIrregularLandscapeMode
|
||||
import org.oxycblt.auxio.settings.SettingsManager
|
||||
import org.oxycblt.auxio.ui.isIrregularLandscape
|
||||
|
||||
/**
|
||||
* A [Fragment] that contains both the user queue and the next queue, with the ability to
|
||||
@@ -49,7 +50,8 @@ class QueueFragment : Fragment() {
|
||||
findNavController().navigateUp()
|
||||
}
|
||||
|
||||
if (!requireActivity().isInIrregularLandscapeMode()) {
|
||||
if (!requireActivity().isIrregularLandscape() &&
|
||||
SettingsManager.getInstance().edgeEnabled) {
|
||||
setOnApplyWindowInsetsListener @Suppress("DEPRECATION") { _, insets ->
|
||||
val top = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||
insets.getInsets(WindowInsets.Type.systemBars()).top
|
||||
|
||||
@@ -5,7 +5,9 @@ import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.fragment.app.Fragment
|
||||
import org.oxycblt.auxio.R
|
||||
import org.oxycblt.auxio.databinding.FragmentSettingsBinding
|
||||
import org.oxycblt.auxio.settings.ui.AboutDialog
|
||||
|
||||
class SettingsFragment : Fragment() {
|
||||
override fun onCreateView(
|
||||
@@ -15,6 +17,13 @@ class SettingsFragment : Fragment() {
|
||||
): View {
|
||||
val binding = FragmentSettingsBinding.inflate(inflater)
|
||||
|
||||
binding.settingsToolbar.setOnMenuItemClickListener {
|
||||
if (it.itemId == R.id.action_open_about) {
|
||||
AboutDialog().show(childFragmentManager, "DIALOG")
|
||||
true
|
||||
} else false
|
||||
}
|
||||
|
||||
return binding.root
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ import org.oxycblt.auxio.R
|
||||
import org.oxycblt.auxio.logD
|
||||
import org.oxycblt.auxio.playback.PlaybackViewModel
|
||||
import org.oxycblt.auxio.recycler.DisplayMode
|
||||
import org.oxycblt.auxio.settings.adapters.AccentAdapter
|
||||
import org.oxycblt.auxio.settings.ui.AccentAdapter
|
||||
import org.oxycblt.auxio.ui.ACCENTS
|
||||
import org.oxycblt.auxio.ui.accent
|
||||
import org.oxycblt.auxio.ui.createToast
|
||||
|
||||
@@ -0,0 +1,121 @@
|
||||
package org.oxycblt.auxio.settings.ui
|
||||
|
||||
import android.app.Dialog
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.WindowManager
|
||||
import androidx.browser.customtabs.CustomTabsIntent
|
||||
import androidx.core.net.toUri
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
|
||||
import org.oxycblt.auxio.BuildConfig
|
||||
import org.oxycblt.auxio.R
|
||||
import org.oxycblt.auxio.databinding.FragmentAboutBinding
|
||||
import org.oxycblt.auxio.logD
|
||||
import org.oxycblt.auxio.logE
|
||||
import org.oxycblt.auxio.music.MusicStore
|
||||
import org.oxycblt.auxio.settings.SettingsManager
|
||||
import org.oxycblt.auxio.ui.createToast
|
||||
import org.oxycblt.auxio.ui.handleTransparentSystemBars
|
||||
import org.oxycblt.auxio.ui.handleTransparentSystemNavBar
|
||||
import org.oxycblt.auxio.ui.isIrregularLandscape
|
||||
import org.oxycblt.auxio.ui.isLandscape
|
||||
import org.oxycblt.auxio.ui.toColor
|
||||
import java.lang.Exception
|
||||
|
||||
class AboutDialog : BottomSheetDialogFragment() {
|
||||
override fun getTheme() = R.style.Theme_BottomSheetFix
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View {
|
||||
val binding = FragmentAboutBinding.inflate(layoutInflater)
|
||||
val musicStore = MusicStore.getInstance()
|
||||
val settingsManager = SettingsManager.getInstance()
|
||||
|
||||
// --- UI SETUP ---
|
||||
|
||||
// Apply edge-to-edge to the dialog if supported/enabled.
|
||||
if (settingsManager.edgeEnabled && !requireActivity().isIrregularLandscape()) {
|
||||
requireDialog().window?.apply {
|
||||
navigationBarColor = R.color.background.toColor(requireContext())
|
||||
handleTransparentSystemNavBar(resources.configuration)
|
||||
}
|
||||
}
|
||||
|
||||
binding.aboutVersion.text = BuildConfig.VERSION_NAME
|
||||
|
||||
binding.aboutCode.setOnClickListener { openLinkInBrowser(LINK_CODEBASE) }
|
||||
binding.aboutFaq.setOnClickListener { openLinkInBrowser(LINK_FAQ) }
|
||||
binding.aboutLicenses.setOnClickListener { openLinkInBrowser(LINK_LICENSES) }
|
||||
|
||||
binding.aboutSongCount.text = getString(
|
||||
R.string.format_songs_loaded, musicStore.songs.size.toString()
|
||||
)
|
||||
binding.aboutAuthor.text = getString(
|
||||
R.string.format_author, getString(R.string.author_oxycblt)
|
||||
)
|
||||
|
||||
logD("Dialog created.")
|
||||
|
||||
return binding.root
|
||||
}
|
||||
|
||||
private fun openLinkInBrowser(link: String) {
|
||||
check(link in LINKS) { "Invalid link." }
|
||||
|
||||
try {
|
||||
val tabsIntent = CustomTabsIntent.Builder()
|
||||
.setShareState(CustomTabsIntent.SHARE_STATE_ON)
|
||||
.setShowTitle(true)
|
||||
.build()
|
||||
|
||||
val uri = link.toUri()
|
||||
val manager = requireActivity().packageManager
|
||||
val browserCandidates = manager.queryIntentActivities(tabsIntent.intent, 0)
|
||||
|
||||
// If there are candidates for this link, then launch it through that.
|
||||
if (browserCandidates.size > 0) {
|
||||
tabsIntent.launchUrl(requireActivity(), uri)
|
||||
} else {
|
||||
// If there are no candidates, then fallback to another list of browsers
|
||||
|
||||
val browserIntent = Intent(Intent.ACTION_VIEW, uri)
|
||||
browserIntent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
|
||||
val fallbackCandidates = manager.queryIntentActivities(browserIntent, 0)
|
||||
|
||||
// If there are candidates here, then launch those.
|
||||
if (fallbackCandidates.size > 0) {
|
||||
requireActivity().startActivity(browserIntent)
|
||||
} else {
|
||||
// Otherwise they don't have a browser on their phone, meaning they should
|
||||
// just see an error.
|
||||
getString(R.string.error_no_browser).createToast(requireContext())
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
logE("Browser intent launching failed [Probably android's fault]")
|
||||
e.printStackTrace()
|
||||
|
||||
// Sometimes people have """""Browsers""""" on their phone according to android,
|
||||
// but they actually don't so here's a fallback for that.
|
||||
getString(R.string.error_no_browser).createToast(requireContext())
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
// TODO: Change dev to master
|
||||
private const val LINK_CODEBASE = "https://github.com/oxygencobalt/Auxio"
|
||||
private const val LINK_FAQ = "$LINK_CODEBASE/blob/master/FAQ.md"
|
||||
private const val LINK_LICENSES = "$LINK_CODEBASE/blob/master/LICENSES.md"
|
||||
|
||||
val LINKS = arrayOf(LINK_CODEBASE, LINK_FAQ, LINK_LICENSES)
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package org.oxycblt.auxio.settings.adapters
|
||||
package org.oxycblt.auxio.settings.ui
|
||||
|
||||
import android.content.res.ColorStateList
|
||||
import android.view.LayoutInflater
|
||||
@@ -22,9 +22,8 @@ import org.oxycblt.auxio.settings.SettingsManager
|
||||
* TODO: Make edge-to-edge work in irregular mode
|
||||
* @return True if we are in the irregular landscape mode, false if not.
|
||||
*/
|
||||
fun Activity.isInIrregularLandscapeMode(): Boolean {
|
||||
return SettingsManager.getInstance().edgeEnabled &&
|
||||
isLandscape(resources) &&
|
||||
fun Activity.isIrregularLandscape(): Boolean {
|
||||
return isLandscape(resources) &&
|
||||
!isSystemBarOnBottom(this)
|
||||
}
|
||||
|
||||
@@ -93,3 +92,31 @@ fun Window.handleTransparentSystemBars(config: Configuration) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle only the transparent navigation bar.
|
||||
*/
|
||||
fun Window.handleTransparentSystemNavBar(config: Configuration) {
|
||||
fun isNight() = config.uiMode and Configuration.UI_MODE_NIGHT_MASK == Configuration.UI_MODE_NIGHT_YES
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||
insetsController?.let { controller ->
|
||||
val appearance = WindowInsetsController.APPEARANCE_LIGHT_NAVIGATION_BARS
|
||||
|
||||
val mask = if (isNight()) 0 else appearance
|
||||
|
||||
controller.setSystemBarsAppearance(appearance, mask)
|
||||
}
|
||||
} else {
|
||||
val flags = decorView.systemUiVisibility
|
||||
|
||||
decorView.systemUiVisibility =
|
||||
if (isNight()) {
|
||||
flags and View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR.inv() and
|
||||
View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR.inv()
|
||||
} else {
|
||||
flags or View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR or
|
||||
View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,20 +16,21 @@ import kotlin.reflect.KProperty
|
||||
/**
|
||||
* A delegate that creates a binding that can be used as a member variable without nullability or
|
||||
* memory leaks.
|
||||
* @param bindingFactory The ViewBinding inflation method that should be used
|
||||
* @param onDestroy Any code that should be run when the binding is destroyed.
|
||||
*/
|
||||
fun <T : ViewBinding> Fragment.memberBinding(
|
||||
viewBindingFactory: (LayoutInflater) -> T,
|
||||
disposeEvents: T.() -> Unit = {}
|
||||
) = FragmentBinderDelegate(this, viewBindingFactory, disposeEvents)
|
||||
bindingFactory: (LayoutInflater) -> T, onDestroy: T.() -> Unit = {}
|
||||
) = FragmentBinderDelegate(this, bindingFactory, onDestroy)
|
||||
|
||||
/**
|
||||
* The delegate for the [binder] shortcut function.
|
||||
* The delegate for the [memberBinding] shortcut function.
|
||||
* Adapted from KAHelpers (https://github.com/FunkyMuse/KAHelpers/tree/master/viewbinding)
|
||||
*/
|
||||
class FragmentBinderDelegate<T : ViewBinding>(
|
||||
private val fragment: Fragment,
|
||||
private val binder: (LayoutInflater) -> T,
|
||||
private val disposeEvents: T.() -> Unit
|
||||
private val inflate: (LayoutInflater) -> T,
|
||||
private val onDestroy: T.() -> Unit
|
||||
) : ReadOnlyProperty<Fragment, T>, LifecycleObserver {
|
||||
private var fragmentBinding: T? = null
|
||||
|
||||
@@ -46,8 +47,8 @@ class FragmentBinderDelegate<T : ViewBinding>(
|
||||
override fun onCreate(owner: LifecycleOwner) {
|
||||
super.onCreate(owner)
|
||||
|
||||
viewLifecycleOwnerLiveData.observe(this@observeOwnerThroughCreation) { owner ->
|
||||
owner.viewOwner()
|
||||
viewLifecycleOwnerLiveData.observe(this@observeOwnerThroughCreation) {
|
||||
it.viewOwner()
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -69,13 +70,13 @@ class FragmentBinderDelegate<T : ViewBinding>(
|
||||
throw IllegalStateException("Fragment views are destroyed.")
|
||||
}
|
||||
|
||||
return binder(LayoutInflater.from(thisRef.requireContext())).also { fragmentBinding = it }
|
||||
return inflate(LayoutInflater.from(thisRef.requireContext())).also { fragmentBinding = it }
|
||||
}
|
||||
|
||||
@Suppress("UNUSED")
|
||||
@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
|
||||
fun dispose() {
|
||||
fragmentBinding?.disposeEvents()
|
||||
fragmentBinding?.onDestroy()
|
||||
fragmentBinding = null
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user