From 93acd8688c4f3125d7731c134d1ab143ff8271cb Mon Sep 17 00:00:00 2001 From: galeen <2math@mail.bg> Date: Mon, 2 Sep 2019 17:00:15 +0300 Subject: [PATCH] update versions to match server weak callback tested with proguard --- app/build.gradle | 29 +++++++++++- .../coreapp/ui/login/LoginActivity.java | 29 +++++++----- core_library/proguard-rules.pro | 4 +- .../base_library/utils/versions/Versions.java | 44 ++++++++++++------- .../utils/versions/VersionsUtil.java | 41 ++++++++++------- gradle.properties | 5 +++ 6 files changed, 106 insertions(+), 46 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 8508d6b..d51526c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,19 +10,46 @@ android { versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } + + signingConfigs { + release { + try { + storeFile file(KEYSTORE) + storePassword KEYSTORE_PASSWORD + keyAlias KEY_USER + keyPassword KEY_PASSWORD + } + catch (ex) { + throw new InvalidUserDataException("You should define KEYSTORE_PASSWORD and KEY_PASSWORD in gradle.properties.") + } + } + debug { + try { + storeFile file(KEYSTORE) + storePassword KEYSTORE_PASSWORD + keyAlias KEY_USER + keyPassword KEY_PASSWORD + } + catch (ex) { + throw new InvalidUserDataException("You should define KEYSTORE_PASSWORD and KEY_PASSWORD in gradle.properties.") + } + } + } + buildTypes { release { minifyEnabled true shrinkResources true proguardFiles(fileTree(dir: 'proguard', include: ['*.pro']).asList().toArray()) proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' -// signingConfig signingConfigs.release + signingConfig signingConfigs.release } debug { minifyEnabled false proguardFiles(fileTree(dir: 'proguard', include: ['*.pro']).asList().toArray()) proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + signingConfig signingConfigs.debug // ext.enableCrashlytics = false } } diff --git a/app/src/main/java/com/criapp_studio/coreapp/ui/login/LoginActivity.java b/app/src/main/java/com/criapp_studio/coreapp/ui/login/LoginActivity.java index 4a3fd38..dcbda92 100644 --- a/app/src/main/java/com/criapp_studio/coreapp/ui/login/LoginActivity.java +++ b/app/src/main/java/com/criapp_studio/coreapp/ui/login/LoginActivity.java @@ -22,6 +22,7 @@ public class LoginActivity extends BaseActivity implements Login private FrameLayout flContainer; private FontTextView tvHello; private boolean initOnResume = false; + private VersionsUtil.Callback versionsCallback; @Override protected void onCreate(Bundle savedInstanceState) { @@ -31,19 +32,23 @@ protected void onCreate(Bundle savedInstanceState) { initView(); if (savedInstanceState == null) {//else is recreate + versionsCallback = new VersionsUtil.Callback() { + @Override + public void onEnd(int status) { + if (status != VersionsUtil.ACTION_MUST_UPDATE && status != VersionsUtil.ACTION_CAN_UPDATE) { + activityViewModel.init(); + } + } + }; + new VersionsUtil().checkVersions(this, activityViewModel.getNetworkCallback(), - new Action(Action.GET_UNAUTHORIZED, "http://www.mocky.io/v2/5d6525d23400002c00f44600", null) - .setIsCheckServerUrl(false) - .setFullUrl(true), - MainCallback.TYPE_DIALOG, BuildConfig.VERSION_CODE, - new VersionsUtil.Callback() { - @Override - public void onEnd(int status) { - if (status != VersionsUtil.ACTION_MUST_UPDATE && status != VersionsUtil.ACTION_CAN_UPDATE) { - activityViewModel.init(); - } - } - }); + new Action(Action.GET_UNAUTHORIZED, + "https://gobeauty-mobile-dev.herokuapp.com/versions/ANDROID", + null) + .setIsCheckServerUrl(false) + .setFullUrl(true), + MainCallback.TYPE_DIALOG, BuildConfig.VERSION_CODE, + versionsCallback); } } diff --git a/core_library/proguard-rules.pro b/core_library/proguard-rules.pro index 1b472bd..1f40fef 100644 --- a/core_library/proguard-rules.pro +++ b/core_library/proguard-rules.pro @@ -47,4 +47,6 @@ ### Square Picasso specific rules ## ### https://square.github.io/picasso/ ## # -#-dontwarn com.squareup.okhttp.** \ No newline at end of file +#-dontwarn com.squareup.okhttp.** + +-keep class com.futurist_labs.android.base_library.utils.versions.Versions** { *; } \ No newline at end of file diff --git a/core_library/src/main/java/com/futurist_labs/android/base_library/utils/versions/Versions.java b/core_library/src/main/java/com/futurist_labs/android/base_library/utils/versions/Versions.java index 2658851..c2c0b66 100644 --- a/core_library/src/main/java/com/futurist_labs/android/base_library/utils/versions/Versions.java +++ b/core_library/src/main/java/com/futurist_labs/android/base_library/utils/versions/Versions.java @@ -7,25 +7,36 @@ * Created by Galeen on 8/27/2019. */ public class Versions implements Parcelable { - private int currentAndroidVersion; - private int minimumAndroidVersion; + private int currentVersion; + private int minimalVersion; + private String clientVersion; - public int getCurrentAndroidVersion() { - return currentAndroidVersion; + public int getCurrentVersion() { + return currentVersion; } - public void setCurrentAndroidVersion(int currentAndroidVersion) { - this.currentAndroidVersion = currentAndroidVersion; + public void setCurrentVersion(int currentVersion) { + this.currentVersion = currentVersion; } - public int getMinimumAndroidVersion() { - return minimumAndroidVersion; + public int getMinimalVersion() { + return minimalVersion; } - public void setMinimumAndroidVersion(int minimumAndroidVersion) { - this.minimumAndroidVersion = minimumAndroidVersion; + public void setMinimalVersion(int minimalVersion) { + this.minimalVersion = minimalVersion; } + public String getClientVersion() { + return clientVersion; + } + + public void setClientVersion(final String clientVersion) { + this.clientVersion = clientVersion; + } + + public Versions() { + } @Override public int describeContents() { @@ -34,16 +45,15 @@ public int describeContents() { @Override public void writeToParcel(Parcel dest, int flags) { - dest.writeInt(this.currentAndroidVersion); - dest.writeInt(this.minimumAndroidVersion); - } - - public Versions() { + dest.writeInt(this.currentVersion); + dest.writeInt(this.minimalVersion); + dest.writeString(this.clientVersion); } protected Versions(Parcel in) { - this.currentAndroidVersion = in.readInt(); - this.minimumAndroidVersion = in.readInt(); + this.currentVersion = in.readInt(); + this.minimalVersion = in.readInt(); + this.clientVersion = in.readString(); } public static final Creator CREATOR = new Creator() { diff --git a/core_library/src/main/java/com/futurist_labs/android/base_library/utils/versions/VersionsUtil.java b/core_library/src/main/java/com/futurist_labs/android/base_library/utils/versions/VersionsUtil.java index 178e18d..6ebf365 100644 --- a/core_library/src/main/java/com/futurist_labs/android/base_library/utils/versions/VersionsUtil.java +++ b/core_library/src/main/java/com/futurist_labs/android/base_library/utils/versions/VersionsUtil.java @@ -10,6 +10,7 @@ import com.futurist_labs.android.base_library.ui.BaseEvents; import com.futurist_labs.android.base_library.ui.versions.UpdateActivity; import com.futurist_labs.android.base_library.ui.versions.UpdateDialogFragment; +import com.futurist_labs.android.base_library.utils.LogUtils; import java.lang.ref.WeakReference; @@ -23,20 +24,23 @@ public class VersionsUtil { public static final int ACTION_MUST_UPDATE = 3; private WeakReference activityWeakReference; + private WeakReference callbackWeakReference; public void checkVersions(AppCompatActivity activity, BaseEvents presenterCallback, Action action, - int progressType, final int currentAppVersion, final Callback callback) { + int progressType, final int currentAppVersion, Callback callback) { if (activity == null || action == null) { return; } activityWeakReference = new WeakReference<>(activity); + callbackWeakReference = new WeakReference<>(callback); + BaseNetworkManager.doMainActionSynchronized( new MainCallback(presenterCallback, progressType) { @Override public void onNoNetwork() { super.onNoNetwork(); - if(callback!=null){ - callback.onEnd(-2); + if (callbackWeakReference.get() != null) { + callbackWeakReference.get().onEnd(-2); } } @@ -44,17 +48,17 @@ public void onNoNetwork() { public void inTheEndOfDoInBackground(NetworkResponse networkResponse) { super.inTheEndOfDoInBackground(networkResponse); networkResponse.object = BaseJsonParser.fromJson(networkResponse.json, - Versions.class); + Versions.class); } @Override public void onSuccess(NetworkResponse networkResponse) { super.onSuccess(networkResponse); - if(activityWeakReference.get() != null){ + if (activityWeakReference.get() != null) { int result = validateVersionsAndAct(activityWeakReference.get(), - networkResponse.object,currentAppVersion); - if(callback!=null){ - callback.onEnd(result); + networkResponse.object, currentAppVersion); + if (callbackWeakReference.get() != null) { + callbackWeakReference.get().onEnd(result); } } } @@ -62,18 +66,19 @@ public void onSuccess(NetworkResponse networkResponse) { @Override public void onError(String msg, NetworkResponse networkResponse) { super.onError(msg, networkResponse); - if(callback!=null){ - callback.onEnd(-1); + if (callbackWeakReference.get() != null) { + callbackWeakReference.get().onEnd(-1); } } }, - action, + action, "checkVersions"); } - public interface Callback{ + public interface Callback { void onEnd(int status); } + /** * Will check versions with current and show blocking activity or update dialog * @@ -84,6 +89,10 @@ public interface Callback{ */ public int validateVersionsAndAct(AppCompatActivity activity, Versions versionsFromServer, int currentVersion) { +// versionsFromServer.setCurrentVersion(4); +// versionsFromServer.setMinimalVersion(3); + LogUtils.d("CurrentVersion : " + versionsFromServer.getCurrentVersion() + + " MinimalVersion: " + versionsFromServer.getMinimalVersion()); int action = validateVersions(versionsFromServer, currentVersion); actOnNewVersions(activity, action); return action; @@ -93,8 +102,8 @@ public int validateVersions(Versions versionsFromServer, int currentVersion) { if (versionsFromServer == null) { return ACTION_NO_VERSIONS; } else { - if (versionsFromServer.getCurrentAndroidVersion() > currentVersion) { - if (versionsFromServer.getMinimumAndroidVersion() > currentVersion) { + if (versionsFromServer.getCurrentVersion() > currentVersion) { + if (versionsFromServer.getMinimalVersion() > currentVersion) { return ACTION_MUST_UPDATE; } else { return ACTION_CAN_UPDATE; @@ -106,7 +115,9 @@ public int validateVersions(Versions versionsFromServer, int currentVersion) { } public void actOnNewVersions(AppCompatActivity activity, int action) { - if (activity == null) return; + if (activity == null) { + return; + } if (action == ACTION_MUST_UPDATE) { UpdateActivity.show(activity); diff --git a/gradle.properties b/gradle.properties index 743d692..1ce0a3d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -11,3 +11,8 @@ org.gradle.jvmargs=-Xmx1536m # This option should only be used with decoupled projects. More details, visit # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects # org.gradle.parallel=true + +KEYSTORE=test_key.jks +KEYSTORE_PASSWORD=test123 +KEY_USER=key +KEY_PASSWORD=test123 \ No newline at end of file