1
0
mirror of https://github.com/wulkanowy/wulkanowy.git synced 2025-01-19 14:26:44 -06:00

Handle URLs from FCM push notification (#1070)

This commit is contained in:
Mikołaj Pich 2021-01-11 10:41:17 +01:00 committed by GitHub
parent d332369872
commit a99e742472
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 29 additions and 6 deletions

View File

@ -9,6 +9,17 @@
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.VIBRATE" /> <uses-permission android:name="android.permission.VIBRATE" />
<queries>
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="http" />
</intent>
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="https" />
</intent>
</queries>
<application <application
android:name=".WulkanowyApp" android:name=".WulkanowyApp"
android:allowBackup="false" android:allowBackup="false"
@ -112,8 +123,7 @@
<meta-data <meta-data
android:name="install_channel" android:name="install_channel"
android:value="${install_channel}"> android:value="${install_channel}" />
</meta-data>
<!-- workaround for https://github.com/firebase/firebase-android-sdk/issues/473 enabled:false --> <!-- workaround for https://github.com/firebase/firebase-android-sdk/issues/473 enabled:false -->
<!-- https://firebase.googleblog.com/2017/03/take-control-of-your-firebase-init-on.html --> <!-- https://firebase.googleblog.com/2017/03/take-control-of-your-firebase-init-on.html -->

View File

@ -8,6 +8,7 @@ import dagger.hilt.android.AndroidEntryPoint
import io.github.wulkanowy.ui.base.BaseActivity import io.github.wulkanowy.ui.base.BaseActivity
import io.github.wulkanowy.ui.modules.login.LoginActivity import io.github.wulkanowy.ui.modules.login.LoginActivity
import io.github.wulkanowy.ui.modules.main.MainActivity import io.github.wulkanowy.ui.modules.main.MainActivity
import io.github.wulkanowy.utils.openInternetBrowser
import javax.inject.Inject import javax.inject.Inject
@AndroidEntryPoint @AndroidEntryPoint
@ -18,7 +19,7 @@ class SplashActivity : BaseActivity<SplashPresenter, ViewBinding>(), SplashView
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
presenter.onAttachView(this) presenter.onAttachView(this, intent?.getStringExtra("external_url"))
} }
override fun openLoginView() { override fun openLoginView() {
@ -31,6 +32,11 @@ class SplashActivity : BaseActivity<SplashPresenter, ViewBinding>(), SplashView
finish() finish()
} }
override fun openExternalUrlAndFinish(url: String) {
openInternetBrowser(url, ::showMessage)
finish()
}
override fun showError(text: String, error: Throwable) { override fun showError(text: String, error: Throwable) {
Toast.makeText(this, text, LENGTH_LONG).show() Toast.makeText(this, text, LENGTH_LONG).show()
} }

View File

@ -14,8 +14,13 @@ class SplashPresenter @Inject constructor(
studentRepository: StudentRepository studentRepository: StudentRepository
) : BasePresenter<SplashView>(errorHandler, studentRepository) { ) : BasePresenter<SplashView>(errorHandler, studentRepository) {
override fun onAttachView(view: SplashView) { fun onAttachView(view: SplashView, externalUrl: String?) {
super.onAttachView(view) super.onAttachView(view)
if (!externalUrl.isNullOrBlank()) {
return view.openExternalUrlAndFinish(externalUrl)
}
flowWithResource { studentRepository.isCurrentStudentSet() }.onEach { flowWithResource { studentRepository.isCurrentStudentSet() }.onEach {
when (it.status) { when (it.status) {
Status.LOADING -> Timber.d("Is current user set check started") Status.LOADING -> Timber.d("Is current user set check started")

View File

@ -7,4 +7,6 @@ interface SplashView : BaseView {
fun openLoginView() fun openLoginView()
fun openMainView() fun openMainView()
fun openExternalUrlAndFinish(url: String)
} }

View File

@ -36,14 +36,14 @@ class SplashPresenterTest {
@Test @Test
fun testOpenLoginView() { fun testOpenLoginView() {
coEvery { studentRepository.isCurrentStudentSet() } returns false coEvery { studentRepository.isCurrentStudentSet() } returns false
presenter.onAttachView(splashView) presenter.onAttachView(splashView, null)
verify { splashView.openLoginView() } verify { splashView.openLoginView() }
} }
@Test @Test
fun testMainMainView() { fun testMainMainView() {
coEvery { studentRepository.isCurrentStudentSet() } returns true coEvery { studentRepository.isCurrentStudentSet() } returns true
presenter.onAttachView(splashView) presenter.onAttachView(splashView, null)
verify { splashView.openMainView() } verify { splashView.openMainView() }
} }
} }