Commit 2954eb4b authored by vvb2060's avatar vvb2060 Committed by John Wu

Remove CustomTab

parent e08de916
package com.topjohnwu.magisk.events
import android.content.Context
import android.content.res.Resources
import android.util.TypedValue
import androidx.annotation.AttrRes
import androidx.browser.customtabs.CustomTabsIntent
import androidx.core.net.toUri
import com.topjohnwu.magisk.R
import com.topjohnwu.magisk.arch.ContextExecutor
import com.topjohnwu.magisk.arch.ViewEvent
data class OpenInappLinkEvent(
private val link: String
) : ViewEvent(), ContextExecutor {
// todo find app that can open the link and as a fallback open custom tabs! it shouldn't be the default
override fun invoke(context: Context) = CustomTabsIntent.Builder()
.setShowTitle(true)
.setToolbarColor(context.themedColor(R.attr.colorSurface))
.enableUrlBarHiding()
.build()
.launchUrl(context, link.toUri())
private fun Context.themedColor(@AttrRes attribute: Int) = theme
.resolveAttribute(attribute).data
private fun Resources.Theme.resolveAttribute(
@AttrRes attribute: Int,
resolveRefs: Boolean = true
) = TypedValue().also { resolveAttribute(attribute, it, resolveRefs) }
}
package com.topjohnwu.magisk.ui.home
import android.content.Context
import androidx.core.net.toUri
import androidx.databinding.Bindable
import androidx.lifecycle.viewModelScope
import com.topjohnwu.magisk.BuildConfig
import com.topjohnwu.magisk.R
import com.topjohnwu.magisk.arch.ActivityExecutor
import com.topjohnwu.magisk.arch.BaseUIActivity
import com.topjohnwu.magisk.arch.BaseViewModel
import com.topjohnwu.magisk.arch.ViewEvent
import com.topjohnwu.magisk.arch.*
import com.topjohnwu.magisk.core.Config
import com.topjohnwu.magisk.core.Info
import com.topjohnwu.magisk.core.download.Subject
......@@ -15,12 +14,12 @@ import com.topjohnwu.magisk.core.download.Subject.Manager
import com.topjohnwu.magisk.data.repository.NetworkService
import com.topjohnwu.magisk.databinding.itemBindingOf
import com.topjohnwu.magisk.databinding.set
import com.topjohnwu.magisk.events.OpenInappLinkEvent
import com.topjohnwu.magisk.events.SnackbarEvent
import com.topjohnwu.magisk.events.dialog.EnvFixDialog
import com.topjohnwu.magisk.events.dialog.ManagerInstallDialog
import com.topjohnwu.magisk.events.dialog.UninstallDialog
import com.topjohnwu.magisk.ktx.await
import com.topjohnwu.magisk.utils.Utils
import com.topjohnwu.magisk.utils.asText
import com.topjohnwu.superuser.Shell
import kotlinx.coroutines.launch
......@@ -116,7 +115,9 @@ class HomeViewModel(
stateManagerProgress = progress.times(100f).roundToInt()
}
fun onLinkPressed(link: String) = OpenInappLinkEvent(link).publish()
fun onLinkPressed(link: String) = object : ViewEvent(), ContextExecutor {
override fun invoke(context: Context) = Utils.openLink(context, link.toUri())
}.publish()
fun onDeletePressed() = UninstallDialog().publish()
......
package com.topjohnwu.magisk.utils
import android.content.ActivityNotFoundException
import android.content.Context
import android.content.Intent
import android.net.Uri
......@@ -29,13 +30,10 @@ object Utils {
fun openLink(context: Context, link: Uri) {
val intent = Intent(Intent.ACTION_VIEW, link)
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
if (intent.resolveActivity(context.packageManager) != null) {
try {
context.startActivity(intent)
} else {
toast(
R.string.open_link_failed_toast,
Toast.LENGTH_SHORT
)
} catch (e: ActivityNotFoundException) {
toast(R.string.open_link_failed_toast, Toast.LENGTH_SHORT)
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment