mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 04:43:54 +01:00
Register location manager accoring to permission is given, then call nearby card view updater methods
This commit is contained in:
parent
23e1aa7ca4
commit
735b4430c6
1 changed files with 62 additions and 12 deletions
|
|
@ -48,16 +48,20 @@ import fr.free.nrw.commons.location.LocationServiceManager;
|
||||||
import fr.free.nrw.commons.location.LocationUpdateListener;
|
import fr.free.nrw.commons.location.LocationUpdateListener;
|
||||||
import fr.free.nrw.commons.media.MediaDetailPagerFragment;
|
import fr.free.nrw.commons.media.MediaDetailPagerFragment;
|
||||||
import fr.free.nrw.commons.mwapi.MediaWikiApi;
|
import fr.free.nrw.commons.mwapi.MediaWikiApi;
|
||||||
|
import fr.free.nrw.commons.nearby.NearbyController;
|
||||||
import fr.free.nrw.commons.nearby.NearbyNoificationCardView;
|
import fr.free.nrw.commons.nearby.NearbyNoificationCardView;
|
||||||
import fr.free.nrw.commons.nearby.NearbyPlaces;
|
import fr.free.nrw.commons.nearby.NearbyPlaces;
|
||||||
|
import fr.free.nrw.commons.nearby.Place;
|
||||||
import fr.free.nrw.commons.notification.Notification;
|
import fr.free.nrw.commons.notification.Notification;
|
||||||
import fr.free.nrw.commons.notification.NotificationController;
|
import fr.free.nrw.commons.notification.NotificationController;
|
||||||
import fr.free.nrw.commons.notification.UnreadNotificationsCheckAsync;
|
import fr.free.nrw.commons.notification.UnreadNotificationsCheckAsync;
|
||||||
import fr.free.nrw.commons.settings.Prefs;
|
import fr.free.nrw.commons.settings.Prefs;
|
||||||
import fr.free.nrw.commons.upload.UploadService;
|
import fr.free.nrw.commons.upload.UploadService;
|
||||||
import fr.free.nrw.commons.utils.ContributionListViewUtils;
|
import fr.free.nrw.commons.utils.ContributionListViewUtils;
|
||||||
|
import io.reactivex.Observable;
|
||||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||||
import io.reactivex.disposables.CompositeDisposable;
|
import io.reactivex.disposables.CompositeDisposable;
|
||||||
|
import io.reactivex.disposables.Disposable;
|
||||||
import io.reactivex.schedulers.Schedulers;
|
import io.reactivex.schedulers.Schedulers;
|
||||||
import timber.log.Timber;
|
import timber.log.Timber;
|
||||||
|
|
||||||
|
|
@ -66,6 +70,7 @@ import static fr.free.nrw.commons.contributions.ContributionDao.Table.ALL_FIELDS
|
||||||
import static fr.free.nrw.commons.contributions.ContributionsContentProvider.BASE_URI;
|
import static fr.free.nrw.commons.contributions.ContributionsContentProvider.BASE_URI;
|
||||||
import static fr.free.nrw.commons.location.LocationServiceManager.LOCATION_REQUEST;
|
import static fr.free.nrw.commons.location.LocationServiceManager.LOCATION_REQUEST;
|
||||||
import static fr.free.nrw.commons.settings.Prefs.UPLOADS_SHOWING;
|
import static fr.free.nrw.commons.settings.Prefs.UPLOADS_SHOWING;
|
||||||
|
import static fr.free.nrw.commons.utils.LengthUtils.formatDistanceBetween;
|
||||||
|
|
||||||
public class ContributionsFragment
|
public class ContributionsFragment
|
||||||
extends CommonsDaggerSupportFragment
|
extends CommonsDaggerSupportFragment
|
||||||
|
|
@ -85,6 +90,8 @@ public class ContributionsFragment
|
||||||
MediaWikiApi mediaWikiApi;
|
MediaWikiApi mediaWikiApi;
|
||||||
@Inject
|
@Inject
|
||||||
NotificationController notificationController;
|
NotificationController notificationController;
|
||||||
|
@Inject
|
||||||
|
NearbyController nearbyController;
|
||||||
|
|
||||||
private ArrayList<DataSetObserver> observersWaitingForLoad = new ArrayList<>();
|
private ArrayList<DataSetObserver> observersWaitingForLoad = new ArrayList<>();
|
||||||
private Cursor allContributions;
|
private Cursor allContributions;
|
||||||
|
|
@ -99,8 +106,11 @@ public class ContributionsFragment
|
||||||
public static final String MEDIA_DETAIL_PAGER_FRAGMENT_TAG = "MediaDetailFragmentTag";
|
public static final String MEDIA_DETAIL_PAGER_FRAGMENT_TAG = "MediaDetailFragmentTag";
|
||||||
|
|
||||||
public NearbyNoificationCardView nearbyNoificationCardView;
|
public NearbyNoificationCardView nearbyNoificationCardView;
|
||||||
|
private Disposable placesDisposable;
|
||||||
|
private LatLng curLatLng;
|
||||||
|
|
||||||
/**
|
|
||||||
|
/**
|
||||||
* Since we will need to use parent activity on onAuthCookieAcquired, we have to wait
|
* Since we will need to use parent activity on onAuthCookieAcquired, we have to wait
|
||||||
* fragment to be attached. Latch will be responsible for this sync.
|
* fragment to be attached. Latch will be responsible for this sync.
|
||||||
*/
|
*/
|
||||||
|
|
@ -285,6 +295,9 @@ public class ContributionsFragment
|
||||||
Timber.d("Location permission granted, refreshing view");
|
Timber.d("Location permission granted, refreshing view");
|
||||||
// No need to display permission request button anymore
|
// No need to display permission request button anymore
|
||||||
nearbyNoificationCardView.displayPermissionRequestButton(false);
|
nearbyNoificationCardView.displayPermissionRequestButton(false);
|
||||||
|
((ContributionsActivity)getActivity()).locationManager.registerLocationManager();
|
||||||
|
Log.d("deneme","location manager registered, location manager:"+((ContributionsActivity)getActivity()).locationManager);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// Still ask for permission
|
// Still ask for permission
|
||||||
nearbyNoificationCardView.displayPermissionRequestButton(true);
|
nearbyNoificationCardView.displayPermissionRequestButton(true);
|
||||||
|
|
@ -427,18 +440,9 @@ public class ContributionsFragment
|
||||||
* @param isThereUnreadNotifications true if user checked notifications before last notification date
|
* @param isThereUnreadNotifications true if user checked notifications before last notification date
|
||||||
*/
|
*/
|
||||||
public void updateNotificationsNotification(boolean isThereUnreadNotifications) {
|
public void updateNotificationsNotification(boolean isThereUnreadNotifications) {
|
||||||
Log.d("deneme","notification updates are called");
|
|
||||||
((ContributionsActivity)getActivity()).updateNotificationIcon(isThereUnreadNotifications);
|
((ContributionsActivity)getActivity()).updateNotificationIcon(isThereUnreadNotifications);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Update nearby indicator on cardview on main screen
|
|
||||||
* @param nearbyPlaces
|
|
||||||
*/
|
|
||||||
public void updateNearbyNotification(List<NearbyPlaces> nearbyPlaces) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStart() {
|
public void onStart() {
|
||||||
super.onStart();
|
super.onStart();
|
||||||
|
|
@ -479,11 +483,15 @@ public class ContributionsFragment
|
||||||
if (((ContributionsActivity)getActivity()).locationManager.isLocationPermissionGranted()) {
|
if (((ContributionsActivity)getActivity()).locationManager.isLocationPermissionGranted()) {
|
||||||
// Display nearest location, first listen
|
// Display nearest location, first listen
|
||||||
nearbyNoificationCardView.displayPermissionRequestButton(false);
|
nearbyNoificationCardView.displayPermissionRequestButton(false);
|
||||||
|
((ContributionsActivity)getActivity()).locationManager.registerLocationManager();
|
||||||
|
Log.d("deneme","location manager registered, location manager:"+((ContributionsActivity)getActivity()).locationManager);
|
||||||
} else {
|
} else {
|
||||||
// Display tab to see button, since permission is not granted and you have to grant it first
|
// Display tab to see button, since permission is not granted and you have to grant it first
|
||||||
nearbyNoificationCardView.displayPermissionRequestButton(true);
|
nearbyNoificationCardView.displayPermissionRequestButton(true);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
nearbyNoificationCardView.displayPermissionRequestButton(false);
|
||||||
|
((ContributionsActivity)getActivity()).locationManager.registerLocationManager();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
nearbyNoificationCardView.setVisibility(View.GONE);
|
nearbyNoificationCardView.setVisibility(View.GONE);
|
||||||
|
|
@ -491,6 +499,39 @@ public class ContributionsFragment
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateClosestNearbyCardViewInfo() {
|
||||||
|
Log.d("deneme"," updateClosestNearbyCardViewInfo called");
|
||||||
|
|
||||||
|
curLatLng = ((ContributionsActivity)getActivity()).locationManager.getLastLocation();
|
||||||
|
|
||||||
|
placesDisposable = Observable.fromCallable(() -> nearbyController
|
||||||
|
.loadAttractionsFromLocation(curLatLng, true)) // thanks to boolean, it will only return closest result
|
||||||
|
.subscribeOn(Schedulers.io())
|
||||||
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
.subscribe(this::updateNearbyNotification,
|
||||||
|
throwable -> {
|
||||||
|
Timber.d(throwable);
|
||||||
|
Log.d("deneme","error");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateNearbyNotification(NearbyController.NearbyPlacesInfo nearbyPlacesInfo) {
|
||||||
|
Log.d("deneme", "update nearby location called");
|
||||||
|
List<Place> placeList = nearbyPlacesInfo.placeList;
|
||||||
|
Log.d("deneme", "placeList is:"+placeList);
|
||||||
|
|
||||||
|
if (placeList != null && placeList.size() > 0) {
|
||||||
|
Place closestNearbyPlace = placeList.get(0);
|
||||||
|
String distance = formatDistanceBetween(curLatLng, closestNearbyPlace.location);
|
||||||
|
closestNearbyPlace.setDistance(distance);
|
||||||
|
nearbyNoificationCardView.updateContent (true, closestNearbyPlace);
|
||||||
|
Log.d("deneme","placelist size > 0");
|
||||||
|
} else {
|
||||||
|
Log.d("deneme","placelist bos");
|
||||||
|
nearbyNoificationCardView.updateContent (false, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
compositeDisposable.clear();
|
compositeDisposable.clear();
|
||||||
|
|
@ -502,15 +543,24 @@ public class ContributionsFragment
|
||||||
getActivity().unbindService(uploadServiceConnection);
|
getActivity().unbindService(uploadServiceConnection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (placesDisposable != null) {
|
||||||
|
placesDisposable.dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLocationChangedSignificantly(LatLng latLng) {
|
public void onLocationChangedSignificantly(LatLng latLng) {
|
||||||
|
// Will be called if location changed more than 1000 meter
|
||||||
|
// Do nothing on slight changes for using network efficiently
|
||||||
|
Log.d("deneme","onLocationChangedSignificantly called");
|
||||||
|
updateClosestNearbyCardViewInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLocationChangedSlightly(LatLng latLng) {
|
public void onLocationChangedSlightly(LatLng latLng) {
|
||||||
|
// Update closest nearby notification card onLocationChangedSlightly
|
||||||
|
Log.d("deneme","onLocationChangedSlightly called");
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue