Skip to content

Commit

Permalink
Merge branch 'release/v1.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
7LPdWcaW committed Aug 24, 2019
2 parents a4f9802 + f79c18c commit ad4f75e
Show file tree
Hide file tree
Showing 12 changed files with 143 additions and 39 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This addon periodically (1 day, only checks when using GrowTracker) checks for u

Downloaded updates are saved in `/sdcard/Download/`

[Latest APK: (MD5) cca4af53d1b2624ca9e19b36838fb3c0 v1.0.2](https://github.com/7LPdWcaW/GrowUpdater-Android/releases/download/v1.0.2/v1.0.2.apk)
[Latest APK: (MD5) bb9c10e1e7758a2fff72581df4a7df75 v1.1](https://github.com/7LPdWcaW/GrowUpdater-Android/releases/download/v1.1/app-release.apk)

# Installation

Expand Down
14 changes: 7 additions & 7 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 28
buildToolsVersion "28.0.3"
compileSdkVersion 29
buildToolsVersion "29.0.2"

defaultConfig {
applicationId "me.anon.grow.updater"

minSdkVersion 17
targetSdkVersion 28
targetSdkVersion 29

versionCode 3
versionName "v1.0.2"
versionCode 4
versionName "v1.1"

manifestPlaceholders = [versionName: versionName]
}
Expand All @@ -25,8 +25,8 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:support-compat:28.0.0'
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.core:core:1.0.2'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'com.loopj.android:android-async-http:1.4.9'
testImplementation 'junit:junit:4.12'
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />

<application
android:allowBackup="true"
Expand All @@ -13,7 +14,7 @@
android:label="Grow Updater"
>
<provider
android:name="android.support.v4.content.FileProvider"
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import android.content.DialogInterface;
import android.content.pm.PackageManager;
import android.os.Build;
import android.support.v4.content.PermissionChecker;
import androidx.core.content.PermissionChecker;

public class PermissionHelper
{
Expand Down
107 changes: 89 additions & 18 deletions app/src/main/java/me/anon/grow/updater/CheckUpdateReceiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@
import android.content.pm.PackageManager;
import android.os.Build;
import android.preference.PreferenceManager;
import android.support.v4.app.NotificationCompat;
import android.text.TextUtils;
import android.widget.Toast;

import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonNull;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.loopj.android.http.AsyncHttpClient;
Expand All @@ -29,10 +30,10 @@
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import androidx.core.app.NotificationCompat;
import cz.msebera.android.httpclient.Header;

import static android.preference.PreferenceManager.getDefaultSharedPreferences;
Expand Down Expand Up @@ -67,6 +68,29 @@ public static class Version implements Serializable

public static Version parse(String version)
{
if (version.equalsIgnoreCase("alpha"))
{
Version v = new Version();
v.major = -1;
v.minor = -1;
v.hot = -1;

v.type = "alpha";
v.iteration = 1;
return v;
}
else if (version.equalsIgnoreCase("beta"))
{
Version v = new Version();
v.major = -1;
v.minor = -1;
v.hot = -1;

v.type = "beta";
v.iteration = 1;
return v;
}

Pattern regex = Pattern.compile("v?([0-9]{1,2})(.?)([0-9]{1,2})((.?)([0-9]{1,2}))?(-([a-zA-Z]+)([0-9]+))?");
Matcher matcher = regex.matcher(version);

Expand Down Expand Up @@ -112,6 +136,8 @@ public boolean newerThan(Version otherVersion)
return false;
}

if (this.major == -1 && this.minor == -1 && this.hot == -1) return this.releaseDate > otherVersion.releaseDate;

if (this.major > otherVersion.major)
{
return true;
Expand Down Expand Up @@ -164,6 +190,11 @@ private boolean checkPreReleaseNewer(Version otherVersion)

@Override public String toString()
{
if (major == -1 && minor == -1 && hot == -1)
{
return type + " Nightly build";
}

String additional = "";

if (hot > 0)
Expand Down Expand Up @@ -198,9 +229,19 @@ private boolean checkPreReleaseNewer(Version otherVersion)
@Override public void onReceive(final Context context, Intent intent)
{
long lastChecked = getDefaultSharedPreferences(context).getLong("last_checked", 0);
long oneDay = TimeUnit.DAYS.toMillis(1);
String frequency = getDefaultSharedPreferences(context).getString("check_frequency", "3600000");
long freqInt = 0;
try
{
freqInt = Long.parseLong(frequency);
}
catch (NumberFormatException e)
{
e.printStackTrace();
}

final boolean force = intent.getExtras() != null && intent.getExtras().containsKey("force");
if (System.currentTimeMillis() - lastChecked > oneDay || force)
if (System.currentTimeMillis() - lastChecked > freqInt || force)
{
getDefaultSharedPreferences(context).edit()
.putLong("last_checked", System.currentTimeMillis())
Expand All @@ -219,7 +260,6 @@ private boolean checkPreReleaseNewer(Version otherVersion)
packageInfo = packageManager.getPackageInfo("me.anon.grow", 0);
}
catch (Exception e){}

final int versionCode = packageInfo == null ? 0 : packageInfo.versionCode;
final String versionName = packageInfo == null ? "0.0" : packageInfo.versionName;
final Version currentVersion = Version.parse(versionName);
Expand All @@ -236,6 +276,7 @@ private boolean checkPreReleaseNewer(Version otherVersion)
if (ai.metaData != null)
{
currentVersion.appType = ai.metaData.getString("me.anon.grow.APP_TYPE", "original");
currentVersion.releaseDate = Long.parseLong(ai.metaData.getString("me.anon.grow.VERSION_DATE", "0"));
}
}
catch (PackageManager.NameNotFoundException e)
Expand All @@ -261,7 +302,18 @@ private boolean checkPreReleaseNewer(Version otherVersion)
for (JsonElement element : jsonArray)
{
JsonObject jsonObject = element.getAsJsonObject();
Version releaseVersion = Version.parse(jsonObject.get("name").getAsString());
String name = "";

if (jsonObject.get("name") != JsonNull.INSTANCE && !TextUtils.isEmpty(jsonObject.get("name").getAsString()))
{
name = jsonObject.get("name").getAsString();
}
else
{
name = jsonObject.get("tag_name").getAsString();
}

Version releaseVersion = Version.parse(name);

if (releaseVersion != null)
{
Expand All @@ -275,7 +327,11 @@ private boolean checkPreReleaseNewer(Version otherVersion)
e.printStackTrace();
}

releaseVersion.releaseNotes = jsonObject.get("body").getAsString();
releaseVersion.releaseNotes = "";
if (jsonObject.get("body") != JsonNull.INSTANCE)
{
releaseVersion.releaseNotes = jsonObject.get("body").getAsString();
}

for (JsonElement assets : jsonObject.get("assets").getAsJsonArray())
{
Expand Down Expand Up @@ -303,27 +359,42 @@ private boolean checkPreReleaseNewer(Version otherVersion)
}
});

Version latest = releases.get(0);
Version latestStable = releases.get(0);
Version latest = null;
Version latestBeta = null;
Version latestStable = null;

for (Version release : releases)
{
if (release.type.equals(""))
if (release.type.equals("") && latestStable == null)
{
latestStable = release;
break;
}
else if (release.type.equals("alpha") && latest == null)
{
latest = release;
}
else if (release.type.equals("beta") && latestBeta == null)
{
latestBeta = release;
}
}

boolean experimental = PreferenceManager.getDefaultSharedPreferences(context).getBoolean("experimental", false);
if ((!latest.type.equals("") && experimental && latest.newerThan(currentVersion))
|| latestStable.newerThan(currentVersion))
boolean beta = PreferenceManager.getDefaultSharedPreferences(context).getBoolean("beta", false);

if (context == null) return;

if (experimental && latest.newerThan(currentVersion))
{
// send notification
if (context != null)
{
sendUpdateNotification(context, experimental ? latest : latestStable);
}
sendUpdateNotification(context, latest);
}
else if (beta && latest.newerThan(currentVersion))
{
sendUpdateNotification(context, latestBeta);
}
else if (latest != null && latest.newerThan(currentVersion))
{
sendUpdateNotification(context, latest);
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/me/anon/grow/updater/ConfigureActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceFragment;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import android.text.Html;

import java.io.BufferedInputStream;
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/java/me/anon/grow/updater/DownloadActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.content.FileProvider;
import android.support.v7.app.AppCompatActivity;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.FileProvider;
import androidx.appcompat.app.AppCompatActivity;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;
Expand Down
15 changes: 15 additions & 0 deletions app/src/main/res/values/arrays.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>

<resources>
<string-array name="frequency_entries">
<item>Hourly</item>
<item>Daily</item>
<item>Weekly</item>
</string-array>

<string-array name="frequency_values">
<item>3600000</item>
<item>86400000</item>
<item>604800000</item>
</string-array>
</resources>
19 changes: 17 additions & 2 deletions app/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,25 @@
android:summary="Tap to check now"
/>

<ListPreference
android:key="check_frequency"
android:title="Maximum check frequency"
android:summary="How often to allow to check - Only triggers when inside GrowTracker. Currently %s"
android:entries="@array/frequency_entries"
android:entryValues="@array/frequency_values"
android:defaultValue="3600000"
/>

<CheckBoxPreference
android:key="beta"
android:title="Opt-in for beta builds"
android:summary="Allow for beta builds to be downloaded"
/>

<CheckBoxPreference
android:key="experimental"
android:title="Opt-in for experimental builds"
android:summary="Allow for alpha and beta builds to be downloaded"
android:title="Opt-in for experimental develop builds"
android:summary="Allow for alpha builds to be downloaded - WARNING: EXPERIMENTAL!"
/>
</PreferenceCategory>

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.android.tools.build:gradle:3.4.2'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
android.enableJetifier=true
android.useAndroidX=true
org.gradle.jvmargs=-Xmx1536m

# When configured, Gradle will run in incubating parallel mode.
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Mon Oct 22 13:42:28 BST 2018
#Sun Aug 18 20:50:58 BST 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip

0 comments on commit ad4f75e

Please sign in to comment.