mirror of
				https://github.com/commons-app/apps-android-commons.git
				synced 2025-10-30 22:34:02 +01:00 
			
		
		
		
	Merge remote-tracking branch 'upstream/master'
This commit is contained in:
		
						commit
						c3649d3efd
					
				
					 18 changed files with 309 additions and 210 deletions
				
			
		|  | @ -10,7 +10,6 @@ import android.net.Uri; | |||
| import android.text.TextUtils; | ||||
| 
 | ||||
| import fr.free.nrw.commons.CommonsApplication; | ||||
| import fr.free.nrw.commons.data.DBOpenHelper; | ||||
| import timber.log.Timber; | ||||
| 
 | ||||
| public class ContributionsContentProvider extends ContentProvider{ | ||||
|  | @ -33,10 +32,8 @@ public class ContributionsContentProvider extends ContentProvider{ | |||
|         return Uri.parse(BASE_URI.toString() + "/" + id); | ||||
|     } | ||||
| 
 | ||||
|     private DBOpenHelper dbOpenHelper; | ||||
|     @Override | ||||
|     public boolean onCreate() { | ||||
|         dbOpenHelper = CommonsApplication.getInstance().getDBOpenHelper(); | ||||
|         return false; | ||||
|     } | ||||
| 
 | ||||
|  | @ -47,7 +44,7 @@ public class ContributionsContentProvider extends ContentProvider{ | |||
| 
 | ||||
|         int uriType = uriMatcher.match(uri); | ||||
| 
 | ||||
|         SQLiteDatabase db = dbOpenHelper.getReadableDatabase(); | ||||
|         SQLiteDatabase db = CommonsApplication.getInstance().getDBOpenHelper().getReadableDatabase(); | ||||
|         Cursor cursor; | ||||
| 
 | ||||
|         switch(uriType) { | ||||
|  | @ -81,7 +78,7 @@ public class ContributionsContentProvider extends ContentProvider{ | |||
|     @Override | ||||
|     public Uri insert(Uri uri, ContentValues contentValues) { | ||||
|         int uriType = uriMatcher.match(uri); | ||||
|         SQLiteDatabase sqlDB = dbOpenHelper.getWritableDatabase(); | ||||
|         SQLiteDatabase sqlDB = CommonsApplication.getInstance().getDBOpenHelper().getWritableDatabase(); | ||||
|         long id = 0; | ||||
|         switch (uriType) { | ||||
|             case CONTRIBUTIONS: | ||||
|  | @ -99,7 +96,7 @@ public class ContributionsContentProvider extends ContentProvider{ | |||
|         int rows = 0; | ||||
|         int uriType = uriMatcher.match(uri); | ||||
| 
 | ||||
|         SQLiteDatabase db = dbOpenHelper.getReadableDatabase(); | ||||
|         SQLiteDatabase db = CommonsApplication.getInstance().getDBOpenHelper().getReadableDatabase(); | ||||
| 
 | ||||
|         switch(uriType) { | ||||
|             case CONTRIBUTIONS_ID: | ||||
|  | @ -120,7 +117,7 @@ public class ContributionsContentProvider extends ContentProvider{ | |||
|     public int bulkInsert(Uri uri, ContentValues[] values) { | ||||
|         Timber.d("Hello, bulk insert! (ContributionsContentProvider)"); | ||||
|         int uriType = uriMatcher.match(uri); | ||||
|         SQLiteDatabase sqlDB = dbOpenHelper.getWritableDatabase(); | ||||
|         SQLiteDatabase sqlDB = CommonsApplication.getInstance().getDBOpenHelper().getWritableDatabase(); | ||||
|         sqlDB.beginTransaction(); | ||||
|         switch (uriType) { | ||||
|             case CONTRIBUTIONS: | ||||
|  | @ -148,7 +145,7 @@ public class ContributionsContentProvider extends ContentProvider{ | |||
|         In here, the only concat created argument is for id. It is cast to an int, and will error out otherwise. | ||||
|          */ | ||||
|         int uriType = uriMatcher.match(uri); | ||||
|         SQLiteDatabase sqlDB = dbOpenHelper.getWritableDatabase(); | ||||
|         SQLiteDatabase sqlDB = CommonsApplication.getInstance().getDBOpenHelper().getWritableDatabase(); | ||||
|         int rowsUpdated = 0; | ||||
|         switch (uriType) { | ||||
|             case CONTRIBUTIONS: | ||||
|  |  | |||
|  | @ -10,7 +10,6 @@ import android.net.Uri; | |||
| import android.text.TextUtils; | ||||
| 
 | ||||
| import fr.free.nrw.commons.CommonsApplication; | ||||
| import fr.free.nrw.commons.data.DBOpenHelper; | ||||
| import timber.log.Timber; | ||||
| 
 | ||||
| public class ModificationsContentProvider extends ContentProvider{ | ||||
|  | @ -33,10 +32,9 @@ public class ModificationsContentProvider extends ContentProvider{ | |||
|         return Uri.parse(BASE_URI.toString() + "/" + id); | ||||
|     } | ||||
| 
 | ||||
|     private DBOpenHelper dbOpenHelper; | ||||
| 
 | ||||
|     @Override | ||||
|     public boolean onCreate() { | ||||
|         dbOpenHelper = CommonsApplication.getInstance().getDBOpenHelper(); | ||||
|         return false; | ||||
|     } | ||||
| 
 | ||||
|  | @ -54,7 +52,7 @@ public class ModificationsContentProvider extends ContentProvider{ | |||
|                 throw new IllegalArgumentException("Unknown URI" + uri); | ||||
|         } | ||||
| 
 | ||||
|         SQLiteDatabase db = dbOpenHelper.getReadableDatabase(); | ||||
|         SQLiteDatabase db = CommonsApplication.getInstance().getDBOpenHelper().getReadableDatabase(); | ||||
| 
 | ||||
|         Cursor cursor = queryBuilder.query(db, projection, selection, selectionArgs, null, null, sortOrder); | ||||
|         cursor.setNotificationUri(getContext().getContentResolver(), uri); | ||||
|  | @ -70,7 +68,7 @@ public class ModificationsContentProvider extends ContentProvider{ | |||
|     @Override | ||||
|     public Uri insert(Uri uri, ContentValues contentValues) { | ||||
|         int uriType = uriMatcher.match(uri); | ||||
|         SQLiteDatabase sqlDB = dbOpenHelper.getWritableDatabase(); | ||||
|         SQLiteDatabase sqlDB = CommonsApplication.getInstance().getDBOpenHelper().getWritableDatabase(); | ||||
|         long id = 0; | ||||
|         switch (uriType) { | ||||
|             case MODIFICATIONS: | ||||
|  | @ -86,7 +84,7 @@ public class ModificationsContentProvider extends ContentProvider{ | |||
|     @Override | ||||
|     public int delete(Uri uri, String s, String[] strings) { | ||||
|         int uriType = uriMatcher.match(uri); | ||||
|         SQLiteDatabase sqlDB = dbOpenHelper.getWritableDatabase(); | ||||
|         SQLiteDatabase sqlDB = CommonsApplication.getInstance().getDBOpenHelper().getWritableDatabase(); | ||||
|         switch (uriType) { | ||||
|             case MODIFICATIONS_ID: | ||||
|                 String id = uri.getLastPathSegment(); | ||||
|  | @ -104,7 +102,7 @@ public class ModificationsContentProvider extends ContentProvider{ | |||
|     public int bulkInsert(Uri uri, ContentValues[] values) { | ||||
|         Timber.d("Hello, bulk insert! (ModificationsContentProvider)"); | ||||
|         int uriType = uriMatcher.match(uri); | ||||
|         SQLiteDatabase sqlDB = dbOpenHelper.getWritableDatabase(); | ||||
|         SQLiteDatabase sqlDB = CommonsApplication.getInstance().getDBOpenHelper().getWritableDatabase(); | ||||
|         sqlDB.beginTransaction(); | ||||
|         switch (uriType) { | ||||
|             case MODIFICATIONS: | ||||
|  | @ -132,7 +130,7 @@ public class ModificationsContentProvider extends ContentProvider{ | |||
|         In here, the only concat created argument is for id. It is cast to an int, and will error out otherwise. | ||||
|          */ | ||||
|         int uriType = uriMatcher.match(uri); | ||||
|         SQLiteDatabase sqlDB = dbOpenHelper.getWritableDatabase(); | ||||
|         SQLiteDatabase sqlDB = CommonsApplication.getInstance().getDBOpenHelper().getWritableDatabase(); | ||||
|         int rowsUpdated = 0; | ||||
|         switch (uriType) { | ||||
|             case MODIFICATIONS: | ||||
|  |  | |||
|  | @ -41,8 +41,7 @@ import timber.log.Timber; | |||
| 
 | ||||
| public class NearbyActivity extends NavigationBaseActivity { | ||||
| 
 | ||||
|     @BindView(R.id.progressBar) | ||||
|     ProgressBar progressBar; | ||||
|     @BindView(R.id.progressBar) ProgressBar progressBar; | ||||
|     private boolean isMapViewActive = false; | ||||
|     private static final int LOCATION_REQUEST = 1; | ||||
| 
 | ||||
|  | @ -133,7 +132,7 @@ public class NearbyActivity extends NavigationBaseActivity { | |||
|         } | ||||
|     } | ||||
| 
 | ||||
|     protected void checkGps() { | ||||
|     private void checkGps() { | ||||
|         LocationManager manager = (LocationManager) getSystemService(LOCATION_SERVICE); | ||||
|         if (!manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { | ||||
|             Timber.d("GPS is not enabled"); | ||||
|  | @ -202,15 +201,11 @@ public class NearbyActivity extends NavigationBaseActivity { | |||
|         } | ||||
|     } | ||||
| 
 | ||||
|     protected void refreshView() { | ||||
|     private void refreshView() { | ||||
|         nearbyAsyncTask = new NearbyAsyncTask(this); | ||||
|         nearbyAsyncTask.execute(); | ||||
|     } | ||||
| 
 | ||||
|     public LocationServiceManager getLocationManager() { | ||||
|         return locationManager; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     protected void onDestroy() { | ||||
|         super.onDestroy(); | ||||
|  | @ -221,17 +216,12 @@ public class NearbyActivity extends NavigationBaseActivity { | |||
| 
 | ||||
|     private class NearbyAsyncTask extends AsyncTask<Void, Integer, List<Place>> { | ||||
| 
 | ||||
|         private Context mContext; | ||||
|         private final Context mContext; | ||||
| 
 | ||||
|         private NearbyAsyncTask (Context context) { | ||||
|             mContext = context; | ||||
|         } | ||||
| 
 | ||||
|         @Override | ||||
|         protected void onPreExecute() { | ||||
|             super.onPreExecute(); | ||||
|         } | ||||
| 
 | ||||
|         @Override | ||||
|         protected void onProgressUpdate(Integer... values) { | ||||
|             super.onProgressUpdate(values); | ||||
|  | @ -284,7 +274,7 @@ public class NearbyActivity extends NavigationBaseActivity { | |||
|     /** | ||||
|      * Calls fragment for map view. | ||||
|      */ | ||||
|     public void setMapFragment() { | ||||
|     private void setMapFragment() { | ||||
|         FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction(); | ||||
|         Fragment fragment = new NearbyMapFragment(); | ||||
|         fragment.setArguments(bundle); | ||||
|  | @ -295,7 +285,7 @@ public class NearbyActivity extends NavigationBaseActivity { | |||
|     /** | ||||
|      * Calls fragment for list view. | ||||
|      */ | ||||
|     public void setListFragment() { | ||||
|     private void setListFragment() { | ||||
|         FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction(); | ||||
|         Fragment fragment = new NearbyListFragment(); | ||||
|         fragment.setArguments(bundle); | ||||
|  |  | |||
|  | @ -1,44 +0,0 @@ | |||
| package fr.free.nrw.commons.nearby; | ||||
| 
 | ||||
| import android.content.Context; | ||||
| import android.view.LayoutInflater; | ||||
| import android.view.View; | ||||
| import android.view.ViewGroup; | ||||
| import android.widget.ArrayAdapter; | ||||
| 
 | ||||
| import fr.free.nrw.commons.R; | ||||
| import timber.log.Timber; | ||||
| 
 | ||||
| public class NearbyAdapter extends ArrayAdapter<Place> { | ||||
| 
 | ||||
|     /** Accepts activity context and list of places. | ||||
|      * @param context activity context | ||||
|      */ | ||||
|     public NearbyAdapter(Context context) { | ||||
|         super(context, R.layout.item_place); | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public View getView(int position, View convertView, ViewGroup parent) { | ||||
|         // Get the data item for this position | ||||
|         Place place = getItem(position); | ||||
|         Timber.v(String.valueOf(place)); | ||||
| 
 | ||||
|         // Check if an existing view is being reused, otherwise inflate the view | ||||
|         if (convertView == null) { | ||||
|             convertView = LayoutInflater.from(getContext()) | ||||
|                     .inflate(R.layout.item_place, parent, false); | ||||
|         } | ||||
| 
 | ||||
|         NearbyViewHolder viewHolder = new NearbyViewHolder(convertView); | ||||
|         viewHolder.bindModel(getContext(), place); | ||||
|         // Return the completed view to render on screen | ||||
|         return convertView; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public long getItemId(int position) { | ||||
|         // TODO: use Wikidata Q-ID instead? | ||||
|         return position; | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,24 @@ | |||
| package fr.free.nrw.commons.nearby; | ||||
| 
 | ||||
| import com.pedrogomez.renderers.ListAdapteeCollection; | ||||
| import com.pedrogomez.renderers.RVRendererAdapter; | ||||
| import com.pedrogomez.renderers.RendererBuilder; | ||||
| 
 | ||||
| import java.util.Collections; | ||||
| import java.util.List; | ||||
| 
 | ||||
| class NearbyAdapterFactory { | ||||
|     private PlaceRenderer.PlaceClickedListener listener; | ||||
| 
 | ||||
|     NearbyAdapterFactory(PlaceRenderer.PlaceClickedListener listener) { | ||||
|         this.listener = listener; | ||||
|     } | ||||
| 
 | ||||
|     public RVRendererAdapter<Place> create(List<Place> placeList) { | ||||
|         RendererBuilder<Place> builder = new RendererBuilder<Place>() | ||||
|                 .bind(Place.class, new PlaceRenderer(listener)); | ||||
|         ListAdapteeCollection<Place> collection = new ListAdapteeCollection<>( | ||||
|                 placeList != null ? placeList : Collections.<Place>emptyList()); | ||||
|         return new RVRendererAdapter<>(builder, collection); | ||||
|     } | ||||
| } | ||||
|  | @ -17,16 +17,11 @@ import fr.free.nrw.commons.utils.UriSerializer; | |||
| 
 | ||||
| public class NearbyBaseMarker extends BaseMarkerOptions<NearbyMarker, NearbyBaseMarker> { | ||||
|     private Place place; | ||||
|     public NearbyBaseMarker() { | ||||
| 
 | ||||
|     NearbyBaseMarker() { | ||||
|     } | ||||
| 
 | ||||
|     public NearbyBaseMarker place(Place place) { | ||||
|         this.place = place; | ||||
|         return getThis(); | ||||
|     } | ||||
| 
 | ||||
|     public NearbyBaseMarker(Parcel in) { | ||||
|     private NearbyBaseMarker(Parcel in) { | ||||
|         Gson gson = new GsonBuilder() | ||||
|                 .registerTypeAdapter(Uri.class, new UriDeserializer()) | ||||
|                 .create(); | ||||
|  | @ -42,6 +37,11 @@ public class NearbyBaseMarker extends BaseMarkerOptions<NearbyMarker, NearbyBase | |||
|         place(gson.fromJson(gsonString, Place.class)); | ||||
|     } | ||||
| 
 | ||||
|     public NearbyBaseMarker place(Place place) { | ||||
|         this.place = place; | ||||
|         return this; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public NearbyBaseMarker getThis() { | ||||
|         return this; | ||||
|  | @ -52,6 +52,10 @@ public class NearbyBaseMarker extends BaseMarkerOptions<NearbyMarker, NearbyBase | |||
|         return new NearbyMarker(this, place); | ||||
|     } | ||||
| 
 | ||||
|     public Place getPlace() { | ||||
|         return place; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public int describeContents() { | ||||
|         return 0; | ||||
|  | @ -71,10 +75,6 @@ public class NearbyBaseMarker extends BaseMarkerOptions<NearbyMarker, NearbyBase | |||
|         dest.writeString(gson.toJson(place)); | ||||
|     } | ||||
| 
 | ||||
|     public Place getPlace() { | ||||
|         return place; | ||||
|     } | ||||
| 
 | ||||
|     public static final Parcelable.Creator<NearbyBaseMarker> CREATOR | ||||
|             = new Parcelable.Creator<NearbyBaseMarker>() { | ||||
|         public NearbyBaseMarker createFromParcel(Parcel in) { | ||||
|  |  | |||
|  | @ -29,19 +29,12 @@ public class NearbyInfoDialog extends OverlayDialog { | |||
|     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; | ||||
|     @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; | ||||
| 
 | ||||
|  | @ -64,7 +57,7 @@ public class NearbyInfoDialog extends OverlayDialog { | |||
|     private void getArticleLink(Bundle bundle) { | ||||
|         this.sitelinks = bundle.getParcelable(ARG_SITE_LINK); | ||||
| 
 | ||||
|         if (sitelinks.getWikipediaLink().equals(Uri.EMPTY)) { | ||||
|         if (sitelinks == null || Uri.EMPTY.equals(sitelinks.getWikipediaLink())) { | ||||
|             goToButton.setVisibility(View.GONE); | ||||
|         } | ||||
| 
 | ||||
|  | @ -99,7 +92,7 @@ public class NearbyInfoDialog extends OverlayDialog { | |||
|                 || !sitelinks.getWikidataLink().equals(Uri.EMPTY); | ||||
|     } | ||||
| 
 | ||||
|     private PopupMenu.OnMenuItemClickListener menuListener = new PopupMenu | ||||
|     private final PopupMenu.OnMenuItemClickListener menuListener = new PopupMenu | ||||
|             .OnMenuItemClickListener() { | ||||
|         @Override | ||||
|         public boolean onMenuItemClick(MenuItem item) { | ||||
|  |  | |||
|  | @ -2,37 +2,37 @@ package fr.free.nrw.commons.nearby; | |||
| 
 | ||||
| import android.net.Uri; | ||||
| import android.os.Bundle; | ||||
| import android.support.v4.app.ListFragment; | ||||
| import android.support.v4.app.Fragment; | ||||
| import android.support.v7.widget.LinearLayoutManager; | ||||
| import android.support.v7.widget.RecyclerView; | ||||
| import android.view.LayoutInflater; | ||||
| import android.view.View; | ||||
| import android.view.ViewGroup; | ||||
| import android.widget.ListView; | ||||
| 
 | ||||
| import com.google.gson.Gson; | ||||
| import com.google.gson.GsonBuilder; | ||||
| import com.google.gson.reflect.TypeToken; | ||||
| 
 | ||||
| import java.lang.reflect.Type; | ||||
| import java.util.Collections; | ||||
| import java.util.List; | ||||
| 
 | ||||
| import butterknife.BindView; | ||||
| import butterknife.ButterKnife; | ||||
| import butterknife.OnItemClick; | ||||
| import fr.free.nrw.commons.R; | ||||
| import fr.free.nrw.commons.location.LatLng; | ||||
| import fr.free.nrw.commons.utils.UriDeserializer; | ||||
| import timber.log.Timber; | ||||
| 
 | ||||
| public class NearbyListFragment extends ListFragment  { | ||||
|     private List<Place> placeList; | ||||
| public class NearbyListFragment extends Fragment { | ||||
|     private static final Type LIST_TYPE = new TypeToken<List<Place>>() { | ||||
|     }.getType(); | ||||
|     private static final Type CUR_LAT_LNG_TYPE = new TypeToken<LatLng>() { | ||||
|     }.getType(); | ||||
|     private static final Gson gson = new GsonBuilder() | ||||
|             .registerTypeAdapter(Uri.class, new UriDeserializer()) | ||||
|             .create(); | ||||
| 
 | ||||
|     @BindView(R.id.listView) ListView listview; | ||||
| 
 | ||||
| 
 | ||||
|     private NearbyAdapter adapter; | ||||
| 
 | ||||
|     public NearbyListFragment() { | ||||
|     } | ||||
|     private NearbyAdapterFactory adapterFactory; | ||||
|     private RecyclerView recyclerView; | ||||
| 
 | ||||
|     @Override | ||||
|     public void onCreate(Bundle savedInstanceState) { | ||||
|  | @ -41,55 +41,39 @@ public class NearbyListFragment extends ListFragment  { | |||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public View onCreateView(LayoutInflater inflater, ViewGroup container, | ||||
|     public View onCreateView(LayoutInflater inflater, | ||||
|                              ViewGroup container, | ||||
|                              Bundle savedInstanceState) { | ||||
| 
 | ||||
|         Timber.d("NearbyListFragment created"); | ||||
|         View view = inflater.inflate(R.layout.fragment_nearby, container, false); | ||||
|         ButterKnife.bind(this, view); | ||||
|         adapter = new NearbyAdapter(getActivity()); | ||||
|         listview.setAdapter(adapter); | ||||
|         recyclerView = (RecyclerView) view.findViewById(R.id.listView); | ||||
|         recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); | ||||
|         adapterFactory = new NearbyAdapterFactory(new PlaceRenderer.PlaceClickedListener() { | ||||
|             @Override | ||||
|             public void placeClicked(Place place) { | ||||
|                 NearbyInfoDialog.showYourself(getActivity(), place); | ||||
|             } | ||||
|         }); | ||||
|         return view; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public void onViewCreated(View view, Bundle savedInstanceState) { | ||||
| 
 | ||||
|         // Check that this is the first time view is created, | ||||
|         // to avoid double list when screen orientation changed | ||||
|         List<Place> placeList = Collections.emptyList(); | ||||
| 
 | ||||
|         Bundle bundle = this.getArguments(); | ||||
|         Gson gson = new GsonBuilder() | ||||
|                 .registerTypeAdapter(Uri.class, new UriDeserializer()) | ||||
|                 .create(); | ||||
|         if (bundle != null) { | ||||
|             String gsonPlaceList = bundle.getString("PlaceList"); | ||||
|             placeList = gson.fromJson(gsonPlaceList, LIST_TYPE); | ||||
| 
 | ||||
|             String gsonLatLng = bundle.getString("CurLatLng"); | ||||
|             Type listType = new TypeToken<List<Place>>() {}.getType(); | ||||
|             placeList = gson.fromJson(gsonPlaceList, listType); | ||||
|             Type curLatLngType = new TypeToken<LatLng>() {}.getType(); | ||||
|             LatLng curLatLng = gson.fromJson(gsonLatLng, curLatLngType); | ||||
|             LatLng curLatLng = gson.fromJson(gsonLatLng, CUR_LAT_LNG_TYPE); | ||||
| 
 | ||||
|             placeList = NearbyController.loadAttractionsFromLocationToPlaces(curLatLng, placeList); | ||||
|         } | ||||
|         if (savedInstanceState == null) { | ||||
|             adapter.clear(); | ||||
|             Timber.d("Saved instance state is null, populating ListView"); | ||||
|         } | ||||
| 
 | ||||
|         adapter.clear(); | ||||
|         adapter.addAll(placeList); | ||||
|         adapter.notifyDataSetChanged(); | ||||
|     } | ||||
| 
 | ||||
|     @OnItemClick(R.id.listView) | ||||
|     void onItemClicked(int position) { | ||||
|         Place place = (Place) listview.getItemAtPosition(position); | ||||
|         LatLng placeLatLng = place.location; | ||||
| 
 | ||||
|         double latitude = placeLatLng.getLatitude(); | ||||
|         double longitude = placeLatLng.getLongitude(); | ||||
| 
 | ||||
|         Timber.d("Item at position %d has coords: Lat: %f Long: %f", position, latitude, longitude); | ||||
| 
 | ||||
|         NearbyInfoDialog.showYourself(getActivity(), place); | ||||
|         recyclerView.setAdapter(adapterFactory.create(placeList)); | ||||
|     } | ||||
| } | ||||
|  |  | |||
|  | @ -5,7 +5,6 @@ import android.net.Uri; | |||
| import android.os.Bundle; | ||||
| import android.preference.PreferenceManager; | ||||
| import android.support.annotation.NonNull; | ||||
| import android.support.annotation.Nullable; | ||||
| import android.view.LayoutInflater; | ||||
| import android.view.View; | ||||
| import android.view.ViewGroup; | ||||
|  | @ -39,7 +38,6 @@ public class NearbyMapFragment extends android.support.v4.app.Fragment { | |||
|     private fr.free.nrw.commons.location.LatLng curLatLng; | ||||
| 
 | ||||
|     public NearbyMapFragment() { | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|  | @ -123,7 +121,7 @@ public class NearbyMapFragment extends android.support.v4.app.Fragment { | |||
|      * which represents the user's position with an accuracy | ||||
|      * of 95%. | ||||
|      */ | ||||
|     public void addCurrentLocationMarker(MapboxMap mapboxMap) { | ||||
|     private void addCurrentLocationMarker(MapboxMap mapboxMap) { | ||||
|         MarkerOptions currentLocationMarker = new MarkerOptions() | ||||
|                 .position(new LatLng(curLatLng.getLatitude(), curLatLng.getLongitude())); | ||||
|         mapboxMap.addMarker(currentLocationMarker); | ||||
|  | @ -146,7 +144,7 @@ public class NearbyMapFragment extends android.support.v4.app.Fragment { | |||
|      * | ||||
|      * @return List List of LatLng points of the circle. | ||||
|      */ | ||||
|     public List<LatLng> createCircleArray( | ||||
|     private List<LatLng> createCircleArray( | ||||
|             double centerLat, double centerLong, float radius, int nodes) { | ||||
|         List<LatLng> circle = new ArrayList<>(); | ||||
|         float radiusKilometer = radius / 1000; | ||||
|  | @ -164,11 +162,6 @@ public class NearbyMapFragment extends android.support.v4.app.Fragment { | |||
|         return circle; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { | ||||
|         super.onViewCreated(view, savedInstanceState); | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public void onStart() { | ||||
|         if (mapView != null) { | ||||
|  |  | |||
|  | @ -2,8 +2,8 @@ package fr.free.nrw.commons.nearby; | |||
| 
 | ||||
| import com.mapbox.mapboxsdk.annotations.Marker; | ||||
| 
 | ||||
| public class NearbyMarker extends Marker { | ||||
|     private Place place; | ||||
| class NearbyMarker extends Marker { | ||||
|     private final Place place; | ||||
|     private NearbyBaseMarker nearbyBaseMarker; | ||||
| 
 | ||||
|     /** | ||||
|  | @ -11,21 +11,17 @@ public class NearbyMarker extends Marker { | |||
|      * | ||||
|      * @param baseMarkerOptions The builder used to construct the Marker. | ||||
|      */ | ||||
|     public NearbyMarker(NearbyBaseMarker baseMarkerOptions, Place place) { | ||||
|     NearbyMarker(NearbyBaseMarker baseMarkerOptions, Place place) { | ||||
|         super(baseMarkerOptions); | ||||
|         this.place = place; | ||||
|         this.nearbyBaseMarker = baseMarkerOptions; | ||||
|     } | ||||
| 
 | ||||
|     public NearbyBaseMarker getNearbyBaseMarker() { | ||||
|     NearbyBaseMarker getNearbyBaseMarker() { | ||||
|         return nearbyBaseMarker; | ||||
|     } | ||||
| 
 | ||||
|     public Place getPlace() { | ||||
|         return place; | ||||
|     } | ||||
| 
 | ||||
|     public void setNearbyBaseMarker(NearbyBaseMarker nearbyBaseMarker) { | ||||
|         this.nearbyBaseMarker = nearbyBaseMarker; | ||||
|     } | ||||
| } | ||||
|  |  | |||
|  | @ -34,8 +34,7 @@ public class NearbyPlaces { | |||
| 
 | ||||
|     public NearbyPlaces() { | ||||
|         try { | ||||
|             String query = FileUtils.readFromResource("/assets/queries/nearby_query.rq"); | ||||
|             wikidataQuery = query; | ||||
|             wikidataQuery = FileUtils.readFromResource("/assets/queries/nearby_query.rq"); | ||||
|             Timber.v(wikidataQuery); | ||||
|         } catch (IOException e) { | ||||
|             throw new RuntimeException(e); | ||||
|  | @ -106,8 +105,8 @@ public class NearbyPlaces { | |||
|             String wikiDataLink = Utils.stripLocalizedString(fields[1]); | ||||
|             String icon = fields[5]; | ||||
| 
 | ||||
|             double latitude = 0; | ||||
|             double longitude = 0; | ||||
|             double latitude; | ||||
|             double longitude; | ||||
|             Matcher matcher = | ||||
|                     Pattern.compile("Point\\(([^ ]+) ([^ ]+)\\)").matcher(point); | ||||
|             if (!matcher.find()) { | ||||
|  |  | |||
|  | @ -1,35 +0,0 @@ | |||
| package fr.free.nrw.commons.nearby; | ||||
| 
 | ||||
| import android.content.Context; | ||||
| import android.view.View; | ||||
| import android.widget.ImageView; | ||||
| import android.widget.TextView; | ||||
| 
 | ||||
| import butterknife.BindView; | ||||
| import butterknife.ButterKnife; | ||||
| import fr.free.nrw.commons.R; | ||||
| import fr.free.nrw.commons.ViewHolder; | ||||
| 
 | ||||
| public class NearbyViewHolder implements ViewHolder<Place> { | ||||
|     @BindView(R.id.tvName) TextView tvName; | ||||
|     @BindView(R.id.tvDesc) TextView tvDesc; | ||||
|     @BindView(R.id.distance) TextView distance; | ||||
|     @BindView(R.id.icon) ImageView icon; | ||||
| 
 | ||||
|     public NearbyViewHolder(View view) { | ||||
|         ButterKnife.bind(this, view); | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public void bindModel(Context context, Place place) { | ||||
|         // Populate the data into the template view using the data object | ||||
|         tvName.setText(place.name); | ||||
|         String descriptionText = place.getDescription().getText(); | ||||
|         if (descriptionText.equals("?")) { | ||||
|             descriptionText = context.getString(R.string.no_description_found); | ||||
|         } | ||||
|         tvDesc.setText(descriptionText); | ||||
|         distance.setText(place.distance); | ||||
|         icon.setImageResource(place.getDescription().getIcon()); | ||||
|     } | ||||
| } | ||||
|  | @ -14,14 +14,14 @@ public class Place { | |||
| 
 | ||||
|     public final String name; | ||||
|     private final Description description; | ||||
|     public final String longDescription; | ||||
|     public final Uri secondaryImageUrl; | ||||
|     private final String longDescription; | ||||
|     private final Uri secondaryImageUrl; | ||||
|     public final LatLng location; | ||||
| 
 | ||||
|     public Bitmap image; | ||||
|     public Bitmap secondaryImage; | ||||
|     public String distance; | ||||
|     public Sitelinks siteLinks; | ||||
|     public final Sitelinks siteLinks; | ||||
| 
 | ||||
| 
 | ||||
|     public Place(String name, Description description, String longDescription, | ||||
|  |  | |||
|  | @ -0,0 +1,64 @@ | |||
| package fr.free.nrw.commons.nearby; | ||||
| 
 | ||||
| import android.view.LayoutInflater; | ||||
| import android.view.View; | ||||
| import android.view.ViewGroup; | ||||
| import android.widget.ImageView; | ||||
| import android.widget.TextView; | ||||
| 
 | ||||
| import com.pedrogomez.renderers.Renderer; | ||||
| 
 | ||||
| import butterknife.BindView; | ||||
| import butterknife.ButterKnife; | ||||
| import fr.free.nrw.commons.R; | ||||
| 
 | ||||
| class PlaceRenderer extends Renderer<Place> { | ||||
|     @BindView(R.id.tvName) TextView tvName; | ||||
|     @BindView(R.id.tvDesc) TextView tvDesc; | ||||
|     @BindView(R.id.distance) TextView distance; | ||||
|     @BindView(R.id.icon) ImageView icon; | ||||
|     private final PlaceClickedListener listener; | ||||
| 
 | ||||
|     PlaceRenderer(PlaceClickedListener listener) { | ||||
|         this.listener = listener; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     protected View inflate(LayoutInflater layoutInflater, ViewGroup viewGroup) { | ||||
|         return layoutInflater.inflate(R.layout.item_place, viewGroup, false); | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     protected void setUpView(View view) { | ||||
|         ButterKnife.bind(this, view); | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     protected void hookListeners(View view) { | ||||
|         view.setOnClickListener(new View.OnClickListener() { | ||||
|             @Override | ||||
|             public void onClick(View v) { | ||||
|                 if (listener != null) { | ||||
|                     listener.placeClicked(getContent()); | ||||
|                 } | ||||
|             } | ||||
|         }); | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public void render() { | ||||
|         Place place = getContent(); | ||||
|         tvName.setText(place.name); | ||||
|         String descriptionText = place.getDescription().getText(); | ||||
|         if (descriptionText.equals("?")) { | ||||
|             descriptionText = getContext().getString(R.string.no_description_found); | ||||
|         } | ||||
|         tvDesc.setText(descriptionText); | ||||
|         distance.setText(place.distance); | ||||
|         icon.setImageResource(place.getDescription().getIcon()); | ||||
|     } | ||||
| 
 | ||||
|     interface PlaceClickedListener { | ||||
|         void placeClicked(Place place); | ||||
|     } | ||||
| } | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Paul Hawke
						Paul Hawke