Add directPrefs injection and obtain CategoryItem for direct cats

This commit is contained in:
misaochan 2018-03-18 18:26:13 +10:00
parent 945aa35864
commit d2b0ffc69d

View file

@ -70,9 +70,19 @@ public class CategorizationFragment extends CommonsDaggerSupportFragment {
@BindView(R.id.categoriesExplanation) @BindView(R.id.categoriesExplanation)
TextView categoriesSkip; TextView categoriesSkip;
@Inject MediaWikiApi mwApi; @Inject
@Inject @Named("default_preferences") SharedPreferences prefs; MediaWikiApi mwApi;
@Inject CategoryDao categoryDao; @Inject
@Named("default_preferences")
SharedPreferences prefs;
@Inject
@Named("prefs")
SharedPreferences prefsPrefs;
@Inject
@Named("direct_nearby_upload_prefs")
SharedPreferences directPrefs;
@Inject
CategoryDao categoryDao;
private RVRendererAdapter<CategoryItem> categoriesAdapter; private RVRendererAdapter<CategoryItem> categoriesAdapter;
private OnCategoriesSaveHandler onCategoriesSaveHandler; private OnCategoriesSaveHandler onCategoriesSaveHandler;
@ -127,7 +137,7 @@ public class CategorizationFragment extends CommonsDaggerSupportFragment {
} }
public void hideKeyboard(View view) { public void hideKeyboard(View view) {
InputMethodManager inputMethodManager =(InputMethodManager)getActivity().getSystemService(Activity.INPUT_METHOD_SERVICE); InputMethodManager inputMethodManager = (InputMethodManager) getActivity().getSystemService(Activity.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0); inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
} }
@ -222,7 +232,7 @@ public class CategorizationFragment extends CommonsDaggerSupportFragment {
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe( .subscribe(
s -> categoriesAdapter.add(s), s -> categoriesAdapter.add(s),
Timber::e, Timber::e,
() -> { () -> {
categoriesAdapter.notifyDataSetChanged(); categoriesAdapter.notifyDataSetChanged();
categoriesSearchInProgress.setVisibility(View.GONE); categoriesSearchInProgress.setVisibility(View.GONE);
@ -259,11 +269,20 @@ public class CategorizationFragment extends CommonsDaggerSupportFragment {
private Observable<CategoryItem> defaultCategories() { private Observable<CategoryItem> defaultCategories() {
return gpsCategories() return gpsCategories()
.concatWith(titleCategories()) .concatWith(titleCategories())
.concatWith(recentCategories()); .concatWith(recentCategories())
.concatWith(directCategories());
//TODO: Add category suggestions for direct uploads here //TODO: Add category suggestions for direct uploads here
} }
//TODO: Add category suggestions for direct uploads here //TODO: Add category suggestions for direct uploads here
private Observable<CategoryItem> directCategories() {
String directCategory = directPrefs.getString("Category", "");
Timber.d("Direct category found: " + directCategory);
//String[] myStringArray = {directCategory};
List<String> categoryList = new ArrayList<>();
categoryList.add(directCategory);
return Observable.fromIterable(categoryList).map(name -> new CategoryItem(name, false));
}
private Observable<CategoryItem> gpsCategories() { private Observable<CategoryItem> gpsCategories() {
return Observable.fromIterable( return Observable.fromIterable(