mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 22:30:30 +05:30
add alternative trending layout
This commit is contained in:
parent
ec306f83dc
commit
b60c63d48f
@ -33,6 +33,7 @@ object PreferenceKeys {
|
||||
const val APP_ICON = "icon_change"
|
||||
const val LEGACY_SUBSCRIPTIONS = "legacy_subscriptions"
|
||||
const val LEGACY_SUBSCRIPTIONS_COLUMNS = "legacy_subscriptions_columns"
|
||||
const val ALTERNATIVE_TRENDING_LAYOUT = "trending_layout"
|
||||
|
||||
/**
|
||||
* Instance
|
||||
|
@ -8,7 +8,9 @@ import android.view.ViewGroup
|
||||
import android.widget.Toast
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import com.github.libretube.R
|
||||
import com.github.libretube.adapters.ChannelAdapter
|
||||
import com.github.libretube.adapters.TrendingAdapter
|
||||
import com.github.libretube.api.RetrofitInstance
|
||||
import com.github.libretube.constants.PreferenceKeys
|
||||
@ -41,11 +43,6 @@ class HomeFragment : BaseFragment() {
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
val grid = PreferenceHelper.getString(
|
||||
PreferenceKeys.GRID_COLUMNS,
|
||||
resources.getInteger(R.integer.grid_items).toString()
|
||||
)
|
||||
|
||||
val regionPref = PreferenceHelper.getString(PreferenceKeys.REGION, "sys")
|
||||
|
||||
// get the system default country if auto region selected
|
||||
@ -57,15 +54,14 @@ class HomeFragment : BaseFragment() {
|
||||
regionPref
|
||||
}
|
||||
|
||||
binding.recview.layoutManager = GridLayoutManager(view.context, grid.toInt())
|
||||
fetchJson()
|
||||
fetchTrending()
|
||||
binding.homeRefresh.isEnabled = true
|
||||
binding.homeRefresh.setOnRefreshListener {
|
||||
fetchJson()
|
||||
fetchTrending()
|
||||
}
|
||||
}
|
||||
|
||||
private fun fetchJson() {
|
||||
private fun fetchTrending() {
|
||||
fun run() {
|
||||
lifecycleScope.launchWhenCreated {
|
||||
val response = try {
|
||||
@ -84,7 +80,29 @@ class HomeFragment : BaseFragment() {
|
||||
}
|
||||
runOnUiThread {
|
||||
binding.progressBar.visibility = View.GONE
|
||||
binding.recview.adapter = TrendingAdapter(response, childFragmentManager)
|
||||
if (
|
||||
PreferenceHelper.getBoolean(
|
||||
PreferenceKeys.ALTERNATIVE_TRENDING_LAYOUT,
|
||||
false
|
||||
)
|
||||
) {
|
||||
binding.recview.layoutManager = LinearLayoutManager(context)
|
||||
|
||||
binding.recview.adapter = ChannelAdapter(
|
||||
response.toMutableList(),
|
||||
childFragmentManager
|
||||
)
|
||||
} else {
|
||||
binding.recview.layoutManager = GridLayoutManager(
|
||||
context,
|
||||
PreferenceHelper.getString(
|
||||
PreferenceKeys.GRID_COLUMNS,
|
||||
resources.getInteger(R.integer.grid_items).toString()
|
||||
).toInt()
|
||||
)
|
||||
|
||||
binding.recview.adapter = TrendingAdapter(response, childFragmentManager)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -315,4 +315,5 @@
|
||||
<string name="device_info">Device Info</string>
|
||||
<string name="audio_video_summary">Quality and format</string>
|
||||
<string name="delete">Delete</string>
|
||||
<string name="trending_layout">Alternative trending layout</string>
|
||||
</resources>
|
||||
|
@ -94,6 +94,12 @@
|
||||
app:key="legacy_subscriptions_columns"
|
||||
app:title="@string/grid" />
|
||||
|
||||
<SwitchPreferenceCompat
|
||||
android:icon="@drawable/ic_trending"
|
||||
app:defaultValue="false"
|
||||
app:key="trending_layout"
|
||||
app:title="@string/trending_layout" />
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
</PreferenceScreen>
|
Loading…
Reference in New Issue
Block a user