-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from allaboutapps/forceupdater
Force Update mode added
- Loading branch information
Showing
16 changed files
with
499 additions
and
251 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,31 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="at.allaboutapps.inappupdaterdemo"> | ||
package="at.allaboutapps.inappupdaterdemo"> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:roundIcon="@mipmap/ic_launcher_round" | ||
android:supportsRtl="true" | ||
android:theme="@style/AppTheme"> | ||
<activity android:name="at.allaboutapps.inappupdaterdemo.MainActivity" | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:roundIcon="@mipmap/ic_launcher_round" | ||
android:supportsRtl="true" | ||
android:theme="@style/AppTheme"> | ||
<activity | ||
android:name=".MainActivity" | ||
android:screenOrientation="portrait"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN"/> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER"/> | ||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
|
||
<activity | ||
android:name=".ForceUpdateDemoActivity" | ||
android:screenOrientation="portrait" /> | ||
<activity | ||
android:name=".UpdateTypeDemoActivity" | ||
android:screenOrientation="portrait" /> | ||
|
||
</application> | ||
|
||
</manifest> |
18 changes: 18 additions & 0 deletions
18
app/src/main/java/at/allaboutapps/inappupdaterdemo/DemoForceUpdateProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package at.allaboutapps.inappupdaterdemo | ||
|
||
import at.allaboutapps.inappupdater.ForceUpdateProvider | ||
|
||
/** | ||
* Implementation of ForceUpdateProvider to start a forced update | ||
*/ | ||
class DemoForceUpdateProvider : ForceUpdateProvider { | ||
|
||
override fun requestUpdateShouldBeImmediate(availableVersionCode: Int, doUpdate: () -> Unit) { | ||
|
||
// place your logic here | ||
|
||
// if a forced update is needed, just call doUpdate | ||
doUpdate() | ||
|
||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
app/src/main/java/at/allaboutapps/inappupdaterdemo/ForceUpdateDemoActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package at.allaboutapps.inappupdaterdemo | ||
|
||
import android.content.Context | ||
import android.content.Intent | ||
import android.os.Bundle | ||
import androidx.appcompat.app.AppCompatActivity | ||
import at.allaboutapps.inappupdater.InAppUpdateManager | ||
import at.allaboutapps.inappupdater.InAppUpdateStatus | ||
import io.reactivex.disposables.Disposables | ||
|
||
class ForceUpdateDemoActivity : AppCompatActivity() { | ||
|
||
companion object { | ||
fun newIntent(context: Context) = Intent(context, ForceUpdateDemoActivity::class.java) | ||
} | ||
|
||
private lateinit var inAppUpdateManager: InAppUpdateManager | ||
private var inAppUpdateStatusDisposable = Disposables.empty() | ||
|
||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
|
||
setContentView(R.layout.activity_force_update) | ||
initInAppUpdate() | ||
} | ||
|
||
private fun initInAppUpdate() { | ||
inAppUpdateManager = InAppUpdateManager(this, DemoForceUpdateProvider()) | ||
inAppUpdateStatusDisposable = inAppUpdateManager.observeInAppUpdateStatus() | ||
.subscribe { currentStatus -> | ||
if (currentStatus.isUpdatePending()) { | ||
inAppUpdateManager.startUpdate() | ||
} | ||
updateUI(currentStatus) | ||
} | ||
} | ||
|
||
fun updateUI(currentStatus: InAppUpdateStatus) { | ||
//Do nothing -> just a demo for forced update | ||
} | ||
|
||
/** | ||
* Immediate update type page is not uncloseable | ||
* Just recall startUpdate at onActivityResult | ||
*/ | ||
|
||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { | ||
inAppUpdateManager.onActivityResult(requestCode, resultCode) | ||
super.onActivityResult(requestCode, resultCode, data) | ||
} | ||
|
||
override fun onDestroy() { | ||
if (!inAppUpdateStatusDisposable.isDisposed) | ||
inAppUpdateStatusDisposable.dispose() | ||
super.onDestroy() | ||
} | ||
} |
81 changes: 6 additions & 75 deletions
81
app/src/main/java/at/allaboutapps/inappupdaterdemo/MainActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,91 +1,22 @@ | ||
package at.allaboutapps.inappupdaterdemo | ||
|
||
import android.os.Bundle | ||
import android.view.View | ||
import androidx.appcompat.app.AppCompatActivity | ||
import at.allaboutapps.inappupdater.InAppUpdateManager | ||
import at.allaboutapps.inappupdater.InAppUpdateStatus | ||
import io.reactivex.disposables.Disposables | ||
import kotlinx.android.synthetic.main.activity_main.* | ||
|
||
class MainActivity : AppCompatActivity() { | ||
|
||
private lateinit var inAppUpdateManager: InAppUpdateManager | ||
private var inAppUpdateStatusDisposable = Disposables.empty() | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_main) | ||
|
||
tvPackageName.text = packageName | ||
tvCurrentVersionCode.text = BuildConfig.VERSION_CODE.toString() | ||
|
||
initInAppUpdate() | ||
|
||
btUpdate.setOnClickListener { | ||
inAppUpdateManager.startUpdate(getSelectedUpdateType()) | ||
} | ||
|
||
btRestart.setOnClickListener { | ||
inAppUpdateManager.completeUpdate() | ||
} | ||
} | ||
|
||
@InAppUpdateManager.InAppUpdateType | ||
private fun getSelectedUpdateType() = | ||
if (updateTypeGroup.checkedButtonId == R.id.btImmediate) InAppUpdateManager.UPDATE_TYPE_IMMEDIATE else InAppUpdateManager.UPDATE_TYPE_FLEXIBLE | ||
|
||
private fun initInAppUpdate() { | ||
inAppUpdateManager = InAppUpdateManager(this) | ||
inAppUpdateStatusDisposable = inAppUpdateManager.observeInAppUpdateStatus() | ||
.subscribe { currentStatus -> | ||
if (currentStatus.isUpdatePending()) { | ||
inAppUpdateManager.startUpdate() | ||
} | ||
updateUI(currentStatus) | ||
} | ||
} | ||
setContentView(R.layout.activity_main) | ||
|
||
private fun updateUI(currentStatus: InAppUpdateStatus) { | ||
if (currentStatus.isUpdateInProgress) { | ||
showUpdateInProgressState(currentStatus) | ||
} else { | ||
tvAvailableAppVersion.text = if (currentStatus.availableVersionCode == 0) { | ||
"App not published in Play Store yet!" | ||
} else { | ||
currentStatus.availableVersionCode.toString() | ||
} | ||
if (currentStatus.isUpdateAvailable()) { | ||
tvUpdateAvailable.text = "YES" | ||
showUpdateAvailableState() | ||
} else { | ||
tvUpdateAvailable.text = "NO" | ||
} | ||
btForceUpdate.setOnClickListener { | ||
startActivity(ForceUpdateDemoActivity.newIntent(this)) | ||
} | ||
} | ||
|
||
private fun showUpdateAvailableState() { | ||
btUpdate.visibility = View.VISIBLE | ||
vgUpdateInProgress.visibility = View.GONE | ||
vgUpdateAvailable.visibility = View.VISIBLE | ||
vgUpdateFinished.visibility = View.GONE | ||
} | ||
|
||
private fun showUpdateInProgressState(currentStatus: InAppUpdateStatus) { | ||
if (currentStatus.isDownloading) { | ||
vgUpdateInProgress.visibility = View.VISIBLE | ||
vgUpdateAvailable.visibility = View.GONE | ||
vgUpdateFinished.visibility = View.GONE | ||
} else if (currentStatus.isDownloaded) { | ||
vgUpdateInProgress.visibility = View.GONE | ||
vgUpdateAvailable.visibility = View.GONE | ||
vgUpdateFinished.visibility = View.VISIBLE | ||
btUpdateType.setOnClickListener { | ||
startActivity(UpdateTypeDemoActivity.newIntent(this)) | ||
} | ||
} | ||
|
||
override fun onDestroy() { | ||
if (!inAppUpdateStatusDisposable.isDisposed) | ||
inAppUpdateStatusDisposable.dispose() | ||
super.onDestroy() | ||
} | ||
} | ||
} |
Oops, something went wrong.