indicate empty history and results

This commit is contained in:
Bnyro 2022-08-01 09:17:36 +02:00
parent f4a4ad41bb
commit 346e3bbe80
18 changed files with 220 additions and 147 deletions

View File

@ -19,7 +19,8 @@ fun View?.setWatchProgressLength(videoId: String, duration: Long) {
positions.forEach { positions.forEach {
if (it.videoId == videoId) { if (it.videoId == videoId) {
val fullWidth = (parent as LinearLayout).width 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 return@forEach
} }
} }

View File

@ -563,7 +563,11 @@ class PlayerFragment : Fragment() {
exoPlayer.pause() exoPlayer.pause()
// start the background mode // start the background mode
BackgroundHelper.playOnBackground(requireContext(), videoId!!, exoPlayer.currentPosition) BackgroundHelper.playOnBackground(
requireContext(),
videoId!!,
exoPlayer.currentPosition
)
} }
binding.playerScrollView.viewTreeObserver binding.playerScrollView.viewTreeObserver

View File

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

View File

@ -7,11 +7,12 @@ import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import androidx.navigation.fragment.findNavController
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import com.github.libretube.R import com.github.libretube.R
import com.github.libretube.adapters.SearchAdapter import com.github.libretube.adapters.SearchAdapter
import com.github.libretube.databinding.FragmentSearchResultBinding 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.RetrofitInstance
import com.github.libretube.util.hideKeyboard import com.github.libretube.util.hideKeyboard
import retrofit2.HttpException import retrofit2.HttpException
@ -44,6 +45,9 @@ class SearchResultFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
// add the query to the history
addToHistory(query)
// filter options // filter options
binding.filterChipGroup.setOnCheckedStateChangeListener { _, _ -> binding.filterChipGroup.setOnCheckedStateChangeListener { _, _ ->
apiSearchFilter = when ( apiSearchFilter = when (
@ -90,6 +94,9 @@ class SearchResultFragment : Fragment() {
binding.searchRecycler.layoutManager = LinearLayoutManager(requireContext()) binding.searchRecycler.layoutManager = LinearLayoutManager(requireContext())
searchAdapter = SearchAdapter(response.items, childFragmentManager) searchAdapter = SearchAdapter(response.items, childFragmentManager)
binding.searchRecycler.adapter = searchAdapter binding.searchRecycler.adapter = searchAdapter
} else {
binding.searchContainer.visibility = View.GONE
binding.noSearchResult.visibility = View.VISIBLE
} }
} }
nextPage = response.nextpage!! nextPage = response.nextpage!!
@ -121,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) { private fun Fragment?.runOnUiThread(action: () -> Unit) {
this ?: return this ?: return
if (!isAdded) return // Fragment not attached to an Activity if (!isAdded) return // Fragment not attached to an Activity

View File

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

View File

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

View File

@ -7,7 +7,8 @@ import androidx.work.WorkerParameters
/** /**
* The notification worker which checks for new streams in a certain frequency * 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" private val TAG = "NotificationWorker"
override fun doWork(): Result { override fun doWork(): Result {

View File

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

View File

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

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<merge xmlns:tools="http://schemas.android.com/tools" <merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/apk/res-auto"> xmlns:tools="http://schemas.android.com/tools">
<View <View
android:id="@id/exo_controls_background" android:id="@id/exo_controls_background"
@ -179,8 +179,8 @@
style="@style/TimeString" /> style="@style/TimeString" />
<TextView <TextView
android:text=" • "
style="@style/TimeString" style="@style/TimeString"
android:text=" • "
tools:ignore="HardcodedText" /> tools:ignore="HardcodedText" />
<TextView <TextView
@ -210,8 +210,8 @@
<TextView <TextView
android:id="@+id/liveIndicator" android:id="@+id/liveIndicator"
android:text="@string/live" style="@style/TimeString"
style="@style/TimeString" /> android:text="@string/live" />
</LinearLayout> </LinearLayout>

View File

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

View File

@ -11,4 +11,29 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginVertical="10dp" /> 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> </FrameLayout>

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?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:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -7,6 +7,12 @@
android:orientation="vertical" android:orientation="vertical"
tools:context=".fragments.SearchFragment"> tools:context=".fragments.SearchFragment">
<LinearLayout
android:id="@+id/search_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<HorizontalScrollView <HorizontalScrollView
android:id="@+id/filter_bar" android:id="@+id/filter_bar"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -76,4 +82,31 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_margin="10dp" /> android:layout_margin="10dp" />
</LinearLayout> </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_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="end" android:layout_gravity="end"
android:layout_marginBottom="5dp"
android:drawablePadding="5dp" android:drawablePadding="5dp"
android:paddingHorizontal="10dp" android:paddingHorizontal="10dp"
android:layout_marginBottom="5dp"
android:text="@string/most_recent" android:text="@string/most_recent"
android:textSize="16sp" android:textSize="16sp"
app:drawableEndCompat="@drawable/ic_arrow_downward" /> app:drawableEndCompat="@drawable/ic_arrow_downward" />

View File

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

View File

@ -286,4 +286,5 @@
<string name="network_wifi">WiFi only</string> <string name="network_wifi">WiFi only</string>
<string name="translate">Translate</string> <string name="translate">Translate</string>
<string name="translate_summary">Help by translating the app to the language you speak</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> </resources>

View File

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