18
18
import android .widget .LinearLayout ;
19
19
import android .widget .ProgressBar ;
20
20
import android .widget .TextView ;
21
+ import android .widget .Toast ;
21
22
22
23
import androidx .annotation .NonNull ;
23
24
import androidx .annotation .Nullable ;
56
57
import fr .free .nrw .commons .nearby .mvp .presenter .NearbyParentFragmentPresenter ;
57
58
import fr .free .nrw .commons .theme .NavigationBaseActivity ;
58
59
import fr .free .nrw .commons .utils .FragmentUtils ;
60
+ import fr .free .nrw .commons .utils .NearbyFABUtils ;
59
61
import fr .free .nrw .commons .utils .NetworkUtils ;
60
62
import fr .free .nrw .commons .utils .PermissionUtils ;
61
63
import fr .free .nrw .commons .utils .ViewUtil ;
71
73
72
74
public class NearbyTestLayersFragment extends CommonsDaggerSupportFragment implements NearbyParentFragmentContract .View {
73
75
76
+ @ BindView (R .id .bottom_sheet )
77
+ View bottomSheetList ;
78
+
79
+ @ BindView (R .id .bottom_sheet_details )
80
+ View bottomSheetDetails ;
81
+
82
+ @ BindView (R .id .transparentView )
83
+ View transparentView ;
84
+
85
+ @ BindView (R .id .directionsButtonText )
86
+ TextView directionsButtonText ;
87
+
88
+ @ BindView (R .id .wikipediaButtonText )
89
+ TextView wikipediaButtonText ;
90
+
91
+ @ BindView (R .id .wikidataButtonText )
92
+ TextView wikidataButtonText ;
93
+
94
+ @ BindView (R .id .commonsButtonText )
95
+ TextView commonsButtonText ;
96
+
74
97
@ BindView (R .id .fab_plus )
75
98
FloatingActionButton fabPlus ;
76
99
@@ -80,16 +103,9 @@ public class NearbyTestLayersFragment extends CommonsDaggerSupportFragment imple
80
103
@ BindView (R .id .fab_gallery )
81
104
FloatingActionButton fabGallery ;
82
105
83
-
84
106
@ BindView (R .id .fab_recenter )
85
107
FloatingActionButton fabRecenter ;
86
108
87
- @ BindView (R .id .bottom_sheet )
88
- View bottomSheetList ;
89
-
90
- @ BindView (R .id .bottom_sheet_details )
91
- View bottomSheetDetails ;
92
-
93
109
@ BindView (R .id .bookmarkButtonImage )
94
110
ImageView bookmarkButtonImage ;
95
111
@@ -192,6 +208,63 @@ public void initViews() {
192
208
fab_close = AnimationUtils .loadAnimation (getActivity (), R .anim .fab_close );
193
209
rotate_forward = AnimationUtils .loadAnimation (getActivity (), R .anim .rotate_forward );
194
210
rotate_backward = AnimationUtils .loadAnimation (getActivity (), R .anim .rotate_backward );
211
+
212
+ bottomSheetDetailsBehavior .setBottomSheetCallback (new BottomSheetBehavior
213
+ .BottomSheetCallback () {
214
+ @ Override
215
+ public void onStateChanged (@ NonNull View bottomSheet , int newState ) {
216
+ prepareViewsForSheetPosition (newState );
217
+ }
218
+
219
+ @ Override
220
+ public void onSlide (@ NonNull View bottomSheet , float slideOffset ) {
221
+ if (slideOffset >= 0 ) {
222
+ transparentView .setAlpha (slideOffset );
223
+ if (slideOffset == 1 ) {
224
+ transparentView .setClickable (true );
225
+ } else if (slideOffset == 0 ) {
226
+ transparentView .setClickable (false );
227
+ }
228
+ }
229
+ }
230
+ });
231
+
232
+ bottomSheetListBehavior .setBottomSheetCallback (new BottomSheetBehavior
233
+ .BottomSheetCallback () {
234
+ @ Override
235
+ public void onStateChanged (@ NonNull View bottomSheet , int newState ) {
236
+ if (newState == BottomSheetBehavior .STATE_EXPANDED ) {
237
+ bottomSheetDetailsBehavior .setState (BottomSheetBehavior .STATE_HIDDEN );
238
+ }
239
+ }
240
+
241
+ @ Override
242
+ public void onSlide (@ NonNull View bottomSheet , float slideOffset ) {
243
+
244
+ }
245
+ });
246
+
247
+ // Remove button text if they exceed 1 line or if internal layout has not been built
248
+ // Only need to check for directions button because it is the longest
249
+ if (directionsButtonText .getLineCount () > 1 || directionsButtonText .getLineCount () == 0 ) {
250
+ wikipediaButtonText .setVisibility (View .GONE );
251
+ wikidataButtonText .setVisibility (View .GONE );
252
+ commonsButtonText .setVisibility (View .GONE );
253
+ directionsButtonText .setVisibility (View .GONE );
254
+ }
255
+ title .setOnLongClickListener (view -> {
256
+ Utils .copy ("place" , title .getText ().toString (), getContext ());
257
+ Toast .makeText (getContext (), "Text copied to clipboard" , Toast .LENGTH_SHORT ).show ();
258
+ return true ;
259
+ }
260
+ );
261
+ title .setOnClickListener (view -> {
262
+ if (bottomSheetDetailsBehavior .getState () == BottomSheetBehavior .STATE_COLLAPSED ) {
263
+ bottomSheetDetailsBehavior .setState (BottomSheetBehavior .STATE_EXPANDED );
264
+ } else {
265
+ bottomSheetDetailsBehavior .setState (BottomSheetBehavior .STATE_COLLAPSED );
266
+ }
267
+ });
195
268
}
196
269
197
270
public void setMapFragment (Bundle savedInstanceState ) {
@@ -259,7 +332,6 @@ public void childMapFragmentAttached() {
259
332
(this , mapFragment , locationManager );
260
333
Timber .d ("Child fragment attached" );
261
334
nearbyParentFragmentPresenter .nearbyFragmentsAreReady ();
262
- //checkPermissionsAndPerformAction(this::registerLocationUpdates);
263
335
initViews ();
264
336
nearbyParentFragmentPresenter .setActionListeners (applicationKvStore );
265
337
@@ -429,6 +501,41 @@ public void animateFABs() {
429
501
}
430
502
}
431
503
504
+ private void showFABs () {
505
+
506
+ NearbyFABUtils .addAnchorToBigFABs (fabPlus , bottomSheetDetails .getId ());
507
+ fabPlus .show ();
508
+ NearbyFABUtils .addAnchorToSmallFABs (fabGallery , getView ().findViewById (R .id .empty_view ).getId ());
509
+ NearbyFABUtils .addAnchorToSmallFABs (fabCamera , getView ().findViewById (R .id .empty_view1 ).getId ());
510
+ }
511
+
512
+ /**
513
+ * Hides all fabs
514
+ */
515
+ private void hideFABs () {
516
+ NearbyFABUtils .removeAnchorFromFAB (fabPlus );
517
+ fabPlus .hide ();
518
+ NearbyFABUtils .removeAnchorFromFAB (fabCamera );
519
+ fabCamera .hide ();
520
+ NearbyFABUtils .removeAnchorFromFAB (fabGallery );
521
+ fabGallery .hide ();
522
+ }
523
+
524
+ /**
525
+ * Hides camera and gallery FABs, turn back plus FAB
526
+ * @param isFabOpen
527
+ */
528
+ private void closeFABs ( boolean isFabOpen ){
529
+ if (isFabOpen ) {
530
+ fabPlus .startAnimation (rotate_backward );
531
+ fabCamera .startAnimation (fab_close );
532
+ fabGallery .startAnimation (fab_close );
533
+ fabCamera .hide ();
534
+ fabGallery .hide ();
535
+ this .isFabOpen = !isFabOpen ;
536
+ }
537
+ }
538
+
432
539
@ Override
433
540
public void displayLoginSkippedWarning () {
434
541
if (applicationKvStore .getBoolean ("login_skipped" , false )) {
@@ -506,6 +613,36 @@ public void displayBottomSheetWithInfo(Marker marker) {
506
613
bottomSheetDetailsBehavior .setState (BottomSheetBehavior .STATE_COLLAPSED );
507
614
}
508
615
616
+ /**
617
+ * If nearby details bottom sheet state is collapsed: show fab plus
618
+ * If nearby details bottom sheet state is expanded: show fab plus
619
+ * If nearby details bottom sheet state is hidden: hide all fabs
620
+ * @param bottomSheetState
621
+ */
622
+ public void prepareViewsForSheetPosition (int bottomSheetState ) {
623
+
624
+ switch (bottomSheetState ) {
625
+ case (BottomSheetBehavior .STATE_COLLAPSED ):
626
+ closeFABs (isFabOpen );
627
+ if (!fabPlus .isShown ()) showFABs ();
628
+ this .getView ().requestFocus ();
629
+ break ;
630
+ case (BottomSheetBehavior .STATE_EXPANDED ):
631
+ this .getView ().requestFocus ();
632
+ break ;
633
+ case (BottomSheetBehavior .STATE_HIDDEN ):
634
+ mapFragment .getMapboxMap ().deselectMarkers ();
635
+ transparentView .setClickable (false );
636
+ transparentView .setAlpha (0 );
637
+ closeFABs (isFabOpen );
638
+ hideFABs ();
639
+ if (this .getView () != null ) {
640
+ this .getView ().requestFocus ();
641
+ }
642
+ break ;
643
+ }
644
+ }
645
+
509
646
/**
510
647
* Same bottom sheet carries information for all nearby places, so we need to pass information
511
648
* (title, description, distance and links) to view on nearby marker click
0 commit comments