Skip to content

Commit

Permalink
Removed Config class
Browse files Browse the repository at this point in the history
  • Loading branch information
SnoopyCodeX committed Apr 25, 2020
1 parent f3a4106 commit 2240532
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import com.cdph.app.UpdateChecker;
import com.cdph.app.UpdateChecker.NewUpdateInfo;
import com.cdph.app.json.JSONReader;
import com.cdph.app.util.Config;

public class MainActivity extends Activity
{
Expand Down Expand Up @@ -48,13 +47,13 @@ public NewUpdateInfo readJson(String json) throws Exception
{
//Parse as jsonObject then get the values
JSONObject job = new JSONObject(json);
int versionCode = job.getInt(Config.KEY_VERSION_CODE);
String versionName = job.getString(Config.KEY_VERSION_NAME);
String downloadUrl = job.getString(Config.KEY_DOWNLOAD_URL);
int versionCode = job.getInt("versionCode");
String versionName = job.getString("versionName");
String downloadUrl = job.getString("url");
String description = "";

//Parse 'description' as jsonArray then get the values
JSONArray jar = job.getJSONArray(Config.KEY_DESCRIPTION);
JSONArray jar = job.getJSONArray("description");
for(int i = 0; i < jar.length(); i++)
description += jar.getString(i) + "\n";
description = description.substring(0, description.length()-1);
Expand Down
2 changes: 1 addition & 1 deletion cdph_updatechecker_lib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ android {
minSdkVersion 14
targetSdkVersion 21
versionCode 21
versionName "21.1.0 - alpha8"
versionName "21.1.0w8y20a2"
}
buildTypes {
release {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public static final UpdateChecker getInstance(Context ctx)
* new updates when connected to the internet.
* Default is false.
*
*@param autoRun
*@param autoRun - Default is false
*@return UpdateChecker.class
*/
public UpdateChecker shouldAutoRun(boolean autoRun)
Expand All @@ -84,7 +84,7 @@ public UpdateChecker shouldAutoRun(boolean autoRun)
* The url where the new info of the app
* will be read to.
*
*@param updateLogsUrl
*@param updateLogsUrl - The url of the json-encoded info of the new update
*@return UpdateChecker.class
*/
public UpdateChecker setUpdateLogsUrl(String updateLogsUrl)
Expand All @@ -98,7 +98,7 @@ public UpdateChecker setUpdateLogsUrl(String updateLogsUrl)
* install the new app after it has been
* downloaded.
*
*@param autoInstall
*@param autoInstall - Default is false
*@return UpdateChecker.class
*/
public UpdateChecker shouldAutoInstall(boolean autoInstall)
Expand All @@ -111,7 +111,7 @@ public UpdateChecker shouldAutoInstall(boolean autoInstall)
* Sets an OnUpdateDetectedListener, when a new update
* is detected, this listener will be triggered.
*
*@param listener
*@param listener - The listener to be triggered
*@return UpdateChecker.class
*/
public UpdateChecker setOnUpdateDetectedListener(UpdateChecker.OnUpdateDetectedListener listener)
Expand All @@ -123,7 +123,7 @@ public UpdateChecker setOnUpdateDetectedListener(UpdateChecker.OnUpdateDetectedL
/*
* Sets a custom json reader to suit your needs
*
*@param jsonReader
*@param jsonReader - A custom class that extends {com.cdph.app.json.JSONReader}
*@return UpdateChecker.class
*/
public <T extends JSONReader> UpdateChecker setJsonReader(T jsonReader)
Expand Down Expand Up @@ -153,7 +153,7 @@ public void runUpdateChecker()
/*
* Installs the application
*
*@param filePath
*@param filePath - The path of the apk to be installed
*@return null
*/
public void installApp(String path)
Expand Down Expand Up @@ -190,6 +190,7 @@ public File downloadUpdate(String url)
file = down.execute(url).get();
} catch(Exception e) {
e.printStackTrace();
Toast.makeText(ctx, String.format("[ERROR]: %s", e.getMessage()), Toast.LENGTH_LONG).show();
}

return file;
Expand Down Expand Up @@ -229,9 +230,6 @@ protected void onPreExecute()
{
super.onPreExecute();

if(jsonReader == null)
jsonReader = new JSONReader();

dlg = new ProgressDialog(ctx);
dlg.setCancelable(false);
dlg.setCanceledOnTouchOutside(false);
Expand Down Expand Up @@ -294,17 +292,18 @@ protected void onPostExecute(NewUpdateInfo result)
if(ctx.getPackageManager().getPackageInfo(ctx.getPackageName(), 0).versionCode < result.app_version)
listener.onUpdateDetected(result, autoInstall);
else
Toast.makeText(ctx, errMsg, Toast.LENGTH_LONG).show();
Toast.makeText(ctx, String.format("[ERROR]: %s", errMsg), Toast.LENGTH_LONG).show();
} catch(Exception e) {
e.printStackTrace();
Toast.makeText(ctx, e.getMessage(), Toast.LENGTH_LONG).show();
Toast.makeText(ctx, String.format("[ERROR]: %s", e.getMessage()), Toast.LENGTH_LONG).show();
}
}
}

private static final class TaskDownloadUpdate extends AsyncTask<String, Void, File>
{
private ProgressDialog dlg;
private String errMsg;

@Override
protected void onPreExecute()
Expand Down Expand Up @@ -361,6 +360,7 @@ protected File doInBackground(String[] params)
}
} catch(Exception e) {
e.printStackTrace();
errMsg += e.getMessage();
}

return file;
Expand All @@ -373,6 +373,9 @@ protected void onPostExecute(File result)

if(dlg != null)
dlg.dismiss();

if(errMsg != null)
Toast.makeText(ctx, String.format("[ERROR]: %s", errMsg), Toast.LENGTH_LONG).show();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,8 @@
import org.json.JSONObject;

import com.cdph.app.UpdateChecker.NewUpdateInfo;
import com.cdph.app.util.Config;

public class JSONReader
public abstract class JSONReader
{
public NewUpdateInfo readJson(String json) throws Exception
{
//Parse as jsonObject then get the values
JSONObject job = new JSONObject(json);
int versionCode = job.getInt(Config.KEY_VERSION_CODE);
String versionName = job.getString(Config.KEY_VERSION_NAME);
String downloadUrl = job.getString(Config.KEY_DOWNLOAD_URL);
String description = "";

//Parse 'description' as jsonArray then get the values
JSONArray jar = job.getJSONArray(Config.KEY_DESCRIPTION);
for(int i = 0; i < jar.length(); i++)
description += jar.getString(i) + "\n";
description = description.substring(0, description.length()-1);

return (new NewUpdateInfo(downloadUrl, versionName, description, versionCode));
}
public abstract NewUpdateInfo readJson(String json) throws Exception
}

This file was deleted.

0 comments on commit 2240532

Please sign in to comment.