Linkify description popup

pull/467/head
Alex Baker 9 years ago
parent b8162cb296
commit b042dcf0cf

@ -10,12 +10,15 @@ import android.content.Context;
import android.content.res.Resources; import android.content.res.Resources;
import android.database.Cursor; import android.database.Cursor;
import android.graphics.Paint; import android.graphics.Paint;
import android.support.v7.app.AlertDialog;
import android.text.SpannableString; import android.text.SpannableString;
import android.text.SpannableStringBuilder; import android.text.SpannableStringBuilder;
import android.text.Spanned; import android.text.Spanned;
import android.text.TextUtils; import android.text.TextUtils;
import android.text.method.LinkMovementMethod;
import android.text.style.BackgroundColorSpan; import android.text.style.BackgroundColorSpan;
import android.text.style.ForegroundColorSpan; import android.text.style.ForegroundColorSpan;
import android.text.util.Linkify;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
import android.util.TypedValue; import android.util.TypedValue;
import android.view.LayoutInflater; import android.view.LayoutInflater;
@ -433,19 +436,20 @@ public class TaskAdapter extends CursorAdapter implements Filterable {
} }
private void showEditNotesDialog(final Task task) { private void showEditNotesDialog(final Task task) {
String notes = null;
Task t = taskDao.fetch(task.getId(), Task.NOTES); Task t = taskDao.fetch(task.getId(), Task.NOTES);
if (t != null) { if (t == null || !t.hasNotes()) {
notes = t.getNotes();
}
if (TextUtils.isEmpty(notes)) {
return; return;
} }
SpannableString description = new SpannableString(t.getNotes());
dialogBuilder.newDialog() Linkify.addLinks(description, Linkify.ALL);
.setMessage(notes) AlertDialog dialog = dialogBuilder.newDialog()
.setMessage(description)
.setPositiveButton(android.R.string.ok, null) .setPositiveButton(android.R.string.ok, null)
.show(); .show();
View message = dialog.findViewById(android.R.id.message);
if (message != null && message instanceof TextView) {
((TextView) message).setMovementMethod(LinkMovementMethod.getInstance());
}
} }
private void showFilesDialog(Task task) { private void showFilesDialog(Task task) {

@ -8,6 +8,7 @@ package com.todoroo.astrid.data;
import android.content.ContentValues; import android.content.ContentValues;
import android.net.Uri; import android.net.Uri;
import android.text.TextUtils;
import com.todoroo.andlib.data.Property; import com.todoroo.andlib.data.Property;
import com.todoroo.andlib.data.Property.IntegerProperty; import com.todoroo.andlib.data.Property.IntegerProperty;
@ -518,6 +519,10 @@ public class Task extends RemoteModel {
return getValue(NOTES); return getValue(NOTES);
} }
public boolean hasNotes() {
return !TextUtils.isEmpty(getValue(NOTES));
}
public void setNotes(String notes) { public void setNotes(String notes) {
setValue(NOTES, notes); setValue(NOTES, notes);
} }

@ -39,6 +39,11 @@ public class AlertDialogBuilder {
return this; return this;
} }
public AlertDialogBuilder setMessage(CharSequence charSequence) {
builder.setMessage(charSequence);
return this;
}
public AlertDialogBuilder setPositiveButton(int ok, DialogInterface.OnClickListener onClickListener) { public AlertDialogBuilder setPositiveButton(int ok, DialogInterface.OnClickListener onClickListener) {
builder.setPositiveButton(ok, onClickListener); builder.setPositiveButton(ok, onClickListener);
return this; return this;

Loading…
Cancel
Save