diff --git a/app/src/main/java/fr/free/nrw/commons/nearby/NearbyMapFragment.java b/app/src/main/java/fr/free/nrw/commons/nearby/NearbyMapFragment.java index 76eff3084..3cd4edbe5 100644 --- a/app/src/main/java/fr/free/nrw/commons/nearby/NearbyMapFragment.java +++ b/app/src/main/java/fr/free/nrw/commons/nearby/NearbyMapFragment.java @@ -104,8 +104,8 @@ public class NearbyMapFragment extends android.support.v4.app.Fragment { super.onViewCreated(view, savedInstanceState); this.getView().setFocusableInTouchMode(true); this.getView().requestFocus(); - this.getView().setOnKeyListener( new View.OnKeyListener() - { + this.getView().setOnKeyListener( new View.OnKeyListener() { + @Override public boolean onKey( View v, int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { diff --git a/app/src/main/java/fr/free/nrw/commons/nearby/PlaceRenderer.java b/app/src/main/java/fr/free/nrw/commons/nearby/PlaceRenderer.java index f4c8a5d61..39cd66a73 100644 --- a/app/src/main/java/fr/free/nrw/commons/nearby/PlaceRenderer.java +++ b/app/src/main/java/fr/free/nrw/commons/nearby/PlaceRenderer.java @@ -1,27 +1,40 @@ package fr.free.nrw.commons.nearby; +import android.os.CountDownTimer; import android.support.annotation.NonNull; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.view.animation.Animation; +import android.view.animation.AnimationUtils; import android.widget.ImageView; +import android.widget.LinearLayout; import android.widget.TextView; import com.pedrogomez.renderers.Renderer; +import java.util.ArrayList; + import butterknife.BindView; import butterknife.ButterKnife; import fr.free.nrw.commons.R; class PlaceRenderer extends Renderer { + @BindView(R.id.tvName) TextView tvName; @BindView(R.id.tvDesc) TextView tvDesc; @BindView(R.id.distance) TextView distance; @BindView(R.id.icon) ImageView icon; - private final PlaceClickedListener listener; + @BindView(R.id.buttonLayout) + LinearLayout buttonLayout; + private Animation animationUp; + private Animation animationDown; + private final int COUNTDOWN_RUNNING_TIME = 300; + private static ArrayList openedItems; - PlaceRenderer(@NonNull PlaceClickedListener listener) { - this.listener = listener; + + PlaceRenderer(){ + openedItems = new ArrayList<>(); } @Override @@ -32,11 +45,57 @@ class PlaceRenderer extends Renderer { @Override protected void setUpView(View view) { ButterKnife.bind(this, view); + animationUp = AnimationUtils.loadAnimation(getContext(),R.anim.slide_up); + animationDown = AnimationUtils.loadAnimation(getContext(),R.anim.slide_down); } @Override protected void hookListeners(View view) { - view.setOnClickListener(v -> listener.placeClicked(getContent())); + final View.OnClickListener listener = new View.OnClickListener() { + @Override + public void onClick(View view) { + if(buttonLayout.isShown()){ + closeLayout(buttonLayout); + }else { + openLayout(buttonLayout); + } + + } + }; + view.setOnClickListener(listener); + view.requestFocus(); + view.setOnFocusChangeListener(new View.OnFocusChangeListener() { + @Override + public void onFocusChange(View view, boolean hasFocus) { + if(!hasFocus && buttonLayout.isShown()){ + closeLayout(buttonLayout); + }else if(hasFocus && !buttonLayout.isShown()) { + listener.onClick(view); + } + } + }); + } + + private void closeLayout(LinearLayout buttonLayout) { + + buttonLayout.startAnimation(animationUp); + CountDownTimer countDownTimerStatic = new CountDownTimer(COUNTDOWN_RUNNING_TIME + , 16) { + @Override + public void onTick(long millisUntilFinished) { + } + + @Override + public void onFinish() { + buttonLayout.setVisibility(View.GONE); + } + }; + countDownTimerStatic.start(); + } + + private void openLayout(LinearLayout buttonLayout){ + buttonLayout.setVisibility(View.VISIBLE); + buttonLayout.startAnimation(animationDown); } @Override @@ -51,8 +110,4 @@ class PlaceRenderer extends Renderer { distance.setText(place.distance); icon.setImageResource(place.getDescription().getIcon()); } - - interface PlaceClickedListener { - void placeClicked(Place place); - } } diff --git a/app/src/main/res/anim/slide_down.xml b/app/src/main/res/anim/slide_down.xml new file mode 100644 index 000000000..049b3e053 --- /dev/null +++ b/app/src/main/res/anim/slide_down.xml @@ -0,0 +1,13 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/anim/slide_up.xml b/app/src/main/res/anim/slide_up.xml new file mode 100644 index 000000000..336f9ec9d --- /dev/null +++ b/app/src/main/res/anim/slide_up.xml @@ -0,0 +1,13 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/item_place.xml b/app/src/main/res/layout/item_place.xml index 88784857b..395d51bbb 100644 --- a/app/src/main/res/layout/item_place.xml +++ b/app/src/main/res/layout/item_place.xml @@ -2,9 +2,10 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" + xmlns:app="http://schemas.android.com/apk/res-auto" android:foreground="?selectableItemBackground" - android:minHeight="72dp" - > + android:focusableInTouchMode="true" + android:minHeight="72dp"> + + - + + + + + + + + + + + + + + + + + + + \ No newline at end of file