Skip to content

Commit 2569bb4

Browse files
committed
Check internet connection before button function, since function requires internet connection
1 parent f3818c6 commit 2569bb4

File tree

2 files changed

+24
-13
lines changed

2 files changed

+24
-13
lines changed

app/src/main/java/fr/free/nrw/commons/contributions/ContributionsListAdapter.java

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
import fr.free.nrw.commons.R;
1212
import fr.free.nrw.commons.upload.UploadService;
13+
import fr.free.nrw.commons.utils.NetworkUtils;
14+
import fr.free.nrw.commons.utils.ViewUtil;
1315
import timber.log.Timber;
1416

1517
import static fr.free.nrw.commons.contributions.Contribution.STATE_FAILED;
@@ -110,29 +112,36 @@ public void onClick(View view) {
110112
* @param cursor cursor will be retried
111113
*/
112114
public void retryUpload(Cursor cursor) {
113-
// TODO: first check for internet connection, if not display a message and do nothing.
114-
Contribution c = contributionDao.fromCursor(cursor);
115-
if (c.getState() == STATE_FAILED) {
116-
uploadService.queue(UploadService.ACTION_UPLOAD_FILE, c);
117-
Timber.d("Restarting for %s", c.toString());
115+
if (NetworkUtils.isInternetConnectionEstablished(mContext)) {
116+
Contribution c = contributionDao.fromCursor(cursor);
117+
if (c.getState() == STATE_FAILED) {
118+
uploadService.queue(UploadService.ACTION_UPLOAD_FILE, c);
119+
Timber.d("Restarting for %s", c.toString());
120+
} else {
121+
Timber.d("Skipping re-upload for non-failed %s", c.toString());
122+
}
118123
} else {
119-
Timber.d("Skipping re-upload for non-failed %s", c.toString());
124+
ViewUtil.showLongToast(mContext,R.string.this_function_needs_network_connection);
120125
}
126+
121127
}
122128

123129
/**
124130
* Delete a failed upload attempt
125131
* @param cursor cursor which will be deleted
126132
*/
127133
public void deleteUpload(Cursor cursor) {
128-
// TODO: check internet connection, warn user and do nothing is a problem occurred
129-
130-
Contribution c = contributionDao.fromCursor(cursor);
131-
if (c.getState() == STATE_FAILED) {
132-
Timber.d("Deleting failed contrib %s", c.toString());
133-
contributionDao.delete(c);
134+
if (NetworkUtils.isInternetConnectionEstablished(mContext)) {
135+
Contribution c = contributionDao.fromCursor(cursor);
136+
if (c.getState() == STATE_FAILED) {
137+
Timber.d("Deleting failed contrib %s", c.toString());
138+
contributionDao.delete(c);
139+
} else {
140+
Timber.d("Skipping deletion for non-failed contrib %s", c.toString());
141+
}
134142
} else {
135-
Timber.d("Skipping deletion for non-failed contrib %s", c.toString());
143+
ViewUtil.showLongToast(mContext,R.string.this_function_needs_network_connection);
136144
}
145+
137146
}
138147
}

app/src/main/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,4 +433,6 @@ Upload your first media by touching the camera or gallery icon above.</string>
433433
<string name="display_location_permission_title">Display location permission</string>
434434
<string name="display_location_permission_explanation">Ask for location permission when needed for nearby notification card view feature.</string>
435435

436+
<string name="this_function_needs_network_connection">This function requires network connection, please check your connection settings.</string>
437+
436438
</resources>

0 commit comments

Comments
 (0)