|
10 | 10 |
|
11 | 11 | import fr.free.nrw.commons.R;
|
12 | 12 | import fr.free.nrw.commons.upload.UploadService;
|
| 13 | +import fr.free.nrw.commons.utils.NetworkUtils; |
| 14 | +import fr.free.nrw.commons.utils.ViewUtil; |
13 | 15 | import timber.log.Timber;
|
14 | 16 |
|
15 | 17 | import static fr.free.nrw.commons.contributions.Contribution.STATE_FAILED;
|
@@ -110,29 +112,36 @@ public void onClick(View view) {
|
110 | 112 | * @param cursor cursor will be retried
|
111 | 113 | */
|
112 | 114 | 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 | + } |
118 | 123 | } else {
|
119 |
| - Timber.d("Skipping re-upload for non-failed %s", c.toString()); |
| 124 | + ViewUtil.showLongToast(mContext,R.string.this_function_needs_network_connection); |
120 | 125 | }
|
| 126 | + |
121 | 127 | }
|
122 | 128 |
|
123 | 129 | /**
|
124 | 130 | * Delete a failed upload attempt
|
125 | 131 | * @param cursor cursor which will be deleted
|
126 | 132 | */
|
127 | 133 | 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 | + } |
134 | 142 | } else {
|
135 |
| - Timber.d("Skipping deletion for non-failed contrib %s", c.toString()); |
| 143 | + ViewUtil.showLongToast(mContext,R.string.this_function_needs_network_connection); |
136 | 144 | }
|
| 145 | + |
137 | 146 | }
|
138 | 147 | }
|
0 commit comments