mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-13 22:00:30 +05:30
fix comment replies
This commit is contained in:
parent
82459d5710
commit
b34170bf08
@ -6,6 +6,7 @@ import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.ImageView
|
||||
import android.widget.TextView
|
||||
import android.widget.Toast
|
||||
import androidx.constraintlayout.motion.widget.MotionLayout
|
||||
import androidx.core.os.bundleOf
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
@ -30,9 +31,8 @@ class CommentsAdapter(
|
||||
|
||||
private val TAG = "CommentsAdapter"
|
||||
private var isLoading = false
|
||||
private var nextPage = ""
|
||||
private lateinit var repliesRecView: RecyclerView
|
||||
private lateinit var repliesPage: CommentsPage
|
||||
private var nextpage = ""
|
||||
private var repliesPage = CommentsPage()
|
||||
|
||||
fun updateItems(newItems: List<Comment>) {
|
||||
var commentsSize = comments.size
|
||||
@ -78,14 +78,18 @@ class CommentsAdapter(
|
||||
} catch (e: Exception) {
|
||||
}
|
||||
}
|
||||
repliesRecView = holder.v.findViewById(R.id.replies_recView)
|
||||
val repliesRecView = holder.v.findViewById<RecyclerView>(R.id.replies_recView)
|
||||
repliesRecView.layoutManager = LinearLayoutManager(holder.v.context)
|
||||
val repliesAdapter = RepliesAdapter(CommentsPage().comments)
|
||||
repliesRecView.adapter = repliesAdapter
|
||||
holder.v.setOnClickListener {
|
||||
if (repliesAdapter.itemCount == 0) {
|
||||
nextPage = comments[position].repliesPage!!
|
||||
fetchReplies(repliesAdapter)
|
||||
if (comments[position].repliesPage != null) {
|
||||
nextpage = comments[position].repliesPage!!
|
||||
fetchReplies(nextpage, repliesAdapter)
|
||||
} else {
|
||||
Toast.makeText(holder.v.context, R.string.no_replies, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
// repliesAdapter.updateItems(repliesPage.comments)
|
||||
} else {
|
||||
repliesAdapter.clear()
|
||||
@ -97,19 +101,19 @@ class CommentsAdapter(
|
||||
return comments.size
|
||||
}
|
||||
|
||||
private fun fetchReplies(repliesAdapter: RepliesAdapter) {
|
||||
private fun fetchReplies(nextpage: String, repliesAdapter: RepliesAdapter) {
|
||||
CoroutineScope(Dispatchers.Main).launch {
|
||||
if (!isLoading && nextPage != null) {
|
||||
if (!isLoading && nextpage != null) {
|
||||
isLoading = true
|
||||
try {
|
||||
repliesPage = RetrofitInstance.api.getCommentsNextPage(videoId!!, nextPage!!)
|
||||
repliesPage = RetrofitInstance.api.getCommentsNextPage(videoId!!, nextpage!!)
|
||||
} catch (e: IOException) {
|
||||
println(e)
|
||||
Log.e(TAG, "IOException, you might not have internet connection")
|
||||
} catch (e: HttpException) {
|
||||
Log.e(TAG, "HttpException, unexpected response," + e.response())
|
||||
}
|
||||
// nextPage = if (repliesPage.nextpage!! != null) repliesPage.nextpage!! else ""
|
||||
// nextpage = if (repliesPage.nextpage!! != null) repliesPage.nextpage!! else ""
|
||||
repliesAdapter.updateItems(repliesPage.comments)
|
||||
isLoading = false
|
||||
}
|
||||
|
@ -1,41 +0,0 @@
|
||||
package com.github.libretube.dialogs
|
||||
|
||||
import android.app.Dialog
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import com.github.libretube.R
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
|
||||
class UpdateAvailableDialog(
|
||||
private val versionTag: String,
|
||||
private val updateLink: String,
|
||||
private val updateAvailable: Boolean
|
||||
) : DialogFragment() {
|
||||
|
||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||
return activity?.let {
|
||||
if (updateAvailable) {
|
||||
MaterialAlertDialogBuilder(requireContext())
|
||||
.setTitle(context?.getString(R.string.update_available, versionTag))
|
||||
.setMessage(context?.getString(R.string.update_available_text))
|
||||
.setNegativeButton(context?.getString(R.string.cancel)) { _, _ ->
|
||||
dismiss()
|
||||
}
|
||||
.setPositiveButton(context?.getString(R.string.okay)) { _, _ ->
|
||||
val uri = Uri.parse(updateLink)
|
||||
val intent = Intent(Intent.ACTION_VIEW).setData(uri)
|
||||
startActivity(intent)
|
||||
}
|
||||
.show()
|
||||
} else {
|
||||
MaterialAlertDialogBuilder(requireContext())
|
||||
.setTitle(context?.getString(R.string.app_uptodate))
|
||||
.setMessage(context?.getString(R.string.no_update_available))
|
||||
.setPositiveButton(context?.getString(R.string.okay)) { _, _ -> }
|
||||
.show()
|
||||
}
|
||||
} ?: throw IllegalStateException("Activity cannot be null")
|
||||
}
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
package com.github.libretube.dialogs
|
||||
|
||||
import android.app.Dialog
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import androidx.core.content.ContentProviderCompat.requireContext
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import com.github.libretube.R
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
|
||||
class UpdateAvailableDialog(
|
||||
private val versionTag: String,
|
||||
private val updateLink: String
|
||||
) : DialogFragment() {
|
||||
|
||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||
return activity?.let {
|
||||
MaterialAlertDialogBuilder(requireContext())
|
||||
.setTitle(context?.getString(R.string.update_available, versionTag))
|
||||
.setMessage(context?.getString(R.string.update_available_text))
|
||||
.setNegativeButton(context?.getString(R.string.cancel)) { _, _ ->
|
||||
dismiss()
|
||||
}
|
||||
.setPositiveButton(context?.getString(R.string.okay)) { _, _ ->
|
||||
val uri = Uri.parse(updateLink)
|
||||
val intent = Intent(Intent.ACTION_VIEW).setData(uri)
|
||||
startActivity(intent)
|
||||
}
|
||||
.create()
|
||||
} ?: throw IllegalStateException("Activity cannot be null")
|
||||
}
|
||||
}
|
||||
|
||||
class NoUpdateAvailableDialog() : DialogFragment() {
|
||||
|
||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||
return activity?.let {
|
||||
MaterialAlertDialogBuilder(requireContext())
|
||||
.setTitle(context?.getString(R.string.app_uptodate))
|
||||
.setMessage(context?.getString(R.string.no_update_available))
|
||||
.setPositiveButton(context?.getString(R.string.okay)) { _, _ -> }
|
||||
.create()
|
||||
} ?: throw IllegalStateException("Activity cannot be null")
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@ package com.github.libretube.util
|
||||
import android.util.Log
|
||||
import androidx.fragment.app.FragmentManager
|
||||
import com.github.libretube.BuildConfig
|
||||
import com.github.libretube.dialogs.NoUpdateAvailableDialog
|
||||
import com.github.libretube.dialogs.UpdateAvailableDialog
|
||||
import java.io.BufferedReader
|
||||
import java.io.InputStreamReader
|
||||
@ -28,18 +29,13 @@ fun checkUpdate(childFragmentManager: FragmentManager) {
|
||||
if (updateInfo?.tagName != "" && BuildConfig.VERSION_NAME != updateInfo?.tagName) {
|
||||
val updateAvailableDialog = UpdateAvailableDialog(
|
||||
updateInfo?.tagName!!,
|
||||
updateInfo?.updateUrl!!,
|
||||
true
|
||||
)
|
||||
updateAvailableDialog.show(childFragmentManager, "UpdateDialog")
|
||||
} else {
|
||||
// otherwise show the no update available dialog
|
||||
val updateAvailableDialog = UpdateAvailableDialog(
|
||||
updateInfo?.tagName!!,
|
||||
updateInfo?.updateUrl!!,
|
||||
false
|
||||
updateInfo?.updateUrl!!
|
||||
)
|
||||
updateAvailableDialog.show(childFragmentManager, "UpdateAvailableDialog")
|
||||
} else {
|
||||
// otherwise show the no update available dialog
|
||||
val noUpdateAvailableDialog = NoUpdateAvailableDialog()
|
||||
noUpdateAvailableDialog.show(childFragmentManager, "NoUpdateAvailableDialog")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -141,4 +141,5 @@
|
||||
<string name="appearance_summary">Make the app look how you want to.</string>
|
||||
<string name="advanced_summary">Player, Downloads, History</string>
|
||||
<string name="live">Live</string>
|
||||
<string name="no_replies">This comment has no replies.</string>
|
||||
</resources>
|
Loading…
Reference in New Issue
Block a user