Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
classpath 'com.android.tools.build:gradle:3.1.4'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
Expand All @@ -15,6 +16,10 @@ buildscript {
allprojects {
repositories {
jcenter()
mavenCentral()
google()

maven { url "https://jitpack.io" }
}
}

Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
14 changes: 7 additions & 7 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ group = 'com.github.eggheadgames'

android {
compileSdkVersion 25
buildToolsVersion "25.0.1"

defaultConfig {
minSdkVersion 15
targetSdkVersion 25
versionCode 13
versionName "1.5.2"
versionName "1.7.0"
}
buildTypes {
release {
Expand All @@ -29,11 +28,12 @@ android {
}

dependencies {
testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:1.10.19'
testCompile 'org.json:json:20160212'
testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-core:1.10.19'
testImplementation 'org.json:json:20160212'

compile fileTree(dir: 'libs', include: ['*.jar'])
implementation fileTree(dir: 'libs', include: ['*.jar'])
//noinspection GradleDependency
compile 'com.android.support:appcompat-v7:25.0.0'
implementation 'com.android.support:appcompat-v7:25.0.0'
implementation 'org.jsoup:jsoup:1.11.3'
}
4 changes: 2 additions & 2 deletions library/quality.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pmd {
reportsDir = file("$project.buildDir/outputs/")
}

task findbugs(type: FindBugs, dependsOn: assembleDebug) {
task findbugs(type: FindBugs, dependsOn: "assembleDebug") {
description 'Run findbugs'
group 'verification'

Expand All @@ -31,7 +31,7 @@ task findbugs(type: FindBugs, dependsOn: assembleDebug) {
}
}

task pmd(type: Pmd, dependsOn: assembleDebug) {
task pmd(type: Pmd, dependsOn: "assembleDebug") {
description 'Run pmd'
group 'verification'

Expand Down
72 changes: 72 additions & 0 deletions library/src/main/java/com/eggheadgames/siren/Siren.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@

import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.AsyncTask;
import android.support.annotation.VisibleForTesting;
import android.util.Log;

import org.json.JSONException;
import org.json.JSONObject;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.io.BufferedReader;
import java.io.IOException;
Expand Down Expand Up @@ -103,6 +109,19 @@ public void checkVersion(Activity activity, SirenVersionCheckType versionCheckTy
}
}


public void checkVersion(Activity activity, SirenVersionCheckType versionCheckType) {

mActivityRef = new WeakReference<>(activity);

if (versionCheckType == SirenVersionCheckType.IMMEDIATELY) {
performVersionCheck();
} else if (versionCheckType.getValue() <= getSirenHelper().getDaysSinceLastCheck(mApplicationContext)
||getSirenHelper().getLastVerificationDate(mApplicationContext) == 0) {
performVersionCheck();
}
}

public void setMajorUpdateAlertType(@SuppressWarnings("SameParameterValue") SirenAlertType majorUpdateAlertType) {
this.majorUpdateAlertType = majorUpdateAlertType;
}
Expand Down Expand Up @@ -136,6 +155,11 @@ protected void performVersionCheck(String appDescriptionUrl) {
new LoadJsonTask().execute(appDescriptionUrl);
}

@VisibleForTesting
protected void performVersionCheck() {
new LoadVersionFromGooglePlayStoreTask().execute();
}

@VisibleForTesting
protected void handleVerificationResults(String json) {
try {
Expand Down Expand Up @@ -196,6 +220,7 @@ private boolean checkVersionName(JSONObject appJson) throws JSONException{
SirenAlertType alertType = null;
String[] minVersionNumbers = minVersionName.split("\\.");
String[] currentVersionNumbers = currentVersionName.split("\\.");

//noinspection ConstantConditions
if (minVersionNumbers != null && currentVersionNumbers != null
&& minVersionNumbers.length == currentVersionNumbers.length) {
Expand Down Expand Up @@ -349,4 +374,51 @@ protected void onPostExecute(String result) {
}
}
}

private static class LoadVersionFromGooglePlayStoreTask extends AsyncTask<Void, Void, String> {

@Override
protected String doInBackground(Void... voids) {
String newVersion = null;
String packageName = Siren.sirenInstance.getSirenHelper().getPackageName(Siren.sirenInstance.mApplicationContext);

try {
Document document = Jsoup.connect("https://play.google.com/store/apps/details?id=" + packageName + "&hl=en")
.timeout(30000)
.userAgent("Mozilla/5.0 (Windows; U; WindowsNT 5.1; en-US; rv1.8.1.6) Gecko/20070725 Firefox/2.0.0.6")
.referrer("http://www.google.com")
.get();
if (document != null) {
Elements element = document.getElementsContainingOwnText("Current Version");
for (Element ele : element) {
if (ele.siblingElements() != null) {
Elements sibElemets = ele.siblingElements();
for (Element sibElemet : sibElemets) {
newVersion = sibElemet.text();
}
}
}
}
} catch (IOException e) {
e.printStackTrace();
}

return newVersion;
}

@Override
protected void onPostExecute(String newVersion) {
super.onPostExecute(newVersion);

if (Siren.sirenInstance.getSirenHelper().isEmpty(newVersion)) {
if (Siren.sirenInstance.mSirenListener != null) {
Siren.sirenInstance.mSirenListener.onError(new NullPointerException());
}
} else {
String packageName = Siren.sirenInstance.getSirenHelper().getPackageName(Siren.sirenInstance.mApplicationContext);
String jsonString = "{ \"" + packageName + "\": { \"" + Constants.JSON_MIN_VERSION_NAME +"\": \"" + newVersion + "\" } }";
Siren.sirenInstance.handleVerificationResults(jsonString);
}
}
}
}