Merge pull request #865 from Bnyro/master

fixes
This commit is contained in:
Bnyro 2022-07-24 11:59:51 +02:00 committed by GitHub
commit c4c41e21f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 201 additions and 212 deletions

View File

@ -10,7 +10,6 @@ import com.github.libretube.fragments.SearchFragment
import com.github.libretube.preferences.PreferenceHelper
class SearchHistoryAdapter(
private val context: Context,
private var historyList: List<String>,
private val editText: EditText,
private val searchFragment: SearchFragment
@ -28,19 +27,19 @@ class SearchHistoryAdapter(
}
override fun onBindViewHolder(holder: SearchHistoryViewHolder, position: Int) {
val history = historyList[position]
val historyQuery = historyList[position]
holder.binding.apply {
historyText.text = history
historyText.text = historyQuery
deleteHistory.setOnClickListener {
historyList = historyList - history
PreferenceHelper.saveHistory(historyList)
historyList = historyList - historyQuery
PreferenceHelper.removeFromSearchHistory(historyQuery)
notifyDataSetChanged()
}
root.setOnClickListener {
editText.setText(history)
searchFragment.fetchSearch(history)
editText.setText(historyQuery)
searchFragment.fetchSearch(historyQuery)
}
}
}

View File

@ -47,8 +47,8 @@ class UpdateDialog(
private fun getDownloadUrl(updateInfo: UpdateInfo): String? {
val supportedArchitectures = Build.SUPPORTED_ABIS
supportedArchitectures.forEach { arch ->
updateInfo.assets.forEach { asset ->
if (asset.name.contains(arch)) return asset.browser_download_url
updateInfo.assets?.forEach { asset ->
if (asset.name?.contains(arch) == true) return asset.browser_download_url
}
}
return null

View File

@ -210,7 +210,7 @@ class PlayerFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
hideKeyboard()
context?.hideKeyboard(view)
setUserPrefs()

View File

@ -150,7 +150,7 @@ class SearchFragment : Fragment() {
binding.autoCompleteTextView.setOnEditorActionListener(
OnEditorActionListener { _, actionId, _ ->
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
hideKeyboard()
view?.let { context?.hideKeyboard(it) }
binding.searchRecycler.visibility = VISIBLE
binding.historyRecycler.visibility = GONE
fetchSearch(binding.autoCompleteTextView.text.toString())
@ -190,7 +190,7 @@ class SearchFragment : Fragment() {
}
lifecycleScope.launchWhenCreated {
isFetchingSearch = true
hideKeyboard()
view?.let { context?.hideKeyboard(it) }
val response = try {
RetrofitInstance.api.getSearchResults(query, apiSearchFilter)
} catch (e: IOException) {
@ -253,16 +253,15 @@ class SearchFragment : Fragment() {
override fun onStop() {
super.onStop()
hideKeyboard()
view?.let { context?.hideKeyboard(it) }
}
private fun showHistory() {
binding.searchRecycler.visibility = GONE
val historyList = PreferenceHelper.getHistory()
val historyList = PreferenceHelper.getSearchHistory()
if (historyList.isNotEmpty()) {
binding.historyRecycler.adapter =
SearchHistoryAdapter(
requireContext(),
historyList,
binding.autoCompleteTextView,
this
@ -274,20 +273,8 @@ class SearchFragment : Fragment() {
private fun addToHistory(query: String) {
val searchHistoryEnabled =
PreferenceHelper.getBoolean(PreferenceKeys.SEARCH_HISTORY_TOGGLE, true)
if (searchHistoryEnabled) {
var historyList = PreferenceHelper.getHistory()
if ((historyList.isNotEmpty() && historyList.contains(query)) || query == "") {
return
} else {
historyList = historyList + query
}
if (historyList.size > 10) {
historyList = historyList.takeLast(10)
}
PreferenceHelper.saveHistory(historyList)
if (searchHistoryEnabled && query != "") {
PreferenceHelper.saveToSearchHistory(query)
}
}
}

View File

@ -4,9 +4,7 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties
@JsonIgnoreProperties(ignoreUnknown = true)
data class ChapterSegment(
var title: String?,
var image: String?,
var start: Long?
) {
constructor() : this("", "", -1)
}
var title: String? = null,
var image: String? = null,
var start: Long? = null
)

View File

@ -4,17 +4,15 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties
@JsonIgnoreProperties(ignoreUnknown = true)
data class Comment(
val author: String?,
val commentId: String?,
val commentText: String?,
val commentedTime: String?,
val commentorUrl: String?,
val repliesPage: String?,
val hearted: Boolean?,
val likeCount: Int?,
val pinned: Boolean?,
val thumbnail: String?,
val verified: Boolean?
) {
constructor() : this("", "", "", "", "", "", null, 0, null, "", null)
}
val author: String? = null,
val commentId: String? = null,
val commentText: String? = null,
val commentedTime: String? = null,
val commentorUrl: String? = null,
val repliesPage: String? = null,
val hearted: Boolean? = null,
val likeCount: Int? = null,
val pinned: Boolean? = null,
val thumbnail: String? = null,
val verified: Boolean? = null
)

View File

@ -7,6 +7,4 @@ data class CommentsPage(
val comments: MutableList<Comment> = arrayListOf(),
val disabled: Boolean? = null,
val nextpage: String? = ""
) {
constructor() : this(arrayListOf(), null, "")
}
)

View File

@ -4,20 +4,18 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties
@JsonIgnoreProperties(ignoreUnknown = true)
data class PipedStream(
var url: String?,
var format: String?,
var quality: String?,
var mimeType: String?,
var codec: String?,
var videoOnly: Boolean?,
var bitrate: Int?,
var initStart: Int?,
var initEnd: Int?,
var indexStart: Int?,
var indexEnd: Int?,
var width: Int?,
var height: Int?,
var fps: Int?
) {
constructor() : this("", "", "", "", "", null, -1, -1, -1, -1, -1, -1, -1, -1)
}
var url: String? = null,
var format: String? = null,
var quality: String? = null,
var mimeType: String? = null,
var codec: String? = null,
var videoOnly: Boolean? = null,
var bitrate: Int? = null,
var initStart: Int? = null,
var initEnd: Int? = null,
var indexStart: Int? = null,
var indexEnd: Int? = null,
var width: Int? = null,
var height: Int? = null,
var fps: Int? = null
)

View File

@ -4,25 +4,23 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties
@JsonIgnoreProperties(ignoreUnknown = true)
data class SearchItem(
var url: String?,
var thumbnail: String?,
var uploaderName: String?,
var uploaded: Long?,
var shortDescription: String?,
var url: String? = null,
var thumbnail: String? = null,
var uploaderName: String? = null,
var uploaded: Long? = null,
var shortDescription: String? = null,
// Video only attributes
var title: String?,
var uploaderUrl: String?,
var uploaderAvatar: String?,
var uploadedDate: String?,
var duration: Long?,
var views: Long?,
var uploaderVerified: Boolean?,
var title: String? = null,
var uploaderUrl: String? = null,
var uploaderAvatar: String? = null,
var uploadedDate: String? = null,
var duration: Long? = null,
var views: Long? = null,
var uploaderVerified: Boolean? = null,
// Channel and Playlist attributes
var name: String? = null,
var description: String? = null,
var subscribers: Long? = -1,
var videos: Long? = -1,
var verified: Boolean? = null
) {
constructor() : this("", "", "", 0, "", "", "", "", "", 0, 0, null)
}
)

View File

@ -4,9 +4,7 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties
@JsonIgnoreProperties(ignoreUnknown = true)
data class Segment(
val actionType: String?,
val category: String?,
val segment: List<Float>?
) {
constructor() : this("", "", arrayListOf())
}
val actionType: String? = null,
val category: String? = null,
val segment: List<Float>? = arrayListOf()
)

View File

@ -5,6 +5,4 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties
@JsonIgnoreProperties(ignoreUnknown = true)
data class Segments(
val segments: MutableList<Segment> = arrayListOf()
) {
constructor() : this(arrayListOf())
}
)

View File

@ -4,18 +4,16 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties
@JsonIgnoreProperties(ignoreUnknown = true)
data class StreamItem(
var url: String?,
var title: String?,
var thumbnail: String?,
var uploaderName: String?,
var uploaderUrl: String?,
var uploaderAvatar: String?,
var uploadedDate: String?,
var duration: Long?,
var views: Long?,
var uploaderVerified: Boolean?,
var uploaded: Long?,
var shortDescription: String?
) {
constructor() : this("", "", "", "", "", "", "", 0, 0, null, 0, "")
}
var url: String? = null,
var title: String? = null,
var thumbnail: String? = null,
var uploaderName: String? = null,
var uploaderUrl: String? = null,
var uploaderAvatar: String? = null,
var uploadedDate: String? = null,
var duration: Long? = null,
var views: Long? = null,
var uploaderVerified: Boolean? = null,
var uploaded: Long? = null,
var shortDescription: String? = null
)

View File

@ -4,11 +4,9 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties
@JsonIgnoreProperties(ignoreUnknown = true)
data class Subtitle(
val url: String?,
val mimeType: String?,
val name: String?,
val code: String?,
val autoGenerated: Boolean?
) {
constructor() : this("", "", "", "", null)
}
val url: String? = null,
val mimeType: String? = null,
val name: String? = null,
val code: String? = null,
val autoGenerated: Boolean? = null
)

View File

@ -1,12 +1,12 @@
package com.github.libretube.obj
data class WatchHistoryItem(
val videoId: String?,
val title: String?,
val uploadDate: String?,
val uploader: String?,
val uploaderUrl: String?,
val uploaderAvatar: String?,
val thumbnailUrl: String?,
val duration: Int?
val videoId: String? = null,
val title: String? = null,
val uploadDate: String? = null,
val uploader: String? = null,
val uploaderUrl: String? = null,
val uploaderAvatar: String? = null,
val thumbnailUrl: String? = null,
val duration: Int? = null
)

View File

@ -1,6 +1,6 @@
package com.github.libretube.obj
data class WatchPosition(
val videoId: String,
val position: Long
val videoId: String = "",
val position: Long = 0L
)

View File

@ -114,17 +114,41 @@ object PreferenceHelper {
}
}
fun getHistory(): List<String> {
fun getSearchHistory(): List<String> {
return try {
val set: Set<String> = settings.getStringSet("search_history", HashSet())!!
val set: Set<String> = settings.getStringSet("search_history", LinkedHashSet())!!
set.toList()
} catch (e: Exception) {
emptyList()
}
}
fun saveHistory(historyList: List<String>) {
val set: Set<String> = HashSet(historyList)
fun saveToSearchHistory(query: String) {
var historyList = getSearchHistory().toMutableList()
if ((historyList.contains(query))) {
// remove from history list if already contained
historyList -= query
}
// append new query to history
historyList.add(0, query)
if (historyList.size > 10) {
historyList.removeAt(historyList.size - 1)
}
updateSearchHistory(historyList)
}
fun removeFromSearchHistory(query: String) {
val historyList = getSearchHistory().toMutableList()
historyList -= query
updateSearchHistory(historyList)
}
private fun updateSearchHistory(historyList: List<String>) {
val set: Set<String> = LinkedHashSet(historyList)
editor.putStringSet("search_history", set).apply()
}

View File

@ -4,17 +4,17 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties
@JsonIgnoreProperties(ignoreUnknown = true)
data class Asset(
val browser_download_url: String,
val content_type: String,
val created_at: String,
val download_count: Int,
val id: Int,
val label: Any,
val name: String,
val node_id: String,
val size: Int,
val state: String,
val updated_at: String,
val uploader: Uploader,
val url: String
val browser_download_url: String? = null,
val content_type: String? = null,
val created_at: String? = null,
val download_count: Int? = null,
val id: Int? = null,
val label: Any? = null,
val name: String? = null,
val node_id: String? = null,
val size: Int? = null,
val state: String? = null,
val updated_at: String? = null,
val uploader: Uploader? = null,
val url: String? = null
)

View File

@ -4,22 +4,22 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties
@JsonIgnoreProperties(ignoreUnknown = true)
data class Author(
val avatar_url: String,
val events_url: String,
val followers_url: String,
val following_url: String,
val gists_url: String,
val gravatar_id: String,
val html_url: String,
val id: Int,
val login: String,
val node_id: String,
val organizations_url: String,
val received_events_url: String,
val repos_url: String,
val site_admin: Boolean,
val starred_url: String,
val subscriptions_url: String,
val type: String,
val url: String
val avatar_url: String? = null,
val events_url: String? = null,
val followers_url: String? = null,
val following_url: String? = null,
val gists_url: String? = null,
val gravatar_id: String? = null,
val html_url: String? = null,
val id: Int? = null,
val login: String? = null,
val node_id: String? = null,
val organizations_url: String? = null,
val received_events_url: String? = null,
val repos_url: String? = null,
val site_admin: Boolean? = null,
val starred_url: String? = null,
val subscriptions_url: String? = null,
val type: String? = null,
val url: String? = null
)

View File

@ -4,12 +4,12 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties
@JsonIgnoreProperties(ignoreUnknown = true)
data class Reactions(
val confused: Int,
val eyes: Int,
val heart: Int,
val hooray: Int,
val laugh: Int,
val rocket: Int,
val total_count: Int,
val url: String
val confused: Int? = null,
val eyes: Int? = null,
val heart: Int? = null,
val hooray: Int? = null,
val laugh: Int? = null,
val rocket: Int? = null,
val total_count: Int? = null,
val url: String? = null
)

View File

@ -1,5 +1,6 @@
package com.github.libretube.update
import android.util.Log
import com.fasterxml.jackson.databind.ObjectMapper
import com.github.libretube.GITHUB_API_URL
import java.net.URL
@ -10,6 +11,7 @@ object UpdateChecker {
// run http request as thread to make it async
val thread = Thread {
// otherwise crashes without internet
versionInfo = getUpdateInfo()
try {
versionInfo = getUpdateInfo()
} catch (e: Exception) {

View File

@ -4,24 +4,24 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties
@JsonIgnoreProperties(ignoreUnknown = true)
data class UpdateInfo(
val assets: List<Asset>,
val assets_url: String,
val author: Author,
val body: String,
val created_at: String,
val draft: Boolean,
val html_url: String,
val id: Int,
val mentions_count: Int,
val name: String,
val node_id: String,
val prerelease: Boolean,
val published_at: String,
val reactions: Reactions,
val tag_name: String,
val tarball_url: String,
val target_commitish: String,
val upload_url: String,
val url: String,
val zipball_url: String
val assets: List<Asset>? = null,
val assets_url: String? = null,
val author: Author? = null,
val body: String? = null,
val created_at: String? = null,
val draft: Boolean? = null,
val html_url: String? = null,
val id: Int? = null,
val mentions_count: Int? = null,
val name: String? = null,
val node_id: String? = null,
val prerelease: Boolean? = null,
val published_at: String? = null,
val reactions: Reactions? = null,
val tag_name: String? = null,
val tarball_url: String? = null,
val target_commitish: String? = null,
val upload_url: String? = null,
val url: String? = null,
val zipball_url: String? = null
)

View File

@ -4,22 +4,22 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties
@JsonIgnoreProperties(ignoreUnknown = true)
data class Uploader(
val avatar_url: String,
val events_url: String,
val followers_url: String,
val following_url: String,
val gists_url: String,
val gravatar_id: String,
val html_url: String,
val id: Int,
val login: String,
val node_id: String,
val organizations_url: String,
val received_events_url: String,
val repos_url: String,
val site_admin: Boolean,
val starred_url: String,
val subscriptions_url: String,
val type: String,
val url: String
val avatar_url: String? = null,
val events_url: String? = null,
val followers_url: String? = null,
val following_url: String? = null,
val gists_url: String? = null,
val gravatar_id: String? = null,
val html_url: String? = null,
val id: Int? = null,
val login: String? = null,
val node_id: String? = null,
val organizations_url: String? = null,
val received_events_url: String? = null,
val repos_url: String? = null,
val site_admin: Boolean? = null,
val starred_url: String? = null,
val subscriptions_url: String? = null,
val type: String? = null,
val url: String? = null
)

View File

@ -4,11 +4,6 @@ import android.app.Activity
import android.content.Context
import android.view.View
import android.view.inputmethod.InputMethodManager
import androidx.fragment.app.Fragment
fun Fragment.hideKeyboard() {
view?.let { activity?.hideKeyboard(it) }
}
fun Context.hideKeyboard(view: View) {
val inputMethodManager = getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager