private void searchFromCache(String keyword) { TextView errorText = (TextView) mErrorView.findViewById(R.id.error_view_error_text); errorText.setText(getString(R.string.PleaseCheckNetworkAndTryAgain)); mRetryBtn.setVisibility(View.VISIBLE); if (mErrorView.getVisibility() == View.VISIBLE) { mErrorView.setVisibility(View.GONE); } if (keyword.length() > 0) { mPartyListRecyclerView.setVisibility(View.VISIBLE); mErrorView.setVisibility(View.GONE); mParties = mPartyAPIHelper.searchPartiesFromCache(keyword); if (mParties != null && mParties.size() > 0) { mPartyAdapter.setParties(mParties); mPartyAdapter.setOnItemClickListener(PartyListActivity.this); } else { mPartyListRecyclerView.setVisibility(View.GONE); mErrorView.setVisibility(View.VISIBLE); mRetryBtn.setVisibility(View.GONE); errorText.setText(R.string.search_not_found); } } else { downloadPartyList(); } }
private void downloadPartyList() { mPartyAPIHelper.getPartiesAsync( new Callback<PartyListReturnObject>() { @Override public void success(PartyListReturnObject returnObject, Response response) { // Hide Progress on success viewUtils.showProgress(mPartyListRecyclerView, mProgressView, false); switch (response.getStatus()) { case 200: mParties = returnObject.getData(); mPartyAdapter.setParties(mParties); mPartyAdapter.setOnItemClickListener(PartyListActivity.this); for (Party data : mParties) { try { mPartyDao.createParty(data); } catch (SQLException e) { e.printStackTrace(); } } break; } } @Override public void failure(RetrofitError error) { switch (error.getKind()) { case HTTP: org.maepaysoh.maepaysohsdk.models.Error mError = (org.maepaysoh.maepaysohsdk.models.Error) error.getBodyAs(Error.class); Toast.makeText( PartyListActivity.this, mError.getError().getMessage(), Toast.LENGTH_SHORT) .show(); break; case NETWORK: Toast.makeText( PartyListActivity.this, getString(R.string.PleaseCheckNetwork), Toast.LENGTH_SHORT) .show(); break; case CONVERSION: Toast.makeText( PartyListActivity.this, getString(R.string.SomethingWentWrong), Toast.LENGTH_SHORT) .show(); } // Hide Progress on failure too // viewUtils.showProgress(mPartyListRecyclerView, mProgressView, false); // mErrorView.setVisibility(View.VISIBLE); loadFromCache(); } }); }
private void loadFromCache() { // mParties = mPartyDao.getAllPartyData(); mParties = mPartyAPIHelper.getPartiesFromCache(); if (mParties != null && mParties.size() > 0) { viewUtils.showProgress(mPartyListRecyclerView, mProgressView, false); mPartyAdapter.setParties(mParties); mPartyAdapter.setOnItemClickListener(PartyListActivity.this); } else { viewUtils.showProgress(mPartyListRecyclerView, mProgressView, false); mErrorView.setVisibility(View.VISIBLE); } }