This commit is contained in:
neslihanturan 2019-09-17 20:23:54 +03:00
parent ee57f84fea
commit cc0cb53777
2 changed files with 134 additions and 260 deletions

View file

@ -21,9 +21,7 @@ public interface NearbyParentFragmentContract {
void listOptionMenuItemClicked(); void listOptionMenuItemClicked();
void populatePlaces(LatLng curlatLng, LatLng searchLatLng); void populatePlaces(LatLng curlatLng, LatLng searchLatLng);
boolean isListBottomSheetExpanded(); boolean isListBottomSheetExpanded();
void checkPermissionsAndPerformAction(Runnable runnable); void checkPermissionsAndPerformAction(Runnable runnable);
void resumeFragment();
void displayLoginSkippedWarning(); void displayLoginSkippedWarning();
void setFABPlusAction(android.view.View.OnClickListener onClickListener); void setFABPlusAction(android.view.View.OnClickListener onClickListener);
void setFABRecenterAction(android.view.View.OnClickListener onClickListener); void setFABRecenterAction(android.view.View.OnClickListener onClickListener);
@ -32,7 +30,6 @@ public interface NearbyParentFragmentContract {
void initViewPositions(); void initViewPositions();
void hideBottomSheet(); void hideBottomSheet();
void displayBottomSheetWithInfo(Marker marker); void displayBottomSheetWithInfo(Marker marker);
void addOnCameraMoveListener(MapboxMap.OnCameraMoveListener onCameraMoveListener); void addOnCameraMoveListener(MapboxMap.OnCameraMoveListener onCameraMoveListener);
void addSearchThisAreaButtonAction(); void addSearchThisAreaButtonAction();
void setSearchThisAreaButtonVisibility(boolean isVisible); void setSearchThisAreaButtonVisibility(boolean isVisible);

View file

@ -8,7 +8,6 @@ import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log;
import android.view.Gravity; import android.view.Gravity;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@ -24,7 +23,6 @@ import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.ConstraintLayout; import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction; import androidx.fragment.app.FragmentTransaction;
@ -39,7 +37,6 @@ import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
import com.mapbox.mapboxsdk.geometry.LatLng; import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.MapboxMap; import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.MapboxMapOptions; import com.mapbox.mapboxsdk.maps.MapboxMapOptions;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.maps.Style; import com.mapbox.mapboxsdk.maps.Style;
import javax.inject.Inject; import javax.inject.Inject;
@ -80,99 +77,38 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
implements NearbyParentFragmentContract.View, implements NearbyParentFragmentContract.View,
WikidataEditListener.WikidataP18EditListener { WikidataEditListener.WikidataP18EditListener {
@BindView(R.id.bottom_sheet) @BindView(R.id.bottom_sheet) View bottomSheetList;
View bottomSheetList; @BindView(R.id.bottom_sheet_details) View bottomSheetDetails;
@BindView(R.id.transparentView) View transparentView;
@BindView(R.id.directionsButtonText) TextView directionsButtonText;
@BindView(R.id.wikipediaButtonText) TextView wikipediaButtonText;
@BindView(R.id.wikidataButtonText) TextView wikidataButtonText;
@BindView(R.id.commonsButtonText) TextView commonsButtonText;
@BindView(R.id.fab_plus) FloatingActionButton fabPlus;
@BindView(R.id.fab_camera) FloatingActionButton fabCamera;
@BindView(R.id.fab_gallery) FloatingActionButton fabGallery;
@BindView(R.id.fab_recenter) FloatingActionButton fabRecenter;
@BindView(R.id.bookmarkButtonImage) ImageView bookmarkButtonImage;
@BindView(R.id.bookmarkButton) LinearLayout bookmarkButton;
@BindView(R.id.wikipediaButton) LinearLayout wikipediaButton;
@BindView(R.id.wikidataButton) LinearLayout wikidataButton;
@BindView(R.id.directionsButton) LinearLayout directionsButton;
@BindView(R.id.commonsButton) LinearLayout commonsButton;
@BindView(R.id.description) TextView description;
@BindView(R.id.title) TextView title;
@BindView(R.id.category) TextView distance;
@BindView(R.id.icon) ImageView icon;
@BindView(R.id.search_this_area_button) Button searchThisAreaButton;
@BindView(R.id.map_progress_bar) ProgressBar progressBar;
@BindView(R.id.container_sheet) FrameLayout frameLayout;
@BindView(R.id.loading_nearby_list) ConstraintLayout loadingNearbyLayout;
@BindView(R.id.bottom_sheet_details) @Inject LocationServiceManager locationManager;
View bottomSheetDetails; @Inject NearbyController nearbyController;
@Inject @Named("default_preferences") JsonKvStore applicationKvStore;
@BindView(R.id.transparentView) @Inject BookmarkLocationsDao bookmarkLocationDao;
View transparentView; @Inject ContributionController controller;
@Inject WikidataEditListener wikidataEditListener;
@BindView(R.id.directionsButtonText)
TextView directionsButtonText;
@BindView(R.id.wikipediaButtonText)
TextView wikipediaButtonText;
@BindView(R.id.wikidataButtonText)
TextView wikidataButtonText;
@BindView(R.id.commonsButtonText)
TextView commonsButtonText;
@BindView(R.id.fab_plus)
FloatingActionButton fabPlus;
@BindView(R.id.fab_camera)
FloatingActionButton fabCamera;
@BindView(R.id.fab_gallery)
FloatingActionButton fabGallery;
@BindView(R.id.fab_recenter)
FloatingActionButton fabRecenter;
@BindView(R.id.bookmarkButtonImage)
ImageView bookmarkButtonImage;
@BindView(R.id.bookmarkButton)
LinearLayout bookmarkButton;
@BindView(R.id.wikipediaButton)
LinearLayout wikipediaButton;
@BindView(R.id.wikidataButton)
LinearLayout wikidataButton;
@BindView(R.id.directionsButton)
LinearLayout directionsButton;
@BindView(R.id.commonsButton)
LinearLayout commonsButton;
@BindView(R.id.description)
TextView description;
@BindView(R.id.title)
TextView title;
@BindView(R.id.category)
TextView distance;
@BindView(R.id.icon)
ImageView icon;
@BindView(R.id.search_this_area_button)
Button searchThisAreaButton;
@BindView(R.id.map_progress_bar)
ProgressBar progressBar;
@BindView(R.id.container_sheet)
FrameLayout frameLayout;
@BindView(R.id.loading_nearby_list)
ConstraintLayout loadingNearbyLayout;
@Inject
LocationServiceManager locationManager;
@Inject
NearbyController nearbyController;
@Inject
@Named("default_preferences")
JsonKvStore applicationKvStore;
@Inject
BookmarkLocationsDao bookmarkLocationDao;
@Inject
ContributionController controller;
@Inject
WikidataEditListener wikidataEditListener;
private BottomSheetBehavior bottomSheetListBehavior; private BottomSheetBehavior bottomSheetListBehavior;
private BottomSheetBehavior bottomSheetDetailsBehavior; private BottomSheetBehavior bottomSheetDetailsBehavior;
@ -182,31 +118,28 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
private Animation rotate_forward; private Animation rotate_forward;
private static final double ZOOM_LEVEL = 14f; private static final double ZOOM_LEVEL = 14f;
private final String NETWORK_INTENT_ACTION = "android.net.conn.CONNECTIVITY_CHANGE"; private final String NETWORK_INTENT_ACTION = "android.net.conn.CONNECTIVITY_CHANGE";
private BroadcastReceiver broadcastReceiver; private BroadcastReceiver broadcastReceiver;
private boolean isNetworkErrorOccurred = false; private boolean isNetworkErrorOccurred = false;
private Snackbar snackbar; private Snackbar snackbar;
FragmentTransaction transaction;
private View view; private View view;
public NearbyParentFragmentPresenter nearbyParentFragmentPresenter; public NearbyParentFragmentPresenter nearbyParentFragmentPresenter;
private boolean isDarkTheme; private boolean isDarkTheme;
private boolean isFabOpen; private boolean isFABsExpanded;
private Marker selectedMarker; private Marker selectedMarker;
private Place selectedPlace; private Place selectedPlace;
private final double CAMERA_TARGET_SHIFT_FACTOR_PORTRAIT = 0.005; private final double CAMERA_TARGET_SHIFT_FACTOR_PORTRAIT = 0.005;
private final double CAMERA_TARGET_SHIFT_FACTOR_LANDSCAPE = 0.004; private final double CAMERA_TARGET_SHIFT_FACTOR_LANDSCAPE = 0.004;
NearbyMapFragment nearbyMapFragment; private NearbyMapFragment nearbyMapFragment;
private NearbyListFragment nearbyListFragment; private NearbyListFragment nearbyListFragment;
public static final String TAG_RETAINED_MAP_FRAGMENT = NearbyMapFragment.class.getSimpleName(); public static final String TAG_RETAINED_MAP_FRAGMENT = NearbyMapFragment.class.getSimpleName();
public static final String TAG_RETAINED_LIST_FRAGMENT = NearbyListFragment.class.getSimpleName(); private static final String TAG_RETAINED_LIST_FRAGMENT = NearbyListFragment.class.getSimpleName();
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { Bundle savedInstanceState) {
view = inflater.inflate(R.layout.fragment_nearby_parent, container, false); view = inflater.inflate(R.layout.fragment_nearby_parent, container, false);
ButterKnife.bind(this, view); ButterKnife.bind(this, view);
@ -215,13 +148,6 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
} }
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
//initViews();
}
@Override @Override
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
@ -230,9 +156,8 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
} }
public void initViews() { private void initViews() {
Timber.d("init views called"); Timber.d("init views called");
//ButterKnife.bind(this, view);
bottomSheetListBehavior = BottomSheetBehavior.from(bottomSheetList); bottomSheetListBehavior = BottomSheetBehavior.from(bottomSheetList);
bottomSheetDetailsBehavior = BottomSheetBehavior.from(bottomSheetDetails); bottomSheetDetailsBehavior = BottomSheetBehavior.from(bottomSheetDetails);
bottomSheetDetailsBehavior.setState(BottomSheetBehavior.STATE_HIDDEN); bottomSheetDetailsBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
@ -252,25 +177,15 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
@Override @Override
public void onSlide(@NonNull View bottomSheet, float slideOffset) { public void onSlide(@NonNull View bottomSheet, float slideOffset) {
if (slideOffset >= 0) {
transparentView.setAlpha(slideOffset);
if (slideOffset == 1) {
transparentView.setClickable(true);
} else if (slideOffset == 0) {
transparentView.setClickable(false);
}
}
} }
}); });
bottomSheetDetails.setOnClickListener(new View.OnClickListener() { bottomSheetDetails.setOnClickListener(v -> {
@Override if (bottomSheetDetailsBehavior.getState() == BottomSheetBehavior.STATE_COLLAPSED) {
public void onClick(View v) { bottomSheetDetailsBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
if (bottomSheetDetailsBehavior.getState() == BottomSheetBehavior.STATE_COLLAPSED) { } else if (bottomSheetDetailsBehavior.getState() == BottomSheetBehavior.STATE_EXPANDED) {
bottomSheetDetailsBehavior.setState(BottomSheetBehavior.STATE_EXPANDED); bottomSheetDetailsBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
} else if (bottomSheetDetailsBehavior.getState() == BottomSheetBehavior.STATE_EXPANDED) {
bottomSheetDetailsBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
}
} }
}); });
@ -301,12 +216,14 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
commonsButtonText.setVisibility(View.GONE); commonsButtonText.setVisibility(View.GONE);
directionsButtonText.setVisibility(View.GONE); directionsButtonText.setVisibility(View.GONE);
} }
title.setOnLongClickListener(view -> { title.setOnLongClickListener(view -> {
Utils.copy("place", title.getText().toString(), getContext()); Utils.copy("place", title.getText().toString(), getContext());
Toast.makeText(getContext(), "Text copied to clipboard", Toast.LENGTH_SHORT).show(); Toast.makeText(getContext(), "Text copied to clipboard", Toast.LENGTH_SHORT).show();
return true; return true;
} }
); );
title.setOnClickListener(view -> { title.setOnClickListener(view -> {
if (bottomSheetDetailsBehavior.getState() == BottomSheetBehavior.STATE_COLLAPSED) { if (bottomSheetDetailsBehavior.getState() == BottomSheetBehavior.STATE_COLLAPSED) {
bottomSheetDetailsBehavior.setState(BottomSheetBehavior.STATE_EXPANDED); bottomSheetDetailsBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
@ -314,11 +231,10 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
bottomSheetDetailsBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED); bottomSheetDetailsBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
} }
}); });
} }
/** /**
* Returns the map fragment added to child fragment manager previously, if exists. * Returns the list fragment added to child fragment manager previously, if exists.
*/ */
private NearbyListFragment getListFragment() { private NearbyListFragment getListFragment() {
NearbyListFragment existingFragment = (NearbyListFragment) getChildFragmentManager() NearbyListFragment existingFragment = (NearbyListFragment) getChildFragmentManager()
@ -341,88 +257,62 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
return existingFragment; return existingFragment;
} }
public NearbyMapFragment setMapFragment() { /**
* Creates the map fragment and prepares map
* @return the map fragment created
*/
private NearbyMapFragment setMapFragment() {
// Mapbox access token is configured here. This needs to be called either in your application // Mapbox access token is configured here. This needs to be called either in your application
// object or in the same activity which contains the mapview. // object or in the same activity which contains the mapview.
Mapbox.getInstance(getActivity(), getString(R.string.mapbox_commons_app_token)); Mapbox.getInstance(getActivity(), getString(R.string.mapbox_commons_app_token));
NearbyMapFragment mapFragment; NearbyMapFragment mapFragment;
// Create supportMapFragment
//if (savedInstanceState == null) {
// Create fragment // Create fragment
transaction = getChildFragmentManager().beginTransaction(); FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
// Build mapboxMap // Build mapboxMap
isDarkTheme = applicationKvStore.getBoolean("theme", false); isDarkTheme = applicationKvStore.getBoolean("theme", false);
MapboxMapOptions options = new MapboxMapOptions() MapboxMapOptions options = new MapboxMapOptions()
.compassGravity(Gravity.BOTTOM | Gravity.LEFT) .compassGravity(Gravity.BOTTOM | Gravity.LEFT)
.compassMargins(new int[]{12, 0, 0, 24}) .compassMargins(new int[]{12, 0, 0, 24})
//.styleUrl(isDarkTheme ? Style.DARK : Style.OUTDOORS) //.styleUrl(isDarkTheme ? Style.DARK : Style.OUTDOORS)
.logoEnabled(false) .logoEnabled(false)
.attributionEnabled(false) .attributionEnabled(false)
.camera(new CameraPosition.Builder() .camera(new CameraPosition.Builder()
.zoom(ZOOM_LEVEL) .zoom(ZOOM_LEVEL)
.target(new com.mapbox.mapboxsdk.geometry.LatLng(-52.6885, -70.1395)) .target(new com.mapbox.mapboxsdk.geometry.LatLng(-52.6885, -70.1395))
.build()); .build());
// Create map fragment // Create map fragment
mapFragment = NearbyMapFragment.newInstance(options); mapFragment = NearbyMapFragment.newInstance(options);
// Add map fragment to parent container // Add map fragment to parent container
getChildFragmentManager().executePendingTransactions(); getChildFragmentManager().executePendingTransactions();
transaction.add(R.id.container, mapFragment, TAG_RETAINED_MAP_FRAGMENT); transaction.add(R.id.container, mapFragment, TAG_RETAINED_MAP_FRAGMENT);
transaction.commit(); transaction.commit();
/*} else {
nearbyMapFragment = (NearbyMapFragment) getChildFragmentManager().findFragmentByTag(TAG_RETAINED_MAP_FRAGMENT);
}*/
mapFragment.getMapAsync(new OnMapReadyCallback() { mapFragment.getMapAsync(mapboxMap ->
@Override mapboxMap.setStyle(
public void onMapReady(@NonNull MapboxMap mapboxMap) { NearbyParentFragment.this.isDarkTheme ? Style.DARK : Style.OUTDOORS, style -> {
NearbyParentFragment.this.childMapFragmentAttached();
mapboxMap.setStyle(NearbyParentFragment.this.isDarkTheme ? Style.DARK : Style.OUTDOORS, new Style.OnStyleLoaded() { // Map is set up and the style has loaded. Now you can add data or make other map adjustments
@Override }));
public void onStyleLoaded(@NonNull Style style) {
NearbyParentFragment.this.childMapFragmentAttached();
Log.d("NearbyTests","Fragment inside fragment with map works");
// Map is set up and the style has loaded. Now you can add data or make other map adjustments
}
});
}
});
return mapFragment; return mapFragment;
} }
public void centerMapToPlace(Place place) { /**
Log.d("denemeson","place:"+place); * Creates the list fragment and put it into container
if (nearbyMapFragment != null) { * @return the list fragment created
nearbyParentFragmentPresenter.centerMapToPlace(place, */
getActivity().getResources().getConfiguration().orientation == private NearbyListFragment setListFragment() {
Configuration.ORIENTATION_PORTRAIT);
/*nearbyMapFragment.centerMapToPlace(
place,
getActivity().getResources().getConfiguration().orientation ==
Configuration.ORIENTATION_PORTRAIT);*/
}
}
NearbyListFragment setListFragment() {
///if (savedInstanceState == null) {
NearbyListFragment nearbyListFragment; NearbyListFragment nearbyListFragment;
loadingNearbyLayout.setVisibility(View.GONE); loadingNearbyLayout.setVisibility(View.GONE);
frameLayout.setVisibility(View.VISIBLE); frameLayout.setVisibility(View.VISIBLE);
FragmentTransaction fragmentTransaction = getChildFragmentManager().beginTransaction(); FragmentTransaction fragmentTransaction = getChildFragmentManager().beginTransaction();
nearbyListFragment = new NearbyListFragment(); nearbyListFragment = new NearbyListFragment();
nearbyListFragment.setArguments(null); nearbyListFragment.setArguments(null);
fragmentTransaction.replace(R.id.container_sheet, nearbyListFragment, TAG_RETAINED_LIST_FRAGMENT); fragmentTransaction.replace(R.id.container_sheet, nearbyListFragment, TAG_RETAINED_LIST_FRAGMENT);
// initBottomSheetBehaviour(); fragmentTransaction.commitAllowingStateLoss();
//bottomSheetListBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
fragmentTransaction.commitAllowingStateLoss();
/*} else {
nearbyListFragment = (NearbyListFragment) getChildFragmentManager().findFragmentByTag(TAG_RETAINED_LIST_FRAGMENT);
}*/
return nearbyListFragment; return nearbyListFragment;
} }
@ -442,26 +332,35 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
} }
} }
/**
* Calls presenter to center map to any place
* @param place the place we want to center map
*/
public void centerMapToPlace(Place place) {
if (nearbyMapFragment != null) {
nearbyParentFragmentPresenter.centerMapToPlace(place,
getActivity().getResources().getConfiguration().orientation ==
Configuration.ORIENTATION_PORTRAIT);
}
}
/** /**
* Thanks to this method we make sure NearbyMapFragment is ready and attached. So that we can * Thanks to this method we make sure NearbyMapFragment is ready and attached. So that we can
* prevent NPE caused by null child fragment. This method is called from child fragment when * prevent NPE caused by null child fragment. This method is called from child fragment when
* it is attached. * it is attached.
*/ */
public void childMapFragmentAttached() { private void childMapFragmentAttached() {
Timber.d("Child map fragment attached");
Log.d("denemeTest","this:"+this+", location manager is:"+locationManager);
nearbyParentFragmentPresenter = new NearbyParentFragmentPresenter nearbyParentFragmentPresenter = new NearbyParentFragmentPresenter
(nearbyListFragment,this, nearbyMapFragment, locationManager); (nearbyListFragment,this, nearbyMapFragment, locationManager);
Timber.d("Child fragment attached");
nearbyParentFragmentPresenter.nearbyFragmentsAreReady(); nearbyParentFragmentPresenter.nearbyFragmentsAreReady();
initViews(); initViews();
nearbyParentFragmentPresenter.setActionListeners(applicationKvStore); nearbyParentFragmentPresenter.setActionListeners(applicationKvStore);
} }
@Override @Override
public void addOnCameraMoveListener(MapboxMap.OnCameraMoveListener onCameraMoveListener) { public void addOnCameraMoveListener(MapboxMap.OnCameraMoveListener onCameraMoveListener) {
Log.d("denemeTestt","on camera move listener is set");
nearbyMapFragment.getMapboxMap().addOnCameraMoveListener(onCameraMoveListener); nearbyMapFragment.getMapboxMap().addOnCameraMoveListener(onCameraMoveListener);
} }
@ -475,20 +374,16 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
return NetworkUtils.isInternetConnectionEstablished(getActivity()); return NetworkUtils.isInternetConnectionEstablished(getActivity());
} }
/** /**
* Adds network broadcast receiver to recognize connection established * Adds network broadcast receiver to recognize connection established
*/ */
@Override @Override
public void addNetworkBroadcastReceiver() { public void addNetworkBroadcastReceiver() {
Log.d("denemeTest","addNetworkBroadcastReceiver");
if (!FragmentUtils.isFragmentUIActive(this)) { if (!FragmentUtils.isFragmentUIActive(this)) {
Log.d("denemeTest","!FragmentUtils.isFragmentUIActive(this)");
return; return;
} }
if (broadcastReceiver != null) { if (broadcastReceiver != null) {
Log.d("denemeTest","broadcastReceiver != null");
return; return;
} }
@ -499,9 +394,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
if (getActivity() != null) { if (getActivity() != null) {
if (NetworkUtils.isInternetConnectionEstablished(getActivity())) { if (NetworkUtils.isInternetConnectionEstablished(getActivity())) {
Log.d("denemeTest","NetworkUtils.isInternetConnectionEstablished(getActivity())");
if (isNetworkErrorOccurred) { if (isNetworkErrorOccurred) {
Log.d("denemeTest","isNetworkErrorOccurred");
nearbyParentFragmentPresenter.updateMapAndList(LOCATION_SIGNIFICANTLY_CHANGED, null); nearbyParentFragmentPresenter.updateMapAndList(LOCATION_SIGNIFICANTLY_CHANGED, null);
isNetworkErrorOccurred = false; isNetworkErrorOccurred = false;
} }
@ -513,7 +406,8 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
} else { } else {
if (snackbar == null) { if (snackbar == null) {
snackbar = Snackbar.make(view, R.string.no_internet, Snackbar.LENGTH_INDEFINITE); snackbar = Snackbar.make(view, R.string.no_internet, Snackbar.LENGTH_INDEFINITE);
// TODO make search this area button invisible setSearchThisAreaButtonVisibility(false);
setProgressBarVisibility(false);
} }
isNetworkErrorOccurred = true; isNetworkErrorOccurred = true;
@ -544,7 +438,6 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
public void populatePlaces(fr.free.nrw.commons.location.LatLng curlatLng, fr.free.nrw.commons.location.LatLng searchLatLng) { public void populatePlaces(fr.free.nrw.commons.location.LatLng curlatLng, fr.free.nrw.commons.location.LatLng searchLatLng) {
boolean checkingAroundCurretLocation; boolean checkingAroundCurretLocation;
if (curlatLng.equals(searchLatLng)) { // Means we are checking around current location if (curlatLng.equals(searchLatLng)) { // Means we are checking around current location
Log.d("denemeTestt","checking around current location1");
checkingAroundCurretLocation = true; checkingAroundCurretLocation = true;
compositeDisposable.add(Observable.fromCallable(() -> nearbyController compositeDisposable.add(Observable.fromCallable(() -> nearbyController
.loadAttractionsFromLocation(curlatLng, searchLatLng, false, checkingAroundCurretLocation)) .loadAttractionsFromLocation(curlatLng, searchLatLng, false, checkingAroundCurretLocation))
@ -553,13 +446,11 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
.subscribe(this::updateMapMarkers, .subscribe(this::updateMapMarkers,
throwable -> { throwable -> {
Timber.d(throwable); Timber.d(throwable);
//showErrorMessage(getString(R.string.error_fetching_nearby_places)); showErrorMessage(getString(R.string.error_fetching_nearby_places));
// TODO solve first unneeded method call here setProgressBarVisibility(false);
//progressBar.setVisibility(View.GONE); nearbyParentFragmentPresenter.lockUnlockNearby(false);
//nearbyParentFragmentPresenter.lockUnlockNearby(false);
})); }));
} else { } else {
Log.d("denemeTestt","not checking around current location2");
checkingAroundCurretLocation = false; checkingAroundCurretLocation = false;
compositeDisposable.add(Observable.fromCallable(() -> nearbyController compositeDisposable.add(Observable.fromCallable(() -> nearbyController
.loadAttractionsFromLocation(curlatLng, searchLatLng, false, checkingAroundCurretLocation)) .loadAttractionsFromLocation(curlatLng, searchLatLng, false, checkingAroundCurretLocation))
@ -568,10 +459,9 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
.subscribe(this::updateMapMarkersForCustomLocation, .subscribe(this::updateMapMarkersForCustomLocation,
throwable -> { throwable -> {
Timber.d(throwable); Timber.d(throwable);
//showErrorMessage(getString(R.string.error_fetching_nearby_places)); showErrorMessage(getString(R.string.error_fetching_nearby_places));
// TODO solve first unneeded method call here setProgressBarVisibility(false);
//progressBar.setVisibility(View.GONE); nearbyParentFragmentPresenter.lockUnlockNearby(false);
//nearbyParentFragmentPresenter.lockUnlockNearby(false);
})); }));
} }
} }
@ -600,10 +490,12 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
return bottomSheetListBehavior.getState() == BottomSheetBehavior.STATE_EXPANDED; return bottomSheetListBehavior.getState() == BottomSheetBehavior.STATE_EXPANDED;
} }
@Override
public boolean isDetailsBottomSheetVisible() { public boolean isDetailsBottomSheetVisible() {
return !(bottomSheetDetailsBehavior.getState() == BottomSheetBehavior.STATE_HIDDEN); return !(bottomSheetDetailsBehavior.getState() == BottomSheetBehavior.STATE_HIDDEN);
} }
@Override
public void setBottomSheetDetailsSmaller() { public void setBottomSheetDetailsSmaller() {
if (bottomSheetDetailsBehavior.getState() == BottomSheetBehavior.STATE_EXPANDED) { if (bottomSheetDetailsBehavior.getState() == BottomSheetBehavior.STATE_EXPANDED) {
bottomSheetDetailsBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED); bottomSheetDetailsBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
@ -642,7 +534,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
@Override @Override
public void checkPermissionsAndPerformAction(Runnable runnable) { public void checkPermissionsAndPerformAction(Runnable runnable) {
Log.d("denemeTest","checkPermissionsAndPerformAction is called"); Timber.d("Checking permission and perfoming action");
PermissionUtils.checkPermissionsAndPerformAction(getActivity(), PermissionUtils.checkPermissionsAndPerformAction(getActivity(),
Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION,
runnable, runnable,
@ -651,35 +543,16 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
R.string.location_permission_rationale_nearby); R.string.location_permission_rationale_nearby);
} }
@Override
public void resumeFragment() {
}
/** /**
* Starts animation of fab plus (turning on opening) and other FABs * Starts animation of fab plus (turning on opening) and other FABs
*/ */
@Override @Override
public void animateFABs() { public void animateFABs() {
if (fabPlus.isShown()){ if (fabPlus.isShown()){
/*if (isFabOpen) { if (isFABsExpanded) {
fabPlus.startAnimation(rotate_backward); collapseFABs(isFABsExpanded);
fabCamera.startAnimation(fab_close);
fabGallery.startAnimation(fab_close);
fabCamera.hide();
fabGallery.hide();
} else { } else {
fabPlus.startAnimation(rotate_forward); expandFABs(isFABsExpanded);
fabCamera.startAnimation(fab_open);
fabGallery.startAnimation(fab_open);
fabCamera.show();
fabGallery.show();
}
this.isFabOpen=!isFabOpen;*/
if (isFabOpen) {
closeFABs(isFabOpen);
} else {
openFABs(isFabOpen);
} }
} }
} }
@ -692,18 +565,18 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
} }
/** /**
* Hides camera and gallery FABs, turn back plus FAB * Expands camera and gallery FABs, turn forward plus FAB
* @param isFabOpen * @param isFABsExpanded true if they are already expanded
*/ */
private void openFABs( boolean isFabOpen){ private void expandFABs(boolean isFABsExpanded){
if (!isFabOpen) { if (!isFABsExpanded) {
showFABs(); showFABs();
fabPlus.startAnimation(rotate_forward); fabPlus.startAnimation(rotate_forward);
fabCamera.startAnimation(fab_open); fabCamera.startAnimation(fab_open);
fabGallery.startAnimation(fab_open); fabGallery.startAnimation(fab_open);
fabCamera.show(); fabCamera.show();
fabGallery.show(); fabGallery.show();
this.isFabOpen = true; this.isFABsExpanded = true;
} }
} }
@ -720,17 +593,17 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
} }
/** /**
* Hides camera and gallery FABs, turn back plus FAB * Collapses camera and gallery FABs, turn back plus FAB
* @param isFabOpen * @param isFABsExpanded
*/ */
private void closeFABs( boolean isFabOpen){ private void collapseFABs(boolean isFABsExpanded){
if (isFabOpen) { if (isFABsExpanded) {
fabPlus.startAnimation(rotate_backward); fabPlus.startAnimation(rotate_backward);
fabCamera.startAnimation(fab_close); fabCamera.startAnimation(fab_close);
fabGallery.startAnimation(fab_close); fabGallery.startAnimation(fab_close);
fabCamera.hide(); fabCamera.hide();
fabGallery.hide(); fabGallery.hide();
this.isFabOpen = false; this.isFABsExpanded = false;
} }
} }
@ -821,7 +694,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
switch (bottomSheetState) { switch (bottomSheetState) {
case (BottomSheetBehavior.STATE_COLLAPSED): case (BottomSheetBehavior.STATE_COLLAPSED):
closeFABs(isFabOpen); collapseFABs(isFABsExpanded);
if (!fabPlus.isShown()) showFABs(); if (!fabPlus.isShown()) showFABs();
this.getView().requestFocus(); this.getView().requestFocus();
break; break;
@ -832,7 +705,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
nearbyMapFragment.getMapboxMap().deselectMarkers(); nearbyMapFragment.getMapboxMap().deselectMarkers();
transparentView.setClickable(false); transparentView.setClickable(false);
transparentView.setAlpha(0); transparentView.setAlpha(0);
closeFABs(isFabOpen); collapseFABs(isFABsExpanded);
hideFABs(); hideFABs();
if (this.getView() != null) { if (this.getView() != null) {
this.getView().requestFocus(); this.getView().requestFocus();
@ -946,4 +819,8 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
} }
} }
private void showErrorMessage(String message) {
ViewUtil.showLongToast(getActivity(), message);
}
} }