Check internet connection before button function, since function requires internet connection

This commit is contained in:
neslihanturan 2018-12-13 20:22:20 +03:00
parent f3818c6e23
commit 2569bb45f7
2 changed files with 24 additions and 13 deletions

View file

@ -10,6 +10,8 @@ import android.view.ViewGroup;
import fr.free.nrw.commons.R;
import fr.free.nrw.commons.upload.UploadService;
import fr.free.nrw.commons.utils.NetworkUtils;
import fr.free.nrw.commons.utils.ViewUtil;
import timber.log.Timber;
import static fr.free.nrw.commons.contributions.Contribution.STATE_FAILED;
@ -110,14 +112,18 @@ class ContributionsListAdapter extends CursorAdapter {
* @param cursor cursor will be retried
*/
public void retryUpload(Cursor cursor) {
// TODO: first check for internet connection, if not display a message and do nothing.
Contribution c = contributionDao.fromCursor(cursor);
if (c.getState() == STATE_FAILED) {
uploadService.queue(UploadService.ACTION_UPLOAD_FILE, c);
Timber.d("Restarting for %s", c.toString());
if (NetworkUtils.isInternetConnectionEstablished(mContext)) {
Contribution c = contributionDao.fromCursor(cursor);
if (c.getState() == STATE_FAILED) {
uploadService.queue(UploadService.ACTION_UPLOAD_FILE, c);
Timber.d("Restarting for %s", c.toString());
} else {
Timber.d("Skipping re-upload for non-failed %s", c.toString());
}
} else {
Timber.d("Skipping re-upload for non-failed %s", c.toString());
ViewUtil.showLongToast(mContext,R.string.this_function_needs_network_connection);
}
}
/**
@ -125,14 +131,17 @@ class ContributionsListAdapter extends CursorAdapter {
* @param cursor cursor which will be deleted
*/
public void deleteUpload(Cursor cursor) {
// TODO: check internet connection, warn user and do nothing is a problem occurred
Contribution c = contributionDao.fromCursor(cursor);
if (c.getState() == STATE_FAILED) {
Timber.d("Deleting failed contrib %s", c.toString());
contributionDao.delete(c);
if (NetworkUtils.isInternetConnectionEstablished(mContext)) {
Contribution c = contributionDao.fromCursor(cursor);
if (c.getState() == STATE_FAILED) {
Timber.d("Deleting failed contrib %s", c.toString());
contributionDao.delete(c);
} else {
Timber.d("Skipping deletion for non-failed contrib %s", c.toString());
}
} else {
Timber.d("Skipping deletion for non-failed contrib %s", c.toString());
ViewUtil.showLongToast(mContext,R.string.this_function_needs_network_connection);
}
}
}

View file

@ -433,4 +433,6 @@ Upload your first media by touching the camera or gallery icon above.</string>
<string name="display_location_permission_title">Display location permission</string>
<string name="display_location_permission_explanation">Ask for location permission when needed for nearby notification card view feature.</string>
<string name="this_function_needs_network_connection">This function requires network connection, please check your connection settings.</string>
</resources>