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

Improvement of UI and UX #184

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ private void readPreferences(@NonNull JsonReader reader, @NonNull Context contex
"settings_dialog_on_trashing",
"settings_color_category",
"notes_reversed_ordering",
"settings_sketch_undo_redo" -> editor.putBoolean(name, reader.nextBoolean());
"settings_sketch_undo_redo",
"settings_import_text_title_file_first_line",
"settings_color_category_always_background" -> editor.putBoolean(name, reader.nextBoolean());
case "settings_font_size", "settings_day_night_theme", "notes_ordering" -> editor.putString(name, reader.nextString());
default -> throw new RuntimeException("Unknown preference " + name);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ class ChecklistAdapter(

fun removeItem(position: Int) {
this.items.removeAt(position)
hasChanged = true
notifyItemRemoved(position)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,22 +80,24 @@ class NoteAdapter(

if (colorCategory) {
mainActivityViewModel.categoryColor(currentNote.category) {
val colorBackground = PreferenceManager.getDefaultSharedPreferences(holder.textViewTitle.context)
.getBoolean("settings_color_category_always_background", false) || !DarkModeUtil.isDarkMode(holder.textViewTitle.context)

if (DarkModeUtil.isDarkMode(holder.textViewTitle.context)) {
if (colorBackground) {
val color: Int = it?.let { Color.parseColor(it) } ?: run {
val value = TypedValue()
holder.itemView.context.theme.resolveAttribute(R.attr.colorOnBackground, value, true)
holder.itemView.context.theme.resolveAttribute(R.attr.colorSurface, value, true)
value.data
}
holder.textViewTitle.setTextColor(color)
holder.textViewExtraText.setTextColor(color)
holder.viewNoteItem.setBackgroundColor(color)
} else {
val color: Int = it?.let { Color.parseColor(it) } ?: run {
val value = TypedValue()
holder.itemView.context.theme.resolveAttribute(R.attr.colorSurface, value, true)
holder.itemView.context.theme.resolveAttribute(R.attr.colorOnBackground, value, true)
value.data
}
holder.viewNoteItem.setBackgroundColor(color)
holder.textViewTitle.setTextColor(color)
holder.textViewExtraText.setTextColor(color)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,8 @@ class MainActivityViewModel(application: Application) : AndroidViewModel(applica
throw IllegalArgumentException("Only checklist notes allowed")
}
return ChecklistUtil.parse(note.content).map { (checked, name) ->
return@map Pair(checked, "[${if (checked) "x" else " "}] $name")
val preview = if (name.length > 30) name.take(30) + "..." else name.take(33)
return@map Pair(checked, "[${if (checked) "x" else " "}] $preview")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ abstract class BaseNoteActivity(noteType: Int) : AppCompatActivity(), View.OnCli
}

private val etName by lazy { findViewById<View>(R.id.etName) as EditText }
val noteTitle: String
get() = etName.text.toString()
private val catSelection by lazy { findViewById<View>(R.id.spinner_category) as AutoCompleteTextView }
private lateinit var reminder: MenuItem

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ class ChecklistNoteActivity : BaseNoteActivity(DbContract.NoteEntry.TYPE_CHECKLI
}

private fun getContentString(): String {
return adapter.getItems().joinToString(System.lineSeparator()) { (checked, name) -> "- [${if (checked) "x" else " "}] $name" }
return adapter.getItems().joinToString(System.lineSeparator()) { (checked, name) -> "- [${if (checked) "x" else " "}] $name" }
}

private fun addItem() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,36 @@
*/
package org.secuso.privacyfriendlynotes.ui.notes

import android.app.Activity
import android.content.Intent
import android.content.res.ColorStateList
import android.graphics.Color
import android.graphics.Typeface
import android.net.Uri
import android.os.Bundle
import android.provider.OpenableColumns
import android.text.Html
import android.text.Spannable
import android.text.SpannableStringBuilder
import android.text.Spanned
import android.text.style.StyleSpan
import android.text.style.UnderlineSpan
import android.util.Log
import android.view.ContextThemeWrapper
import android.view.Menu
import android.view.MenuItem
import android.view.View
import android.widget.EditText
import android.widget.Toast
import androidx.activity.result.contract.ActivityResultContracts
import androidx.lifecycle.MutableLiveData
import androidx.preference.PreferenceManager
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.floatingactionbutton.FloatingActionButton
import org.secuso.privacyfriendlynotes.R
import org.secuso.privacyfriendlynotes.room.DbContract
import org.secuso.privacyfriendlynotes.room.model.Note
import org.secuso.privacyfriendlynotes.ui.util.ChecklistUtil
import java.io.File
import java.io.InputStreamReader
import java.io.OutputStream
import java.io.PrintWriter
Expand Down Expand Up @@ -121,6 +126,13 @@ class TextNoteActivity : BaseNoteActivity(DbContract.NoteEntry.TYPE_TEXT) {
.setIcon(android.R.drawable.ic_dialog_alert)
.show()
}
R.id.action_export_plain -> {
val intent = Intent(Intent.ACTION_CREATE_DOCUMENT)
intent.addCategory(Intent.CATEGORY_OPENABLE)
intent.putExtra(Intent.EXTRA_TITLE, noteTitle + getFileExtension())
intent.type = getMimeType()
saveToExternalStorageResultLauncher.launch(intent)
}

else -> {}
}
Expand All @@ -131,13 +143,18 @@ class TextNoteActivity : BaseNoteActivity(DbContract.NoteEntry.TYPE_TEXT) {
if (intent != null) {
val uri: Uri? = listOf(intent.data, intent.getParcelableExtra(Intent.EXTRA_STREAM)).firstNotNullOfOrNull { it }
if (uri != null) {
val text = InputStreamReader(contentResolver.openInputStream(uri)).readLines()
super.setTitle(text[0])
etContent.setText(Html.fromHtml(text.subList(1, text.size).joinToString("<br>")))
val (title: String, text) = InputStreamReader(contentResolver.openInputStream(uri)).readLines().let {
if (PreferenceManager.getDefaultSharedPreferences(this@TextNoteActivity).getBoolean("settings_import_text_title_file_first_line", false)) {
it[0] to it.subList(1, it.size)
} else {
(uri.path?.let { file -> File(file).nameWithoutExtension } ?: "") to it
}
}
super.setTitle(Html.fromHtml(title).toString())
etContent.setText(Html.fromHtml(text.joinToString("<br>")))
}
val text = intent.getStringExtra(Intent.EXTRA_TEXT)
if (text != null) {
etContent.setText(Html.fromHtml(text))
intent.getStringExtra(Intent.EXTRA_TEXT)?.let {
etContent.setText(Html.fromHtml(it))
}
}
}
Expand Down Expand Up @@ -424,10 +441,28 @@ class TextNoteActivity : BaseNoteActivity(DbContract.NoteEntry.TYPE_TEXT) {

override fun getFileExtension() = ".txt"

private val saveToExternalStorageResultLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
if (result.resultCode == Activity.RESULT_OK) {
result.data?.data?.let { uri ->
val fileOutputStream: OutputStream? = contentResolver.openOutputStream(uri)
fileOutputStream?.let {
val out = PrintWriter(it)
out.println(Html.toHtml(etContent.text))
out.close()
Toast.makeText(
applicationContext,
String.format(getString(R.string.toast_file_exported_to), uri.toString()),
Toast.LENGTH_LONG
).show()
}
fileOutputStream?.close()
}
}
}

override fun onSaveExternalStorage(outputStream: OutputStream) {
val out = PrintWriter(outputStream)
out.println(Html.toHtml(etContent.text))
out.println(Html.fromHtml(Html.toHtml(etContent.text)).toString())
out.close()
}
}
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/baseline_html_24.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="#000000" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">

<path android:fillColor="@android:color/white" android:pathData="M3.5,9H5v6H3.5v-2.5h-2V15H0V9h1.5v2h2V9zM17.5,9H13c-0.55,0 -1,0.45 -1,1v5h1.5v-4.5h1V14H16v-3.51h1V15h1.5v-5C18.5,9.45 18.05,9 17.5,9zM11,9H6v1.5h1.75V15h1.5v-4.5H11V9zM24,15v-1.5h-2.5V9H20v6H24z"/>

</vector>
3 changes: 1 addition & 2 deletions app/src/main/res/layout/activity_checklist_note.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/etNewItem"
android:singleLine="true"
android:layout_weight="1"
android:hint="@string/hint_new_item"
android:textColor="?attr/colorOnBackground"
android:inputType="textCapSentences" />
android:inputType="textCapSentences|textMultiLine" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/item_checklist.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
android:layout_weight="1"
android:layout_height="wrap_content"
android:textSize="20sp"
android:inputType="text|textCapSentences"
android:inputType="text|textCapSentences|textMultiLine"
android:padding="10dp"
android:background="@null"/>

Expand Down
7 changes: 7 additions & 0 deletions app/src/main/res/menu/activity_text.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_export_plain"
android:orderInCategory="140"
android:title="@string/action_export_html"
android:icon="@drawable/baseline_html_24"
app:showAsAction="ifRoom"/>
<item
android:id="@+id/action_convert_to_checklist"
android:orderInCategory="150"
android:title="@string/action_convert_to_checklist"
android:icon="@drawable/ic_format_list_bulleted_icon_24dp"
app:showAsAction="ifRoom"/>

</menu>
6 changes: 5 additions & 1 deletion app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
<string name="toast_updated">Notiz aktualisiert</string>
<string name="toast_emptyNote">Leere Notiz kann nicht gespeichert werden</string>
<string name="toast_checklist_oneItem">Nur ein Punkt kann gleichzeitig verändert werden.</string>
<string name="toast_deleted">Notiz gelöscht</string>


<string name="action_bold">F</string>
Expand All @@ -75,6 +74,7 @@
<string name="action_share">Teilen</string>
<string name="action_edit">Bearbeiten</string>
<string name="action_export">Exportieren</string>
<string name="action_export_html">Als HTML exportieren</string>
<string name="action_category">Kategorie</string>
<string name="action_convert_to_checklist">In Checkliste umwandeln</string>
<string name="action_convert_to_text">In Textnotiz umwandeln</string>
Expand Down Expand Up @@ -167,4 +167,8 @@
<string name="dialog_convert_to_text_desc">Dadurch wird diese Notiz in eine Textnotiz umgewandelt. Möchten Sie fortfahren?</string>
<string name="settings_sketch_undo_redo_desc">Aktiviere die Rückgängig/Wiederherstellen Funktionalität in Skizzen. Diese Funktion kann auf älteren Geräten zu Leistungsproblemen führen.</string>
<string name="settings_sketch_undo_redo_title">Rückgängig/Wiederherstellen in Skizzen</string>
<string name="settings_import_text_title_file_first_line_title">Erste Zeile als Titel</string>
<string name="settings_import_text_title_file_first_line_desc">Wenn diese Option aktiviert ist, entspricht der Titel der importierten Textnotiz der gesamten ersten Zeile des importierten Textes. Andernfalls wird der Name der importierten Datei ausgewählt.</string>
<string name="settings_color_category_always_background_title">Immer den Hintergrund färben</string>
<string name="settings_color_category_always_background_desc">Wenn aktiviert, wird der Hintergrund immer in der Farbe der Kategorie eingefärbt, unabhängig vom ausgewählten Design.</string>
</resources>
5 changes: 5 additions & 0 deletions app/src/main/res/values-ja/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@
<string name="settings_settings_show_preview_title">ノートプレビューを表示する</string>
<string name="settings_settings_settings_show_preview_sum">ノートの短いプレビューを表示する</string>
<string name="action_export">輸出</string>
<string name="action_export_html">HTMLとしてエクスポート</string>
<string name="action_category">カテゴリ</string>
<string name="text_note_fab_menu_desc">フォーマッティング</string>
<string name="note_not_saved">メモが保存されていません</string>
Expand All @@ -162,5 +163,9 @@
<string name="dialog_convert_to_text_desc">このメモはテキストメモに変換されます。続けますか?</string>
<string name="settings_sketch_undo_redo_desc">スケッチの元に戻す/やり直し機能を有効にします。このオプションは、古いデバイスでパフォーマンスの問題を引き起こす可能性があります。</string>
<string name="settings_sketch_undo_redo_title">スケッチの元に戻す/やり直し</string>
<string name="settings_import_text_title_file_first_line_title">最初の行をタイトルとして</string>
<string name="settings_import_text_title_file_first_line_desc">有効にすると、インポートされたテキスト ノートのタイトルは、インポートされたテキストの最初の行全体になります。有効にしない場合は、インポートされたファイルの名前が選択されます。</string>
<string name="settings_color_category_always_background_title">常に背景をカラーにする</string>
<string name="settings_color_category_always_background_desc">有効にすると、選択したテーマに関係なく、背景は常にカテゴリの色になります。</string>

</resources>
6 changes: 5 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
<string name="action_italics">I</string>
<string name="action_underline"><u>U</u></string>
<string name="action_export">Export</string>
<string name="action_export_html">Export as HTML</string>
<string name="action_category">Category</string>
<string name="action_sketch_undo">Undo</string>
<string name="action_sketch_redo">Redo</string>
Expand Down Expand Up @@ -193,5 +194,8 @@
<string name="dialog_convert_to_text_desc">This will convert this note into a text note. Do you want to continue?</string>
<string name="settings_sketch_undo_redo_desc">Enable the undo/redo functionality in sketches. This option may lead to performance issues on older devices.</string>
<string name="settings_sketch_undo_redo_title">Undo/Redo in sketches</string>

<string name="settings_import_text_title_file_first_line_title">First line as Title</string>
<string name="settings_import_text_title_file_first_line_desc">If enabled, the title of the imported text note will be the whole first line of the imported text. Otherwise the name of the imported file will be selected.</string>
<string name="settings_color_category_always_background_title">Always color background</string>
<string name="settings_color_category_always_background_desc">If enabled, the background is always colored in the color of the category, regardless of the selected theme.</string>
</resources>
13 changes: 13 additions & 0 deletions app/src/main/res/xml/pref_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
android:title="@string/settings_sketch_undo_redo_title"
android:summary="@string/settings_sketch_undo_redo_desc"
app:iconSpaceReserved="false" />
<androidx.preference.SwitchPreferenceCompat
android:key="settings_import_text_title_file_first_line"
android:defaultValue="false"
android:title="@string/settings_import_text_title_file_first_line_title"
android:summary="@string/settings_import_text_title_file_first_line_desc"
app:iconSpaceReserved="false" />
</androidx.preference.PreferenceCategory>
<androidx.preference.PreferenceCategory android:title="@string/settings_appearance_heading"
app:iconSpaceReserved="false">
Expand All @@ -40,6 +46,13 @@
android:summary="@string/settings_color_category_summary"
android:defaultValue="true"
app:iconSpaceReserved="false" />
<androidx.preference.SwitchPreferenceCompat
android:key="settings_color_category_always_background"
android:title="@string/settings_color_category_always_background_title"
android:summary="@string/settings_color_category_always_background_desc"
android:dependency="settings_color_category"
android:defaultValue="false"
app:iconSpaceReserved="false" />
<androidx.preference.SwitchPreferenceCompat
android:key="settings_use_custom_font_size"
android:defaultValue="false"
Expand Down
Loading