Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b0060dde authored by Fan Zhang's avatar Fan Zhang
Browse files

Restore selected country when rotating screen.

Bug: 29105266
Change-Id: I5c070a40465b32b4989481f270c448ba48f0e865
parent e9fcb2c9
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -88,8 +88,8 @@ public final class SupportFragment extends InstrumentedFragment implements View.
        mAccountManager = AccountManager.get(mActivity);
        mSupportFeatureProvider =
                FeatureFactory.getFactory(mActivity).getSupportFeatureProvider(mActivity);
        mSupportItemAdapter = new SupportItemAdapter(mActivity, mSupportFeatureProvider,
                this /* itemClickListener */);
        mSupportItemAdapter = new SupportItemAdapter(mActivity, savedInstanceState,
                mSupportFeatureProvider, this /* itemClickListener */);
        mConnectivityManager =
                (ConnectivityManager) mActivity.getSystemService(Context.CONNECTIVITY_SERVICE);
    }
@@ -129,6 +129,12 @@ public final class SupportFragment extends InstrumentedFragment implements View.
        mConnectivityManager.unregisterNetworkCallback(mNetworkCallback);
    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        mSupportItemAdapter.onSaveInstanceState(outState);
    }

    @Override
    public void onAccountsUpdated(Account[] accounts) {
        // Account changed, update support items.
+11 −2
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import android.app.Activity;
import android.app.DialogFragment;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
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> {

    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_ESCALATION_OPTIONS = R.layout.support_escalation_options;
    private static final int TYPE_ESCALATION_OPTIONS_OFFLINE =
@@ -71,8 +73,8 @@ public final class SupportItemAdapter extends RecyclerView.Adapter<SupportItemAd
    private boolean mHasInternet;
    private Account mAccount;

    public SupportItemAdapter(Activity activity, SupportFeatureProvider supportFeatureProvider,
            View.OnClickListener itemClickListener) {
    public SupportItemAdapter(Activity activity, Bundle savedInstanceState,
            SupportFeatureProvider supportFeatureProvider, View.OnClickListener itemClickListener) {
        mActivity = activity;
        mSupportFeatureProvider = supportFeatureProvider;
        mItemClickListener = itemClickListener;
@@ -81,6 +83,9 @@ public final class SupportItemAdapter extends RecyclerView.Adapter<SupportItemAd
        mSupportData = new ArrayList<>();
        // Optimistically assume we have Internet access. It will be updated later to correct value.
        mHasInternet = true;
        if (savedInstanceState != null) {
            mSelectedCountry = savedInstanceState.getString(STATE_SELECTED_COUNTRY);
        }
        setAccount(mSupportFeatureProvider.getSupportEligibleAccount(mActivity));
        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
     * destroyed and recreated.