added a try catch block
This commit is contained in:
parent
d643895e06
commit
bb53021d2a
|
@ -1,8 +1,10 @@
|
||||||
package com.vanced.manager.utils
|
package com.vanced.manager.utils
|
||||||
|
|
||||||
|
import android.content.ActivityNotFoundException
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
|
import android.widget.Toast
|
||||||
import androidx.browser.customtabs.CustomTabColorSchemeParams
|
import androidx.browser.customtabs.CustomTabColorSchemeParams
|
||||||
import androidx.browser.customtabs.CustomTabsIntent
|
import androidx.browser.customtabs.CustomTabsIntent
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
|
@ -12,6 +14,7 @@ import androidx.preference.PreferenceManager.getDefaultSharedPreferences
|
||||||
import com.beust.klaxon.JsonArray
|
import com.beust.klaxon.JsonArray
|
||||||
import com.beust.klaxon.JsonObject
|
import com.beust.klaxon.JsonObject
|
||||||
import com.vanced.manager.R
|
import com.vanced.manager.R
|
||||||
|
import com.vanced.manager.library.network.okhttp.interceptors.LOG_INTERCEPTOR
|
||||||
import com.vanced.manager.utils.AppUtils.generateChecksum
|
import com.vanced.manager.utils.AppUtils.generateChecksum
|
||||||
import com.vanced.manager.utils.Extensions.getDefaultPrefs
|
import com.vanced.manager.utils.Extensions.getDefaultPrefs
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
@ -36,16 +39,21 @@ object InternetTools {
|
||||||
//var braveTiers = MutableLiveData<JsonObject?>()
|
//var braveTiers = MutableLiveData<JsonObject?>()
|
||||||
|
|
||||||
fun openUrl(url: String, color: Int, context: Context) {
|
fun openUrl(url: String, color: Int, context: Context) {
|
||||||
val customTabPrefs = getDefaultSharedPreferences(context).getBoolean("use_custom_tabs", true)
|
try {
|
||||||
if (customTabPrefs) {
|
val customTabPrefs = getDefaultSharedPreferences(context).getBoolean("use_custom_tabs", true)
|
||||||
val builder = CustomTabsIntent.Builder()
|
if (customTabPrefs) {
|
||||||
val params = CustomTabColorSchemeParams.Builder().setToolbarColor(ContextCompat.getColor(context, color))
|
val builder = CustomTabsIntent.Builder()
|
||||||
builder.setDefaultColorSchemeParams(params.build())
|
val params = CustomTabColorSchemeParams.Builder().setToolbarColor(ContextCompat.getColor(context, color))
|
||||||
val customTabsIntent = builder.build()
|
builder.setDefaultColorSchemeParams(params.build())
|
||||||
customTabsIntent.intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
val customTabsIntent = builder.build()
|
||||||
customTabsIntent.launchUrl(context, url.toUri())
|
customTabsIntent.intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
||||||
} else
|
customTabsIntent.launchUrl(context, url.toUri())
|
||||||
context.startActivity(Intent(Intent.ACTION_VIEW, url.toUri()).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK))
|
} else
|
||||||
|
context.startActivity(Intent(Intent.ACTION_VIEW, url.toUri()).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK))
|
||||||
|
|
||||||
|
} catch (e: ActivityNotFoundException) {
|
||||||
|
Toast.makeText(context, R.string.error, Toast.LENGTH_SHORT).show()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getFileNameFromUrl(url: String) = url.substring(url.lastIndexOf('/') + 1, url.length)
|
fun getFileNameFromUrl(url: String) = url.substring(url.lastIndexOf('/') + 1, url.length)
|
||||||
|
|
Loading…
Reference in New Issue