diff --git a/app/src/main/java/com/github/libretube/adapters/CommentsAdapter.kt b/app/src/main/java/com/github/libretube/adapters/CommentsAdapter.kt index 00f74b68f..3176cad6e 100644 --- a/app/src/main/java/com/github/libretube/adapters/CommentsAdapter.kt +++ b/app/src/main/java/com/github/libretube/adapters/CommentsAdapter.kt @@ -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) { 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(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 } diff --git a/app/src/main/java/com/github/libretube/dialogs/UpdateAvailableDialog.kt b/app/src/main/java/com/github/libretube/dialogs/UpdateAvailableDialog.kt deleted file mode 100644 index e5fe2cde5..000000000 --- a/app/src/main/java/com/github/libretube/dialogs/UpdateAvailableDialog.kt +++ /dev/null @@ -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") - } -} diff --git a/app/src/main/java/com/github/libretube/dialogs/UpdateDialog.kt b/app/src/main/java/com/github/libretube/dialogs/UpdateDialog.kt new file mode 100644 index 000000000..2ca40e58f --- /dev/null +++ b/app/src/main/java/com/github/libretube/dialogs/UpdateDialog.kt @@ -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") + } +} diff --git a/app/src/main/java/com/github/libretube/util/UpdateChecker.kt b/app/src/main/java/com/github/libretube/util/UpdateChecker.kt index 7f4db01f3..554cef26c 100644 --- a/app/src/main/java/com/github/libretube/util/UpdateChecker.kt +++ b/app/src/main/java/com/github/libretube/util/UpdateChecker.kt @@ -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") } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d4b240d65..336ecb55a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -141,4 +141,5 @@ Make the app look how you want to. Player, Downloads, History Live + This comment has no replies. \ No newline at end of file