@@ -68,6 +68,7 @@ public class CategorizationFragment extends Fragment {
68
68
private HashMap <String , ArrayList <String >> categoriesCache ;
69
69
private List <CategoryItem > selectedCategories = new ArrayList <>();
70
70
private ContentProviderClient databaseClient ;
71
+
71
72
private final CategoriesAdapterFactory adapterFactory = new CategoriesAdapterFactory (item -> {
72
73
if (item .isSelected ()) {
73
74
selectedCategories .add (item );
@@ -77,26 +78,6 @@ public class CategorizationFragment extends Fragment {
77
78
}
78
79
});
79
80
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
-
100
81
@ Override
101
82
public View onCreateView (LayoutInflater inflater , ViewGroup container ,
102
83
Bundle savedInstanceState ) {
@@ -131,50 +112,6 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
131
112
return rootView ;
132
113
}
133
114
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
-
178
115
@ Override
179
116
public void onCreateOptionsMenu (Menu menu , MenuInflater inflater ) {
180
117
menu .clear ();
@@ -243,6 +180,50 @@ public void onActivityCreated(Bundle savedInstanceState) {
243
180
databaseClient = getActivity ().getContentResolver ().acquireContentProviderClient (AUTHORITY );
244
181
}
245
182
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
+
246
227
private List <String > getStringList (List <CategoryItem > input ) {
247
228
List <String > output = new ArrayList <>();
248
229
for (CategoryItem item : input ) {
@@ -273,7 +254,7 @@ private Observable<CategoryItem> recentCategories() {
273
254
.map (s -> new CategoryItem (s , false ));
274
255
}
275
256
276
- private Observable <CategoryItem > search (String term ) {
257
+ private Observable <CategoryItem > searchAll (String term ) {
277
258
//If user hasn't typed anything in yet, get GPS and recent items
278
259
if (TextUtils .isEmpty (term )) {
279
260
return Observable .empty ();
@@ -291,7 +272,7 @@ private Observable<CategoryItem> search(String term) {
291
272
.map (name -> new CategoryItem (name , false ));
292
273
}
293
274
294
- private Observable <CategoryItem > search2 (String term ) {
275
+ private Observable <CategoryItem > searchCategories (String term ) {
295
276
//If user hasn't typed anything in yet, get GPS and recent items
296
277
if (TextUtils .isEmpty (term )) {
297
278
return Observable .empty ();
@@ -319,6 +300,26 @@ private boolean containsYear(String items) {
319
300
|| items .matches ("(.*)needing(.*)" ) || items .matches ("(.*)taken on(.*)" ));
320
301
}
321
302
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
+
322
323
public int getCurrentSelectedCount () {
323
324
return selectedCategories .size ();
324
325
}
@@ -336,7 +337,7 @@ public void showBackButtonDialog() {
336
337
.show ();
337
338
}
338
339
339
- public void showConfirmationDialog () {
340
+ private void showConfirmationDialog () {
340
341
new AlertDialog .Builder (getActivity ())
341
342
.setMessage ("Images without categories are rarely usable. "
342
343
+ "Are you sure you want to submit without selecting "
0 commit comments