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

Commit 4139f908 authored by Marcus Hagerott's avatar Marcus Hagerott Committed by Android (Google) Code Review
Browse files

Merge "Show confirmation dialog when leaving customize screen." into ub-contactsdialer-g-dev

parents daecf84f 10f856c4
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -675,6 +675,9 @@
      and return to the editor [CHAR LIMIT=30] -->
    <string name="cancel_confirmation_dialog_keep_editing_button">Cancel</string>

    <!-- Contents of the alert dialog when the user hits the Cancel button in the customize screen [CHAR LIMIT=128] -->
    <string name="leave_customize_confirmation_dialog_message">Discard customizations?</string>

    <!-- Description of a call log entry, made of a call type and a date -->
    <string name="call_type_and_date">
        <xliff:g id="call_type" example="Friends">%1$s</xliff:g>  <xliff:g id="call_short_date" example="Friends">%2$s</xliff:g>
+0 −5
Original line number Diff line number Diff line
@@ -486,11 +486,6 @@ background and text color. See also android:style/Widget.Holo.TextView.ListSepar
        <item name="android:overScrollMode">always</item>
    </style>

    <style name="ContactListFilterTheme" parent="@android:Theme.Holo.Light">
        <item name="android:listViewStyle">@style/ListViewStyle</item>
        <item name="android:actionButtonStyle">@style/FilterActionButtonStyle</item>
    </style>

    <!-- Adding padding to action button doesn't move it to left, we increase the button width to
     make margin between the button and screen edge 16dp -->
    <style name="FilterActionButtonStyle" parent="@android:Widget.ActionButton">
+3 −2
Original line number Diff line number Diff line
@@ -90,8 +90,9 @@ public class AccountFilterActivity extends Activity implements AdapterView.OnIte
        if (filter.filterType == ContactListFilter.FILTER_TYPE_CUSTOM) {
            mCustomFilterView = listFilterView;
            mIsCustomFilterViewSelected = listFilterView.isChecked();
            final Intent intent = new Intent(this,
                    CustomContactListFilterActivity.class);
            final Intent intent = new Intent(this, CustomContactListFilterActivity.class)
                    .putExtra(CustomContactListFilterActivity.EXTRA_CURRENT_LIST_FILTER_TYPE,
                            mCurrentFilterType);
            listFilterView.setActivated(true);
            // Switching activity has the highest priority. So when we open another activity, the
            // announcement that indicates an account is checked will be interrupted. This is the
+62 −8
Original line number Diff line number Diff line
@@ -19,6 +19,8 @@ package com.android.contacts.common.list;
import android.app.ActionBar;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.app.LoaderManager.LoaderCallbacks;
import android.app.ProgressDialog;
import android.content.AsyncTaskLoader;
@@ -30,14 +32,12 @@ import android.content.DialogInterface;
import android.content.Intent;
import android.content.Loader;
import android.content.OperationApplicationException;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.net.Uri;
import android.os.Bundle;
import android.os.RemoteException;
import android.preference.PreferenceManager;
import android.provider.ContactsContract;
import android.provider.ContactsContract.Groups;
import android.provider.ContactsContract.Settings;
@@ -81,13 +81,13 @@ public class CustomContactListFilterActivity extends Activity implements
        LoaderCallbacks<CustomContactListFilterActivity.AccountSet> {
    private static final String TAG = "CustomContactListFilterActivity";

    public static final String EXTRA_CURRENT_LIST_FILTER_TYPE = "currentListFilterType";

    private static final int ACCOUNT_SET_LOADER_ID = 1;

    private ExpandableListView mList;
    private DisplayAdapter mAdapter;

    private SharedPreferences mPrefs;

    @Override
    protected void onCreate(Bundle icicle) {
        super.onCreate(icicle);
@@ -111,7 +111,6 @@ public class CustomContactListFilterActivity extends Activity implements
            }
        });

        mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
        mAdapter = new DisplayAdapter(this);

        mList.setOnCreateContextMenuListener(this);
@@ -837,6 +836,20 @@ public class CustomContactListFilterActivity extends Activity implements
        }
    }

    private boolean hasUnsavedChanges() {
        if (mAdapter == null || mAdapter.mAccounts == null) {
            return false;
        }
        if (getCurrentListFilterType() != ContactListFilter.FILTER_TYPE_CUSTOM) {
            return true;
        }
        final ArrayList<ContentProviderOperation> diff = mAdapter.mAccounts.buildDiff();
        if (diff.isEmpty()) {
            return false;
        }
        return true;
    }

    @SuppressWarnings("unchecked")
    private void doSaveAction() {
        if (mAdapter == null || mAdapter.mAccounts == null) {
@@ -933,9 +946,7 @@ public class CustomContactListFilterActivity extends Activity implements
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                // Pretend cancel.
                setResult(Activity.RESULT_CANCELED);
                finish();
                confirmFinish();
                return true;
            case R.id.menu_save:
                this.doSaveAction();
@@ -945,4 +956,47 @@ public class CustomContactListFilterActivity extends Activity implements
        }
        return super.onOptionsItemSelected(item);
    }

    @Override
    public void onBackPressed() {
        confirmFinish();
    }

    private void confirmFinish() {
        // Prompt the user whether they want to discard there customizations unless
        // nothing will be changed.
        if (hasUnsavedChanges()) {
            new ConfirmNavigationDialogFragment().show(getFragmentManager(),
                    "ConfirmNavigationDialog");
        } else {
            setResult(RESULT_CANCELED);
            finish();
        }
    }

    private int getCurrentListFilterType() {
        return getIntent().getIntExtra(EXTRA_CURRENT_LIST_FILTER_TYPE,
                ContactListFilter.FILTER_TYPE_ALL_ACCOUNTS);
    }

    public static class ConfirmNavigationDialogFragment
            extends DialogFragment implements DialogInterface.OnClickListener {

        @Override
        public Dialog onCreateDialog(Bundle savedInstanceState) {
            return new AlertDialog.Builder(getActivity(), getTheme())
                    .setMessage(R.string.leave_customize_confirmation_dialog_message)
                    .setNegativeButton(android.R.string.no, null)
                    .setPositiveButton(android.R.string.yes, this)
                    .create();
        }

        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
            if (i == DialogInterface.BUTTON_POSITIVE) {
                getActivity().setResult(RESULT_CANCELED);
                getActivity().finish();
            }
        }
    }
}