1
0
mirror of https://github.com/wulkanowy/wulkanowy.git synced 2024-09-20 01:19:08 -05:00

Fix crash when no webview activity (#338)

This commit is contained in:
Rafał Borcz 2019-05-14 11:45:27 +02:00 committed by Mikołaj Pich
parent 103ab95c80
commit d169f964f2
4 changed files with 14 additions and 6 deletions

View File

@ -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)
}
}
}

View File

@ -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() {

View File

@ -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)

View File

@ -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)
}
}