Skip to content

Commit

Permalink
bugfix: state save and restore error #177
Browse files Browse the repository at this point in the history
  • Loading branch information
cgspine committed Mar 7, 2018
1 parent 516a286 commit 6427790
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
package com.qmuiteam.qmuidemo.fragment.home;

import android.content.Context;
import android.os.Parcelable;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.SparseArray;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;

import com.qmuiteam.qmui.util.QMUIViewHelper;
import com.qmuiteam.qmui.widget.QMUITopBar;
import com.qmuiteam.qmuidemo.decorator.GridDividerItemDecoration;
import com.qmuiteam.qmuidemo.R;
import com.qmuiteam.qmuidemo.base.BaseFragment;
import com.qmuiteam.qmuidemo.base.BaseRecyclerAdapter;
import com.qmuiteam.qmuidemo.base.RecyclerViewHolder;
import com.qmuiteam.qmuidemo.decorator.GridDividerItemDecoration;
import com.qmuiteam.qmuidemo.fragment.QDAboutFragment;
import com.qmuiteam.qmuidemo.model.QDItemDescription;

Expand All @@ -33,6 +36,7 @@ public abstract class HomeController extends FrameLayout {

private HomeControlListener mHomeControlListener;
private ItemAdapter mItemAdapter;
private int mDiffRecyclerViewSaveStateId = QMUIViewHelper.generateViewId();

public HomeController(Context context) {
super(context);
Expand Down Expand Up @@ -92,6 +96,22 @@ public interface HomeControlListener {
void startFragment(BaseFragment fragment);
}

@Override
protected void dispatchSaveInstanceState(SparseArray<Parcelable> container) {
int id = mRecyclerView.getId();
mRecyclerView.setId(mDiffRecyclerViewSaveStateId);
super.dispatchSaveInstanceState(container);
mRecyclerView.setId(id);
}

@Override
protected void dispatchRestoreInstanceState(SparseArray<Parcelable> container) {
int id = mRecyclerView.getId();
mRecyclerView.setId(mDiffRecyclerViewSaveStateId);
super.dispatchRestoreInstanceState(container);
mRecyclerView.setId(id);
}

static class ItemAdapter extends BaseRecyclerAdapter<QDItemDescription> {

public ItemAdapter(Context ctx, List<QDItemDescription> data) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.qmuiteam.qmuidemo.fragment.home;

import android.graphics.drawable.Drawable;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
Expand All @@ -9,11 +8,10 @@
import android.view.ViewGroup;
import android.widget.FrameLayout;

import com.qmuiteam.qmui.util.QMUIDisplayHelper;
import com.qmuiteam.qmui.util.QMUIResHelper;
import com.qmuiteam.qmui.widget.QMUITabSegment;
import com.qmuiteam.qmuidemo.base.BaseFragment;
import com.qmuiteam.qmuidemo.R;
import com.qmuiteam.qmuidemo.base.BaseFragment;

import java.util.HashMap;

Expand Down

0 comments on commit 6427790

Please sign in to comment.