Merge remote-tracking branch 'refs/remotes/commons-app/directNearbyUploads' into nearby-uploads

This commit is contained in:
misaochan 2017-12-31 01:01:44 +10:00
commit 152fca30d3
11 changed files with 93 additions and 327 deletions

View file

@ -1,6 +1,7 @@
package fr.free.nrw.commons.location; package fr.free.nrw.commons.location;
import android.location.Location; import android.location.Location;
import android.net.Uri;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
public class LatLng { public class LatLng {
@ -129,4 +130,8 @@ public class LatLng {
public double getLatitude() { public double getLatitude() {
return latitude; return latitude;
} }
public Uri getGmmIntentUri() {
return Uri.parse("geo:0,0?q=" + latitude + "," + longitude);
}
} }

View file

@ -1,19 +1,15 @@
package fr.free.nrw.commons.nearby; package fr.free.nrw.commons.nearby;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.design.widget.BottomSheetBehavior; import android.support.design.widget.BottomSheetBehavior;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction; import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.util.Log;
import android.view.Menu; import android.view.Menu;
import android.view.MenuInflater; import android.view.MenuInflater;
import android.view.MenuItem; import android.view.MenuItem;
@ -66,7 +62,6 @@ public class NearbyActivity extends NavigationBaseActivity implements LocationUp
private LatLng curLatLang; private LatLng curLatLang;
private Bundle bundle; private Bundle bundle;
private NearbyActivityMode viewMode;
private Disposable placesDisposable; private Disposable placesDisposable;
private boolean lockNearbyView; //Determines if the nearby places needs to be refreshed private boolean lockNearbyView; //Determines if the nearby places needs to be refreshed
private BottomSheetBehavior bottomSheetBehavior; // Behavior for list bottom sheet private BottomSheetBehavior bottomSheetBehavior; // Behavior for list bottom sheet
@ -325,7 +320,7 @@ public class NearbyActivity extends NavigationBaseActivity implements LocationUp
progressBar.setVisibility(View.VISIBLE); progressBar.setVisibility(View.VISIBLE);
placesDisposable = Observable.fromCallable(() -> nearbyController placesDisposable = Observable.fromCallable(() -> nearbyController
.loadAttractionsFromLocation(curLatLang, this)) .loadAttractionsFromLocation(curLatLang))
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(this::populatePlaces); .subscribe(this::populatePlaces);

View file

@ -1,30 +0,0 @@
package fr.free.nrw.commons.nearby;
import android.support.annotation.DrawableRes;
import fr.free.nrw.commons.R;
enum NearbyActivityMode {
MAP(R.drawable.ic_list_white_24dp),
LIST(R.drawable.ic_map_white_24dp);
@DrawableRes
private final int icon;
NearbyActivityMode(int icon) {
this.icon = icon;
}
@DrawableRes
public int getIcon() {
return icon;
}
public NearbyActivityMode toggle() {
return isMap() ? LIST : MAP;
}
public boolean isMap() {
return MAP.equals(this);
}
}

View file

@ -1,7 +1,5 @@
package fr.free.nrw.commons.nearby; package fr.free.nrw.commons.nearby;
import android.support.annotation.NonNull;
import com.pedrogomez.renderers.ListAdapteeCollection; import com.pedrogomez.renderers.ListAdapteeCollection;
import com.pedrogomez.renderers.RVRendererAdapter; import com.pedrogomez.renderers.RVRendererAdapter;
import com.pedrogomez.renderers.RendererBuilder; import com.pedrogomez.renderers.RendererBuilder;
@ -19,7 +17,7 @@ class NearbyAdapterFactory {
RendererBuilder<Place> builder = new RendererBuilder<Place>() RendererBuilder<Place> builder = new RendererBuilder<Place>()
.bind(Place.class, new PlaceRenderer()); .bind(Place.class, new PlaceRenderer());
ListAdapteeCollection<Place> collection = new ListAdapteeCollection<>( ListAdapteeCollection<Place> collection = new ListAdapteeCollection<>(
placeList != null ? placeList : Collections.<Place>emptyList()); placeList != null ? placeList : Collections.emptyList());
return new RVRendererAdapter<>(builder, collection); return new RVRendererAdapter<>(builder, collection);
} }
} }

View file

