mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 14:20:30 +05:30
commit
6a2364d5bc
@ -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 {
|
||||
|
@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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()
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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 {
|
||||
|
@ -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>
|
@ -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>
|
||||
|
||||
|
@ -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>
|
||||
|
||||
|
@ -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"
|
||||
|
@ -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>
|
@ -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,6 +7,12 @@
|
||||
android:orientation="vertical"
|
||||
tools:context=".fragments.SearchFragment">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/search_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<HorizontalScrollView
|
||||
android:id="@+id/filter_bar"
|
||||
android:layout_width="wrap_content"
|
||||
@ -23,6 +29,7 @@
|
||||
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">
|
||||
@ -75,4 +82,31 @@
|
||||
android:layout_height="wrap_content"
|
||||
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>
|
@ -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" />
|
||||
|
@ -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"
|
||||
|
@ -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>
|
@ -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"
|
||||
|
Loading…
Reference in New Issue
Block a user