mirror of
				https://github.com/commons-app/apps-android-commons.git
				synced 2025-10-31 14:53:59 +01:00 
			
		
		
		
	Merge remote-tracking branch 'refs/remotes/commons-app/directNearbyUploads' into nearby-uploads
This commit is contained in:
		
						commit
						152fca30d3
					
				
					 11 changed files with 93 additions and 327 deletions
				
			
		|  | @ -1,6 +1,7 @@ | |||
| package fr.free.nrw.commons.location; | ||||
| 
 | ||||
| import android.location.Location; | ||||
| import android.net.Uri; | ||||
| import android.support.annotation.NonNull; | ||||
| 
 | ||||
| public class LatLng { | ||||
|  | @ -129,4 +130,8 @@ public class LatLng { | |||
|     public double getLatitude() { | ||||
|         return latitude; | ||||
|     } | ||||
| 
 | ||||
|     public Uri getGmmIntentUri() { | ||||
|         return Uri.parse("geo:0,0?q=" + latitude + "," + longitude); | ||||
|     } | ||||
| } | ||||
|  |  | |||
|  | @ -1,19 +1,15 @@ | |||
| package fr.free.nrw.commons.nearby; | ||||
| 
 | ||||
| import android.content.Intent; | ||||
| import android.content.SharedPreferences; | ||||
| import android.content.pm.PackageManager; | ||||
| import android.net.Uri; | ||||
| import android.os.Build; | ||||
| import android.os.Bundle; | ||||
| import android.preference.PreferenceManager; | ||||
| import android.support.annotation.NonNull; | ||||
| import android.support.design.widget.BottomSheetBehavior; | ||||
| import android.support.design.widget.FloatingActionButton; | ||||
| import android.support.v4.app.Fragment; | ||||
| import android.support.v4.app.FragmentTransaction; | ||||
| import android.support.v7.app.AlertDialog; | ||||
| import android.util.Log; | ||||
| import android.view.Menu; | ||||
| import android.view.MenuInflater; | ||||
| import android.view.MenuItem; | ||||
|  | @ -66,7 +62,6 @@ public class NearbyActivity extends NavigationBaseActivity implements LocationUp | |||
| 
 | ||||
|     private LatLng curLatLang; | ||||
|     private Bundle bundle; | ||||
|     private NearbyActivityMode viewMode; | ||||
|     private Disposable placesDisposable; | ||||
|     private boolean lockNearbyView; //Determines if the nearby places needs to be refreshed | ||||
|     private BottomSheetBehavior bottomSheetBehavior; // Behavior for list bottom sheet | ||||
|  | @ -325,7 +320,7 @@ public class NearbyActivity extends NavigationBaseActivity implements LocationUp | |||
| 
 | ||||
|         progressBar.setVisibility(View.VISIBLE); | ||||
|         placesDisposable = Observable.fromCallable(() -> nearbyController | ||||
|                 .loadAttractionsFromLocation(curLatLang, this)) | ||||
|                 .loadAttractionsFromLocation(curLatLang)) | ||||
|                 .subscribeOn(Schedulers.io()) | ||||
|                 .observeOn(AndroidSchedulers.mainThread()) | ||||
|                 .subscribe(this::populatePlaces); | ||||
|  |  | |||
|  | @ -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); | ||||
|     } | ||||
| } | ||||
|  | @ -1,7 +1,5 @@ | |||
| package fr.free.nrw.commons.nearby; | ||||
| 
 | ||||
| import android.support.annotation.NonNull; | ||||
| 
 | ||||
| import com.pedrogomez.renderers.ListAdapteeCollection; | ||||
| import com.pedrogomez.renderers.RVRendererAdapter; | ||||
| import com.pedrogomez.renderers.RendererBuilder; | ||||
|  | @ -19,7 +17,7 @@ class NearbyAdapterFactory { | |||
|         RendererBuilder<Place> builder = new RendererBuilder<Place>() | ||||
|                 .bind(Place.class, new PlaceRenderer()); | ||||
|         ListAdapteeCollection<Place> collection = new ListAdapteeCollection<>( | ||||
|                 placeList != null ? placeList : Collections.<Place>emptyList()); | ||||
|                 placeList != null ? placeList : Collections.emptyList()); | ||||
|         return new RVRendererAdapter<>(builder, collection); | ||||
|     } | ||||
| } | ||||
|  | @ -37,7 +37,7 @@ public class NearbyBaseMarker extends BaseMarkerOptions<NearbyMarker, NearbyBase | |||
|                 .registerTypeAdapter(Uri.class, new UriDeserializer()) | ||||
|                 .create(); | ||||
| 
 | ||||
