Skip to content

Commit 81c6da2

Browse files
committed
avoid showing locked note content without password
1 parent ca32224 commit 81c6da2

File tree

5 files changed

+166
-36
lines changed

5 files changed

+166
-36
lines changed

app/src/main/kotlin/com/simplemobiletools/notes/pro/fragments/ChecklistFragment.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,18 @@ class ChecklistFragment : NoteFragment(), ChecklistItemsListener {
116116
}
117117
}
118118

119+
checkLockState()
119120
setupAdapter()
120121
}
121122

123+
override fun checkLockState() {
124+
view.apply {
125+
checklist_content_holder.beVisibleIf(!note!!.isLocked() || shouldShowLockedContent)
126+
checklist_fab.beVisibleIf(!note!!.isLocked() || shouldShowLockedContent)
127+
setupLockedViews(this, note!!)
128+
}
129+
}
130+
122131
private fun showNewItemDialog() {
123132
NewChecklistItemDialog(activity as SimpleActivity) { titles ->
124133
var currentMaxId = items.maxBy { item -> item.id }?.id ?: 0
Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,40 @@
11
package com.simplemobiletools.notes.pro.fragments
22

3+
import android.util.TypedValue
4+
import android.view.ViewGroup
35
import androidx.fragment.app.Fragment
6+
import com.simplemobiletools.commons.dialogs.SecurityDialog
7+
import com.simplemobiletools.commons.extensions.applyColorFilter
8+
import com.simplemobiletools.commons.extensions.beVisibleIf
9+
import com.simplemobiletools.commons.extensions.getAdjustedPrimaryColor
10+
import com.simplemobiletools.notes.pro.extensions.config
11+
import com.simplemobiletools.notes.pro.extensions.getPercentageFontSize
12+
import com.simplemobiletools.notes.pro.models.Note
13+
import kotlinx.android.synthetic.main.fragment_checklist.view.*
414

5-
abstract class NoteFragment : Fragment()
15+
abstract class NoteFragment : Fragment() {
16+
protected var shouldShowLockedContent = false
17+
18+
protected fun setupLockedViews(view: ViewGroup, note: Note) {
19+
view.apply {
20+
note_locked_layout.beVisibleIf(note.isLocked() && !shouldShowLockedContent)
21+
note_locked_image.applyColorFilter(config!!.textColor)
22+
23+
note_locked_label.setTextColor(context!!.config.textColor)
24+
note_locked_label.setTextSize(TypedValue.COMPLEX_UNIT_PX, context.getPercentageFontSize())
25+
26+
note_locked_show.setTextColor(context!!.getAdjustedPrimaryColor())
27+
note_locked_show.setTextSize(TypedValue.COMPLEX_UNIT_PX, context.getPercentageFontSize())
28+
note_locked_show.setOnClickListener {
29+
SecurityDialog(activity!!, note.protectionHash, note.protectionType) { hash, type, success ->
30+
if (success) {
31+
shouldShowLockedContent = true
32+
checkLockState()
33+
}
34+
}
35+
}
36+
}
37+
}
38+
39+
abstract fun checkLockState()
40+
}

app/src/main/kotlin/com/simplemobiletools/notes/pro/fragments/TextFragment.kt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ class TextFragment : NoteFragment() {
141141
setSelection(if (config.placeCursorToEnd) text.length else 0)
142142
}
143143

144-
if (config.showKeyboard && isMenuVisible) {
144+
if (config.showKeyboard && isMenuVisible && (!note!!.isLocked() || shouldShowLockedContent)) {
145145
onGlobalLayout {
146146
if (activity?.isDestroyed == false) {
147147
requestFocus()
@@ -159,13 +159,11 @@ class TextFragment : NoteFragment() {
159159
}
160160

161161
if (config.showWordCount) {
162-
view.notes_counter.beVisible()
163162
view.notes_counter.setTextColor(config.textColor)
164163
setWordCounter(view.text_note_view.text.toString())
165-
} else {
166-
view.notes_counter.beGone()
167164
}
168165

166+
checkLockState()
169167
setTextWatcher()
170168
}
171169

@@ -178,6 +176,14 @@ class TextFragment : NoteFragment() {
178176

179177
fun removeTextWatcher() = view.text_note_view.removeTextChangedListener(textWatcher)
180178

179+
override fun checkLockState() {
180+
view.apply {
181+
notes_counter.beVisibleIf((!note!!.isLocked() || shouldShowLockedContent) && config!!.showWordCount)
182+
notes_scrollview.beVisibleIf(!note!!.isLocked() || shouldShowLockedContent)
183+
setupLockedViews(this, note!!)
184+
}
185+
}
186+
181187
fun updateNoteValue(value: String) {
182188
note?.value = value
183189
}

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

Lines changed: 74 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,41 +10,84 @@
1010
android:layout_width="match_parent"
1111
android:layout_height="match_parent">
1212

13-
<com.simplemobiletools.commons.views.MyRecyclerView
14-
android:id="@+id/checklist_list"
13+
<RelativeLayout
14+
android:id="@+id/note_locked_layout"
1515
android:layout_width="match_parent"
1616
android:layout_height="match_parent"
17-
android:clipToPadding="false"
18-
android:overScrollMode="never"
19-
android:visibility="gone"
20-
app:layoutManager="com.simplemobiletools.commons.views.MyLinearLayoutManager" />
17+
android:layout_marginTop="@dimen/activity_margin"
18+
android:visibility="gone">
19+
20+
<ImageView
21+
android:id="@+id/note_locked_image"
22+
android:layout_width="@dimen/normal_icon_size"
23+
android:layout_height="@dimen/normal_icon_size"
24+
android:layout_centerHorizontal="true"
25+
android:layout_marginTop="@dimen/medium_margin"
26+
android:src="@drawable/ic_lock_vector" />
27+
28+
<com.simplemobiletools.commons.views.MyTextView
29+
android:id="@+id/note_locked_label"
30+
android:layout_width="wrap_content"
31+
android:layout_height="wrap_content"
32+
android:layout_below="@+id/note_locked_image"
33+
android:layout_centerHorizontal="true"
34+
android:layout_marginTop="@dimen/activity_margin"
35+
android:text="@string/note_content_locked" />
36+
37+
<TextView
38+
android:id="@+id/note_locked_show"
39+
android:layout_width="wrap_content"
40+
android:layout_height="wrap_content"
41+
android:layout_below="@+id/note_locked_label"
42+
android:layout_centerHorizontal="true"
43+
android:layout_marginTop="@dimen/small_margin"
44+
android:background="?attr/selectableItemBackground"
45+
android:padding="@dimen/activity_margin"
46+
android:text="@string/show_content" />
47+
48+
</RelativeLayout>
2149

22-
<com.simplemobiletools.commons.views.MyTextView
23-
android:id="@+id/fragment_placeholder"
50+
<RelativeLayout
51+
android:id="@+id/checklist_content_holder"
2452
android:layout_width="match_parent"
25-
android:layout_height="wrap_content"
26-
android:layout_marginTop="@dimen/activity_margin"
27-
android:alpha="0.8"
28-
android:gravity="center"
29-
android:paddingStart="@dimen/activity_margin"
30-
android:paddingEnd="@dimen/activity_margin"
31-
android:text="@string/checklist_is_empty"
32-
android:textSize="@dimen/bigger_text_size"
33-
android:textStyle="italic"
34-
android:visibility="gone" />
35-
36-
<com.simplemobiletools.commons.views.MyTextView
37-
android:id="@+id/fragment_placeholder_2"
38-
android:layout_width="wrap_content"
39-
android:layout_height="wrap_content"
40-
android:layout_below="@+id/fragment_placeholder"
41-
android:layout_centerHorizontal="true"
42-
android:background="?attr/selectableItemBackground"
43-
android:gravity="center"
44-
android:padding="@dimen/activity_margin"
45-
android:text="@string/add_new_checklist_items"
46-
android:textSize="@dimen/bigger_text_size"
47-
android:visibility="gone" />
53+
android:layout_height="wrap_content">
54+
55+
<com.simplemobiletools.commons.views.MyRecyclerView
56+
android:id="@+id/checklist_list"
57+
android:layout_width="match_parent"
58+
android:layout_height="match_parent"
59+
android:clipToPadding="false"
60+
android:overScrollMode="never"
61+
android:visibility="gone"
62+
app:layoutManager="com.simplemobiletools.commons.views.MyLinearLayoutManager" />
63+
64+
<com.simplemobiletools.commons.views.MyTextView
65+
android:id="@+id/fragment_placeholder"
66+
android:layout_width="match_parent"
67+
android:layout_height="wrap_content"
68+
android:layout_marginTop="@dimen/activity_margin"
69+
android:alpha="0.8"
70+
android:gravity="center"
71+
android:paddingStart="@dimen/activity_margin"
72+
android:paddingEnd="@dimen/activity_margin"
73+
android:text="@string/checklist_is_empty"
74+
android:textSize="@dimen/bigger_text_size"
75+
android:textStyle="italic"
76+
android:visibility="gone" />
77+
78+
<com.simplemobiletools.commons.views.MyTextView
79+
android:id="@+id/fragment_placeholder_2"
80+
android:layout_width="wrap_content"
81+
android:layout_height="wrap_content"
82+
android:layout_below="@+id/fragment_placeholder"
83+
android:layout_centerHorizontal="true"
84+
android:background="?attr/selectableItemBackground"
85+
android:gravity="center"
86+
android:padding="@dimen/activity_margin"
87+
android:text="@string/add_new_checklist_items"
88+
android:textSize="@dimen/bigger_text_size"
89+
android:visibility="gone" />
90+
</RelativeLayout>
4891
</RelativeLayout>
4992

5093
<com.simplemobiletools.commons.views.MyFloatingActionButton

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,43 @@
55
android:layout_width="match_parent"
66
android:layout_height="match_parent">
77

8+
<RelativeLayout
9+
android:id="@+id/note_locked_layout"
10+
android:layout_width="match_parent"
11+
android:layout_height="match_parent"
12+
android:layout_marginTop="@dimen/activity_margin"
13+
android:visibility="gone">
14+
15+
<ImageView
16+
android:id="@+id/note_locked_image"
17+
android:layout_width="@dimen/normal_icon_size"
18+
android:layout_height="@dimen/normal_icon_size"
19+
android:layout_centerHorizontal="true"
20+
android:layout_marginTop="@dimen/medium_margin"
21+
android:src="@drawable/ic_lock_vector" />
22+
23+
<com.simplemobiletools.commons.views.MyTextView
24+
android:id="@+id/note_locked_label"
25+
android:layout_width="wrap_content"
26+
android:layout_height="wrap_content"
27+
android:layout_below="@+id/note_locked_image"
28+
android:layout_centerHorizontal="true"
29+
android:layout_marginTop="@dimen/activity_margin"
30+
android:text="@string/note_content_locked" />
31+
32+
<TextView
33+
android:id="@+id/note_locked_show"
34+
android:layout_width="wrap_content"
35+
android:layout_height="wrap_content"
36+
android:layout_below="@+id/note_locked_label"
37+
android:layout_centerHorizontal="true"
38+
android:layout_marginTop="@dimen/small_margin"
39+
android:background="?attr/selectableItemBackground"
40+
android:padding="@dimen/activity_margin"
41+
android:text="@string/show_content" />
42+
43+
</RelativeLayout>
44+
845
<ScrollView
946
android:id="@+id/notes_scrollview"
1047
android:layout_width="match_parent"

0 commit comments

Comments
 (0)