Add option to linkify task list text

pull/757/head
Alex Baker 6 years ago
parent 78a664753d
commit e789b943fa

@ -26,11 +26,15 @@ public class Linkify {
}
public void linkify(TextView textView) {
linkify(textView, () -> {});
}
public void linkify(TextView textView, Runnable onEdit) {
BetterLinkMovementMethod.linkify(android.text.util.Linkify.ALL, textView)
.setOnLinkClickListener(this::handleLink);
.setOnLinkClickListener((tv, url) -> handleLink(url, onEdit));
}
private boolean handleLink(TextView textView, String url) {
private boolean handleLink(String url, Runnable onEdit) {
String title;
String edit = context.getString(R.string.TAd_actionEditTask);
String action;
@ -71,6 +75,8 @@ public class Linkify {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(uri);
context.startActivity(intent);
} else {
onEdit.run();
}
})
.show();

@ -46,11 +46,14 @@ public class AppearancePreferences extends InjectingPreferenceActivity
addPreferencesFromResource(R.xml.preferences_appearance);
setExtraOnChange(R.string.p_fontSize, EXTRA_RESTART);
setExtraOnChange(R.string.p_rowPadding, EXTRA_RESTART);
setExtraOnChange(R.string.p_fullTaskTitle, EXTRA_RESTART);
setExtraOnChange(R.string.p_show_description, EXTRA_RESTART);
setExtraOnChange(R.string.p_show_full_description, EXTRA_RESTART);
setExtraOnChange(
EXTRA_RESTART,
R.string.p_fontSize,
R.string.p_rowPadding,
R.string.p_fullTaskTitle,
R.string.p_show_description,
R.string.p_show_full_description,
R.string.p_linkify_task_list);
setExtraOnChange(R.string.p_show_today_filter, EXTRA_FILTERS_CHANGED);
setExtraOnChange(R.string.p_show_recently_modified_filter, EXTRA_FILTERS_CHANGED);
setExtraOnChange(R.string.p_show_not_in_list_filter, EXTRA_FILTERS_CHANGED);
@ -147,6 +150,12 @@ public class AppearancePreferences extends InjectingPreferenceActivity
});
}
private void setExtraOnChange(final String extra, final int... resIds) {
for (int resId : resIds) {
setExtraOnChange(resId, extra);
}
}
@Override
public void inject(ActivityComponent component) {
component.inject(this);

@ -30,6 +30,7 @@ import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.ui.CheckableImageView;
import java.util.List;
import org.tasks.R;
import org.tasks.dialogs.Linkify;
import org.tasks.locale.Locale;
import org.tasks.preferences.Preferences;
import org.tasks.ui.CheckBoxes;
@ -47,6 +48,7 @@ class ViewHolder extends RecyclerView.ViewHolder {
private final DisplayMetrics metrics;
private final int background;
private final int selectedColor;
private final Linkify linkify;
private final int textColorOverdue;
private final ChipProvider chipProvider;
private final int fontSizeDetails;
@ -97,7 +99,8 @@ class ViewHolder extends RecyclerView.ViewHolder {
DisplayMetrics metrics,
int background,
int selectedColor,
int rowPadding) {
int rowPadding,
Linkify linkify) {
super(view);
this.context = context;
this.preferences = preferences;
@ -111,6 +114,7 @@ class ViewHolder extends RecyclerView.ViewHolder {
this.metrics = metrics;
this.background = background;
this.selectedColor = selectedColor;
this.linkify = linkify;
ButterKnife.bind(this, view);
if (preferences.getBoolean(R.string.p_fullTaskTitle, false)) {
@ -207,6 +211,10 @@ class ViewHolder extends RecyclerView.ViewHolder {
description.setText(task.getNotes());
description.setVisibility(task.hasNotes() ? View.VISIBLE : View.GONE);
}
if (preferences.getBoolean(R.string.p_linkify_task_list, false)) {
linkify.linkify(nameView, this::onRowBodyClick);
linkify.linkify(description, this::onRowBodyClick);
}
}
/** Helper method to set the contents and visibility of each field */

@ -12,6 +12,7 @@ import android.view.ViewGroup;
import com.todoroo.astrid.dao.TaskDao;
import javax.inject.Inject;
import org.tasks.R;
import org.tasks.dialogs.Linkify;
import org.tasks.injection.ForActivity;
import org.tasks.locale.Locale;
import org.tasks.preferences.Preferences;
@ -33,6 +34,7 @@ public class ViewHolderFactory {
private final int background;
private final int selectedColor;
private final int rowPadding;
private final Linkify linkify;
private final Preferences preferences;
@Inject
@ -42,13 +44,15 @@ public class ViewHolderFactory {
Preferences preferences,
CheckBoxes checkBoxes,
ChipProvider chipProvider,
TaskDao taskDao) {
TaskDao taskDao,
Linkify linkify) {
this.context = context;
this.locale = locale;
this.checkBoxes = checkBoxes;
this.chipProvider = chipProvider;
this.taskDao = taskDao;
this.preferences = preferences;
this.linkify = linkify;
textColorPrimary = getColor(context, R.color.text_primary);
textColorSecondary = getData(context, android.R.attr.textColorSecondary);
textColorOverdue = getColor(context, R.color.overdue);
@ -77,6 +81,7 @@ public class ViewHolderFactory {
metrics,
background,
selectedColor,
rowPadding);
rowPadding,
linkify);
}
}

@ -293,4 +293,5 @@
<string name="p_last_backup">last_backup</string>
<string name="p_show_description">show_description</string>
<string name="p_show_full_description">show_full_description</string>
<string name="p_linkify_task_list">linkify_task_list</string>
</resources>

@ -871,4 +871,6 @@ File %1$s contained %2$s.\n\n
<string name="action_create_new_task">Create new task</string>
<string name="show_description">Show description</string>
<string name="show_full_description">Show full description</string>
<string name="linkify">Show links</string>
<string name="linkify_description">Add links to websites, addresses, and phone numbers</string>
</resources>

@ -34,6 +34,12 @@
android:dependency="@string/p_show_description"
android:title="@string/show_full_description" />
<CheckBoxPreference
android:defaultValue="false"
android:key="@string/p_linkify_task_list"
android:title="@string/linkify"
android:summary="@string/linkify_description"/>
</PreferenceCategory>
<PreferenceCategory android:title="@string/EPr_edit_screen_options">

Loading…
Cancel
Save