-
Notifications
You must be signed in to change notification settings - Fork 0
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
Have DefaultDialog automatically launch Play Store for the user (#14) #22
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
149d127
PackageDetails interface additions (getVersion, isDevelopmentBuild, a…
ssawchenko ae83f4f
Added unit tests for development failure
ssawchenko a1bc69c
DefautUpgradeDialog now handles development failure state
ssawchenko 6648e41
DefaultPackageDetails now assumes that all development builds have a …
ssawchenko 7de67a1
Updated readme
ssawchenko f111fd3
Fixed incorrect package name
ssawchenko 1448c44
DefaultUpgradeDialog now takes package name, and launches the Play St…
ssawchenko 70008c8
Merge branch 'main' into ss/14_play_store_launch
ssawchenko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,18 +1,25 @@ | ||
package com.steamclock.versioncheckkotlin.interfaces | ||
package com.steamclock.versioncheckkotlin | ||
|
||
import android.app.Activity | ||
import android.app.AlertDialog | ||
import android.app.Application | ||
import android.content.Context | ||
import android.content.Intent | ||
import android.net.Uri | ||
import android.os.Bundle | ||
import com.steamclock.versioncheckkotlin.models.DisplayState | ||
import kotlinx.coroutines.MainScope | ||
import kotlinx.coroutines.flow.StateFlow | ||
import kotlinx.coroutines.flow.collect | ||
import kotlinx.coroutines.launch | ||
import java.lang.Exception | ||
import java.lang.ref.WeakReference | ||
|
||
class DefaultUpgradeDialog(private val versionDisplayState: StateFlow<DisplayState>) : Application.ActivityLifecycleCallbacks { | ||
class DefaultUpgradeDialog( | ||
private val versionDisplayState: StateFlow<DisplayState>, | ||
private val packageName: String | ||
) : Application.ActivityLifecycleCallbacks { | ||
|
||
private var dialog: AlertDialog? = null | ||
private val coroutineScope = MainScope() | ||
private var needToShowDialog = false | ||
|
@@ -21,6 +28,7 @@ class DefaultUpgradeDialog(private val versionDisplayState: StateFlow<DisplaySta | |
init { | ||
coroutineScope.launch { | ||
versionDisplayState.collect { displayState -> | ||
// If we have a current context, show the dialog immediately; else we need to wait. | ||
when (val ctx = currentActivityContext?.get()) { | ||
null -> needToShowDialog = true | ||
else -> showForState(ctx, displayState) | ||
|
@@ -95,13 +103,12 @@ class DefaultUpgradeDialog(private val versionDisplayState: StateFlow<DisplaySta | |
|
||
if (requiresUpdate) { | ||
// Do not set click listener here, we do not want the button to dismiss the dialog. | ||
setNeutralButton("Upgrade", null) | ||
setPositiveButton("Update", null) | ||
} | ||
|
||
if (canDismiss) { | ||
setPositiveButton("OK") { _, _ -> | ||
setNegativeButton("Close") { _, _ -> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed button wording to imply that action would close dialog |
||
dialog = null | ||
/* todo */ | ||
} | ||
} | ||
} | ||
|
@@ -111,13 +118,25 @@ class DefaultUpgradeDialog(private val versionDisplayState: StateFlow<DisplaySta | |
// Tap dance a little to override the click listener so the dialog will not dismiss | ||
dialog?.apply { | ||
setOnShowListener { | ||
getButton(AlertDialog.BUTTON_NEUTRAL)?.setOnClickListener { | ||
// todo Proxy out to Play Store. | ||
getButton(AlertDialog.BUTTON_POSITIVE)?.setOnClickListener { | ||
launchPlayStorePage() | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Set BUTTON_POSITIVE instead, since it is the affirmative action |
||
} | ||
} | ||
} | ||
|
||
private fun launchPlayStorePage() { | ||
try { | ||
val intent = Intent(Intent.ACTION_VIEW).apply { | ||
data = Uri.parse("https://play.google.com/store/apps/details?id=$packageName") | ||
setPackage("com.android.vending") | ||
} | ||
currentActivityContext?.get()?.startActivity(intent) | ||
} catch (e: Exception) { | ||
// 2021-10-05 How to handle error | ||
} | ||
} | ||
|
||
//----------------------------------------------------------------- | ||
// Using ActivityLifecycleCallbacks to launch version checks and collect | ||
// state flows. | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now using same comments and setup in App and Readme for UpgradeDialog