Start cleaning up QuickResponse code
Change-Id: I76b5adbe8e05713c44d11a2e51d317cae6266a56
This commit is contained in:
parent
6d3e1c9dad
commit
05273f8309
@ -14,7 +14,7 @@
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<RelativeLayout
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/line_item"
|
||||
android:layout_width="match_parent"
|
||||
@ -23,27 +23,14 @@
|
||||
android:focusable="true"
|
||||
android:padding="7dip"
|
||||
>
|
||||
<ImageView
|
||||
android:id="@+id/delete_icon"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:background="?android:attr/listChoiceBackgroundIndicator"
|
||||
android:focusable="true"
|
||||
android:padding="7dip"
|
||||
android:src="@drawable/ic_menu_trash_holo_light"
|
||||
/>
|
||||
<TextView
|
||||
android:id="@+id/quick_response_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_toLeftOf="@id/delete_icon"
|
||||
android:layout_centerVertical="true"
|
||||
style="@style/accountSetupInfoText"
|
||||
android:ellipsize="end"
|
||||
android:focusable="false"
|
||||
android:maxLines="2"
|
||||
/>
|
||||
</RelativeLayout>
|
||||
</LinearLayout>
|
||||
|
@ -54,8 +54,7 @@ import android.widget.TextView;
|
||||
*
|
||||
* <p>This fragment is run as a preference panel from AccountSettings.</p>
|
||||
*/
|
||||
public class AccountSettingsEditQuickResponsesFragment extends Fragment
|
||||
implements OnClickListener {
|
||||
public class AccountSettingsEditQuickResponsesFragment extends Fragment {
|
||||
private ListView mQuickResponsesView;
|
||||
private Account mAccount;
|
||||
private Context mContext;
|
||||
@ -69,10 +68,9 @@ public class AccountSettingsEditQuickResponsesFragment extends Fragment
|
||||
private static class ArrayAdapterWithButtons extends ArrayAdapter<QuickResponse> {
|
||||
private QuickResponse[] mQuickResponses;
|
||||
private final long mAccountId;
|
||||
private final Context mContext;
|
||||
private final FragmentManager mFragmentManager;
|
||||
|
||||
private OnClickListener mOnEditListener = new OnClickListener() {
|
||||
private final OnClickListener mOnEditListener = new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
QuickResponse quickResponse = (QuickResponse) (view.getTag());
|
||||
@ -82,23 +80,6 @@ public class AccountSettingsEditQuickResponsesFragment extends Fragment
|
||||
}
|
||||
};
|
||||
|
||||
private OnClickListener mOnDeleteListener = new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
final QuickResponse quickResponse = (QuickResponse) view.getTag();
|
||||
|
||||
// Delete the QuickResponse from the database. Content watchers used to
|
||||
// update the ListView of QuickResponses upon deletion.
|
||||
EmailAsyncTask.runAsyncParallel(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
EmailContent.delete(mContext, quickResponse.getBaseUri(),
|
||||
quickResponse.getId());
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
private static final int resourceId = R.layout.quick_response_item;
|
||||
private static final int textViewId = R.id.quick_response_text;
|
||||
|
||||
@ -116,7 +97,6 @@ public class AccountSettingsEditQuickResponsesFragment extends Fragment
|
||||
super(context, resourceId, textViewId, quickResponses);
|
||||
mQuickResponses = quickResponses;
|
||||
mAccountId = accountId;
|
||||
mContext = context;
|
||||
mFragmentManager = fragmentManager;
|
||||
}
|
||||
|
||||
@ -126,10 +106,6 @@ public class AccountSettingsEditQuickResponsesFragment extends Fragment
|
||||
convertView.setTag(mQuickResponses[position]);
|
||||
convertView.setOnClickListener(mOnEditListener);
|
||||
|
||||
ImageView deleteIcon = (ImageView) convertView.findViewById(R.id.delete_icon);
|
||||
deleteIcon.setTag(mQuickResponses[position]);
|
||||
deleteIcon.setOnClickListener(mOnDeleteListener);
|
||||
|
||||
return convertView;
|
||||
}
|
||||
}
|
||||
@ -241,13 +217,13 @@ public class AccountSettingsEditQuickResponsesFragment extends Fragment
|
||||
if (Logging.DEBUG_LIFECYCLE && MailActivityEmail.DEBUG) {
|
||||
LogUtils.d(Logging.LOG_TAG, "AccountSettingsEditQuickResponsesFragment onCreateView");
|
||||
}
|
||||
int layoutId = R.layout.account_settings_edit_quick_responses_fragment;
|
||||
View view = inflater.inflate(layoutId, container, false);
|
||||
View view = inflater.inflate(R.layout.account_settings_edit_quick_responses_fragment,
|
||||
container, false);
|
||||
mContext = getActivity();
|
||||
|
||||
mQuickResponsesView = UiUtilities.getView(view,
|
||||
R.id.account_settings_quick_responses_list);
|
||||
TextView emptyView = (TextView)
|
||||
TextView emptyView =
|
||||
UiUtilities.getView(((ViewGroup) mQuickResponsesView.getParent()), R.id.empty_view);
|
||||
mQuickResponsesView.setEmptyView(emptyView);
|
||||
|
||||
@ -265,7 +241,14 @@ public class AccountSettingsEditQuickResponsesFragment extends Fragment
|
||||
}
|
||||
});
|
||||
|
||||
UiUtilities.getView(view, R.id.create_new).setOnClickListener(this);
|
||||
UiUtilities.getView(view, R.id.create_new).setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
EditQuickResponseDialog
|
||||
.newInstance(null, mAccount.mId)
|
||||
.show(getFragmentManager(), null);
|
||||
}
|
||||
});
|
||||
|
||||
return view;
|
||||
}
|
||||
@ -275,16 +258,4 @@ public class AccountSettingsEditQuickResponsesFragment extends Fragment
|
||||
mTaskTracker.cancellAllInterrupt();
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements OnClickListener
|
||||
*/
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (v.getId() == R.id.create_new) {
|
||||
EditQuickResponseDialog
|
||||
.newInstance(null, mAccount.mId)
|
||||
.show(getFragmentManager(), null);
|
||||
}
|
||||
}
|
||||
}
|
@ -38,8 +38,7 @@ import android.widget.EditText;
|
||||
/**
|
||||
* Dialog to edit the text of a given or new quick response
|
||||
*/
|
||||
public class EditQuickResponseDialog extends DialogFragment
|
||||
implements DialogInterface.OnClickListener, TextWatcher {
|
||||
public class EditQuickResponseDialog extends DialogFragment {
|
||||
private EditText mQuickResponseEditText;
|
||||
private QuickResponse mQuickResponse;
|
||||
private AlertDialog mDialog;
|
||||
@ -73,7 +72,7 @@ public class EditQuickResponseDialog extends DialogFragment
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
final Context context = getActivity();
|
||||
mQuickResponse = (QuickResponse) getArguments().getParcelable(QUICK_RESPONSE);
|
||||
View wrapper = LayoutInflater.from(context)
|
||||
final View wrapper = LayoutInflater.from(context)
|
||||
.inflate(R.layout.quick_response_edit_dialog, null);
|
||||
mQuickResponseEditText = (EditText) wrapper.findViewById(R.id.quick_response_text);
|
||||
if (savedInstanceState != null) {
|
||||
@ -86,13 +85,66 @@ public class EditQuickResponseDialog extends DialogFragment
|
||||
mQuickResponseEditText.setText(mQuickResponse.toString());
|
||||
}
|
||||
mQuickResponseEditText.setSelection(mQuickResponseEditText.length());
|
||||
mQuickResponseEditText.addTextChangedListener(this);
|
||||
mQuickResponseEditText.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
mDialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(s.length() > 0);
|
||||
}
|
||||
});
|
||||
|
||||
DialogInterface.OnClickListener saveClickListener =
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
final long accountId = getArguments().getLong("accountId");
|
||||
final String text = mQuickResponseEditText.getText().toString();
|
||||
final Context context = getActivity();
|
||||
if (mQuickResponse == null) {
|
||||
mQuickResponse = new QuickResponse(accountId, text);
|
||||
}
|
||||
|
||||
// Insert the new QuickResponse into the database. Content watchers used to
|
||||
// update the ListView of QuickResponses upon insertion.
|
||||
EmailAsyncTask.runAsyncParallel(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!mQuickResponse.isSaved()) {
|
||||
mQuickResponse.save(context);
|
||||
} else {
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(QuickResponseColumns.TEXT, text);
|
||||
mQuickResponse.update(context, values);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
};
|
||||
DialogInterface.OnClickListener deleteClickListener =
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
if (mQuickResponse == null) {
|
||||
return;
|
||||
}
|
||||
// TODO: confirm delete
|
||||
mQuickResponse.delete(context, mQuickResponse.getBaseUri(),
|
||||
mQuickResponse.getId());
|
||||
}
|
||||
};
|
||||
|
||||
final AlertDialog.Builder b = new AlertDialog.Builder(context);
|
||||
b.setTitle(getResources().getString(R.string.edit_quick_response_dialog))
|
||||
.setView(wrapper)
|
||||
.setNegativeButton(R.string.cancel_action, this)
|
||||
.setPositiveButton(R.string.save_action, this);
|
||||
.setNegativeButton(R.string.cancel_action, null)
|
||||
.setPositiveButton(R.string.save_action, saveClickListener)
|
||||
.setNeutralButton(R.string.delete, deleteClickListener);
|
||||
mDialog = b.create();
|
||||
return mDialog;
|
||||
}
|
||||
@ -107,20 +159,6 @@ public class EditQuickResponseDialog extends DialogFragment
|
||||
}
|
||||
}
|
||||
|
||||
// implements TextWatcher
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
mDialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(s.length() > 0);
|
||||
}
|
||||
|
||||
// implements TextWatcher
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
|
||||
|
||||
// implements TextWatcher
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {}
|
||||
|
||||
// Saves contents during orientation change
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
@ -128,40 +166,4 @@ public class EditQuickResponseDialog extends DialogFragment
|
||||
outState.putString(
|
||||
QUICK_RESPONSE_EDITED_STRING, mQuickResponseEditText.getText().toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements DialogInterface.OnClickListener
|
||||
*/
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
switch (which) {
|
||||
case DialogInterface.BUTTON_NEGATIVE:
|
||||
dialog.cancel();
|
||||
break;
|
||||
case DialogInterface.BUTTON_POSITIVE:
|
||||
final long accountId = getArguments().getLong("accountId");
|
||||
final String text = mQuickResponseEditText.getText().toString();
|
||||
final Context context = getActivity();
|
||||
if (mQuickResponse == null) {
|
||||
mQuickResponse = new QuickResponse(accountId, text);
|
||||
}
|
||||
|
||||
// Insert the new QuickResponse into the database. Content watchers used to
|
||||
// update the ListView of QuickResponses upon insertion.
|
||||
EmailAsyncTask.runAsyncParallel(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!mQuickResponse.isSaved()) {
|
||||
mQuickResponse.save(context);
|
||||
} else {
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(QuickResponseColumns.TEXT, text);
|
||||
mQuickResponse.update(context, values);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user