From be1ca1a2ae6e635d92dfc844e5597d5d9d785433 Mon Sep 17 00:00:00 2001 From: neslihanturan Date: Thu, 12 Sep 2019 17:19:43 +0300 Subject: [PATCH] Fix progress bar visibility issue --- .../commons/nearby/NearbyTestLayersFragment.java | 16 +++++----------- .../contract/NearbyParentFragmentContract.java | 2 +- .../mvp/fragments/NearbyParentFragment.java | 10 ++-------- .../presenter/NearbyParentFragmentPresenter.java | 14 ++++++++------ app/src/main/res/layout/fragment_nearby.xml | 2 +- app/src/main/res/layout/fragment_simple.xml | 3 ++- 6 files changed, 19 insertions(+), 28 deletions(-) diff --git a/app/src/main/java/fr/free/nrw/commons/nearby/NearbyTestLayersFragment.java b/app/src/main/java/fr/free/nrw/commons/nearby/NearbyTestLayersFragment.java index efee6fe4c..97e8c18e6 100644 --- a/app/src/main/java/fr/free/nrw/commons/nearby/NearbyTestLayersFragment.java +++ b/app/src/main/java/fr/free/nrw/commons/nearby/NearbyTestLayersFragment.java @@ -23,7 +23,6 @@ import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentTransaction; import com.google.android.material.bottomsheet.BottomSheetBehavior; @@ -44,19 +43,15 @@ 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.Utils; import fr.free.nrw.commons.bookmarks.locations.BookmarkLocationsDao; import fr.free.nrw.commons.contributions.ContributionController; -import fr.free.nrw.commons.contributions.MainActivity; import fr.free.nrw.commons.di.CommonsDaggerSupportFragment; import fr.free.nrw.commons.kvstore.JsonKvStore; import fr.free.nrw.commons.location.LocationServiceManager; import fr.free.nrw.commons.nearby.mvp.contract.NearbyParentFragmentContract; -import fr.free.nrw.commons.nearby.mvp.fragments.NearbyParentFragment; import fr.free.nrw.commons.nearby.mvp.presenter.NearbyParentFragmentPresenter; -import fr.free.nrw.commons.theme.NavigationBaseActivity; import fr.free.nrw.commons.utils.FragmentUtils; import fr.free.nrw.commons.utils.NearbyFABUtils; import fr.free.nrw.commons.utils.NetworkUtils; @@ -67,7 +62,6 @@ import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.schedulers.Schedulers; import timber.log.Timber; -import static fr.free.nrw.commons.contributions.ContributionsFragment.CONTRIBUTION_LIST_FRAGMENT_TAG; import static fr.free.nrw.commons.location.LocationServiceManager.LocationChangeType.LOCATION_SIGNIFICANTLY_CHANGED; import static fr.free.nrw.commons.nearby.NearbyTestFragmentLayersActivity.CONTRIBUTIONS_TAB_POSITION; @@ -140,8 +134,8 @@ public class NearbyTestLayersFragment extends CommonsDaggerSupportFragment imple @BindView(R.id.search_this_area_button) Button searchThisAreaButton; - @BindView(R.id.search_this_area_button_progress_bar) - ProgressBar searchThisAreaButtonProgressBar; + @BindView(R.id.map_progress_bar) + ProgressBar progressBar; @Inject LocationServiceManager locationManager; @@ -506,11 +500,11 @@ public class NearbyTestLayersFragment extends CommonsDaggerSupportFragment imple } @Override - public void setSearchThisAreaProgressVisibility(boolean isVisible) { + public void setProgressBarVisibility(boolean isVisible) { if (isVisible) { - searchThisAreaButtonProgressBar.setVisibility(View.VISIBLE); + progressBar.setVisibility(View.VISIBLE); } else { - searchThisAreaButtonProgressBar.setVisibility(View.GONE); + progressBar.setVisibility(View.GONE); } } diff --git a/app/src/main/java/fr/free/nrw/commons/nearby/mvp/contract/NearbyParentFragmentContract.java b/app/src/main/java/fr/free/nrw/commons/nearby/mvp/contract/NearbyParentFragmentContract.java index 2aa00a970..e5ec8bba0 100644 --- a/app/src/main/java/fr/free/nrw/commons/nearby/mvp/contract/NearbyParentFragmentContract.java +++ b/app/src/main/java/fr/free/nrw/commons/nearby/mvp/contract/NearbyParentFragmentContract.java @@ -35,7 +35,7 @@ public interface NearbyParentFragmentContract { void addOnCameraMoveListener(MapboxMap.OnCameraMoveListener onCameraMoveListener); void addSearchThisAreaButtonAction(); void setSearchThisAreaButtonVisibility(boolean isVisible); - void setSearchThisAreaProgressVisibility(boolean isVisible); + void setProgressBarVisibility(boolean isVisible); } interface UserActions { diff --git a/app/src/main/java/fr/free/nrw/commons/nearby/mvp/fragments/NearbyParentFragment.java b/app/src/main/java/fr/free/nrw/commons/nearby/mvp/fragments/NearbyParentFragment.java index d9351cf11..45d365fdd 100644 --- a/app/src/main/java/fr/free/nrw/commons/nearby/mvp/fragments/NearbyParentFragment.java +++ b/app/src/main/java/fr/free/nrw/commons/nearby/mvp/fragments/NearbyParentFragment.java @@ -7,7 +7,6 @@ import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.res.Configuration; -import android.os.Build; import android.os.Bundle; import android.util.Log; import android.view.LayoutInflater; @@ -33,7 +32,6 @@ import javax.inject.Inject; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.appcompat.app.AlertDialog; import androidx.constraintlayout.widget.ConstraintLayout; import androidx.fragment.app.FragmentTransaction; import butterknife.BindView; @@ -43,12 +41,10 @@ import fr.free.nrw.commons.contributions.MainActivity; import fr.free.nrw.commons.di.CommonsDaggerSupportFragment; import fr.free.nrw.commons.location.LatLng; import fr.free.nrw.commons.location.LocationServiceManager; -import fr.free.nrw.commons.location.LocationUpdateListener; import fr.free.nrw.commons.nearby.NearbyController; import fr.free.nrw.commons.nearby.mvp.contract.NearbyParentFragmentContract; import fr.free.nrw.commons.nearby.mvp.presenter.NearbyParentFragmentPresenter; import fr.free.nrw.commons.utils.FragmentUtils; -import fr.free.nrw.commons.utils.LocationUtils; import fr.free.nrw.commons.utils.NetworkUtils; import fr.free.nrw.commons.utils.PermissionUtils; import fr.free.nrw.commons.wikidata.WikidataEditListener; @@ -58,9 +54,7 @@ import io.reactivex.schedulers.Schedulers; import timber.log.Timber; import static fr.free.nrw.commons.contributions.MainActivity.CONTRIBUTIONS_TAB_POSITION; -import static fr.free.nrw.commons.contributions.MainActivity.NEARBY_TAB_POSITION; import static fr.free.nrw.commons.location.LocationServiceManager.LocationChangeType.LOCATION_SIGNIFICANTLY_CHANGED; -import static fr.free.nrw.commons.location.LocationServiceManager.LocationChangeType.SEARCH_CUSTOM_AREA; /** * This fragment is under MainActivity at the came level with ContributionFragment and holds @@ -84,7 +78,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment ConstraintLayout loadingNearbyLayout; @BindView(R.id.search_this_area_button) Button searchThisAreaButton; - @BindView(R.id.search_this_area_button_progress_bar) + @BindView(R.id.progress_bar) ProgressBar searchThisAreaButtonProgressBar; @Inject @@ -187,7 +181,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment } @Override - public void setSearchThisAreaProgressVisibility(boolean isVisible) { + public void setProgressBarVisibility(boolean isVisible) { if (isVisible) { searchThisAreaButtonProgressBar.setVisibility(View.VISIBLE); } else { diff --git a/app/src/main/java/fr/free/nrw/commons/nearby/mvp/presenter/NearbyParentFragmentPresenter.java b/app/src/main/java/fr/free/nrw/commons/nearby/mvp/presenter/NearbyParentFragmentPresenter.java index d0c146bb0..efa10114f 100644 --- a/app/src/main/java/fr/free/nrw/commons/nearby/mvp/presenter/NearbyParentFragmentPresenter.java +++ b/app/src/main/java/fr/free/nrw/commons/nearby/mvp/presenter/NearbyParentFragmentPresenter.java @@ -99,6 +99,7 @@ public class NearbyParentFragmentPresenter */ @Override public void initializeNearbyOperations() { + // TODO: do not update every time user selected tab Timber.d("initializing nearby operations started"); // Add location listener to be notified about location changes //locationServiceManager.addLocationListener(this); @@ -259,8 +260,8 @@ public class NearbyParentFragmentPresenter || locationChangeType.equals(MAP_UPDATED)) { Log.d("denemeTest","1"); lockUnlockNearby(true); + nearbyParentFragmentView.setProgressBarVisibility(true); nearbyParentFragmentView.populatePlaces(lastLocation, lastLocation); - nearbyParentFragmentView.setSearchThisAreaProgressVisibility(false); //nearbyMapFragmentView.updateMapToTrackPosition(curLatLng); // TODO: when unneeded populate places call problem is solved, open commented out line and remove it from update map markers method // TODO dont forget map updated state after an wikidata item is updated @@ -268,8 +269,8 @@ public class NearbyParentFragmentPresenter } else if (locationChangeType.equals(SEARCH_CUSTOM_AREA)) { Log.d("denemeTest","2"); lockUnlockNearby(true); + nearbyParentFragmentView.setProgressBarVisibility(true); nearbyParentFragmentView.populatePlaces(lastLocation, cameraTarget); - nearbyParentFragmentView.setSearchThisAreaProgressVisibility(false); searchingThisArea = false; } else { // Means location changed slightly, ie user is walking or driving. Log.d("denemeTest","3"); @@ -290,6 +291,7 @@ public class NearbyParentFragmentPresenter nearbyMapFragmentView.addCurrentLocationMarker(nearbyPlacesInfo.curLatLng); nearbyMapFragmentView.updateMapToTrackPosition(nearbyPlacesInfo.curLatLng); lockUnlockNearby(false); // So that new location updates wont come + nearbyParentFragmentView.setProgressBarVisibility(false); } /** @@ -301,6 +303,8 @@ public class NearbyParentFragmentPresenter nearbyMapFragmentView.updateMapMarkers(nearbyPlacesInfo.curLatLng, nearbyPlacesInfo.placeList, selectedMarker, this); nearbyMapFragmentView.addCurrentLocationMarker(nearbyPlacesInfo.curLatLng); lockUnlockNearby(false); // So that new location updates wont come + nearbyParentFragmentView.setProgressBarVisibility(false); + } @Override @@ -336,7 +340,8 @@ public class NearbyParentFragmentPresenter // If our nearby markers are calculated at least once if (NearbyController.currentLocation != null) { Log.d("denemeTestt","NearbyController.currentLocation != null"); - double distance = mapboxMap.getCameraPosition().target.distanceTo + double distance = mapboxMap.getCameraPosition().target.distanceTo + //TODO: test this distances (LocationUtils.commonsLatLngToMapBoxLatLng(NearbyController.latestSearchLocation)); if (nearbyParentFragmentView.isNetworkConnectionEstablished()) { if (distance > NearbyController.latestSearchRadius) { @@ -359,9 +364,6 @@ public class NearbyParentFragmentPresenter public void onClick(View v) { Log.d("denemeTestt","onSearchThisAreaClicked"); // Lock map operations during search this area operation - // TODO: test lock nearby - nearbyParentFragmentView.setSearchThisAreaProgressVisibility(true); - // TODO: make this invisible at somewhere nearbyParentFragmentView.setSearchThisAreaButtonVisibility(false); if (searchCloseToCurrentLocation()){ diff --git a/app/src/main/res/layout/fragment_nearby.xml b/app/src/main/res/layout/fragment_nearby.xml index 0baed1ff6..1e493e110 100644 --- a/app/src/main/res/layout/fragment_nearby.xml +++ b/app/src/main/res/layout/fragment_nearby.xml @@ -83,7 +83,7 @@ app:elevation="6dp" />