Skip to content

Commit 753cfab

Browse files
authored
Merge pull request commons-app#1324 from commons-app/fixCornerButtonBug
Fix corner FABs visibility bug
2 parents 1e83d67 + 56fb147 commit 753cfab

File tree

1 file changed

+74
-35
lines changed

1 file changed

+74
-35
lines changed

app/src/main/java/fr/free/nrw/commons/nearby/NearbyMapFragment.java

+74-35
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
import android.support.design.widget.CoordinatorLayout;
1717
import android.support.design.widget.FloatingActionButton;
1818

19+
import android.util.Log;
20+
import android.view.Gravity;
1921
import android.view.KeyEvent;
2022
import android.view.LayoutInflater;
2123
import android.view.View;
@@ -508,22 +510,54 @@ public void prepareViewsForSheetPosition(int bottomSheetState) {
508510
}
509511

510512
private void hideFAB() {
511-
//get rid of anchors
512-
//Somehow this was the only way https://stackoverflow.com/questions/32732932/floatingactionbutton-visible-for-sometime-even-if-visibility-is-set-to-gone
513-
CoordinatorLayout.LayoutParams p = (CoordinatorLayout.LayoutParams) fabPlus
514-
.getLayoutParams();
515-
p.setAnchorId(View.NO_ID);
516-
fabPlus.setLayoutParams(p);
513+
514+
removeAnchorFromFABs(fabPlus);
517515
fabPlus.hide();
516+
517+
removeAnchorFromFABs(fabCamera);
518518
fabCamera.hide();
519+
520+
removeAnchorFromFABs(fabGallery);
519521
fabGallery.hide();
522+
523+
}
524+
525+
/*
526+
* We are not able to hide FABs without removing anchors, this method removes anchors
527+
* */
528+
private void removeAnchorFromFABs(FloatingActionButton floatingActionButton) {
529+
//get rid of anchors
530+
//Somehow this was the only way https://stackoverflow.com/questions/32732932
531+
// /floatingactionbutton-visible-for-sometime-even-if-visibility-is-set-to-gone
532+
CoordinatorLayout.LayoutParams param = (CoordinatorLayout.LayoutParams) floatingActionButton
533+
.getLayoutParams();
534+
param.setAnchorId(View.NO_ID);
535+
// If we don't set them to zero, then they become visible for a moment on upper left side
536+
param.width = 0;
537+
param.height = 0;
538+
floatingActionButton.setLayoutParams(param);
520539
}
521540

522541
private void showFAB() {
523-
CoordinatorLayout.LayoutParams p = (CoordinatorLayout.LayoutParams) fabPlus.getLayoutParams();
524-
p.setAnchorId(getActivity().findViewById(R.id.bottom_sheet_details).getId());
525-
fabPlus.setLayoutParams(p);
542+
543+
addAnchorToFABs(fabPlus, getActivity().findViewById(R.id.bottom_sheet_details).getId());
526544
fabPlus.show();
545+
546+
addAnchorToFABs(fabGallery, getActivity().findViewById(R.id.empty_view).getId());
547+
548+
addAnchorToFABs(fabCamera, getActivity().findViewById(R.id.empty_view1).getId());
549+
550+
}
551+
552+
/*
553+
* Add amnchors back before making them visible again.
554+
* */
555+
private void addAnchorToFABs(FloatingActionButton floatingActionButton, int anchorID) {
556+
CoordinatorLayout.LayoutParams params = new CoordinatorLayout.LayoutParams
557+
(ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT);
558+
params.setAnchorId(anchorID);
559+
params.anchorGravity = Gravity.TOP|Gravity.RIGHT|Gravity.END;
560+
floatingActionButton.setLayoutParams(params);
527561
}
528562

529563
private void passInfoToSheet(Place place) {
@@ -554,25 +588,28 @@ private void passInfoToSheet(Place place) {
554588
distance.setText(place.distance.toString());
555589

556590
fabCamera.setOnClickListener(view -> {
557-
Timber.d("Camera button tapped. Image title: " + place.getName() + "Image desc: " + place.getLongDescription());
558-
controller = new ContributionController(this);
591+
if (fabCamera.isShown()) {
592+
Timber.d("Camera button tapped. Image title: " + place.getName() + "Image desc: " + place.getLongDescription());
593+
controller = new ContributionController(this);
559594

560-
DirectUpload directUpload = new DirectUpload(this, controller);
561-
storeSharedPrefs();
562-
directUpload.initiateCameraUpload();
595+
DirectUpload directUpload = new DirectUpload(this, controller);
596+
storeSharedPrefs();
597+
directUpload.initiateCameraUpload();
598+
}
563599
});
564600

565601
fabGallery.setOnClickListener(view -> {
566-
Timber.d("Gallery button tapped. Image title: " + place.getName() + "Image desc: " + place.getLongDescription());
567-
controller = new ContributionController(this);
602+
if (fabGallery.isShown()) {
603+
Timber.d("Gallery button tapped. Image title: " + place.getName() + "Image desc: " + place.getLongDescription());
604+
controller = new ContributionController(this);
568605

569-
DirectUpload directUpload = new DirectUpload(this, controller);
570-
storeSharedPrefs();
571-
directUpload.initiateGalleryUpload();
572-
573-
//TODO: App crashes after image upload completes
574-
//TODO: Handle onRequestPermissionsResult
606+
DirectUpload directUpload = new DirectUpload(this, controller);
607+
storeSharedPrefs();
608+
directUpload.initiateGalleryUpload();
575609

610+
//TODO: App crashes after image upload completes
611+
//TODO: Handle onRequestPermissionsResult
612+
}
576613
});
577614
}
578615

@@ -627,20 +664,22 @@ private void openWebView(Uri link) {
627664
}
628665

629666
private void animateFAB(boolean isFabOpen) {
630-
if (isFabOpen) {
631-
fabPlus.startAnimation(rotate_backward);
632-
fabCamera.startAnimation(fab_close);
633-
fabGallery.startAnimation(fab_close);
634-
fabCamera.hide();
635-
fabGallery.hide();
636-
} else {
637-
fabPlus.startAnimation(rotate_forward);
638-
fabCamera.startAnimation(fab_open);
639-
fabGallery.startAnimation(fab_open);
640-
fabCamera.show();
641-
fabGallery.show();
667+
if (fabPlus.isShown()){
668+
if (isFabOpen) {
669+
fabPlus.startAnimation(rotate_backward);
670+
fabCamera.startAnimation(fab_close);
671+
fabGallery.startAnimation(fab_close);
672+
fabCamera.hide();
673+
fabGallery.hide();
674+
} else {
675+
fabPlus.startAnimation(rotate_forward);
676+
fabCamera.startAnimation(fab_open);
677+
fabGallery.startAnimation(fab_open);
678+
fabCamera.show();
679+
fabGallery.show();
680+
}
681+
this.isFabOpen=!isFabOpen;
642682
}
643-
this.isFabOpen=!isFabOpen;
644683
}
645684

646685
private void closeFabs(boolean isFabOpen){

0 commit comments

Comments
 (0)