Add progress bars on home screen while data is being fetched.
This commit is contained in:
parent
f7a5d4c2d5
commit
21a545d70a
|
@ -9,12 +9,12 @@ import com.github.apognu.otter.R
|
|||
import com.github.apognu.otter.utils.mustNormalizeUrl
|
||||
import com.squareup.picasso.Picasso
|
||||
import jp.wasabeef.picasso.transformations.RoundedCornersTransformation
|
||||
import kotlinx.android.synthetic.main.row_dummy.view.*
|
||||
import kotlinx.android.synthetic.main.row_home_media.view.*
|
||||
|
||||
class DummyAdapter(val context: Context?, val viewRes: Int = R.layout.row_dummy) : RecyclerView.Adapter<DummyAdapter.ViewHolder>() {
|
||||
data class DummyItem(val label: String, val cover: String?)
|
||||
class HomeMediaAdapter(val context: Context?, val viewRes: Int = R.layout.row_home_media) : RecyclerView.Adapter<HomeMediaAdapter.ViewHolder>() {
|
||||
data class HomeMediaItem(val label: String, val cover: String?)
|
||||
|
||||
var data: List<DummyItem> = listOf()
|
||||
var data: List<HomeMediaItem> = listOf()
|
||||
|
||||
override fun getItemCount() = data.size
|
||||
|
|
@ -7,7 +7,7 @@ import android.view.ViewGroup
|
|||
import androidx.fragment.app.Fragment
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import com.github.apognu.otter.R
|
||||
import com.github.apognu.otter.adapters.home.DummyAdapter
|
||||
import com.github.apognu.otter.adapters.home.HomeMediaAdapter
|
||||
import com.github.apognu.otter.repositories.Repository
|
||||
import com.github.apognu.otter.repositories.home.RecentlyAddedRepository
|
||||
import com.github.apognu.otter.repositories.home.RecentlyListenedRepository
|
||||
|
@ -25,10 +25,10 @@ class HomeFragment : Fragment() {
|
|||
private lateinit var recentlyAddedRepository: RecentlyAddedRepository
|
||||
private lateinit var recentlyListenedRepository: RecentlyListenedRepository
|
||||
|
||||
private lateinit var tagsAdapter: DummyAdapter
|
||||
private lateinit var recentlyAddedAdapter: DummyAdapter
|
||||
private lateinit var recentlyListenedAdapter: DummyAdapter
|
||||
private lateinit var dummyAdapter: DummyAdapter
|
||||
private lateinit var tagsAdapter: HomeMediaAdapter
|
||||
private lateinit var recentlyAddedAdapter: HomeMediaAdapter
|
||||
private lateinit var recentlyListenedAdapter: HomeMediaAdapter
|
||||
private lateinit var randomAdapter: HomeMediaAdapter
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
@ -37,10 +37,10 @@ class HomeFragment : Fragment() {
|
|||
recentlyAddedRepository = RecentlyAddedRepository(context)
|
||||
recentlyListenedRepository = RecentlyListenedRepository(context)
|
||||
|
||||
tagsAdapter = DummyAdapter(context, R.layout.row_tag)
|
||||
recentlyAddedAdapter = DummyAdapter(context)
|
||||
recentlyListenedAdapter = DummyAdapter(context)
|
||||
dummyAdapter = DummyAdapter(context)
|
||||
tagsAdapter = HomeMediaAdapter(context, R.layout.row_tag)
|
||||
recentlyAddedAdapter = HomeMediaAdapter(context)
|
||||
recentlyListenedAdapter = HomeMediaAdapter(context)
|
||||
randomAdapter = HomeMediaAdapter(context)
|
||||
}
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||
|
@ -58,7 +58,7 @@ class HomeFragment : Fragment() {
|
|||
}
|
||||
|
||||
random.apply {
|
||||
adapter = dummyAdapter
|
||||
adapter = randomAdapter
|
||||
layoutManager = LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false)
|
||||
}
|
||||
|
||||
|
@ -72,33 +72,37 @@ class HomeFragment : Fragment() {
|
|||
layoutManager = LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false)
|
||||
}
|
||||
|
||||
playlists.apply {
|
||||
adapter = dummyAdapter
|
||||
layoutManager = LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false)
|
||||
}
|
||||
|
||||
refresh()
|
||||
}
|
||||
|
||||
private fun refresh() {
|
||||
tagsRepository.fetch(Repository.Origin.Network.origin).untilNetwork(IO) {data, _, _ ->
|
||||
GlobalScope.launch(Main) {
|
||||
tagsAdapter.data = data.map { DummyAdapter.DummyItem(it.name, null) }
|
||||
tagsAdapter.data = data.map { HomeMediaAdapter.HomeMediaItem(it.name, null) }
|
||||
tagsAdapter.notifyDataSetChanged()
|
||||
|
||||
tags_loader.visibility = View.GONE
|
||||
tags.visibility = View.VISIBLE
|
||||
}
|
||||
}
|
||||
|
||||
recentlyListenedRepository.fetch(Repository.Origin.Network.origin).untilNetwork(IO) { data, _, _ ->
|
||||
GlobalScope.launch(Main) {
|
||||
recentlyListenedAdapter.data = data.map { DummyAdapter.DummyItem(it.track.title, it.track.album.cover.original) }
|
||||
recentlyListenedAdapter.data = data.map { HomeMediaAdapter.HomeMediaItem(it.track.title, it.track.album.cover.original) }
|
||||
recentlyListenedAdapter.notifyDataSetChanged()
|
||||
|
||||
recently_listened_loader.visibility = View.GONE
|
||||
recently_listened.visibility = View.VISIBLE
|
||||
}
|
||||
}
|
||||
|
||||
recentlyAddedRepository.fetch(Repository.Origin.Network.origin).untilNetwork(IO) { data, _, _ ->
|
||||
GlobalScope.launch(Main) {
|
||||
recentlyAddedAdapter.data = data.map { DummyAdapter.DummyItem(it.title, it.album.cover.original) }
|
||||
recentlyAddedAdapter.data = data.map { HomeMediaAdapter.HomeMediaItem(it.title, it.album.cover.original) }
|
||||
recentlyAddedAdapter.notifyDataSetChanged()
|
||||
|
||||
recently_added_loader.visibility = View.GONE
|
||||
recently_added.visibility = View.VISIBLE
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,12 +19,19 @@
|
|||
android:layout_marginBottom="16dp"
|
||||
android:text="Tags" />
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/tags_loader"
|
||||
android:layout_width="32dp"
|
||||
android:layout_height="32dp"
|
||||
android:layout_gravity="center_horizontal" />
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/tags"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:orientation="horizontal" />
|
||||
android:orientation="horizontal"
|
||||
android:visibility="gone" />
|
||||
|
||||
<TextView
|
||||
style="@style/AppTheme.Title"
|
||||
|
@ -36,12 +43,19 @@
|
|||
android:layout_marginBottom="16dp"
|
||||
android:text="Random picks" />
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/random_loader"
|
||||
android:layout_width="32dp"
|
||||
android:layout_height="32dp"
|
||||
android:layout_gravity="center_horizontal" />
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/random"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:orientation="horizontal" />
|
||||
android:orientation="horizontal"
|
||||
android:visibility="gone" />
|
||||
|
||||
<TextView
|
||||
style="@style/AppTheme.Title"
|
||||
|
@ -53,12 +67,19 @@
|
|||
android:layout_marginBottom="16dp"
|
||||
android:text="Recently listened" />
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/recently_listened_loader"
|
||||
android:layout_width="32dp"
|
||||
android:layout_height="32dp"
|
||||
android:layout_gravity="center_horizontal" />
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/recently_listened"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:orientation="horizontal" />
|
||||
android:orientation="horizontal"
|
||||
android:visibility="gone" />
|
||||
|
||||
<TextView
|
||||
style="@style/AppTheme.Title"
|
||||
|
@ -70,26 +91,16 @@
|
|||
android:layout_marginBottom="16dp"
|
||||
android:text="Newly uploaded" />
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/recently_added_loader"
|
||||
android:layout_width="32dp"
|
||||
android:layout_height="32dp"
|
||||
android:layout_gravity="center_horizontal" />
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/recently_added"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:orientation="horizontal" />
|
||||
|
||||
<TextView
|
||||
style="@style/AppTheme.Title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:text="Playlists and radios" />
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/playlists"
|
||||
android:layout_width="match_parent"
|
||||
android:visibility="gone"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:orientation="horizontal" />
|
||||
|
|
Loading…
Reference in New Issue