Merge pull request #1250 from Bnyro/master

Alternative trending layout
This commit is contained in:
Bnyro 2022-09-10 11:39:30 +02:00 committed by GitHub
commit aaabcfe701
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 36 additions and 61 deletions

View File

@ -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
@ -77,12 +78,6 @@ object PreferenceKeys {
*/
const val BACKGROUND_PLAYBACK_SPEED = "background_playback_speed"
/**
* Download
*/
const val DOWNLOAD_LOCATION = "download_location"
const val DOWNLOAD_FOLDER = "download_folder"
/**
* Notifications
*/

View File

@ -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)
}
}
}
}

View File

@ -641,19 +641,6 @@
<item>.mkv</item>
</string-array>
<string-array name="downloadLocation">
<item>@string/downloads_directory</item>
<item>@string/music_directory</item>
<item>@string/movies_directory</item>
<item>@string/sdcard</item>
</string-array>
<string-array name="downloadLocationValues">
<item>downloads</item>
<item>music</item>
<item>movies</item>
<item>sdcard</item>
</string-array>
<string-array name="bufferingGoal">
<item>50s</item>
<item>100s</item>

View File

@ -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>

View File

@ -2,38 +2,6 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<!--
<PreferenceCategory app:title="@string/downloads">
<ListPreference
android:defaultValue="downloads"
android:entries="@array/downloadLocation"
android:entryValues="@array/downloadLocationValues"
app:icon="@drawable/ic_download_filled"
app:key="download_location"
app:summary="@string/download_directory_summary"
app:title="@string/download_directory" />
<EditTextPreference
android:defaultValue="LibreTube"
app:icon="@drawable/ic_folder"
app:key="download_folder"
app:summary="@string/download_folder_summary"
app:title="@string/download_folder" />
</PreferenceCategory>
<PreferenceCategory app:title="@string/share">
<SwitchPreferenceCompat
app:defaultValue="true"
app:icon="@drawable/ic_time"
app:key="share_with_time_code"
app:title="@string/share_with_time" />
</PreferenceCategory>
-->
<PreferenceCategory app:title="@string/advanced">
<SwitchPreferenceCompat

View File

@ -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>