Skip to content

Commit 2240532

Browse files
committed
Removed Config class
1 parent f3a4106 commit 2240532

File tree

5 files changed

+21
-45
lines changed

5 files changed

+21
-45
lines changed

cdph_updatechecker_app/src/main/java/com/cdph/updatechecker/MainActivity.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import com.cdph.app.UpdateChecker;
88
import com.cdph.app.UpdateChecker.NewUpdateInfo;
99
import com.cdph.app.json.JSONReader;
10-
import com.cdph.app.util.Config;
1110

1211
public class MainActivity extends Activity
1312
{
@@ -48,13 +47,13 @@ public NewUpdateInfo readJson(String json) throws Exception
4847
{
4948
//Parse as jsonObject then get the values
5049
JSONObject job = new JSONObject(json);
51-
int versionCode = job.getInt(Config.KEY_VERSION_CODE);
52-
String versionName = job.getString(Config.KEY_VERSION_NAME);
53-
String downloadUrl = job.getString(Config.KEY_DOWNLOAD_URL);
50+
int versionCode = job.getInt("versionCode");
51+
String versionName = job.getString("versionName");
52+
String downloadUrl = job.getString("url");
5453
String description = "";
5554

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

cdph_updatechecker_lib/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ android {
99
minSdkVersion 14
1010
targetSdkVersion 21
1111
versionCode 21
12-
versionName "21.1.0 - alpha8"
12+
versionName "21.1.0w8y20a2"
1313
}
1414
buildTypes {
1515
release {

cdph_updatechecker_lib/src/main/java/com/cdph/app/UpdateChecker.java

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public static final UpdateChecker getInstance(Context ctx)
6767
* new updates when connected to the internet.
6868
* Default is false.
6969
*
70-
*@param autoRun
70+
*@param autoRun - Default is false
7171
*@return UpdateChecker.class
7272
*/
7373
public UpdateChecker shouldAutoRun(boolean autoRun)
@@ -84,7 +84,7 @@ public UpdateChecker shouldAutoRun(boolean autoRun)
8484
* The url where the new info of the app
8585
* will be read to.
8686
*
87-
*@param updateLogsUrl
87+
*@param updateLogsUrl - The url of the json-encoded info of the new update
8888
*@return UpdateChecker.class
8989
*/
9090
public UpdateChecker setUpdateLogsUrl(String updateLogsUrl)
@@ -98,7 +98,7 @@ public UpdateChecker setUpdateLogsUrl(String updateLogsUrl)
9898
* install the new app after it has been
9999
* downloaded.
100100
*
101-
*@param autoInstall
101+
*@param autoInstall - Default is false
102102
*@return UpdateChecker.class
103103
*/
104104
public UpdateChecker shouldAutoInstall(boolean autoInstall)
@@ -111,7 +111,7 @@ public UpdateChecker shouldAutoInstall(boolean autoInstall)
111111
* Sets an OnUpdateDetectedListener, when a new update
112112
* is detected, this listener will be triggered.
113113
*
114-
*@param listener
114+
*@param listener - The listener to be triggered
115115
*@return UpdateChecker.class
116116
*/
117117
public UpdateChecker setOnUpdateDetectedListener(UpdateChecker.OnUpdateDetectedListener listener)
@@ -123,7 +123,7 @@ public UpdateChecker setOnUpdateDetectedListener(UpdateChecker.OnUpdateDetectedL
123123
/*
124124
* Sets a custom json reader to suit your needs
125125
*
126-
*@param jsonReader
126+
*@param jsonReader - A custom class that extends {com.cdph.app.json.JSONReader}
127127
*@return UpdateChecker.class
128128
*/
129129
public <T extends JSONReader> UpdateChecker setJsonReader(T jsonReader)
@@ -153,7 +153,7 @@ public void runUpdateChecker()
153153
/*
154154
* Installs the application
155155
*
156-
*@param filePath
156+
*@param filePath - The path of the apk to be installed
157157
*@return null
158158
*/
159159
public void installApp(String path)
@@ -190,6 +190,7 @@ public File downloadUpdate(String url)
190190
file = down.execute(url).get();
191191
} catch(Exception e) {
192192
e.printStackTrace();
193+
Toast.makeText(ctx, String.format("[ERROR]: %s", e.getMessage()), Toast.LENGTH_LONG).show();
193194
}
194195

195196
return file;
@@ -229,9 +230,6 @@ protected void onPreExecute()
229230
{
230231
super.onPreExecute();
231232

232-
if(jsonReader == null)
233-
jsonReader = new JSONReader();
234-
235233
dlg = new ProgressDialog(ctx);
236234
dlg.setCancelable(false);
237235
dlg.setCanceledOnTouchOutside(false);
@@ -294,17 +292,18 @@ protected void onPostExecute(NewUpdateInfo result)
294292
if(ctx.getPackageManager().getPackageInfo(ctx.getPackageName(), 0).versionCode < result.app_version)
295293
listener.onUpdateDetected(result, autoInstall);
296294
else
297-
Toast.makeText(ctx, errMsg, Toast.LENGTH_LONG).show();
295+
Toast.makeText(ctx, String.format("[ERROR]: %s", errMsg), Toast.LENGTH_LONG).show();
298296
} catch(Exception e) {
299297
e.printStackTrace();
300-
Toast.makeText(ctx, e.getMessage(), Toast.LENGTH_LONG).show();
298+
Toast.makeText(ctx, String.format("[ERROR]: %s", e.getMessage()), Toast.LENGTH_LONG).show();
301299
}
302300
}
303301
}
304302

305303
private static final class TaskDownloadUpdate extends AsyncTask<String, Void, File>
306304
{
307305
private ProgressDialog dlg;
306+
private String errMsg;
308307

309308
@Override
310309
protected void onPreExecute()
@@ -361,6 +360,7 @@ protected File doInBackground(String[] params)
361360
}
362361
} catch(Exception e) {
363362
e.printStackTrace();
363+
errMsg += e.getMessage();
364364
}
365365

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

374374
if(dlg != null)
375375
dlg.dismiss();
376+
377+
if(errMsg != null)
378+
Toast.makeText(ctx, String.format("[ERROR]: %s", errMsg), Toast.LENGTH_LONG).show();
376379
}
377380
}
378381

cdph_updatechecker_lib/src/main/java/com/cdph/app/json/JSONReader.java

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,8 @@
44
import org.json.JSONObject;
55

66
import com.cdph.app.UpdateChecker.NewUpdateInfo;
7-
import com.cdph.app.util.Config;
87

9-
public class JSONReader
8+
public abstract class JSONReader
109
{
11-
public NewUpdateInfo readJson(String json) throws Exception
12-
{
13-
//Parse as jsonObject then get the values
14-
JSONObject job = new JSONObject(json);
15-
int versionCode = job.getInt(Config.KEY_VERSION_CODE);
16-
String versionName = job.getString(Config.KEY_VERSION_NAME);
17-
String downloadUrl = job.getString(Config.KEY_DOWNLOAD_URL);
18-
String description = "";
19-
20-
//Parse 'description' as jsonArray then get the values
21-
JSONArray jar = job.getJSONArray(Config.KEY_DESCRIPTION);
22-
for(int i = 0; i < jar.length(); i++)
23-
description += jar.getString(i) + "\n";
24-
description = description.substring(0, description.length()-1);
25-
26-
return (new NewUpdateInfo(downloadUrl, versionName, description, versionCode));
27-
}
10+
public abstract NewUpdateInfo readJson(String json) throws Exception
2811
}

cdph_updatechecker_lib/src/main/java/com/cdph/app/util/Config.java

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)