Merge pull request #940 from Bnyro/master

fixes and UI improvements
This commit is contained in:
Bnyro 2022-08-01 09:18:03 +02:00 committed by GitHub
commit 6a2364d5bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 232 additions and 163 deletions

View File

@ -25,8 +25,9 @@ class ChannelAdapter(
}
fun updateItems(newItems: List<StreamItem>) {
val feedSize = videoFeed.size
videoFeed.addAll(newItems)
notifyDataSetChanged()
notifyItemRangeInserted(feedSize, newItems.size)
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ChannelViewHolder {

View File

@ -81,9 +81,8 @@ class LoginDialog : DialogFragment() {
Toast.makeText(context, R.string.loggedIn, Toast.LENGTH_SHORT).show()
PreferenceHelper.setToken(response.token!!)
PreferenceHelper.setUsername(login.username!!)
val restartDialog = RequireRestartDialog()
restartDialog.show(parentFragmentManager, "RequireRestartDialog")
dialog?.dismiss()
activity?.recreate()
}
}
}

View File

@ -19,7 +19,8 @@ fun View?.setWatchProgressLength(videoId: String, duration: Long) {
positions.forEach {
if (it.videoId == videoId) {
val fullWidth = (parent as LinearLayout).width
if (duration != 0L) newWidth = (fullWidth * (it.position / (duration))) / 1000
if (duration != 0L) newWidth =
(fullWidth * (it.position / (duration))) / 1000
return@forEach
}
}

View File

@ -83,7 +83,7 @@ class ChannelFragment : Fragment() {
if (nextPage != null && !isLoading) {
isLoading = true
binding.channelRefresh.isRefreshing = true
fetchNextPage()
fetchChannelNextPage()
}
}
}
@ -217,7 +217,7 @@ class ChannelFragment : Fragment() {
run()
}
private fun fetchNextPage() {
private fun fetchChannelNextPage() {
fun run() {
lifecycleScope.launchWhenCreated {
val response = try {

View File

@ -563,7 +563,11 @@ class PlayerFragment : Fragment() {
exoPlayer.pause()
// start the background mode
BackgroundHelper.playOnBackground(requireContext(), videoId!!)
BackgroundHelper.playOnBackground(
requireContext(),
videoId!!,
exoPlayer.currentPosition
)
}
binding.playerScrollView.viewTreeObserver
@ -1080,7 +1084,7 @@ class PlayerFragment : Fragment() {
})
// check if livestream
if (response.duration!! > 0) {
if (response.duration > 0) {
// download clicked
binding.relPlayerDownload.setOnClickListener {
if (!Globals.IS_DOWNLOAD_RUNNING) {
@ -1148,7 +1152,6 @@ class PlayerFragment : Fragment() {
binding.playerMotionLayout.transitionToEnd()
}
if (token != "") {
val channelId = response.uploaderUrl?.toID()
isSubscribed()
binding.relPlayerSave.setOnClickListener {
val newFragment = AddtoPlaylistDialog()
@ -1241,11 +1244,6 @@ class PlayerFragment : Fragment() {
}
}
private fun toggleController() {
if (exoPlayerView.isControllerFullyVisible) exoPlayerView.hideController()
else exoPlayerView.showController()
}
// enable seek bar preview
private fun enableSeekbarPreview() {
playerBinding.exoProgress.addListener(object : TimeBar.OnScrubListener {

View File

@ -15,7 +15,6 @@ import com.github.libretube.adapters.SearchHistoryAdapter
import com.github.libretube.adapters.SearchSuggestionsAdapter
import com.github.libretube.databinding.FragmentSearchBinding
import com.github.libretube.preferences.PreferenceHelper
import com.github.libretube.preferences.PreferenceKeys
import com.github.libretube.util.RetrofitInstance
import retrofit2.HttpException
import java.io.IOException
@ -43,23 +42,12 @@ class SearchFragment() : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
// add the query to the history
if (query != null) addToHistory(query!!)
binding.suggestionsRecycler.layoutManager = LinearLayoutManager(requireContext())
// fetch the search or history
if (query == null || query == "") showHistory()
else fetchSuggestions(query!!)
}
private fun addToHistory(query: String) {
val searchHistoryEnabled =
PreferenceHelper.getBoolean(PreferenceKeys.SEARCH_HISTORY_TOGGLE, true)
if (searchHistoryEnabled && query != "") {
PreferenceHelper.saveToSearchHistory(query)
}
}
private fun fetchSuggestions(query: String) {
fun run() {
lifecycleScope.launchWhenCreated {
@ -95,6 +83,9 @@ class SearchFragment() : Fragment() {
historyList,
(activity as MainActivity).searchView
)
} else {
binding.suggestionsRecycler.visibility = View.GONE
binding.historyEmpty.visibility = View.VISIBLE
}
}

View File

@ -11,6 +11,8 @@ import androidx.recyclerview.widget.LinearLayoutManager
import com.github.libretube.R
import com.github.libretube.adapters.SearchAdapter
import com.github.libretube.databinding.FragmentSearchResultBinding
import com.github.libretube.preferences.PreferenceHelper
import com.github.libretube.preferences.PreferenceKeys
import com.github.libretube.util.RetrofitInstance
import com.github.libretube.util.hideKeyboard
import retrofit2.HttpException
@ -43,6 +45,9 @@ class SearchResultFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
// add the query to the history
addToHistory(query)
// filter options
binding.filterChipGroup.setOnCheckedStateChangeListener { _, _ ->
apiSearchFilter = when (
@ -89,6 +94,9 @@ class SearchResultFragment : Fragment() {
binding.searchRecycler.layoutManager = LinearLayoutManager(requireContext())
searchAdapter = SearchAdapter(response.items, childFragmentManager)
binding.searchRecycler.adapter = searchAdapter
} else {
binding.searchContainer.visibility = View.GONE
binding.noSearchResult.visibility = View.VISIBLE
}
}
nextPage = response.nextpage!!
@ -120,6 +128,14 @@ class SearchResultFragment : Fragment() {
}
}
private fun addToHistory(query: String) {
val searchHistoryEnabled =
PreferenceHelper.getBoolean(PreferenceKeys.SEARCH_HISTORY_TOGGLE, true)
if (searchHistoryEnabled && query != "") {
PreferenceHelper.saveToSearchHistory(query)
}
}
private fun Fragment?.runOnUiThread(action: () -> Unit) {
this ?: return
if (!isAdded) return // Fragment not attached to an Activity

View File

@ -197,7 +197,8 @@ class SubscriptionsFragment : Fragment() {
binding.subRefresh.isRefreshing = false
}
if (response.isNotEmpty()) {
binding.subChannels.adapter = SubscriptionChannelAdapter(response.toMutableList())
binding.subChannels.adapter =
SubscriptionChannelAdapter(response.toMutableList())
} else {
Toast.makeText(context, R.string.subscribeIsEmpty, Toast.LENGTH_SHORT).show()
}

View File

@ -18,7 +18,8 @@ class NotificationSettings : PreferenceFragmentCompat() {
val settingsActivity = activity as SettingsActivity
settingsActivity.changeTopBarText(getString(R.string.notifications))
val notificationsEnabled = findPreference<SwitchPreferenceCompat>(PreferenceKeys.NOTIFICATION_ENABLED)
val notificationsEnabled =
findPreference<SwitchPreferenceCompat>(PreferenceKeys.NOTIFICATION_ENABLED)
notificationsEnabled?.setOnPreferenceChangeListener { _, _ ->
updateNotificationPrefs()
true

View File

@ -66,10 +66,10 @@ class BackgroundMode : Service() {
override fun onCreate() {
super.onCreate()
if (Build.VERSION.SDK_INT >= 26) {
val channelId = "background service"
val channelId = BACKGROUND_CHANNEL_ID
val channel = NotificationChannel(
channelId,
"BackgroundPlay Service",
"Background Service",
NotificationManager.IMPORTANCE_DEFAULT
)
val notificationManager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager
@ -77,7 +77,7 @@ class BackgroundMode : Service() {
val notification: Notification = Notification.Builder(this, channelId)
.setContentTitle(getString(R.string.app_name))
.setContentText(getString(R.string.playingOnBackground)).build()
startForeground(1, notification)
startForeground(PLAYER_NOTIFICATION_ID, notification)
}
}

View File

@ -8,7 +8,7 @@ object BackgroundHelper {
fun playOnBackground(
context: Context,
videoId: String,
position: Int? = null
position: Long? = null
) {
val intent = Intent(context, BackgroundMode::class.java)
intent.putExtra("videoId", videoId)

View File

@ -7,7 +7,8 @@ import androidx.work.WorkerParameters
/**
* The notification worker which checks for new streams in a certain frequency
*/
class NotificationWorker(appContext: Context, parameters: WorkerParameters) : Worker(appContext, parameters) {
class NotificationWorker(appContext: Context, parameters: WorkerParameters) :
Worker(appContext, parameters) {
private val TAG = "NotificationWorker"
override fun doWork(): Result {

View File

@ -36,9 +36,9 @@
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:stateListAnimator="@null"
android:text="@string/unsubscribe"
android:textColor="?android:attr/textColorPrimary"
android:textSize="12sp"
app:cornerRadius="20dp"
app:elevation="20dp"
android:text="@string/unsubscribe" />
app:elevation="20dp" />
</RelativeLayout>

View File

@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:background="?attr/selectableItemBackground"
android:backgroundTint="@android:color/transparent"
app:strokeWidth="0dp">
@ -24,13 +24,13 @@
<TextView
android:id="@+id/chapter_title"
tools:text="Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
android:ellipsize="end"
android:maxLines="3"
android:textSize="13sp" />
android:textSize="13sp"
tools:text="Title" />
</LinearLayout>

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<View
android:id="@id/exo_controls_background"
@ -172,15 +172,15 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginStart="5dp">
android:layout_marginStart="10dp">
<TextView
android:id="@id/exo_position"
style="@style/TimeString" />
<TextView
android:text=" • "
style="@style/TimeString"
android:text=" • "
tools:ignore="HardcodedText" />
<TextView
@ -194,7 +194,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginStart="5dp"
android:layout_marginStart="10dp"
android:visibility="gone">
<TextView
@ -210,8 +210,8 @@
<TextView
android:id="@+id/liveIndicator"
android:text="@string/live"
style="@style/TimeString" />
style="@style/TimeString"
android:text="@string/live" />
</LinearLayout>

View File

@ -376,9 +376,9 @@
<com.github.libretube.views.DoubleTapOverlay
android:id="@+id/doubleTapOverlay"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:layout_height="wrap_content" />
android:gravity="center" />
</com.github.libretube.views.CustomExoPlayerView>
@ -411,12 +411,12 @@
android:id="@+id/title_textView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:paddingVertical="15dp"
android:paddingStart="8dp"
android:paddingEnd="12dp"
android:alpha="0"
android:ellipsize="end"
android:maxLines="1"
android:paddingVertical="15dp"
android:paddingStart="8dp"
android:paddingEnd="12dp"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="@+id/play_imageView"
app:layout_constraintEnd_toStartOf="@+id/play_imageView"

View File

@ -11,4 +11,29 @@
android:layout_height="wrap_content"
android:layout_marginVertical="10dp" />
<LinearLayout
android:id="@+id/history_empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical"
android:visibility="gone">
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center"
android:layout_marginVertical="10dp"
android:src="@drawable/ic_history" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/history_empty"
android:textAlignment="center"
android:textSize="20sp"
android:textStyle="bold" />
</LinearLayout>
</FrameLayout>

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
@ -7,72 +7,106 @@
android:orientation="vertical"
tools:context=".fragments.SearchFragment">
<HorizontalScrollView
android:id="@+id/filter_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scrollbars="none"
app:layout_constraintBottom_toTopOf="@id/recycler_view"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<com.google.android.material.chip.ChipGroup
android:id="@+id/filter_chip_group"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingStart="8dp"
android:paddingEnd="8dp"
app:selectionRequired="true"
app:singleLine="true"
app:singleSelection="true">
<com.google.android.material.chip.Chip
android:id="@+id/chip_all"
style="@style/Chip"
android:text="@string/all" />
<com.google.android.material.chip.Chip
android:id="@+id/chip_videos"
style="@style/Chip"
android:text="@string/videos" />
<com.google.android.material.chip.Chip
android:id="@+id/chip_channels"
style="@style/Chip"
android:text="@string/channels" />
<com.google.android.material.chip.Chip
android:id="@+id/chip_playlists"
style="@style/Chip"
android:text="@string/playlists" />
<com.google.android.material.chip.Chip
android:id="@+id/chip_music_songs"
style="@style/Chip"
android:text="@string/music_songs" />
<com.google.android.material.chip.Chip
android:id="@+id/chip_music_videos"
style="@style/Chip"
android:text="@string/music_videos" />
<com.google.android.material.chip.Chip
android:id="@+id/chip_music_albums"
style="@style/Chip"
android:text="@string/music_albums" />
<com.google.android.material.chip.Chip
android:id="@+id/chip_music_playlists"
style="@style/Chip"
android:text="@string/music_playlists" />
</com.google.android.material.chip.ChipGroup>
</HorizontalScrollView>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/search_recycler"
<LinearLayout
android:id="@+id/search_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp" />
android:orientation="vertical">
</LinearLayout>
<HorizontalScrollView
android:id="@+id/filter_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scrollbars="none"
app:layout_constraintBottom_toTopOf="@id/recycler_view"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<com.google.android.material.chip.ChipGroup
android:id="@+id/filter_chip_group"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingStart="8dp"
android:paddingEnd="8dp"
app:checkedChip="@id/chip_all"
app:selectionRequired="true"
app:singleLine="true"
app:singleSelection="true">
<com.google.android.material.chip.Chip
android:id="@+id/chip_all"
style="@style/Chip"
android:text="@string/all" />
<com.google.android.material.chip.Chip
android:id="@+id/chip_videos"
style="@style/Chip"
android:text="@string/videos" />
<com.google.android.material.chip.Chip
android:id="@+id/chip_channels"
style="@style/Chip"
android:text="@string/channels" />
<com.google.android.material.chip.Chip
android:id="@+id/chip_playlists"
style="@style/Chip"
android:text="@string/playlists" />
<com.google.android.material.chip.Chip
android:id="@+id/chip_music_songs"
style="@style/Chip"
android:text="@string/music_songs" />
<com.google.android.material.chip.Chip
android:id="@+id/chip_music_videos"
style="@style/Chip"
android:text="@string/music_videos" />
<com.google.android.material.chip.Chip
android:id="@+id/chip_music_albums"
style="@style/Chip"
android:text="@string/music_albums" />
<com.google.android.material.chip.Chip
android:id="@+id/chip_music_playlists"
style="@style/Chip"
android:text="@string/music_playlists" />
</com.google.android.material.chip.ChipGroup>
</HorizontalScrollView>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/search_recycler"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp" />
</LinearLayout>
<LinearLayout
android:id="@+id/no_search_result"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical"
android:visibility="gone">
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center"
android:layout_marginVertical="10dp"
android:src="@drawable/ic_search" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/no_search_result"
android:textAlignment="center"
android:textSize="20sp"
android:textStyle="bold" />
</LinearLayout>
</FrameLayout>

View File

@ -120,9 +120,9 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:layout_marginBottom="5dp"
android:drawablePadding="5dp"
android:paddingHorizontal="10dp"
android:layout_marginBottom="5dp"
android:text="@string/most_recent"
android:textSize="16sp"
app:drawableEndCompat="@drawable/ic_arrow_downward" />

View File

@ -4,11 +4,11 @@
<item
android:id="@+id/action_search"
android:focusableInTouchMode="true"
android:icon="@drawable/ic_search"
android:title="@string/search_hint"
app:showAsAction="ifRoom"
app:actionViewClass="androidx.appcompat.widget.SearchView"
android:focusableInTouchMode="true" />
app:showAsAction="ifRoom" />
<item
android:id="@+id/action_settings"

View File

@ -286,4 +286,5 @@
<string name="network_wifi">WiFi only</string>
<string name="translate">Translate</string>
<string name="translate_summary">Help by translating the app to the language you speak</string>
<string name="no_search_result">No results found.</string>
</resources>

View File

@ -6,10 +6,10 @@
<SwitchPreferenceCompat
android:icon="@drawable/ic_notification"
android:summary="@string/notify_new_streams_summary"
app:defaultValue="true"
app:key="notification_toggle"
app:title="@string/notify_new_streams"
android:summary="@string/notify_new_streams_summary"/>
app:title="@string/notify_new_streams" />
<ListPreference
android:icon="@drawable/ic_time"

View File

@ -2,53 +2,53 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<Preference
android:icon="@drawable/ic_settings"
android:summary="@string/general_summary"
app:key="general"
app:title="@string/general" />
<Preference
android:icon="@drawable/ic_settings"
android:summary="@string/general_summary"
app:key="general"
app:title="@string/general" />
<Preference
android:icon="@drawable/ic_server"
app:key="instance"
app:summary="@string/instance_summary"
app:title="@string/instance" />
<Preference
android:icon="@drawable/ic_server"
app:key="instance"
app:summary="@string/instance_summary"
app:title="@string/instance" />
<Preference
android:icon="@drawable/ic_color"
app:key="appearance"
app:summary="@string/appearance_summary"
app:title="@string/appearance" />
<Preference
android:icon="@drawable/ic_color"
app:key="appearance"
app:summary="@string/appearance_summary"
app:title="@string/appearance" />
<Preference
android:icon="@drawable/ic_block"
app:key="sponsorblock"
app:summary="@string/sponsorblock_summary"
app:title="@string/sponsorblock" />
<Preference
android:icon="@drawable/ic_block"
app:key="sponsorblock"
app:summary="@string/sponsorblock_summary"
app:title="@string/sponsorblock" />
<Preference
android:icon="@drawable/ic_movie"
app:key="player"
app:summary="@string/player_summary"
app:title="@string/audio_video" />
<Preference
android:icon="@drawable/ic_movie"
app:key="player"
app:summary="@string/player_summary"
app:title="@string/audio_video" />
<Preference
android:icon="@drawable/ic_history_filled"
android:summary="@string/history_summary"
app:key="history"
app:title="@string/history" />
<Preference
android:icon="@drawable/ic_history_filled"
android:summary="@string/history_summary"
app:key="history"
app:title="@string/history" />
<Preference
android:icon="@drawable/ic_notification"
android:summary="@string/notify_new_streams"
app:key="notifications"
app:title="@string/notifications" />
<Preference
android:icon="@drawable/ic_notification"
android:summary="@string/notify_new_streams"
app:key="notifications"
app:title="@string/notifications" />
<Preference
android:icon="@drawable/ic_list"
app:key="advanced"
app:summary="@string/advanced_summary"
app:title="@string/advanced" />
<Preference
android:icon="@drawable/ic_list"
app:key="advanced"
app:summary="@string/advanced_summary"
app:title="@string/advanced" />
<PreferenceCategory>