open links fixed

This commit is contained in:
Bnyro 2022-06-09 09:28:41 +02:00
parent b34170bf08
commit 8712aa4efe
3 changed files with 20 additions and 18 deletions

View File

@ -12,9 +12,13 @@ class RouterActivity : AppCompatActivity() {
val TAG = "RouterActivity"
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
if (checkHost(intent)) {
if (intent.getStringExtra(Intent.EXTRA_TEXT) != null && checkHost(intent)) {
// start the main activity using the given URI as data if the host is known
handleSendText(intent)
val uri = Uri.parse(intent.getStringExtra(Intent.EXTRA_TEXT)!!)
handleSendText(uri)
} else if (intent.data != null) {
val uri = intent.data
handleSendText(uri!!)
} else {
// start app as normal if URI not in host list
ThemeHelper().restartMainActivity(this)
@ -30,16 +34,13 @@ class RouterActivity : AppCompatActivity() {
return hostsList.contains(intentDataHost)
}
private fun handleSendText(intent: Intent) {
intent.getStringExtra(Intent.EXTRA_TEXT)?.let {
Log.i(TAG, it)
val pm: PackageManager = this.packageManager
// startIntent(this, MainActivity::class.java doesn't work for the activity aliases needed for the logo switch option
val intent = pm.getLaunchIntentForPackage(this.packageName)
intent?.flags = Intent.FLAG_ACTIVITY_CLEAR_TASK
intent?.data = Uri.parse(it)
this.startActivity(intent)
this.finishAndRemoveTask()
}
private fun handleSendText(uri: Uri) {
Log.i(TAG, uri.toString())
val pm: PackageManager = this.packageManager
val intent = pm.getLaunchIntentForPackage(this.packageName)
intent?.flags = Intent.FLAG_ACTIVITY_CLEAR_TASK
intent?.data = uri
this.startActivity(intent)
this.finishAndRemoveTask()
}
}

View File

@ -1,5 +1,6 @@
package com.github.libretube.adapters
import android.annotation.SuppressLint
import android.util.Log
import android.view.LayoutInflater
import android.view.View
@ -35,17 +36,18 @@ class CommentsAdapter(
private var repliesPage = CommentsPage()
fun updateItems(newItems: List<Comment>) {
var commentsSize = comments.size
val commentsSize = comments.size
comments.addAll(newItems)
notifyItemRangeInserted(commentsSize, newItems.size)
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CommentsViewHolder {
var commentsView =
val commentsView =
LayoutInflater.from(parent.context).inflate(R.layout.comments_row, parent, false)
return CommentsViewHolder(commentsView)
}
@SuppressLint("SetTextI18n")
override fun onBindViewHolder(holder: CommentsViewHolder, position: Int) {
holder.v.findViewById<TextView>(R.id.comment_infos).text =
comments[position].author.toString() +
@ -103,10 +105,10 @@ class CommentsAdapter(
private fun fetchReplies(nextpage: String, repliesAdapter: RepliesAdapter) {
CoroutineScope(Dispatchers.Main).launch {
if (!isLoading && nextpage != null) {
if (!isLoading) {
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")

View File

@ -4,7 +4,6 @@ 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