mirror of
https://github.com/home-assistant/android
synced 2024-10-15 12:32:54 +00:00
Allow the firebase instance id be optional. (#673)
This is discouraged but helpful for contributors. This way we don't need everyone to setup firebase just to help on the app.
This commit is contained in:
parent
359bcefef4
commit
16073dccbf
|
@ -12,6 +12,7 @@ import android.view.View
|
|||
import android.view.ViewGroup
|
||||
import android.widget.Button
|
||||
import android.widget.ViewFlipper
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.appcompat.widget.AppCompatButton
|
||||
import androidx.appcompat.widget.AppCompatTextView
|
||||
import androidx.appcompat.widget.SwitchCompat
|
||||
|
@ -22,6 +23,7 @@ import io.homeassistant.companion.android.R
|
|||
import io.homeassistant.companion.android.common.dagger.GraphComponentAccessor
|
||||
import io.homeassistant.companion.android.util.PermissionManager
|
||||
import javax.inject.Inject
|
||||
import kotlinx.android.synthetic.main.fragment_mobile_app_integration.*
|
||||
|
||||
class MobileAppIntegrationFragment : Fragment(), MobileAppIntegrationView {
|
||||
|
||||
|
@ -100,6 +102,20 @@ class MobileAppIntegrationFragment : Fragment(), MobileAppIntegrationView {
|
|||
(activity as MobileAppIntegrationListener).onIntegrationRegistrationComplete()
|
||||
}
|
||||
|
||||
findViewById<AppCompatButton>(R.id.skip).setOnClickListener {
|
||||
AlertDialog.Builder(context)
|
||||
.setTitle(R.string.firebase_error_title)
|
||||
.setMessage(R.string.firebase_error_message)
|
||||
.setPositiveButton(R.string.skip) { _, _ ->
|
||||
presenter.onRegistrationAttempt(false)
|
||||
}
|
||||
.setNegativeButton(R.string.retry) { _, _ ->
|
||||
presenter.onRegistrationAttempt(true)
|
||||
}
|
||||
.create()
|
||||
.show()
|
||||
}
|
||||
|
||||
presenter.onRegistrationAttempt()
|
||||
}
|
||||
}
|
||||
|
@ -108,7 +124,10 @@ class MobileAppIntegrationFragment : Fragment(), MobileAppIntegrationView {
|
|||
viewFlipper.displayedChild = SETTINGS_VIEW
|
||||
}
|
||||
|
||||
override fun showError() {
|
||||
override fun showError(skippable: Boolean) {
|
||||
if (skippable) {
|
||||
skip.visibility = View.VISIBLE
|
||||
}
|
||||
viewFlipper.displayedChild = ERROR_VIEW
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package io.homeassistant.companion.android.onboarding.integration
|
||||
|
||||
interface MobileAppIntegrationPresenter {
|
||||
fun onRegistrationAttempt()
|
||||
fun onRegistrationAttempt(includeFirebase: Boolean = true)
|
||||
fun onToggleZoneTracking(enabled: Boolean)
|
||||
fun onToggleBackgroundTracking(enabled: Boolean)
|
||||
fun onFinish()
|
||||
|
|
|
@ -24,33 +24,39 @@ class MobileAppIntegrationPresenterImpl @Inject constructor(
|
|||
|
||||
private val mainScope: CoroutineScope = CoroutineScope(Dispatchers.Main + Job())
|
||||
|
||||
override fun onRegistrationAttempt() {
|
||||
|
||||
override fun onRegistrationAttempt(includeFirebase: Boolean) {
|
||||
view.showLoading()
|
||||
val instanceId = FirebaseInstanceId.getInstance().instanceId
|
||||
instanceId.addOnSuccessListener {
|
||||
mainScope.launch {
|
||||
val token = it.token
|
||||
|
||||
val deviceRegistration = DeviceRegistration(
|
||||
"${BuildConfig.VERSION_NAME} (${BuildConfig.VERSION_CODE})",
|
||||
Build.MODEL ?: "UNKNOWN",
|
||||
token
|
||||
)
|
||||
val deviceRegistration = DeviceRegistration(
|
||||
"${BuildConfig.VERSION_NAME} (${BuildConfig.VERSION_CODE})",
|
||||
Build.MODEL ?: "UNKNOWN"
|
||||
)
|
||||
|
||||
try {
|
||||
integrationUseCase.registerDevice(deviceRegistration)
|
||||
// TODO: Get the name of the instance to display
|
||||
view.deviceRegistered()
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "Error with registering application", e)
|
||||
view.showError()
|
||||
}
|
||||
if (includeFirebase) {
|
||||
val instanceId = FirebaseInstanceId.getInstance().instanceId
|
||||
instanceId.addOnSuccessListener {
|
||||
deviceRegistration.pushToken = it.token
|
||||
register(deviceRegistration)
|
||||
}
|
||||
instanceId.addOnFailureListener {
|
||||
Log.e(TAG, "Couldn't get FirebaseInstanceId", it)
|
||||
view.showError(true)
|
||||
}
|
||||
} else {
|
||||
register(deviceRegistration)
|
||||
}
|
||||
instanceId.addOnFailureListener {
|
||||
Log.e(TAG, "Couldn't get FirebaseInstanceId", it)
|
||||
view.showError()
|
||||
}
|
||||
|
||||
private fun register(deviceRegistration: DeviceRegistration) {
|
||||
mainScope.launch {
|
||||
try {
|
||||
integrationUseCase.registerDevice(deviceRegistration)
|
||||
// TODO: Get the name of the instance to display
|
||||
view.deviceRegistered()
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "Error with registering application", e)
|
||||
view.showError()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,5 +6,5 @@ interface MobileAppIntegrationView {
|
|||
|
||||
fun showLoading()
|
||||
|
||||
fun showError()
|
||||
fun showError(skippable: Boolean = false)
|
||||
}
|
||||
|
|
|
@ -28,7 +28,8 @@
|
|||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
android:layout_height="match_parent"
|
||||
android:padding="@dimen/activity_margin">
|
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
android:id="@+id/title"
|
||||
|
@ -66,6 +67,16 @@
|
|||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/subtitle" />
|
||||
|
||||
<androidx.appcompat.widget.AppCompatButton
|
||||
android:id="@+id/skip"
|
||||
style="@style/Widget.HomeAssistant.Button.Outlined"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
android:text="@string/skip" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
<ScrollView
|
||||
|
|
|
@ -107,7 +107,7 @@ like to connect to:</string>
|
|||
<string name="webview_error_SSL_DATE_INVALID">The date of the Home Assistant certificate is invalid, please review the Home Assistant certificate or the connection settings and try again.</string>
|
||||
<string name="webview_error_SSL_EXPIRED">The Home Assistant certificate has expired, please review the Home Assistant certificate or the connection settings and try again.</string>
|
||||
<string name="webview_error_SSL_IDMISMATCH">The Home Assistant Hostname certificate mismatch, please review the Home Assistant certificate or the connection settings and try again.</string>
|
||||
<string name="webview_error_SSL_INVALID">A generic SSL error occured when loading Home Assistant, please review the Home Assistant certificate or the connection settings and try again.</string>
|
||||
<string name="webview_error_SSL_INVALID">A generic SSL error occurred when loading Home Assistant, please review the Home Assistant certificate or the connection settings and try again.</string>
|
||||
<string name="webview_error_SSL_NOTYETVALID">The Home Assistant certificate is not yet valid, please review the Home Assistant certificate or the connection settings and try again.</string>
|
||||
<string name="webview_error_SSL_UNTRUSTED">The Home Assistant certificate authority is not trusted, please review the Home Assistant certificate or the connection settings and try again.</string>
|
||||
<string name="widget_config_service_error">A custom component is preventing service data from loading.</string>
|
||||
|
@ -118,4 +118,6 @@ like to connect to:</string>
|
|||
<string name="widget_text_hint_service_data">Entity ID</string>
|
||||
<string name="widget_text_hint_service_domain">Domain</string>
|
||||
<string name="widget_text_hint_service_service">Service</string>
|
||||
<string name="firebase_error_title">Firebase Error</string>
|
||||
<string name="firebase_error_message">By skipping/ignoring this error you will be unable to receive any push notifications.</string>
|
||||
</resources>
|
||||
|
|
|
@ -384,6 +384,15 @@ class IntegrationRepositoryImpl @Inject constructor(
|
|||
|
||||
private suspend fun createUpdateRegistrationRequest(deviceRegistration: DeviceRegistration): RegisterDeviceRequest {
|
||||
val oldDeviceRegistration = getRegistration()
|
||||
val pushToken = deviceRegistration.pushToken ?: oldDeviceRegistration.pushToken
|
||||
val appData = if (pushToken == null) {
|
||||
null
|
||||
} else {
|
||||
hashMapOf(
|
||||
"push_url" to PUSH_URL,
|
||||
"push_token" to pushToken
|
||||
)
|
||||
}
|
||||
return RegisterDeviceRequest(
|
||||
null,
|
||||
null,
|
||||
|
@ -394,11 +403,7 @@ class IntegrationRepositoryImpl @Inject constructor(
|
|||
null,
|
||||
osVersion,
|
||||
null,
|
||||
hashMapOf(
|
||||
"push_url" to PUSH_URL,
|
||||
"push_token" to (deviceRegistration.pushToken ?: oldDeviceRegistration.pushToken
|
||||
?: "")
|
||||
),
|
||||
appData,
|
||||
null
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue