Skip to content

Commit 2f08222

Browse files
author
maskara
committed
Fix default state for upload activity
1 parent 378c90d commit 2f08222

File tree

2 files changed

+59
-51
lines changed

2 files changed

+59
-51
lines changed

app/src/main/java/fr/free/nrw/commons/upload/UploadModel.java

+33-26
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
public class UploadModel {
3838

39-
MediaWikiApi mwApi;
39+
private MediaWikiApi mwApi;
4040
private static UploadItem DUMMY = new UploadItem(Uri.EMPTY, "", "", GPSExtractor.DUMMY, "", null,-1l) {
4141
@Override
4242
public boolean isDummy() {
@@ -78,8 +78,8 @@ public boolean isDummy() {
7878
}
7979

8080
@SuppressLint("CheckResult")
81-
public void receive(List<Uri> mediaUri, String mimeType, String source, SimilarImageInterface similarImageInterface) {
82-
currentStepIndex = 0;
81+
void receive(List<Uri> mediaUri, String mimeType, String source, SimilarImageInterface similarImageInterface) {
82+
initDefaultValues();
8383
Observable<UploadItem> itemObservable = Observable.fromIterable(mediaUri)
8484
.map(media -> {
8585
currentMediaUri=media;
@@ -112,9 +112,8 @@ public void receive(List<Uri> mediaUri, String mimeType, String source, SimilarI
112112
}
113113

114114
@SuppressLint("CheckResult")
115-
public void receiveDirect(Uri media, String mimeType, String source, String wikidataEntityIdPref, String title, String desc, SimilarImageInterface similarImageInterface) {
116-
currentStepIndex = 0;
117-
items = new ArrayList<>();
115+
void receiveDirect(Uri media, String mimeType, String source, String wikidataEntityIdPref, String title, String desc, SimilarImageInterface similarImageInterface) {
116+
initDefaultValues();
118117
long fileCreatedDate = getFileCreatedDate(media);
119118
String filePath = this.cacheFileUpload(media);
120119
Uri uri = Uri.fromFile(new File(filePath));
@@ -141,6 +140,14 @@ public void receiveDirect(Uri media, String mimeType, String source, String wiki
141140
items.get(0).first = true;
142141
}
143142

143+
private void initDefaultValues() {
144+
currentStepIndex = 0;
145+
topCardState = true;
146+
bottomCardState = true;
147+
rightCardState = true;
148+
items = new ArrayList<>();
149+
}
150+
144151
/**
145152
* Get file creation date from uri from all possible content providers
146153
* @param media
@@ -168,15 +175,15 @@ private long getFileCreatedDate(Uri media) {
168175
}
169176
}
170177

171-
public boolean isPreviousAvailable() {
178+
boolean isPreviousAvailable() {
172179
return currentStepIndex > 0;
173180
}
174181

175-
public boolean isNextAvailable() {
182+
boolean isNextAvailable() {
176183
return currentStepIndex < (items.size() + 1);
177184
}
178185

179-
public boolean isSubmitAvailable() {
186+
boolean isSubmitAvailable() {
180187
int count = items.size();
181188
boolean hasError = license == null;
182189
for (int i = 0; i < count; i++) {
@@ -186,11 +193,11 @@ public boolean isSubmitAvailable() {
186193
return !hasError;
187194
}
188195

189-
public int getCurrentStep() {
196+
int getCurrentStep() {
190197
return currentStepIndex + 1;
191198
}
192199

193-
public int getStepCount() {
200+
int getStepCount() {
194201
return items.size() + 2;
195202
}
196203

@@ -202,27 +209,27 @@ public List<UploadItem> getUploads() {
202209
return items;
203210
}
204211

205-
public boolean isTopCardState() {
212+
boolean isTopCardState() {
206213
return topCardState;
207214
}
208215

209-
public void setTopCardState(boolean topCardState) {
216+
void setTopCardState(boolean topCardState) {
210217
this.topCardState = topCardState;
211218
}
212219

213-
public boolean isBottomCardState() {
220+
boolean isBottomCardState() {
214221
return bottomCardState;
215222
}
216223

217-
public void setRightCardState(boolean rightCardState) {
224+
void setRightCardState(boolean rightCardState) {
218225
this.rightCardState = rightCardState;
219226
}
220227

221-
public boolean isRightCardState() {
228+
boolean isRightCardState() {
222229
return rightCardState;
223230
}
224231

225-
public void setBottomCardState(boolean bottomCardState) {
232+
void setBottomCardState(boolean bottomCardState) {
226233
this.bottomCardState = bottomCardState;
227234
}
228235

@@ -246,17 +253,17 @@ public void previous() {
246253
updateItemState();
247254
}
248255

249-
public void jumpTo(UploadItem item) {
256+
void jumpTo(UploadItem item) {
250257
currentStepIndex = items.indexOf(item);
251258
item.visited = true;
252259
updateItemState();
253260
}
254261

255-
public UploadItem getCurrentItem() {
262+
UploadItem getCurrentItem() {
256263
return isShowingItem() ? items.get(currentStepIndex) : DUMMY;
257264
}
258265

259-
public boolean isShowingItem() {
266+
boolean isShowingItem() {
260267
return currentStepIndex < items.size();
261268
}
262269

@@ -279,15 +286,15 @@ public List<String> getLicenses() {
279286
return licenses;
280287
}
281288

282-
public String getSelectedLicense() {
289+
String getSelectedLicense() {
283290
return license;
284291
}
285292

286-
public void setSelectedLicense(String licenseName) {
293+
void setSelectedLicense(String licenseName) {
287294
this.license = licensesByName.get(licenseName);
288295
}
289296

290-
public Observable<Contribution> buildContributions(List<String> categoryStringList) {
297+
Observable<Contribution> buildContributions(List<String> categoryStringList) {
291298
return Observable.fromIterable(items).map(item ->
292299
{
293300
Contribution contribution = new Contribution(item.mediaUri, null, item.title + "." + item.fileExt,
@@ -328,17 +335,17 @@ private String cacheFileUpload(Uri media) {
328335
}
329336
}
330337

331-
public void keepPicture() {
338+
void keepPicture() {
332339
items.get(currentStepIndex).imageQuality.onNext(ImageUtils.IMAGE_KEEP);
333340
}
334341

335-
public void deletePicture() {
342+
void deletePicture() {
336343
badImageSubscription.dispose();
337344
items.remove(currentStepIndex).imageQuality.onComplete();
338345
updateItemState();
339346
}
340347

341-
public void subscribeBadPicture(Consumer<Integer> consumer) {
348+
void subscribeBadPicture(Consumer<Integer> consumer) {
342349
badImageSubscription = getCurrentItem().imageQuality.subscribe(consumer, Timber::e);
343350
}
344351

app/src/main/java/fr/free/nrw/commons/upload/UploadPresenter.java

+26-25
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,20 @@ public class UploadPresenter {
4646
new Class[]{SimilarImageInterface.class}, (proxy, method, methodArgs) -> null);
4747
private SimilarImageInterface similarImageInterface = SIMILAR_IMAGE;
4848

49-
@UploadView.UploadPage int currentPage = UploadView.PLEASE_WAIT;
49+
@UploadView.UploadPage
50+
private int currentPage = UploadView.PLEASE_WAIT;
5051

5152

5253
@Inject
53-
public UploadPresenter(UploadModel uploadModel,
54-
UploadController uploadController,
55-
MediaWikiApi mediaWikiApi) {
54+
UploadPresenter(UploadModel uploadModel,
55+
UploadController uploadController,
56+
MediaWikiApi mediaWikiApi) {
5657
this.uploadModel = uploadModel;
5758
this.uploadController = uploadController;
5859
this.mediaWikiApi = mediaWikiApi;
5960
}
6061

61-
public void receive(Uri mediaUri, String mimeType, String source) {
62+
void receive(Uri mediaUri, String mimeType, String source) {
6263
receive(Collections.singletonList(mediaUri), mimeType, source);
6364
}
6465

@@ -70,7 +71,7 @@ public void receive(Uri mediaUri, String mimeType, String source) {
7071
* @param source File source from {@link Contribution.FileSource}
7172
*/
7273
@SuppressLint("CheckResult")
73-
public void receive(List<Uri> media, String mimeType, @Contribution.FileSource String source) {
74+
void receive(List<Uri> media, String mimeType, @Contribution.FileSource String source) {
7475
Completable.fromRunnable(() -> uploadModel.receive(media, mimeType, source, similarImageInterface))
7576
.subscribeOn(Schedulers.io())
7677
.observeOn(AndroidSchedulers.mainThread())
@@ -91,7 +92,7 @@ public void receive(List<Uri> media, String mimeType, @Contribution.FileSource S
9192
* @param source File source from {@link Contribution.FileSource}
9293
*/
9394
@SuppressLint("CheckResult")
94-
public void receiveDirect(Uri media, String mimeType, @Contribution.FileSource String source, String wikidataEntityIdPref, String title, String desc) {
95+
void receiveDirect(Uri media, String mimeType, @Contribution.FileSource String source, String wikidataEntityIdPref, String title, String desc) {
9596
Completable.fromRunnable(() -> uploadModel.receiveDirect(media, mimeType, source, wikidataEntityIdPref, title, desc, similarImageInterface))
9697
.subscribeOn(Schedulers.io())
9798
.observeOn(AndroidSchedulers.mainThread())
@@ -108,7 +109,7 @@ public void receiveDirect(Uri media, String mimeType, @Contribution.FileSource S
108109
*
109110
* @param licenseName license name
110111
*/
111-
public void selectLicense(String licenseName) {
112+
void selectLicense(String licenseName) {
112113
uploadModel.setSelectedLicense(licenseName);
113114
view.updateLicenseSummary(uploadModel.getSelectedLicense());
114115
}
@@ -119,7 +120,7 @@ public void selectLicense(String licenseName) {
119120
* Called by the next button in {@link UploadActivity}
120121
*/
121122
@SuppressLint("CheckResult")
122-
public void handleNext(CategoriesModel categoriesModel, boolean noCategoryWarningShown) {
123+
void handleNext(CategoriesModel categoriesModel, boolean noCategoryWarningShown) {
123124
if(currentPage == UploadView.TITLE_CARD) {
124125
validateCurrentItemTitle()
125126
.subscribeOn(Schedulers.io())
@@ -167,7 +168,7 @@ private Title getCurrentImageTitle() {
167168
return getCurrentItem().title;
168169
}
169170

170-
public String getCurrentImageFileName() {
171+
String getCurrentImageFileName() {
171172
UploadItem currentItem = getCurrentItem();
172173
return currentItem.title + "." + uploadModel.getCurrentItem().fileExt;
173174
}
@@ -193,7 +194,7 @@ private Observable<Integer> validateCurrentItemTitle() {
193194
/**
194195
* Called by the previous button in {@link UploadActivity}
195196
*/
196-
public void handlePrevious() {
197+
void handlePrevious() {
197198
uploadModel.previous();
198199
updateContent();
199200
if (uploadModel.isShowingItem()) {
@@ -205,7 +206,7 @@ public void handlePrevious() {
205206
/**
206207
* Called when one of the pictures on the top card is clicked on in {@link UploadActivity}
207208
*/
208-
public void thumbnailClicked(UploadItem item) {
209+
void thumbnailClicked(UploadItem item) {
209210
uploadModel.jumpTo(item);
210211
updateContent();
211212
}
@@ -214,7 +215,7 @@ public void thumbnailClicked(UploadItem item) {
214215
* Called by the submit button in {@link UploadActivity}
215216
*/
216217
@SuppressLint("CheckResult")
217-
public void handleSubmit(CategoriesModel categoriesModel) {
218+
void handleSubmit(CategoriesModel categoriesModel) {
218219
if (view.checkIfLoggedIn())
219220
uploadModel.buildContributions(categoriesModel.getCategoryStringList())
220221
.observeOn(Schedulers.io())
@@ -224,7 +225,7 @@ public void handleSubmit(CategoriesModel categoriesModel) {
224225
/**
225226
* Called by the map button on the right card in {@link UploadActivity}
226227
*/
227-
public void openCoordinateMap() {
228+
void openCoordinateMap() {
228229
GPSExtractor gpsObj = uploadModel.getCurrentItem().gpsCoords;
229230
if (gpsObj != null && gpsObj.imageCoordsExists) {
230231
view.launchMapActivity(gpsObj.getDecLatitude() + "," + gpsObj.getDecLongitude());
@@ -241,11 +242,11 @@ private void handleBadPicture(@ImageUtils.Result int result) {
241242
view.showBadPicturePopup(result);
242243
}
243244

244-
public void keepPicture() {
245+
void keepPicture() {
245246
uploadModel.keepPicture();
246247
}
247248

248-
public void deletePicture() {
249+
void deletePicture() {
249250
if (uploadModel.getCount() == 1)
250251
view.finish();
251252
else {
@@ -265,31 +266,31 @@ public void deletePicture() {
265266
/**
266267
* Toggles the top card's state between open and closed.
267268
*/
268-
public void toggleTopCardState() {
269+
void toggleTopCardState() {
269270
uploadModel.setTopCardState(!uploadModel.isTopCardState());
270271
view.setTopCardState(uploadModel.isTopCardState());
271272
}
272273

273274
/**
274275
* Toggles the bottom card's state between open and closed.
275276
*/
276-
public void toggleBottomCardState() {
277+
void toggleBottomCardState() {
277278
uploadModel.setBottomCardState(!uploadModel.isBottomCardState());
278279
view.setBottomCardState(uploadModel.isBottomCardState());
279280
}
280281

281282
/**
282283
* Toggles the right card's state between open and closed.
283284
*/
284-
public void toggleRightCardState() {
285+
void toggleRightCardState() {
285286
uploadModel.setRightCardState(!uploadModel.isRightCardState());
286287
view.setRightCardState(uploadModel.isRightCardState());
287288
}
288289

289290
/**
290291
* Sets all the cards' states to closed.
291292
*/
292-
public void closeAllCards() {
293+
void closeAllCards() {
293294
if (uploadModel.isTopCardState()) {
294295
uploadModel.setTopCardState(false);
295296
view.setTopCardState(false);
@@ -310,15 +311,15 @@ public void init() {
310311
uploadController.prepareService();
311312
}
312313

313-
public void cleanup() {
314+
void cleanup() {
314315
uploadController.cleanup();
315316
}
316317

317-
public void removeView() {
318+
void removeView() {
318319
this.view = DUMMY;
319320
}
320321

321-
public void addView(UploadView view) {
322+
void addView(UploadView view) {
322323
this.view = view;
323324

324325
updateCards();
@@ -399,11 +400,11 @@ private void showCorrectCards(int currentStep, int uploadCount) {
399400
/**
400401
* @return the item currently being displayed
401402
*/
402-
public UploadItem getCurrentItem() {
403+
private UploadItem getCurrentItem() {
403404
return uploadModel.getCurrentItem();
404405
}
405406

406-
public List<String> getImageTitleList() {
407+
List<String> getImageTitleList() {
407408
List<String> titleList = new ArrayList<>();
408409
for (UploadItem item : uploadModel.getUploads()) {
409410
if (item.title.isSet()) {

0 commit comments

Comments
 (0)