Disable "Download" button without internet connection

This commit is contained in:
Alex Sytnyk 2018-04-30 14:57:02 +03:00
parent 70c510e7cd
commit c9acd57e1f
2 changed files with 9 additions and 4 deletions

View file

@ -12,7 +12,6 @@ import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
@ -161,12 +160,10 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadIn
downloadUpdateCard.setListener(new TravelDownloadUpdateCard.ClickListener() {
@Override
public void onPrimaryButtonClick() {
if (app.getSettings().isInternetConnectionAvailable()) {
if (indexItem != null) {
new DownloadValidationManager(app).startDownload(getMyActivity(), indexItem);
downloadUpdateCard.setLoadingInProgress(true);
adapter.updateDownloadUpdateCard();
} else {
Toast.makeText(app, app.getString(R.string.no_index_file_to_download), Toast.LENGTH_SHORT).show();
}
}

View file

@ -107,6 +107,10 @@ public class TravelDownloadUpdateCard extends BaseTravelCard {
return app.getString(download ? R.string.download_file : R.string.update_is_available);
}
private boolean isInternetAvailable() {
return app.getSettings().isInternetConnectionAvailable();
}
private Drawable getIcon() {
int id = download ? R.drawable.travel_card_download_icon : R.drawable.travel_card_update_icon;
return ContextCompat.getDrawable(app, id);
@ -114,6 +118,9 @@ public class TravelDownloadUpdateCard extends BaseTravelCard {
@NonNull
private String getDescription() {
if (!isInternetAvailable()) {
return app.getString(R.string.no_index_file_to_download);
}
return app.getString(download ? R.string.travel_card_download_descr : R.string.travel_card_update_descr);
}
@ -175,6 +182,7 @@ public class TravelDownloadUpdateCard extends BaseTravelCard {
private boolean updatePrimaryButton(DownloadUpdateVH vh) {
if (!loadingInProgress) {
vh.primaryBtnContainer.setVisibility(View.VISIBLE);
vh.primaryButton.setEnabled(isInternetAvailable());
vh.primaryButton.setText(download ? R.string.shared_string_download : R.string.shared_string_update);
vh.primaryButton.setOnClickListener(new View.OnClickListener() {
@Override