Skip to content

Commit 0869da1

Browse files
feat: Add conditional/relative date/time formatting
Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
1 parent 433091e commit 0869da1

File tree

8 files changed

+530
-116
lines changed

8 files changed

+530
-116
lines changed

app/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ dependencies {
119119
}
120120

121121
// Nextcloud SSO
122-
implementation 'com.github.nextcloud.android-common:ui:0.28.0'
122+
implementation 'com.github.nextcloud.android-common:ui:869b4380ad'
123+
implementation 'com.github.nextcloud.android-common:core:869b4380ad'
123124
implementation("com.github.nextcloud:Android-SingleSignOn:$singleSignOnVersion") {
124125
version {
125126
strictly(singleSignOnVersion)

app/src/main/java/it/niedermann/owncloud/notes/main/items/ItemAdapter.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ public void onBindViewHolder(@NonNull final RecyclerView.ViewHolder holder, int
181181
((ImageView) holder.itemView.findViewById(R.id.custom_checkbox)).setImageResource(R.drawable.ic_checkbox_blank_outline);
182182
}
183183
holder.itemView.findViewById(R.id.custom_checkbox).setVisibility(isMultiSelect ? View.VISIBLE : View.GONE);
184+
holder.itemView.findViewById(R.id.noteFavorite).setVisibility(isMultiSelect ? View.GONE : View.VISIBLE);
184185
((NoteViewHolder) holder).bind(isSelected, (Note) itemList.get(position), showCategory, color, searchQuery);
185186
}
186187
}

app/src/main/java/it/niedermann/owncloud/notes/main/items/NoteViewHolder.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
import android.content.Context;
1414
import android.text.TextUtils;
15-
import android.text.format.DateFormat;
1615
import android.view.View;
1716
import android.widget.ImageView;
1817
import android.widget.TextView;
@@ -26,11 +25,10 @@
2625
import androidx.recyclerview.widget.RecyclerView;
2726

2827
import com.google.android.material.chip.Chip;
28+
import com.nextcloud.android.common.core.utils.DateFormatter;
2929
import com.nextcloud.android.common.ui.theme.utils.ColorRole;
3030

31-
import java.text.SimpleDateFormat;
3231
import java.util.Calendar;
33-
import java.util.Locale;
3432

3533
import it.niedermann.owncloud.notes.R;
3634
import it.niedermann.owncloud.notes.branding.BrandingUtil;
@@ -42,16 +40,14 @@ public abstract class NoteViewHolder extends RecyclerView.ViewHolder {
4240
@NonNull
4341
private final NoteClickListener noteClickListener;
4442

45-
private final SimpleDateFormat sdf;
43+
@NonNull
44+
private final DateFormatter dateFormatter;
4645

4746
public NoteViewHolder(@NonNull View v, @NonNull NoteClickListener noteClickListener) {
4847
super(v);
4948
this.noteClickListener = noteClickListener;
5049
this.setIsRecyclable(false);
51-
52-
Locale locale = v.getResources().getConfiguration().locale;
53-
String pattern = DateFormat.getBestDateTimePattern(locale, "dd.MM.");
54-
this.sdf = new SimpleDateFormat(pattern, locale);
50+
this.dateFormatter = new DateFormatter(v.getContext());
5551
}
5652

5753
@CallSuper
@@ -63,7 +59,7 @@ public void bind(boolean isSelected, @NonNull Note note, boolean showCategory, @
6359

6460
protected void bindModified(@NonNull TextView noteModified, @Nullable Calendar modified) {
6561
if (modified != null && modified.getTimeInMillis() > 0) {
66-
noteModified.setText(sdf.format(modified.getTime()));
62+
noteModified.setText(dateFormatter.getConditionallyRelativeFormattedTimeSpan(modified));
6763
noteModified.setVisibility(VISIBLE);
6864
} else {
6965
noteModified.setVisibility(INVISIBLE);

app/src/main/res/layout/item_notes_list_note_item_grid.xml

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,17 @@
6464
android:padding="@dimen/spacer_2x"
6565
tools:src="@drawable/ic_star_yellow_24dp" />
6666

67+
<ImageView
68+
android:id="@+id/custom_checkbox"
69+
android:layout_width="wrap_content"
70+
android:layout_height="match_parent"
71+
android:layout_gravity="top"
72+
android:clickable="false"
73+
android:contentDescription="@null"
74+
android:focusable="false"
75+
android:padding="@dimen/spacer_2x"
76+
android:src="@drawable/ic_checkbox_blank_outline" />
77+
6778
<androidx.appcompat.widget.AppCompatImageView
6879
android:id="@+id/noteStatus"
6980
android:layout_width="wrap_content"
@@ -114,18 +125,6 @@
114125
tools:text="27.11." />
115126

116127
</LinearLayout>
117-
118-
<ImageView
119-
android:id="@+id/custom_checkbox"
120-
android:layout_width="wrap_content"
121-
android:layout_height="match_parent"
122-
android:layout_gravity="top"
123-
android:clickable="false"
124-
android:contentDescription="@null"
125-
android:focusable="false"
126-
android:paddingStart="@dimen/spacer_1x"
127-
android:paddingEnd="@dimen/spacer_1x"
128-
android:src="@drawable/ic_checkbox_blank_outline" />
129128
</LinearLayout>
130129
</LinearLayout>
131130
</com.google.android.material.card.MaterialCardView>

app/src/main/res/layout/item_notes_list_note_item_grid_only_title.xml

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,16 @@
5858
android:padding="@dimen/spacer_2x"
5959
tools:src="@drawable/ic_star_yellow_24dp" />
6060

61+
<ImageView
62+
android:id="@+id/custom_checkbox"
63+
android:layout_width="wrap_content"
64+
android:layout_height="match_parent"
65+
android:clickable="false"
66+
android:contentDescription="@null"
67+
android:focusable="false"
68+
android:padding="@dimen/spacer_2x"
69+
android:src="@drawable/ic_checkbox_blank_outline" />
70+
6171
<androidx.appcompat.widget.AppCompatImageView
6272
android:id="@+id/noteStatus"
6373
android:layout_width="wrap_content"
@@ -108,18 +118,6 @@
108118
tools:text="27.11." />
109119

110120
</LinearLayout>
111-
112-
<ImageView
113-
android:id="@+id/custom_checkbox"
114-
android:layout_width="wrap_content"
115-
android:layout_height="match_parent"
116-
android:layout_gravity="top"
117-
android:clickable="false"
118-
android:contentDescription="@null"
119-
android:focusable="false"
120-
android:paddingStart="@dimen/spacer_1x"
121-
android:paddingEnd="@dimen/spacer_1x"
122-
android:src="@drawable/ic_checkbox_blank_outline" />
123121
</LinearLayout>
124122
</LinearLayout>
125123

app/src/main/res/layout/item_notes_list_note_item_with_excerpt.xml

Lines changed: 25 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,8 @@
2828
android:id="@+id/noteDeleteRight"
2929
android:layout_width="wrap_content"
3030
android:layout_height="wrap_content"
31-
android:layout_gravity="end|top"
32-
android:layout_marginEnd="@dimen/spacer_1x"
33-
android:layout_marginTop="@dimen/spacer_1x"
31+
android:layout_gravity="end|center_vertical"
32+
android:layout_marginEnd="@dimen/spacer_2x"
3433
android:contentDescription="@string/menu_delete"
3534
app:srcCompat="@drawable/ic_delete_white_24dp" />
3635

@@ -40,6 +39,7 @@
4039
android:layout_height="wrap_content"
4140
android:background="@drawable/list_item_background_selector"
4241
android:baselineAligned="false"
42+
android:gravity="center_vertical"
4343
android:paddingStart="@dimen/spacer_activity_sides"
4444
android:paddingEnd="@null">
4545

@@ -49,13 +49,23 @@
4949

5050
<ImageView
5151
android:id="@+id/noteFavorite"
52-
android:layout_width="wrap_content"
52+
android:layout_width="56dp"
5353
android:layout_height="match_parent"
5454
android:background="?attr/selectableItemBackgroundBorderless"
5555
android:contentDescription="@string/menu_favorite"
5656
android:padding="@dimen/spacer_2x"
5757
tools:src="@drawable/ic_star_yellow_24dp" />
5858

59+
<ImageView
60+
android:id="@+id/custom_checkbox"
61+
android:layout_width="56dp"
62+
android:layout_height="match_parent"
63+
android:clickable="false"
64+
android:contentDescription="@null"
65+
android:focusable="false"
66+
android:padding="@dimen/spacer_2x"
67+
android:src="@drawable/ic_checkbox_blank_outline" />
68+
5969
<androidx.appcompat.widget.AppCompatImageView
6070
android:id="@+id/noteStatus"
6171
android:layout_width="wrap_content"
@@ -67,14 +77,13 @@
6777
app:srcCompat="@drawable/ic_sync_blue_18dp" />
6878
</FrameLayout>
6979

70-
7180
<LinearLayout
7281
android:layout_width="0dp"
7382
android:layout_height="wrap_content"
7483
android:layout_weight="1"
7584
android:orientation="vertical"
7685
android:paddingVertical="@dimen/spacer_2x"
77-
android:paddingStart="0dp"
86+
android:paddingStart="@dimen/zero"
7887
android:paddingEnd="@dimen/spacer_2x">
7988

8089
<LinearLayout
@@ -91,6 +100,16 @@
91100
android:textColor="?android:textColorPrimary"
92101
android:textSize="@dimen/primary_font_size"
93102
tools:text="@tools:sample/lorem/random" />
103+
104+
<TextView
105+
android:id="@+id/noteModified"
106+
android:layout_width="wrap_content"
107+
android:layout_height="wrap_content"
108+
android:paddingStart="@dimen/spacer_1x"
109+
android:paddingEnd="@dimen/zero"
110+
android:layout_gravity="end"
111+
tools:text="27.11." />
112+
94113
</LinearLayout>
95114

96115

@@ -126,35 +145,5 @@
126145
</LinearLayout>
127146
</LinearLayout>
128147

129-
<LinearLayout
130-
android:layout_width="wrap_content"
131-
android:layout_height="match_parent"
132-
android:gravity="bottom"
133-
android:orientation="vertical">
134-
135-
<ImageView
136-
android:id="@+id/custom_checkbox"
137-
android:layout_width="wrap_content"
138-
android:layout_height="wrap_content"
139-
android:layout_gravity="end"
140-
android:clickable="false"
141-
android:contentDescription="@null"
142-
android:focusable="false"
143-
android:paddingStart="@dimen/spacer_1x"
144-
android:paddingEnd="@dimen/spacer_1x"
145-
android:src="@drawable/ic_checkbox_blank_outline" />
146-
147-
<TextView
148-
android:id="@+id/noteModified"
149-
android:layout_width="wrap_content"
150-
android:layout_height="wrap_content"
151-
android:layout_gravity="end"
152-
android:paddingStart="@dimen/zero"
153-
android:paddingTop="@dimen/spacer_1x"
154-
android:paddingEnd="@dimen/spacer_1x"
155-
android:paddingBottom="@dimen/spacer_2x"
156-
tools:text="27.11." />
157-
158-
</LinearLayout>
159148
</LinearLayout>
160149
</FrameLayout>

app/src/main/res/layout/item_notes_list_note_item_without_excerpt.xml

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
android:layout_width="wrap_content"
2828
android:layout_height="wrap_content"
2929
android:layout_gravity="end|center_vertical"
30-
android:layout_marginEnd="@dimen/button_padding"
30+
android:layout_marginEnd="@dimen/spacer_2x"
3131
android:contentDescription="@string/menu_delete"
3232
app:srcCompat="@drawable/ic_delete_white_24dp" />
3333

@@ -47,13 +47,23 @@
4747

4848
<ImageView
4949
android:id="@+id/noteFavorite"
50-
android:layout_width="wrap_content"
50+
android:layout_width="56dp"
5151
android:layout_height="match_parent"
5252
android:background="?attr/selectableItemBackgroundBorderless"
5353
android:contentDescription="@string/menu_favorite"
5454
android:padding="@dimen/spacer_2x"
5555
tools:src="@drawable/ic_star_yellow_24dp" />
5656

57+
<ImageView
58+
android:id="@+id/custom_checkbox"
59+
android:layout_width="56dp"
60+
android:layout_height="match_parent"
61+
android:clickable="false"
62+
android:contentDescription="@null"
63+
android:focusable="false"
64+
android:padding="@dimen/spacer_2x"
65+
android:src="@drawable/ic_checkbox_blank_outline" />
66+
5767
<androidx.appcompat.widget.AppCompatImageView
5868
android:id="@+id/noteStatus"
5969
android:layout_width="wrap_content"
@@ -65,62 +75,52 @@
6575
app:srcCompat="@drawable/ic_sync_blue_18dp" />
6676
</FrameLayout>
6777

68-
<TextView
69-
android:id="@+id/noteTitle"
78+
<LinearLayout
7079
android:layout_width="0dp"
7180
android:layout_height="wrap_content"
72-
android:layout_marginVertical="10sp"
81+
android:layout_gravity="center_vertical"
7382
android:layout_weight="1"
74-
android:ellipsize="end"
75-
android:maxLines="1"
76-
android:paddingVertical="@dimen/spacer_2x"
77-
android:textColor="?android:textColorPrimary"
78-
android:textSize="@dimen/primary_font_size"
79-
tools:text="@tools:sample/lorem/random" />
80-
81-
<TextView
82-
android:id="@+id/noteCategory"
83-
android:layout_width="wrap_content"
84-
android:layout_height="wrap_content"
85-
android:layout_marginStart="@dimen/spacer_1x"
86-
android:layout_marginTop="1dp"
87-
android:layout_marginEnd="@dimen/spacer_2x"
88-
android:background="@drawable/border"
89-
android:maxLines="1"
90-
android:paddingHorizontal="@dimen/spacer_1x"
91-
android:paddingBottom="1dp"
92-
android:singleLine="true"
93-
android:textColor="?android:textColorPrimary"
94-
android:textSize="@dimen/secondary_font_size"
95-
tools:maxLength="15"
96-
tools:text="@tools:sample/lorem/random" />
83+
android:orientation="horizontal"
84+
android:paddingStart="@dimen/zero"
85+
android:paddingEnd="@dimen/spacer_2x">
9786

98-
<LinearLayout
99-
android:layout_width="wrap_content"
100-
android:layout_height="match_parent"
101-
android:gravity="center_vertical"
102-
android:orientation="vertical">
87+
<TextView
88+
android:id="@+id/noteTitle"
89+
android:layout_width="0dp"
90+
android:layout_height="wrap_content"
91+
android:layout_marginVertical="10sp"
92+
android:layout_weight="1"
93+
android:ellipsize="end"
94+
android:maxLines="1"
95+
android:paddingVertical="@dimen/spacer_2x"
96+
android:textColor="?android:textColorPrimary"
97+
android:textSize="@dimen/primary_font_size"
98+
tools:text="@tools:sample/lorem/random" />
10399

104-
<ImageView
105-
android:id="@+id/custom_checkbox"
100+
<TextView
101+
android:id="@+id/noteCategory"
106102
android:layout_width="wrap_content"
107103
android:layout_height="wrap_content"
108-
android:layout_gravity="end"
109-
android:clickable="false"
110-
android:contentDescription="@null"
111-
android:focusable="false"
112-
android:paddingStart="@dimen/spacer_1x"
113-
android:layout_marginBottom="@dimen/spacer_1x"
114-
android:paddingEnd="@dimen/spacer_1x"
115-
android:src="@drawable/ic_checkbox_blank_outline" />
104+
android:layout_marginVertical="10sp"
105+
android:layout_marginStart="@dimen/spacer_1x"
106+
android:layout_marginTop="1dp"
107+
android:background="@drawable/border"
108+
android:maxLines="1"
109+
android:paddingHorizontal="@dimen/spacer_1x"
110+
android:paddingBottom="1dp"
111+
android:singleLine="true"
112+
android:textColor="?android:textColorPrimary"
113+
android:textSize="@dimen/secondary_font_size"
114+
tools:maxLength="15"
115+
tools:text="@tools:sample/lorem/random" />
116116

117117
<TextView
118118
android:id="@+id/noteModified"
119119
android:layout_width="wrap_content"
120120
android:layout_height="wrap_content"
121-
android:layout_gravity="end"
122-
android:paddingStart="@dimen/zero"
123-
android:paddingEnd="@dimen/spacer_1x"
121+
android:layout_marginVertical="10sp"
122+
android:paddingStart="@dimen/spacer_1x"
123+
android:paddingEnd="@dimen/zero"
124124
tools:text="27.11." />
125125

126126
</LinearLayout>

0 commit comments

Comments
 (0)