Restore selected country when rotating screen.
Bug: 29105266 Change-Id: I5c070a40465b32b4989481f270c448ba48f0e865
This commit is contained in:
@@ -88,8 +88,8 @@ public final class SupportFragment extends InstrumentedFragment implements View.
|
|||||||
mAccountManager = AccountManager.get(mActivity);
|
mAccountManager = AccountManager.get(mActivity);
|
||||||
mSupportFeatureProvider =
|
mSupportFeatureProvider =
|
||||||
FeatureFactory.getFactory(mActivity).getSupportFeatureProvider(mActivity);
|
FeatureFactory.getFactory(mActivity).getSupportFeatureProvider(mActivity);
|
||||||
mSupportItemAdapter = new SupportItemAdapter(mActivity, mSupportFeatureProvider,
|
mSupportItemAdapter = new SupportItemAdapter(mActivity, savedInstanceState,
|
||||||
this /* itemClickListener */);
|
mSupportFeatureProvider, this /* itemClickListener */);
|
||||||
mConnectivityManager =
|
mConnectivityManager =
|
||||||
(ConnectivityManager) mActivity.getSystemService(Context.CONNECTIVITY_SERVICE);
|
(ConnectivityManager) mActivity.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||||
}
|
}
|
||||||
@@ -129,6 +129,12 @@ public final class SupportFragment extends InstrumentedFragment implements View.
|
|||||||
mConnectivityManager.unregisterNetworkCallback(mNetworkCallback);
|
mConnectivityManager.unregisterNetworkCallback(mNetworkCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSaveInstanceState(Bundle outState) {
|
||||||
|
super.onSaveInstanceState(outState);
|
||||||
|
mSupportItemAdapter.onSaveInstanceState(outState);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAccountsUpdated(Account[] accounts) {
|
public void onAccountsUpdated(Account[] accounts) {
|
||||||
// Account changed, update support items.
|
// Account changed, update support items.
|
||||||
|
@@ -23,6 +23,7 @@ import android.app.Activity;
|
|||||||
import android.app.DialogFragment;
|
import android.app.DialogFragment;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.os.Bundle;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
@@ -53,6 +54,7 @@ import static com.android.settings.overlay.SupportFeatureProvider.SupportType.PH
|
|||||||
*/
|
*/
|
||||||
public final class SupportItemAdapter extends RecyclerView.Adapter<SupportItemAdapter.ViewHolder> {
|
public final class SupportItemAdapter extends RecyclerView.Adapter<SupportItemAdapter.ViewHolder> {
|
||||||
|
|
||||||
|
private static final String STATE_SELECTED_COUNTRY = "STATE_SELECTED_COUNTRY";
|
||||||
private static final int TYPE_TITLE = R.layout.support_item_title;
|
private static final int TYPE_TITLE = R.layout.support_item_title;
|
||||||
private static final int TYPE_ESCALATION_OPTIONS = R.layout.support_escalation_options;
|
private static final int TYPE_ESCALATION_OPTIONS = R.layout.support_escalation_options;
|
||||||
private static final int TYPE_ESCALATION_OPTIONS_OFFLINE =
|
private static final int TYPE_ESCALATION_OPTIONS_OFFLINE =
|
||||||
@@ -71,8 +73,8 @@ public final class SupportItemAdapter extends RecyclerView.Adapter<SupportItemAd
|
|||||||
private boolean mHasInternet;
|
private boolean mHasInternet;
|
||||||
private Account mAccount;
|
private Account mAccount;
|
||||||
|
|
||||||
public SupportItemAdapter(Activity activity, SupportFeatureProvider supportFeatureProvider,
|
public SupportItemAdapter(Activity activity, Bundle savedInstanceState,
|
||||||
View.OnClickListener itemClickListener) {
|
SupportFeatureProvider supportFeatureProvider, View.OnClickListener itemClickListener) {
|
||||||
mActivity = activity;
|
mActivity = activity;
|
||||||
mSupportFeatureProvider = supportFeatureProvider;
|
mSupportFeatureProvider = supportFeatureProvider;
|
||||||
mItemClickListener = itemClickListener;
|
mItemClickListener = itemClickListener;
|
||||||
@@ -81,6 +83,9 @@ public final class SupportItemAdapter extends RecyclerView.Adapter<SupportItemAd
|
|||||||
mSupportData = new ArrayList<>();
|
mSupportData = new ArrayList<>();
|
||||||
// Optimistically assume we have Internet access. It will be updated later to correct value.
|
// Optimistically assume we have Internet access. It will be updated later to correct value.
|
||||||
mHasInternet = true;
|
mHasInternet = true;
|
||||||
|
if (savedInstanceState != null) {
|
||||||
|
mSelectedCountry = savedInstanceState.getString(STATE_SELECTED_COUNTRY);
|
||||||
|
}
|
||||||
setAccount(mSupportFeatureProvider.getSupportEligibleAccount(mActivity));
|
setAccount(mSupportFeatureProvider.getSupportEligibleAccount(mActivity));
|
||||||
refreshData();
|
refreshData();
|
||||||
}
|
}
|
||||||
@@ -149,6 +154,10 @@ public final class SupportItemAdapter extends RecyclerView.Adapter<SupportItemAd
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void onSaveInstanceState(Bundle outState) {
|
||||||
|
outState.putString(STATE_SELECTED_COUNTRY, mSelectedCountry);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create data for the adapter. If there is already data in the adapter, they will be
|
* Create data for the adapter. If there is already data in the adapter, they will be
|
||||||
* destroyed and recreated.
|
* destroyed and recreated.
|
||||||
|
Reference in New Issue
Block a user