Fix conflicts

This commit is contained in:
neslihanturan 2018-03-06 19:47:18 +03:00
commit 5b88111289
324 changed files with 9238 additions and 2883 deletions

View file

@ -13,16 +13,14 @@ import static android.Manifest.permission.READ_EXTERNAL_STORAGE;
import static android.Manifest.permission.WRITE_EXTERNAL_STORAGE;
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
public class DirectUpload {
class DirectUpload {
private ContributionController controller;
private Fragment fragment;
private SharedPreferences prefs;
DirectUpload(Fragment fragment, ContributionController controller, SharedPreferences prefs) {
DirectUpload(Fragment fragment, ContributionController controller) {
this.fragment = fragment;
this.controller = controller;
this.prefs = prefs;
}
void initiateCameraUpload() {

View file

@ -7,7 +7,9 @@ import android.os.Build;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomSheetBehavior;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AlertDialog;
import android.util.Log;
import android.view.Menu;
@ -71,6 +73,7 @@ public class NearbyActivity extends NavigationBaseActivity implements LocationUp
private static final String TAG_RETAINED_MAP_FRAGMENT = NearbyMapFragment.class.getSimpleName();
private static final String TAG_RETAINED_LIST_FRAGMENT = NearbyListFragment.class.getSimpleName();
@BindView(R.id.swipe_container) SwipeRefreshLayout swipeLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -78,6 +81,8 @@ public class NearbyActivity extends NavigationBaseActivity implements LocationUp
ButterKnife.bind(this);
resumeFragment();
bundle = new Bundle();
initBottomSheetBehaviour();
initDrawer();
}
@ -90,6 +95,14 @@ public class NearbyActivity extends NavigationBaseActivity implements LocationUp
private void initBottomSheetBehaviour() {
transparentView.setAlpha(0);
swipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
lockNearbyView(false);
refreshView(true);
}
});
bottomSheet.getLayoutParams().height = getWindowManager()
.getDefaultDisplay().getHeight() / 16 * 9;
bottomSheetBehavior = BottomSheetBehavior.from(bottomSheet);

View file

@ -1,5 +1,8 @@
package fr.free.nrw.commons.nearby;
import android.support.v4.app.Fragment;
import com.pedrogomez.renderers.ListAdapteeCollection;
import com.pedrogomez.renderers.RVRendererAdapter;
import com.pedrogomez.renderers.RendererBuilder;
@ -7,11 +10,25 @@ import com.pedrogomez.renderers.RendererBuilder;
import java.util.Collections;
import java.util.List;
import fr.free.nrw.commons.contributions.ContributionController;
class NearbyAdapterFactory {
private Fragment fragment;
private ContributionController controller;
NearbyAdapterFactory(){
}
NearbyAdapterFactory(Fragment fragment, ContributionController controller) {
this.fragment = fragment;
this.controller = controller;
}
public RVRendererAdapter<Place> create(List<Place> placeList) {
RendererBuilder<Place> builder = new RendererBuilder<Place>()
.bind(Place.class, new PlaceRenderer());
.bind(Place.class, new PlaceRenderer(fragment, controller));
ListAdapteeCollection<Place> collection = new ListAdapteeCollection<>(
placeList != null ? placeList : Collections.emptyList());
return new RVRendererAdapter<>(builder, collection);

View file

@ -39,11 +39,13 @@ public class NearbyController {
/**
* Prepares Place list to make their distance information update later.
*
* @param curLatLng current location for user
* @return Place list without distance information
* @return NearbyPlacesInfo a variable holds Place list without distance information
* and boundary coordinates of current Place List
*/
//public List<Place> loadAttractionsFromLocation(LatLng curLatLng) {
public NearbyPlacesInfo loadAttractionsFromLocation(LatLng curLatLng) {
Timber.d("Loading attractions near %s", curLatLng);
NearbyPlacesInfo nearbyPlacesInfo = new NearbyPlacesInfo();
@ -51,10 +53,12 @@ public class NearbyController {
return null;
}
List<Place> places = nearbyPlaces.getFromWikidataQuery(curLatLng, Locale.getDefault().getLanguage());
LatLng[] boundaryCoordinates = {places.get(0).location, // south
places.get(0).location, // north
places.get(0).location, // west
places.get(0).location};// east, init with a random location
if (curLatLng != null) {
Timber.d("Sorting places by distance...");
final Map<Place, Double> distances = new HashMap<>();
@ -89,6 +93,7 @@ public class NearbyController {
/**
* Loads attractions from location for list view, we need to return Place data type.
*
* @param curLatLng users current location
* @param placeList list of nearby places in Place data type
* @return Place list that holds nearby places
@ -97,7 +102,7 @@ public class NearbyController {
LatLng curLatLng,
List<Place> placeList) {
placeList = placeList.subList(0, Math.min(placeList.size(), MAX_RESULTS));
for (Place place: placeList) {
for (Place place : placeList) {
String distance = formatDistanceBetween(curLatLng, place.location);
place.setDistance(distance);
}
@ -105,7 +110,8 @@ public class NearbyController {
}
/**
*Loads attractions from location for map view, we need to return BaseMarkerOption data type.
* Loads attractions from location for map view, we need to return BaseMarkerOption data type.
*
* @param curLatLng users current location
* @param placeList list of nearby places in Place data type
* @return BaseMarkerOptions list that holds nearby places
@ -122,26 +128,28 @@ public class NearbyController {
placeList = placeList.subList(0, Math.min(placeList.size(), MAX_RESULTS));
Bitmap icon = UiUtils.getBitmap(
VectorDrawableCompat.create(
context.getResources(), R.drawable.ic_custom_map_marker, context.getTheme()
));
VectorDrawableCompat vectorDrawable = VectorDrawableCompat.create(
context.getResources(), R.drawable.ic_custom_map_marker, context.getTheme()
);
if (vectorDrawable != null) {
Bitmap icon = UiUtils.getBitmap(vectorDrawable);
for (Place place: placeList) {
String distance = formatDistanceBetween(curLatLng, place.location);
place.setDistance(distance);
for (Place place : placeList) {
String distance = formatDistanceBetween(curLatLng, place.location);
place.setDistance(distance);
NearbyBaseMarker nearbyBaseMarker = new NearbyBaseMarker();
nearbyBaseMarker.title(place.name);
nearbyBaseMarker.position(
new com.mapbox.mapboxsdk.geometry.LatLng(
place.location.getLatitude(),
place.location.getLongitude()));
nearbyBaseMarker.place(place);
nearbyBaseMarker.icon(IconFactory.getInstance(context)
.fromBitmap(icon));
NearbyBaseMarker nearbyBaseMarker = new NearbyBaseMarker();
nearbyBaseMarker.title(place.name);
nearbyBaseMarker.position(
new com.mapbox.mapboxsdk.geometry.LatLng(
place.location.getLatitude(),
place.location.getLongitude()));
nearbyBaseMarker.place(place);
nearbyBaseMarker.icon(IconFactory.getInstance(context)
.fromBitmap(icon));
baseMarkerOptions.add(nearbyBaseMarker);
baseMarkerOptions.add(nearbyBaseMarker);
}
}
return baseMarkerOptions;
}

View file

@ -1,7 +1,11 @@
package fr.free.nrw.commons.nearby;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
@ -17,12 +21,17 @@ import java.lang.reflect.Type;
import java.util.Collections;
import java.util.List;
import dagger.android.support.AndroidSupportInjection;
import dagger.android.support.DaggerFragment;
import fr.free.nrw.commons.R;
import fr.free.nrw.commons.contributions.ContributionController;
import fr.free.nrw.commons.location.LatLng;
import fr.free.nrw.commons.utils.UriDeserializer;
import timber.log.Timber;
import static android.app.Activity.RESULT_OK;
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
public class NearbyListFragment extends DaggerFragment {
private static final Type LIST_TYPE = new TypeToken<List<Place>>() {
}.getType();
@ -34,6 +43,7 @@ public class NearbyListFragment extends DaggerFragment {
private NearbyAdapterFactory adapterFactory;
private RecyclerView recyclerView;
private ContributionController controller;
@Override
public void onCreate(Bundle savedInstanceState) {
@ -41,6 +51,12 @@ public class NearbyListFragment extends DaggerFragment {
setRetainInstance(true);
}
@Override
public void onAttach(Context context) {
AndroidSupportInjection.inject(this);
super.onAttach(context);
}
@Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container,
@ -49,7 +65,9 @@ public class NearbyListFragment extends DaggerFragment {
View view = inflater.inflate(R.layout.fragment_nearby, container, false);
recyclerView = view.findViewById(R.id.listView);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
adapterFactory = new NearbyAdapterFactory();
controller = new ContributionController(this);
adapterFactory = new NearbyAdapterFactory(this, controller);
return view;
}
@ -79,6 +97,47 @@ public class NearbyListFragment extends DaggerFragment {
placeList = NearbyController.loadAttractionsFromLocationToPlaces(curLatLng, placeList);
}
return placeList;
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
Timber.d("onRequestPermissionsResult: req code = " + " perm = " + permissions + " grant =" + grantResults);
switch (requestCode) {
// 1 = "Read external storage" allowed when gallery selected
case 1: {
if (grantResults.length > 0 && grantResults[0] == PERMISSION_GRANTED) {
Timber.d("Call controller.startGalleryPick()");
controller.startGalleryPick();
}
}
break;
// 3 = "Write external storage" allowed when camera selected
case 3: {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
Timber.d("Call controller.startCameraCapture()");
controller.startCameraCapture();
}
}
}
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
Timber.d("OnActivityResult() parameters: Req code: %d Result code: %d Data: %s",
requestCode, resultCode, data);
controller.handleImagePicked(requestCode, data, true);
} else {
Timber.e("OnActivityResult() parameters: Req code: %d Result code: %d Data: %s",
requestCode, resultCode, data);
}
}
}

View file

@ -3,6 +3,7 @@ package fr.free.nrw.commons.nearby;
import android.animation.ObjectAnimator;
import android.animation.TypeEvaluator;
import android.animation.ValueAnimator;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
@ -15,7 +16,6 @@ import android.support.design.widget.BottomSheetBehavior;
import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.FloatingActionButton;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
@ -115,7 +115,6 @@ public class NearbyMapFragment extends DaggerFragment {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle bundle = this.getArguments();
Gson gson = new GsonBuilder()
.registerTypeAdapter(Uri.class, new UriDeserializer())
.create();
@ -388,6 +387,8 @@ public class NearbyMapFragment extends DaggerFragment {
private void setupMapView(Bundle savedInstanceState) {
MapboxMapOptions options = new MapboxMapOptions()
.styleUrl(Style.OUTDOORS)
.logoEnabled(false)
.attributionEnabled(false)
.camera(new CameraPosition.Builder()
.target(new LatLng(curLatLng.getLatitude(), curLatLng.getLongitude()))
.zoom(11)
@ -546,6 +547,8 @@ public class NearbyMapFragment extends DaggerFragment {
icon.setImageResource(place.getLabel().getIcon());
title.setText(place.name);
distance.setText(place.distance);
description.setText(place.getLongDescription());
title.setText(place.name.toString());
distance.setText(place.distance.toString());
@ -553,7 +556,8 @@ public class NearbyMapFragment extends DaggerFragment {
fabCamera.setOnClickListener(view -> {
Timber.d("Camera button tapped. Image title: " + place.getName() + "Image desc: " + place.getLongDescription());
controller = new ContributionController(this);
DirectUpload directUpload = new DirectUpload(this, controller, prefs);
DirectUpload directUpload = new DirectUpload(this, controller);
storeSharedPrefs();
directUpload.initiateCameraUpload();
});
@ -561,9 +565,14 @@ public class NearbyMapFragment extends DaggerFragment {
fabGallery.setOnClickListener(view -> {
Timber.d("Gallery button tapped. Image title: " + place.getName() + "Image desc: " + place.getLongDescription());
controller = new ContributionController(this);
DirectUpload directUpload = new DirectUpload(this, controller, prefs);
DirectUpload directUpload = new DirectUpload(this, controller);
storeSharedPrefs();
directUpload.initiateGalleryUpload();
//TODO: App crashes after image upload completes
//TODO: Handle onRequestPermissionsResult
});
}

View file

@ -32,7 +32,7 @@ public class NearbyPlaces {
public NearbyPlaces() {
try {
wikidataQuery = FileUtils.readFromResource("/assets/queries/nearby_query.rq");
wikidataQuery = FileUtils.readFromResource("/queries/nearby_query.rq");
Timber.v(wikidataQuery);
} catch (IOException e) {
throw new RuntimeException(e);

View file

@ -1,23 +1,31 @@
package fr.free.nrw.commons.nearby;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import butterknife.ButterKnife;
import dagger.android.support.DaggerFragment;
import dagger.android.support.AndroidSupportInjection;
import fr.free.nrw.commons.R;
import timber.log.Timber;
/**
* Tells user that Nearby Places cannot be displayed if location permissions are denied
*/
public class NoPermissionsFragment extends DaggerFragment {
public class NoPermissionsFragment extends Fragment {
public NoPermissionsFragment() {
}
@Override
public void onAttach(Context context) {
AndroidSupportInjection.inject(this);
super.onAttach(context);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {

View file

@ -1,7 +1,10 @@
package fr.free.nrw.commons.nearby;
import android.content.Intent;
import android.net.Uri;
import android.content.SharedPreferences;
import android.support.v4.app.Fragment;
import android.support.transition.TransitionManager;
import android.support.v7.widget.PopupMenu;
import android.util.Log;
@ -17,11 +20,17 @@ import com.pedrogomez.renderers.Renderer;
import java.util.ArrayList;
import javax.inject.Inject;
import javax.inject.Named;
import butterknife.BindView;
import butterknife.ButterKnife;
import fr.free.nrw.commons.CommonsApplication;
import fr.free.nrw.commons.R;
import fr.free.nrw.commons.contributions.ContributionController;
import timber.log.Timber;
class PlaceRenderer extends Renderer<Place> {
public class PlaceRenderer extends Renderer<Place> {
@BindView(R.id.tvName) TextView tvName;
@BindView(R.id.tvDesc) TextView tvDesc;
@ -29,11 +38,13 @@ class PlaceRenderer extends Renderer<Place> {
@BindView(R.id.icon) ImageView icon;
@BindView(R.id.buttonLayout) LinearLayout buttonLayout;
@BindView(R.id.cameraButton) LinearLayout cameraButton;
@BindView(R.id.galeryButton) LinearLayout galeryButton;
@BindView(R.id.galleryButton) LinearLayout galleryButton;
@BindView(R.id.directionsButton) LinearLayout directionsButton;
@BindView(R.id.iconOverflow) LinearLayout iconOverflow;
@BindView(R.id.cameraButtonText) TextView cameraButtonText;
@BindView(R.id.galeryButtonText) TextView galeryButtonText;
@BindView(R.id.galleryButtonText) TextView galleryButtonText;
@BindView(R.id.directionsButtonText) TextView directionsButtonText;
@BindView(R.id.iconOverflowText) TextView iconOverflowText;
@ -41,8 +52,20 @@ class PlaceRenderer extends Renderer<Place> {
private static ArrayList<LinearLayout> openedItems;
private Place place;
private Fragment fragment;
private ContributionController controller;
PlaceRenderer(){
@Inject @Named("prefs") SharedPreferences prefs;
@Inject @Named("direct_nearby_upload_prefs") SharedPreferences directPrefs;
public PlaceRenderer(){
openedItems = new ArrayList<>();
}
public PlaceRenderer(Fragment fragment, ContributionController controller) {
this.fragment = fragment;
this.controller = controller;
openedItems = new ArrayList<>();
}
@ -81,7 +104,28 @@ class PlaceRenderer extends Renderer<Place> {
}
});
//TODO: Set onClickListeners for camera and gallery in list here
cameraButton.setOnClickListener(view2 -> {
Timber.d("Camera button tapped. Image title: " + place.getName() + "Image desc: " + place.getLongDescription());
DirectUpload directUpload = new DirectUpload(fragment, controller);
storeSharedPrefs();
directUpload.initiateCameraUpload();
});
galleryButton.setOnClickListener(view3 -> {
Timber.d("Gallery button tapped. Image title: " + place.getName() + "Image desc: " + place.getLongDescription());
DirectUpload directUpload = new DirectUpload(fragment, controller);
storeSharedPrefs();
directUpload.initiateGalleryUpload();
});
}
private void storeSharedPrefs() {
SharedPreferences.Editor editor = directPrefs.edit();
Timber.d("directPrefs stored");
editor.putString("Title", place.getName());
editor.putString("Desc", place.getLongDescription());
editor.apply();
}
private void closeLayout(LinearLayout buttonLayout){
@ -94,9 +138,11 @@ class PlaceRenderer extends Renderer<Place> {
@Override
public void render() {
place = getContent();
tvName.setText(place.name);
String descriptionText = place.getLabel().getText();
String descriptionText = place.getLongDescription();
if (descriptionText.equals("?")) {
descriptionText = getContext().getString(R.string.no_description_found);
}
@ -114,6 +160,7 @@ class PlaceRenderer extends Renderer<Place> {
iconOverflow.setVisibility(showMenu() ? View.VISIBLE : View.GONE);
iconOverflow.setOnClickListener(v -> popupMenuListener());
}
private void popupMenuListener() {