diff --git a/CHANGELOG.md b/CHANGELOG.md index f5df63c2..5d8fbace 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## v1.4.0 - Added a label attribute to hide all notes with that label in active & archive destinations. The notes are still visible in the trash and in the label's destination. +- Added clickable links for website & email in edit screen. - Added Spanish translation - Show keyboard when note is converted to text or list. - Fixed bug allowing to create two labels with the same name, and blank labels. diff --git a/app/src/main/kotlin/com/maltaisn/notes/ui/edit/adapter/EditListViewHolder.kt b/app/src/main/kotlin/com/maltaisn/notes/ui/edit/adapter/EditListViewHolder.kt index 462b45da..d4366dbb 100644 --- a/app/src/main/kotlin/com/maltaisn/notes/ui/edit/adapter/EditListViewHolder.kt +++ b/app/src/main/kotlin/com/maltaisn/notes/ui/edit/adapter/EditListViewHolder.kt @@ -19,13 +19,17 @@ package com.maltaisn.notes.ui.edit.adapter import android.text.Editable import android.text.TextWatcher import android.text.format.DateUtils +import android.text.method.LinkMovementMethod import android.text.style.CharacterStyle +import android.text.util.Linkify import android.view.KeyEvent import android.view.LayoutInflater import android.view.View import androidx.core.text.getSpans +import androidx.core.text.util.LinkifyCompat import androidx.core.view.isInvisible -import androidx.core.widget.doOnTextChanged +import androidx.core.widget.addTextChangedListener +import androidx.core.widget.doAfterTextChanged import androidx.recyclerview.widget.RecyclerView import com.google.android.material.chip.Chip import com.maltaisn.notes.hideKeyboard @@ -95,6 +99,7 @@ class EditTitleViewHolder(binding: ItemEditTitleBinding, callback: EditAdapter.C override fun setFocus(pos: Int) { titleEdt.requestFocus() titleEdt.setSelection(pos) + titleEdt.showKeyboard() } } @@ -106,6 +111,13 @@ class EditContentViewHolder(binding: ItemEditContentBinding, callback: EditAdapt init { contentEdt.addTextChangedListener(BulletTextWatcher()) contentEdt.addTextChangedListener(clearSpansTextWatcher) + contentEdt.doAfterTextChanged { editable -> + // Add new links + LinkifyCompat.addLinks(editable ?: return@doAfterTextChanged, + Linkify.WEB_URLS or Linkify.EMAIL_ADDRESSES) + } + contentEdt.movementMethod = LinkMovementMethod.getInstance() // Clickable links + contentEdt.setOnClickListener { callback.onNoteClickedToEdit() } @@ -157,16 +169,24 @@ class EditItemViewHolder(binding: ItemEditItemBinding, callback: EditAdapter.Cal itemEdt.addTextChangedListener(clearSpansTextWatcher) - itemEdt.doOnTextChanged { _, _, _, count -> - // This is used to detect when user enters line breaks into the input, so the - // item can be split into multiple items. When user enters a single line break, - // selection is set at the beginning of new item. On paste, i.e. when more than one - // character is entered, selection is set at the end of last new item. - val pos = bindingAdapterPosition - if (pos != RecyclerView.NO_POSITION) { - callback.onNoteItemChanged(pos, count > 1) - } - } + itemEdt.addTextChangedListener( + beforeTextChanged = { _, _, _, _ -> }, + onTextChanged = { _, _, _, count -> + // This is used to detect when user enters line breaks into the input, so the + // item can be split into multiple items. When user enters a single line break, + // selection is set at the beginning of new item. On paste, i.e. when more than one + // character is entered, selection is set at the end of last new item. + val pos = bindingAdapterPosition + if (pos != RecyclerView.NO_POSITION) { + callback.onNoteItemChanged(pos, count > 1) + } + }, + afterTextChanged = { editable -> + // Add new links + LinkifyCompat.addLinks(editable ?: return@addTextChangedListener, + Linkify.WEB_URLS or Linkify.EMAIL_ADDRESSES) + }) + itemEdt.movementMethod = LinkMovementMethod.getInstance() // Clickable links itemEdt.setOnFocusChangeListener { _, hasFocus -> // Only show delete icon for currently focused item. deleteImv.isInvisible = !hasFocus diff --git a/app/src/main/res/layout/item_edit_content.xml b/app/src/main/res/layout/item_edit_content.xml index 626534ea..dee2b176 100644 --- a/app/src/main/res/layout/item_edit_content.xml +++ b/app/src/main/res/layout/item_edit_content.xml @@ -31,4 +31,6 @@ android:inputType="textMultiLine|textLongMessage|textCapSentences|textAutoCorrect" android:textAppearance="?textAppearanceBody1" android:textSize="15sp" + android:autoLink="web|email" + android:linksClickable="true" /> diff --git a/app/src/main/res/layout/item_edit_header.xml b/app/src/main/res/layout/item_edit_header.xml index 8fb03b95..3f9007e5 100644 --- a/app/src/main/res/layout/item_edit_header.xml +++ b/app/src/main/res/layout/item_edit_header.xml @@ -18,12 +18,14 @@ xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/title_txv" - android:layout_width="match_parent" + android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingTop="16dp" android:paddingBottom="8dp" android:paddingStart="40dp" android:paddingEnd="16dp" + android:maxLines="1" + android:ellipsize="end" android:textAppearance="@style/TextAppearance.MaterialComponents.Body2" android:textColor="@color/material_on_background_emphasis_medium" android:textStyle="bold" diff --git a/app/src/main/res/layout/item_edit_item.xml b/app/src/main/res/layout/item_edit_item.xml index d06682fe..942d7b18 100644 --- a/app/src/main/res/layout/item_edit_item.xml +++ b/app/src/main/res/layout/item_edit_item.xml @@ -64,6 +64,8 @@ android:textDirection="anyRtl" android:textColor="@color/item_edit_item_text_color" android:textSize="15sp" + android:autoLink="web|email" + android:linksClickable="true" tools:ignore="LabelFor" tools:text="Mauris rutrum massa placerat felis pharetra tristique. Nulla sed urna a dui vehicula euismod." />