Skip to content

Commit

Permalink
smooth scroll
Browse files Browse the repository at this point in the history
  • Loading branch information
guillerial committed Apr 17, 2018
1 parent b862871 commit dcd1913
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
11 changes: 6 additions & 5 deletions app/src/main/java/es/indios/markn/ui/guide/GuideAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.Layout;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand All @@ -27,7 +28,7 @@

public class GuideAdapter extends RecyclerView.Adapter<GuideAdapter.IndicationViewHolder> {
private ArrayList<Indication> mIndications;
private LinearLayoutManager mLayoutManager;
private RecyclerView.LayoutManager mLayoutManager;

@Inject
public GuideAdapter() {
Expand Down Expand Up @@ -61,15 +62,15 @@ public int getItemCount() {
return mIndications.size();
}

public void scrollToIndication(String route) {
public int getRoutePosition(String route) {
for(int i=0; i<mIndications.size(); i++){
if(mIndications.get(i).getRoute().equals(route))
mLayoutManager.scrollToPositionWithOffset(i, 20);

return i;
}
return 500;
}

public void setManager(LinearLayoutManager indicationLayoutManager) {
public void setManager(RecyclerView.LayoutManager indicationLayoutManager) {
mLayoutManager = indicationLayoutManager;
}

Expand Down
8 changes: 6 additions & 2 deletions app/src/main/java/es/indios/markn/ui/guide/GuideFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public class GuideFragment extends BaseFragment implements GuideMvpView, Locatio
@BindView(R.id.guide_indication_recycler) RecyclerView mIndicationRecyclerView;
@BindView(R.id.guide_location_recycler) RecyclerView mLocationRecyclerView;

private RecyclerView.LayoutManager indicationLayoutManager;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -55,7 +57,7 @@ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,

mIndicationRecyclerView.setAdapter(mGuideAdapter);
mLocationRecyclerView.setAdapter(mLocationAdapter);
LinearLayoutManager indicationLayoutManager = new LinearLayoutManager(getContext());
indicationLayoutManager = new LinearLayoutManager(getContext());
mIndicationRecyclerView.setLayoutManager(indicationLayoutManager);
mGuideAdapter.setManager(indicationLayoutManager);
mLocationRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
Expand Down Expand Up @@ -94,7 +96,9 @@ public void scrollToIndication(String route) {
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
mGuideAdapter.scrollToIndication(route);
if(mGuideAdapter.getRoutePosition(route)!=500){
mIndicationRecyclerView.smoothScrollToPosition(mGuideAdapter.getRoutePosition(route));
}
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ public void generatePathIndicationList(){
String actualBeacon = new StringBuilder().append(mActualBeacon.getId3()).toString();
Timber.i("Beacon actual:"+actualBeacon+"Beacon destino:"+mActualDestination.getNearby_beacon());
Route route = mTopology.get(actualBeacon+"-"+mActualDestination.getNearby_beacon());
Route actualRoute = route;
if(actualBeacon.equals(mActualDestination.getNearby_beacon())){
indications.add(new Indication(mActualDestination.getLast_indication(), mActualDestination.getLast_image()));
}else {
Expand All @@ -183,7 +184,8 @@ public void generatePathIndicationList(){
}
getMvpView().setIndicationList(indications);
}else{
getMvpView().scrollToIndication(mActualIndication.getRoute());
getMvpView().scrollToIndication(indications.get(0).getRoute());

}
}
}
Expand Down

0 comments on commit dcd1913

Please sign in to comment.