Skip to content

Commit

Permalink
* Fixed APKPure parser.
Browse files Browse the repository at this point in the history
* Disabled Google Play parses since it's mostly useless.
* Updates now display both old and new version.
  • Loading branch information
rumboalla committed Feb 19, 2017
1 parent f227a27 commit ed58e7e
Show file tree
Hide file tree
Showing 12 changed files with 57 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class UpdaterAdapter
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

UpdaterAdapter(
Context context
Context context
) {
super(context, 0);
}
Expand Down
17 changes: 16 additions & 1 deletion app/src/main/java/com/apkupdater/model/Update.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,21 @@ public class Update
private String mName;
private String mPname;
private String mVersion;
private String mNewVersion;
private String mUrl;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

public Update(
InstalledApp app,
String url
String url,
String version
) {
setName(app.getName());
setPname(app.getPname());
setVersion(app.getVersion());
setUrl(url);
setNewVersion(version);
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -57,6 +60,18 @@ public void setPname(String pname) {

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

public String getNewVersion() {
return mNewVersion;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

public void setNewVersion(String version) {
mNewVersion = version;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

public String getVersion() {
return mVersion;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ private void updateSource(
public void run() {
IUpdater upd = createUpdater(type, getBaseContext(), app.getPname(), app.getVersion());
if (upd.getResultStatus() == UpdaterStatus.STATUS_UPDATE_FOUND) {
Update u = new Update(app, upd.getResultUrl());
Update u = new Update(app, upd.getResultUrl(), upd.getResultVersion());
mUpdates.add(u);
mBus.post(new UpdateProgressEvent(u));
} else if (upd.getResultStatus() == UpdaterStatus.STATUS_ERROR){
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/com/apkupdater/updater/IUpdater.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public interface IUpdater
String getResultUrl();
Throwable getResultError();
UpdaterStatus getResultStatus();
String getResultVersion();

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ protected UpdaterStatus parseUrl(

if (compareVersions(mCurrentVersion, app) == -1) {
mResultUrl = BaseUrl + row.getElementsByTag("a").get(0).attr("href");
mResultVersion = VersionUtil.getStringVersionFromString(app);
return UpdaterStatus.STATUS_UPDATE_FOUND;
}
} catch (Exception e) {
Expand Down
6 changes: 4 additions & 2 deletions app/src/main/java/com/apkupdater/updater/UpdaterAPKPure.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,16 @@ protected UpdaterStatus parseUrl(
doc = Jsoup.connect(url).get();

// Try to get the version
elements = doc.getElementsByAttributeValue("itemprop", "softwareVersion");
//elements = doc.getElementsByAttributeValue("itemprop", "softwareVersion");
elements = doc.getElementsByClass("version-ul").get(0).getElementsByTag("p");
if(elements == null || elements.size() == 0) {
return UpdaterStatus.STATUS_UPDATE_NOT_FOUND;
}

// If version is old, report update
if (compareVersions(mCurrentVersion, elements.get(0).text()) == -1) {
if (compareVersions(mCurrentVersion, elements.get(3).text()) == -1) {
mResultUrl = url;
mResultVersion = elements.get(3).text();
return UpdaterStatus.STATUS_UPDATE_FOUND;
}

Expand Down
9 changes: 9 additions & 0 deletions app/src/main/java/com/apkupdater/updater/UpdaterBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class UpdaterBase
protected String mPname;
protected String mUrl;
protected String mResultUrl;
protected String mResultVersion;
protected Throwable mError;
protected UpdaterStatus mResultStatus;
protected String mCurrentVersion;
Expand Down Expand Up @@ -110,6 +111,14 @@ public UpdaterStatus getResultStatus(
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

@Override
public String getResultVersion(
) {
return mResultVersion;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ protected UpdaterStatus parseUrl(

if (compareVersions(mCurrentVersion, elements.get(0).text()) == -1) {
mResultUrl = DownloadUrl + mPname;
mResultVersion = elements.get(0).text();
return UpdaterStatus.STATUS_UPDATE_FOUND;
}

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/apkupdater/updater/UpdaterUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void run() {
IUpdater upd = createUpdater(type, context, app.getPname(), app.getVersion());
if (upd != null) {
if (upd.getResultStatus() == UpdaterStatus.STATUS_UPDATE_FOUND) {
callback.onUpdate(new Update(app, upd.getResultUrl()));
callback.onUpdate(new Update(app, upd.getResultUrl(), upd.getResultVersion()));
} else if (upd.getResultStatus() == UpdaterStatus.STATUS_ERROR) {
errors.add(0);
}
Expand Down
13 changes: 13 additions & 0 deletions app/src/main/java/com/apkupdater/util/VersionUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,19 @@ public class VersionUtil {

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

static public String getStringVersionFromString(
String full_string
) {
List<Integer> v = getVersionFromString(full_string);
String version = "";
for (Integer i : v) {
version += i + ".";
}
return version.substring(0, version.length() - 1);
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

static public List<Integer> getVersionFromString(
String full_string
) {
Expand Down
9 changes: 8 additions & 1 deletion app/src/main/java/com/apkupdater/view/UpdaterView.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,14 @@ public void bind(
) {
mName.setText(update.getName());
mPname.setText(update.getPname());
mVersion.setText(update.getVersion());

// Build version string with both old and new version
String version = update.getVersion();
if (update.getNewVersion() != null && !update.getNewVersion().isEmpty()) {
version += " -> " + update.getNewVersion();
}

mVersion.setText(version);
mUrl.setText(update.getUrl());
mUrl.setTextColor(ColorUtitl.getColorFromTheme(getContext().getTheme(), R.attr.colorAccent));
try {
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
android:summary="@string/preferences_general_use_googleplay_summary"
android:title="@string/preferences_general_use_googleplay_title"
android:defaultValue="false"
android:enabled="false"
/>
<CheckBoxPreference
android:key="@string/preferences_general_use_apkpure_key"
Expand Down

0 comments on commit ed58e7e

Please sign in to comment.