avoid showing locked note content without password

This commit is contained in:
tibbi 2021-05-20 22:48:05 +02:00
parent ca32224071
commit 81c6da22d4
5 changed files with 166 additions and 36 deletions

View File

@ -116,9 +116,18 @@ class ChecklistFragment : NoteFragment(), ChecklistItemsListener {
}
}
checkLockState()
setupAdapter()
}
override fun checkLockState() {
view.apply {
checklist_content_holder.beVisibleIf(!note!!.isLocked() || shouldShowLockedContent)
checklist_fab.beVisibleIf(!note!!.isLocked() || shouldShowLockedContent)
setupLockedViews(this, note!!)
}
}
private fun showNewItemDialog() {
NewChecklistItemDialog(activity as SimpleActivity) { titles ->
var currentMaxId = items.maxBy { item -> item.id }?.id ?: 0

View File

@ -1,5 +1,40 @@
package com.simplemobiletools.notes.pro.fragments
import android.util.TypedValue
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.simplemobiletools.commons.dialogs.SecurityDialog
import com.simplemobiletools.commons.extensions.applyColorFilter
import com.simplemobiletools.commons.extensions.beVisibleIf
import com.simplemobiletools.commons.extensions.getAdjustedPrimaryColor
import com.simplemobiletools.notes.pro.extensions.config
import com.simplemobiletools.notes.pro.extensions.getPercentageFontSize
import com.simplemobiletools.notes.pro.models.Note
import kotlinx.android.synthetic.main.fragment_checklist.view.*
abstract class NoteFragment : Fragment()
abstract class NoteFragment : Fragment() {
protected var shouldShowLockedContent = false
protected fun setupLockedViews(view: ViewGroup, note: Note) {
view.apply {
note_locked_layout.beVisibleIf(note.isLocked() && !shouldShowLockedContent)
note_locked_image.applyColorFilter(config!!.textColor)
note_locked_label.setTextColor(context!!.config.textColor)
note_locked_label.setTextSize(TypedValue.COMPLEX_UNIT_PX, context.getPercentageFontSize())
note_locked_show.setTextColor(context!!.getAdjustedPrimaryColor())
note_locked_show.setTextSize(TypedValue.COMPLEX_UNIT_PX, context.getPercentageFontSize())
note_locked_show.setOnClickListener {
SecurityDialog(activity!!, note.protectionHash, note.protectionType) { hash, type, success ->
if (success) {
shouldShowLockedContent = true
checkLockState()
}
}
}
}
}
abstract fun checkLockState()
}

View File

@ -141,7 +141,7 @@ class TextFragment : NoteFragment() {
setSelection(if (config.placeCursorToEnd) text.length else 0)
}
if (config.showKeyboard && isMenuVisible) {
if (config.showKeyboard && isMenuVisible && (!note!!.isLocked() || shouldShowLockedContent)) {
onGlobalLayout {
if (activity?.isDestroyed == false) {
requestFocus()
@ -159,13 +159,11 @@ class TextFragment : NoteFragment() {
}
if (config.showWordCount) {
view.notes_counter.beVisible()
view.notes_counter.setTextColor(config.textColor)
setWordCounter(view.text_note_view.text.toString())
} else {
view.notes_counter.beGone()
}
checkLockState()
setTextWatcher()
}
@ -178,6 +176,14 @@ class TextFragment : NoteFragment() {
fun removeTextWatcher() = view.text_note_view.removeTextChangedListener(textWatcher)
override fun checkLockState() {
view.apply {
notes_counter.beVisibleIf((!note!!.isLocked() || shouldShowLockedContent) && config!!.showWordCount)
notes_scrollview.beVisibleIf(!note!!.isLocked() || shouldShowLockedContent)
setupLockedViews(this, note!!)
}
}
fun updateNoteValue(value: String) {
note?.value = value
}

View File

@ -10,41 +10,84 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.simplemobiletools.commons.views.MyRecyclerView
android:id="@+id/checklist_list"
<RelativeLayout
android:id="@+id/note_locked_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:overScrollMode="never"
android:visibility="gone"
app:layoutManager="com.simplemobiletools.commons.views.MyLinearLayoutManager" />
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/fragment_placeholder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/activity_margin"
android:alpha="0.8"
android:gravity="center"
android:paddingStart="@dimen/activity_margin"
android:paddingEnd="@dimen/activity_margin"
android:text="@string/checklist_is_empty"
android:textSize="@dimen/bigger_text_size"
android:textStyle="italic"
android:visibility="gone" />
android:visibility="gone">
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/fragment_placeholder_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/fragment_placeholder"
android:layout_centerHorizontal="true"
android:background="?attr/selectableItemBackground"
android:gravity="center"
android:padding="@dimen/activity_margin"
android:text="@string/add_new_checklist_items"
android:textSize="@dimen/bigger_text_size"
android:visibility="gone" />
<ImageView
android:id="@+id/note_locked_image"
android:layout_width="@dimen/normal_icon_size"
android:layout_height="@dimen/normal_icon_size"
android:layout_centerHorizontal="true"
android:layout_marginTop="@dimen/medium_margin"
android:src="@drawable/ic_lock_vector" />
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/note_locked_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/note_locked_image"
android:layout_centerHorizontal="true"
android:layout_marginTop="@dimen/activity_margin"
android:text="@string/note_content_locked" />
<TextView
android:id="@+id/note_locked_show"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/note_locked_label"
android:layout_centerHorizontal="true"
android:layout_marginTop="@dimen/small_margin"
android:background="?attr/selectableItemBackground"
android:padding="@dimen/activity_margin"
android:text="@string/show_content" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/checklist_content_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.simplemobiletools.commons.views.MyRecyclerView
android:id="@+id/checklist_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:overScrollMode="never"
android:visibility="gone"
app:layoutManager="com.simplemobiletools.commons.views.MyLinearLayoutManager" />
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/fragment_placeholder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/activity_margin"
android:alpha="0.8"
android:gravity="center"
android:paddingStart="@dimen/activity_margin"
android:paddingEnd="@dimen/activity_margin"
android:text="@string/checklist_is_empty"
android:textSize="@dimen/bigger_text_size"
android:textStyle="italic"
android:visibility="gone" />
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/fragment_placeholder_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/fragment_placeholder"
android:layout_centerHorizontal="true"
android:background="?attr/selectableItemBackground"
android:gravity="center"
android:padding="@dimen/activity_margin"
android:text="@string/add_new_checklist_items"
android:textSize="@dimen/bigger_text_size"
android:visibility="gone" />
</RelativeLayout>
</RelativeLayout>
<com.simplemobiletools.commons.views.MyFloatingActionButton

View File

@ -5,6 +5,43 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="@+id/note_locked_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="@dimen/activity_margin"
android:visibility="gone">
<ImageView
android:id="@+id/note_locked_image"
android:layout_width="@dimen/normal_icon_size"
android:layout_height="@dimen/normal_icon_size"
android:layout_centerHorizontal="true"
android:layout_marginTop="@dimen/medium_margin"
android:src="@drawable/ic_lock_vector" />
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/note_locked_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/note_locked_image"
android:layout_centerHorizontal="true"
android:layout_marginTop="@dimen/activity_margin"
android:text="@string/note_content_locked" />
<TextView
android:id="@+id/note_locked_show"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/note_locked_label"
android:layout_centerHorizontal="true"
android:layout_marginTop="@dimen/small_margin"
android:background="?attr/selectableItemBackground"
android:padding="@dimen/activity_margin"
android:text="@string/show_content" />
</RelativeLayout>
<ScrollView
android:id="@+id/notes_scrollview"
android:layout_width="match_parent"