Skip to content

Commit

Permalink
Position saved onSaveState in FragmentCurve
Browse files Browse the repository at this point in the history
Readme fix
  • Loading branch information
Vladimir Jovanovic committed Jan 26, 2017
1 parent 589c806 commit 2a4229f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
![Lemniscate header](http://i.imgur.com/i9t5vUm.png)


[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://github.com/vlad1m1r990/Lemniscate/blob/master/LICENSE)
[![](https://jitpack.io/v/vlad1m1r990/Lemniscate.svg)](https://jitpack.io/#vlad1m1r990/Lemniscate)
[![API](https://img.shields.io/badge/API-11%2B-green.svg?style=flat)](https://android-arsenal.com/api?level-11)
[![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-Lemniscate-green.svg?style=flat)](https://android-arsenal.com/details/1/5142)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://github.com/vlad1m1r990/Lemniscate/blob/master/LICENSE) [![](https://jitpack.io/v/vlad1m1r990/Lemniscate.svg)](https://jitpack.io/#vlad1m1r990/Lemniscate) [![API](https://img.shields.io/badge/API-11%2B-green.svg?style=flat)](https://android-arsenal.com/api?level-11) [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-Lemniscate-green.svg?style=flat)](https://android-arsenal.com/details/1/5142)
-----

Lemniscate is a library that will help you to make your progress view nice and sleek.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
public class FragmentCurve extends Fragment {


private static final String KEY_POSITION = "position";

public interface OnViewCreated {
void onViewShown(int position, BaseCurveProgressView baseCurveProgressView);
Expand All @@ -36,7 +37,7 @@ public interface OnViewCreated {
private BaseCurveProgressView mBaseCurveProgressView;

private TextView mCurveName;
private LinearLayout mLayoutViewholder;
private LinearLayout mLayoutViewHolder;

private int mPosition;

Expand All @@ -50,6 +51,10 @@ public static FragmentCurve getInstance(int position) {
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

if(savedInstanceState != null && savedInstanceState.containsKey(KEY_POSITION))
mPosition = savedInstanceState.getInt(KEY_POSITION);

if(mBaseCurveProgressView == null) {
mBaseCurveProgressView = getViewForPosition(mPosition);
mBaseCurveProgressView.setLayoutParams(new LinearLayout.LayoutParams(
Expand All @@ -64,12 +69,12 @@ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
ViewGroup root = (ViewGroup) inflater.inflate(R.layout.fragment_curve, container, false);

mCurveName = (TextView) root.findViewById(R.id.textCurveName);
mLayoutViewholder = (LinearLayout) root.findViewById(R.id.layoutViewHolder);
mLayoutViewHolder = (LinearLayout) root.findViewById(R.id.layoutViewHolder);

if(mBaseCurveProgressView.getParent() != null) {
((ViewGroup) mBaseCurveProgressView.getParent()).removeView(mBaseCurveProgressView);
}
mLayoutViewholder.addView(mBaseCurveProgressView);
mLayoutViewHolder.addView(mBaseCurveProgressView);

mCurveName.setText(mBaseCurveProgressView.getClass().getSimpleName());

Expand Down Expand Up @@ -121,4 +126,11 @@ public int getPosition() {
public void setPosition(int position) {
this.mPosition = position;
}


@Override
public void onSaveInstanceState(Bundle outState) {
outState.putInt(KEY_POSITION, mPosition);
super.onSaveInstanceState(outState);
}
}

0 comments on commit 2a4229f

Please sign in to comment.