Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature update version dialog #228

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ android {
}

debug {
debuggable true
minifyEnabled false
manifestPlaceholders = [enableCrashReporting: "false"]
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package ro.code4.monitorizarevot.data.model

import android.os.Parcelable
import kotlinx.android.parcel.Parcelize
import org.parceler.Parcel

/*
CREATED BY @PEDROFSN IN 31/10/20 16:29
*/

@Parcelize
data class UpdateApp(
val hasUpdate : Boolean,
val needForceUpdate : Boolean
) : Parcelable
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ object Constants {
const val REMOTE_CONFIG_PRIVACY_POLICY_URL = "privacy_policy_url"
const val REMOTE_CONFIG_OBSERVER_GUIDE_URL = "observer_guide_url"
const val REMOTE_CONFIG_SAFETY_GUIDE_URL = "safety_guide_url"
const val REMOTE_CONFIG_UPDATE_CHECK = "android_check_update_available"
const val REMOTE_CONFIG_UPDATE_FORCE = "android_force_update"

const val PUSH_NOTIFICATION_TITLE = "title"
const val PUSH_NOTIFICATION_BODY = "body"
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/java/ro/code4/monitorizarevot/helper/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -483,3 +483,13 @@ fun collapseKeyboardIfFocusOutsideEditText(
?.hideSoftInputFromWindow(newFocusedView.windowToken, 0)
}
}

fun Context.openAppInPlayStore(appPackageName: String = packageName) {
val uri = try {
Uri.parse("market://details?id=$appPackageName")
} catch (exception: ActivityNotFoundException) {
Uri.parse("https://play.google.com/store/apps/details?id=$appPackageName")
}
val intent = Intent(Intent.ACTION_VIEW, uri)
startActivity(intent)
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
package ro.code4.monitorizarevot.ui.login

import android.content.DialogInterface
import android.os.Bundle
import android.text.TextWatcher
import androidx.appcompat.app.AlertDialog
import androidx.lifecycle.Observer
import androidx.lifecycle.observe
import com.google.android.material.snackbar.Snackbar
import kotlinx.android.synthetic.main.activity_login.*
import org.koin.android.viewmodel.ext.android.viewModel
import ro.code4.monitorizarevot.BuildConfig
import ro.code4.monitorizarevot.R
import ro.code4.monitorizarevot.data.model.UpdateApp
import ro.code4.monitorizarevot.helper.TextWatcherDelegate
import ro.code4.monitorizarevot.helper.isOnline
import ro.code4.monitorizarevot.helper.openAppInPlayStore
import ro.code4.monitorizarevot.helper.startActivityWithoutTrace
import ro.code4.monitorizarevot.ui.base.BaseAnalyticsActivity
import ro.code4.monitorizarevot.widget.ProgressDialogFragment
Expand Down Expand Up @@ -51,6 +56,28 @@ class LoginActivity : BaseAnalyticsActivity<LoginViewModel>() {
loginButton.isEnabled = !p0.isNullOrEmpty() && !phone.text.isNullOrEmpty()
}
})
observeAppUpdates()
}

private fun observeAppUpdates() {
viewModel.shouldUpdateAppVersion().observe(this) { shouldUpdateApp(update = it) }
}

private fun shouldUpdateApp(update: UpdateApp) {
if (update.hasUpdate) {
AlertDialog.Builder(this)
.setTitle(R.string.app_update_dialog_title)
.setMessage(R.string.app_update_dialog_message)
.setCancelable(update.needForceUpdate.not())
.setPositiveButton(android.R.string.ok) { dialog: DialogInterface, _ ->
if (update.needForceUpdate) {
openAppInPlayStore()
}
dialog.dismiss()
}
.create()
.show()
}
}

override fun onDestroy() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
package ro.code4.monitorizarevot.ui.login

import android.content.SharedPreferences
import android.util.Log
import androidx.lifecycle.LiveData
import com.google.firebase.FirebaseApp
import com.google.firebase.analytics.FirebaseAnalytics
import com.google.firebase.iid.FirebaseInstanceId
import com.google.firebase.remoteconfig.FirebaseRemoteConfig
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
import org.koin.android.ext.android.inject
import org.koin.core.inject
import ro.code4.monitorizarevot.BuildConfig
import ro.code4.monitorizarevot.analytics.Event
import ro.code4.monitorizarevot.data.model.UpdateApp
import ro.code4.monitorizarevot.data.model.User
import ro.code4.monitorizarevot.data.model.response.LoginResponse
import ro.code4.monitorizarevot.helper.*
import ro.code4.monitorizarevot.helper.Constants.REMOTE_CONFIG_UPDATE_CHECK
import ro.code4.monitorizarevot.helper.Constants.REMOTE_CONFIG_UPDATE_FORCE
import ro.code4.monitorizarevot.repositories.Repository
import ro.code4.monitorizarevot.ui.base.BaseViewModel
import ro.code4.monitorizarevot.ui.onboarding.OnboardingActivity
Expand All @@ -26,6 +29,16 @@ class LoginViewModel : BaseViewModel() {
private val firebaseAnalytics: FirebaseAnalytics by inject()

private val loginLiveData = SingleLiveEvent<Result<Class<*>>>()
private val updates = SingleLiveEvent<UpdateApp>()

fun shouldUpdateAppVersion(): LiveData<UpdateApp> {
FirebaseRemoteConfig.getInstance().run {
val needForceUpdate = getBoolean(REMOTE_CONFIG_UPDATE_FORCE)
val hasUpdate = getBoolean(REMOTE_CONFIG_UPDATE_CHECK)
updates.postValue(UpdateApp(hasUpdate, needForceUpdate))
}
return updates
}

fun loggedIn(): LiveData<Result<Class<*>>> = loginLiveData

Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/values-ro-rRO/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,8 @@
<string name="about_privacy_policy">Politică de confidențialitate</string>
<string name="about_send_mail_via">Trimiteți email prin</string>
<string name="about_app_version">v%1$S build %2$d aplicație dezvoltată de</string>

<!-- Updates -->
<string name="app_update_dialog_title">Actualizare disponibilă</string>
<string name="app_update_dialog_message">O nouă versiune a aplicației este disponibilă. Te rugăm să faci update pentru a folosi cele mai recente funcționalități.</string>
</resources>
4 changes: 4 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,8 @@
<string name="about_privacy_policy">Privacy policy</string>
<string name="about_send_mail_via">Send email via</string>
<string name="about_app_version">v%1$S build %2$d app developed by</string>

<!-- Updates -->
<string name="app_update_dialog_title">App UpdateAvailable</string>
<string name="app_update_dialog_message">A new app version is available. Please update the app to use the latest features.</string>
</resources>