|         position((LatLng) in.readParcelable(LatLng.class.getClassLoader())); | ||||
|         position(in.readParcelable(LatLng.class.getClassLoader())); | ||||
|         snippet(in.readString()); | ||||
|         String iconId = in.readString(); | ||||
|         Bitmap iconBitmap = in.readParcelable(Bitmap.class.getClassLoader()); | ||||
|  |  | |||
|  | @ -40,10 +40,9 @@ public class NearbyController { | |||
|     /** | ||||
|      * Prepares Place list to make their distance information update later. | ||||
|      * @param curLatLng current location for user | ||||
|      * @param context context | ||||
|      * @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); | ||||
|         if (curLatLng == null) { | ||||
|             return Collections.emptyList(); | ||||
|  |  | |||
|  | @ -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(); | ||||
|     } | ||||
| } | ||||
|  | @ -2,7 +2,6 @@ package fr.free.nrw.commons.nearby; | |||
| 
 | ||||
| import android.net.Uri; | ||||
| import android.os.Bundle; | ||||
| import android.support.v4.app.Fragment; | ||||
| import android.support.v7.widget.LinearLayoutManager; | ||||
| import android.support.v7.widget.RecyclerView; | ||||
| import android.view.LayoutInflater; | ||||
|  | @ -47,7 +46,7 @@ public class NearbyListFragment extends DaggerFragment { | |||
|                              Bundle savedInstanceState) { | ||||
|         Timber.d("NearbyListFragment created"); | ||||
|         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())); | ||||
|         adapterFactory = new NearbyAdapterFactory(); | ||||
|         return view; | ||||
|  |  | |||
|  | @ -126,25 +126,21 @@ public class NearbyMapFragment extends android.support.v4.app.Fragment { | |||
|         super.onViewCreated(view, savedInstanceState); | ||||
|         this.getView().setFocusableInTouchMode(true); | ||||
|         this.getView().requestFocus(); | ||||
|         this.getView().setOnKeyListener( new View.OnKeyListener() { | ||||
| 
 | ||||
|             @Override | ||||
|             public boolean onKey( View v, int keyCode, KeyEvent event) { | ||||
|                 if (keyCode == KeyEvent.KEYCODE_BACK) { | ||||
|                     if(bottomSheetDetailsBehavior.getState() == BottomSheetBehavior | ||||
|                             .STATE_EXPANDED) { | ||||
|                         bottomSheetDetailsBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED); | ||||
|                         return true; | ||||
|                     } | ||||
|                     else if (bottomSheetDetailsBehavior.getState() == BottomSheetBehavior | ||||
|                             .STATE_COLLAPSED) { | ||||
|                         bottomSheetDetailsBehavior.setState(BottomSheetBehavior.STATE_HIDDEN); | ||||
|                         return true; | ||||
|                     } | ||||
|         this.getView().setOnKeyListener((v, keyCode, event) -> { | ||||
|             if (keyCode == KeyEvent.KEYCODE_BACK) { | ||||
|                 if(bottomSheetDetailsBehavior.getState() == BottomSheetBehavior | ||||
|                         .STATE_EXPANDED) { | ||||
|                     bottomSheetDetailsBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED); | ||||
|                     return true; | ||||
|                 } | ||||
|                 else if (bottomSheetDetailsBehavior.getState() == BottomSheetBehavior | ||||
|                         .STATE_COLLAPSED) { | ||||
|                     bottomSheetDetailsBehavior.setState(BottomSheetBehavior.STATE_HIDDEN); | ||||
|                     return true; | ||||
|                 } | ||||
|                 return false; | ||||
|             } | ||||
|         } ); | ||||
|             return false; | ||||
|         }); | ||||
|     } | ||||
| 
 | ||||
|     private void initViews() { | ||||
|  | @ -183,22 +179,14 @@ public class NearbyMapFragment extends android.support.v4.app.Fragment { | |||
|     } | ||||
| 
 | ||||
|     private void setListeners() { | ||||
|         fabPlus.setOnClickListener(new View.OnClickListener() { | ||||
|             @Override | ||||
|             public void onClick(View view) { | ||||
|                 animateFAB(isFabOpen); | ||||
|             } | ||||
|         }); | ||||
|         fabPlus.setOnClickListener(view -> animateFAB(isFabOpen)); | ||||
| 
 | ||||
|         bottomSheetDetails.setOnClickListener(new View.OnClickListener() { | ||||
|             @Override | ||||
|             public void onClick(View view) { | ||||
|                 if(bottomSheetDetailsBehavior.getState() == BottomSheetBehavior.STATE_COLLAPSED) { | ||||
|                     bottomSheetDetailsBehavior.setState(BottomSheetBehavior.STATE_EXPANDED); | ||||
|                 } | ||||
|                 else{ | ||||
|                     bottomSheetDetailsBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED); | ||||
|                 } | ||||
|         bottomSheetDetails.setOnClickListener(view -> { | ||||
|             if(bottomSheetDetailsBehavior.getState() == BottomSheetBehavior.STATE_COLLAPSED) { | ||||
|                 bottomSheetDetailsBehavior.setState(BottomSheetBehavior.STATE_EXPANDED); | ||||
|             } | ||||
|             else{ | ||||
|                 bottomSheetDetailsBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED); | ||||
|             } | ||||
|         }); | ||||
| 
 | ||||
|  | @ -369,50 +357,25 @@ public class NearbyMapFragment extends android.support.v4.app.Fragment { | |||
| 
 | ||||
|     private void passInfoToSheet(Place place) { | ||||
|         this.place = place; | ||||
|         wikipediaButton.setEnabled( | ||||
|                 !(place.siteLinks == null || Uri.EMPTY.equals(place.siteLinks.getWikipediaLink()))); | ||||
|         wikipediaButton.setOnClickListener(new View.OnClickListener() { | ||||
|             @Override | ||||
|             public void onClick(View view) { | ||||
|                 openWebView(place.siteLinks.getWikipediaLink()); | ||||
|         wikipediaButton.setEnabled(place.hasWikipediaLink()); | ||||
|         wikipediaButton.setOnClickListener(view -> openWebView(place.siteLinks.getWikipediaLink())); | ||||
| 
 | ||||
|         wikidataButton.setEnabled(place.hasWikidataLink()); | ||||
|         wikidataButton.setOnClickListener(view -> openWebView(place.siteLinks.getWikidataLink())); | ||||
| 
 | ||||
|         directionsButton.setOnClickListener(view -> { | ||||
|             //Open map app at given position | ||||
|             Intent mapIntent = new Intent(Intent.ACTION_VIEW, place.location.getGmmIntentUri()); | ||||
|             if (mapIntent.resolveActivity(getActivity().getPackageManager()) != null) { | ||||
|                 startActivity(mapIntent); | ||||
|             } | ||||
|         }); | ||||
| 
 | ||||
|         wikidataButton.setEnabled( | ||||
|                 !(place.siteLinks == null || Uri.EMPTY.equals(place.siteLinks.getWikidataLink()))); | ||||
|         wikidataButton.setOnClickListener(new View.OnClickListener() { | ||||
|             @Override | ||||
|             public void onClick(View view) { | ||||
|                 openWebView(place.siteLinks.getWikidataLink()); | ||||
|             } | ||||
|         }); | ||||
| 
 | ||||
|         directionsButton.setOnClickListener(new View.OnClickListener() { | ||||
|             @Override | ||||
|             public void onClick(View view) { | ||||
|                 LatLng location = new LatLng(place.location.getLatitude() | ||||
|                         , place.location.getLongitude(), 0); | ||||
|                 //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); | ||||
|                 } | ||||
|             } | ||||
|         }); | ||||
| 
 | ||||
|         commonsButton.setEnabled( | ||||
|                 !(place.siteLinks == null || Uri.EMPTY.equals(place.siteLinks.getCommonsLink()))); | ||||
|         commonsButton.setOnClickListener(new View.OnClickListener() { | ||||
|             @Override | ||||
|             public void onClick(View view) { | ||||
|                 openWebView(place.siteLinks.getCommonsLink()); | ||||
|             } | ||||
|         }); | ||||
|         commonsButton.setEnabled(place.hasCommonsLink()); | ||||
|         commonsButton.setOnClickListener(view -> openWebView(place.siteLinks.getCommonsLink())); | ||||
| 
 | ||||
|         icon.setImageResource(place.getDescription().getIcon()); | ||||
| 
 | ||||
|         description.setText(place.getLongDescription()); | ||||
|         title.setText(place.name.toString()); | ||||
|         distance.setText(place.distance.toString()); | ||||
|  | @ -436,6 +399,7 @@ public class NearbyMapFragment extends android.support.v4.app.Fragment { | |||
|                 openWebView(place.siteLinks.getWikidataLink()); | ||||
|             } | ||||
|         }); | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
|     private void openWebView(Uri link) { | ||||
|  |  | |||
|  | @ -46,6 +46,18 @@ public class Place { | |||
|         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 | ||||
|     public boolean equals(Object o) { | ||||
|         if (o instanceof Place) { | ||||
|  |  | |||
|  | @ -2,19 +2,13 @@ package fr.free.nrw.commons.nearby; | |||
| 
 | ||||
| import android.content.Intent; | ||||
| import android.net.Uri; | ||||
| import android.os.CountDownTimer; | ||||
| import android.support.annotation.NonNull; | ||||
| import android.support.transition.TransitionManager; | ||||
| import android.support.v4.view.ViewCompat; | ||||
| import android.support.v7.widget.PopupMenu; | ||||
| import android.util.Log; | ||||
| import android.view.LayoutInflater; | ||||
| import android.view.MenuItem; | ||||
| import android.view.View; | ||||
| 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.LinearLayout; | ||||
| import android.widget.TextView; | ||||
|  | @ -67,30 +61,24 @@ class PlaceRenderer extends Renderer<Place> { | |||
|     @Override | ||||
|     protected void hookListeners(View view) { | ||||
| 
 | ||||
|         final View.OnClickListener listener = new View.OnClickListener() { | ||||
|             @Override | ||||
|             public void onClick(View view) { | ||||
|                 Log.d("Renderer", "clicked"); | ||||
|                 TransitionManager.beginDelayedTransition(buttonLayout); | ||||
| 
 | ||||
|                 if(buttonLayout.isShown()){ | ||||
|                     closeLayout(buttonLayout); | ||||
|                 }else { | ||||
|                     openLayout(buttonLayout); | ||||
|                 } | ||||
|         final View.OnClickListener listener = view12 -> { | ||||
|             Log.d("Renderer", "clicked"); | ||||
|             TransitionManager.beginDelayedTransition(buttonLayout); | ||||
| 
 | ||||
|             if(buttonLayout.isShown()){ | ||||
|                 closeLayout(buttonLayout); | ||||
|             }else { | ||||
|                 openLayout(buttonLayout); | ||||
|             } | ||||
| 
 | ||||
|         }; | ||||
|         view.setOnClickListener(listener); | ||||
|         view.requestFocus(); | ||||
|         view.setOnFocusChangeListener(new View.OnFocusChangeListener() { | ||||
|             @Override | ||||
|             public void onFocusChange(View view, boolean hasFocus) { | ||||
|                 if(!hasFocus && buttonLayout.isShown()){ | ||||
|                     closeLayout(buttonLayout); | ||||
|                 }else if(hasFocus && !buttonLayout.isShown()) { | ||||
|                     listener.onClick(view); | ||||
|                 } | ||||
|         view.setOnFocusChangeListener((view1, hasFocus) -> { | ||||
|             if (!hasFocus && buttonLayout.isShown()) { | ||||
|                 closeLayout(buttonLayout); | ||||
|             } else if (hasFocus && !buttonLayout.isShown()) { | ||||
|                 listener.onClick(view1); | ||||
|             } | ||||
|         }); | ||||
| 
 | ||||
|  | @ -116,19 +104,11 @@ class PlaceRenderer extends Renderer<Place> { | |||
|         distance.setText(place.distance); | ||||
|         icon.setImageResource(place.getDescription().getIcon()); | ||||
| 
 | ||||
|         directionsButton.setOnClickListener(new View.OnClickListener() { | ||||
|             @Override | ||||
|             public void onClick(View view) { | ||||
|                 LatLng location = new LatLng(place.location.getLatitude() | ||||
|                         , place.location.getLongitude(), 0); | ||||
|                 //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(view.getContext().getPackageManager()) != null) { | ||||
|                     view.getContext().startActivity(mapIntent); | ||||
|                 } | ||||
|         directionsButton.setOnClickListener(view -> { | ||||
|             //Open map app at given position | ||||
|             Intent mapIntent = new Intent(Intent.ACTION_VIEW, place.location.getGmmIntentUri()); | ||||
|             if (mapIntent.resolveActivity(view.getContext().getPackageManager()) != null) { | ||||
|                 view.getContext().startActivity(mapIntent); | ||||
|             } | ||||
|         }); | ||||
| 
 | ||||
|  | @ -147,28 +127,25 @@ class PlaceRenderer extends Renderer<Place> { | |||
|         MenuItem wikipediaArticle = popupMenu.getMenu() | ||||
|                 .findItem(R.id.nearby_info_menu_wikipedia_article); | ||||
| 
 | ||||
|         commonsArticle.setEnabled(!place.siteLinks.getCommonsLink().equals(Uri.EMPTY)); | ||||
|         wikiDataArticle.setEnabled(!place.siteLinks.getWikidataLink().equals(Uri.EMPTY)); | ||||
|         wikipediaArticle.setEnabled(!place.siteLinks.getWikipediaLink().equals(Uri.EMPTY)); | ||||
|         commonsArticle.setEnabled(place.hasCommonsLink()); | ||||
|         wikiDataArticle.setEnabled(place.hasWikidataLink()); | ||||
|         wikipediaArticle.setEnabled(place.hasWikipediaLink()); | ||||
| 
 | ||||
|         popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { | ||||
|             @Override | ||||
|             public boolean onMenuItemClick(MenuItem item) { | ||||
|                 switch (item.getItemId()) { | ||||
|                     case R.id.nearby_info_menu_commons_article: | ||||
|                         openWebView(place.siteLinks.getCommonsLink()); | ||||
|                         return true; | ||||
|                     case R.id.nearby_info_menu_wikidata_article: | ||||
|                         openWebView(place.siteLinks.getWikidataLink()); | ||||
|                         return true; | ||||
|                     case R.id.nearby_info_menu_wikipedia_article: | ||||
|                         openWebView(place.siteLinks.getWikipediaLink()); | ||||
|                         return true; | ||||
|                     default: | ||||
|                         break; | ||||
|                 } | ||||
|                 return false; | ||||
|         popupMenu.setOnMenuItemClickListener(item -> { | ||||
|             switch (item.getItemId()) { | ||||
|                 case R.id.nearby_info_menu_commons_article: | ||||
|                     openWebView(place.siteLinks.getCommonsLink()); | ||||
|                     return true; | ||||
|                 case R.id.nearby_info_menu_wikidata_article: | ||||
|                     openWebView(place.siteLinks.getWikidataLink()); | ||||
|                     return true; | ||||
|                 case R.id.nearby_info_menu_wikipedia_article: | ||||
|                     openWebView(place.siteLinks.getWikipediaLink()); | ||||
|                     return true; | ||||
|                 default: | ||||
|                     break; | ||||
|             } | ||||
|             return false; | ||||
|         }); | ||||
|         popupMenu.show(); | ||||
|     } | ||||
|  | @ -179,8 +156,7 @@ class PlaceRenderer extends Renderer<Place> { | |||
|     } | ||||
| 
 | ||||
|     private boolean showMenu() { | ||||
|         return !place.siteLinks.getCommonsLink().equals(Uri.EMPTY) | ||||
|                 || !place.siteLinks.getWikidataLink().equals(Uri.EMPTY); | ||||
|         return place.hasCommonsLink() || place.hasWikidataLink(); | ||||
|     } | ||||
| 
 | ||||
| } | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 misaochan
						misaochan