Skip to content

Commit 0443f65

Browse files
committed
Reorder to clarify
1 parent 22cd1ac commit 0443f65

File tree

2 files changed

+69
-68
lines changed

2 files changed

+69
-68
lines changed

app/src/main/java/fr/free/nrw/commons/category/CategorizationFragment.java

Lines changed: 68 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ public class CategorizationFragment extends Fragment {
6868
private HashMap<String, ArrayList<String>> categoriesCache;
6969
private List<CategoryItem> selectedCategories = new ArrayList<>();
7070
private ContentProviderClient databaseClient;
71+
7172
private final CategoriesAdapterFactory adapterFactory = new CategoriesAdapterFactory(item -> {
7273
if (item.isSelected()) {
7374
selectedCategories.add(item);
@@ -77,26 +78,6 @@ public class CategorizationFragment extends Fragment {
7778
}
7879
});
7980

80-
private void updateCategoryCount(CategoryItem item, ContentProviderClient client) {
81-
Category cat = lookupCategory(item.getName());
82-
cat.incTimesUsed();
83-
cat.save(client);
84-
}
85-
86-
private Category lookupCategory(String name) {
87-
Category cat = Category.find(databaseClient, name);
88-
89-
if (cat == null) {
90-
// Newly used category...
91-
cat = new Category();
92-
cat.setName(name);
93-
cat.setLastUsed(new Date());
94-
cat.setTimesUsed(0);
95-
}
96-
97-
return cat;
98-
}
99-
10081
@Override
10182
public View onCreateView(LayoutInflater inflater, ViewGroup container,
10283
Bundle savedInstanceState) {
@@ -131,50 +112,6 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
131112
return rootView;
132113
}
133114

134-
private void updateCategoryList(String filter) {
135-
Observable.fromIterable(selectedCategories)
136-
.subscribeOn(Schedulers.io())
137-
.observeOn(AndroidSchedulers.mainThread())
138-
.doOnSubscribe(disposable -> {
139-
categoriesSearchInProgress.setVisibility(View.VISIBLE);
140-
categoriesNotFoundView.setVisibility(View.GONE);
141-
categoriesSkip.setVisibility(View.GONE);
142-
categoriesAdapter.clear();
143-
})
144-
.observeOn(Schedulers.io())
145-
.concatWith(
146-
search(filter)
147-
.mergeWith(search2(filter))
148-
.filter(categoryItem -> !selectedCategories.contains(categoryItem))
149-
.switchIfEmpty(
150-
gpsCategories()
151-
.concatWith(titleCategories())
152-
.concatWith(recentCategories())
153-
.filter(categoryItem -> !selectedCategories.contains(categoryItem))
154-
)
155-
)
156-
.filter(categoryItem -> !containsYear(categoryItem.getName()))
157-
.observeOn(AndroidSchedulers.mainThread())
158-
.subscribe(
159-
s -> categoriesAdapter.add(s),
160-
throwable -> Timber.e(throwable),
161-
() -> {
162-
categoriesAdapter.notifyDataSetChanged();
163-
categoriesSearchInProgress.setVisibility(View.GONE);
164-
165-
if (categoriesAdapter.getItemCount() == 0) {
166-
if (TextUtils.isEmpty(filter)) {
167-
// If we found no recent cats, show the skip message!
168-
categoriesSkip.setVisibility(View.VISIBLE);
169-
} else {
170-
categoriesNotFoundView.setText(getString(R.string.categories_not_found, filter));
171-
categoriesNotFoundView.setVisibility(View.VISIBLE);
172-
}
173-
}
174-
}
175-
);
176-
}
177-
178115
@Override
179116
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
180117
menu.clear();
@@ -243,6 +180,50 @@ public void onActivityCreated(Bundle savedInstanceState) {
243180
databaseClient = getActivity().getContentResolver().acquireContentProviderClient(AUTHORITY);
244181
}
245182

183+
private void updateCategoryList(String filter) {
184+
Observable.fromIterable(selectedCategories)
185+
.subscribeOn(Schedulers.io())
186+
.observeOn(AndroidSchedulers.mainThread())
187+
.doOnSubscribe(disposable -> {
188+
categoriesSearchInProgress.setVisibility(View.VISIBLE);
189+
categoriesNotFoundView.setVisibility(View.GONE);
190+
categoriesSkip.setVisibility(View.GONE);
191+
categoriesAdapter.clear();
192+
})
193+
.observeOn(Schedulers.io())
194+
.concatWith(
195+
searchAll(filter)
196+
.mergeWith(searchCategories(filter))
197+
.filter(categoryItem -> !selectedCategories.contains(categoryItem))
198+
.switchIfEmpty(
199+
gpsCategories()
200+
.concatWith(titleCategories())
201+
.concatWith(recentCategories())
202+
.filter(categoryItem -> !selectedCategories.contains(categoryItem))
203+
)
204+
)
205+
.filter(categoryItem -> !containsYear(categoryItem.getName()))
206+
.observeOn(AndroidSchedulers.mainThread())
207+
.subscribe(
208+
s -> categoriesAdapter.add(s),
209+
throwable -> Timber.e(throwable),
210+
() -> {
211+
categoriesAdapter.notifyDataSetChanged();
212+
categoriesSearchInProgress.setVisibility(View.GONE);
213+
214+
if (categoriesAdapter.getItemCount() == 0) {
215+
if (TextUtils.isEmpty(filter)) {
216+
// If we found no recent cats, show the skip message!
217+
categoriesSkip.setVisibility(View.VISIBLE);
218+
} else {
219+
categoriesNotFoundView.setText(getString(R.string.categories_not_found, filter));
220+
categoriesNotFoundView.setVisibility(View.VISIBLE);
221+
}
222+
}
223+
}
224+
);
225+
}
226+
246227
private List<String> getStringList(List<CategoryItem> input) {
247228
List<String> output = new ArrayList<>();
248229
for (CategoryItem item : input) {
@@ -273,7 +254,7 @@ private Observable<CategoryItem> recentCategories() {
273254
.map(s -> new CategoryItem(s, false));
274255
}
275256

276-
private Observable<CategoryItem> search(String term) {
257+
private Observable<CategoryItem> searchAll(String term) {
277258
//If user hasn't typed anything in yet, get GPS and recent items
278259
if (TextUtils.isEmpty(term)) {
279260
return Observable.empty();
@@ -291,7 +272,7 @@ private Observable<CategoryItem> search(String term) {
291272
.map(name -> new CategoryItem(name, false));
292273
}
293274

294-
private Observable<CategoryItem> search2(String term) {
275+
private Observable<CategoryItem> searchCategories(String term) {
295276
//If user hasn't typed anything in yet, get GPS and recent items
296277
if (TextUtils.isEmpty(term)) {
297278
return Observable.empty();
@@ -319,6 +300,26 @@ private boolean containsYear(String items) {
319300
|| items.matches("(.*)needing(.*)") || items.matches("(.*)taken on(.*)"));
320301
}
321302

303+
private void updateCategoryCount(CategoryItem item, ContentProviderClient client) {
304+
Category cat = lookupCategory(item.getName());
305+
cat.incTimesUsed();
306+
cat.save(client);
307+
}
308+
309+
private Category lookupCategory(String name) {
310+
Category cat = Category.find(databaseClient, name);
311+
312+
if (cat == null) {
313+
// Newly used category...
314+
cat = new Category();
315+
cat.setName(name);
316+
cat.setLastUsed(new Date());
317+
cat.setTimesUsed(0);
318+
}
319+
320+
return cat;
321+
}
322+
322323
public int getCurrentSelectedCount() {
323324
return selectedCategories.size();
324325
}
@@ -336,7 +337,7 @@ public void showBackButtonDialog() {
336337
.show();
337338
}
338339

339-
public void showConfirmationDialog() {
340+
private void showConfirmationDialog() {
340341
new AlertDialog.Builder(getActivity())
341342
.setMessage("Images without categories are rarely usable. "
342343
+ "Are you sure you want to submit without selecting "

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
525525
switch (item.getItemId()) {
526526
case android.R.id.home:
527527
if(categorizationFragment!=null && categorizationFragment.isVisible()) {
528-
categorizationFragment.backButtonDialog();
528+
categorizationFragment.showBackButtonDialog();
529529
} else {
530530
onBackPressed();
531531
}

0 commit comments

Comments
 (0)