mirror of
				https://github.com/commons-app/apps-android-commons.git
				synced 2025-10-31 14:53:59 +01:00 
			
		
		
		
	Dead/redundent code and import removal.
This commit is contained in:
		
							parent
							
								
									a9e62cb1ea
								
							
						
					
					
						commit
						1c43426579
					
				
					 9 changed files with 7 additions and 204 deletions
				
			
		|  | @ -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; | ||||
|  |  | |||
|  | @ -413,8 +413,8 @@ public class NearbyMapFragment extends android.support.v4.app.Fragment { | |||
| 
 | ||||
|         icon.setImageResource(place.getDescription().getIcon()); | ||||
|         description.setText(place.getDescription().getText()); | ||||
|         title.setText(place.name.toString()); | ||||
|         distance.setText(place.distance.toString()); | ||||
|         title.setText(place.name); | ||||
|         distance.setText(place.distance); | ||||
|     } | ||||
| 
 | ||||
|     private void openWebView(Uri link) { | ||||
|  |  | |||
|  | @ -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; | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Paul Hawke
						Paul Hawke