-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Download & Custom JSONReader support
- Loading branch information
1 parent
d0e37db
commit 1791be1
Showing
5 changed files
with
192 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
cdph_updatechecker_lib/src/main/java/com/cdph/app/json/JSONReader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.cdph.app.json; | ||
|
||
import org.json.JSONArray; | ||
import org.json.JSONObject; | ||
|
||
import com.cdph.app.UpdateChecker.NewUpdateInfo; | ||
import com.cdph.app.util.Config; | ||
|
||
public 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)); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
cdph_updatechecker_lib/src/main/java/com/cdph/app/util/Config.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.cdph.app.util; | ||
|
||
public final class Config | ||
{ | ||
public static final String KEY_VERSION_CODE = "versionCode"; | ||
public static final String KEY_VERSION_NAME = "versionName"; | ||
public static final String KEY_DOWNLOAD_URL = "url"; | ||
public static final String KEY_DESCRIPTION = "description"; | ||
} |