mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-28 21:33:53 +01:00
Merge pull request #1319 from misaochan/category-suggestions-new
Category suggestions for direct nearby uploads
This commit is contained in:
commit
4c192e48e0
9 changed files with 59 additions and 15 deletions
|
|
@ -72,6 +72,8 @@ public class CategorizationFragment extends CommonsDaggerSupportFragment {
|
||||||
|
|
||||||
@Inject MediaWikiApi mwApi;
|
@Inject MediaWikiApi mwApi;
|
||||||
@Inject @Named("default_preferences") SharedPreferences prefs;
|
@Inject @Named("default_preferences") SharedPreferences prefs;
|
||||||
|
@Inject @Named("prefs") SharedPreferences prefsPrefs;
|
||||||
|
@Inject @Named("direct_nearby_upload_prefs") SharedPreferences directPrefs;
|
||||||
@Inject CategoryDao categoryDao;
|
@Inject CategoryDao categoryDao;
|
||||||
|
|
||||||
private RVRendererAdapter<CategoryItem> categoriesAdapter;
|
private RVRendererAdapter<CategoryItem> categoriesAdapter;
|
||||||
|
|
@ -79,6 +81,7 @@ public class CategorizationFragment extends CommonsDaggerSupportFragment {
|
||||||
private HashMap<String, ArrayList<String>> categoriesCache;
|
private HashMap<String, ArrayList<String>> categoriesCache;
|
||||||
private List<CategoryItem> selectedCategories = new ArrayList<>();
|
private List<CategoryItem> selectedCategories = new ArrayList<>();
|
||||||
private TitleTextWatcher textWatcher = new TitleTextWatcher();
|
private TitleTextWatcher textWatcher = new TitleTextWatcher();
|
||||||
|
private boolean hasDirectCategories = false;
|
||||||
|
|
||||||
private final CategoriesAdapterFactory adapterFactory = new CategoriesAdapterFactory(item -> {
|
private final CategoriesAdapterFactory adapterFactory = new CategoriesAdapterFactory(item -> {
|
||||||
if (item.isSelected()) {
|
if (item.isSelected()) {
|
||||||
|
|
@ -127,7 +130,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 +225,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);
|
||||||
|
|
@ -257,9 +260,34 @@ public class CategorizationFragment extends CommonsDaggerSupportFragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
private Observable<CategoryItem> defaultCategories() {
|
private Observable<CategoryItem> defaultCategories() {
|
||||||
return gpsCategories()
|
|
||||||
.concatWith(titleCategories())
|
Observable<CategoryItem> directCat = directCategories();
|
||||||
.concatWith(recentCategories());
|
if (hasDirectCategories) {
|
||||||
|
Timber.d("Image has direct Cat");
|
||||||
|
return directCat
|
||||||
|
.concatWith(gpsCategories())
|
||||||
|
.concatWith(titleCategories())
|
||||||
|
.concatWith(recentCategories());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Timber.d("Image has no direct Cat");
|
||||||
|
return gpsCategories()
|
||||||
|
.concatWith(titleCategories())
|
||||||
|
.concatWith(recentCategories());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Observable<CategoryItem> directCategories() {
|
||||||
|
String directCategory = directPrefs.getString("Category", "");
|
||||||
|
List<String> categoryList = new ArrayList<>();
|
||||||
|
Timber.d("Direct category found: " + directCategory);
|
||||||
|
|
||||||
|
if (!directCategory.equals("")) {
|
||||||
|
hasDirectCategories = true;
|
||||||
|
categoryList.add(directCategory);
|
||||||
|
Timber.d("DirectCat does not equal emptyString. Direct Cat list has " + categoryList);
|
||||||
|
}
|
||||||
|
return Observable.fromIterable(categoryList).map(name -> new CategoryItem(name, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
private Observable<CategoryItem> gpsCategories() {
|
private Observable<CategoryItem> gpsCategories() {
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,7 @@ public interface CommonsApplicationComponent extends AndroidInjector<Application
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void inject(ApplicationlessInjection instance);
|
void inject(ApplicationlessInjection instance);
|
||||||
|
|
||||||
void inject(PlaceRenderer placeRenderer);
|
void inject(PlaceRenderer placeRenderer);
|
||||||
|
|
||||||
@Component.Builder
|
@Component.Builder
|
||||||
|
|
|
||||||
|
|
@ -623,6 +623,7 @@ public class NearbyMapFragment extends DaggerFragment {
|
||||||
SharedPreferences.Editor editor = directPrefs.edit();
|
SharedPreferences.Editor editor = directPrefs.edit();
|
||||||
editor.putString("Title", place.getName());
|
editor.putString("Title", place.getName());
|
||||||
editor.putString("Desc", place.getLongDescription());
|
editor.putString("Desc", place.getLongDescription());
|
||||||
|
editor.putString("Category", place.getCategory());
|
||||||
editor.apply();
|
editor.apply();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ import java.io.InputStreamReader;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLConnection;
|
import java.net.URLConnection;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
@ -100,13 +101,17 @@ public class NearbyPlaces {
|
||||||
}
|
}
|
||||||
|
|
||||||
String[] fields = line.split("\t");
|
String[] fields = line.split("\t");
|
||||||
|
Timber.v("Fields: " + Arrays.toString(fields));
|
||||||
String point = fields[0];
|
String point = fields[0];
|
||||||
|
String wikiDataLink = Utils.stripLocalizedString(fields[1]);
|
||||||
String name = Utils.stripLocalizedString(fields[2]);
|
String name = Utils.stripLocalizedString(fields[2]);
|
||||||
String type = Utils.stripLocalizedString(fields[4]);
|
String type = Utils.stripLocalizedString(fields[4]);
|
||||||
|
String icon = fields[5];
|
||||||
String wikipediaSitelink = Utils.stripLocalizedString(fields[7]);
|
String wikipediaSitelink = Utils.stripLocalizedString(fields[7]);
|
||||||
String commonsSitelink = Utils.stripLocalizedString(fields[8]);
|
String commonsSitelink = Utils.stripLocalizedString(fields[8]);
|
||||||
String wikiDataLink = Utils.stripLocalizedString(fields[1]);
|
String category = Utils.stripLocalizedString(fields[9]);
|
||||||
String icon = fields[5];
|
|
||||||
|
Timber.v("Name: " + name + ", type: " + type + ", category: " + category + ", wikipediaSitelink: " + wikipediaSitelink + ", commonsSitelink: " + commonsSitelink);
|
||||||
|
|
||||||
double latitude;
|
double latitude;
|
||||||
double longitude;
|
double longitude;
|
||||||
|
|
@ -128,6 +133,7 @@ public class NearbyPlaces {
|
||||||
type, // details
|
type, // details
|
||||||
Uri.parse(icon),
|
Uri.parse(icon),
|
||||||
new LatLng(latitude, longitude, 0),
|
new LatLng(latitude, longitude, 0),
|
||||||
|
category,
|
||||||
new Sitelinks.Builder()
|
new Sitelinks.Builder()
|
||||||
.setWikipediaLink(wikipediaSitelink)
|
.setWikipediaLink(wikipediaSitelink)
|
||||||
.setCommonsLink(commonsSitelink)
|
.setCommonsLink(commonsSitelink)
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ public class Place {
|
||||||
private final String longDescription;
|
private final String longDescription;
|
||||||
private final Uri secondaryImageUrl;
|
private final Uri secondaryImageUrl;
|
||||||
public final LatLng location;
|
public final LatLng location;
|
||||||
|
private final String category;
|
||||||
|
|
||||||
public Bitmap image;
|
public Bitmap image;
|
||||||
public Bitmap secondaryImage;
|
public Bitmap secondaryImage;
|
||||||
|
|
@ -25,12 +26,13 @@ public class Place {
|
||||||
|
|
||||||
|
|
||||||
public Place(String name, Label label, String longDescription,
|
public Place(String name, Label label, String longDescription,
|
||||||
Uri secondaryImageUrl, LatLng location, Sitelinks siteLinks) {
|
Uri secondaryImageUrl, LatLng location, String category, Sitelinks siteLinks) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.label = label;
|
this.label = label;
|
||||||
this.longDescription = longDescription;
|
this.longDescription = longDescription;
|
||||||
this.secondaryImageUrl = secondaryImageUrl;
|
this.secondaryImageUrl = secondaryImageUrl;
|
||||||
this.location = location;
|
this.location = location;
|
||||||
|
this.category = category;
|
||||||
this.siteLinks = siteLinks;
|
this.siteLinks = siteLinks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -42,6 +44,8 @@ public class Place {
|
||||||
|
|
||||||
public String getLongDescription() { return longDescription; }
|
public String getLongDescription() { return longDescription; }
|
||||||
|
|
||||||
|
public String getCategory() {return category; }
|
||||||
|
|
||||||
public void setDistance(String distance) {
|
public void setDistance(String distance) {
|
||||||
this.distance = distance;
|
this.distance = distance;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ import butterknife.ButterKnife;
|
||||||
import fr.free.nrw.commons.CommonsApplication;
|
import fr.free.nrw.commons.CommonsApplication;
|
||||||
import fr.free.nrw.commons.R;
|
import fr.free.nrw.commons.R;
|
||||||
import fr.free.nrw.commons.contributions.ContributionController;
|
import fr.free.nrw.commons.contributions.ContributionController;
|
||||||
|
import fr.free.nrw.commons.di.ApplicationlessInjection;
|
||||||
import timber.log.Timber;
|
import timber.log.Timber;
|
||||||
|
|
||||||
public class PlaceRenderer extends Renderer<Place> {
|
public class PlaceRenderer extends Renderer<Place> {
|
||||||
|
|
@ -124,8 +125,8 @@ public class PlaceRenderer extends Renderer<Place> {
|
||||||
Timber.d("directPrefs stored");
|
Timber.d("directPrefs stored");
|
||||||
editor.putString("Title", place.getName());
|
editor.putString("Title", place.getName());
|
||||||
editor.putString("Desc", place.getLongDescription());
|
editor.putString("Desc", place.getLongDescription());
|
||||||
|
editor.putString("Category", place.getCategory());
|
||||||
editor.apply();
|
editor.apply();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void closeLayout(LinearLayout buttonLayout){
|
private void closeLayout(LinearLayout buttonLayout){
|
||||||
|
|
@ -138,7 +139,8 @@ public class PlaceRenderer extends Renderer<Place> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render() {
|
public void render() {
|
||||||
|
ApplicationlessInjection.getInstance(getContext().getApplicationContext())
|
||||||
|
.getCommonsApplicationComponent().inject(this);
|
||||||
place = getContent();
|
place = getContent();
|
||||||
tvName.setText(place.name);
|
tvName.setText(place.name);
|
||||||
String descriptionText = place.getLongDescription();
|
String descriptionText = place.getLongDescription();
|
||||||
|
|
|
||||||
|
|
@ -114,6 +114,8 @@ public class SingleUploadFragment extends CommonsDaggerSupportFragment {
|
||||||
if (isNearbyUpload) {
|
if (isNearbyUpload) {
|
||||||
String imageTitle = directPrefs.getString("Title", "");
|
String imageTitle = directPrefs.getString("Title", "");
|
||||||
String imageDesc = directPrefs.getString("Desc", "");
|
String imageDesc = directPrefs.getString("Desc", "");
|
||||||
|
String imageCats = directPrefs.getString("Category", "");
|
||||||
|
Timber.d("Image title: " + imageTitle + ", image desc: " + imageDesc + ", image categories: " + imageCats);
|
||||||
titleEdit.setText(imageTitle);
|
titleEdit.setText(imageTitle);
|
||||||
descEdit.setText(imageDesc);
|
descEdit.setText(imageDesc);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,7 @@ public class ImageUtils {
|
||||||
|
|
||||||
while ((checkImageRightPosition <= loadImageWidth) && (checkImageLeftPosition < checkImageRightPosition)) {
|
while ((checkImageRightPosition <= loadImageWidth) && (checkImageLeftPosition < checkImageRightPosition)) {
|
||||||
while ((checkImageBottomPosition <= loadImageHeight) && (checkImageTopPosition < checkImageBottomPosition)) {
|
while ((checkImageBottomPosition <= loadImageHeight) && (checkImageTopPosition < checkImageBottomPosition)) {
|
||||||
Timber.d("left: " + checkImageLeftPosition + " right: " + checkImageRightPosition + " top: " + checkImageTopPosition + " bottom: " + checkImageBottomPosition);
|
Timber.v("left: " + checkImageLeftPosition + " right: " + checkImageRightPosition + " top: " + checkImageTopPosition + " bottom: " + checkImageBottomPosition);
|
||||||
|
|
||||||
Rect rect = new Rect(checkImageLeftPosition,checkImageTopPosition,checkImageRightPosition,checkImageBottomPosition);
|
Rect rect = new Rect(checkImageLeftPosition,checkImageTopPosition,checkImageRightPosition,checkImageBottomPosition);
|
||||||
totalDividedRectangles++;
|
totalDividedRectangles++;
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ SELECT
|
||||||
(SAMPLE(COALESCE(?emoji0, ?emoji1)) as ?emoji)
|
(SAMPLE(COALESCE(?emoji0, ?emoji1)) as ?emoji)
|
||||||
?wikipediaArticle
|
?wikipediaArticle
|
||||||
?commonsArticle
|
?commonsArticle
|
||||||
|
(SAMPLE(?Commons_category) as ?Commons_category)
|
||||||
WHERE {
|
WHERE {
|
||||||
# Around given location...
|
# Around given location...
|
||||||
SERVICE wikibase:around {
|
SERVICE wikibase:around {
|
||||||
|
|
@ -23,6 +24,9 @@ SELECT
|
||||||
OPTIONAL {?item rdfs:label ?item_label_preferred_language. FILTER (lang(?item_label_preferred_language) = "${LANG}")}
|
OPTIONAL {?item rdfs:label ?item_label_preferred_language. FILTER (lang(?item_label_preferred_language) = "${LANG}")}
|
||||||
OPTIONAL {?item rdfs:label ?item_label_any_language}
|
OPTIONAL {?item rdfs:label ?item_label_any_language}
|
||||||
|
|
||||||
|
# Get Commons category (P373)
|
||||||
|
OPTIONAL { ?item wdt:P373 ?Commons_category. }
|
||||||
|
|
||||||
# Get the class label in the preferred language of the user, or any other language if no label is available in that language.
|
# Get the class label in the preferred language of the user, or any other language if no label is available in that language.
|
||||||
OPTIONAL {
|
OPTIONAL {
|
||||||
?item p:P31/ps:P31 ?classId.
|
?item p:P31/ps:P31 ?classId.
|
||||||
|
|
@ -35,10 +39,6 @@ SELECT
|
||||||
# Get emoji
|
# Get emoji
|
||||||
OPTIONAL { ?classId wdt:P487 ?emoji0. }
|
OPTIONAL { ?classId wdt:P487 ?emoji0. }
|
||||||
OPTIONAL { ?classId wdt:P279*/wdt:P487 ?emoji1. }
|
OPTIONAL { ?classId wdt:P279*/wdt:P487 ?emoji1. }
|
||||||
OPTIONAL {
|
|
||||||
?sitelink schema:about ?item .
|
|
||||||
?sitelink schema:inLanguage "en"
|
|
||||||
}
|
|
||||||
OPTIONAL {
|
OPTIONAL {
|
||||||
?wikipediaArticle schema:about ?item ;
|
?wikipediaArticle schema:about ?item ;
|
||||||
schema:isPartOf <https://en.wikipedia.org/> .
|
schema:isPartOf <https://en.wikipedia.org/> .
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue