added option to open links in external broser

This commit is contained in:
X1nto 2020-07-04 19:06:01 +04:00
parent ef0863649b
commit f9e0776d95
4 changed files with 30 additions and 10 deletions

View File

@ -13,6 +13,7 @@ import androidx.core.content.ContextCompat
import androidx.core.content.ContextCompat.startActivity
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.MutableLiveData
import androidx.preference.PreferenceManager
import androidx.preference.PreferenceManager.getDefaultSharedPreferences
import com.vanced.manager.R
import com.vanced.manager.utils.InternetTools.displayJsonInt
@ -72,6 +73,7 @@ class HomeViewModel(application: Application): AndroidViewModel(application) {
}
fun openUrl(Url: String) {
val customTabPrefs = getDefaultSharedPreferences(getApplication()).getBoolean("use_customtabs", true)
val color: Int =
when (Url) {
"https://discord.gg/TUVd7rd" -> R.color.Discord
@ -83,11 +85,14 @@ class HomeViewModel(application: Application): AndroidViewModel(application) {
else -> R.color.Vanced
}
val builder = CustomTabsIntent.Builder()
builder.setToolbarColor(ContextCompat.getColor(getApplication(), color))
val customTabsIntent = builder.build()
customTabsIntent.intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
customTabsIntent.launchUrl(getApplication(), Uri.parse(Url))
if (customTabPrefs) {
val builder = CustomTabsIntent.Builder()
builder.setToolbarColor(ContextCompat.getColor(getApplication(), color))
val customTabsIntent = builder.build()
customTabsIntent.intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
customTabsIntent.launchUrl(getApplication(), Uri.parse(Url))
} else
startActivity(getApplication(), Intent(Intent.ACTION_VIEW, Uri.parse(Url)), null)
}
private fun getPkgInfo(toCheck: Boolean, pkg: String, application: Application): String {

View File

@ -1,21 +1,27 @@
package com.vanced.manager.utils
import android.content.Context
import android.content.Intent
import android.net.Uri
import androidx.browser.customtabs.CustomTabsIntent
import androidx.core.content.ContextCompat
import androidx.preference.PreferenceManager
import androidx.preference.PreferenceManager.getDefaultSharedPreferences
import androidx.viewbinding.BuildConfig
import com.dezlum.codelabs.getjson.GetJson
import com.vanced.manager.BuildConfig
import com.vanced.manager.R
object InternetTools {
fun openUrl(Url: String, color: Int, context: Context) {
val builder = CustomTabsIntent.Builder()
builder.setToolbarColor(ContextCompat.getColor(context, color))
val customTabsIntent = builder.build()
customTabsIntent.launchUrl(context, Uri.parse(Url))
val customTabPrefs = getDefaultSharedPreferences(context).getBoolean("use_customtabs", true)
if (customTabPrefs) {
val builder = CustomTabsIntent.Builder()
builder.setToolbarColor(ContextCompat.getColor(context, color))
val customTabsIntent = builder.build()
customTabsIntent.launchUrl(context, Uri.parse(Url))
} else
context.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(Url)))
}
fun getFileNameFromUrl(url: String) = url.substring(url.lastIndexOf('/')+1, url.length)

View File

@ -55,6 +55,9 @@
<string name="chosen_install_values">Chosen installation preferences</string>
<string name="chosen_lang">Language: %1$s</string>
<string name="chosen_theme">Theme: %1$s</string>
<string name="link_title">Use Chrome Custom Tabs</string>
<string name="link_custom_tabs">Links will be opened in Chrome Custom Tabs</string>
<string name="link_external_browser">Links will be opened in an External Browser</string>
<string name="theme">Theme</string>
<string name="theme_follow">Follow System</string>
<string name="theme_dark">Dark Theme</string>

View File

@ -13,6 +13,12 @@
android:title="@string/check_updates"
android:icon="@drawable/ic_cloud_upload_black_24dp" />
<SwitchPreference
android:key="use_customtabs"
android:title="@string/link_title"
android:summaryOn="@string/link_custom_tabs"
android:summaryOff="@string/link_external_browser" />
<SwitchPreference
android:title="@string/push_notifications"
android:key="push_notifications_status"