Create AddLabelDialog and use in TimerViewHolder
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
package com.philliphsu.clock2;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.app.AppCompatDialogFragment;
|
||||
import android.widget.EditText;
|
||||
|
||||
/**
|
||||
* Created by Phillip Hsu on 8/30/2016.
|
||||
*
|
||||
* TODO: If we have any other needs for a dialog with an EditText, rename this to EditTextDialog,
|
||||
* and change the callback interface name appropriately.
|
||||
*/
|
||||
public class AddLabelDialog extends AppCompatDialogFragment {
|
||||
|
||||
private EditText mEditText;
|
||||
private OnLabelSetListener mOnLabelSetListener;
|
||||
|
||||
private CharSequence mInitialText;
|
||||
|
||||
public interface OnLabelSetListener {
|
||||
void onLabelSet(CharSequence label);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param text the initial text
|
||||
*/
|
||||
public static AddLabelDialog newInstance(CharSequence text) {
|
||||
AddLabelDialog dialog = new AddLabelDialog();
|
||||
dialog.mInitialText = text;
|
||||
return dialog;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
mEditText = new EditText(getActivity());
|
||||
mEditText.setText(mInitialText);
|
||||
mEditText.setSelection(0, mEditText.length());
|
||||
|
||||
return new AlertDialog.Builder(getActivity(), getTheme())
|
||||
.setTitle(R.string.label)
|
||||
.setView(mEditText)
|
||||
.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dismiss();
|
||||
}
|
||||
})
|
||||
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
if (mOnLabelSetListener != null) {
|
||||
mOnLabelSetListener.onLabelSet(mEditText.getText());
|
||||
}
|
||||
dismiss();
|
||||
}
|
||||
})
|
||||
.create();
|
||||
}
|
||||
|
||||
public void setOnLabelSetListener(OnLabelSetListener onLabelSetListener) {
|
||||
mOnLabelSetListener = onLabelSetListener;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.philliphsu.clock2.timers;
|
||||
|
||||
import android.animation.ObjectAnimator;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@@ -8,6 +9,7 @@ import android.widget.ImageButton;
|
||||
import android.widget.SeekBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.philliphsu.clock2.AddLabelDialog;
|
||||
import com.philliphsu.clock2.AsyncTimersTableUpdateHandler;
|
||||
import com.philliphsu.clock2.BaseViewHolder;
|
||||
import com.philliphsu.clock2.OnListItemInteractionListener;
|
||||
@@ -69,6 +71,14 @@ public class TimerViewHolder extends BaseViewHolder<Timer> {
|
||||
mController.stop();
|
||||
}
|
||||
|
||||
@OnClick(R.id.label)
|
||||
void openLabelEditor() {
|
||||
AddLabelDialog dialog = AddLabelDialog.newInstance(mLabel.getText());
|
||||
// TODO: This is bad! Use a Controller instead!
|
||||
AppCompatActivity act = (AppCompatActivity) getContext();
|
||||
dialog.show(act.getSupportFragmentManager(), "TAG");
|
||||
}
|
||||
|
||||
private void bindLabel(String label) {
|
||||
if (!label.isEmpty()) {
|
||||
mLabel.setText(label);
|
||||
|
||||
Reference in New Issue
Block a user