Update LoadingFragment layout
Update the layout of LoadingFragment with a new error icon/text style.
This commit is contained in:
@@ -9,9 +9,15 @@ import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.appcompat.app.AppCompatDelegate
|
||||
import org.oxycblt.auxio.theme.accent
|
||||
|
||||
const val PERM_READ_EXTERNAL_STORAGE = 2488
|
||||
|
||||
class MainActivity : AppCompatActivity() {
|
||||
|
||||
override fun onCreateView(name: String, context: Context, attrs: AttributeSet): View? {
|
||||
// Debugging placeholder
|
||||
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
|
||||
|
||||
// Apply the theme
|
||||
setTheme(accent.second)
|
||||
|
||||
return super.onCreateView(name, context, attrs)
|
||||
@@ -19,9 +25,8 @@ class MainActivity : AppCompatActivity() {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_main)
|
||||
|
||||
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
|
||||
setContentView(R.layout.activity_main)
|
||||
|
||||
Log.d(this::class.simpleName, "Activity Created.")
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.databinding.DataBindingUtil
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.Observer
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import org.oxycblt.auxio.R
|
||||
@@ -41,14 +40,14 @@ class LoadingFragment : Fragment() {
|
||||
|
||||
loadingModel.musicRepoResponse.observe(
|
||||
viewLifecycleOwner,
|
||||
Observer { response ->
|
||||
{ response ->
|
||||
onMusicLoadResponse(response)
|
||||
}
|
||||
)
|
||||
|
||||
loadingModel.doRetry.observe(
|
||||
viewLifecycleOwner,
|
||||
Observer { retry ->
|
||||
{ retry ->
|
||||
onRetry(retry)
|
||||
}
|
||||
)
|
||||
@@ -59,7 +58,6 @@ class LoadingFragment : Fragment() {
|
||||
}
|
||||
|
||||
private fun onMusicLoadResponse(repoResponse: MusicLoaderResponse?) {
|
||||
|
||||
// Don't run this if the value is null, Which is what the value changes to after
|
||||
// this is run.
|
||||
repoResponse?.let { response ->
|
||||
@@ -73,13 +71,14 @@ class LoadingFragment : Fragment() {
|
||||
|
||||
binding.loadingBar.visibility = View.GONE
|
||||
binding.errorText.visibility = View.VISIBLE
|
||||
binding.resetButton.visibility = View.VISIBLE
|
||||
binding.statusIcon.visibility = View.VISIBLE
|
||||
binding.retryButton.visibility = View.VISIBLE
|
||||
|
||||
if (response == MusicLoaderResponse.NO_MUSIC) {
|
||||
binding.errorText.text = getString(R.string.error_no_music)
|
||||
} else {
|
||||
binding.errorText.text = getString(R.string.error_music_load_failed)
|
||||
}
|
||||
binding.errorText.text =
|
||||
if (response == MusicLoaderResponse.NO_MUSIC)
|
||||
getString(R.string.error_no_music)
|
||||
else
|
||||
getString(R.string.error_music_load_failed)
|
||||
}
|
||||
|
||||
loadingModel.doneWithResponse()
|
||||
@@ -90,7 +89,8 @@ class LoadingFragment : Fragment() {
|
||||
if (retry) {
|
||||
binding.loadingBar.visibility = View.VISIBLE
|
||||
binding.errorText.visibility = View.GONE
|
||||
binding.resetButton.visibility = View.GONE
|
||||
binding.statusIcon.visibility = View.GONE
|
||||
binding.retryButton.visibility = View.GONE
|
||||
|
||||
loadingModel.doneWithRetry()
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package org.oxycblt.auxio.loading
|
||||
|
||||
import android.app.Application
|
||||
import android.util.Log
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
@@ -29,8 +28,6 @@ class LoadingViewModel(private val app: Application) : ViewModel() {
|
||||
|
||||
init {
|
||||
startMusicRepo()
|
||||
|
||||
Log.d(this::class.simpleName, "ViewModel created.")
|
||||
}
|
||||
|
||||
private fun startMusicRepo() {
|
||||
@@ -52,9 +49,9 @@ class LoadingViewModel(private val app: Application) : ViewModel() {
|
||||
}
|
||||
|
||||
fun retry() {
|
||||
mDoRetry.value = true
|
||||
|
||||
startMusicRepo()
|
||||
|
||||
mDoRetry.value = true
|
||||
}
|
||||
|
||||
fun doneWithRetry() {
|
||||
|
||||
@@ -52,7 +52,7 @@ class MusicRepository {
|
||||
)
|
||||
}
|
||||
|
||||
return loader.response
|
||||
return MusicLoaderResponse.NO_MUSIC
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
@@ -51,6 +51,10 @@ class MusicLoader(private val resolver: ContentResolver) {
|
||||
return MusicLoaderResponse.FAILURE
|
||||
}
|
||||
|
||||
if (songs.size == 0) {
|
||||
return MusicLoaderResponse.NO_MUSIC
|
||||
}
|
||||
|
||||
return MusicLoaderResponse.DONE
|
||||
}
|
||||
|
||||
|
||||
@@ -12,8 +12,6 @@ class SongAdapter(private val data: List<Song>) : RecyclerView.Adapter<SongViewH
|
||||
override fun getItemCount(): Int = data.size
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SongViewHolder {
|
||||
val then = System.currentTimeMillis()
|
||||
|
||||
val binding = SongItemBinding.inflate(LayoutInflater.from(parent.context))
|
||||
|
||||
// Force the item to *actually* be the screen width so ellipsizing can work.
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
package org.oxycblt.auxio.recycler.viewholders
|
||||
|
||||
// Generic ClickListener
|
||||
class ClickListener<T>(val action: (T) -> Unit) {
|
||||
fun onClick(action: T) = action
|
||||
}
|
||||
Reference in New Issue
Block a user