Create AddLabelDialog and use in TimerViewHolder
This commit is contained in:
parent
c2d86389b0
commit
d1f3fae2c3
68
app/src/main/java/com/philliphsu/clock2/AddLabelDialog.java
Normal file
68
app/src/main/java/com/philliphsu/clock2/AddLabelDialog.java
Normal file
@ -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;
|
package com.philliphsu.clock2.timers;
|
||||||
|
|
||||||
import android.animation.ObjectAnimator;
|
import android.animation.ObjectAnimator;
|
||||||
|
import android.support.v7.app.AppCompatActivity;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
@ -8,6 +9,7 @@ import android.widget.ImageButton;
|
|||||||
import android.widget.SeekBar;
|
import android.widget.SeekBar;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.philliphsu.clock2.AddLabelDialog;
|
||||||
import com.philliphsu.clock2.AsyncTimersTableUpdateHandler;
|
import com.philliphsu.clock2.AsyncTimersTableUpdateHandler;
|
||||||
import com.philliphsu.clock2.BaseViewHolder;
|
import com.philliphsu.clock2.BaseViewHolder;
|
||||||
import com.philliphsu.clock2.OnListItemInteractionListener;
|
import com.philliphsu.clock2.OnListItemInteractionListener;
|
||||||
@ -69,6 +71,14 @@ public class TimerViewHolder extends BaseViewHolder<Timer> {
|
|||||||
mController.stop();
|
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) {
|
private void bindLabel(String label) {
|
||||||
if (!label.isEmpty()) {
|
if (!label.isEmpty()) {
|
||||||
mLabel.setText(label);
|
mLabel.setText(label);
|
||||||
|
|||||||
@ -15,7 +15,7 @@
|
|||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_centerHorizontal="true"
|
android:layout_centerHorizontal="true"
|
||||||
android:text="Label"
|
android:hint="@string/label"
|
||||||
android:textSize="@dimen/text_size_medium"
|
android:textSize="@dimen/text_size_medium"
|
||||||
android:layout_marginTop="@dimen/item_padding_top"
|
android:layout_marginTop="@dimen/item_padding_top"
|
||||||
android:layout_marginBottom="@dimen/item_margin_between_elements"/>
|
android:layout_marginBottom="@dimen/item_margin_between_elements"/>
|
||||||
|
|||||||
@ -16,7 +16,7 @@
|
|||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_centerHorizontal="true"
|
android:layout_centerHorizontal="true"
|
||||||
android:text="Label"
|
android:hint="@string/label"
|
||||||
android:textSize="@dimen/text_size_medium"
|
android:textSize="@dimen/text_size_medium"
|
||||||
android:layout_marginTop="@dimen/item_padding_top"
|
android:layout_marginTop="@dimen/item_padding_top"
|
||||||
android:layout_marginBottom="@dimen/item_margin_between_elements"/>
|
android:layout_marginBottom="@dimen/item_margin_between_elements"/>
|
||||||
|
|||||||
@ -200,4 +200,6 @@
|
|||||||
|
|
||||||
<string name="alarm_auto_silenced_text">You missed your alarm.</string>
|
<string name="alarm_auto_silenced_text">You missed your alarm.</string>
|
||||||
<string name="timer_auto_silenced_text">Your timer expired.</string>
|
<string name="timer_auto_silenced_text">Your timer expired.</string>
|
||||||
|
|
||||||
|
<string name="label">Label</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user