Skip to content

Commit

Permalink
Fix refresh button (spaceapi-community#5)
Browse files Browse the repository at this point in the history
Previously the data was loaded from cache, even if the refresh button
was pressed.
  • Loading branch information
dbrgn authored Feb 20, 2021
1 parent 28c9a8b commit 7f195af
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions app/src/main/java/io/spaceapi/myhackerspace/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public void onCreate(Bundle savedInstanceState) {
Log.d(TAG, "onCreate() intent=" + getIntent().toString());
setCache();
getHsList();
showHsInfo(getIntent());
showHsInfo(getIntent(), true);
} else {
showError(getString(R.string.error_title) + getString(R.string.error_network_title),
getString(R.string.error_network_msg));
Expand All @@ -140,7 +140,7 @@ public void onCreate(Bundle savedInstanceState) {
@UiThread
protected void onNewIntent(Intent intent) {
Log.d(TAG, "onNewIntent()=" + intent);
showHsInfo(intent);
showHsInfo(intent, false);
}

@Override
Expand Down Expand Up @@ -170,7 +170,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
final int id = item.getItemId();
if (id == R.id.menu_refresh) {
if (hasNetwork()) {
showHsInfo(getIntent());
showHsInfo(getIntent(), true);
} else {
showError(getString(R.string.error_title) + getString(R.string.error_network_title),
getString(R.string.error_network_msg));
Expand Down Expand Up @@ -339,7 +339,7 @@ private void getHsList() {
/**
* Fetch the endpoint and update the `mApiUrl` and `mResultHs` variables.
*/
private void showHsInfo(@Nullable Intent intent) {
private void showHsInfo(@Nullable Intent intent, boolean skipCache) {
final Bundle data = (Bundle) getLastNonConfigurationInstance();

// Get space endpoint URL
Expand Down Expand Up @@ -368,7 +368,7 @@ private void showHsInfo(@Nullable Intent intent) {
finishApi = true;
mResultHs = (HashMap<String, String>) data.getSerializable(STATE_HS);
populateDataHs();
} else if(mResultHs.containsKey(mApiUrl)) {
} else if(mResultHs.containsKey(mApiUrl) && !skipCache) {
Log.d(TAG, "showHsInfo(data from cache)");
finishApi = true;
populateDataHs();
Expand Down Expand Up @@ -512,7 +512,7 @@ protected void onPostExecute(String result) {
dismissLoading();
if (mErrorMsg == null) {
mResultHs.put(mUrl, result);
showHsInfo(getIntent());
showHsInfo(getIntent(), false);
} else {
setViewVisibility(false);
showError(mErrorTitle, mErrorMsg);
Expand Down

0 comments on commit 7f195af

Please sign in to comment.