mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 12:53:55 +01:00
Make larger methods smaller
This commit is contained in:
parent
7e40d94dd0
commit
25a88f32f9
1 changed files with 72 additions and 40 deletions
|
|
@ -161,16 +161,27 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
|
|
||||||
private void initViews() {
|
private void initViews() {
|
||||||
Timber.d("init views called");
|
Timber.d("init views called");
|
||||||
|
initBottomSheets();
|
||||||
|
loadAnimations();
|
||||||
|
setBottomSheetCallbacks();
|
||||||
|
decideButtonVisibilities();
|
||||||
|
addActionToTitle();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates bottom sheet behaviours from bottom sheets, sets initial states and visibility
|
||||||
|
*/
|
||||||
|
private void initBottomSheets() {
|
||||||
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);
|
||||||
bottomSheetDetails.setVisibility(View.VISIBLE);
|
bottomSheetDetails.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
|
||||||
fab_open = AnimationUtils.loadAnimation(getActivity(), R.anim.fab_open);
|
/**
|
||||||
fab_close = AnimationUtils.loadAnimation(getActivity(), R.anim.fab_close);
|
* Defines how bottom sheets will act on click
|
||||||
rotate_forward = AnimationUtils.loadAnimation(getActivity(), R.anim.rotate_forward);
|
*/
|
||||||
rotate_backward = AnimationUtils.loadAnimation(getActivity(), R.anim.rotate_backward);
|
private void setBottomSheetCallbacks() {
|
||||||
|
|
||||||
bottomSheetDetailsBehavior.setBottomSheetCallback(new BottomSheetBehavior
|
bottomSheetDetailsBehavior.setBottomSheetCallback(new BottomSheetBehavior
|
||||||
.BottomSheetCallback() {
|
.BottomSheetCallback() {
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -210,7 +221,22 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads animations will be used for FABs
|
||||||
|
*/
|
||||||
|
private void loadAnimations() {
|
||||||
|
fab_open = AnimationUtils.loadAnimation(getActivity(), R.anim.fab_open);
|
||||||
|
fab_close = AnimationUtils.loadAnimation(getActivity(), R.anim.fab_close);
|
||||||
|
rotate_forward = AnimationUtils.loadAnimation(getActivity(), R.anim.rotate_forward);
|
||||||
|
rotate_backward = AnimationUtils.loadAnimation(getActivity(), R.anim.rotate_backward);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fits buttons according to our layout
|
||||||
|
*/
|
||||||
|
private void decideButtonVisibilities() {
|
||||||
// Remove button text if they exceed 1 line or if internal layout has not been built
|
// Remove button text if they exceed 1 line or if internal layout has not been built
|
||||||
// Only need to check for directions button because it is the longest
|
// Only need to check for directions button because it is the longest
|
||||||
if (directionsButtonText.getLineCount() > 1 || directionsButtonText.getLineCount() == 0) {
|
if (directionsButtonText.getLineCount() > 1 || directionsButtonText.getLineCount() == 0) {
|
||||||
|
|
@ -219,15 +245,15 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
commonsButtonText.setVisibility(View.GONE);
|
commonsButtonText.setVisibility(View.GONE);
|
||||||
directionsButtonText.setVisibility(View.GONE);
|
directionsButtonText.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
title.setOnLongClickListener(view -> {
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private void addActionToTitle() {
|
||||||
|
title.setOnClickListener(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;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
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);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -435,14 +461,19 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
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 checkingAroundCurrentLocation;
|
|
||||||
if (curlatLng.equals(searchLatLng)) { // Means we are checking around current location
|
if (curlatLng.equals(searchLatLng)) { // Means we are checking around current location
|
||||||
checkingAroundCurrentLocation = true;
|
populatePlacesForCurrentLocation(curlatLng, searchLatLng);
|
||||||
|
} else {
|
||||||
|
populatePlacesForAnotherLocation(curlatLng, searchLatLng);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void populatePlacesForCurrentLocation(fr.free.nrw.commons.location.LatLng curlatLng,
|
||||||
|
fr.free.nrw.commons.location.LatLng searchLatLng) {
|
||||||
compositeDisposable.add(Observable.fromCallable(() -> nearbyController
|
compositeDisposable.add(Observable.fromCallable(() -> nearbyController
|
||||||
.loadAttractionsFromLocation(curlatLng, searchLatLng, false, checkingAroundCurrentLocation))
|
.loadAttractionsFromLocation(curlatLng, searchLatLng, false, true))
|
||||||
.subscribeOn(Schedulers.io())
|
.subscribeOn(Schedulers.io())
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribe(this::updateMapMarkers,
|
.subscribe(this::updateMapMarkers,
|
||||||
|
|
@ -453,10 +484,12 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
setProgressBarVisibility(false);
|
setProgressBarVisibility(false);
|
||||||
nearbyParentFragmentPresenter.lockUnlockNearby(false);
|
nearbyParentFragmentPresenter.lockUnlockNearby(false);
|
||||||
}));
|
}));
|
||||||
} else {
|
}
|
||||||
checkingAroundCurrentLocation = false;
|
|
||||||
|
private void populatePlacesForAnotherLocation(fr.free.nrw.commons.location.LatLng curlatLng,
|
||||||
|
fr.free.nrw.commons.location.LatLng searchLatLng) {
|
||||||
compositeDisposable.add(Observable.fromCallable(() -> nearbyController
|
compositeDisposable.add(Observable.fromCallable(() -> nearbyController
|
||||||
.loadAttractionsFromLocation(curlatLng, searchLatLng, false, checkingAroundCurrentLocation))
|
.loadAttractionsFromLocation(curlatLng, searchLatLng, false, false))
|
||||||
.subscribeOn(Schedulers.io())
|
.subscribeOn(Schedulers.io())
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribe(this::updateMapMarkersForCustomLocation,
|
.subscribe(this::updateMapMarkersForCustomLocation,
|
||||||
|
|
@ -468,7 +501,6 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
nearbyParentFragmentPresenter.lockUnlockNearby(false);
|
nearbyParentFragmentPresenter.lockUnlockNearby(false);
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Populates places for your location, should be used for finding nearby places around a
|
* Populates places for your location, should be used for finding nearby places around a
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue