Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "note shared" indicator to notes in the notes list #1499

Merged
merged 8 commits into from
Sep 24, 2021
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,7 @@ public interface Callbacks {

// view holder for NotesCursorAdapter
private static class NoteViewHolder {
private ImageView mHasCollaborators;
private ImageView mPinned;
private ImageView mPublished;
private TextView mContent;
Expand Down Expand Up @@ -938,6 +939,7 @@ public View getView(final int position, View view, ViewGroup parent) {
holder.mTitle = view.findViewById(R.id.note_title);
holder.mContent = view.findViewById(R.id.note_content);
holder.mDate = view.findViewById(R.id.note_date);
holder.mHasCollaborators = view.findViewById(R.id.note_shared);
holder.mPinned = view.findViewById(R.id.note_pinned);
holder.mPublished = view.findViewById(R.id.note_published);
holder.mStatus = view.findViewById(R.id.note_status);
Expand Down Expand Up @@ -966,11 +968,13 @@ public View getView(final int position, View view, ViewGroup parent) {
Calendar date = getDateByPreference(mCursor.getObject());
holder.mDate.setText(date != null ? DateTimeUtils.getDateTextNumeric(date) : "");
holder.mDate.setVisibility(mIsSearching && date != null ? View.VISIBLE : View.GONE);
boolean hasCollaborators = mCursor.getObject().hasCollaborators();
holder.mHasCollaborators.setVisibility(!hasCollaborators || mIsSearching ? View.GONE : View.VISIBLE);
boolean isPinned = mCursor.getObject().isPinned();
holder.mPinned.setVisibility(!isPinned || mIsSearching ? View.GONE : View.VISIBLE);
boolean isPublished = !mCursor.getObject().getPublishedUrl().isEmpty();
holder.mPublished.setVisibility(!isPublished || mIsSearching ? View.GONE : View.VISIBLE);
boolean showIcons = isPinned || isPublished;
boolean showIcons = isPinned || isPublished || hasCollaborators;
boolean showDate = mIsSearching && date != null;
holder.mStatus.setVisibility(showIcons || showDate ? View.VISIBLE : View.GONE);
String title = mCursor.getString(mCursor.getColumnIndex(Note.TITLE_INDEX_NAME));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import com.automattic.simplenote.R;
import com.automattic.simplenote.utils.DateTimeUtils;
import com.automattic.simplenote.utils.StrUtils;
import com.automattic.simplenote.utils.TagUtils;
import com.simperium.client.Bucket;
import com.simperium.client.BucketObject;
Expand Down Expand Up @@ -38,6 +39,7 @@ public class Note extends BucketObject {
public static final String BUCKET_NAME = "note";
public static final String MARKDOWN_TAG = "markdown";
public static final String PINNED_TAG = "pinned";
public static final String SHARED_TAG = "shared";
public static final String PREVIEW_TAG = "preview";
public static final String PUBLISHED_TAG = "published";
public static final String NEW_LINE = "\n";
Expand Down Expand Up @@ -480,6 +482,20 @@ public boolean isPinned() {
return hasSystemTag(PINNED_TAG);
}

public boolean isShared() {
return hasSystemTag(SHARED_TAG);
}

public boolean hasCollaborators() {
for (String tag : getTags()) {
if (StrUtils.isEmail(tag)) {
return true;
}
}

return false;
}

public void setPinned(boolean isPinned) {
if (isPinned) {
addSystemTag(PINNED_TAG);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package com.automattic.simplenote.repositories

import android.text.TextUtils
import androidx.core.util.PatternsCompat.EMAIL_ADDRESS
import com.automattic.simplenote.di.IO_THREAD
import com.automattic.simplenote.models.Note
import com.automattic.simplenote.utils.Either
import com.automattic.simplenote.utils.StrUtils.isEmail
import com.simperium.client.Bucket
import com.simperium.client.BucketObjectMissingException
import kotlinx.coroutines.CoroutineDispatcher
Expand All @@ -29,7 +28,7 @@ class SimperiumCollaboratorsRepository @Inject constructor(
* For now we do not make an extra check to see whether there is an account linked to the email or not
*/
override fun isValidCollaborator(collaborator: String): Boolean {
return !TextUtils.isEmpty(collaborator) && EMAIL_ADDRESS.matcher(collaborator).matches()
return isEmail(collaborator)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* added 01-Apr-2013 by Nick Bradbury
*/

import static androidx.core.util.PatternsCompat.EMAIL_ADDRESS;

import android.text.Spanned;
import android.text.TextUtils;

Expand All @@ -21,6 +23,10 @@ private StrUtils() {
throw new AssertionError();
}

public static boolean isEmail(String str) {
return !TextUtils.isEmpty(str) && EMAIL_ADDRESS.matcher(str).matches();
}

// returns true if the passed string is null or empty
public static boolean isBlankStr(String str) {
return (str == null || str.length() == 0);
Expand Down
9 changes: 9 additions & 0 deletions Simplenote/src/main/res/drawable/ic_collaborate_16dp.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="16dp"
android:height="16dp"
android:viewportWidth="16"
android:viewportHeight="16">
<path
android:fillColor="@android:color/white"
android:pathData="M4,5a4,4 0,1 1,8 0,4 4,0 0,1 -8,0zM8,10a7,7 0,0 0,-6.706 5h13.413A7.002,7.002 0,0 0,8 10z"/>
</vector>
16 changes: 16 additions & 0 deletions Simplenote/src/main/res/layout/note_list_row.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
android:focusable="false"
android:layout_height="@dimen/icon_status"
android:layout_marginStart="@dimen/padding_small"
android:layout_toEndOf="@id/note_shared"
android:layout_width="@dimen/icon_status"
android:src="@drawable/ic_publish_16dp"
android:tint="?attr/notePreviewColor"
Expand All @@ -66,6 +67,21 @@
tools:visibility="visible">
</ImageView>

<ImageView
android:id="@+id/note_shared"
android:contentDescription="@string/note_shared"
android:clickable="false"
android:focusable="false"
android:layout_height="@dimen/icon_status"
android:layout_marginStart="@dimen/padding_small"
android:layout_width="@dimen/icon_status"
android:src="@drawable/ic_collaborate_16dp"
android:tint="?attr/notePreviewColor"
android:visibility="gone"
tools:tint="@color/text_content_light"
tools:visibility="visible">
</ImageView>

</RelativeLayout>

<TextView
Expand Down
2 changes: 2 additions & 0 deletions Simplenote/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -326,9 +326,11 @@

<string name="toast_email_sent">Email sent</string>


<string name="shared_with">Shared With</string>

<!-- Collaboration -->
<string name="note_shared">Note Shared</string>
<string name="add_collaborator">Add Collaborator</string>
<string name="add_email_collaborator_message">Add an email address to share this note with someone then you can both make changes to it. When you add a collaborator, they will be notified by email.</string>
<string name="loading_collaborators">Loading…</string>
Expand Down