Skip to content

Commit

Permalink
Addressing #36
Browse files Browse the repository at this point in the history
Internal Updater behavior.
  • Loading branch information
avluis committed Aug 25, 2015
1 parent a442680 commit fba32f9
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 17 deletions.
4 changes: 2 additions & 2 deletions app/src/main/java/me/devsaki/hentoid/HentoidApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ protected int sizeOf(String key, Bitmap bitmap) {

private void UpdateCheck(boolean onlyWifi) {
if (onlyWifi) {
UpdateCheck.getInstance().checkForUpdate(getApplicationContext(), updateURL, true, new UpdateCheck.UpdateCheckCallback() {
UpdateCheck.getInstance().checkForUpdate(getApplicationContext(), updateURL, true, false, new UpdateCheck.UpdateCheckCallback() {
@Override
public void noUpdateAvailable() {
System.out.println("No update available.");
Expand All @@ -93,7 +93,7 @@ public void onUpdateAvailable() {
}
});
} else {
UpdateCheck.getInstance().checkForUpdate(getApplicationContext(), updateURL, false, new UpdateCheck.UpdateCheckCallback() {
UpdateCheck.getInstance().checkForUpdate(getApplicationContext(), updateURL, false, false, new UpdateCheck.UpdateCheckCallback() {
@Override
public void noUpdateAvailable() {
System.out.println("No update available.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,8 @@ public void onClick(DialogInterface dialog, int which) {
mUpdateCheck.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
UpdateCheck.getInstance().checkForUpdate(getActivity().getApplicationContext(), updateURL, false, new UpdateCheck.UpdateCheckCallback() {
Toast.makeText(getActivity().getApplicationContext(), "Checking for updates...", Toast.LENGTH_SHORT).show();
UpdateCheck.getInstance().checkForUpdate(getActivity().getApplicationContext(), updateURL, false, true, new UpdateCheck.UpdateCheckCallback() {
@Override
public void noUpdateAvailable() {
System.out.println("Manual update check: No update available.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* Created by avluis on 8/21/15.
*/
public interface IUpdateCheck {
void checkForUpdate(final Context context, final String updateURL, final boolean onlyWifi, final UpdateCheck.UpdateCheckCallback updateCheckResult);
void checkForUpdate(final Context context, final String updateURL, final boolean onlyWifi, final boolean showToast, final UpdateCheck.UpdateCheckCallback updateCheckResult);

int getAppVersionCode(final Context context) throws PackageManager.NameNotFoundException;
}
33 changes: 20 additions & 13 deletions app/src/main/java/me/devsaki/hentoid/updater/UpdateCheck.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public class UpdateCheck implements IUpdateCheck {
private int progressBar;
private long total;
private long done;
private boolean showToast;

private UpdateCheck() {
}
Expand All @@ -75,7 +76,7 @@ public static UpdateCheck getInstance() {
}

@Override
public void checkForUpdate(Context context, final String updateURL, final boolean onlyWifi, final UpdateCheckCallback updateCheckResult) {
public void checkForUpdate(Context context, final String updateURL, final boolean onlyWifi, final boolean showToast, final UpdateCheckCallback updateCheckResult) {
if (context == null || updateURL == null) {
throw new NullPointerException("context or UpdateURL is null");
}
Expand All @@ -98,6 +99,8 @@ public void checkForUpdate(Context context, final String updateURL, final boolea
} else {
Log.e("networkInfo", "Network is not connected!");
}

this.showToast = showToast;
}

private void runAsyncTask(String updateURL) {
Expand Down Expand Up @@ -311,24 +314,28 @@ protected Void doInBackground(String... params) {
if (getAppVersionCode(context) < updateVersionCode) {
if (updateCheckResult != null) {
updateCheckResult.onUpdateAvailable();
mHandler.post(new Runnable() {
@Override
public void run() {
Toast.makeText(context, "Update Check: An update is available!", Toast.LENGTH_SHORT).show();
}
});
if (showToast) {
mHandler.post(new Runnable() {
@Override
public void run() {
Toast.makeText(context, "Update Check: An update is available!", Toast.LENGTH_LONG).show();
}
});
}
}
downloadURL = jsonObject.getString(KEY_UPDATED_URL);
updateAvailableNotification(downloadURL);
} else {
if (updateCheckResult != null) {
updateCheckResult.noUpdateAvailable();
mHandler.post(new Runnable() {
@Override
public void run() {
Toast.makeText(context, "Update Check: No new updates.", Toast.LENGTH_SHORT).show();
}
});
if (showToast) {
mHandler.post(new Runnable() {
@Override
public void run() {
Toast.makeText(context, "Update Check: No new updates.", Toast.LENGTH_LONG).show();
}
});
}
}
Log.i(DEBUG_TAG, "NO_UPDATE_FOUND_ON_SERVER");
}
Expand Down

0 comments on commit fba32f9

Please sign in to comment.