@ -37,7 +37,7 @@ public class NearbyBaseMarker extends BaseMarkerOptions<NearbyMarker, NearbyBase
.registerTypeAdapter(Uri.class, new UriDeserializer()) .registerTypeAdapter(Uri.class, new UriDeserializer())
.create(); .create();
position((LatLng) in.readParcelable(LatLng.class.getClassLoader())); position(in.readParcelable(LatLng.class.getClassLoader()));
snippet(in.readString()); snippet(in.readString());
String iconId = in.readString(); String iconId = in.readString();
Bitmap iconBitmap = in.readParcelable(Bitmap.class.getClassLoader()); Bitmap iconBitmap = in.readParcelable(Bitmap.class.getClassLoader());

View file

@ -40,10 +40,9 @@ public class NearbyController {
/** /**
* Prepares Place list to make their distance information update later. * Prepares Place list to make their distance information update later.
* @param curLatLng current location for user * @param curLatLng current location for user
* @param context context
* @return Place list without distance information * @return Place list without distance information
*/ */
public List<Place> loadAttractionsFromLocation(LatLng curLatLng, Context context) { public List<Place> loadAttractionsFromLocation(LatLng curLatLng) {
Timber.d("Loading attractions near %s", curLatLng); Timber.d("Loading attractions near %s", curLatLng);
if (curLatLng == null) { if (curLatLng == null) {
return Collections.emptyList(); return Collections.emptyList();

View file

@ -1,152 +0,0 @@
package fr.free.nrw.commons.nearby;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v7.widget.PopupMenu;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;
import fr.free.nrw.commons.R;
import fr.free.nrw.commons.location.LatLng;
import fr.free.nrw.commons.ui.widget.OverlayDialog;
import fr.free.nrw.commons.utils.DialogUtil;
public class NearbyInfoDialog extends OverlayDialog {
private final static String ARG_TITLE = "placeTitle";
private final static String ARG_DESC = "placeDesc";
private final static String ARG_LATITUDE = "latitude";
private final static String ARG_LONGITUDE = "longitude";
private final static String ARG_SITE_LINK = "sitelink";
@BindView(R.id.link_preview_title) TextView placeTitle;
@BindView(R.id.link_preview_extract) TextView placeDescription;
@BindView(R.id.link_preview_go_button) TextView goToButton;
@BindView(R.id.link_preview_overflow_button) ImageView overflowButton;
private Unbinder unbinder;
private LatLng location;
private Sitelinks sitelinks;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.dialog_nearby_info, container, false);
unbinder = ButterKnife.bind(this, view);
initUi();
return view;
}
private void initUi() {
Bundle bundle = getArguments();
placeTitle.setText(bundle.getString(ARG_TITLE));
placeDescription.setText(bundle.getString(ARG_DESC));
location = new LatLng(bundle.getDouble(ARG_LATITUDE), bundle.getDouble(ARG_LONGITUDE), 0);
getArticleLink(bundle);
}
private void getArticleLink(Bundle bundle) {
this.sitelinks = bundle.getParcelable(ARG_SITE_LINK);
if (sitelinks == null || Uri.EMPTY.equals(sitelinks.getWikipediaLink())) {
goToButton.setVisibility(View.GONE);
}
overflowButton.setVisibility(showMenu() ? View.VISIBLE : View.GONE);
overflowButton.setOnClickListener(v -> popupMenuListener());
}
private void popupMenuListener() {
PopupMenu popupMenu = new PopupMenu(getActivity(), overflowButton);
popupMenu.inflate(R.menu.nearby_info_dialog_options);
MenuItem commonsArticle = popupMenu.getMenu()
.findItem(R.id.nearby_info_menu_commons_article);
MenuItem wikiDataArticle = popupMenu.getMenu()
.findItem(R.id.nearby_info_menu_wikidata_article);
commonsArticle.setEnabled(!sitelinks.getCommonsLink().equals(Uri.EMPTY));
wikiDataArticle.setEnabled(!sitelinks.getWikidataLink().equals(Uri.EMPTY));
popupMenu.setOnMenuItemClickListener(menuListener);
popupMenu.show();
}
private boolean showMenu() {
return !sitelinks.getCommonsLink().equals(Uri.EMPTY)
|| !sitelinks.getWikidataLink().equals(Uri.EMPTY);
}
private final PopupMenu.OnMenuItemClickListener menuListener = new PopupMenu
.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()) {
case R.id.nearby_info_menu_commons_article:
openWebView(sitelinks.getCommonsLink());
return true;
case R.id.nearby_info_menu_wikidata_article:
openWebView(sitelinks.getWikidataLink());
return true;
default:
break;
}
return false;
}
};
public static void showYourself(FragmentActivity fragmentActivity, Place place) {
NearbyInfoDialog mDialog = new NearbyInfoDialog();
Bundle bundle = new Bundle();
bundle.putString(ARG_TITLE, place.name);
bundle.putString(ARG_DESC, place.getDescription().getText());
bundle.putDouble(ARG_LATITUDE, place.location.getLatitude());
bundle.putDouble(ARG_LONGITUDE, place.location.getLongitude());
bundle.putParcelable(ARG_SITE_LINK, place.siteLinks);
mDialog.setArguments(bundle);
DialogUtil.showSafely(fragmentActivity, mDialog);
}
@Override
public void onDestroyView() {
super.onDestroyView();
unbinder.unbind();
}
@OnClick(R.id.link_preview_directions_button)
void onDirectionsClick() {
//Open map app at given position
Uri gmmIntentUri = Uri.parse(
"geo:0,0?q=" + location.getLatitude() + "," + location.getLongitude());
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
if (mapIntent.resolveActivity(getActivity().getPackageManager()) != null) {
startActivity(mapIntent);
}
}
@OnClick(R.id.link_preview_go_button)
void onReadArticleClick() {
openWebView(sitelinks.getWikipediaLink());
}
private void openWebView(Uri link) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, link);
startActivity(browserIntent);
}
@OnClick(R.id.emptyLayout)
void onCloseClicked() {
dismissAllowingStateLoss();
}
}

