mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 12:53:55 +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 @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;
|
||||
|
|
@ -79,6 +81,7 @@ public class CategorizationFragment extends CommonsDaggerSupportFragment {
|
|||
private HashMap<String, ArrayList<String>> categoriesCache;
|
||||
private List<CategoryItem> selectedCategories = new ArrayList<>();
|
||||
private TitleTextWatcher textWatcher = new TitleTextWatcher();
|
||||
private boolean hasDirectCategories = false;
|
||||
|
||||
private final CategoriesAdapterFactory adapterFactory = new CategoriesAdapterFactory(item -> {
|
||||
if (item.isSelected()) {
|
||||
|
|
@ -127,7 +130,7 @@ public class CategorizationFragment extends CommonsDaggerSupportFragment {
|
|||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
@ -222,7 +225,7 @@ public class CategorizationFragment extends CommonsDaggerSupportFragment {
|
|||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(
|
||||
s -> categoriesAdapter.add(s),
|
||||
Timber::e,
|
||||
Timber::e,
|
||||
() -> {
|
||||
categoriesAdapter.notifyDataSetChanged();
|
||||
categoriesSearchInProgress.setVisibility(View.GONE);
|
||||
|
|
@ -257,9 +260,34 @@ public class CategorizationFragment extends CommonsDaggerSupportFragment {
|
|||
}
|
||||
|
||||
private Observable<CategoryItem> defaultCategories() {
|
||||
return gpsCategories()
|
||||
.concatWith(titleCategories())
|
||||
.concatWith(recentCategories());
|
||||
|
||||
Observable<CategoryItem> directCat = directCategories();
|
||||
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() {
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ public interface CommonsApplicationComponent extends AndroidInjector<Application
|
|||
|
||||
@Override
|
||||
void inject(ApplicationlessInjection instance);
|
||||
|
||||
void inject(PlaceRenderer placeRenderer);
|
||||
|
||||
@Component.Builder
|
||||
|
|
|
|||
|
|
@ -623,6 +623,7 @@ public class NearbyMapFragment extends DaggerFragment {
|
|||
SharedPreferences.Editor editor = directPrefs.edit();
|
||||
editor.putString("Title", place.getName());
|
||||
editor.putString("Desc", place.getLongDescription());
|
||||
editor.putString("Category", place.getCategory());
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import java.io.InputStreamReader;
|
|||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
|
@ -100,13 +101,17 @@ public class NearbyPlaces {
|
|||
}
|
||||
|
||||
String[] fields = line.split("\t");
|
||||
Timber.v("Fields: " + Arrays.toString(fields));
|
||||
String point = fields[0];
|
||||
String wikiDataLink = Utils.stripLocalizedString(fields[1]);
|
||||
String name = Utils.stripLocalizedString(fields[2]);
|
||||
String type = Utils.stripLocalizedString(fields[4]);
|
||||
String icon = fields[5];
|
||||
String wikipediaSitelink = Utils.stripLocalizedString(fields[7]);
|
||||
String commonsSitelink = Utils.stripLocalizedString(fields[8]);
|
||||
String wikiDataLink = Utils.stripLocalizedString(fields[1]);
|
||||
String icon = fields[5];
|
||||
String category = Utils.stripLocalizedString(fields[9]);
|
||||
|
||||
Timber.v("Name: " + name + ", type: " + type + ", category: " + category + ", wikipediaSitelink: " + wikipediaSitelink + ", commonsSitelink: " + commonsSitelink);
|
||||
|
||||
double latitude;
|
||||
double longitude;
|
||||
|
|
@ -128,6 +133,7 @@ public class NearbyPlaces {
|
|||
type, // details
|
||||
Uri.parse(icon),
|
||||
new LatLng(latitude, longitude, 0),
|
||||
category,
|
||||
new Sitelinks.Builder()
|
||||
.setWikipediaLink(wikipediaSitelink)
|
||||
.setCommonsLink(commonsSitelink)
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ public class Place {
|
|||
private final String longDescription;
|
||||
private final Uri secondaryImageUrl;
|
||||
public final LatLng location;
|
||||
private final String category;
|
||||
|
||||
public Bitmap image;
|
||||
public Bitmap secondaryImage;
|
||||
|
|
@ -25,12 +26,13 @@ public class Place {
|
|||
|
||||
|
||||
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.label = label;
|
||||
this.longDescription = longDescription;
|
||||
this.secondaryImageUrl = secondaryImageUrl;
|
||||
this.location = location;
|
||||
this.category = category;
|
||||
this.siteLinks = siteLinks;
|
||||
}
|
||||
|
||||
|
|
@ -42,6 +44,8 @@ public class Place {
|
|||
|
||||
public String getLongDescription() { return longDescription; }
|
||||
|
||||
public String getCategory() {return category; }
|
||||
|
||||
public void setDistance(String distance) {
|
||||
this.distance = distance;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ import butterknife.ButterKnife;
|
|||
import fr.free.nrw.commons.CommonsApplication;
|
||||
import fr.free.nrw.commons.R;
|
||||
import fr.free.nrw.commons.contributions.ContributionController;
|
||||
import fr.free.nrw.commons.di.ApplicationlessInjection;
|
||||
import timber.log.Timber;
|
||||
|
||||
public class PlaceRenderer extends Renderer<Place> {
|
||||
|
|
@ -124,8 +125,8 @@ public class PlaceRenderer extends Renderer<Place> {
|
|||
Timber.d("directPrefs stored");
|
||||
editor.putString("Title", place.getName());
|
||||
editor.putString("Desc", place.getLongDescription());
|
||||
editor.putString("Category", place.getCategory());
|
||||
editor.apply();
|
||||
|
||||
}
|
||||
|
||||
private void closeLayout(LinearLayout buttonLayout){
|
||||
|
|
@ -138,7 +139,8 @@ public class PlaceRenderer extends Renderer<Place> {
|
|||
|
||||
@Override
|
||||
public void render() {
|
||||
|
||||
ApplicationlessInjection.getInstance(getContext().getApplicationContext())
|
||||
.getCommonsApplicationComponent().inject(this);
|
||||
place = getContent();
|
||||
tvName.setText(place.name);
|
||||
String descriptionText = place.getLongDescription();
|
||||
|
|
|
|||
|
|
@ -114,6 +114,8 @@ public class SingleUploadFragment extends CommonsDaggerSupportFragment {
|
|||
if (isNearbyUpload) {
|
||||
String imageTitle = directPrefs.getString("Title", "");
|
||||
String imageDesc = directPrefs.getString("Desc", "");
|
||||
String imageCats = directPrefs.getString("Category", "");
|
||||
Timber.d("Image title: " + imageTitle + ", image desc: " + imageDesc + ", image categories: " + imageCats);
|
||||
titleEdit.setText(imageTitle);
|
||||
descEdit.setText(imageDesc);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ public class ImageUtils {
|
|||
|
||||
while ((checkImageRightPosition <= loadImageWidth) && (checkImageLeftPosition < checkImageRightPosition)) {
|
||||
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);
|
||||
totalDividedRectangles++;
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ SELECT
|
|||
(SAMPLE(COALESCE(?emoji0, ?emoji1)) as ?emoji)
|
||||
?wikipediaArticle
|
||||
?commonsArticle
|
||||
(SAMPLE(?Commons_category) as ?Commons_category)
|
||||
WHERE {
|
||||
# Around given location...
|
||||
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_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.
|
||||
OPTIONAL {
|
||||
?item p:P31/ps:P31 ?classId.
|
||||
|
|
@ -35,10 +39,6 @@ SELECT
|
|||
# Get emoji
|
||||
OPTIONAL { ?classId wdt:P487 ?emoji0. }
|
||||
OPTIONAL { ?classId wdt:P279*/wdt:P487 ?emoji1. }
|
||||
OPTIONAL {
|
||||
?sitelink schema:about ?item .
|
||||
?sitelink schema:inLanguage "en"
|
||||
}
|
||||
OPTIONAL {
|
||||
?wikipediaArticle schema:about ?item ;
|
||||
schema:isPartOf <https://en.wikipedia.org/> .
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue