Supporting PlayStore and Website App Update (#5397)
* Supporting PlayStore and Website App Update * Remove un-used REQUEST_INSTALL_PACKAGES permission * Code improvising Co-authored-by: adarshs <adarsh.s@navi.com>
This commit is contained in:
committed by
GitHub Enterprise
parent
20c13ecccb
commit
3b4fb0e4e9
@@ -29,7 +29,6 @@
|
||||
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
|
||||
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
|
||||
<uses-permission android:name="android.permission.VIBRATE" />
|
||||
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES"/>
|
||||
<uses-permission
|
||||
android:name="android.permission.QUERY_ALL_PACKAGES"
|
||||
tools:ignore="QueryAllPackagesPermission" />
|
||||
|
||||
@@ -1,36 +1,22 @@
|
||||
/*
|
||||
*
|
||||
* * Copyright © 2019 by Navi Technologies Private Limited
|
||||
* * All rights reserved. Strictly confidential
|
||||
*
|
||||
*/
|
||||
|
||||
package com.naviapp.appupdate.activities
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.widget.Toast
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.databinding.DataBindingUtil
|
||||
import com.navi.common.model.ModuleNameV2
|
||||
import com.navi.common.ui.activity.BaseActivity
|
||||
import com.navi.common.utils.Constants.UPDATE_TYPE_WEB
|
||||
import com.navi.common.utils.orTrue
|
||||
import com.naviapp.R
|
||||
import com.naviapp.databinding.ActivityUpdateAppBinding
|
||||
import com.naviapp.models.response.AppUpgradeResponse
|
||||
import com.naviapp.utils.NaviAppUpdateDownloadManager
|
||||
|
||||
class UpdateAppActivity :
|
||||
BaseActivity(), View.OnClickListener, NaviAppUpdateDownloadManager.Callback {
|
||||
import com.naviapp.utils.openPlayStore
|
||||
|
||||
class UpdateAppActivity : BaseActivity(), View.OnClickListener {
|
||||
private lateinit var binding: ActivityUpdateAppBinding
|
||||
private val resultLauncher =
|
||||
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
|
||||
onUpdateResult(it.resultCode == Activity.RESULT_OK)
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
@@ -48,7 +34,7 @@ class UpdateAppActivity :
|
||||
private fun initUi() {
|
||||
binding.primaryAbv.setProperties(resources.getString(R.string.update_now))
|
||||
intent.getParcelableExtra<AppUpgradeResponse>(APP_UPGRADE_DATA)?.let {
|
||||
binding.closeIv.isVisible = !it.hardUpgrade.orTrue()
|
||||
binding.closeIv.visibility = if (it.hardUpgrade.orTrue()) View.GONE else View.VISIBLE
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,41 +42,30 @@ class UpdateAppActivity :
|
||||
when (view?.id) {
|
||||
R.id.close_iv -> goBack()
|
||||
R.id.primary_abv -> {
|
||||
intent.getParcelableExtra<AppUpgradeResponse>(APP_UPGRADE_DATA)?.let {
|
||||
it.downloadableUrl?.let { downloadUrl ->
|
||||
if (it.hardUpgrade.orTrue()) {
|
||||
binding.progressBar.isVisible = true
|
||||
binding.primaryAbv.isVisible = false
|
||||
startDownloadingUpdate(downloadUrl, it.verificationHash, true)
|
||||
} else {
|
||||
startDownloadingUpdate(downloadUrl, it.verificationHash, false)
|
||||
intent.getParcelableExtra<AppUpgradeResponse>(APP_UPGRADE_DATA)
|
||||
?.let { appUpdateResponse ->
|
||||
when (appUpdateResponse.updateType) {
|
||||
UPDATE_TYPE_WEB -> {
|
||||
appUpdateResponse.downloadableUrl?.let { downloadUrl ->
|
||||
startActivity(
|
||||
Intent(
|
||||
Intent.ACTION_VIEW,
|
||||
Uri.parse(downloadUrl)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
openPlayStore(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
} ?: run {
|
||||
openPlayStore(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun startDownloadingUpdate(
|
||||
url: String,
|
||||
verificationHash: String?,
|
||||
waitForResult: Boolean
|
||||
) {
|
||||
if (waitForResult) {
|
||||
NaviAppUpdateDownloadManager.updateApp(
|
||||
this,
|
||||
url,
|
||||
verificationHash,
|
||||
this,
|
||||
resultLauncher
|
||||
)
|
||||
} else {
|
||||
Toast.makeText(this, getString(R.string.download_progress), Toast.LENGTH_SHORT).show()
|
||||
NaviAppUpdateDownloadManager.updateApp(this.applicationContext, url, verificationHash)
|
||||
goBack()
|
||||
}
|
||||
}
|
||||
|
||||
private fun goBack() {
|
||||
val intent = Intent()
|
||||
setResult(Activity.RESULT_CANCELED, intent)
|
||||
@@ -107,11 +82,4 @@ class UpdateAppActivity :
|
||||
const val TAG = "UPDATE_APP_ACTIVITY"
|
||||
const val APP_UPGRADE_DATA = "APP_UPGRADE_DATA"
|
||||
}
|
||||
|
||||
override fun onUpdateResult(isSuccess: Boolean) {
|
||||
binding.progressBar.isVisible = false
|
||||
if (!isSuccess) {
|
||||
binding.primaryAbv.isVisible = true
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,5 +17,6 @@ data class AppUpgradeResponse(
|
||||
@SerializedName("hardUpgrade") val hardUpgrade: Boolean?,
|
||||
@SerializedName("expectedAppVersionCode") val expectedAppVersionCode: Int?,
|
||||
@SerializedName("downloadableUrl") val downloadableUrl: String? = null,
|
||||
@SerializedName("verificationHash") val verificationHash: String? = null
|
||||
@SerializedName("verificationHash") val verificationHash: String? = null,
|
||||
@SerializedName("updateType") val updateType: String? = null
|
||||
) : Parcelable
|
||||
|
||||
@@ -39,7 +39,10 @@ object NaviAppUpdateDownloadManager {
|
||||
resultLauncher: ActivityResultLauncher<Intent>? = null
|
||||
) {
|
||||
|
||||
if (!updateJob?.isCompleted.orTrue()) {
|
||||
//commenting below code as the play store app doesn't support REQUEST_INSTALL_PACKAGES permission
|
||||
//And there is no point in download the update and attempting to install it.
|
||||
|
||||
/* if (!updateJob?.isCompleted.orTrue()) {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -113,6 +116,6 @@ object NaviAppUpdateDownloadManager {
|
||||
)
|
||||
callback?.onUpdateResult(false)
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
@@ -52,15 +52,6 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/layout_dp_32" />
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/progress_bar"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:indeterminateTint="@color/abv_bg_color_default"
|
||||
android:layout_marginTop="@dimen/layout_dp_32"
|
||||
android:indeterminate="true"
|
||||
android:visibility="gone" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<ImageView
|
||||
|
||||
@@ -113,4 +113,6 @@ object Constants {
|
||||
const val ERROR_CODE = "ERROR_CODE"
|
||||
const val AUTH_TOKEN = "authToken"
|
||||
const val DIALOG_DISMISS = "DIALOG_DISMISS"
|
||||
const val UPDATE_TYPE_PLAY_STORE = "navigateToPlayStore"
|
||||
const val UPDATE_TYPE_WEB = "navigateToWeb"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user