View file

@ -2,7 +2,6 @@ package fr.free.nrw.commons.nearby;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater; import android.view.LayoutInflater;
@ -47,7 +46,7 @@ public class NearbyListFragment extends DaggerFragment {
Bundle savedInstanceState) { Bundle savedInstanceState) {
Timber.d("NearbyListFragment created"); Timber.d("NearbyListFragment created");
View view = inflater.inflate(R.layout.fragment_nearby, container, false); View view = inflater.inflate(R.layout.fragment_nearby, container, false);
recyclerView = (RecyclerView) view.findViewById(R.id.listView); recyclerView = view.findViewById(R.id.listView);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
adapterFactory = new NearbyAdapterFactory(); adapterFactory = new NearbyAdapterFactory();
return view; return view;

View file

@ -126,10 +126,7 @@ public class NearbyMapFragment extends android.support.v4.app.Fragment {
super.onViewCreated(view, savedInstanceState); super.onViewCreated(view, savedInstanceState);
this.getView().setFocusableInTouchMode(true); this.getView().setFocusableInTouchMode(true);
this.getView().requestFocus(); this.getView().requestFocus();
this.getView().setOnKeyListener( new View.OnKeyListener() { this.getView().setOnKeyListener((v, keyCode, event) -> {
@Override
public boolean onKey( View v, int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) { if (keyCode == KeyEvent.KEYCODE_BACK) {
if(bottomSheetDetailsBehavior.getState() == BottomSheetBehavior if(bottomSheetDetailsBehavior.getState() == BottomSheetBehavior
.STATE_EXPANDED) { .STATE_EXPANDED) {
@ -143,7 +140,6 @@ public class NearbyMapFragment extends android.support.v4.app.Fragment {
} }
} }
return false; return false;
}
}); });
} }
@ -183,23 +179,15 @@ public class NearbyMapFragment extends android.support.v4.app.Fragment {
} }
private void setListeners() { private void setListeners() {
fabPlus.setOnClickListener(new View.OnClickListener() { fabPlus.setOnClickListener(view -> animateFAB(isFabOpen));
@Override
public void onClick(View view) {
animateFAB(isFabOpen);
}
});
bottomSheetDetails.setOnClickListener(new View.OnClickListener() { bottomSheetDetails.setOnClickListener(view -> {
@Override
public void onClick(View view) {
if(bottomSheetDetailsBehavior.getState() == BottomSheetBehavior.STATE_COLLAPSED) { if(bottomSheetDetailsBehavior.getState() == BottomSheetBehavior.STATE_COLLAPSED) {
bottomSheetDetailsBehavior.setState(BottomSheetBehavior.STATE_EXPANDED); bottomSheetDetailsBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
} }
else{ else{
bottomSheetDetailsBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED); bottomSheetDetailsBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
} }
}
}); });
bottomSheetDetailsBehavior.setBottomSheetCallback(new BottomSheetBehavior bottomSheetDetailsBehavior.setBottomSheetCallback(new BottomSheetBehavior
@ -369,50 +357,25 @@ public class NearbyMapFragment extends android.support.v4.app.Fragment {
private void passInfoToSheet(Place place) { private void passInfoToSheet(Place place) {
this.place = place; this.place = place;
wikipediaButton.setEnabled( wikipediaButton.setEnabled(place.hasWikipediaLink());
!(place.siteLinks == null || Uri.EMPTY.equals(place.siteLinks.getWikipediaLink()))); wikipediaButton.setOnClickListener(view -> openWebView(place.siteLinks.getWikipediaLink()));
wikipediaButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
openWebView(place.siteLinks.getWikipediaLink());
}
});
wikidataButton.setEnabled( wikidataButton.setEnabled(place.hasWikidataLink());
!(place.siteLinks == null || Uri.EMPTY.equals(place.siteLinks.getWikidataLink()))); wikidataButton.setOnClickListener(view -> openWebView(place.siteLinks.getWikidataLink()));
wikidataButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
openWebView(place.siteLinks.getWikidataLink());
}
});
directionsButton.setOnClickListener(new View.OnClickListener() { directionsButton.setOnClickListener(view -> {
@Override
public void onClick(View view) {
LatLng location = new LatLng(place.location.getLatitude()
, place.location.getLongitude(), 0);
//Open map app at given position //Open map app at given position
Uri gmmIntentUri = Uri.parse( Intent mapIntent = new Intent(Intent.ACTION_VIEW, place.location.getGmmIntentUri());
"geo:0,0?q=" + location.getLatitude() + "," + location.getLongitude());
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
if (mapIntent.resolveActivity(getActivity().getPackageManager()) != null) { if (mapIntent.resolveActivity(getActivity().getPackageManager()) != null) {
startActivity(mapIntent); startActivity(mapIntent);
} }
}
}); });
commonsButton.setEnabled( commonsButton.setEnabled(place.hasCommonsLink());
!(place.siteLinks == null || Uri.EMPTY.equals(place.siteLinks.getCommonsLink()))); commonsButton.setOnClickListener(view -> openWebView(place.siteLinks.getCommonsLink()));
commonsButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
openWebView(place.siteLinks.getCommonsLink());
}
});
icon.setImageResource(place.getDescription().getIcon()); icon.setImageResource(place.getDescription().getIcon());
description.setText(place.getLongDescription()); description.setText(place.getLongDescription());
title.setText(place.name.toString()); title.setText(place.name.toString());
distance.setText(place.distance.toString()); distance.setText(place.distance.toString());
@ -436,6 +399,7 @@ public class NearbyMapFragment extends android.support.v4.app.Fragment {
openWebView(place.siteLinks.getWikidataLink()); openWebView(place.siteLinks.getWikidataLink());
} }
}); });
} }
private void openWebView(Uri link) { private void openWebView(Uri link) {

View file

@ -46,6 +46,18 @@ public class Place {
this.distance = distance; this.distance = distance;
} }
public boolean hasWikipediaLink() {
return !(siteLinks == null || Uri.EMPTY.equals(siteLinks.getWikipediaLink()));
}
public boolean hasWikidataLink() {
return !(siteLinks == null || Uri.EMPTY.equals(siteLinks.getWikidataLink()));
}
public boolean hasCommonsLink() {
return !(siteLinks == null || Uri.EMPTY.equals(siteLinks.getCommonsLink()));
}
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (o instanceof Place) { if (o instanceof Place) {

View file

@ -2,19 +2,13 @@ package fr.free.nrw.commons.nearby;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.os.CountDownTimer;
import android.support.annotation.NonNull;
import android.support.transition.TransitionManager; import android.support.transition.TransitionManager;
import android.support.v4.view.ViewCompat;
import android.support.v7.widget.PopupMenu; import android.support.v7.widget.PopupMenu;
import android.util.Log; import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
@ -67,9 +61,7 @@ class PlaceRenderer extends Renderer<Place> {
@Override @Override
protected void hookListeners(View view) { protected void hookListeners(View view) {
final View.OnClickListener listener = new View.OnClickListener() { final View.OnClickListener listener = view12 -> {
@Override
public void onClick(View view) {
Log.d("Renderer", "clicked"); Log.d("Renderer", "clicked");
TransitionManager.beginDelayedTransition(buttonLayout); TransitionManager.beginDelayedTransition(buttonLayout);
@ -79,18 +71,14 @@ class PlaceRenderer extends Renderer<Place> {
openLayout(buttonLayout); openLayout(buttonLayout);
} }
}
}; };
view.setOnClickListener(listener); view.setOnClickListener(listener);
view.requestFocus(); view.requestFocus();
view.setOnFocusChangeListener(new View.OnFocusChangeListener() { view.setOnFocusChangeListener((view1, hasFocus) -> {
@Override
public void onFocusChange(View view, boolean hasFocus) {
if (!hasFocus && buttonLayout.isShown()) { if (!hasFocus && buttonLayout.isShown()) {
closeLayout(buttonLayout); closeLayout(buttonLayout);
} else if (hasFocus && !buttonLayout.isShown()) { } else if (hasFocus && !buttonLayout.isShown()) {
listener.onClick(view); listener.onClick(view1);
}
} }
}); });
@ -116,20 +104,12 @@ class PlaceRenderer extends Renderer<Place> {
distance.setText(place.distance); distance.setText(place.distance);
icon.setImageResource(place.getDescription().getIcon()); icon.setImageResource(place.getDescription().getIcon());
directionsButton.setOnClickListener(new View.OnClickListener() { directionsButton.setOnClickListener(view -> {
@Override
public void onClick(View view) {
LatLng location = new LatLng(place.location.getLatitude()
, place.location.getLongitude(), 0);
//Open map app at given position //Open map app at given position
Uri gmmIntentUri = Uri.parse( Intent mapIntent = new Intent(Intent.ACTION_VIEW, place.location.getGmmIntentUri());
"geo:0,0?q=" + location.getLatitude() + "," + location.getLongitude());
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
if (mapIntent.resolveActivity(view.getContext().getPackageManager()) != null) { if (mapIntent.resolveActivity(view.getContext().getPackageManager()) != null) {
view.getContext().startActivity(mapIntent); view.getContext().startActivity(mapIntent);
} }
}
}); });
iconOverflow.setVisibility(showMenu() ? View.VISIBLE : View.GONE); iconOverflow.setVisibility(showMenu() ? View.VISIBLE : View.GONE);
@ -147,13 +127,11 @@ class PlaceRenderer extends Renderer<Place> {
MenuItem wikipediaArticle = popupMenu.getMenu() MenuItem wikipediaArticle = popupMenu.getMenu()
.findItem(R.id.nearby_info_menu_wikipedia_article); .findItem(R.id.nearby_info_menu_wikipedia_article);
commonsArticle.setEnabled(!place.siteLinks.getCommonsLink().equals(Uri.EMPTY)); commonsArticle.setEnabled(place.hasCommonsLink());
wikiDataArticle.setEnabled(!place.siteLinks.getWikidataLink().equals(Uri.EMPTY)); wikiDataArticle.setEnabled(place.hasWikidataLink());
wikipediaArticle.setEnabled(!place.siteLinks.getWikipediaLink().equals(Uri.EMPTY)); wikipediaArticle.setEnabled(place.hasWikipediaLink());
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { popupMenu.setOnMenuItemClickListener(item -> {
@Override
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()) { switch (item.getItemId()) {
case R.id.nearby_info_menu_commons_article: case R.id.nearby_info_menu_commons_article:
openWebView(place.siteLinks.getCommonsLink()); openWebView(place.siteLinks.getCommonsLink());
@ -168,7 +146,6 @@ class PlaceRenderer extends Renderer<Place> {
break; break;
} }
return false; return false;
}
}); });
popupMenu.show(); popupMenu.show();
} }
@ -179,8 +156,7 @@ class PlaceRenderer extends Renderer<Place> {
} }
private boolean showMenu() { private boolean showMenu() {
return !place.siteLinks.getCommonsLink().equals(Uri.EMPTY) return place.hasCommonsLink() || place.hasWikidataLink();
|| !place.siteLinks.getWikidataLink().equals(Uri.EMPTY);
} }
} }