Skip to content

Commit

Permalink
update versions to match server
Browse files Browse the repository at this point in the history
weak callback
tested with proguard
  • Loading branch information
2math committed Sep 2, 2019
1 parent 0dd3927 commit 93acd86
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 46 deletions.
29 changes: 28 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class LoginActivity extends BaseActivity<LoginViewModel> implements Login
private FrameLayout flContainer;
private FontTextView tvHello;
private boolean initOnResume = false;
private VersionsUtil.Callback versionsCallback;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -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);
}
}

Expand Down
4 changes: 3 additions & 1 deletion core_library/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,6 @@
### Square Picasso specific rules ##
### https://square.github.io/picasso/ ##
#
#-dontwarn com.squareup.okhttp.**
#-dontwarn com.squareup.okhttp.**

-keep class com.futurist_labs.android.base_library.utils.versions.Versions** { *; }
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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<Versions> CREATOR = new Creator<Versions>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -23,57 +24,61 @@ public class VersionsUtil {
public static final int ACTION_MUST_UPDATE = 3;

private WeakReference<AppCompatActivity> activityWeakReference;
private WeakReference<Callback> 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<Versions>(presenterCallback, progressType) {
@Override
public void onNoNetwork() {
super.onNoNetwork();
if(callback!=null){
callback.onEnd(-2);
if (callbackWeakReference.get() != null) {
callbackWeakReference.get().onEnd(-2);
}
}

@Override
public void inTheEndOfDoInBackground(NetworkResponse networkResponse) {
super.inTheEndOfDoInBackground(networkResponse);
networkResponse.object = BaseJsonParser.fromJson(networkResponse.json,
Versions.class);
Versions.class);
}

@Override
public void onSuccess(NetworkResponse<Versions> 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);
}
}
}

@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
*
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 93acd86

Please sign in to comment.