fixed url opening in about menu

This commit is contained in:
X1nto 2020-07-05 20:15:00 +04:00
parent 75202544b6
commit 87964d1fd7
1 changed files with 14 additions and 6 deletions

View File

@ -6,16 +6,24 @@ import android.net.Uri
import androidx.browser.customtabs.CustomTabsIntent
import androidx.core.content.ContextCompat
import androidx.lifecycle.AndroidViewModel
import androidx.preference.PreferenceManager
import com.vanced.manager.R
open class AboutViewModel(application: Application): AndroidViewModel(application) {
class AboutViewModel(application: Application): AndroidViewModel(application) {
fun openUrl(Url: String) {
val builder = CustomTabsIntent.Builder()
builder.setToolbarColor(ContextCompat.getColor(getApplication(), R.color.GitHub))
val customTabsIntent = builder.build()
customTabsIntent.intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
customTabsIntent.launchUrl(getApplication(), Uri.parse(Url))
val customTabPrefs = PreferenceManager.getDefaultSharedPreferences(getApplication()).getBoolean("use_customtabs", true)
if (customTabPrefs) {
val builder = CustomTabsIntent.Builder()
builder.setToolbarColor(ContextCompat.getColor(getApplication(), R.color.GitHub))
val customTabsIntent = builder.build()
customTabsIntent.intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
customTabsIntent.launchUrl(getApplication(), Uri.parse(Url))
} else {
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(Url))
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
ContextCompat.startActivity(getApplication(), intent, null)
}
}
}