public void getDBSize() { AsyncHttpClient client = new AsyncHttpClient(); RequestParams params = new RequestParams(); params.put(Settings.DB_HOST, sharedPrefs.getValueStr(SharedPrefs.KEY_DB_HOST)); params.put(Settings.DB_NAME, sharedPrefs.getValueStr(SharedPrefs.KEY_DB_NAME)); params.put(Settings.DB_USER, sharedPrefs.getValueStr(SharedPrefs.KEY_DB_USERNAME)); params.put(Settings.DB_PASSWORD, sharedPrefs.getValueStr(SharedPrefs.KEY_DB_PASSWORD)); System.out.println("params: " + params.toString()); String url = sharedPrefs.getValueStr(SharedPrefs.KEY_DOMAIN_NAME) + "/php/checkDBSize.php"; Log.i("getDBSize", "URL: " + url); client.post( url, params, new AsyncHttpResponseHandler() { @Override public void onSuccess(String response) { System.out.println("sucess sa dbcheck"); try { JSONObject json_data = new JSONObject(response); double size = (json_data.getDouble("size")); dataHandler.setDbSize(size); Log.i("checkDBSize", "DB Size: " + dataHandler.getDbSize()); dialog.dismiss(); updateDialog.dismiss(); Intent intent = new Intent(getApplicationContext(), UpdateManager.class); startActivity(intent); } catch (Exception e) { updateDialog.dismiss(); Log.e("Fail 3", e.toString()); } } @Override public void onFailure(int statusCode, Throwable error, String content) { dialog.dismiss(); System.out.println("failed sa dbcheck"); if (statusCode == 404) { Log.e("getDBSize", "ERROR 404"); } else if (statusCode == 500) { Log.e("getDBSize", "ERROR 500"); } else { Log.e( "getDBSize", "ERROR OCCURED! content: " + content + "\nstatus: " + statusCode + "\nerror: " + error.toString()); } } }); }
@Override protected void onCreate(Bundle savedInstanceState) { this.getWindow() .setFlags( WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); sharedPrefs = new SharedPrefs(this); SharedPrefs.initializeInstance(this); Thread.setDefaultUncaughtExceptionHandler(new ExceptionHandler(this)); databaseHandler = new DatabaseHandler(getBaseContext()); credentials = new Credential(getApplicationContext(), this); editTextUsername = (EditText) findViewById(R.id.editTextUsername); editTextPassword = (EditText) findViewById(R.id.editTextPassword); submitButton = (RobotoButtonBold) findViewById(R.id.submit_button); toggleBtn = (ImageView) findViewById(R.id.rememberSwitch); editTextUsername.setGravity(Gravity.CENTER); editTextPassword.setGravity(Gravity.CENTER); editTextPassword.setOnEditorActionListener( new EditText.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_DONE) { logIn(); return true; } return false; } }); editTextUsername.setOnEditorActionListener( new EditText.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_DONE) { logIn(); return true; } return false; } }); // set ddatabaseHandler size // getDBSize(); if (!credentials.getUsername().isEmpty()) { Log.i( "MainActivity", "U: " + credentials.getUsername() + "/ P: " + credentials.getPassword()); editTextUsername.setText(credentials.getUsername()); editTextPassword.setText(credentials.getPassword()); } // if the app is configured if (sharedPrefs.getValueBol(SharedPrefs.KEY_CONFIGURED)) { } else { // getDBSize(); Intent intent = new Intent(this, WelcomeActivity.class); startActivity(intent); } }
public void checkNeedUpdate() { final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); Date datelocal = new Date(sharedPrefs.getValueLong(SharedPrefs.KEY_DATE_MODIFIED)); Log.i("checkNeedUpdate", sdf.format(datelocal)); final Date dateModifiedLocal = datelocal; AsyncHttpClient client = new AsyncHttpClient(); RequestParams params = new RequestParams(); params.put(Settings.DB_HOST, sharedPrefs.getValueStr(SharedPrefs.KEY_DB_HOST)); params.put(Settings.DB_NAME, sharedPrefs.getValueStr(SharedPrefs.KEY_DB_NAME)); params.put(Settings.DB_USER, sharedPrefs.getValueStr(SharedPrefs.KEY_DB_USERNAME)); params.put(Settings.DB_PASSWORD, sharedPrefs.getValueStr(SharedPrefs.KEY_DB_PASSWORD)); System.out.println("need Update params: " + params.toString()); String url = sharedPrefs.getValueStr(SharedPrefs.KEY_DOMAIN_NAME) + "/php/getDateModified.php"; Log.i("getDBSize", "URL: " + url); client.post( url, params, new AsyncHttpResponseHandler() { @Override public void onSuccess(String response) { System.out.println("success sa dbcheck"); try { JSONObject json_data = new JSONObject(response); long date_modified = (json_data.getLong("date_modified")); date_modified = date_modified * 1000; Date dateremote = new Date(date_modified); Log.i("needUpdate", "date_modified (long)(remote): " + date_modified); Log.i( "needUpdate", "date_modified (long)(local): " + sharedPrefs.getValueLong(SharedPrefs.KEY_DATE_MODIFIED)); Log.i("needUpdate", "date_modified (remote): " + sdf.format(dateremote)); Log.i("needUpdate", "date_modified (local): " + sdf.format(dateModifiedLocal)); if (dateremote.after(dateModifiedLocal)) { Log.i("needUpdate", "WEE NEED BLOODY UPDATES"); getDBSize(); } else { Log.i("needUpdate", "WEE DONT NEED BLOODY UPDATES"); updateDialog.dismiss(); Intent intent = new Intent(getBaseContext(), SearchActivity.class); startActivity(intent); } } catch (Exception e) { updateDialog.dismiss(); Log.e("Fail 3", e.toString()); } } @Override public void onFailure(int statusCode, Throwable error, String content) { System.out.println("failed sa dbcheck"); if (statusCode == 404) { Log.e("getDBSize", "ERROR 404"); } else if (statusCode == 500) { Log.e("getDBSize", "ERROR 500"); } else { Log.e( "getDBSize", "ERROR OCCURED! content: " + content + "\nstatus: " + statusCode + "\nerror: " + error.toString()); } } }); }