mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-11-24 10:35:26 +00:00
Added link opening on homepage
This commit is contained in:
parent
fe1ce08a6c
commit
f1dcecc6cf
@ -0,0 +1,32 @@
|
||||
package com.topjohnwu.magisk.model.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.skoumal.teanity.viewevents.ViewEvent
|
||||
import com.topjohnwu.magisk.R
|
||||
|
||||
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) }
|
||||
|
||||
}
|
@ -12,6 +12,7 @@ import com.topjohnwu.magisk.model.entity.MagiskJson
|
||||
import com.topjohnwu.magisk.model.entity.ManagerJson
|
||||
import com.topjohnwu.magisk.model.entity.UpdateInfo
|
||||
import com.topjohnwu.magisk.model.entity.recycler.HomeItem
|
||||
import com.topjohnwu.magisk.model.events.OpenInappLinkEvent
|
||||
import com.topjohnwu.magisk.model.observer.Observer
|
||||
import com.topjohnwu.magisk.redesign.compat.CompatViewModel
|
||||
import com.topjohnwu.magisk.ui.home.MagiskState
|
||||
@ -70,7 +71,7 @@ class HomeViewModel(
|
||||
}
|
||||
|
||||
fun onDeletePressed() {}
|
||||
fun onLinkPressed(link: String) {}
|
||||
fun onLinkPressed(link: String) = OpenInappLinkEvent(link).publish()
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user