diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/about/AboutFragment.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/about/AboutFragment.kt index 6815b45f2..8d07566f7 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/about/AboutFragment.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/about/AboutFragment.kt @@ -12,6 +12,7 @@ import io.github.wulkanowy.BuildConfig import io.github.wulkanowy.R import io.github.wulkanowy.ui.base.BaseFragment import io.github.wulkanowy.ui.modules.main.MainView +import io.github.wulkanowy.utils.openInternetBrowser import io.github.wulkanowy.utils.withOnExtraListener import javax.inject.Inject @@ -57,11 +58,11 @@ class AboutFragment : BaseFragment(), AboutView, MainView.TitledView { } override fun openDiscordInviteView() { - startActivity(Intent.parseUri("https://discord.gg/vccAQBr", 0)) + context?.openInternetBrowser("https://discord.gg/vccAQBr", ::showMessage) } override fun openHomepageWebView() { - startActivity(Intent.parseUri("https://wulkanowy.github.io/", 0)) + context?.openInternetBrowser("https://wulkanowy.github.io/", ::showMessage) } override fun openEmailClientView() { @@ -80,7 +81,7 @@ class AboutFragment : BaseFragment(), AboutView, MainView.TitledView { if (intent.resolveActivity(it.packageManager) != null) { startActivity(Intent.createChooser(intent, getString(R.string.about_feedback))) } else { - startActivity(Intent.parseUri("https://github.com/wulkanowy/wulkanowy/issues", 0)) + it.openInternetBrowser("https://github.com/wulkanowy/wulkanowy/issues", ::showMessage) } } } diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/login/form/LoginFormFragment.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/login/form/LoginFormFragment.kt index 2a0467d9f..b17a1205c 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/login/form/LoginFormFragment.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/login/form/LoginFormFragment.kt @@ -1,7 +1,6 @@ package io.github.wulkanowy.ui.modules.login.form import android.annotation.SuppressLint -import android.content.Intent import android.os.Bundle import android.view.LayoutInflater import android.view.View @@ -17,6 +16,7 @@ import io.github.wulkanowy.data.db.entities.Student import io.github.wulkanowy.ui.base.BaseFragment import io.github.wulkanowy.ui.modules.login.LoginActivity import io.github.wulkanowy.utils.hideSoftInput +import io.github.wulkanowy.utils.openInternetBrowser import io.github.wulkanowy.utils.setOnItemSelectedListener import io.github.wulkanowy.utils.setOnTextChangedListener import io.github.wulkanowy.utils.showSoftInput @@ -145,7 +145,7 @@ class LoginFormFragment : BaseFragment(), LoginFormView { } override fun openPrivacyPolicyPage() { - startActivity(Intent.parseUri("https://wulkanowy.github.io/polityka-prywatnosci.html", 0)) + context?.openInternetBrowser("https://wulkanowy.github.io/polityka-prywatnosci.html", ::showMessage) } override fun onDestroyView() { diff --git a/app/src/main/java/io/github/wulkanowy/utils/ActivityExtension.kt b/app/src/main/java/io/github/wulkanowy/utils/ActivityExtension.kt index c0314d02e..93781a9fe 100644 --- a/app/src/main/java/io/github/wulkanowy/utils/ActivityExtension.kt +++ b/app/src/main/java/io/github/wulkanowy/utils/ActivityExtension.kt @@ -4,7 +4,6 @@ import android.app.Activity import android.content.Context.INPUT_METHOD_SERVICE import android.view.inputmethod.InputMethodManager - fun Activity.showSoftInput() { (getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager?)?.run { if (currentFocus != null) showSoftInput(currentFocus, 0) diff --git a/app/src/main/java/io/github/wulkanowy/utils/ContextExtension.kt b/app/src/main/java/io/github/wulkanowy/utils/ContextExtension.kt index 70368badd..c367ecd07 100644 --- a/app/src/main/java/io/github/wulkanowy/utils/ContextExtension.kt +++ b/app/src/main/java/io/github/wulkanowy/utils/ContextExtension.kt @@ -1,6 +1,7 @@ package io.github.wulkanowy.utils import android.content.Context +import android.content.Intent import androidx.annotation.AttrRes import androidx.annotation.ColorInt import androidx.annotation.ColorRes @@ -18,3 +19,10 @@ fun Context.getThemeAttrColor(@AttrRes colorAttr: Int): Int { @ColorInt fun Context.getCompatColor(@ColorRes colorRes: Int) = ContextCompat.getColor(this, colorRes) + +fun Context.openInternetBrowser(uri: String, onActivityNotFound: (uri: String) -> Unit) { + Intent.parseUri(uri, 0).let { + if (it.resolveActivity(packageManager) != null) startActivity(it) + else onActivityNotFound(uri) + } +}