private void refreshAccount() { mAccountItem.setSummary(R.string.retrieving_status); ThreadingRunnable.background( new ThreadingRunnable() { @Override public void run() { try { final HttpGet get = new HttpGet(ServiceHelper.STATUS_URL); final JSONObject payload = ServiceHelper.retryExecuteAsJSONObject( MainActivity.this, mSettings.getString("account"), get); final long expiration = payload.getLong("subscription_expiration"); foreground( new Runnable() { @Override public void run() { refreshAccount(expiration); } }); } catch (Exception ex) { foreground( new Runnable() { @Override public void run() { mAccountItem.setSummary(R.string.status_error); } }); ex.printStackTrace(); } } }); }
private void refreshAccount(long expiration) { String account = mSettings.getString("account"); if (Helper.isJavaScriptNullOrEmpty(account)) { finish(); return; } long daysLeft = (expiration - System.currentTimeMillis()) / 1000L / 60L / 60L / 24L; daysLeft = Math.max(0, daysLeft); mAccountItem.setSummary(getString(R.string.days_left, String.valueOf(daysLeft))); }