Skip to content

Commit

Permalink
Refactors: InAppUpdateListener
Browse files Browse the repository at this point in the history
  • Loading branch information
pantstamp committed May 20, 2024
1 parent ec5dbb6 commit c138065
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 37 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package org.wordpress.android.inappupdate
import android.app.Activity

interface IInAppUpdateManager {
fun checkForAppUpdate(activity: Activity, listener: IInAppUpdateListener)
fun checkForAppUpdate(activity: Activity, listener: InAppUpdateListener)
fun completeAppUpdate()
fun cancelAppUpdate(updateType: Int)
fun onUserAcceptedAppUpdate(updateType: Int)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.wordpress.android.inappupdate

/**
* Abstract class for handling callbacks related to in-app update events.
*
* Each method provides a default implementation that does nothing, allowing
* implementers to only override the necessary methods without implementing
* all callback methods.
*/
abstract class InAppUpdateListener {
open fun onAppUpdateStarted(type: Int) {
// Default empty implementation
}

open fun onAppUpdateDownloaded() {
// Default empty implementation
}

open fun onAppUpdateInstalled() {
// Default empty implementation
}

open fun onAppUpdateFailed() {
// Default empty implementation
}

open fun onAppUpdateCancelled() {
// Default empty implementation
}

open fun onAppUpdatePending() {
// Default empty implementation
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ class InAppUpdateManagerImpl(
private val inAppUpdateAnalyticsTracker: InAppUpdateAnalyticsTracker,
private val currentTimeProvider: () -> Long = {System.currentTimeMillis()}
): IInAppUpdateManager {
private var updateListener: IInAppUpdateListener? = null
private var updateListener: InAppUpdateListener? = null

override fun checkForAppUpdate(activity: Activity, listener: IInAppUpdateListener) {
override fun checkForAppUpdate(activity: Activity, listener: InAppUpdateListener) {
updateListener = listener
appUpdateManager.appUpdateInfo.addOnSuccessListener { appUpdateInfo ->
handleUpdateInfoSuccess(appUpdateInfo, activity)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package org.wordpress.android.inappupdate
import android.app.Activity

class InAppUpdateManagerNoop: IInAppUpdateManager {
override fun checkForAppUpdate(activity: Activity, listener: IInAppUpdateListener) {
override fun checkForAppUpdate(activity: Activity, listener: InAppUpdateListener) {
/* Empty implementation */
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import org.wordpress.android.BuildConfig;
import org.wordpress.android.inappupdate.IInAppUpdateListener;
import org.wordpress.android.inappupdate.InAppUpdateListener;
import org.wordpress.android.inappupdate.IInAppUpdateManager;
import org.wordpress.android.R;
import org.wordpress.android.WordPress;
Expand Down Expand Up @@ -1213,30 +1213,10 @@ private void checkForInAppUpdate() {
mInAppUpdateManager.checkForAppUpdate(this, mInAppUpdateListener);
}

@NonNull final IInAppUpdateListener mInAppUpdateListener = new IInAppUpdateListener() {
@Override public void onAppUpdatePending() {
/* do nothing */
}

@NonNull final InAppUpdateListener mInAppUpdateListener = new InAppUpdateListener() {
@Override public void onAppUpdateDownloaded() {
popupSnackbarForCompleteUpdate();
}
@Override public void onAppUpdateStarted(int type) {
/* do nothing */
}

@Override public void onAppUpdateInstalled() {
/* do nothing */
}

@Override public void onAppUpdateFailed() {
/* do nothing */
}

@Override public void onAppUpdateCancelled() {
// Todo do I need to handle this?
/* do nothing */
}
};

private void popupSnackbarForCompleteUpdate() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class InAppUpdateManagerImplTest {
lateinit var inAppUpdateAnalyticsTracker: InAppUpdateAnalyticsTracker

@Mock
lateinit var updateListener: IInAppUpdateListener
lateinit var updateListener: InAppUpdateListener

@Mock
lateinit var activity: Activity
Expand Down

0 comments on commit c138065

Please sign in to comment.