Persist scrolling after configuration change

pull/157/merge
Alinson S. Xavier 9 years ago
parent 3fe09efe9b
commit 56f2ae57fe

@ -40,7 +40,7 @@ public class BundleSavedState extends View.BaseSavedState
}
};
final Bundle bundle;
public final Bundle bundle;
public BundleSavedState(Parcelable superState, Bundle bundle)
{

@ -20,12 +20,14 @@
package org.isoron.uhabits.activities.habits.list.views;
import android.content.*;
import android.os.*;
import android.support.annotation.*;
import android.support.v7.widget.*;
import android.support.v7.widget.helper.*;
import android.util.*;
import android.view.*;
import org.isoron.uhabits.activities.common.views.*;
import org.isoron.uhabits.activities.habits.list.controllers.*;
import org.isoron.uhabits.activities.habits.list.model.*;
import org.isoron.uhabits.models.*;
@ -127,7 +129,7 @@ public class HabitCardListView extends RecyclerView
public void setDataOffset(int dataOffset)
{
this.dataOffset = dataOffset;
for(HabitCardViewHolder holder : attachedHolders)
for (HabitCardViewHolder holder : attachedHolders)
{
HabitCardView cardView = (HabitCardView) holder.itemView;
cardView.setDataOffset(dataOffset);
@ -148,6 +150,23 @@ public class HabitCardListView extends RecyclerView
super.onDetachedFromWindow();
}
@Override
protected void onRestoreInstanceState(Parcelable state)
{
BundleSavedState bss = (BundleSavedState) state;
dataOffset = bss.bundle.getInt("dataOffset");
super.onRestoreInstanceState(bss.getSuperState());
}
@Override
protected Parcelable onSaveInstanceState()
{
Parcelable superState = super.onSaveInstanceState();
Bundle bundle = new Bundle();
bundle.putInt("dataOffset", dataOffset);
return new BundleSavedState(superState, bundle);
}
protected void setupCardViewController(@NonNull HabitCardViewHolder holder)
{
HabitCardView cardView = (HabitCardView) holder.itemView;
@ -193,7 +212,7 @@ public class HabitCardListView extends RecyclerView
{
int position = holder.getAdapterPosition();
if (controller != null) controller.onItemLongClick(position);
if(adapter.isSortable()) touchHelper.startDrag(holder);
if (adapter.isSortable()) touchHelper.startDrag(holder);
}
@Override

Loading…
Cancel
Save