Skip to content
This repository has been archived by the owner on Mar 27, 2020. It is now read-only.

Commit

Permalink
#178 changes to handle the Settings subscreen for advanced trigger se…
Browse files Browse the repository at this point in the history
…ttings
  • Loading branch information
niccs committed Mar 21, 2016
1 parent 69f3527 commit e6e61a0
Show file tree
Hide file tree
Showing 3 changed files with 174 additions and 245 deletions.
221 changes: 23 additions & 198 deletions app/src/main/java/org/iilab/pb/HomeActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,22 +114,21 @@ public void onCreate(Bundle savedInstanceState) {

/* We update the device language content if the english mobile_en.json version has increased or
* if the language of the device OS was previously not installed*/
Log.d(TAG, "currentLocalContentVersion is" +currentLocalContentVersion +"and newLocalContentVersion is "+ newLocalContentVersion);
Log.d(TAG, "currentLocalContentVersion is" + currentLocalContentVersion + "and newLocalContentVersion is " + newLocalContentVersion);
if ((newLocalContentVersion > currentLocalContentVersion) || (!isLanguageDataExists(getApplicationContext(), selectedLang))) {
Log.d(TAG, "Update local data as the english mobile_en.json version has increased");
// to check if the app is installed first time, -1 is the default value
if(currentLocalContentVersion== FRESH_INSTALL_APP_RELEASE_NO){
setFirstRun(getApplicationContext(),true);
if (currentLocalContentVersion == FRESH_INSTALL_APP_RELEASE_NO) {
setFirstRun(getApplicationContext(), true);
setAppUpdated(getApplicationContext(), false);
}else {
setFirstRun(getApplicationContext(),false);
} else {
setFirstRun(getApplicationContext(), false);
setAppUpdated(getApplicationContext(), true);
}
new InitializeLocalData().execute();
addDBLoadedLanguage(getApplicationContext(), selectedLang);

}
else {
} else {
Log.d(TAG, "no update of local data needed");
startNextActivity();
}
Expand Down Expand Up @@ -174,30 +173,33 @@ private void setSupportedLanguages(Page languagesPage) {
private void startNextActivity() {
Log.d(TAG, "starting next activity");
int wizardState = getWizardState(this);
supportedLangs = getSupportedLanguages(this);
Log.d(TAG, "Checking supported languages " + supportedLangs);
if (null == supportedLangs) {
PBDatabase dbInstance = new PBDatabase(this);
dbInstance.open();
Page languagesPage = dbInstance.retrievePage(PAGE_SETUP_LANGUAGE, DEFAULT_LANGUAGE_ENG);
setSupportedLanguages(languagesPage);
dbInstance.close();
}
if ((supportedLangs == null) || !(supportedLangs.contains(selectedLang))) {
setSelectedLanguage(this, DEFAULT_LANGUAGE_ENG);
}

//TODO remove after testing
// wizardState=WIZARD_FLAG_HOME_READY;
// wizardState = WIZARD_FLAG_HOME_READY;
if (wizardState != WIZARD_FLAG_HOME_READY) {
Log.d(TAG, "First run TRUE, running WizardActivity with pageId = " + pageId);

supportedLangs = getSupportedLanguages(this);
Log.d(TAG, "Checking supported languages " + supportedLangs);
if (null == supportedLangs) {
PBDatabase dbInstance = new PBDatabase(this);
dbInstance.open();
Page languagesPage = dbInstance.retrievePage(PAGE_SETUP_LANGUAGE, DEFAULT_LANGUAGE_ENG);
setSupportedLanguages(languagesPage);
dbInstance.close();
}
if ((supportedLangs == null) || !(supportedLangs.contains(selectedLang))) {
setSelectedLanguage(this, DEFAULT_LANGUAGE_ENG);
}

Intent i = new Intent(HomeActivity.this, WizardActivity.class);
i.putExtra(PAGE_ID, pageId);
startActivity(i);
} else {
Log.d(TAG, "First run FALSE, running CalculatorActivity");
Intent i = new Intent(HomeActivity.this, CalculatorActivity.class);
// Make sure the HardwareTriggerService is started
if(isHardwareTriggerServiceEnabled(this)) {
if (isHardwareTriggerServiceEnabled(this)) {
startService(new Intent(this, HardwareTriggerService.class));
}
startActivity(i);
Expand Down Expand Up @@ -256,184 +258,7 @@ protected void onPostExecute(Boolean response) {
Log.e(TAG, "Exception while dismissing progress dialog " + e.getMessage());
e.printStackTrace();
}

// setLocalDataInsertion(HomeActivity.this, true);
// setLastUpdatedDBVersion(HomeActivity.this, DATABASE_VERSION);

startNextActivity();
}
}

// private class GetLatestVersion extends AsyncTask<Void, Void, Boolean> {
//
// @Override
// protected void onPreExecute() {
// super.onPreExecute();
// pDialog = ProgressDialog.show(HomeActivity.this, "Application", "Starting...", true, false);
// }
//
// @Override
// protected Boolean doInBackground(Void... params) {
//
// String url = AppConstants.BASE_URL + AppConstants.VERSION_CHECK_URL;
// JsonParser jsonParser = new JsonParser();
// ServerResponse response = jsonParser.retrieveServerData(AppConstants.HTTP_REQUEST_TYPE_GET, url, null, null, null);
// if (response.getStatus() == 200) {
// try {
// JSONObject responseObj = response.getjObj();
// latestVersion = responseObj.getInt("version");
// Log.e("??????", "latest version = " + latestVersion + " last updated version = " + lastUpdatedVersion);
// return true;
// } catch (JSONException e) {
// e.printStackTrace();
// }
// }
// return false;
// }
//
// @Override
// protected void onPostExecute(Boolean response) {
// super.onPostExecute(response);
//
// if (latestVersion > lastUpdatedVersion) {
// new GetMobileDataUpdate().execute();
// } else {
// setLastRunTimeInMillis(HomeActivity.this, System.currentTimeMillis());
// if (pDialog.isShowing())
// try {
// pDialog.dismiss();
// } catch (Exception e) {
// e.printStackTrace();
// }
// startNextActivity();
// }
// }
// }


// private class GetMobileDataUpdate extends AsyncTask<Void, Void, Boolean> {
//
// @Override
// protected void onPreExecute() {
// super.onPreExecute();
// try {
// pDialog = ProgressDialog.show(HomeActivity.this, "Application", "Downloading updates...", true, false);
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
//
// @Override
// protected Boolean doInBackground(Void... params) {
//
// int version = 0;
// for(version = lastUpdatedVersion + 1; version <= latestVersion; version ++){
// if (selectedLang.equals("en")) {
// mobileDataUrl = AppConstants.BASE_URL + "/api/mobile." + version + ".json";
// } else {
// mobileDataUrl = AppConstants.BASE_URL + "/api/" + selectedLang + "/" + "mobile." + version + ".json";
// }
//
// JsonParser jsonParser = new JsonParser();
// ServerResponse response = jsonParser.retrieveServerData(AppConstants.HTTP_REQUEST_TYPE_GET, mobileDataUrl, null, null, null);
// if (response.getStatus() == 200) {
// Log.d(">>>><<<<", "success in retrieving server-response for url = " + mobileDataUrl);
// try {
// JSONObject responseObj = response.getjObj();
// JSONObject mobObj = responseObj.getJSONObject(JSON_OBJECT_MOBILE);
// JSONArray dataArray = mobObj.getJSONArray(JSON_ARRAY_DATA);
// insertMobileDataToLocalDB(dataArray);
// } catch (JSONException e) {
// e.printStackTrace();
// return false;
// }
// }
// }
//
// if(version > latestVersion){
// return true;
// } else{
// return false;
// }
// }
//
// @Override
// protected void onPostExecute(Boolean response) {
// super.onPostExecute(response);
//
// if(response){
// new GetHelpDataUpdate().execute();
// }
// else{
// if (pDialog.isShowing())
// pDialog.dismiss();
//
// startNextActivity();
// }
// }
// }


// private class GetHelpDataUpdate extends AsyncTask<Void, Void, Boolean> {
//
// @Override
// protected void onPreExecute() {
// super.onPreExecute();
// try {
// pDialog = ProgressDialog.show(HomeActivity.this, "Application", "Downloading help pages...", true, false);
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
//
// @Override
// protected Boolean doInBackground(Void... params) {
//
// JsonParser jsonParser = new JsonParser();
// ServerResponse response = jsonParser.retrieveServerData(AppConstants.HTTP_REQUEST_TYPE_GET, helpDataUrl, null, null, null);
// if (response.getStatus() == 200) {
// Log.d(">>>><<<<", "success in retrieving server-response for url = " + helpDataUrl);
// setLastRunTimeInMillis(HomeActivity.this, System.currentTimeMillis()); // if we can retrieve a single data, we change it up-to-date
// try {
// JSONObject responseObj = response.getjObj();
// JSONObject mobObj = responseObj.getJSONObject(JSON_OBJECT_HELP);
// JSONArray dataArray = mobObj.getJSONArray(JSON_ARRAY_DATA);
// insertHelpDataToLocalDB(dataArray);
// setLastUpdatedVersion(HomeActivity.this, latestVersion);
// return true;
// } catch (JSONException e) {
// e.printStackTrace();
// }
// }
// return false;
// }
//
// @Override
// protected void onPostExecute(Boolean response) {
// super.onPostExecute(response);
// if (pDialog.isShowing())
// try {
// pDialog.dismiss();
// } catch (Exception e) {
// e.printStackTrace();
// }
//
// startNextActivity();
// }
// }


// private void insertHelpDataToLocalDB(JSONArray dataArray) {
// List<HelpPage> pageList = HelpPage.parseHelpPages(dataArray);
//
// PBDatabase dbInstance = new PBDatabase(HomeActivity.this);
// dbInstance.open();
//
// for (int i = 0; i < pageList.size(); i++) {
// dbInstance.insertOrUpdateHelpPage(pageList.get(i));
// }
// dbInstance.close();
// }


}
Loading

0 comments on commit e6e61a0

Please sign in to comment.