зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1220928 - Handle configuration changes. r=sebastian
MozReview-Commit-ID: E5MoWlcMCdj --HG-- extra : rebase_source : 006266b04f760acfead496d0d97ab01fde44900d
This commit is contained in:
Родитель
33befac088
Коммит
b40dd78458
|
@ -47,6 +47,7 @@ public class CombinedHistoryAdapter extends RecyclerView.Adapter<CombinedHistory
|
|||
|
||||
private List<RemoteClient> remoteClients = Collections.emptyList();
|
||||
private List<RemoteTab> clientChildren;
|
||||
private int remoteClientIndexOfParent = -1;
|
||||
private Cursor historyCursor;
|
||||
|
||||
// Maintain group collapsed and hidden state. Only accessed from the UI thread.
|
||||
|
@ -61,9 +62,7 @@ public class CombinedHistoryAdapter extends RecyclerView.Adapter<CombinedHistory
|
|||
|
||||
private final Context context;
|
||||
|
||||
private boolean inChildView = false;
|
||||
|
||||
public CombinedHistoryAdapter(Context context) {
|
||||
public CombinedHistoryAdapter(Context context, int savedParentIndex) {
|
||||
super();
|
||||
this.context = context;
|
||||
sectionHeaders = new SparseArray<>();
|
||||
|
@ -76,6 +75,7 @@ public class CombinedHistoryAdapter extends RecyclerView.Adapter<CombinedHistory
|
|||
if (sState == null) {
|
||||
sState = new RemoteTabsExpandableListState(GeckoSharedPrefs.forProfile(context));
|
||||
}
|
||||
remoteClientIndexOfParent = savedParentIndex;
|
||||
}
|
||||
|
||||
public void setClients(List<RemoteClient> clients) {
|
||||
|
@ -184,22 +184,30 @@ public class CombinedHistoryAdapter extends RecyclerView.Adapter<CombinedHistory
|
|||
return null;
|
||||
}
|
||||
|
||||
public int getParentIndex() {
|
||||
return remoteClientIndexOfParent;
|
||||
}
|
||||
|
||||
private boolean isInChildView() {
|
||||
return remoteClientIndexOfParent != -1;
|
||||
}
|
||||
|
||||
public void showChildView(int parentPosition) {
|
||||
if (clientChildren == null) {
|
||||
clientChildren = new ArrayList<>();
|
||||
}
|
||||
// Handle "back" view.
|
||||
clientChildren.add(null);
|
||||
clientChildren.addAll(remoteClients.get(transformAdapterPositionForDataStructure(ItemType.CLIENT, parentPosition)).tabs);
|
||||
inChildView = true;
|
||||
remoteClientIndexOfParent = transformAdapterPositionForDataStructure(ItemType.CLIENT, parentPosition);
|
||||
clientChildren.addAll(remoteClients.get(remoteClientIndexOfParent).tabs);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public boolean exitChildView() {
|
||||
if (!inChildView) {
|
||||
if (!isInChildView()) {
|
||||
return false;
|
||||
}
|
||||
inChildView = false;
|
||||
remoteClientIndexOfParent = -1;
|
||||
clientChildren.clear();
|
||||
notifyDataSetChanged();
|
||||
return true;
|
||||
|
@ -285,7 +293,7 @@ public class CombinedHistoryAdapter extends RecyclerView.Adapter<CombinedHistory
|
|||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
if (inChildView) {
|
||||
if (isInChildView()) {
|
||||
if (position == 0) {
|
||||
return ItemType.itemTypeToViewType(ItemType.NAVIGATION_BACK);
|
||||
}
|
||||
|
@ -310,8 +318,13 @@ public class CombinedHistoryAdapter extends RecyclerView.Adapter<CombinedHistory
|
|||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
if (inChildView) {
|
||||
return (clientChildren == null) ? 0 : clientChildren.size();
|
||||
if (isInChildView()) {
|
||||
if (clientChildren == null) {
|
||||
clientChildren = new ArrayList<>();
|
||||
clientChildren.add(null);
|
||||
clientChildren.addAll(remoteClients.get(remoteClientIndexOfParent).tabs);
|
||||
}
|
||||
return clientChildren.size();
|
||||
} else {
|
||||
final int historySize = historyCursor == null ? 0 : historyCursor.getCount();
|
||||
return remoteClients.size() + historySize + sectionHeaders.size();
|
||||
|
|
|
@ -9,6 +9,7 @@ import android.app.AlertDialog;
|
|||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.res.Configuration;
|
||||
import android.database.Cursor;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.LoaderManager;
|
||||
|
@ -82,6 +83,7 @@ public class CombinedHistoryPanel extends HomeFragment implements RemoteClientsD
|
|||
private CombinedHistoryRecyclerView mRecyclerView;
|
||||
private CombinedHistoryAdapter mAdapter;
|
||||
private CursorLoaderCallbacks mCursorLoaderCallbacks;
|
||||
private int mSavedParentIndex = -1;
|
||||
|
||||
private OnPanelLevelChangeListener.PanelLevel mPanelLevel = OnPanelLevelChangeListener.PanelLevel.PARENT;
|
||||
private Button mPanelFooterButton;
|
||||
|
@ -106,7 +108,7 @@ public class CombinedHistoryPanel extends HomeFragment implements RemoteClientsD
|
|||
super.onViewCreated(view, savedInstanceState);
|
||||
|
||||
mRecyclerView = (CombinedHistoryRecyclerView) view.findViewById(R.id.combined_recycler_view);
|
||||
mAdapter = new CombinedHistoryAdapter(getContext());
|
||||
mAdapter = new CombinedHistoryAdapter(getContext(), mSavedParentIndex);
|
||||
mRecyclerView.setAdapter(mAdapter);
|
||||
mRecyclerView.setItemAnimator(new DefaultItemAnimator());
|
||||
mRecyclerView.addItemDecoration(new DividerItemDecoration(getContext()));
|
||||
|
@ -125,6 +127,17 @@ public class CombinedHistoryPanel extends HomeFragment implements RemoteClientsD
|
|||
mCursorLoaderCallbacks = new CursorLoaderCallbacks();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConfigurationChanged(Configuration newConfig) {
|
||||
super.onConfigurationChanged(newConfig);
|
||||
|
||||
if (isVisible()) {
|
||||
// The parent stack is saved just so that the folder state can be
|
||||
// restored on rotation.
|
||||
mSavedParentIndex = mAdapter.getParentIndex();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void load() {
|
||||
getLoaderManager().initLoader(LOADER_ID_HISTORY, null, mCursorLoaderCallbacks);
|
||||
|
@ -285,7 +298,7 @@ public class CombinedHistoryPanel extends HomeFragment implements RemoteClientsD
|
|||
break;
|
||||
|
||||
case CHILD:
|
||||
final JSONArray tabUrls = ((CombinedHistoryAdapter) mRecyclerView.getAdapter()).getCurrentChildTabs();
|
||||
final JSONArray tabUrls = mAdapter.getCurrentChildTabs();
|
||||
if (tabUrls != null) {
|
||||
final JSONObject message = new JSONObject();
|
||||
try {
|
||||
|
@ -425,7 +438,7 @@ public class CombinedHistoryPanel extends HomeFragment implements RemoteClientsD
|
|||
|
||||
final int itemId = item.getItemId();
|
||||
if (itemId == R.id.home_remote_tabs_hide_client) {
|
||||
((CombinedHistoryAdapter) mRecyclerView.getAdapter()).removeItem(info.position);
|
||||
mAdapter.removeItem(info.position);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -452,7 +465,7 @@ public class CombinedHistoryPanel extends HomeFragment implements RemoteClientsD
|
|||
|
||||
@Override
|
||||
public void onClients(List<RemoteClient> clients) {
|
||||
((CombinedHistoryAdapter) mRecyclerView.getAdapter()).unhideClients(clients);
|
||||
mAdapter.unhideClients(clients);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Загрузка…
Ссылка в новой задаче