mirror of
https://github.com/PhilKes/NotallyX.git
synced 2025-06-28 12:19:55 +00:00
Deploy website - based on bede5146dd46235ea72dc65c6a1e8bc19b60efd3
This commit is contained in:
parent
6b3fec40eb
commit
a324487699
587 changed files with 1640 additions and 306109 deletions
1
.github/FUNDING.yml
vendored
1
.github/FUNDING.yml
vendored
|
@ -1 +0,0 @@
|
|||
ko_fi: philkes
|
36
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
36
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
|
@ -1,36 +0,0 @@
|
|||
name: Bug Report
|
||||
description: Create a report to help us improve
|
||||
labels: ["bug"]
|
||||
projects: []
|
||||
body:
|
||||
- type: textarea
|
||||
id: what-happened
|
||||
attributes:
|
||||
label: What happened?
|
||||
description: Also tell us, what did you expect to happen?
|
||||
placeholder: Tell us what you see!
|
||||
value: "A bug happened!"
|
||||
validations:
|
||||
required: true
|
||||
- type: input
|
||||
id: version
|
||||
attributes:
|
||||
label: App Version
|
||||
description: What version of the app are you running?
|
||||
validations:
|
||||
required: true
|
||||
- type: input
|
||||
id: android-version
|
||||
attributes:
|
||||
label: Android Version (API Level)
|
||||
description: What Android version are you using?
|
||||
- type: textarea
|
||||
id: logs
|
||||
attributes:
|
||||
label: (Optional) Relevant log output
|
||||
description: Please copy and paste any relevant log output. This will be automatically formatted into code, so no need for backticks.
|
||||
render: shell
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
Thanks for taking the time to fill out this bug report!
|
14
.github/ISSUE_TEMPLATE/feature_request.md
vendored
14
.github/ISSUE_TEMPLATE/feature_request.md
vendored
|
@ -1,14 +0,0 @@
|
|||
---
|
||||
name: Feature request
|
||||
about: Suggest an idea for this project
|
||||
title: ''
|
||||
labels: enhancement
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Describe the solution you'd like**
|
||||
A clear and concise description of what you want to happen.
|
||||
|
||||
**Additional context**
|
||||
Add any other context or screenshots about the feature request here.
|
10
.github/ISSUE_TEMPLATE/translation.md
vendored
10
.github/ISSUE_TEMPLATE/translation.md
vendored
|
@ -1,10 +0,0 @@
|
|||
---
|
||||
name: Translation Update
|
||||
about: Update translations by uploading updated translations.xlsx
|
||||
title: '<INSERT LANGUAGE HERE> translations update'
|
||||
labels: translations
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
Drag'n'drop your updated translations.xlsx file here 🙂
|
16
.gitignore
vendored
16
.gitignore
vendored
|
@ -1,16 +0,0 @@
|
|||
*.iml
|
||||
.gradle
|
||||
/local.properties
|
||||
/.idea/
|
||||
.DS_Store
|
||||
/build
|
||||
/captures
|
||||
.externalNativeBuild
|
||||
.cxx
|
||||
*/.attach_pid*
|
||||
fastlane/*
|
||||
!fastlane/join-testers.png
|
||||
!fastlane/metadata
|
||||
Gemfile*
|
||||
*.sh
|
||||
!generate-changelogs.sh
|
0
.nojekyll
Normal file
0
.nojekyll
Normal file
|
@ -1,25 +0,0 @@
|
|||
#!/bin/sh
|
||||
|
||||
# Capture the list of initially staged Kotlin files
|
||||
initial_staged_files=$(git diff --name-only --cached -- '*.kt')
|
||||
|
||||
if [ -z "$initial_staged_files" ]; then
|
||||
echo "No Kotlin files staged for commit."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
formatted_files=$(echo "$initial_staged_files" | sed 's|^app/||' | paste -sd "," -)
|
||||
echo "Formatting Kotlin files: $formatted_files"
|
||||
./gradlew ktfmtPrecommit --include-only="$formatted_files"
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Kotlin formatting failed. Please fix the issues."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Re-stage only the initially staged Kotlin files
|
||||
for file in $initial_staged_files; do
|
||||
git add "$file"
|
||||
done
|
||||
|
||||
echo "Kotlin files formatted"
|
|
@ -1,35 +0,0 @@
|
|||
@echo off
|
||||
setlocal enabledelayedexpansion
|
||||
|
||||
rem Capture the list of initially staged Kotlin files
|
||||
set "initial_staged_files="
|
||||
for /f "delims=" %%f in ('git diff --name-only --cached -- "*.kt"') do (
|
||||
set "initial_staged_files=!initial_staged_files! %%f,"
|
||||
)
|
||||
|
||||
rem Check if there are any staged Kotlin files
|
||||
if "%initial_staged_files%"=="" (
|
||||
echo No Kotlin files staged for commit.
|
||||
exit /b 0
|
||||
)
|
||||
|
||||
rem Remove the trailing comma from the list of formatted files
|
||||
set "formatted_files=%initial_staged_files:~0,-1%"
|
||||
|
||||
echo Formatting Kotlin files: %formatted_files%
|
||||
call gradlew ktfmtPrecommit --include-only="%formatted_files%"
|
||||
|
||||
rem Check if the formatting command was successful
|
||||
if errorlevel 1 (
|
||||
echo Kotlin formatting failed. Please fix the issues.
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
rem Re-stage only the initially staged Kotlin files
|
||||
for %%f in (%initial_staged_files%) do (
|
||||
git add "%%f"
|
||||
)
|
||||
|
||||
echo Kotlin files formatted
|
||||
|
||||
exit /b 0
|
14
404.html
Normal file
14
404.html
Normal file
File diff suppressed because one or more lines are too long
313
CHANGELOG.md
313
CHANGELOG.md
|
@ -1,313 +0,0 @@
|
|||
# Changelog
|
||||
|
||||
## [v7.2.1](https://github.com/PhilKes/NotallyX/tree/v7.2.1) (2025-03-18)
|
||||
|
||||
[Full Changelog](https://github.com/PhilKes/NotallyX/compare/v7.2.0...v7.2.1)
|
||||
|
||||
### Added Features
|
||||
|
||||
- Note not automatically saved when App is killed by system [\#446](https://github.com/PhilKes/NotallyX/issues/446)
|
||||
|
||||
### Fixed Bugs
|
||||
|
||||
- Auto Backup failed [\#456](https://github.com/PhilKes/NotallyX/issues/456)
|
||||
|
||||
## [v7.2.1](https://github.com/PhilKes/NotallyX/tree/v7.2.1) (2025-03-18)
|
||||
|
||||
[Full Changelog](https://github.com/PhilKes/NotallyX/compare/v7.2.0...v7.2.1)
|
||||
|
||||
### Added Features
|
||||
|
||||
- Note not automatically saved when App is killed by system [\#446](https://github.com/PhilKes/NotallyX/issues/446)
|
||||
|
||||
### Fixed Bugs
|
||||
|
||||
- Auto Backup failed [\#456](https://github.com/PhilKes/NotallyX/issues/456)
|
||||
|
||||
## [v7.2.0](https://github.com/PhilKes/NotallyX/tree/v7.2.0) (2025-03-08)
|
||||
|
||||
[Full Changelog](https://github.com/PhilKes/NotallyX/compare/v7.1.0...v7.2.0)
|
||||
|
||||
### Added Features
|
||||
|
||||
- Sort notes by color [\#442](https://github.com/PhilKes/NotallyX/issues/442)
|
||||
|
||||
### Fixed Bugs
|
||||
|
||||
- Unable to locate the 'Uncheck all' option [\#444](https://github.com/PhilKes/NotallyX/issues/444)
|
||||
- List crash when last unchecked item moved [\#436](https://github.com/PhilKes/NotallyX/issues/436)
|
||||
- Pasting multi line text in empty lists crash [\#434](https://github.com/PhilKes/NotallyX/issues/434)
|
||||
- Quickly tapping delete button crash [\#428](https://github.com/PhilKes/NotallyX/issues/428)
|
||||
- First list item can keep parent property [\#427](https://github.com/PhilKes/NotallyX/issues/427)
|
||||
- \(List\) Move last unchecked item above parent bug [\#425](https://github.com/PhilKes/NotallyX/issues/425)
|
||||
- Dragging child item to same position breaks parent association [\#422](https://github.com/PhilKes/NotallyX/issues/422)
|
||||
- Disabling list auto sorting crash [\#421](https://github.com/PhilKes/NotallyX/issues/421)
|
||||
- Crash while indenting a checklist item [\#419](https://github.com/PhilKes/NotallyX/issues/419)
|
||||
- List swipe as subtask crash [\#418](https://github.com/PhilKes/NotallyX/issues/418)
|
||||
- List crash [\#413](https://github.com/PhilKes/NotallyX/issues/413)
|
||||
- Checked parent + subtask places between item [\#410](https://github.com/PhilKes/NotallyX/issues/410)
|
||||
- App crashed while screen was off [\#408](https://github.com/PhilKes/NotallyX/issues/408)
|
||||
- Unchecked items can't be deleted [\#407](https://github.com/PhilKes/NotallyX/issues/407)
|
||||
- Some list items can't be set to subtask after unchecked [\#406](https://github.com/PhilKes/NotallyX/issues/406)
|
||||
- List items deleted [\#405](https://github.com/PhilKes/NotallyX/issues/405)
|
||||
- List item parent task becomes subtask [\#404](https://github.com/PhilKes/NotallyX/issues/404)
|
||||
- Check empty item crash [\#403](https://github.com/PhilKes/NotallyX/issues/403)
|
||||
- Drag problem in long checklist [\#396](https://github.com/PhilKes/NotallyX/issues/396)
|
||||
- List swap items bug [\#395](https://github.com/PhilKes/NotallyX/issues/395)
|
||||
- Background crashes [\#323](https://github.com/PhilKes/NotallyX/issues/323)
|
||||
|
||||
## [v7.1.0](https://github.com/PhilKes/NotallyX/tree/v7.1.0) (2025-02-20)
|
||||
|
||||
[Full Changelog](https://github.com/PhilKes/NotallyX/compare/v7.0.0...v7.1.0)
|
||||
|
||||
### Added Features
|
||||
|
||||
- Dark mode for note colors [\#352](https://github.com/PhilKes/NotallyX/issues/352)
|
||||
- Add "new color" option when deleting a color [\#347](https://github.com/PhilKes/NotallyX/issues/347)
|
||||
- Make "Start view" as default view [\#339](https://github.com/PhilKes/NotallyX/issues/339)
|
||||
- Display first item as title for lists without title [\#317](https://github.com/PhilKes/NotallyX/issues/317)
|
||||
- Remove delete option from top bar since it's already in the bottom more menu [\#316](https://github.com/PhilKes/NotallyX/issues/316)
|
||||
- Add "Export" to bottom menu [\#315](https://github.com/PhilKes/NotallyX/issues/315)
|
||||
- Move "Hide labels" switch up below the labels slider [\#311](https://github.com/PhilKes/NotallyX/issues/311)
|
||||
- Display widgets with the notes' colors [\#300](https://github.com/PhilKes/NotallyX/issues/300)
|
||||
- Allow Pinning a Specific Label as the Starting Page [\#269](https://github.com/PhilKes/NotallyX/issues/269)
|
||||
- Move checked / unchecked items in list [\#251](https://github.com/PhilKes/NotallyX/issues/251)
|
||||
- Moving all labels to the sidebar [\#240](https://github.com/PhilKes/NotallyX/issues/240)
|
||||
- Add "no label" category [\#219](https://github.com/PhilKes/NotallyX/issues/219)
|
||||
- Manual color selection [\#187](https://github.com/PhilKes/NotallyX/issues/187)
|
||||
- Pure Dark Mode [\#16](https://github.com/PhilKes/NotallyX/issues/16)
|
||||
|
||||
### Fixed Bugs
|
||||
|
||||
- Moving group of task at first position wrong order [\#392](https://github.com/PhilKes/NotallyX/issues/392)
|
||||
- Parent task not checked in specific case [\#391](https://github.com/PhilKes/NotallyX/issues/391)
|
||||
- Add auto-backup no error notification [\#381](https://github.com/PhilKes/NotallyX/issues/381)
|
||||
- Backup on save setting not restored [\#373](https://github.com/PhilKes/NotallyX/issues/373)
|
||||
- Start View setting not restored [\#367](https://github.com/PhilKes/NotallyX/issues/367)
|
||||
- \(List\) Child item can't be place after the item below it [\#362](https://github.com/PhilKes/NotallyX/issues/362)
|
||||
- Android 9 Crash java.lang.NoSuchMethodError: getTextSelectHandleLeft\(\) [\#358](https://github.com/PhilKes/NotallyX/issues/358)
|
||||
- List items order bug [\#357](https://github.com/PhilKes/NotallyX/issues/357)
|
||||
- Lists parent-child items crash [\#356](https://github.com/PhilKes/NotallyX/issues/356)
|
||||
- List new items wrong position [\#354](https://github.com/PhilKes/NotallyX/issues/354)
|
||||
- Replacement color message title limited to 2 lines [\#348](https://github.com/PhilKes/NotallyX/issues/348)
|
||||
- \(Lists\) Delete checked items and undo crash [\#331](https://github.com/PhilKes/NotallyX/issues/331)
|
||||
- Sort List items strange bug [\#330](https://github.com/PhilKes/NotallyX/issues/330)
|
||||
- Backup folder re-select prompt closes automatically [\#324](https://github.com/PhilKes/NotallyX/issues/324)
|
||||
- Biometric lock can't be enabled [\#259](https://github.com/PhilKes/NotallyX/issues/259)
|
||||
|
||||
|
||||
## [v7.0.0](https://github.com/PhilKes/NotallyX/tree/v7.0.0) (2025-01-27)
|
||||
|
||||
[Full Changelog](https://github.com/PhilKes/NotallyX/compare/v6.4.1...v7.0.0)
|
||||
|
||||
### Added Features
|
||||
|
||||
- Add Reminders menu to navigation panel [\#294](https://github.com/PhilKes/NotallyX/issues/294)
|
||||
- Extend notes colors to full screen [\#264](https://github.com/PhilKes/NotallyX/issues/264)
|
||||
- Auto-backup on note modification [\#203](https://github.com/PhilKes/NotallyX/issues/203)
|
||||
- Option to show full date inside the note regardless of chosen date format [\#111](https://github.com/PhilKes/NotallyX/issues/111)
|
||||
- Reminder for Notes [\#85](https://github.com/PhilKes/NotallyX/issues/85)
|
||||
|
||||
### Fixed Bugs
|
||||
|
||||
- Restoring settings and backup folder [\#310](https://github.com/PhilKes/NotallyX/issues/310)
|
||||
- Settings can't be imported [\#307](https://github.com/PhilKes/NotallyX/issues/307)
|
||||
- Label create/edit dialog broken [\#302](https://github.com/PhilKes/NotallyX/issues/302)
|
||||
- Rotating screen moves the cursor to the end of note [\#293](https://github.com/PhilKes/NotallyX/issues/293)
|
||||
- Creating an empty note corrupts auto backup archive [\#288](https://github.com/PhilKes/NotallyX/issues/288)
|
||||
- Changes to check lists \(checking items and removing items\) reverts when screen rotatates [\#287](https://github.com/PhilKes/NotallyX/issues/287)
|
||||
- Auto-backups stop exporting after set limit is reached [\#270](https://github.com/PhilKes/NotallyX/issues/270)
|
||||
- Link is not saved if it's the last edit [\#267](https://github.com/PhilKes/NotallyX/issues/267)
|
||||
- Labels hidden in overview not applied when importing JSON [\#266](https://github.com/PhilKes/NotallyX/issues/266)
|
||||
- An unexpected error occurred. Sorry for the inconvenience [\#262](https://github.com/PhilKes/NotallyX/issues/262)
|
||||
- List subtasks bugs [\#207](https://github.com/PhilKes/NotallyX/issues/207)
|
||||
- Remove link also remove text [\#201](https://github.com/PhilKes/NotallyX/issues/201)
|
||||
- Biometric Lock crash [\#177](https://github.com/PhilKes/NotallyX/issues/177)
|
||||
- Import from Evernote and Google Keep not working [\#134](https://github.com/PhilKes/NotallyX/issues/134)
|
||||
|
||||
## [v6.4.1](https://github.com/PhilKes/NotallyX/tree/v6.4.1) (2025-01-17)
|
||||
|
||||
[Full Changelog](https://github.com/PhilKes/NotallyX/compare/v6.4.0...v6.4.1)
|
||||
|
||||
### Added Features
|
||||
|
||||
- Bottom AppBar cutoff + chinese translations [\#176](https://github.com/PhilKes/NotallyX/issues/176)
|
||||
|
||||
### Fixed Bugs
|
||||
|
||||
- Crash loop when enabling biometrics [\#256](https://github.com/PhilKes/NotallyX/issues/256)
|
||||
- Crash when creating notes in 6.4.0 [\#255](https://github.com/PhilKes/NotallyX/issues/255)
|
||||
|
||||
## [v6.4.0](https://github.com/PhilKes/NotallyX/tree/v6.4.0) (2025-01-17)
|
||||
|
||||
[Full Changelog](https://github.com/PhilKes/NotallyX/compare/v6.3.0...v6.4.0)
|
||||
|
||||
### Added Features
|
||||
|
||||
- Prevent word wrap in titles [\#220](https://github.com/PhilKes/NotallyX/issues/220)
|
||||
- Move more top menu to bottom appbar [\#206](https://github.com/PhilKes/NotallyX/issues/206)
|
||||
- App settings backup [\#204](https://github.com/PhilKes/NotallyX/issues/204)
|
||||
- Add a touch bar to scroll quickly [\#202](https://github.com/PhilKes/NotallyX/issues/202)
|
||||
- Select all notes menu button [\#186](https://github.com/PhilKes/NotallyX/issues/186)
|
||||
- One line entries in main menu [\#185](https://github.com/PhilKes/NotallyX/issues/185)
|
||||
- Some suggestions [\#183](https://github.com/PhilKes/NotallyX/issues/183)
|
||||
|
||||
### Fixed Bugs
|
||||
|
||||
- Cutting text during search causes app crash [\#245](https://github.com/PhilKes/NotallyX/issues/245)
|
||||
- Long notes can't be shared [\#243](https://github.com/PhilKes/NotallyX/issues/243)
|
||||
- Trigger disable/enable dataOnExternalStorage on settings import [\#231](https://github.com/PhilKes/NotallyX/issues/231)
|
||||
- Fast scrollbar in notes overview lags [\#230](https://github.com/PhilKes/NotallyX/issues/230)
|
||||
- Handle user unenrolling device biometrics while biometric lock is enabled [\#229](https://github.com/PhilKes/NotallyX/issues/229)
|
||||
- Crash on import if no file explorer app installed [\#227](https://github.com/PhilKes/NotallyX/issues/227)
|
||||
- Assign label inactive checkboxes [\#221](https://github.com/PhilKes/NotallyX/issues/221)
|
||||
- List icon bug in main view [\#215](https://github.com/PhilKes/NotallyX/issues/215)
|
||||
- Import plain text issues [\#209](https://github.com/PhilKes/NotallyX/issues/209)
|
||||
- "Auto backup period in days" cursor buggy [\#192](https://github.com/PhilKes/NotallyX/issues/192)
|
||||
- Unable to view full link while editing [\#181](https://github.com/PhilKes/NotallyX/issues/181)
|
||||
- Scrollbar missing ... [\#178](https://github.com/PhilKes/NotallyX/issues/178)
|
||||
- Widget is invisible when placed [\#156](https://github.com/PhilKes/NotallyX/issues/156)
|
||||
|
||||
**Closed issues:**
|
||||
|
||||
- Items in Lists [\#184](https://github.com/PhilKes/NotallyX/issues/184)
|
||||
|
||||
## [v6.3.0](https://github.com/PhilKes/NotallyX/tree/v6.3.0) (2024-12-23)
|
||||
|
||||
[Full Changelog](https://github.com/PhilKes/NotallyX/compare/v6.2.2...v6.3.0)
|
||||
|
||||
### Added Features
|
||||
|
||||
- Possibility to directly report bug when crash occurs [\#170](https://github.com/PhilKes/NotallyX/issues/170)
|
||||
- "Link Note" text for notes without a title [\#166](https://github.com/PhilKes/NotallyX/issues/166)
|
||||
- Improve app theme's color contrasts [\#163](https://github.com/PhilKes/NotallyX/issues/163)
|
||||
- Paste text containing link does not convert to clickable link + polish translation [\#157](https://github.com/PhilKes/NotallyX/issues/157)
|
||||
- Bottom navigation to increase accessibility for one handed usage [\#129](https://github.com/PhilKes/NotallyX/issues/129)
|
||||
- Search in selected note [\#108](https://github.com/PhilKes/NotallyX/issues/108)
|
||||
|
||||
### Fixed Bugs
|
||||
|
||||
- App crashes when enabling biometric lock [\#168](https://github.com/PhilKes/NotallyX/issues/168)
|
||||
- Barely visible Navigation buttons on Motorola devices in Light Theme [\#161](https://github.com/PhilKes/NotallyX/issues/161)
|
||||
|
||||
## [v6.2.2](https://github.com/PhilKes/NotallyX/tree/v6.2.2) (2024-12-09)
|
||||
|
||||
[Full Changelog](https://github.com/PhilKes/NotallyX/compare/v6.2.1...v6.2.2)
|
||||
|
||||
### Added Features
|
||||
|
||||
- Encrypted backups [\#151](https://github.com/PhilKes/NotallyX/issues/151)
|
||||
- Parse list items when pasting a list formatted text into a list note [\#150](https://github.com/PhilKes/NotallyX/issues/150)
|
||||
- Chinese display of options interface [\#149](https://github.com/PhilKes/NotallyX/issues/149)
|
||||
|
||||
### Fixed Bugs
|
||||
|
||||
- List notes deleting item even though text is not empty on backspace pressed [\#142](https://github.com/PhilKes/NotallyX/issues/142)
|
||||
|
||||
## [v6.2.1](https://github.com/PhilKes/NotallyX/tree/v6.2.1) (2024-12-06)
|
||||
|
||||
[Full Changelog](https://github.com/PhilKes/NotallyX/compare/v6.2.0...v6.2.1)
|
||||
|
||||
### Added Features
|
||||
|
||||
- Add change color option inside of a Note [\#140](https://github.com/PhilKes/NotallyX/issues/140)
|
||||
- Let user choose whether add items in a todo-list at the bottom or top of already existing items [\#132](https://github.com/PhilKes/NotallyX/issues/132)
|
||||
- Migrate Theme to Material 3 [\#104](https://github.com/PhilKes/NotallyX/issues/104)
|
||||
|
||||
### Fixed Bugs
|
||||
|
||||
- Exporting multiple notes with same title overwrites files [\#144](https://github.com/PhilKes/NotallyX/issues/144)
|
||||
- Single notes export as "Untitled.txt" [\#143](https://github.com/PhilKes/NotallyX/issues/143)
|
||||
|
||||
## [v6.2.0](https://github.com/PhilKes/NotallyX/tree/v6.2.0) (2024-12-03)
|
||||
|
||||
[Full Changelog](https://github.com/PhilKes/NotallyX/compare/v6.1.2...v6.2.0)
|
||||
|
||||
### Added Features
|
||||
|
||||
- Replace positions of "Link Note" and "Select all" [\#136](https://github.com/PhilKes/NotallyX/issues/136)
|
||||
- Allow to add Notes in Label View [\#128](https://github.com/PhilKes/NotallyX/issues/128)
|
||||
- Empty notes deleted forever [\#118](https://github.com/PhilKes/NotallyX/issues/118)
|
||||
- Sync devices using Syncthing [\#109](https://github.com/PhilKes/NotallyX/issues/109)
|
||||
- Import from txt files [\#103](https://github.com/PhilKes/NotallyX/issues/103)
|
||||
- Add more Export formats [\#62](https://github.com/PhilKes/NotallyX/issues/62)
|
||||
|
||||
### Fixed Bugs
|
||||
|
||||
- Using delete option from inside a note won't delete the note [\#131](https://github.com/PhilKes/NotallyX/issues/131)
|
||||
- The app crashes when creating a link [\#112](https://github.com/PhilKes/NotallyX/issues/112)
|
||||
- Pinning does not work [\#110](https://github.com/PhilKes/NotallyX/issues/110)
|
||||
|
||||
## [v6.1.2](https://github.com/PhilKes/NotallyX/tree/v6.1.2) (2024-11-19)
|
||||
|
||||
[Full Changelog](https://github.com/PhilKes/NotallyX/compare/v6.1.1...v6.1.2)
|
||||
|
||||
### Fixed Bugs
|
||||
|
||||
- F-Droid can't build [\#126](https://github.com/PhilKes/NotallyX/issues/126)
|
||||
- Undo in list can be quite destructive [\#125](https://github.com/PhilKes/NotallyX/issues/125)
|
||||
- Actions like pin/label/archive only work from overview, not individual note/list [\#124](https://github.com/PhilKes/NotallyX/issues/124)
|
||||
- Jumbled notes after opening settings [\#100](https://github.com/PhilKes/NotallyX/issues/100)
|
||||
|
||||
## [v6.1.1](https://github.com/PhilKes/NotallyX/tree/v6.1.1) (2024-11-14)
|
||||
|
||||
[Full Changelog](https://github.com/PhilKes/NotallyX/compare/v6.0...v6.1.1)
|
||||
|
||||
### Added Features
|
||||
|
||||
- Show delete option in top bar after selecting a note [\#105](https://github.com/PhilKes/NotallyX/issues/105)
|
||||
- Clear previous search term by default [\#96](https://github.com/PhilKes/NotallyX/issues/96)
|
||||
- Color the navigation bar [\#95](https://github.com/PhilKes/NotallyX/issues/95)
|
||||
- Make multiselection easier [\#91](https://github.com/PhilKes/NotallyX/issues/91)
|
||||
- Auto Discard Empty Notes [\#86](https://github.com/PhilKes/NotallyX/issues/86)
|
||||
- Pin/label multiple Notes [\#78](https://github.com/PhilKes/NotallyX/issues/78)
|
||||
- Hide widget notes when app locked. [\#75](https://github.com/PhilKes/NotallyX/issues/75)
|
||||
- Creating categories [\#72](https://github.com/PhilKes/NotallyX/issues/72)
|
||||
- Add Search Bar to Archived and Deleted Notes Sections [\#68](https://github.com/PhilKes/NotallyX/issues/68)
|
||||
- Ability to swipe ListItem on DragHandle [\#67](https://github.com/PhilKes/NotallyX/issues/67)
|
||||
- Show Last Modified Dates in Notes [\#60](https://github.com/PhilKes/NotallyX/issues/60)
|
||||
- Import from major note apps [\#53](https://github.com/PhilKes/NotallyX/issues/53)
|
||||
- Display Labels in NavigationView [\#49](https://github.com/PhilKes/NotallyX/issues/49)
|
||||
- Unneeded Notification Permission on Image Upload [\#34](https://github.com/PhilKes/NotallyX/issues/34)
|
||||
- Linking Notes Within Notes [\#32](https://github.com/PhilKes/NotallyX/issues/32)
|
||||
|
||||
### Fixed Bugs
|
||||
|
||||
- Deleted notes won't "delete forever" [\#117](https://github.com/PhilKes/NotallyX/issues/117)
|
||||
- Empty Auto Backup [\#101](https://github.com/PhilKes/NotallyX/issues/101)
|
||||
- Selector Moves Left in Widget When Selecting Untitled Notes [\#63](https://github.com/PhilKes/NotallyX/issues/63)
|
||||
|
||||
## [v6.0](https://github.com/PhilKes/NotallyX/tree/v6.0) (2024-10-28)
|
||||
|
||||
[Full Changelog](https://github.com/PhilKes/NotallyX/compare/a29bff9a2d1adcbea47cb024ab21426bd678c016...v6.0)
|
||||
|
||||
### Added Features
|
||||
|
||||
- Change icon and add monochrome icon [\#44](https://github.com/PhilKes/NotallyX/issues/44)
|
||||
- Improve copy&paste behaviour [\#40](https://github.com/PhilKes/NotallyX/issues/40)
|
||||
- Option to Change a Note in Widget [\#36](https://github.com/PhilKes/NotallyX/issues/36)
|
||||
- Improve auto-backups [\#31](https://github.com/PhilKes/NotallyX/issues/31)
|
||||
- Lock Notes via PIN/Fingerprint [\#30](https://github.com/PhilKes/NotallyX/issues/30)
|
||||
- More options for sorting Notes in Overview [\#29](https://github.com/PhilKes/NotallyX/issues/29)
|
||||
- Support subtasks in Widgets \(for list notes\) [\#6](https://github.com/PhilKes/NotallyX/issues/6)
|
||||
- Improving Image Display on Notes [\#15](https://github.com/PhilKes/NotallyX/issues/15)
|
||||
- File attachment [\#9](https://github.com/PhilKes/NotallyX/issues/9)
|
||||
- Highlighting Completed Tasks in widget [\#17](https://github.com/PhilKes/NotallyX/issues/17)
|
||||
- Encrypt backups [\#18](https://github.com/PhilKes/NotallyX/issues/18)
|
||||
- Undo deleting/archiving notes [\#19](https://github.com/PhilKes/NotallyX/issues/19)
|
||||
|
||||
### Fixed Bugs
|
||||
|
||||
- Title Change Doesn’t Update Last Modified Date [\#61](https://github.com/PhilKes/NotallyX/issues/61)
|
||||
- Biometric Lock Improvement [\#58](https://github.com/PhilKes/NotallyX/issues/58)
|
||||
- App crashes when pin lock is enabled [\#50](https://github.com/PhilKes/NotallyX/issues/50)
|
||||
- Undo action ignored Spans [\#47](https://github.com/PhilKes/NotallyX/issues/47)
|
||||
- Crash After Importing a Note [\#13](https://github.com/PhilKes/NotallyX/issues/13)
|
||||
- Tasks Disappear When Changing App Language [\#4](https://github.com/PhilKes/NotallyX/issues/4)
|
||||
- Unable to Swipe Back After Adding Tasks [\#5](https://github.com/PhilKes/NotallyX/issues/5)
|
||||
- App Crash When Importing Notes and Opening a Task Note [\#7](https://github.com/PhilKes/NotallyX/issues/7)
|
||||
- improving subtasks [\#8](https://github.com/PhilKes/NotallyX/issues/8)
|
||||
|
||||
|
||||
|
||||
\* *This Changelog was automatically generated by [github_changelog_generator](https://github.com/github-changelog-generator/github-changelog-generator)*
|
|
@ -1,28 +0,0 @@
|
|||
### Translations
|
||||
1. 🇬🇧 English
|
||||
2. 🇭🇺 Hungarian
|
||||
3. 🇬🇷 Greek by xamps
|
||||
4. 🇳🇱 Dutch by [tlmnot](https://github.com/tlmnot)
|
||||
5. 🇨🇿 Czech by [tomo90](https://github.com/tomo90)
|
||||
6. 🇯🇵 Japanese by [kato-k](https://github.com/kato-k)
|
||||
7. 🇦🇩 Catalan by retiolus
|
||||
8. 🇵🇱 Polish by [ZiomaleQ](https://github.com/ZiomaleQ), [rehork](https://github.com/rehork)
|
||||
9. 🇸🇰 Slovak by [Juraj Liso](https://github.com/LiJu09)
|
||||
10. 🇮🇩 Indonesian by [zmni](https://github.com/zmni)
|
||||
11. 🇮🇹 Italian by Luigi Sforza, [IlmastroStefanuzzo](https://github.com/IlmastroStefanuzzo)
|
||||
12. 🇪🇸 Spanish by Jose Casas
|
||||
13. 🇹🇷 Turkish by Helpful User
|
||||
14. 🇺🇦 Ukrainian by Alex Shpak
|
||||
15. 🇩🇰 Danish by [shoddysheep](https://github.com/shoddysheep)
|
||||
16. 🇸🇪 Swedish by Erik Lindström
|
||||
17. 🇷🇺 Russian by Denis Bondarenko, Lyyako
|
||||
18. 🇫🇷 French by Arnaud Dieumegard, [Co-7](https://github.com/Co-7)
|
||||
19. 🇧🇷 Portuguese (Brazil) by [fabianski7](https://github.com/fabianski7)
|
||||
20. 🇵🇹 Portuguese (Portugal) by [joaopmatos](https://github.com/joaopmatos)
|
||||
21. 🇳🇴 Norwegian (Bokmål) by Fredrik Magnussen, [Erik Thom](https://github.com/erikthm)
|
||||
22. 🇳🇴 Norwegian (Nynorsk) by [Erik Thom](https://github.com/erikthm)
|
||||
23. 🇵🇭 Tagalog by Isaiah Collins Abetong
|
||||
24. 🇨🇳 Chinese (Simplified) by [Austin Huang](https://github.com/austinhuang0131), [sr093906](https://github.com/sr093906)
|
||||
25. 🇩🇪 German by Maximilian Braunschmied, [jonas-haeusler](https://github.com/jonas-haeusler),
|
||||
[samuel141](https://github.com/samuel141), [nautilusx](https://github.com/nautilusx)
|
||||
26. 🇻🇳 Vietnamese by [mastoduy](https://github.com/mastoduy)
|
674
LICENSE.md
674
LICENSE.md
|
@ -1,674 +0,0 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
|
@ -1,25 +0,0 @@
|
|||
## Privacy Policy
|
||||
|
||||
This privacy policy applies to the NotallyX app (hereby referred to as "Application") for mobile devices that was created as an Open Source service. This service is intended for use "AS IS".
|
||||
|
||||
### What information does the Application obtain and how is it used?
|
||||
|
||||
The Application does not obtain any information when you download and use it. Registration is not required to use the Application.
|
||||
|
||||
### Does the Application collect precise real time location information of the device?
|
||||
|
||||
This Application does not collect precise information about the location of your mobile device.
|
||||
|
||||
### Do third parties see and/or have access to information obtained by the Application?
|
||||
|
||||
Since the Application does not collect any information, no data is shared with third parties.
|
||||
|
||||
### Your Consent
|
||||
|
||||
By using the Application, you are consenting to this Privacy Policy now and as amended by the developer.
|
||||
|
||||
### Contact Us
|
||||
|
||||
If you have any questions regarding privacy while using the Application, or have questions about the practices, please contact us via email at philkeyplaystore@gmail.com.
|
||||
|
||||
This privacy policy is effective as of 2024-10-30
|
88
README.md
88
README.md
|
@ -1,88 +0,0 @@
|
|||
<h2 align="center">
|
||||
<img src="fastlane/metadata/android/en-US/images/icon.png" alt="icon" width="90"/>
|
||||
<br />
|
||||
<b>NotallyX | Minimalistic note taking app</b>
|
||||
<p>
|
||||
<center>
|
||||
<a href='https://play.google.com/store/apps/details?id=com.philkes.notallyx&pcampaignid=pcampaignidMKT-Other-global-all-co-prtnr-py-PartBadge-Mar2515-1'><img alt='Get it on Google Play' src='https://play.google.com/intl/en_us/badges/static/images/badges/en_badge_web_generic.png' height='80'/></a>
|
||||
<a href="https://f-droid.org/en/packages/com.philkes.notallyx"><img alt='IzzyOnDroid' height='80' src='https://fdroid.gitlab.io/artwork/badge/get-it-on.png' /></a>
|
||||
<a href="https://apt.izzysoft.de/fdroid/index/apk/com.philkes.notallyx"><img alt='F-Droid' height='80' src='https://gitlab.com/IzzyOnDroid/repo/-/raw/master/assets/IzzyOnDroid.png' /></a>
|
||||
</center>
|
||||
</p>
|
||||
</h2>
|
||||
|
||||
<div style="display: flex; justify-content: space-between; width: 100%;">
|
||||
<img src="fastlane/metadata/android/en-US/images/phoneScreenshots/1.png" alt="Image 6" style="width: 32%;"/>
|
||||
<img src="fastlane/metadata/android/en-US/images/phoneScreenshots/2.png" alt="Image 2" style="width: 32%;"/>
|
||||
<img src="fastlane/metadata/android/en-US/images/phoneScreenshots/3.png" alt="Image 3" style="width: 32%;"/>
|
||||
</div>
|
||||
|
||||
<div style="display: flex; justify-content: space-between; width: 100%;">
|
||||
<img src="fastlane/metadata/android/en-US/images/phoneScreenshots/4.png" alt="Image 4" style="width: 32%;"/>
|
||||
<img src="fastlane/metadata/android/en-US/images/phoneScreenshots/5.png" alt="Image 5" style="width: 32%;"/>
|
||||
<img src="fastlane/metadata/android/en-US/images/phoneScreenshots/7.png" alt="Image 7" style="width: 32%;"/>
|
||||
</div>
|
||||
|
||||
### Features
|
||||
[Notally](https://github.com/OmGodse/Notally), but eXtended
|
||||
|
||||
* Create **rich text** notes with support for bold, italics, mono space and strike-through
|
||||
* Create **task lists** and order them with subtasks (+ auto-sort checked items to the end)
|
||||
* Set **reminders** with notifications for important notes
|
||||
* Complement your notes with any type of file such as **pictures**, PDFs, etc.
|
||||
* **Sort notes** by title, last modified date, creation date
|
||||
* **Color, pin and label** your notes for quick organisation
|
||||
* Add **clickable links** to notes with support for phone numbers, email addresses and web urls
|
||||
* **Undo/Redo actions**
|
||||
* Use **Home Screen Widget** to access important notes fast
|
||||
* **Lock your notes via Biometric/PIN**
|
||||
* Configurable **auto-backups**
|
||||
* Create quick audio notes
|
||||
* Display the notes either in a **List or Grid**
|
||||
* Quickly share notes by text
|
||||
* Extensive preferences to adjust views to your liking
|
||||
* Actions to quickly remove checked tasks
|
||||
* Adaptive android app icon
|
||||
* Support for Lollipop devices and up
|
||||
|
||||
---
|
||||
|
||||
### Bug Reports / Feature-Requests
|
||||
If you find any bugs or want to propose a new Feature/Enhancement, feel free to [create a new Issue](https://github.com/PhilKes/NotallyX/issues/new/choose)
|
||||
|
||||
When using the app and an unknown error occurs, causing the app to crash you will see a dialog (see showcase video in https://github.com/PhilKes/NotallyX/pull/171) from which you can immediately create a bug report on Github with the crash details pre-filled.
|
||||
|
||||
#### Beta Releases
|
||||
|
||||
I occasionally release BETA versions of the app during development, since its very valuable for me to get feedback before publicly releasing a new version.
|
||||
These BETA releases have another `applicationId` as the release versions, thats why when you install a BETA version it will show up on your device as a separate app called `NotallyX BETA`.
|
||||
BETA versions also have their own data, they do not use the data of your NotallyX app
|
||||
You can download the most recent BETA release [here on Github](https://github.com/PhilKes/NotallyX/releases/tag/beta)
|
||||
|
||||
### Translations
|
||||
All translations are crowd sourced.
|
||||
To contribute:
|
||||
1. Download current [translations.xlsx](https://github.com/PhilKes/NotallyX/raw/refs/heads/main/app/translations.xlsx)
|
||||
2. Open in Excel/LibreOffice and add missing translations
|
||||
Notes:
|
||||
- Missing translations are marked in red
|
||||
- You can filter by key or any language column values
|
||||
- Non-Translatable strings are hidden and marked in gray, do not add translations for them
|
||||
- For plurals, some languages need/have more quantity strings than others, if a quantity string in the default language (english) is not needed the row is highlighted in yellow. If your language does not need that quantity string either, ignore them.
|
||||
3. Open a [Update Translations Issue](https://github.com/PhilKes/NotallyX/issues/new?assignees=&labels=translations&projects=&template=translation.md&title=%3CINSERT+LANGUAGE+HERE%3E+translations+update)
|
||||
4. I will create a Pull-Request to add your updated translations
|
||||
|
||||
See [Android Translations Converter](https://github.com/PhilKes/android-translations-converter-plugin) for more details
|
||||
|
||||
### Contributing
|
||||
|
||||
If you would like to contribute code yourself, just grab any open issue (that has no other developer assigned yet), leave a comment that you want to work on it and start developing by forking this repo.
|
||||
|
||||
The project is a default Android project written in Kotlin, I highly recommend using Android Studio for development. Also be sure to test your changes with an Android device/emulator that uses the same Android SDK Version as defined in the `build.gradle` `targetSdk`.
|
||||
|
||||
Before submitting your proposed changes as a Pull-Request, make sure all tests are still working (`./gradlew test`), and run `./gradlew ktfmtFormat` for common formatting (also executed automatically as pre-commit hook).
|
||||
|
||||
### Attribution
|
||||
The original Notally project was developed by [OmGodse](https://github.com/OmGodse) under the [GPL 3.0 License](https://github.com/OmGodse/Notally/blob/master/LICENSE.md).
|
||||
|
||||
In accordance to GPL 3.0, this project is licensed under the same [GPL 3.0 License](https://github.com/PhilKes/NotallyX/blob/master/LICENSE.md).
|
2
app/.gitignore
vendored
2
app/.gitignore
vendored
|
@ -1,2 +0,0 @@
|
|||
/build
|
||||
/release
|
|
@ -1,223 +0,0 @@
|
|||
import com.android.build.gradle.internal.tasks.factory.dependsOn
|
||||
import com.ncorti.ktfmt.gradle.tasks.KtfmtFormatTask
|
||||
import org.apache.commons.configuration2.PropertiesConfiguration
|
||||
import org.apache.commons.configuration2.io.FileHandler
|
||||
|
||||
plugins {
|
||||
id("com.android.application")
|
||||
id("org.jetbrains.kotlin.android")
|
||||
id("org.jetbrains.kotlin.plugin.parcelize")
|
||||
id("com.google.devtools.ksp")
|
||||
id("com.ncorti.ktfmt.gradle") version "0.20.1"
|
||||
id("org.jetbrains.kotlin.plugin.serialization") version "1.9.0"
|
||||
id("io.github.philkes.android-translations-converter") version "1.0.5"
|
||||
}
|
||||
|
||||
android {
|
||||
namespace = "com.philkes.notallyx"
|
||||
compileSdk = 34
|
||||
ndkVersion = "29.0.13113456"
|
||||
defaultConfig {
|
||||
applicationId = "com.philkes.notallyx"
|
||||
minSdk = 21
|
||||
targetSdk = 34
|
||||
versionCode = project.findProperty("app.versionCode").toString().toInt()
|
||||
versionName = project.findProperty("app.versionName").toString()
|
||||
resourceConfigurations += listOf(
|
||||
"en", "ca", "cs", "da", "de", "el", "es", "fr", "hu", "in", "it", "ja", "my", "nb", "nl", "nn", "pl", "pt-rBR", "pt-rPT", "ro", "ru", "sk", "sv", "tl", "tr", "uk", "vi", "zh-rCN", "zh-rTW"
|
||||
)
|
||||
vectorDrawables.generatedDensities?.clear()
|
||||
ndk {
|
||||
debugSymbolLevel= "FULL"
|
||||
}
|
||||
}
|
||||
ksp {
|
||||
arg("room.generateKotlin", "true")
|
||||
arg("room.schemaLocation", "$projectDir/schemas")
|
||||
}
|
||||
|
||||
signingConfigs {
|
||||
create("release") {
|
||||
storeFile = file(providers.gradleProperty("RELEASE_STORE_FILE").get())
|
||||
storePassword = providers.gradleProperty("RELEASE_STORE_PASSWORD").get()
|
||||
keyAlias = providers.gradleProperty("RELEASE_KEY_ALIAS").get()
|
||||
keyPassword = providers.gradleProperty("RELEASE_KEY_PASSWORD").get()
|
||||
}
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
debug {
|
||||
applicationIdSuffix = ".debug"
|
||||
versionNameSuffix = "-DEBUG"
|
||||
resValue("string", "app_name", "NotallyX DEBUG")
|
||||
}
|
||||
release {
|
||||
isCrunchPngs = false
|
||||
isMinifyEnabled = true
|
||||
isShrinkResources = true
|
||||
proguardFiles(
|
||||
getDefaultProguardFile("proguard-android-optimize.txt"),
|
||||
"proguard-rules.pro"
|
||||
)
|
||||
signingConfig = signingConfigs.getByName("release")
|
||||
}
|
||||
create("beta"){
|
||||
initWith(getByName("release"))
|
||||
applicationIdSuffix = ".beta"
|
||||
versionNameSuffix = "-BETA"
|
||||
resValue("string", "app_name", "NotallyX BETA")
|
||||
}
|
||||
}
|
||||
|
||||
applicationVariants.all {
|
||||
this.outputs
|
||||
.map { it as com.android.build.gradle.internal.api.ApkVariantOutputImpl }
|
||||
.forEach { output ->
|
||||
output.outputFileName = "NotallyX-$versionName.apk"
|
||||
}
|
||||
}
|
||||
|
||||
dependenciesInfo {
|
||||
includeInApk = false
|
||||
includeInBundle = false
|
||||
}
|
||||
|
||||
kotlinOptions {
|
||||
jvmTarget = "1.8"
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
targetCompatibility = JavaVersion.VERSION_1_8
|
||||
}
|
||||
|
||||
buildFeatures {
|
||||
viewBinding = true
|
||||
}
|
||||
|
||||
packaging {
|
||||
resources.excludes += listOf(
|
||||
"DebugProbesKt.bin",
|
||||
"META-INF/**.version",
|
||||
"kotlin/**.kotlin_builtins",
|
||||
"kotlin-tooling-metadata.json"
|
||||
)
|
||||
}
|
||||
|
||||
testOptions {
|
||||
unitTests.isIncludeAndroidResources = true
|
||||
}
|
||||
}
|
||||
|
||||
ktfmt {
|
||||
kotlinLangStyle()
|
||||
}
|
||||
|
||||
tasks.register<KtfmtFormatTask>("ktfmtPrecommit") {
|
||||
source = project.fileTree(rootDir)
|
||||
include("**/*.kt")
|
||||
}
|
||||
|
||||
tasks.register<Copy>("installLocalGitHooks") {
|
||||
val scriptsDir = File(rootProject.rootDir, ".scripts/")
|
||||
val hooksDir = File(rootProject.rootDir, ".git/hooks")
|
||||
from(scriptsDir) {
|
||||
include("pre-commit", "pre-commit.bat")
|
||||
}
|
||||
into(hooksDir)
|
||||
inputs.files(file("${scriptsDir}/pre-commit"), file("${scriptsDir}/pre-commit.bat"))
|
||||
outputs.dir(hooksDir)
|
||||
fileMode = 509 // 0775 octal in decimal
|
||||
// If this throws permission denied:
|
||||
// chmod +rwx ./.git/hooks/pre-commit*
|
||||
}
|
||||
|
||||
tasks.preBuild.dependsOn(tasks.named("installLocalGitHooks"), tasks.exportTranslationsToExcel)
|
||||
|
||||
tasks.register("generateChangelogs") {
|
||||
doLast {
|
||||
val githubToken = providers.gradleProperty("CHANGELOG_GITHUB_TOKEN").orNull
|
||||
|
||||
val command = mutableListOf(
|
||||
"bash",
|
||||
rootProject.file("generate-changelogs.sh").absolutePath,
|
||||
"v${project.findProperty("app.lastVersionName").toString()}",
|
||||
rootProject.file("CHANGELOG.md").absolutePath
|
||||
)
|
||||
if (!githubToken.isNullOrEmpty()) {
|
||||
command.add(githubToken)
|
||||
} else {
|
||||
println("CHANGELOG_GITHUB_TOKEN not found, which limits the allowed amount of Github API calls")
|
||||
}
|
||||
exec {
|
||||
commandLine(command)
|
||||
standardOutput = System.out
|
||||
errorOutput = System.err
|
||||
}
|
||||
|
||||
val config = PropertiesConfiguration()
|
||||
val fileHandler = FileHandler(config).apply {
|
||||
file = rootProject.file("gradle.properties")
|
||||
load()
|
||||
}
|
||||
val currentVersionName = config.getProperty("app.versionName")
|
||||
config.setProperty("app.lastVersionName", currentVersionName)
|
||||
fileHandler.save()
|
||||
println("Updated app.lastVersionName to $currentVersionName")
|
||||
}
|
||||
}
|
||||
|
||||
afterEvaluate {
|
||||
tasks.named("bundleRelease").configure {
|
||||
dependsOn(tasks.named("testReleaseUnitTest"))
|
||||
}
|
||||
tasks.named("assembleRelease").configure {
|
||||
dependsOn(tasks.named("testReleaseUnitTest"))
|
||||
finalizedBy(tasks.named("generateChangelogs"))
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
val navVersion = "2.8.9"
|
||||
val roomVersion = "2.6.1"
|
||||
|
||||
implementation("androidx.navigation:navigation-fragment-ktx:$navVersion")
|
||||
implementation("androidx.navigation:navigation-ui-ktx:$navVersion")
|
||||
implementation("androidx.preference:preference-ktx:1.2.1")
|
||||
ksp("androidx.room:room-compiler:$roomVersion")
|
||||
implementation("androidx.room:room-ktx:$roomVersion")
|
||||
implementation("androidx.room:room-runtime:$roomVersion")
|
||||
implementation("androidx.security:security-crypto:1.1.0-alpha06")
|
||||
implementation("androidx.sqlite:sqlite-ktx:2.4.0")
|
||||
implementation("androidx.work:work-runtime:2.9.1")
|
||||
|
||||
implementation("cat.ereza:customactivityoncrash:2.4.0")
|
||||
implementation("com.davemorrissey.labs:subsampling-scale-image-view-androidx:3.10.0")
|
||||
implementation("com.github.bumptech.glide:glide:4.15.1")
|
||||
implementation("cn.Leaqi:SwipeDrawer:1.6")
|
||||
implementation("com.github.skydoves:colorpickerview:2.3.0")
|
||||
implementation("com.google.android.material:material:1.12.0")
|
||||
implementation("com.google.code.findbugs:jsr305:3.0.2")
|
||||
implementation("me.zhanghai.android.fastscroll:library:1.3.0")
|
||||
implementation("net.lingala.zip4j:zip4j:2.11.5")
|
||||
implementation("net.zetetic:android-database-sqlcipher:4.5.3")
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.3")
|
||||
implementation("org.jsoup:jsoup:1.18.1")
|
||||
implementation("org.ocpsoft.prettytime:prettytime:4.0.6.Final")
|
||||
implementation("org.simpleframework:simple-xml:2.7.1") {
|
||||
exclude(group = "xpp3", module = "xpp3")
|
||||
}
|
||||
|
||||
androidTestImplementation("androidx.room:room-testing:$roomVersion")
|
||||
androidTestImplementation("androidx.work:work-testing:2.9.1")
|
||||
testImplementation("androidx.arch.core:core-testing:2.2.0")
|
||||
testImplementation("androidx.test:core-ktx:1.6.1")
|
||||
testImplementation("androidx.test:core:1.6.1")
|
||||
testImplementation("io.mockk:mockk:1.13.12")
|
||||
testImplementation("junit:junit:4.13.2")
|
||||
testImplementation("org.assertj:assertj-core:3.24.2")
|
||||
testImplementation("org.json:json:20180813")
|
||||
testImplementation("org.mockito.kotlin:mockito-kotlin:5.4.0")
|
||||
testImplementation("org.mockito:mockito-core:5.13.0")
|
||||
testImplementation("org.robolectric:robolectric:4.13")
|
||||
}
|
266425
app/obfuscation/mapping.txt
266425
app/obfuscation/mapping.txt
File diff suppressed because it is too large
Load diff
49
app/proguard-rules.pro
vendored
49
app/proguard-rules.pro
vendored
|
@ -1,49 +0,0 @@
|
|||
# Add project specific ProGuard rules here.
|
||||
# You can control the set of applied configuration files using the
|
||||
# proguardFiles setting in build.gradle.kts.
|
||||
#
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
||||
# If your project uses WebView with JS, uncomment the following
|
||||
# and specify the fully qualified class name to the JavaScript interface
|
||||
# class:
|
||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||
# public *;
|
||||
#}
|
||||
-keepattributes LineNumberTable,SourceFile
|
||||
-renamesourcefileattribute SourceFile
|
||||
-dontobfuscate
|
||||
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*,!code/allocation/variable
|
||||
-printmapping obfuscation/mapping.txt
|
||||
|
||||
-keep class ** extends androidx.navigation.Navigator
|
||||
-keep class ** implements org.ocpsoft.prettytime.TimeUnit
|
||||
|
||||
# SQLCipher
|
||||
-keep class net.sqlcipher.** { *; }
|
||||
-keep class net.sqlcipher.database.** { *; }
|
||||
|
||||
# SimpleXML
|
||||
-keepattributes Signature
|
||||
-keepattributes *Annotation
|
||||
-keep interface org.simpleframework.xml.core.Label {
|
||||
public *;
|
||||
}
|
||||
-keep class * implements org.simpleframework.xml.core.Label {
|
||||
public *;
|
||||
}
|
||||
-keep interface org.simpleframework.xml.core.Parameter {
|
||||
public *;
|
||||
}
|
||||
-keep class * implements org.simpleframework.xml.core.Parameter {
|
||||
public *;
|
||||
}
|
||||
-keep interface org.simpleframework.xml.core.Extractor {
|
||||
public *;
|
||||
}
|
||||
-keep class * implements org.simpleframework.xml.core.Extractor {
|
||||
public *;
|
||||
}
|
||||
|
||||
-keep class * implements java.io.Serializable
|
|
@ -1,121 +0,0 @@
|
|||
{
|
||||
"formatVersion": 1,
|
||||
"database": {
|
||||
"version": 1,
|
||||
"identityHash": "561523a76ccf21fe0a7ff6c1fef657a9",
|
||||
"entities": [
|
||||
{
|
||||
"tableName": "BaseNote",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `type` TEXT NOT NULL, `folder` TEXT NOT NULL, `title` TEXT NOT NULL, `pinned` INTEGER NOT NULL, `timestamp` INTEGER NOT NULL, `labels` TEXT NOT NULL, `body` TEXT NOT NULL, `spans` TEXT NOT NULL, `items` TEXT NOT NULL)",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "id",
|
||||
"columnName": "id",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "type",
|
||||
"columnName": "type",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "folder",
|
||||
"columnName": "folder",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "title",
|
||||
"columnName": "title",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "pinned",
|
||||
"columnName": "pinned",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "timestamp",
|
||||
"columnName": "timestamp",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "labels",
|
||||
"columnName": "labels",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "body",
|
||||
"columnName": "body",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "spans",
|
||||
"columnName": "spans",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "items",
|
||||
"columnName": "items",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"columnNames": [
|
||||
"id"
|
||||
],
|
||||
"autoGenerate": true
|
||||
},
|
||||
"indices": [
|
||||
{
|
||||
"name": "index_BaseNote_id_folder_pinned_timestamp_labels",
|
||||
"unique": false,
|
||||
"columnNames": [
|
||||
"id",
|
||||
"folder",
|
||||
"pinned",
|
||||
"timestamp",
|
||||
"labels"
|
||||
],
|
||||
"createSql": "CREATE INDEX IF NOT EXISTS `index_BaseNote_id_folder_pinned_timestamp_labels` ON `${TABLE_NAME}` (`id`, `folder`, `pinned`, `timestamp`, `labels`)"
|
||||
}
|
||||
],
|
||||
"foreignKeys": []
|
||||
},
|
||||
{
|
||||
"tableName": "Label",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`value` TEXT NOT NULL, PRIMARY KEY(`value`))",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "value",
|
||||
"columnName": "value",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"columnNames": [
|
||||
"value"
|
||||
],
|
||||
"autoGenerate": false
|
||||
},
|
||||
"indices": [],
|
||||
"foreignKeys": []
|
||||
}
|
||||
],
|
||||
"views": [],
|
||||
"setupQueries": [
|
||||
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
|
||||
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '561523a76ccf21fe0a7ff6c1fef657a9')"
|
||||
]
|
||||
}
|
||||
}
|
|
@ -1,128 +0,0 @@
|
|||
{
|
||||
"formatVersion": 1,
|
||||
"database": {
|
||||
"version": 2,
|
||||
"identityHash": "4b4b549bcedcae938a5da7fd5433af4f",
|
||||
"entities": [
|
||||
{
|
||||
"tableName": "BaseNote",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `type` TEXT NOT NULL, `folder` TEXT NOT NULL, `color` TEXT NOT NULL, `title` TEXT NOT NULL, `pinned` INTEGER NOT NULL, `timestamp` INTEGER NOT NULL, `labels` TEXT NOT NULL, `body` TEXT NOT NULL, `spans` TEXT NOT NULL, `items` TEXT NOT NULL)",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "id",
|
||||
"columnName": "id",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "type",
|
||||
"columnName": "type",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "folder",
|
||||
"columnName": "folder",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "color",
|
||||
"columnName": "color",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "title",
|
||||
"columnName": "title",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "pinned",
|
||||
"columnName": "pinned",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "timestamp",
|
||||
"columnName": "timestamp",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "labels",
|
||||
"columnName": "labels",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "body",
|
||||
"columnName": "body",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "spans",
|
||||
"columnName": "spans",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "items",
|
||||
"columnName": "items",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"columnNames": [
|
||||
"id"
|
||||
],
|
||||
"autoGenerate": true
|
||||
},
|
||||
"indices": [
|
||||
{
|
||||
"name": "index_BaseNote_id_folder_pinned_timestamp_labels",
|
||||
"unique": false,
|
||||
"columnNames": [
|
||||
"id",
|
||||
"folder",
|
||||
"pinned",
|
||||
"timestamp",
|
||||
"labels"
|
||||
],
|
||||
"orders": [],
|
||||
"createSql": "CREATE INDEX IF NOT EXISTS `index_BaseNote_id_folder_pinned_timestamp_labels` ON `${TABLE_NAME}` (`id`, `folder`, `pinned`, `timestamp`, `labels`)"
|
||||
}
|
||||
],
|
||||
"foreignKeys": []
|
||||
},
|
||||
{
|
||||
"tableName": "Label",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`value` TEXT NOT NULL, PRIMARY KEY(`value`))",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "value",
|
||||
"columnName": "value",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"columnNames": [
|
||||
"value"
|
||||
],
|
||||
"autoGenerate": false
|
||||
},
|
||||
"indices": [],
|
||||
"foreignKeys": []
|
||||
}
|
||||
],
|
||||
"views": [],
|
||||
"setupQueries": [
|
||||
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
|
||||
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '4b4b549bcedcae938a5da7fd5433af4f')"
|
||||
]
|
||||
}
|
||||
}
|
|
@ -1,134 +0,0 @@
|
|||
{
|
||||
"formatVersion": 1,
|
||||
"database": {
|
||||
"version": 3,
|
||||
"identityHash": "0caeb621e051e4c032b6fb638eb9844f",
|
||||
"entities": [
|
||||
{
|
||||
"tableName": "BaseNote",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `type` TEXT NOT NULL, `folder` TEXT NOT NULL, `color` TEXT NOT NULL, `title` TEXT NOT NULL, `pinned` INTEGER NOT NULL, `timestamp` INTEGER NOT NULL, `labels` TEXT NOT NULL, `body` TEXT NOT NULL, `spans` TEXT NOT NULL, `items` TEXT NOT NULL, `images` TEXT NOT NULL)",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "id",
|
||||
"columnName": "id",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "type",
|
||||
"columnName": "type",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "folder",
|
||||
"columnName": "folder",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "color",
|
||||
"columnName": "color",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "title",
|
||||
"columnName": "title",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "pinned",
|
||||
"columnName": "pinned",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "timestamp",
|
||||
"columnName": "timestamp",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "labels",
|
||||
"columnName": "labels",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "body",
|
||||
"columnName": "body",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "spans",
|
||||
"columnName": "spans",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "items",
|
||||
"columnName": "items",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "images",
|
||||
"columnName": "images",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"autoGenerate": true,
|
||||
"columnNames": [
|
||||
"id"
|
||||
]
|
||||
},
|
||||
"indices": [
|
||||
{
|
||||
"name": "index_BaseNote_id_folder_pinned_timestamp_labels",
|
||||
"unique": false,
|
||||
"columnNames": [
|
||||
"id",
|
||||
"folder",
|
||||
"pinned",
|
||||
"timestamp",
|
||||
"labels"
|
||||
],
|
||||
"orders": [],
|
||||
"createSql": "CREATE INDEX IF NOT EXISTS `index_BaseNote_id_folder_pinned_timestamp_labels` ON `${TABLE_NAME}` (`id`, `folder`, `pinned`, `timestamp`, `labels`)"
|
||||
}
|
||||
],
|
||||
"foreignKeys": []
|
||||
},
|
||||
{
|
||||
"tableName": "Label",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`value` TEXT NOT NULL, PRIMARY KEY(`value`))",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "value",
|
||||
"columnName": "value",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"autoGenerate": false,
|
||||
"columnNames": [
|
||||
"value"
|
||||
]
|
||||
},
|
||||
"indices": [],
|
||||
"foreignKeys": []
|
||||
}
|
||||
],
|
||||
"views": [],
|
||||
"setupQueries": [
|
||||
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
|
||||
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '0caeb621e051e4c032b6fb638eb9844f')"
|
||||
]
|
||||
}
|
||||
}
|
|
@ -1,146 +0,0 @@
|
|||
{
|
||||
"formatVersion": 1,
|
||||
"database": {
|
||||
"version": 4,
|
||||
"identityHash": "01fd1bdfcfa83b65d83ff1209b964329",
|
||||
"entities": [
|
||||
{
|
||||
"tableName": "BaseNote",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `type` TEXT NOT NULL, `folder` TEXT NOT NULL, `color` TEXT NOT NULL, `title` TEXT NOT NULL, `pinned` INTEGER NOT NULL, `timestamp` INTEGER NOT NULL, `labels` TEXT NOT NULL, `body` TEXT NOT NULL, `spans` TEXT NOT NULL, `items` TEXT NOT NULL, `images` TEXT NOT NULL, `files` TEXT NOT NULL, `audios` TEXT NOT NULL)",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "id",
|
||||
"columnName": "id",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "type",
|
||||
"columnName": "type",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "folder",
|
||||
"columnName": "folder",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "color",
|
||||
"columnName": "color",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "title",
|
||||
"columnName": "title",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "pinned",
|
||||
"columnName": "pinned",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "timestamp",
|
||||
"columnName": "timestamp",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "labels",
|
||||
"columnName": "labels",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "body",
|
||||
"columnName": "body",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "spans",
|
||||
"columnName": "spans",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "items",
|
||||
"columnName": "items",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "images",
|
||||
"columnName": "images",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "files",
|
||||
"columnName": "files",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "audios",
|
||||
"columnName": "audios",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"autoGenerate": true,
|
||||
"columnNames": [
|
||||
"id"
|
||||
]
|
||||
},
|
||||
"indices": [
|
||||
{
|
||||
"name": "index_BaseNote_id_folder_pinned_timestamp_labels",
|
||||
"unique": false,
|
||||
"columnNames": [
|
||||
"id",
|
||||
"folder",
|
||||
"pinned",
|
||||
"timestamp",
|
||||
"labels"
|
||||
],
|
||||
"orders": [],
|
||||
"createSql": "CREATE INDEX IF NOT EXISTS `index_BaseNote_id_folder_pinned_timestamp_labels` ON `${TABLE_NAME}` (`id`, `folder`, `pinned`, `timestamp`, `labels`)"
|
||||
}
|
||||
],
|
||||
"foreignKeys": []
|
||||
},
|
||||
{
|
||||
"tableName": "Label",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`value` TEXT NOT NULL, PRIMARY KEY(`value`))",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "value",
|
||||
"columnName": "value",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"autoGenerate": false,
|
||||
"columnNames": [
|
||||
"value"
|
||||
]
|
||||
},
|
||||
"indices": [],
|
||||
"foreignKeys": []
|
||||
}
|
||||
],
|
||||
"views": [],
|
||||
"setupQueries": [
|
||||
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
|
||||
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '01fd1bdfcfa83b65d83ff1209b964329')"
|
||||
]
|
||||
}
|
||||
}
|
|
@ -1,152 +0,0 @@
|
|||
{
|
||||
"formatVersion": 1,
|
||||
"database": {
|
||||
"version": 5,
|
||||
"identityHash": "a0ebadcc625f8b49bf549975d7288f10",
|
||||
"entities": [
|
||||
{
|
||||
"tableName": "BaseNote",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `type` TEXT NOT NULL, `folder` TEXT NOT NULL, `color` TEXT NOT NULL, `title` TEXT NOT NULL, `pinned` INTEGER NOT NULL, `timestamp` INTEGER NOT NULL, `modifiedTimestamp` INTEGER NOT NULL, `labels` TEXT NOT NULL, `body` TEXT NOT NULL, `spans` TEXT NOT NULL, `items` TEXT NOT NULL, `images` TEXT NOT NULL, `files` TEXT NOT NULL, `audios` TEXT NOT NULL)",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "id",
|
||||
"columnName": "id",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "type",
|
||||
"columnName": "type",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "folder",
|
||||
"columnName": "folder",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "color",
|
||||
"columnName": "color",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "title",
|
||||
"columnName": "title",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "pinned",
|
||||
"columnName": "pinned",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "timestamp",
|
||||
"columnName": "timestamp",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "modifiedTimestamp",
|
||||
"columnName": "modifiedTimestamp",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "labels",
|
||||
"columnName": "labels",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "body",
|
||||
"columnName": "body",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "spans",
|
||||
"columnName": "spans",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "items",
|
||||
"columnName": "items",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "images",
|
||||
"columnName": "images",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "files",
|
||||
"columnName": "files",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "audios",
|
||||
"columnName": "audios",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"autoGenerate": true,
|
||||
"columnNames": [
|
||||
"id"
|
||||
]
|
||||
},
|
||||
"indices": [
|
||||
{
|
||||
"name": "index_BaseNote_id_folder_pinned_timestamp_labels",
|
||||
"unique": false,
|
||||
"columnNames": [
|
||||
"id",
|
||||
"folder",
|
||||
"pinned",
|
||||
"timestamp",
|
||||
"labels"
|
||||
],
|
||||
"orders": [],
|
||||
"createSql": "CREATE INDEX IF NOT EXISTS `index_BaseNote_id_folder_pinned_timestamp_labels` ON `${TABLE_NAME}` (`id`, `folder`, `pinned`, `timestamp`, `labels`)"
|
||||
}
|
||||
],
|
||||
"foreignKeys": []
|
||||
},
|
||||
{
|
||||
"tableName": "Label",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`value` TEXT NOT NULL, PRIMARY KEY(`value`))",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "value",
|
||||
"columnName": "value",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"autoGenerate": false,
|
||||
"columnNames": [
|
||||
"value"
|
||||
]
|
||||
},
|
||||
"indices": [],
|
||||
"foreignKeys": []
|
||||
}
|
||||
],
|
||||
"views": [],
|
||||
"setupQueries": [
|
||||
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
|
||||
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'a0ebadcc625f8b49bf549975d7288f10')"
|
||||
]
|
||||
}
|
||||
}
|
|
@ -1,158 +0,0 @@
|
|||
{
|
||||
"formatVersion": 1,
|
||||
"database": {
|
||||
"version": 6,
|
||||
"identityHash": "3ac03ff6740f6a6bcb19de11c7b3d750",
|
||||
"entities": [
|
||||
{
|
||||
"tableName": "BaseNote",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `type` TEXT NOT NULL, `folder` TEXT NOT NULL, `color` TEXT NOT NULL, `title` TEXT NOT NULL, `pinned` INTEGER NOT NULL, `timestamp` INTEGER NOT NULL, `modifiedTimestamp` INTEGER NOT NULL, `labels` TEXT NOT NULL, `body` TEXT NOT NULL, `spans` TEXT NOT NULL, `items` TEXT NOT NULL, `images` TEXT NOT NULL, `files` TEXT NOT NULL, `audios` TEXT NOT NULL, `reminders` TEXT NOT NULL)",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "id",
|
||||
"columnName": "id",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "type",
|
||||
"columnName": "type",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "folder",
|
||||
"columnName": "folder",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "color",
|
||||
"columnName": "color",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "title",
|
||||
"columnName": "title",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "pinned",
|
||||
"columnName": "pinned",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "timestamp",
|
||||
"columnName": "timestamp",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "modifiedTimestamp",
|
||||
"columnName": "modifiedTimestamp",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "labels",
|
||||
"columnName": "labels",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "body",
|
||||
"columnName": "body",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "spans",
|
||||
"columnName": "spans",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "items",
|
||||
"columnName": "items",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "images",
|
||||
"columnName": "images",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "files",
|
||||
"columnName": "files",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "audios",
|
||||
"columnName": "audios",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "reminders",
|
||||
"columnName": "reminders",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"autoGenerate": true,
|
||||
"columnNames": [
|
||||
"id"
|
||||
]
|
||||
},
|
||||
"indices": [
|
||||
{
|
||||
"name": "index_BaseNote_id_folder_pinned_timestamp_labels",
|
||||
"unique": false,
|
||||
"columnNames": [
|
||||
"id",
|
||||
"folder",
|
||||
"pinned",
|
||||
"timestamp",
|
||||
"labels"
|
||||
],
|
||||
"orders": [],
|
||||
"createSql": "CREATE INDEX IF NOT EXISTS `index_BaseNote_id_folder_pinned_timestamp_labels` ON `${TABLE_NAME}` (`id`, `folder`, `pinned`, `timestamp`, `labels`)"
|
||||
}
|
||||
],
|
||||
"foreignKeys": []
|
||||
},
|
||||
{
|
||||
"tableName": "Label",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`value` TEXT NOT NULL, PRIMARY KEY(`value`))",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "value",
|
||||
"columnName": "value",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"autoGenerate": false,
|
||||
"columnNames": [
|
||||
"value"
|
||||
]
|
||||
},
|
||||
"indices": [],
|
||||
"foreignKeys": []
|
||||
}
|
||||
],
|
||||
"views": [],
|
||||
"setupQueries": [
|
||||
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
|
||||
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '3ac03ff6740f6a6bcb19de11c7b3d750')"
|
||||
]
|
||||
}
|
||||
}
|
|
@ -1,158 +0,0 @@
|
|||
{
|
||||
"formatVersion": 1,
|
||||
"database": {
|
||||
"version": 7,
|
||||
"identityHash": "3ac03ff6740f6a6bcb19de11c7b3d750",
|
||||
"entities": [
|
||||
{
|
||||
"tableName": "BaseNote",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `type` TEXT NOT NULL, `folder` TEXT NOT NULL, `color` TEXT NOT NULL, `title` TEXT NOT NULL, `pinned` INTEGER NOT NULL, `timestamp` INTEGER NOT NULL, `modifiedTimestamp` INTEGER NOT NULL, `labels` TEXT NOT NULL, `body` TEXT NOT NULL, `spans` TEXT NOT NULL, `items` TEXT NOT NULL, `images` TEXT NOT NULL, `files` TEXT NOT NULL, `audios` TEXT NOT NULL, `reminders` TEXT NOT NULL)",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "id",
|
||||
"columnName": "id",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "type",
|
||||
"columnName": "type",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "folder",
|
||||
"columnName": "folder",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "color",
|
||||
"columnName": "color",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "title",
|
||||
"columnName": "title",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "pinned",
|
||||
"columnName": "pinned",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "timestamp",
|
||||
"columnName": "timestamp",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "modifiedTimestamp",
|
||||
"columnName": "modifiedTimestamp",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "labels",
|
||||
"columnName": "labels",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "body",
|
||||
"columnName": "body",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "spans",
|
||||
"columnName": "spans",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "items",
|
||||
"columnName": "items",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "images",
|
||||
"columnName": "images",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "files",
|
||||
"columnName": "files",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "audios",
|
||||
"columnName": "audios",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "reminders",
|
||||
"columnName": "reminders",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"autoGenerate": true,
|
||||
"columnNames": [
|
||||
"id"
|
||||
]
|
||||
},
|
||||
"indices": [
|
||||
{
|
||||
"name": "index_BaseNote_id_folder_pinned_timestamp_labels",
|
||||
"unique": false,
|
||||
"columnNames": [
|
||||
"id",
|
||||
"folder",
|
||||
"pinned",
|
||||
"timestamp",
|
||||
"labels"
|
||||
],
|
||||
"orders": [],
|
||||
"createSql": "CREATE INDEX IF NOT EXISTS `index_BaseNote_id_folder_pinned_timestamp_labels` ON `${TABLE_NAME}` (`id`, `folder`, `pinned`, `timestamp`, `labels`)"
|
||||
}
|
||||
],
|
||||
"foreignKeys": []
|
||||
},
|
||||
{
|
||||
"tableName": "Label",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`value` TEXT NOT NULL, PRIMARY KEY(`value`))",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "value",
|
||||
"columnName": "value",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"autoGenerate": false,
|
||||
"columnNames": [
|
||||
"value"
|
||||
]
|
||||
},
|
||||
"indices": [],
|
||||
"foreignKeys": []
|
||||
}
|
||||
],
|
||||
"views": [],
|
||||
"setupQueries": [
|
||||
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
|
||||
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '3ac03ff6740f6a6bcb19de11c7b3d750')"
|
||||
]
|
||||
}
|
||||
}
|
|
@ -1,158 +0,0 @@
|
|||
{
|
||||
"formatVersion": 1,
|
||||
"database": {
|
||||
"version": 8,
|
||||
"identityHash": "3ac03ff6740f6a6bcb19de11c7b3d750",
|
||||
"entities": [
|
||||
{
|
||||
"tableName": "BaseNote",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `type` TEXT NOT NULL, `folder` TEXT NOT NULL, `color` TEXT NOT NULL, `title` TEXT NOT NULL, `pinned` INTEGER NOT NULL, `timestamp` INTEGER NOT NULL, `modifiedTimestamp` INTEGER NOT NULL, `labels` TEXT NOT NULL, `body` TEXT NOT NULL, `spans` TEXT NOT NULL, `items` TEXT NOT NULL, `images` TEXT NOT NULL, `files` TEXT NOT NULL, `audios` TEXT NOT NULL, `reminders` TEXT NOT NULL)",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "id",
|
||||
"columnName": "id",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "type",
|
||||
"columnName": "type",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "folder",
|
||||
"columnName": "folder",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "color",
|
||||
"columnName": "color",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "title",
|
||||
"columnName": "title",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "pinned",
|
||||
"columnName": "pinned",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "timestamp",
|
||||
"columnName": "timestamp",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "modifiedTimestamp",
|
||||
"columnName": "modifiedTimestamp",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "labels",
|
||||
"columnName": "labels",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "body",
|
||||
"columnName": "body",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "spans",
|
||||
"columnName": "spans",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "items",
|
||||
"columnName": "items",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "images",
|
||||
"columnName": "images",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "files",
|
||||
"columnName": "files",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "audios",
|
||||
"columnName": "audios",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "reminders",
|
||||
"columnName": "reminders",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"autoGenerate": true,
|
||||
"columnNames": [
|
||||
"id"
|
||||
]
|
||||
},
|
||||
"indices": [
|
||||
{
|
||||
"name": "index_BaseNote_id_folder_pinned_timestamp_labels",
|
||||
"unique": false,
|
||||
"columnNames": [
|
||||
"id",
|
||||
"folder",
|
||||
"pinned",
|
||||
"timestamp",
|
||||
"labels"
|
||||
],
|
||||
"orders": [],
|
||||
"createSql": "CREATE INDEX IF NOT EXISTS `index_BaseNote_id_folder_pinned_timestamp_labels` ON `${TABLE_NAME}` (`id`, `folder`, `pinned`, `timestamp`, `labels`)"
|
||||
}
|
||||
],
|
||||
"foreignKeys": []
|
||||
},
|
||||
{
|
||||
"tableName": "Label",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`value` TEXT NOT NULL, PRIMARY KEY(`value`))",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "value",
|
||||
"columnName": "value",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"autoGenerate": false,
|
||||
"columnNames": [
|
||||
"value"
|
||||
]
|
||||
},
|
||||
"indices": [],
|
||||
"foreignKeys": []
|
||||
}
|
||||
],
|
||||
"views": [],
|
||||
"setupQueries": [
|
||||
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
|
||||
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '3ac03ff6740f6a6bcb19de11c7b3d750')"
|
||||
]
|
||||
}
|
||||
}
|
|
@ -1,164 +0,0 @@
|
|||
{
|
||||
"formatVersion": 1,
|
||||
"database": {
|
||||
"version": 9,
|
||||
"identityHash": "042b20b5b4cfc8415e6cf6348196e869",
|
||||
"entities": [
|
||||
{
|
||||
"tableName": "BaseNote",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `type` TEXT NOT NULL, `folder` TEXT NOT NULL, `color` TEXT NOT NULL, `title` TEXT NOT NULL, `pinned` INTEGER NOT NULL, `timestamp` INTEGER NOT NULL, `modifiedTimestamp` INTEGER NOT NULL, `labels` TEXT NOT NULL, `body` TEXT NOT NULL, `spans` TEXT NOT NULL, `items` TEXT NOT NULL, `images` TEXT NOT NULL, `files` TEXT NOT NULL, `audios` TEXT NOT NULL, `reminders` TEXT NOT NULL, `viewMode` TEXT NOT NULL)",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "id",
|
||||
"columnName": "id",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "type",
|
||||
"columnName": "type",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "folder",
|
||||
"columnName": "folder",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "color",
|
||||
"columnName": "color",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "title",
|
||||
"columnName": "title",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "pinned",
|
||||
"columnName": "pinned",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "timestamp",
|
||||
"columnName": "timestamp",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "modifiedTimestamp",
|
||||
"columnName": "modifiedTimestamp",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "labels",
|
||||
"columnName": "labels",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "body",
|
||||
"columnName": "body",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "spans",
|
||||
"columnName": "spans",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "items",
|
||||
"columnName": "items",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "images",
|
||||
"columnName": "images",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "files",
|
||||
"columnName": "files",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "audios",
|
||||
"columnName": "audios",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "reminders",
|
||||
"columnName": "reminders",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "viewMode",
|
||||
"columnName": "viewMode",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"autoGenerate": true,
|
||||
"columnNames": [
|
||||
"id"
|
||||
]
|
||||
},
|
||||
"indices": [
|
||||
{
|
||||
"name": "index_BaseNote_id_folder_pinned_timestamp_labels",
|
||||
"unique": false,
|
||||
"columnNames": [
|
||||
"id",
|
||||
"folder",
|
||||
"pinned",
|
||||
"timestamp",
|
||||
"labels"
|
||||
],
|
||||
"orders": [],
|
||||
"createSql": "CREATE INDEX IF NOT EXISTS `index_BaseNote_id_folder_pinned_timestamp_labels` ON `${TABLE_NAME}` (`id`, `folder`, `pinned`, `timestamp`, `labels`)"
|
||||
}
|
||||
],
|
||||
"foreignKeys": []
|
||||
},
|
||||
{
|
||||
"tableName": "Label",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`value` TEXT NOT NULL, PRIMARY KEY(`value`))",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "value",
|
||||
"columnName": "value",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"autoGenerate": false,
|
||||
"columnNames": [
|
||||
"value"
|
||||
]
|
||||
},
|
||||
"indices": [],
|
||||
"foreignKeys": []
|
||||
}
|
||||
],
|
||||
"views": [],
|
||||
"setupQueries": [
|
||||
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
|
||||
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '042b20b5b4cfc8415e6cf6348196e869')"
|
||||
]
|
||||
}
|
||||
}
|
|
@ -1,158 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:installLocation="auto">
|
||||
|
||||
<uses-permission
|
||||
android:name="android.permission.ACCESS_NETWORK_STATE"
|
||||
tools:node="remove" />
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MICROPHONE" />
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK" />
|
||||
<uses-permission android:name="android.permission.RECORD_AUDIO" />
|
||||
|
||||
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
||||
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />
|
||||
|
||||
<uses-permission android:name="android.permission.USE_BIOMETRIC" />
|
||||
<uses-permission android:name="android.permission.USE_FINGERPRINT" />
|
||||
|
||||
<application
|
||||
android:name=".NotallyXApplication"
|
||||
android:allowBackup="true"
|
||||
android:appCategory="productivity"
|
||||
android:dataExtractionRules="@xml/data_rules"
|
||||
android:fullBackupContent="@xml/backup_content"
|
||||
android:icon="@mipmap/notallyx"
|
||||
android:label="@string/app_name"
|
||||
android:localeConfig="@xml/locales"
|
||||
android:roundIcon="@mipmap/notallyx_round"
|
||||
android:theme="@style/AppTheme">
|
||||
|
||||
<provider
|
||||
android:name="androidx.core.content.FileProvider"
|
||||
android:authorities="${applicationId}.provider"
|
||||
android:exported="false"
|
||||
android:grantUriPermissions="true">
|
||||
|
||||
<meta-data
|
||||
android:name="android.support.FILE_PROVIDER_PATHS"
|
||||
android:resource="@xml/provider_paths" />
|
||||
|
||||
</provider>
|
||||
|
||||
<activity
|
||||
android:name=".presentation.activity.main.MainActivity"
|
||||
android:exported="true">
|
||||
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
|
||||
<meta-data
|
||||
android:name="android.app.shortcuts"
|
||||
android:resource="@xml/shortcuts" />
|
||||
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name=".presentation.activity.note.EditListActivity"
|
||||
android:windowSoftInputMode="adjustResize" />
|
||||
|
||||
<activity
|
||||
android:name=".presentation.activity.note.EditNoteActivity"
|
||||
android:exported="true"
|
||||
android:windowSoftInputMode="adjustResize">
|
||||
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.SEND" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<data android:mimeType="*/*" />
|
||||
</intent-filter>
|
||||
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.SEND_MULTIPLE" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<data android:mimeType="*/*" />
|
||||
</intent-filter>
|
||||
|
||||
</activity>
|
||||
|
||||
<activity android:name=".presentation.activity.note.ViewImageActivity" />
|
||||
|
||||
<activity android:name=".presentation.activity.note.SelectLabelsActivity" />
|
||||
|
||||
<activity android:name=".presentation.activity.note.reminders.RemindersActivity" />
|
||||
|
||||
<activity
|
||||
android:name=".presentation.activity.note.RecordAudioActivity"
|
||||
android:launchMode="singleTask" />
|
||||
|
||||
<activity android:name=".presentation.activity.note.PlayAudioActivity" />
|
||||
|
||||
<activity
|
||||
android:name=".presentation.activity.ConfigureWidgetActivity"
|
||||
android:exported="false">
|
||||
|
||||
<intent-filter>
|
||||
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
|
||||
</intent-filter>
|
||||
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name=".presentation.activity.note.PickNoteActivity"
|
||||
android:exported="false">
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name=".utils.ErrorActivity"
|
||||
android:exported="true"
|
||||
android:label="@string/unknown_error"
|
||||
android:process=":error_activity">
|
||||
<intent-filter>
|
||||
<action android:name="cat.ereza.customactivityoncrash.ERROR" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<receiver
|
||||
android:name=".presentation.widget.WidgetProvider"
|
||||
android:exported="false"
|
||||
android:label="@string/single_note_or_list">
|
||||
|
||||
<intent-filter>
|
||||
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
|
||||
</intent-filter>
|
||||
|
||||
<meta-data
|
||||
android:name="android.appwidget.provider"
|
||||
android:resource="@xml/widget" />
|
||||
|
||||
</receiver>
|
||||
|
||||
<receiver android:name=".presentation.activity.note.reminders.ReminderReceiver" android:enabled="true" android:exported="true" >
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
||||
<action android:name="android.app.action.SCHEDULE_EXACT_ALARM_PERMISSION_STATE_CHANGED" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
<service
|
||||
android:name=".presentation.widget.WidgetService"
|
||||
android:permission="android.permission.BIND_REMOTEVIEWS" />
|
||||
|
||||
<service
|
||||
android:name=".utils.audio.AudioRecordService"
|
||||
android:exported="false"
|
||||
android:foregroundServiceType="microphone" />
|
||||
|
||||
<service
|
||||
android:name=".utils.audio.AudioPlayService"
|
||||
android:exported="false"
|
||||
android:foregroundServiceType="mediaPlayback" />
|
||||
|
||||
</application>
|
||||
|
||||
</manifest>
|
|
@ -1,83 +0,0 @@
|
|||
package android.print
|
||||
|
||||
import android.content.ContentResolver
|
||||
import android.content.Context
|
||||
import android.webkit.WebView
|
||||
import android.webkit.WebViewClient
|
||||
import androidx.documentfile.provider.DocumentFile
|
||||
import com.philkes.notallyx.utils.nameWithoutExtension
|
||||
|
||||
/**
|
||||
* Needs to be in android.print package to access the package private methods of
|
||||
* [PrintDocumentAdapter]
|
||||
*/
|
||||
fun Context.printPdf(file: DocumentFile, content: String, pdfPrintListener: PdfPrintListener) {
|
||||
val webView = WebView(this)
|
||||
webView.loadDataWithBaseURL(null, content, "text/html", "utf-8", null)
|
||||
webView.webViewClient =
|
||||
object : WebViewClient() {
|
||||
|
||||
override fun onPageFinished(view: WebView?, url: String?) {
|
||||
val adapter = webView.createPrintDocumentAdapter(file.nameWithoutExtension!!)
|
||||
contentResolver.printPdf(file, adapter, pdfPrintListener)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun ContentResolver.printPdf(
|
||||
file: DocumentFile,
|
||||
adapter: PrintDocumentAdapter,
|
||||
pdfPrintListener: PdfPrintListener,
|
||||
) {
|
||||
val onLayoutResult =
|
||||
object : PrintDocumentAdapter.LayoutResultCallback() {
|
||||
|
||||
override fun onLayoutFailed(error: CharSequence?) {
|
||||
pdfPrintListener.onFailure(error)
|
||||
}
|
||||
|
||||
override fun onLayoutFinished(info: PrintDocumentInfo?, changed: Boolean) {
|
||||
this@printPdf.writeToFile(file, adapter, pdfPrintListener)
|
||||
}
|
||||
}
|
||||
|
||||
adapter.onLayout(null, createPrintAttributes(), null, onLayoutResult, null)
|
||||
}
|
||||
|
||||
private fun ContentResolver.writeToFile(
|
||||
file: DocumentFile,
|
||||
adapter: PrintDocumentAdapter,
|
||||
pdfPrintListener: PdfPrintListener,
|
||||
) {
|
||||
val onWriteResult =
|
||||
object : PrintDocumentAdapter.WriteResultCallback() {
|
||||
|
||||
override fun onWriteFailed(error: CharSequence?) {
|
||||
pdfPrintListener.onFailure(error)
|
||||
}
|
||||
|
||||
override fun onWriteFinished(pages: Array<out PageRange>?) {
|
||||
pdfPrintListener.onSuccess(file)
|
||||
}
|
||||
}
|
||||
|
||||
val pages = arrayOf(PageRange.ALL_PAGES)
|
||||
val fileDescriptor = openFileDescriptor(file.uri, "rw")
|
||||
adapter.onWrite(pages, fileDescriptor, null, onWriteResult)
|
||||
}
|
||||
|
||||
private fun createPrintAttributes(): PrintAttributes {
|
||||
return with(PrintAttributes.Builder()) {
|
||||
setMediaSize(PrintAttributes.MediaSize.ISO_A4)
|
||||
setMinMargins(PrintAttributes.Margins.NO_MARGINS)
|
||||
setResolution(PrintAttributes.Resolution("Standard", "Standard", 100, 100))
|
||||
build()
|
||||
}
|
||||
}
|
||||
|
||||
interface PdfPrintListener {
|
||||
|
||||
fun onSuccess(file: DocumentFile)
|
||||
|
||||
fun onFailure(message: CharSequence?)
|
||||
}
|
|
@ -1,118 +0,0 @@
|
|||
package androidx.recyclerview.widget
|
||||
|
||||
import android.graphics.Rect
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.view.children
|
||||
import androidx.core.widget.NestedScrollView
|
||||
import kotlin.math.abs
|
||||
|
||||
class NestedScrollViewItemTouchHelper(
|
||||
callback: Callback,
|
||||
private val scrollView: NestedScrollView,
|
||||
) : ItemTouchHelper(callback) {
|
||||
private var selectedStartY: Int = -1
|
||||
private var selectedStartScrollY: Float = -1f
|
||||
private var selectedView: View? = null
|
||||
private var dragScrollStartTimeInMs: Long = 0
|
||||
|
||||
private var lastmDy = 0f
|
||||
private var lastScrollY = 0
|
||||
private var tmpRect: Rect? = null
|
||||
|
||||
override fun select(selected: RecyclerView.ViewHolder?, actionState: Int) {
|
||||
super.select(selected, actionState)
|
||||
if (selected != null) {
|
||||
selectedView = selected.itemView
|
||||
selectedStartY = selected.itemView.top
|
||||
selectedStartScrollY = scrollView!!.scrollY.toFloat()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Scrolls [scrollView] when an item in [mRecyclerView] is dragged to the top or bottom of the
|
||||
* [scrollView].
|
||||
*
|
||||
* Inspired by
|
||||
* [https://stackoverflow.com/a/70699988/9748566](https://stackoverflow.com/a/70699988/9748566)
|
||||
*/
|
||||
override fun scrollIfNecessary(): Boolean {
|
||||
if (mSelected == null) {
|
||||
dragScrollStartTimeInMs = Long.MIN_VALUE
|
||||
return false
|
||||
}
|
||||
val now = System.currentTimeMillis()
|
||||
val scrollDuration =
|
||||
if (dragScrollStartTimeInMs == Long.MIN_VALUE) 0 else now - dragScrollStartTimeInMs
|
||||
val lm = mRecyclerView.layoutManager
|
||||
if (tmpRect == null) {
|
||||
tmpRect = Rect()
|
||||
}
|
||||
var scrollY = 0
|
||||
val currentScrollY = scrollView.scrollY
|
||||
|
||||
// We need to use the height of NestedScrollView, not RecyclerView's!
|
||||
val actualShowingHeight =
|
||||
scrollView.height - mRecyclerView.top - mRecyclerView.paddingBottom
|
||||
|
||||
lm!!.calculateItemDecorationsForChild(mSelected.itemView, tmpRect!!)
|
||||
if (lm.canScrollVertically()) {
|
||||
// Keep scrolling if the user didnt change the drag direction
|
||||
if (lastScrollY != 0 && abs(lastmDy) >= abs(mDy)) {
|
||||
scrollY = lastScrollY
|
||||
} else {
|
||||
// The true current Y of the item in NestedScrollView, not in RecyclerView!
|
||||
val curY = (selectedStartY + mDy - currentScrollY).toInt()
|
||||
// The true mDy should plus the initial scrollY and minus current scrollY of
|
||||
// NestedScrollView
|
||||
val checkDy = (mDy + selectedStartScrollY - currentScrollY).toInt()
|
||||
val topDiff = curY - tmpRect!!.top - mRecyclerView.paddingTop
|
||||
if (checkDy < 0 && topDiff < 0) { // User is draging the item out of the top edge.
|
||||
scrollY = topDiff
|
||||
} else if (checkDy > 0) { // User is draging the item out of the bottom edge.
|
||||
val bottomDiff = (curY + mSelected.itemView.height - actualShowingHeight) + 10
|
||||
if (bottomDiff >= 0) {
|
||||
scrollY = bottomDiff
|
||||
}
|
||||
} else {
|
||||
scrollY = 0
|
||||
}
|
||||
}
|
||||
}
|
||||
lastScrollY = scrollY
|
||||
lastmDy = mDy
|
||||
if (scrollY != 0) {
|
||||
scrollY =
|
||||
mCallback.interpolateOutOfBoundsScroll(
|
||||
mRecyclerView,
|
||||
mSelected.itemView.height,
|
||||
scrollY,
|
||||
actualShowingHeight,
|
||||
scrollDuration,
|
||||
)
|
||||
}
|
||||
if (scrollY != 0) {
|
||||
val maxScrollY = scrollView.childrenHeightsSum - scrollView.height
|
||||
// Check if we can scroll further before applying the scroll
|
||||
if (
|
||||
(scrollY < 0 && scrollView.scrollY > 0) ||
|
||||
(scrollY > 0 && scrollView.scrollY < maxScrollY)
|
||||
) {
|
||||
if (dragScrollStartTimeInMs == Long.MIN_VALUE) {
|
||||
dragScrollStartTimeInMs = now
|
||||
}
|
||||
scrollView.scrollBy(0, scrollY)
|
||||
// Update the dragged item position as well
|
||||
selectedView?.translationY = selectedView!!.translationY + scrollY
|
||||
return true
|
||||
}
|
||||
}
|
||||
dragScrollStartTimeInMs = Long.MIN_VALUE
|
||||
lastScrollY = 0
|
||||
lastmDy = 0f
|
||||
return false
|
||||
}
|
||||
|
||||
private val ViewGroup.childrenHeightsSum
|
||||
get() = children.map { it.measuredHeight }.sum()
|
||||
}
|
|
@ -1,171 +0,0 @@
|
|||
package com.philkes.notallyx
|
||||
|
||||
import android.app.Application
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.IntentFilter
|
||||
import android.os.Build
|
||||
import androidx.appcompat.app.AppCompatDelegate
|
||||
import androidx.lifecycle.Observer
|
||||
import androidx.work.WorkInfo
|
||||
import androidx.work.WorkManager
|
||||
import com.google.android.material.color.DynamicColors
|
||||
import com.philkes.notallyx.presentation.view.misc.NotNullLiveData
|
||||
import com.philkes.notallyx.presentation.viewmodel.preference.BiometricLock
|
||||
import com.philkes.notallyx.presentation.viewmodel.preference.NotallyXPreferences
|
||||
import com.philkes.notallyx.presentation.viewmodel.preference.NotallyXPreferences.Companion.EMPTY_PATH
|
||||
import com.philkes.notallyx.presentation.viewmodel.preference.Theme
|
||||
import com.philkes.notallyx.presentation.widget.WidgetProvider
|
||||
import com.philkes.notallyx.utils.backup.AUTO_BACKUP_WORK_NAME
|
||||
import com.philkes.notallyx.utils.backup.autoBackupOnSave
|
||||
import com.philkes.notallyx.utils.backup.cancelAutoBackup
|
||||
import com.philkes.notallyx.utils.backup.containsNonCancelled
|
||||
import com.philkes.notallyx.utils.backup.deleteModifiedNoteBackup
|
||||
import com.philkes.notallyx.utils.backup.isEqualTo
|
||||
import com.philkes.notallyx.utils.backup.modifiedNoteBackupExists
|
||||
import com.philkes.notallyx.utils.backup.scheduleAutoBackup
|
||||
import com.philkes.notallyx.utils.backup.updateAutoBackup
|
||||
import com.philkes.notallyx.utils.observeOnce
|
||||
import com.philkes.notallyx.utils.security.UnlockReceiver
|
||||
import java.util.concurrent.TimeUnit
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.MainScope
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
class NotallyXApplication : Application() {
|
||||
|
||||
private lateinit var biometricLockObserver: Observer<BiometricLock>
|
||||
private lateinit var preferences: NotallyXPreferences
|
||||
private var unlockReceiver: UnlockReceiver? = null
|
||||
|
||||
val locked = NotNullLiveData(true)
|
||||
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
if (isTestRunner()) return
|
||||
preferences = NotallyXPreferences.getInstance(this)
|
||||
if (preferences.useDynamicColors.value) {
|
||||
if (DynamicColors.isDynamicColorAvailable()) {
|
||||
DynamicColors.applyToActivitiesIfAvailable(this)
|
||||
}
|
||||
} else {
|
||||
setTheme(R.style.AppTheme)
|
||||
}
|
||||
preferences.theme.observeForeverWithPrevious { (oldTheme, theme) ->
|
||||
when (theme) {
|
||||
Theme.DARK ->
|
||||
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
|
||||
|
||||
Theme.LIGHT ->
|
||||
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
|
||||
|
||||
Theme.FOLLOW_SYSTEM ->
|
||||
AppCompatDelegate.setDefaultNightMode(
|
||||
AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
|
||||
)
|
||||
}
|
||||
if (oldTheme != null) {
|
||||
WidgetProvider.updateWidgets(this)
|
||||
}
|
||||
}
|
||||
|
||||
preferences.backupsFolder.observeForeverWithPrevious { (backupFolderBefore, backupFolder) ->
|
||||
checkUpdatePeriodicBackup(
|
||||
backupFolderBefore,
|
||||
backupFolder,
|
||||
preferences.periodicBackups.value.periodInDays.toLong(),
|
||||
)
|
||||
}
|
||||
preferences.periodicBackups.observeForever { value ->
|
||||
val backupFolder = preferences.backupsFolder.value
|
||||
checkUpdatePeriodicBackup(backupFolder, backupFolder, value.periodInDays.toLong())
|
||||
}
|
||||
|
||||
val filter = IntentFilter().apply { addAction(Intent.ACTION_SCREEN_OFF) }
|
||||
biometricLockObserver = Observer { biometricLock ->
|
||||
if (biometricLock == BiometricLock.ENABLED) {
|
||||
unlockReceiver = UnlockReceiver(this)
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||
registerReceiver(unlockReceiver, filter, Context.RECEIVER_NOT_EXPORTED)
|
||||
} else {
|
||||
registerReceiver(unlockReceiver, filter)
|
||||
}
|
||||
} else {
|
||||
unlockReceiver?.let { unregisterReceiver(it) }
|
||||
if (locked.value) {
|
||||
locked.postValue(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
preferences.biometricLock.observeForever(biometricLockObserver)
|
||||
|
||||
locked.observeForever { isLocked -> WidgetProvider.updateWidgets(this, locked = isLocked) }
|
||||
|
||||
preferences.backupPassword.observeForeverWithPrevious {
|
||||
(previousBackupPassword, backupPassword) ->
|
||||
if (preferences.backupOnSave.value) {
|
||||
val backupPath = preferences.backupsFolder.value
|
||||
if (backupPath != EMPTY_PATH) {
|
||||
if (
|
||||
!modifiedNoteBackupExists(backupPath) ||
|
||||
(previousBackupPassword != null &&
|
||||
previousBackupPassword != backupPassword)
|
||||
) {
|
||||
deleteModifiedNoteBackup(backupPath)
|
||||
MainScope().launch {
|
||||
withContext(Dispatchers.IO) {
|
||||
autoBackupOnSave(
|
||||
backupPath,
|
||||
savedNote = null,
|
||||
password = backupPassword,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun checkUpdatePeriodicBackup(
|
||||
backupFolderBefore: String?,
|
||||
backupFolder: String,
|
||||
periodInDays: Long,
|
||||
) {
|
||||
val workManager = getWorkManagerSafe() ?: return
|
||||
workManager.getWorkInfosForUniqueWorkLiveData(AUTO_BACKUP_WORK_NAME).observeOnce { workInfos
|
||||
->
|
||||
if (backupFolder == EMPTY_PATH || periodInDays < 1) {
|
||||
if (workInfos?.containsNonCancelled() == true) {
|
||||
workManager.cancelAutoBackup()
|
||||
}
|
||||
} else if (
|
||||
workInfos.isNullOrEmpty() ||
|
||||
workInfos.all { it.state == WorkInfo.State.CANCELLED } ||
|
||||
(backupFolderBefore != null && backupFolderBefore != backupFolder)
|
||||
) {
|
||||
workManager.scheduleAutoBackup(this, periodInDays)
|
||||
} else if (
|
||||
workInfos.first().periodicityInfo?.isEqualTo(periodInDays, TimeUnit.DAYS) == false
|
||||
) {
|
||||
workManager.updateAutoBackup(workInfos, periodInDays)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun getWorkManagerSafe(): WorkManager? {
|
||||
return try {
|
||||
WorkManager.getInstance(this)
|
||||
} catch (e: Exception) {
|
||||
// TODO: Happens when ErrorActivity is launched
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private fun isTestRunner(): Boolean {
|
||||
return Build.FINGERPRINT.equals("robolectric", ignoreCase = true)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,276 +0,0 @@
|
|||
package com.philkes.notallyx.data
|
||||
|
||||
import android.content.Context
|
||||
import android.content.ContextWrapper
|
||||
import android.os.Build
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.lifecycle.Observer
|
||||
import androidx.room.Database
|
||||
import androidx.room.Room
|
||||
import androidx.room.RoomDatabase
|
||||
import androidx.room.TypeConverters
|
||||
import androidx.room.migration.Migration
|
||||
import androidx.sqlite.db.SimpleSQLiteQuery
|
||||
import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
import com.philkes.notallyx.data.dao.BaseNoteDao
|
||||
import com.philkes.notallyx.data.dao.CommonDao
|
||||
import com.philkes.notallyx.data.dao.LabelDao
|
||||
import com.philkes.notallyx.data.model.BaseNote
|
||||
import com.philkes.notallyx.data.model.Color
|
||||
import com.philkes.notallyx.data.model.Converters
|
||||
import com.philkes.notallyx.data.model.Label
|
||||
import com.philkes.notallyx.data.model.NoteViewMode
|
||||
import com.philkes.notallyx.data.model.toColorString
|
||||
import com.philkes.notallyx.presentation.view.misc.NotNullLiveData
|
||||
import com.philkes.notallyx.presentation.viewmodel.preference.BiometricLock
|
||||
import com.philkes.notallyx.presentation.viewmodel.preference.NotallyXPreferences
|
||||
import com.philkes.notallyx.presentation.viewmodel.preference.observeForeverSkipFirst
|
||||
import com.philkes.notallyx.utils.getExternalMediaDirectory
|
||||
import com.philkes.notallyx.utils.security.SQLCipherUtils
|
||||
import com.philkes.notallyx.utils.security.getInitializedCipherForDecryption
|
||||
import java.io.File
|
||||
import net.sqlcipher.database.SQLiteDatabase
|
||||
import net.sqlcipher.database.SupportFactory
|
||||
|
||||
@TypeConverters(Converters::class)
|
||||
@Database(entities = [BaseNote::class, Label::class], version = 9)
|
||||
abstract class NotallyDatabase : RoomDatabase() {
|
||||
|
||||
abstract fun getLabelDao(): LabelDao
|
||||
|
||||
abstract fun getCommonDao(): CommonDao
|
||||
|
||||
abstract fun getBaseNoteDao(): BaseNoteDao
|
||||
|
||||
fun checkpoint() {
|
||||
getBaseNoteDao().query(SimpleSQLiteQuery("pragma wal_checkpoint(FULL)"))
|
||||
}
|
||||
|
||||
private var biometricLockObserver: Observer<BiometricLock>? = null
|
||||
private var dataInPublicFolderObserver: Observer<Boolean>? = null
|
||||
|
||||
companion object {
|
||||
|
||||
const val DATABASE_NAME = "NotallyDatabase"
|
||||
|
||||
@Volatile private var instance: NotNullLiveData<NotallyDatabase>? = null
|
||||
|
||||
fun getCurrentDatabaseFile(context: ContextWrapper): File {
|
||||
return if (NotallyXPreferences.getInstance(context).dataInPublicFolder.value) {
|
||||
getExternalDatabaseFile(context)
|
||||
} else {
|
||||
getInternalDatabaseFile(context)
|
||||
}
|
||||
}
|
||||
|
||||
fun getExternalDatabaseFile(context: ContextWrapper): File {
|
||||
return File(context.getExternalMediaDirectory(), DATABASE_NAME)
|
||||
}
|
||||
|
||||
fun getExternalDatabaseFiles(context: ContextWrapper): List<File> {
|
||||
return listOf(
|
||||
File(context.getExternalMediaDirectory(), DATABASE_NAME),
|
||||
File(context.getExternalMediaDirectory(), "$DATABASE_NAME-shm"),
|
||||
File(context.getExternalMediaDirectory(), "$DATABASE_NAME-wal"),
|
||||
)
|
||||
}
|
||||
|
||||
fun getInternalDatabaseFile(context: Context): File {
|
||||
return context.getDatabasePath(DATABASE_NAME)
|
||||
}
|
||||
|
||||
fun getInternalDatabaseFiles(context: ContextWrapper): List<File> {
|
||||
val directory = context.getDatabasePath(DATABASE_NAME).parentFile
|
||||
return listOf(
|
||||
File(directory, DATABASE_NAME),
|
||||
File(directory, "$DATABASE_NAME-shm"),
|
||||
File(directory, "$DATABASE_NAME-wal"),
|
||||
)
|
||||
}
|
||||
|
||||
private fun getCurrentDatabaseName(context: ContextWrapper): String {
|
||||
return if (NotallyXPreferences.getInstance(context).dataInPublicFolder.value) {
|
||||
getExternalDatabaseFile(context).absolutePath
|
||||
} else {
|
||||
DATABASE_NAME
|
||||
}
|
||||
}
|
||||
|
||||
fun getDatabase(
|
||||
context: ContextWrapper,
|
||||
observePreferences: Boolean = true,
|
||||
): NotNullLiveData<NotallyDatabase> {
|
||||
return instance
|
||||
?: synchronized(this) {
|
||||
val preferences = NotallyXPreferences.getInstance(context)
|
||||
this.instance =
|
||||
NotNullLiveData(createInstance(context, preferences, observePreferences))
|
||||
return this.instance!!
|
||||
}
|
||||
}
|
||||
|
||||
fun getFreshDatabase(context: ContextWrapper): NotallyDatabase {
|
||||
return createInstance(context, NotallyXPreferences.getInstance(context), false)
|
||||
}
|
||||
|
||||
private fun createInstance(
|
||||
context: ContextWrapper,
|
||||
preferences: NotallyXPreferences,
|
||||
observePreferences: Boolean,
|
||||
): NotallyDatabase {
|
||||
val instanceBuilder =
|
||||
Room.databaseBuilder(
|
||||
context,
|
||||
NotallyDatabase::class.java,
|
||||
getCurrentDatabaseName(context),
|
||||
)
|
||||
.addMigrations(
|
||||
Migration2,
|
||||
Migration3,
|
||||
Migration4,
|
||||
Migration5,
|
||||
Migration6,
|
||||
Migration7,
|
||||
Migration8,
|
||||
Migration9,
|
||||
)
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
SQLiteDatabase.loadLibs(context)
|
||||
if (preferences.biometricLock.value == BiometricLock.ENABLED) {
|
||||
if (
|
||||
SQLCipherUtils.getDatabaseState(getCurrentDatabaseFile(context)) ==
|
||||
SQLCipherUtils.State.ENCRYPTED
|
||||
) {
|
||||
initializeDecryption(preferences, instanceBuilder)
|
||||
} else {
|
||||
preferences.biometricLock.save(BiometricLock.DISABLED)
|
||||
}
|
||||
} else {
|
||||
if (
|
||||
SQLCipherUtils.getDatabaseState(getCurrentDatabaseFile(context)) ==
|
||||
SQLCipherUtils.State.ENCRYPTED
|
||||
) {
|
||||
preferences.biometricLock.save(BiometricLock.ENABLED)
|
||||
initializeDecryption(preferences, instanceBuilder)
|
||||
}
|
||||
}
|
||||
val instance = instanceBuilder.build()
|
||||
if (observePreferences) {
|
||||
instance.biometricLockObserver = Observer {
|
||||
NotallyDatabase.instance?.value?.biometricLockObserver?.let {
|
||||
preferences.biometricLock.removeObserver(it)
|
||||
}
|
||||
val newInstance = createInstance(context, preferences, true)
|
||||
NotallyDatabase.instance?.postValue(newInstance)
|
||||
preferences.biometricLock.observeForeverSkipFirst(
|
||||
newInstance.biometricLockObserver!!
|
||||
)
|
||||
}
|
||||
preferences.biometricLock.observeForeverSkipFirst(
|
||||
instance.biometricLockObserver!!
|
||||
)
|
||||
|
||||
instance.dataInPublicFolderObserver = Observer {
|
||||
NotallyDatabase.instance?.value?.dataInPublicFolderObserver?.let {
|
||||
preferences.dataInPublicFolder.removeObserver(it)
|
||||
}
|
||||
val newInstance = createInstance(context, preferences, true)
|
||||
NotallyDatabase.instance?.postValue(newInstance)
|
||||
preferences.dataInPublicFolder.observeForeverSkipFirst(
|
||||
newInstance.dataInPublicFolderObserver!!
|
||||
)
|
||||
}
|
||||
preferences.dataInPublicFolder.observeForeverSkipFirst(
|
||||
instance.dataInPublicFolderObserver!!
|
||||
)
|
||||
}
|
||||
return instance
|
||||
}
|
||||
return instanceBuilder.build()
|
||||
}
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.M)
|
||||
private fun initializeDecryption(
|
||||
preferences: NotallyXPreferences,
|
||||
instanceBuilder: Builder<NotallyDatabase>,
|
||||
) {
|
||||
val initializationVector = preferences.iv.value!!
|
||||
val cipher = getInitializedCipherForDecryption(iv = initializationVector)
|
||||
val encryptedPassphrase = preferences.databaseEncryptionKey.value
|
||||
val passphrase = cipher.doFinal(encryptedPassphrase)
|
||||
val factory = SupportFactory(passphrase)
|
||||
instanceBuilder.openHelperFactory(factory)
|
||||
}
|
||||
|
||||
object Migration2 : Migration(1, 2) {
|
||||
|
||||
override fun migrate(db: SupportSQLiteDatabase) {
|
||||
db.execSQL(
|
||||
"ALTER TABLE `BaseNote` ADD COLUMN `color` TEXT NOT NULL DEFAULT 'DEFAULT'"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
object Migration3 : Migration(2, 3) {
|
||||
|
||||
override fun migrate(db: SupportSQLiteDatabase) {
|
||||
db.execSQL("ALTER TABLE `BaseNote` ADD COLUMN `images` TEXT NOT NULL DEFAULT `[]`")
|
||||
}
|
||||
}
|
||||
|
||||
object Migration4 : Migration(3, 4) {
|
||||
|
||||
override fun migrate(db: SupportSQLiteDatabase) {
|
||||
db.execSQL("ALTER TABLE `BaseNote` ADD COLUMN `audios` TEXT NOT NULL DEFAULT `[]`")
|
||||
}
|
||||
}
|
||||
|
||||
object Migration5 : Migration(4, 5) {
|
||||
|
||||
override fun migrate(db: SupportSQLiteDatabase) {
|
||||
db.execSQL("ALTER TABLE `BaseNote` ADD COLUMN `files` TEXT NOT NULL DEFAULT `[]`")
|
||||
}
|
||||
}
|
||||
|
||||
object Migration6 : Migration(5, 6) {
|
||||
|
||||
override fun migrate(db: SupportSQLiteDatabase) {
|
||||
db.execSQL(
|
||||
"ALTER TABLE `BaseNote` ADD COLUMN `modifiedTimestamp` INTEGER NOT NULL DEFAULT 'timestamp'"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
object Migration7 : Migration(6, 7) {
|
||||
|
||||
override fun migrate(db: SupportSQLiteDatabase) {
|
||||
db.execSQL(
|
||||
"ALTER TABLE `BaseNote` ADD COLUMN `reminders` TEXT NOT NULL DEFAULT `[]`"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
object Migration8 : Migration(7, 8) {
|
||||
override fun migrate(db: SupportSQLiteDatabase) {
|
||||
val cursor = db.query("SELECT id, color FROM BaseNote")
|
||||
while (cursor.moveToNext()) {
|
||||
val id = cursor.getLong(cursor.getColumnIndexOrThrow("id"))
|
||||
val colorString = cursor.getString(cursor.getColumnIndexOrThrow("color"))
|
||||
val color = Color.valueOfOrDefault(colorString)
|
||||
val hexColor = color.toColorString()
|
||||
db.execSQL("UPDATE BaseNote SET color = ? WHERE id = ?", arrayOf(hexColor, id))
|
||||
}
|
||||
cursor.close()
|
||||
}
|
||||
}
|
||||
|
||||
object Migration9 : Migration(8, 9) {
|
||||
|
||||
override fun migrate(db: SupportSQLiteDatabase) {
|
||||
db.execSQL(
|
||||
"ALTER TABLE `BaseNote` ADD COLUMN `viewMode` TEXT NOT NULL DEFAULT '${NoteViewMode.EDIT.name}'"
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,243 +0,0 @@
|
|||
package com.philkes.notallyx.data.dao
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.map
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Insert
|
||||
import androidx.room.OnConflictStrategy
|
||||
import androidx.room.Query
|
||||
import androidx.room.RawQuery
|
||||
import androidx.room.Update
|
||||
import androidx.sqlite.db.SupportSQLiteQuery
|
||||
import com.philkes.notallyx.data.model.Audio
|
||||
import com.philkes.notallyx.data.model.BaseNote
|
||||
import com.philkes.notallyx.data.model.FileAttachment
|
||||
import com.philkes.notallyx.data.model.Folder
|
||||
import com.philkes.notallyx.data.model.LabelsInBaseNote
|
||||
import com.philkes.notallyx.data.model.ListItem
|
||||
import com.philkes.notallyx.data.model.Reminder
|
||||
import com.philkes.notallyx.data.model.Type
|
||||
|
||||
data class NoteIdReminder(val id: Long, val reminders: List<Reminder>)
|
||||
|
||||
data class NoteReminder(
|
||||
val id: Long,
|
||||
val title: String,
|
||||
val type: Type,
|
||||
val reminders: List<Reminder>,
|
||||
)
|
||||
|
||||
@Dao
|
||||
interface BaseNoteDao {
|
||||
|
||||
@RawQuery fun query(query: SupportSQLiteQuery): Int
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE) suspend fun insert(baseNote: BaseNote): Long
|
||||
|
||||
@Insert suspend fun insert(baseNotes: List<BaseNote>)
|
||||
|
||||
@Update(entity = BaseNote::class) suspend fun update(labelsInBaseNotes: List<LabelsInBaseNote>)
|
||||
|
||||
@Query("SELECT COUNT(*) FROM BaseNote") fun count(): Int
|
||||
|
||||
@Query("DELETE FROM BaseNote WHERE id = :id") suspend fun delete(id: Long)
|
||||
|
||||
@Query("DELETE FROM BaseNote WHERE id IN (:ids)") suspend fun delete(ids: LongArray)
|
||||
|
||||
@Query("DELETE FROM BaseNote WHERE folder = :folder") suspend fun deleteFrom(folder: Folder)
|
||||
|
||||
@Query("SELECT * FROM BaseNote WHERE folder = :folder ORDER BY pinned DESC, timestamp DESC")
|
||||
fun getFrom(folder: Folder): LiveData<List<BaseNote>>
|
||||
|
||||
@Query("SELECT * FROM BaseNote WHERE folder = 'NOTES' ORDER BY pinned DESC, timestamp DESC")
|
||||
suspend fun getAllNotes(): List<BaseNote>
|
||||
|
||||
@Query("SELECT * FROM BaseNote") fun getAllAsync(): LiveData<List<BaseNote>>
|
||||
|
||||
@Query("SELECT * FROM BaseNote") fun getAll(): List<BaseNote>
|
||||
|
||||
@Query("SELECT * FROM BaseNote WHERE id IN (:ids)") fun getByIds(ids: LongArray): List<BaseNote>
|
||||
|
||||
@Query("SELECT B.id FROM BaseNote B") fun getAllIds(): List<Long>
|
||||
|
||||
@Query("SELECT * FROM BaseNote WHERE id = :id") fun get(id: Long): BaseNote?
|
||||
|
||||
@Query("SELECT images FROM BaseNote WHERE id = :id") fun getImages(id: Long): String
|
||||
|
||||
@Query("SELECT images FROM BaseNote") fun getAllImages(): List<String>
|
||||
|
||||
@Query("SELECT files FROM BaseNote") fun getAllFiles(): List<String>
|
||||
|
||||
@Query("SELECT audios FROM BaseNote") fun getAllAudios(): List<String>
|
||||
|
||||
@Query("SELECT id, reminders FROM BaseNote WHERE reminders IS NOT NULL AND reminders != '[]'")
|
||||
suspend fun getAllReminders(): List<NoteIdReminder>
|
||||
|
||||
@Query("SELECT color FROM BaseNote WHERE id = :id ") fun getColorOfNote(id: Long): String
|
||||
|
||||
@Query(
|
||||
"SELECT id, title, type, reminders FROM BaseNote WHERE reminders IS NOT NULL AND reminders != '[]'"
|
||||
)
|
||||
fun getAllRemindersAsync(): LiveData<List<NoteReminder>>
|
||||
|
||||
@Query("SELECT id FROM BaseNote WHERE folder = 'DELETED'")
|
||||
suspend fun getDeletedNoteIds(): LongArray
|
||||
|
||||
@Query("SELECT images FROM BaseNote WHERE folder = 'DELETED'")
|
||||
suspend fun getDeletedNoteImages(): List<String>
|
||||
|
||||
@Query("SELECT files FROM BaseNote WHERE folder = 'DELETED'")
|
||||
suspend fun getDeletedNoteFiles(): List<String>
|
||||
|
||||
@Query("SELECT audios FROM BaseNote WHERE folder = 'DELETED'")
|
||||
suspend fun getDeletedNoteAudios(): List<String>
|
||||
|
||||
@Query("UPDATE BaseNote SET folder = :folder WHERE id IN (:ids)")
|
||||
suspend fun move(ids: LongArray, folder: Folder)
|
||||
|
||||
@Query("SELECT DISTINCT color FROM BaseNote") fun getAllColorsAsync(): LiveData<List<String>>
|
||||
|
||||
@Query("SELECT DISTINCT color FROM BaseNote") suspend fun getAllColors(): List<String>
|
||||
|
||||
@Query("UPDATE BaseNote SET color = :color WHERE id IN (:ids)")
|
||||
suspend fun updateColor(ids: LongArray, color: String)
|
||||
|
||||
@Query("UPDATE BaseNote SET color = :newColor WHERE color = :oldColor")
|
||||
suspend fun updateColor(oldColor: String, newColor: String)
|
||||
|
||||
@Query("UPDATE BaseNote SET pinned = :pinned WHERE id IN (:ids)")
|
||||
suspend fun updatePinned(ids: LongArray, pinned: Boolean)
|
||||
|
||||
@Query("UPDATE BaseNote SET labels = :labels WHERE id = :id")
|
||||
suspend fun updateLabels(id: Long, labels: List<String>)
|
||||
|
||||
@Query("UPDATE BaseNote SET labels = :labels WHERE id IN (:ids)")
|
||||
suspend fun updateLabels(ids: LongArray, labels: List<String>)
|
||||
|
||||
@Query("UPDATE BaseNote SET items = :items WHERE id = :id")
|
||||
suspend fun updateItems(id: Long, items: List<ListItem>)
|
||||
|
||||
@Query("UPDATE BaseNote SET images = :images WHERE id = :id")
|
||||
suspend fun updateImages(id: Long, images: List<FileAttachment>)
|
||||
|
||||
@Query("UPDATE BaseNote SET files = :files WHERE id = :id")
|
||||
suspend fun updateFiles(id: Long, files: List<FileAttachment>)
|
||||
|
||||
@Query("UPDATE BaseNote SET audios = :audios WHERE id = :id")
|
||||
suspend fun updateAudios(id: Long, audios: List<Audio>)
|
||||
|
||||
@Query("UPDATE BaseNote SET reminders = :reminders WHERE id = :id")
|
||||
suspend fun updateReminders(id: Long, reminders: List<Reminder>)
|
||||
|
||||
/**
|
||||
* Both id and position can be invalid.
|
||||
*
|
||||
* Example of id being invalid - User adds a widget, then goes to Settings and clears app data.
|
||||
* Now the widget refers to a list which doesn't exist.
|
||||
*
|
||||
* Example of position being invalid - User adds a widget, goes to Settings, clears app data and
|
||||
* then imports a backup. Even if the backup contains the same list and it is inserted with the
|
||||
* same id, it may not be of the safe size.
|
||||
*
|
||||
* In this case, an exception will be thrown. It is the caller's responsibility to handle it.
|
||||
*/
|
||||
suspend fun updateChecked(id: Long, position: Int, checked: Boolean) {
|
||||
val items = requireNotNull(get(id)).items
|
||||
items[position].checked = checked
|
||||
updateItems(id, items)
|
||||
}
|
||||
|
||||
/** see [updateChecked] */
|
||||
suspend fun updateChecked(id: Long, positions: List<Int>, checked: Boolean) {
|
||||
val items = requireNotNull(get(id)).items
|
||||
positions.forEach { position -> items[position].checked = checked }
|
||||
updateItems(id, items)
|
||||
}
|
||||
|
||||
/**
|
||||
* Since we store the labels as a JSON Array, it is not possible to perform operations on it.
|
||||
* Thus, we use the 'Like' query which can return false positives sometimes.
|
||||
*
|
||||
* For example, a request for all base notes having the label 'Important' will also return base
|
||||
* notes with the label 'Unimportant'. To prevent this, we use the extension function `map`
|
||||
* directly on the LiveData to filter the results accordingly.
|
||||
*/
|
||||
fun getBaseNotesByLabel(label: String): LiveData<List<BaseNote>> {
|
||||
val result = getBaseNotesByLabel(label, setOf(Folder.NOTES, Folder.ARCHIVED))
|
||||
return result.map { list -> list.filter { baseNote -> baseNote.labels.contains(label) } }
|
||||
}
|
||||
|
||||
@Query(
|
||||
"SELECT * FROM BaseNote WHERE folder IN (:folders) AND labels LIKE '%' || :label || '%' ORDER BY folder DESC, pinned DESC, timestamp DESC"
|
||||
)
|
||||
fun getBaseNotesByLabel(label: String, folders: Collection<Folder>): LiveData<List<BaseNote>>
|
||||
|
||||
@Query(
|
||||
"SELECT * FROM BaseNote WHERE folder = :folder AND labels == '[]' ORDER BY pinned DESC, timestamp DESC"
|
||||
)
|
||||
fun getBaseNotesWithoutLabel(folder: Folder): LiveData<List<BaseNote>>
|
||||
|
||||
suspend fun getListOfBaseNotesByLabel(label: String): List<BaseNote> {
|
||||
val result = getListOfBaseNotesByLabelImpl(label)
|
||||
return result.filter { baseNote -> baseNote.labels.contains(label) }
|
||||
}
|
||||
|
||||
@Query("SELECT * FROM BaseNote WHERE labels LIKE '%' || :label || '%'")
|
||||
suspend fun getListOfBaseNotesByLabelImpl(label: String): List<BaseNote>
|
||||
|
||||
fun getBaseNotesByKeyword(
|
||||
keyword: String,
|
||||
folder: Folder,
|
||||
label: String?,
|
||||
): LiveData<List<BaseNote>> {
|
||||
val result =
|
||||
when (label) {
|
||||
null -> getBaseNotesByKeywordUnlabeledImpl(keyword, folder)
|
||||
"" -> getBaseNotesByKeywordImpl(keyword, folder)
|
||||
else -> getBaseNotesByKeywordImpl(keyword, folder, label)
|
||||
}
|
||||
return result.map { list -> list.filter { baseNote -> matchesKeyword(baseNote, keyword) } }
|
||||
}
|
||||
|
||||
@Query(
|
||||
"SELECT * FROM BaseNote WHERE folder = :folder AND labels LIKE '%' || :label || '%' AND (title LIKE '%' || :keyword || '%' OR body LIKE '%' || :keyword || '%' OR items LIKE '%' || :keyword || '%') ORDER BY pinned DESC, timestamp DESC"
|
||||
)
|
||||
fun getBaseNotesByKeywordImpl(
|
||||
keyword: String,
|
||||
folder: Folder,
|
||||
label: String,
|
||||
): LiveData<List<BaseNote>>
|
||||
|
||||
@Query(
|
||||
"SELECT * FROM BaseNote WHERE folder = :folder AND (title LIKE '%' || :keyword || '%' OR body LIKE '%' || :keyword || '%' OR items LIKE '%' || :keyword || '%' OR labels LIKE '%' || :keyword || '%') ORDER BY pinned DESC, timestamp DESC"
|
||||
)
|
||||
fun getBaseNotesByKeywordImpl(keyword: String, folder: Folder): LiveData<List<BaseNote>>
|
||||
|
||||
@Query(
|
||||
"SELECT * FROM BaseNote WHERE folder = :folder AND labels == '[]' AND (title LIKE '%' || :keyword || '%' OR body LIKE '%' || :keyword || '%' OR items LIKE '%' || :keyword || '%') ORDER BY pinned DESC, timestamp DESC"
|
||||
)
|
||||
fun getBaseNotesByKeywordUnlabeledImpl(
|
||||
keyword: String,
|
||||
folder: Folder,
|
||||
): LiveData<List<BaseNote>>
|
||||
|
||||
private fun matchesKeyword(baseNote: BaseNote, keyword: String): Boolean {
|
||||
if (baseNote.title.contains(keyword, true)) {
|
||||
return true
|
||||
}
|
||||
if (baseNote.body.contains(keyword, true)) {
|
||||
return true
|
||||
}
|
||||
for (label in baseNote.labels) {
|
||||
if (label.contains(keyword, true)) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
for (item in baseNote.items) {
|
||||
if (item.body.contains(keyword, true)) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
|
@ -1,43 +0,0 @@
|
|||
package com.philkes.notallyx.data.dao
|
||||
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Transaction
|
||||
import com.philkes.notallyx.data.NotallyDatabase
|
||||
import com.philkes.notallyx.data.model.BaseNote
|
||||
import com.philkes.notallyx.data.model.Label
|
||||
import com.philkes.notallyx.data.model.LabelsInBaseNote
|
||||
|
||||
@Dao
|
||||
abstract class CommonDao(private val database: NotallyDatabase) {
|
||||
|
||||
@Transaction
|
||||
open suspend fun deleteLabel(value: String) {
|
||||
val labelsInBaseNotes =
|
||||
database.getBaseNoteDao().getListOfBaseNotesByLabel(value).map { baseNote ->
|
||||
val labels = ArrayList(baseNote.labels)
|
||||
labels.remove(value)
|
||||
LabelsInBaseNote(baseNote.id, labels)
|
||||
}
|
||||
database.getBaseNoteDao().update(labelsInBaseNotes)
|
||||
database.getLabelDao().delete(value)
|
||||
}
|
||||
|
||||
@Transaction
|
||||
open suspend fun updateLabel(oldValue: String, newValue: String) {
|
||||
val labelsInBaseNotes =
|
||||
database.getBaseNoteDao().getListOfBaseNotesByLabel(oldValue).map { baseNote ->
|
||||
val labels = ArrayList(baseNote.labels)
|
||||
labels.remove(oldValue)
|
||||
labels.add(newValue)
|
||||
LabelsInBaseNote(baseNote.id, labels)
|
||||
}
|
||||
database.getBaseNoteDao().update(labelsInBaseNotes)
|
||||
database.getLabelDao().update(oldValue, newValue)
|
||||
}
|
||||
|
||||
@Transaction
|
||||
open suspend fun importBackup(baseNotes: List<BaseNote>, labels: List<Label>) {
|
||||
database.getBaseNoteDao().insert(baseNotes)
|
||||
database.getLabelDao().insert(labels)
|
||||
}
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
package com.philkes.notallyx.data.dao
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Insert
|
||||
import androidx.room.OnConflictStrategy
|
||||
import androidx.room.Query
|
||||
import com.philkes.notallyx.data.model.Label
|
||||
|
||||
@Dao
|
||||
interface LabelDao {
|
||||
|
||||
@Insert suspend fun insert(label: Label)
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.IGNORE) suspend fun insert(labels: List<Label>)
|
||||
|
||||
@Query("DELETE FROM Label WHERE value = :value") suspend fun delete(value: String)
|
||||
|
||||
@Query("DELETE FROM Label") suspend fun deleteAll()
|
||||
|
||||
@Query("UPDATE Label SET value = :newValue WHERE value = :oldValue")
|
||||
suspend fun update(oldValue: String, newValue: String)
|
||||
|
||||
@Query("SELECT value FROM Label ORDER BY value") fun getAll(): LiveData<List<String>>
|
||||
|
||||
@Query("SELECT value FROM Label ORDER BY value") suspend fun getArrayOfAll(): Array<String>
|
||||
|
||||
@Query("SELECT EXISTS(SELECT 1 FROM Label WHERE value = :value)")
|
||||
suspend fun exists(value: String): Boolean
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
package com.philkes.notallyx.data.imports
|
||||
|
||||
import android.app.Application
|
||||
import android.net.Uri
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import com.philkes.notallyx.data.model.BaseNote
|
||||
import java.io.File
|
||||
|
||||
interface ExternalImporter {
|
||||
|
||||
/**
|
||||
* Parses [BaseNote]s from [source] and copies attached files/images/audios to [destination]
|
||||
*
|
||||
* @return List of [BaseNote]s to import + folder containing attached files (if no attached
|
||||
* files possible, return null).
|
||||
*/
|
||||
fun import(
|
||||
app: Application,
|
||||
source: Uri,
|
||||
destination: File,
|
||||
progress: MutableLiveData<ImportProgress>? = null,
|
||||
): Pair<List<BaseNote>, File?>
|
||||
}
|
|
@ -1,213 +0,0 @@
|
|||
package com.philkes.notallyx.data.imports
|
||||
|
||||
import androidx.core.util.PatternsCompat
|
||||
import com.philkes.notallyx.data.model.SpanRepresentation
|
||||
import org.jsoup.Jsoup
|
||||
import org.jsoup.nodes.Document
|
||||
import org.jsoup.nodes.Element
|
||||
import org.jsoup.nodes.TextNode
|
||||
|
||||
/**
|
||||
* Tries to parse the plain body text from the text as well as parse all text formatting into
|
||||
* [SpanRepresentation]s
|
||||
*/
|
||||
fun parseBodyAndSpansFromHtml(
|
||||
html: String,
|
||||
rootTag: String = "body",
|
||||
useInnermostRootTag: Boolean = false,
|
||||
brTagsAsNewLine: Boolean = true,
|
||||
paragraphsAsNewLine: Boolean = false,
|
||||
): Pair<String, MutableList<SpanRepresentation>> {
|
||||
val document: Document = Jsoup.parse(html)
|
||||
val rootNoteElement = document.body().getElementsByTag(rootTag)
|
||||
if (rootNoteElement.isEmpty()) {
|
||||
return Pair("", mutableListOf())
|
||||
}
|
||||
val rootElement =
|
||||
if (useInnermostRootTag) rootNoteElement.last()!! else rootNoteElement.first()!!
|
||||
val bodyText = StringBuilder()
|
||||
val spans = mutableListOf<SpanRepresentation>()
|
||||
processElement(
|
||||
rootElement,
|
||||
bodyText,
|
||||
spans,
|
||||
brTagsAsNewLine = brTagsAsNewLine,
|
||||
paragraphsAsNewLine = paragraphsAsNewLine,
|
||||
)
|
||||
return Pair(bodyText.trimEnd().toString(), spans)
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds plain text to [bodyText] and adds [SpanRepresentation]s:
|
||||
* - `<b>` or `font-weight`>`400` -> [SpanRepresentation.bold]
|
||||
* - `<i>` or `font-style:italic` -> [SpanRepresentation.italic]
|
||||
* - `<s>` -> [SpanRepresentation.strikethrough]
|
||||
* - `<a>` or text starting with `http` -> [SpanRepresentation.link]
|
||||
* - `<span>` with `font-family` includes `monospace` or `Source Code Pro` ->
|
||||
* [SpanRepresentation.monospace]
|
||||
*/
|
||||
private fun processElement(
|
||||
element: Element,
|
||||
bodyText: StringBuilder,
|
||||
spans: MutableList<SpanRepresentation>,
|
||||
brTagsAsNewLine: Boolean,
|
||||
paragraphsAsNewLine: Boolean,
|
||||
) {
|
||||
|
||||
for (child in element.childNodes()) {
|
||||
when (child) {
|
||||
is TextNode -> {
|
||||
// If the child is a text node, append its text and update the offset
|
||||
val text = child.text()
|
||||
if (text != " ") {
|
||||
bodyText.appendWithUrlCheck(text, spans)
|
||||
}
|
||||
}
|
||||
|
||||
is Element -> {
|
||||
when (child.tagName()) {
|
||||
"b" -> {
|
||||
handleTextSpan(child, bodyText, spans, bold = true)
|
||||
}
|
||||
|
||||
"i" -> {
|
||||
handleTextSpan(child, bodyText, spans, italic = true)
|
||||
}
|
||||
|
||||
"s" -> {
|
||||
handleTextSpan(child, bodyText, spans, strikethrough = true)
|
||||
}
|
||||
|
||||
"span" -> {
|
||||
handleTextSpan(
|
||||
child,
|
||||
bodyText,
|
||||
spans,
|
||||
monospace = child.isMonospaceFont(),
|
||||
bold = child.isBold(),
|
||||
italic = child.isItalic(),
|
||||
)
|
||||
}
|
||||
|
||||
"a" -> {
|
||||
handleTextSpan(
|
||||
child,
|
||||
bodyText,
|
||||
spans,
|
||||
link = true,
|
||||
linkData = child.attr("href"),
|
||||
)
|
||||
}
|
||||
|
||||
"div" -> {
|
||||
// div always means new-line, except for first
|
||||
if (bodyText.isNotEmpty()) {
|
||||
bodyText.append("\n")
|
||||
}
|
||||
processElement(
|
||||
child,
|
||||
bodyText,
|
||||
spans,
|
||||
brTagsAsNewLine = brTagsAsNewLine,
|
||||
paragraphsAsNewLine = paragraphsAsNewLine,
|
||||
)
|
||||
}
|
||||
|
||||
"br" -> {
|
||||
if (brTagsAsNewLine) {
|
||||
bodyText.append("\n")
|
||||
}
|
||||
}
|
||||
|
||||
else -> {
|
||||
processElement(child, bodyText, spans, brTagsAsNewLine, paragraphsAsNewLine)
|
||||
if (
|
||||
paragraphsAsNewLine &&
|
||||
(child.tagName().startsWith("h") || child.tagName() == "p")
|
||||
) {
|
||||
bodyText.append("\n")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun handleTextSpan(
|
||||
element: Element,
|
||||
bodyText: StringBuilder,
|
||||
spans: MutableList<SpanRepresentation>,
|
||||
bold: Boolean = false,
|
||||
italic: Boolean = false,
|
||||
link: Boolean = false,
|
||||
linkData: String? = null,
|
||||
strikethrough: Boolean = false,
|
||||
monospace: Boolean = false,
|
||||
) {
|
||||
val text = element.ownText()
|
||||
if (bold || italic || link || strikethrough || monospace) {
|
||||
val spanStart = bodyText.length
|
||||
spans.add(
|
||||
SpanRepresentation(
|
||||
start = spanStart,
|
||||
end = spanStart + text.length,
|
||||
bold = bold,
|
||||
link = link,
|
||||
linkData = linkData,
|
||||
italic = italic,
|
||||
monospace = monospace,
|
||||
strikethrough = strikethrough,
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
if (link) {
|
||||
bodyText.append(text)
|
||||
} else {
|
||||
bodyText.appendWithUrlCheck(text, spans)
|
||||
}
|
||||
}
|
||||
|
||||
private fun StringBuilder.appendWithUrlCheck(text: String, spans: MutableList<SpanRepresentation>) {
|
||||
checkForUrlSpan(text, spans, length)
|
||||
append(text)
|
||||
}
|
||||
|
||||
private fun checkForUrlSpan(
|
||||
text: String,
|
||||
spans: MutableList<SpanRepresentation>,
|
||||
elementOffset: Int,
|
||||
) {
|
||||
val matcher = PatternsCompat.WEB_URL.matcher(text)
|
||||
if (matcher.find() && matcher.group().startsWith("http")) {
|
||||
val url = matcher.group()
|
||||
spans.add(
|
||||
SpanRepresentation(
|
||||
start = elementOffset + matcher.start(),
|
||||
end = elementOffset + matcher.end(),
|
||||
link = true,
|
||||
linkData = url,
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun Element.isMonospaceFont(): Boolean {
|
||||
val fontFamily = attr("style")
|
||||
return fontFamily.contains("monospace", ignoreCase = true) ||
|
||||
fontFamily.contains("Source Code Pro", ignoreCase = true)
|
||||
}
|
||||
|
||||
private fun Element.isBold(): Boolean {
|
||||
val style = attr("style")
|
||||
return if (style.contains("font-weight")) {
|
||||
val fontWeight: String = style.split("font-weight:")[1].split(";")[0].trim()
|
||||
return fontWeight.toInt() > 400 // Google Keep normal text has fontWeight 400
|
||||
} else false
|
||||
}
|
||||
|
||||
private fun Element.isItalic(): Boolean {
|
||||
val style = attr("style")
|
||||
return style.contains("font-style:italic")
|
||||
}
|
|
@ -1,3 +0,0 @@
|
|||
package com.philkes.notallyx.data.imports
|
||||
|
||||
class ImportException(val textResId: Int, cause: Throwable) : RuntimeException(cause)
|
|
@ -1,17 +0,0 @@
|
|||
package com.philkes.notallyx.data.imports
|
||||
|
||||
import com.philkes.notallyx.presentation.view.misc.Progress
|
||||
|
||||
open class ImportProgress(
|
||||
current: Int = 0,
|
||||
total: Int = 0,
|
||||
inProgress: Boolean = true,
|
||||
indeterminate: Boolean = false,
|
||||
val stage: ImportStage = ImportStage.IMPORT_NOTES,
|
||||
) : Progress(current, total, inProgress, indeterminate)
|
||||
|
||||
enum class ImportStage {
|
||||
IMPORT_NOTES,
|
||||
EXTRACT_FILES,
|
||||
IMPORT_FILES,
|
||||
}
|
|
@ -1,167 +0,0 @@
|
|||
package com.philkes.notallyx.data.imports
|
||||
|
||||
import android.app.Application
|
||||
import android.net.Uri
|
||||
import android.util.Log
|
||||
import androidx.core.net.toUri
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import com.philkes.notallyx.R
|
||||
import com.philkes.notallyx.data.NotallyDatabase
|
||||
import com.philkes.notallyx.data.imports.evernote.EvernoteImporter
|
||||
import com.philkes.notallyx.data.imports.google.GoogleKeepImporter
|
||||
import com.philkes.notallyx.data.imports.txt.JsonImporter
|
||||
import com.philkes.notallyx.data.imports.txt.PlainTextImporter
|
||||
import com.philkes.notallyx.data.model.Audio
|
||||
import com.philkes.notallyx.data.model.FileAttachment
|
||||
import com.philkes.notallyx.data.model.Label
|
||||
import com.philkes.notallyx.presentation.viewmodel.NotallyModel
|
||||
import com.philkes.notallyx.utils.MIME_TYPE_ZIP
|
||||
import com.philkes.notallyx.utils.backup.importAudio
|
||||
import com.philkes.notallyx.utils.backup.importFile
|
||||
import com.philkes.notallyx.utils.backup.importImage
|
||||
import java.io.File
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
|
||||
class NotesImporter(private val app: Application, private val database: NotallyDatabase) {
|
||||
|
||||
suspend fun import(
|
||||
uri: Uri,
|
||||
importSource: ImportSource,
|
||||
progress: MutableLiveData<ImportProgress>? = null,
|
||||
): Int {
|
||||
val tempDir = File(app.cacheDir, IMPORT_CACHE_FOLDER)
|
||||
if (!tempDir.exists()) {
|
||||
tempDir.mkdirs()
|
||||
}
|
||||
try {
|
||||
val (notes, importDataFolder) =
|
||||
try {
|
||||
when (importSource) {
|
||||
ImportSource.GOOGLE_KEEP -> GoogleKeepImporter()
|
||||
ImportSource.EVERNOTE -> EvernoteImporter()
|
||||
ImportSource.PLAIN_TEXT -> PlainTextImporter()
|
||||
ImportSource.JSON -> JsonImporter()
|
||||
}.import(app, uri, tempDir, progress)
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "import: failed", e)
|
||||
progress?.postValue(ImportProgress(inProgress = false))
|
||||
throw e
|
||||
}
|
||||
database.getLabelDao().insert(notes.flatMap { it.labels }.distinct().map { Label(it) })
|
||||
val files = notes.flatMap { it.files }.distinct()
|
||||
val images = notes.flatMap { it.images }.distinct()
|
||||
val audios = notes.flatMap { it.audios }.distinct()
|
||||
val totalFiles = files.size + images.size + audios.size
|
||||
val counter = AtomicInteger(1)
|
||||
progress?.postValue(
|
||||
ImportProgress(total = totalFiles, stage = ImportStage.IMPORT_FILES)
|
||||
)
|
||||
importDataFolder?.let {
|
||||
importFiles(files, it, NotallyModel.FileType.ANY, progress, totalFiles, counter)
|
||||
importFiles(images, it, NotallyModel.FileType.IMAGE, progress, totalFiles, counter)
|
||||
importAudios(audios, it, progress, totalFiles, counter)
|
||||
}
|
||||
database.getBaseNoteDao().insert(notes)
|
||||
progress?.postValue(ImportProgress(inProgress = false))
|
||||
return notes.size
|
||||
} finally {
|
||||
tempDir.deleteRecursively()
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun importFiles(
|
||||
files: List<FileAttachment>,
|
||||
sourceFolder: File,
|
||||
fileType: NotallyModel.FileType,
|
||||
progress: MutableLiveData<ImportProgress>?,
|
||||
total: Int?,
|
||||
counter: AtomicInteger?,
|
||||
) {
|
||||
files.forEach { file ->
|
||||
val uri = File(sourceFolder, file.localName).toUri()
|
||||
val (fileAttachment, error) =
|
||||
if (fileType == NotallyModel.FileType.IMAGE) app.importImage(uri, file.mimeType)
|
||||
else app.importFile(uri, file.mimeType)
|
||||
fileAttachment?.let {
|
||||
file.localName = fileAttachment.localName
|
||||
file.originalName = fileAttachment.originalName
|
||||
file.mimeType = fileAttachment.mimeType
|
||||
}
|
||||
error?.let { Log.e(TAG, "Failed to import: $error") }
|
||||
progress?.postValue(
|
||||
ImportProgress(
|
||||
current = counter!!.getAndIncrement(),
|
||||
total = total!!,
|
||||
stage = ImportStage.IMPORT_FILES,
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun importAudios(
|
||||
audios: List<Audio>,
|
||||
sourceFolder: File,
|
||||
progress: MutableLiveData<ImportProgress>?,
|
||||
totalFiles: Int,
|
||||
counter: AtomicInteger,
|
||||
) {
|
||||
audios.forEach { originalAudio ->
|
||||
val file = File(sourceFolder, originalAudio.name)
|
||||
val audio = app.importAudio(file, false)
|
||||
originalAudio.name = audio.name
|
||||
originalAudio.duration = if (audio.duration == 0L) null else audio.duration
|
||||
originalAudio.timestamp = audio.timestamp
|
||||
progress?.postValue(
|
||||
ImportProgress(
|
||||
current = counter.getAndIncrement(),
|
||||
total = totalFiles,
|
||||
stage = ImportStage.IMPORT_FILES,
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val TAG = "NotesImporter"
|
||||
const val IMPORT_CACHE_FOLDER = "imports"
|
||||
}
|
||||
}
|
||||
|
||||
enum class ImportSource(
|
||||
val displayNameResId: Int,
|
||||
val mimeType: String,
|
||||
val helpTextResId: Int,
|
||||
val documentationUrl: String?,
|
||||
val iconResId: Int,
|
||||
) {
|
||||
GOOGLE_KEEP(
|
||||
R.string.google_keep,
|
||||
MIME_TYPE_ZIP,
|
||||
R.string.google_keep_help,
|
||||
"https://support.google.com/keep/answer/10017039",
|
||||
R.drawable.icon_google_keep,
|
||||
),
|
||||
EVERNOTE(
|
||||
R.string.evernote,
|
||||
"*/*", // 'application/enex+xml' is not recognized
|
||||
R.string.evernote_help,
|
||||
"https://help.evernote.com/hc/en-us/articles/209005557-Export-notes-and-notebooks-as-ENEX-or-HTML",
|
||||
R.drawable.icon_evernote,
|
||||
),
|
||||
PLAIN_TEXT(
|
||||
R.string.plain_text_files,
|
||||
FOLDER_OR_FILE_MIMETYPE,
|
||||
R.string.plain_text_files_help,
|
||||
null,
|
||||
R.drawable.text_file,
|
||||
),
|
||||
JSON(
|
||||
R.string.json_files,
|
||||
FOLDER_OR_FILE_MIMETYPE,
|
||||
R.string.json_files_help,
|
||||
null,
|
||||
R.drawable.file_json,
|
||||
),
|
||||
}
|
||||
|
||||
const val FOLDER_OR_FILE_MIMETYPE = "FOLDER_OR_FILE"
|
|
@ -1,168 +0,0 @@
|
|||
package com.philkes.notallyx.data.imports.evernote
|
||||
|
||||
import org.simpleframework.xml.Attribute
|
||||
import org.simpleframework.xml.Element
|
||||
import org.simpleframework.xml.ElementList
|
||||
import org.simpleframework.xml.Root
|
||||
import org.simpleframework.xml.Text
|
||||
import org.simpleframework.xml.convert.Convert
|
||||
import org.simpleframework.xml.convert.Converter
|
||||
import org.simpleframework.xml.stream.InputNode
|
||||
import org.simpleframework.xml.stream.OutputNode
|
||||
|
||||
@Root(name = "en-export", strict = false)
|
||||
data class EvernoteExport
|
||||
@JvmOverloads
|
||||
constructor(
|
||||
@field:Attribute(name = "export-date", required = false)
|
||||
@param:Attribute(name = "export-date", required = false)
|
||||
val exportDate: String = "",
|
||||
// @field:Attribute(name = "application", required = false)
|
||||
// @param:Attribute(name = "application", required = false)
|
||||
// val application: String = "",
|
||||
// @field:Attribute(name = "version", required = false)
|
||||
// @param:Attribute(name = "version", required = false)
|
||||
// val version: String = "",
|
||||
@field:ElementList(name = "note", inline = true)
|
||||
@param:ElementList(name = "note", inline = true)
|
||||
val notes: List<EvernoteNote> = listOf(),
|
||||
)
|
||||
|
||||
@Root(name = "note", strict = false)
|
||||
data class EvernoteNote
|
||||
@JvmOverloads
|
||||
constructor(
|
||||
@field:Element(name = "title") @param:Element(name = "title") val title: String = "",
|
||||
@field:Element(name = "created") @param:Element(name = "created") val created: String = "",
|
||||
@field:Element(name = "updated") @param:Element(name = "updated") val updated: String = "",
|
||||
@field:ElementList(name = "tag", inline = true, required = false, empty = false)
|
||||
@param:ElementList(name = "tag", inline = true, required = false, empty = false)
|
||||
var tag: List<EvernoteTag> = listOf(),
|
||||
@field:Element(name = "content", data = true)
|
||||
@param:Element(name = "content", data = true)
|
||||
val content: String = "",
|
||||
@field:ElementList(name = "resource", inline = true, required = false, empty = false)
|
||||
@param:ElementList(name = "resource", inline = true, required = false, empty = false)
|
||||
val resources: List<EvernoteResource> = listOf(),
|
||||
@field:ElementList(name = "task", inline = true, required = false, empty = false)
|
||||
@param:ElementList(name = "task", inline = true, required = false, empty = false)
|
||||
val tasks: List<EvernoteTask> = listOf(),
|
||||
)
|
||||
|
||||
@Root(name = "tag", strict = false)
|
||||
data class EvernoteTag
|
||||
@JvmOverloads
|
||||
constructor(@field:Text(required = false) @param:Text(required = false) val name: String = "")
|
||||
|
||||
@Root(name = "resource", strict = false)
|
||||
data class EvernoteResource
|
||||
@JvmOverloads
|
||||
constructor(
|
||||
@field:Element(name = "data", required = false)
|
||||
@param:Element(name = "data", required = false)
|
||||
val data: EvernoteResourceData? = null,
|
||||
@field:Element(name = "mime", required = false)
|
||||
@param:Element(name = "mime", required = false)
|
||||
val mime: String = "*/*",
|
||||
@field:Element(name = "width", required = false)
|
||||
@param:Element(name = "width", required = false)
|
||||
val width: Int? = null,
|
||||
@field:Element(name = "height", required = false)
|
||||
@param:Element(name = "height", required = false)
|
||||
val height: Int? = null,
|
||||
@field:Element(name = "resource-attributes", required = false)
|
||||
@param:Element(name = "resource-attributes", required = false)
|
||||
val attributes: EvernoteResourceAttributes? = null,
|
||||
)
|
||||
|
||||
@Root(name = "data", strict = false)
|
||||
data class EvernoteResourceData
|
||||
@JvmOverloads
|
||||
constructor(
|
||||
@field:Attribute(name = "encoding", required = false)
|
||||
@param:Attribute(name = "encoding", required = false)
|
||||
val encoding: String = "base64",
|
||||
@field:Text(required = false) @param:Text(required = false) val content: String = "",
|
||||
)
|
||||
|
||||
@Root(name = "resource-attributes", strict = false)
|
||||
data class EvernoteResourceAttributes
|
||||
@JvmOverloads
|
||||
constructor(
|
||||
@field:Element(name = "file-name", required = false)
|
||||
@param:Element(name = "file-name", required = false)
|
||||
val fileName: String = ""
|
||||
|
||||
// @field:Element(name = "source-url", required = false)
|
||||
// @param:Element(name = "source-url", required = false)
|
||||
// val sourceUrl: String= ""
|
||||
)
|
||||
|
||||
@Root(name = "task", strict = false)
|
||||
data class EvernoteTask
|
||||
@JvmOverloads
|
||||
constructor(
|
||||
@field:Element(name = "title", required = false)
|
||||
@param:Element(name = "title", required = false)
|
||||
val title: String = "",
|
||||
//
|
||||
// @field:Element(name = "created") @param:Element(name = "created")
|
||||
// val created: String = "",
|
||||
//
|
||||
// @field:Element(name = "updated") @param:Element(name = "updated")
|
||||
// val updated: String = "",
|
||||
//
|
||||
@field:Element(name = "taskStatus", required = false)
|
||||
@param:Element(name = "taskStatus", required = false)
|
||||
@field:Convert(TaskStatusConverter::class)
|
||||
@param:Convert(TaskStatusConverter::class)
|
||||
val taskStatus: TaskStatus = TaskStatus.OPEN,
|
||||
//
|
||||
// @field:Element(name = "taskFlag") @param:Element(name = "taskFlag")
|
||||
// val taskFlag: Boolean = false,
|
||||
//
|
||||
@field:Element(name = "sortWeight", required = false)
|
||||
@param:Element(name = "sortWeight", required = false)
|
||||
val sortWeight: String = "",
|
||||
//
|
||||
// @field:Element(name = "noteLevelID") @param:Element(name = "noteLevelID")
|
||||
// val noteLevelID: String = "",
|
||||
//
|
||||
// @field:Element(name = "taskGroupNoteLevelID") @param:Element(name =
|
||||
// "taskGroupNoteLevelID")
|
||||
// val taskGroupNoteLevelID: String = "",
|
||||
//
|
||||
// @field:Element(name = "dueDate") @param:Element(name = "dueDate")
|
||||
// val dueDate: String = "",
|
||||
//
|
||||
// @field:Element(name = "statusUpdated") @param:Element(name = "statusUpdated")
|
||||
// val statusUpdated: String = "",
|
||||
//
|
||||
// @field:Element(name = "creator") @param:Element(name = "creator")
|
||||
// val creator: String = "",
|
||||
//
|
||||
// @field:Element(name = "lastEditor") @param:Element(name = "lastEditor")
|
||||
// val lastEditor: String = ""
|
||||
)
|
||||
|
||||
enum class TaskStatus(val status: String) {
|
||||
OPEN("open"),
|
||||
COMPLETED("completed");
|
||||
|
||||
companion object {
|
||||
fun fromString(value: String): TaskStatus? {
|
||||
return entries.find { it.status == value }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class TaskStatusConverter : Converter<TaskStatus> {
|
||||
override fun read(node: InputNode): TaskStatus? {
|
||||
val value = node.value ?: return null
|
||||
return TaskStatus.fromString(value)
|
||||
}
|
||||
|
||||
override fun write(node: OutputNode, value: TaskStatus?) {
|
||||
node.value = value?.status
|
||||
}
|
||||
}
|
|
@ -1,190 +0,0 @@
|
|||
package com.philkes.notallyx.data.imports.evernote
|
||||
|
||||
import android.app.Application
|
||||
import android.net.Uri
|
||||
import android.util.Base64
|
||||
import android.webkit.MimeTypeMap
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import com.philkes.notallyx.R
|
||||
import com.philkes.notallyx.data.imports.ExternalImporter
|
||||
import com.philkes.notallyx.data.imports.ImportException
|
||||
import com.philkes.notallyx.data.imports.ImportProgress
|
||||
import com.philkes.notallyx.data.imports.ImportStage
|
||||
import com.philkes.notallyx.data.imports.evernote.EvernoteImporter.Companion.parseTimestamp
|
||||
import com.philkes.notallyx.data.imports.parseBodyAndSpansFromHtml
|
||||
import com.philkes.notallyx.data.model.Audio
|
||||
import com.philkes.notallyx.data.model.BaseNote
|
||||
import com.philkes.notallyx.data.model.FileAttachment
|
||||
import com.philkes.notallyx.data.model.Folder
|
||||
import com.philkes.notallyx.data.model.ListItem
|
||||
import com.philkes.notallyx.data.model.NoteViewMode
|
||||
import com.philkes.notallyx.data.model.Type
|
||||
import com.philkes.notallyx.utils.log
|
||||
import com.philkes.notallyx.utils.startsWithAnyOf
|
||||
import com.philkes.notallyx.utils.write
|
||||
import java.io.File
|
||||
import java.io.InputStream
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Date
|
||||
import java.util.Locale
|
||||
import java.util.TimeZone
|
||||
import org.simpleframework.xml.Serializer
|
||||
import org.simpleframework.xml.convert.AnnotationStrategy
|
||||
import org.simpleframework.xml.core.Persister
|
||||
|
||||
class EvernoteImporter : ExternalImporter {
|
||||
private val serializer: Serializer = Persister(AnnotationStrategy())
|
||||
|
||||
override fun import(
|
||||
app: Application,
|
||||
source: Uri,
|
||||
destination: File,
|
||||
progress: MutableLiveData<ImportProgress>?,
|
||||
): Pair<List<BaseNote>, File> {
|
||||
progress?.postValue(ImportProgress(indeterminate = true))
|
||||
if (MimeTypeMap.getFileExtensionFromUrl(source.toString()) != "enex") {
|
||||
throw ImportException(
|
||||
R.string.invalid_evernote,
|
||||
IllegalArgumentException("Provided file is not in ENEX format"),
|
||||
)
|
||||
}
|
||||
val evernoteExport: EvernoteExport =
|
||||
parseExport(app.contentResolver.openInputStream(source)!!)!!
|
||||
|
||||
val total = evernoteExport.notes.size
|
||||
progress?.postValue(ImportProgress(total = total))
|
||||
var counter = 1
|
||||
try {
|
||||
val notes =
|
||||
evernoteExport.notes.map {
|
||||
val note = it.mapToBaseNote()
|
||||
progress?.postValue(ImportProgress(current = counter++, total = total))
|
||||
note
|
||||
}
|
||||
val resources =
|
||||
evernoteExport.notes.flatMap { it.resources }.distinctBy { it.attributes?.fileName }
|
||||
saveResourcesToFiles(app, resources, destination, progress)
|
||||
return Pair(notes, destination)
|
||||
} catch (e: Exception) {
|
||||
throw ImportException(R.string.invalid_evernote, e)
|
||||
}
|
||||
}
|
||||
|
||||
fun parseExport(inputStream: InputStream): EvernoteExport? =
|
||||
try {
|
||||
serializer.read(EvernoteExport::class.java, inputStream)
|
||||
} catch (e: Exception) {
|
||||
throw ImportException(R.string.invalid_evernote, e)
|
||||
}
|
||||
|
||||
private fun saveResourcesToFiles(
|
||||
app: Application,
|
||||
resources: Collection<EvernoteResource>,
|
||||
dir: File,
|
||||
progress: MutableLiveData<ImportProgress>? = null,
|
||||
) {
|
||||
progress?.postValue(
|
||||
ImportProgress(total = resources.size, stage = ImportStage.EXTRACT_FILES)
|
||||
)
|
||||
resources.forEachIndexed { idx, it ->
|
||||
val file = File(dir, it.attributes!!.fileName)
|
||||
try {
|
||||
val data = Base64.decode(it.data!!.content.trimStart(), Base64.DEFAULT)
|
||||
file.write(data)
|
||||
} catch (e: Exception) {
|
||||
app.log(TAG, throwable = e)
|
||||
}
|
||||
progress?.postValue(
|
||||
ImportProgress(
|
||||
current = idx + 1,
|
||||
total = resources.size,
|
||||
stage = ImportStage.EXTRACT_FILES,
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val TAG = "EvernoteImporter"
|
||||
|
||||
fun parseTimestamp(timestamp: String): Long {
|
||||
val format = SimpleDateFormat(EVERNOTE_DATE_FORMAT, Locale.getDefault())
|
||||
format.timeZone = TimeZone.getTimeZone("UTC")
|
||||
return try {
|
||||
val date: Date = format.parse(timestamp) ?: Date()
|
||||
date.time // Return milliseconds since epoch
|
||||
} catch (e: Exception) {
|
||||
System.currentTimeMillis()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private const val EVERNOTE_DATE_FORMAT = "yyyyMMdd'T'HHmmss'Z'"
|
||||
private const val EVERNOTE_NOTE_XML_TAG = "en-note"
|
||||
|
||||
fun EvernoteNote.mapToBaseNote(): BaseNote {
|
||||
val (body, spans) =
|
||||
parseBodyAndSpansFromHtml(
|
||||
content,
|
||||
EVERNOTE_NOTE_XML_TAG,
|
||||
useInnermostRootTag = true,
|
||||
brTagsAsNewLine = false,
|
||||
)
|
||||
val images = resources.filterByMimeTypePrefix("image").toFileAttachments()
|
||||
val files = resources.filterByExcludedMimeTypePrefixes("image", "audio").toFileAttachments()
|
||||
val audios =
|
||||
resources.filterByMimeTypePrefix("audio").map {
|
||||
Audio(it.attributes!!.fileName, -1, System.currentTimeMillis())
|
||||
}
|
||||
|
||||
return BaseNote(
|
||||
0L,
|
||||
type = if (tasks.isEmpty()) Type.NOTE else Type.LIST,
|
||||
folder = Folder.NOTES, // There is no archive in Evernote, also deleted notes are not
|
||||
// exported
|
||||
color = BaseNote.COLOR_DEFAULT, // TODO: possible in Evernote?
|
||||
title = title,
|
||||
pinned = false, // not exported from Evernote
|
||||
timestamp = parseTimestamp(created),
|
||||
modifiedTimestamp = parseTimestamp(updated),
|
||||
labels = tag.map { it.name },
|
||||
body = body,
|
||||
spans = spans,
|
||||
items = tasks.mapToListItem(),
|
||||
images = images,
|
||||
files = files,
|
||||
audios = audios,
|
||||
reminders = mutableListOf(),
|
||||
NoteViewMode.EDIT,
|
||||
)
|
||||
}
|
||||
|
||||
fun Collection<EvernoteResource>.filterByMimeTypePrefix(
|
||||
mimeTypePrefix: String
|
||||
): List<EvernoteResource> {
|
||||
return filter { it.mime.startsWith(mimeTypePrefix) }
|
||||
}
|
||||
|
||||
fun Collection<EvernoteResource>.filterByExcludedMimeTypePrefixes(
|
||||
vararg mimeTypePrefix: String
|
||||
): List<EvernoteResource> {
|
||||
return filter { !it.mime.startsWithAnyOf(*mimeTypePrefix) }
|
||||
}
|
||||
|
||||
fun Collection<EvernoteResource>.toFileAttachments(): List<FileAttachment> {
|
||||
return map { FileAttachment(it.attributes!!.fileName, it.attributes.fileName, it.mime) }
|
||||
}
|
||||
|
||||
fun Collection<EvernoteTask>.mapToListItem(): List<ListItem> {
|
||||
return sortedBy { it.sortWeight }
|
||||
.mapIndexed { index, evernoteTask ->
|
||||
ListItem(
|
||||
body = evernoteTask.title,
|
||||
checked = evernoteTask.taskStatus == TaskStatus.COMPLETED,
|
||||
isChild = false, // You cant indent tasks in Evernote
|
||||
order = index,
|
||||
children = mutableListOf(),
|
||||
)
|
||||
}
|
||||
}
|
|
@ -1,218 +0,0 @@
|
|||
package com.philkes.notallyx.data.imports.google
|
||||
|
||||
import android.app.Application
|
||||
import android.net.Uri
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import com.philkes.notallyx.R
|
||||
import com.philkes.notallyx.data.imports.ExternalImporter
|
||||
import com.philkes.notallyx.data.imports.ImportException
|
||||
import com.philkes.notallyx.data.imports.ImportProgress
|
||||
import com.philkes.notallyx.data.imports.ImportStage
|
||||
import com.philkes.notallyx.data.imports.parseBodyAndSpansFromHtml
|
||||
import com.philkes.notallyx.data.model.Audio
|
||||
import com.philkes.notallyx.data.model.BaseNote
|
||||
import com.philkes.notallyx.data.model.FileAttachment
|
||||
import com.philkes.notallyx.data.model.Folder
|
||||
import com.philkes.notallyx.data.model.ListItem
|
||||
import com.philkes.notallyx.data.model.NoteViewMode
|
||||
import com.philkes.notallyx.data.model.Type
|
||||
import com.philkes.notallyx.utils.listFilesRecursive
|
||||
import com.philkes.notallyx.utils.log
|
||||
import java.io.File
|
||||
import java.io.FileOutputStream
|
||||
import java.io.IOException
|
||||
import java.io.InputStream
|
||||
import java.util.zip.ZipEntry
|
||||
import java.util.zip.ZipInputStream
|
||||
import kotlinx.serialization.ExperimentalSerializationApi
|
||||
import kotlinx.serialization.json.Json
|
||||
|
||||
class GoogleKeepImporter : ExternalImporter {
|
||||
|
||||
@OptIn(ExperimentalSerializationApi::class)
|
||||
private val json = Json {
|
||||
ignoreUnknownKeys = true
|
||||
isLenient = true
|
||||
allowTrailingComma = true
|
||||
}
|
||||
|
||||
override fun import(
|
||||
app: Application,
|
||||
source: Uri,
|
||||
destination: File,
|
||||
progress: MutableLiveData<ImportProgress>?,
|
||||
): Pair<List<BaseNote>, File> {
|
||||
progress?.postValue(ImportProgress(indeterminate = true, stage = ImportStage.EXTRACT_FILES))
|
||||
val dataFolder =
|
||||
try {
|
||||
app.contentResolver.openInputStream(source)!!.use { unzip(destination, it) }
|
||||
} catch (e: Exception) {
|
||||
throw ImportException(R.string.invalid_google_keep, e)
|
||||
}
|
||||
|
||||
if (!dataFolder.exists()) {
|
||||
throw ImportException(
|
||||
R.string.invalid_google_keep,
|
||||
RuntimeException("Extracting Takeout.zip failed"),
|
||||
)
|
||||
}
|
||||
|
||||
val noteFiles =
|
||||
dataFolder
|
||||
.listFilesRecursive { file ->
|
||||
file.isFile && file.extension.equals("json", ignoreCase = true)
|
||||
}
|
||||
.toList()
|
||||
val total = noteFiles.size
|
||||
progress?.postValue(ImportProgress(0, total, stage = ImportStage.IMPORT_NOTES))
|
||||
var counter = 1
|
||||
val baseNotes =
|
||||
noteFiles
|
||||
.mapNotNull { file ->
|
||||
val baseNote =
|
||||
try {
|
||||
val relativePath = file.parentFile!!.toRelativeString(dataFolder)
|
||||
file.readText().parseToBaseNote(relativePath)
|
||||
} catch (e: Exception) {
|
||||
app.log(
|
||||
TAG,
|
||||
msg =
|
||||
"Could not parse BaseNote from JSON in file '${file.absolutePath}'",
|
||||
throwable = e,
|
||||
)
|
||||
null
|
||||
}
|
||||
progress?.postValue(
|
||||
ImportProgress(counter++, total, stage = ImportStage.IMPORT_NOTES)
|
||||
)
|
||||
baseNote
|
||||
}
|
||||
.toList()
|
||||
return Pair(baseNotes, dataFolder)
|
||||
}
|
||||
|
||||
fun String.parseToBaseNote(relativePath: String? = null): BaseNote {
|
||||
val googleKeepNote = json.decodeFromString<GoogleKeepNote>(this)
|
||||
val (body, spans) =
|
||||
parseBodyAndSpansFromHtml(
|
||||
googleKeepNote.textContentHtml,
|
||||
paragraphsAsNewLine = true,
|
||||
brTagsAsNewLine = true,
|
||||
)
|
||||
|
||||
val images =
|
||||
googleKeepNote.attachments
|
||||
.filter { it.mimetype.startsWith("image") }
|
||||
.map { attachment ->
|
||||
FileAttachment(
|
||||
"${relativePath?.let { "$it/" } ?: ""}${attachment.filePath}",
|
||||
attachment.filePath,
|
||||
attachment.mimetype,
|
||||
)
|
||||
}
|
||||
val files =
|
||||
googleKeepNote.attachments
|
||||
.filter { !it.mimetype.startsWith("audio") && !it.mimetype.startsWith("image") }
|
||||
.map { attachment ->
|
||||
FileAttachment(
|
||||
"${relativePath?.let { "$it/" } ?: ""}${attachment.filePath}",
|
||||
attachment.filePath,
|
||||
attachment.mimetype,
|
||||
)
|
||||
}
|
||||
val audios =
|
||||
googleKeepNote.attachments
|
||||
.filter { it.mimetype.startsWith("audio") }
|
||||
.map { attachment ->
|
||||
Audio(
|
||||
"${relativePath?.let { "$it/" } ?: ""}${attachment.filePath}",
|
||||
0L,
|
||||
System.currentTimeMillis(),
|
||||
)
|
||||
}
|
||||
val items =
|
||||
googleKeepNote.listContent.mapIndexed { index, item ->
|
||||
ListItem(
|
||||
body = item.text,
|
||||
checked = item.isChecked,
|
||||
isChild = false, // Google Keep doesn't have explicit child/indentation info
|
||||
order = index,
|
||||
children = mutableListOf(),
|
||||
)
|
||||
}
|
||||
|
||||
return BaseNote(
|
||||
id = 0L, // Auto-generated
|
||||
type = if (googleKeepNote.listContent.isNotEmpty()) Type.LIST else Type.NOTE,
|
||||
folder =
|
||||
when {
|
||||
googleKeepNote.isTrashed -> Folder.DELETED
|
||||
googleKeepNote.isArchived -> Folder.ARCHIVED
|
||||
else -> Folder.NOTES
|
||||
},
|
||||
color = BaseNote.COLOR_DEFAULT, // Ignoring color mapping
|
||||
title = googleKeepNote.title,
|
||||
pinned = googleKeepNote.isPinned,
|
||||
timestamp = googleKeepNote.createdTimestampUsec / 1000,
|
||||
modifiedTimestamp = googleKeepNote.userEditedTimestampUsec / 1000,
|
||||
labels = googleKeepNote.labels.map { it.name },
|
||||
body = body,
|
||||
spans = spans,
|
||||
items = items,
|
||||
images = images,
|
||||
files = files,
|
||||
audios = audios,
|
||||
reminders = mutableListOf(),
|
||||
NoteViewMode.EDIT,
|
||||
)
|
||||
}
|
||||
|
||||
private fun newFile(destinationDir: File, zipEntry: ZipEntry): File {
|
||||
val destFile = File(destinationDir, zipEntry.name)
|
||||
|
||||
val destDirPath = destinationDir.canonicalPath
|
||||
val destFilePath = destFile.canonicalPath
|
||||
|
||||
if (!destFilePath.startsWith(destDirPath + File.separator)) {
|
||||
throw IOException("Entry is outside of the target dir: " + zipEntry.name)
|
||||
}
|
||||
|
||||
return destFile
|
||||
}
|
||||
|
||||
private fun unzip(destinationPath: File, inputStream: InputStream): File {
|
||||
val buffer = ByteArray(1024)
|
||||
val zis = ZipInputStream(inputStream)
|
||||
var zipEntry = zis.nextEntry
|
||||
while (zipEntry != null) {
|
||||
val newFile: File = newFile(destinationPath, zipEntry)
|
||||
if (zipEntry.isDirectory) {
|
||||
if (!newFile.isDirectory && !newFile.mkdirs()) {
|
||||
throw IOException("Failed to create directory $newFile")
|
||||
}
|
||||
} else {
|
||||
val parent = newFile.parentFile
|
||||
if (parent != null) {
|
||||
if (!parent.isDirectory && !parent.mkdirs()) {
|
||||
throw IOException("Failed to create directory $parent")
|
||||
}
|
||||
}
|
||||
FileOutputStream(newFile).use {
|
||||
var len: Int
|
||||
while ((zis.read(buffer).also { length -> len = length }) > 0) {
|
||||
it.write(buffer, 0, len)
|
||||
}
|
||||
}
|
||||
}
|
||||
zipEntry = zis.nextEntry
|
||||
}
|
||||
|
||||
zis.closeEntry()
|
||||
zis.close()
|
||||
return destinationPath
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val TAG = "GoogleKeepImporter"
|
||||
}
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
package com.philkes.notallyx.data.imports.google
|
||||
|
||||
import com.philkes.notallyx.data.model.BaseNote
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class GoogleKeepNote(
|
||||
val attachments: List<GoogleKeepAttachment> = listOf(),
|
||||
val color: String = BaseNote.COLOR_DEFAULT,
|
||||
val isTrashed: Boolean = false,
|
||||
val isArchived: Boolean = false,
|
||||
val isPinned: Boolean = false,
|
||||
val textContent: String = "",
|
||||
val textContentHtml: String = "",
|
||||
val title: String = "",
|
||||
val labels: List<GoogleKeepLabel> = listOf(),
|
||||
val userEditedTimestampUsec: Long = System.currentTimeMillis(),
|
||||
val createdTimestampUsec: Long = System.currentTimeMillis(),
|
||||
val listContent: List<GoogleKeepListItem> = listOf(),
|
||||
)
|
||||
|
||||
@Serializable data class GoogleKeepLabel(val name: String)
|
||||
|
||||
@Serializable data class GoogleKeepAttachment(val filePath: String, val mimetype: String)
|
||||
|
||||
@Serializable data class GoogleKeepListItem(val text: String, val isChecked: Boolean)
|
|
@ -1,52 +0,0 @@
|
|||
package com.philkes.notallyx.data.imports.txt
|
||||
|
||||
import android.app.Application
|
||||
import android.net.Uri
|
||||
import androidx.documentfile.provider.DocumentFile
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import com.philkes.notallyx.data.imports.ExternalImporter
|
||||
import com.philkes.notallyx.data.imports.ImportProgress
|
||||
import com.philkes.notallyx.data.model.BaseNote
|
||||
import com.philkes.notallyx.data.model.toBaseNote
|
||||
import com.philkes.notallyx.utils.MIME_TYPE_JSON
|
||||
import java.io.BufferedReader
|
||||
import java.io.File
|
||||
import java.io.InputStreamReader
|
||||
|
||||
class JsonImporter : ExternalImporter {
|
||||
|
||||
override fun import(
|
||||
app: Application,
|
||||
source: Uri,
|
||||
destination: File,
|
||||
progress: MutableLiveData<ImportProgress>?,
|
||||
): Pair<List<BaseNote>, File?> {
|
||||
val notes = mutableListOf<BaseNote>()
|
||||
fun readJsonFiles(file: DocumentFile) {
|
||||
when {
|
||||
file.isDirectory -> {
|
||||
file.listFiles().forEach { readJsonFiles(it) }
|
||||
}
|
||||
file.isFile -> {
|
||||
if (file.type != MIME_TYPE_JSON) {
|
||||
return
|
||||
}
|
||||
val fileNameWithoutExtension = file.name?.substringBeforeLast(".") ?: ""
|
||||
val content =
|
||||
app.contentResolver.openInputStream(file.uri)?.use { inputStream ->
|
||||
BufferedReader(InputStreamReader(inputStream)).use { reader ->
|
||||
reader.readText()
|
||||
}
|
||||
} ?: ""
|
||||
notes.add(content.toBaseNote().copy(id = 0L, title = fileNameWithoutExtension))
|
||||
}
|
||||
}
|
||||
}
|
||||
val file =
|
||||
if (source.pathSegments.firstOrNull() == "tree") {
|
||||
DocumentFile.fromTreeUri(app, source)
|
||||
} else DocumentFile.fromSingleUri(app, source)
|
||||
file?.let { readJsonFiles(it) }
|
||||
return Pair(notes, null)
|
||||
}
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
package com.philkes.notallyx.data.imports.txt
|
||||
|
||||
import com.philkes.notallyx.data.model.ListItem
|
||||
|
||||
fun CharSequence.extractListItems(regex: Regex): List<ListItem> {
|
||||
return regex
|
||||
.findAll(this)
|
||||
.mapIndexedNotNull { idx, matchResult ->
|
||||
val isChild = matchResult.groupValues[1] != ""
|
||||
val isChecked = matchResult.groupValues[2] != ""
|
||||
val itemText = matchResult.groupValues[3]
|
||||
if (itemText.isNotBlank()) {
|
||||
ListItem(itemText.trimStart(), isChecked, isChild, idx, mutableListOf())
|
||||
} else null
|
||||
}
|
||||
.toList()
|
||||
}
|
||||
|
||||
fun CharSequence.findListSyntaxRegex(
|
||||
checkContains: Boolean = false,
|
||||
plainNewLineAllowed: Boolean = false,
|
||||
): Regex? {
|
||||
val checkCallback: (String) -> Boolean =
|
||||
if (checkContains) {
|
||||
{ string -> startsWith(string) || contains(string, ignoreCase = true) }
|
||||
} else {
|
||||
{ string -> startsWith(string) }
|
||||
}
|
||||
if (checkCallback("- [ ]") || checkCallback("- [x]")) {
|
||||
return "\n?(\\s*)-? ?\\[? ?([xX]?)\\]?(.*)".toRegex()
|
||||
}
|
||||
if (checkCallback("[ ]") || checkCallback("[✓]")) {
|
||||
return "\n?(\\s*)\\[? ?(✓?)\\]?(.*)".toRegex()
|
||||
}
|
||||
if (checkCallback("-") || checkCallback("*")) {
|
||||
return "\n?(\\s*)[-*]?\\s*()(.*)".toRegex()
|
||||
}
|
||||
if (plainNewLineAllowed && contains("\n")) {
|
||||
return "\n?(\\s*)()(.*)".toRegex()
|
||||
}
|
||||
return null
|
||||
}
|
|
@ -1,89 +0,0 @@
|
|||
package com.philkes.notallyx.data.imports.txt
|
||||
|
||||
import android.app.Application
|
||||
import android.net.Uri
|
||||
import androidx.documentfile.provider.DocumentFile
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import com.philkes.notallyx.data.imports.ExternalImporter
|
||||
import com.philkes.notallyx.data.imports.ImportProgress
|
||||
import com.philkes.notallyx.data.model.BaseNote
|
||||
import com.philkes.notallyx.data.model.Folder
|
||||
import com.philkes.notallyx.data.model.ListItem
|
||||
import com.philkes.notallyx.data.model.NoteViewMode
|
||||
import com.philkes.notallyx.data.model.Type
|
||||
import com.philkes.notallyx.utils.MIME_TYPE_JSON
|
||||
import com.philkes.notallyx.utils.readFileContents
|
||||
import java.io.File
|
||||
|
||||
class PlainTextImporter : ExternalImporter {
|
||||
|
||||
override fun import(
|
||||
app: Application,
|
||||
source: Uri,
|
||||
destination: File,
|
||||
progress: MutableLiveData<ImportProgress>?,
|
||||
): Pair<List<BaseNote>, File?> {
|
||||
val notes = mutableListOf<BaseNote>()
|
||||
fun readTxtFiles(file: DocumentFile) {
|
||||
when {
|
||||
file.isDirectory -> {
|
||||
file.listFiles().forEach { readTxtFiles(it) }
|
||||
}
|
||||
|
||||
file.isFile -> {
|
||||
if (file.type?.isTextMimeType() == false) {
|
||||
return
|
||||
}
|
||||
val fileNameWithoutExtension = file.name?.substringBeforeLast(".") ?: ""
|
||||
var content = app.contentResolver.readFileContents(file.uri)
|
||||
val listItems = mutableListOf<ListItem>()
|
||||
content.findListSyntaxRegex()?.let { listSyntaxRegex ->
|
||||
listItems.addAll(content.extractListItems(listSyntaxRegex))
|
||||
content = ""
|
||||
}
|
||||
val timestamp = System.currentTimeMillis()
|
||||
notes.add(
|
||||
BaseNote(
|
||||
id = 0L, // Auto-generated
|
||||
type = if (listItems.isEmpty()) Type.NOTE else Type.LIST,
|
||||
folder = Folder.NOTES,
|
||||
color = BaseNote.COLOR_DEFAULT,
|
||||
title = fileNameWithoutExtension,
|
||||
pinned = false,
|
||||
timestamp = timestamp,
|
||||
modifiedTimestamp = timestamp,
|
||||
labels = listOf(),
|
||||
body = content,
|
||||
spans = listOf(),
|
||||
items = listItems,
|
||||
images = listOf(),
|
||||
files = listOf(),
|
||||
audios = listOf(),
|
||||
reminders = listOf(),
|
||||
NoteViewMode.EDIT,
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
val file =
|
||||
if (source.pathSegments.firstOrNull() == "tree") {
|
||||
DocumentFile.fromTreeUri(app, source)
|
||||
} else DocumentFile.fromSingleUri(app, source)
|
||||
file?.let { readTxtFiles(it) }
|
||||
return Pair(notes, null)
|
||||
}
|
||||
|
||||
private fun String.isTextMimeType(): Boolean {
|
||||
return startsWith("text/") || this in APPLICATION_TEXT_MIME_TYPES
|
||||
}
|
||||
}
|
||||
|
||||
val APPLICATION_TEXT_MIME_TYPES =
|
||||
arrayOf(
|
||||
MIME_TYPE_JSON,
|
||||
"application/xml",
|
||||
"application/javascript",
|
||||
"application/xhtml+xml",
|
||||
"application/yaml",
|
||||
)
|
|
@ -1,5 +0,0 @@
|
|||
package com.philkes.notallyx.data.model
|
||||
|
||||
import android.os.Parcelable
|
||||
|
||||
sealed interface Attachment : Parcelable
|
|
@ -1,6 +0,0 @@
|
|||
package com.philkes.notallyx.data.model
|
||||
|
||||
import kotlinx.parcelize.Parcelize
|
||||
|
||||
@Parcelize
|
||||
data class Audio(var name: String, var duration: Long?, var timestamp: Long) : Attachment
|
|
@ -1,93 +0,0 @@
|
|||
package com.philkes.notallyx.data.model
|
||||
|
||||
import androidx.room.Entity
|
||||
import androidx.room.Index
|
||||
import androidx.room.PrimaryKey
|
||||
|
||||
/** Format: `#RRGGBB` or `#AARRGGBB` or [BaseNote.COLOR_DEFAULT] */
|
||||
typealias ColorString = String
|
||||
|
||||
@Entity(indices = [Index(value = ["id", "folder", "pinned", "timestamp", "labels"])])
|
||||
data class BaseNote(
|
||||
@PrimaryKey(autoGenerate = true) val id: Long,
|
||||
val type: Type,
|
||||
val folder: Folder,
|
||||
val color: ColorString,
|
||||
val title: String,
|
||||
val pinned: Boolean,
|
||||
val timestamp: Long,
|
||||
val modifiedTimestamp: Long,
|
||||
val labels: List<String>,
|
||||
val body: String,
|
||||
val spans: List<SpanRepresentation>,
|
||||
val items: List<ListItem>,
|
||||
val images: List<FileAttachment>,
|
||||
val files: List<FileAttachment>,
|
||||
val audios: List<Audio>,
|
||||
val reminders: List<Reminder>,
|
||||
val viewMode: NoteViewMode,
|
||||
) : Item {
|
||||
|
||||
companion object {
|
||||
const val COLOR_DEFAULT = "DEFAULT"
|
||||
const val COLOR_NEW = "NEW"
|
||||
}
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (javaClass != other?.javaClass) return false
|
||||
|
||||
other as BaseNote
|
||||
|
||||
if (id != other.id) return false
|
||||
if (type != other.type) return false
|
||||
if (folder != other.folder) return false
|
||||
if (color != other.color) return false
|
||||
if (title != other.title) return false
|
||||
if (pinned != other.pinned) return false
|
||||
if (timestamp != other.timestamp) return false
|
||||
if (labels != other.labels) return false
|
||||
if (body != other.body) return false
|
||||
if (spans != other.spans) return false
|
||||
if (items != other.items) return false
|
||||
if (images != other.images) return false
|
||||
if (files != other.files) return false
|
||||
if (audios != other.audios) return false
|
||||
if (reminders != other.reminders) return false
|
||||
if (viewMode != other.viewMode) return false
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
var result = id.hashCode()
|
||||
result = 31 * result + type.hashCode()
|
||||
result = 31 * result + folder.hashCode()
|
||||
result = 31 * result + color.hashCode()
|
||||
result = 31 * result + title.hashCode()
|
||||
result = 31 * result + pinned.hashCode()
|
||||
result = 31 * result + timestamp.hashCode()
|
||||
result = 31 * result + labels.hashCode()
|
||||
result = 31 * result + body.hashCode()
|
||||
result = 31 * result + spans.hashCode()
|
||||
result = 31 * result + items.hashCode()
|
||||
result = 31 * result + images.hashCode()
|
||||
result = 31 * result + files.hashCode()
|
||||
result = 31 * result + audios.hashCode()
|
||||
result = 31 * result + reminders.hashCode()
|
||||
result = 31 * result + viewMode.hashCode()
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
fun BaseNote.deepCopy(): BaseNote {
|
||||
return copy(
|
||||
labels = labels.toMutableList(),
|
||||
spans = spans.map { it.copy() }.toMutableList(),
|
||||
items = items.map { it.copy() }.toMutableList(),
|
||||
images = images.map { it.copy() }.toMutableList(),
|
||||
files = files.map { it.copy() }.toMutableList(),
|
||||
audios = audios.map { it.copy() }.toMutableList(),
|
||||
reminders = reminders.map { it.copy() }.toMutableList(),
|
||||
)
|
||||
}
|
|
@ -1,56 +0,0 @@
|
|||
package com.philkes.notallyx.data.model
|
||||
|
||||
enum class Color {
|
||||
DEFAULT,
|
||||
CORAL,
|
||||
ORANGE,
|
||||
SAND,
|
||||
STORM,
|
||||
FOG,
|
||||
SAGE,
|
||||
MINT,
|
||||
DUSK,
|
||||
FLOWER,
|
||||
BLOSSOM,
|
||||
CLAY;
|
||||
|
||||
companion object {
|
||||
fun allColorStrings() = entries.map { it.toColorString() }.toList()
|
||||
|
||||
fun valueOfOrDefault(value: String) =
|
||||
try {
|
||||
Color.valueOf(value)
|
||||
} catch (e: Exception) {
|
||||
DEFAULT
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun Color.toColorString() =
|
||||
when (this) {
|
||||
Color.DEFAULT -> BaseNote.COLOR_DEFAULT
|
||||
Color.CORAL -> "#FAAFA9"
|
||||
Color.ORANGE -> "#FFCC80"
|
||||
Color.SAND -> "#FFF8B9"
|
||||
Color.STORM -> "#AFCCDC"
|
||||
Color.FOG -> "#D3E4EC"
|
||||
Color.SAGE -> "#B4DED4"
|
||||
Color.MINT -> "#E2F6D3"
|
||||
Color.DUSK -> "#D3BFDB"
|
||||
Color.FLOWER -> "#F8BBD0"
|
||||
Color.BLOSSOM -> "#F5E2DC"
|
||||
Color.CLAY -> "#E9E3D3"
|
||||
}
|
||||
|
||||
fun String.parseToColorString() =
|
||||
try {
|
||||
android.graphics.Color.parseColor(this)
|
||||
this
|
||||
} catch (_: Exception) {
|
||||
try {
|
||||
val colorEnum = Color.valueOf(this)
|
||||
colorEnum.toColorString()
|
||||
} catch (e: Exception) {
|
||||
BaseNote.COLOR_DEFAULT
|
||||
}
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
package com.philkes.notallyx.data.model
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.Observer
|
||||
|
||||
/**
|
||||
* The instance of LiveData returned by Room only listens for changes while the fragment observing
|
||||
* it is alive. Observation of the data stops when the fragment is destroyed and resumes when it's
|
||||
* created.
|
||||
*
|
||||
* Take for example, the following situation
|
||||
*
|
||||
* User goes to the deleted section User restores 5 notes User returns to the notes section
|
||||
*
|
||||
* The observation of notes had stopped when the user went to the deleted section and is resumed
|
||||
* when the user comes back. This leads to lag and flickering.
|
||||
*
|
||||
* To stop this, this class acts as a wrapper over the LiveData returned by Room and continuously
|
||||
* observes it.
|
||||
*/
|
||||
class Content(
|
||||
private var liveData: LiveData<List<BaseNote>>,
|
||||
private val transform: (List<BaseNote>) -> List<Item>,
|
||||
) : LiveData<List<Item>>() {
|
||||
private var observer: Observer<List<BaseNote>>? = null
|
||||
|
||||
init {
|
||||
setObserver(liveData)
|
||||
}
|
||||
|
||||
fun setObserver(liveData: LiveData<List<BaseNote>>) {
|
||||
observer?.let { this.liveData.removeObserver(it) }
|
||||
this.liveData = liveData
|
||||
observer = Observer { list -> value = transform(list) }
|
||||
this.liveData.observeForever(observer!!)
|
||||
}
|
||||
}
|
|
@ -1,252 +0,0 @@
|
|||
package com.philkes.notallyx.data.model
|
||||
|
||||
import androidx.room.TypeConverter
|
||||
import java.util.Date
|
||||
import org.json.JSONArray
|
||||
import org.json.JSONException
|
||||
import org.json.JSONObject
|
||||
|
||||
object Converters {
|
||||
|
||||
@TypeConverter fun labelsToJson(labels: List<String>) = JSONArray(labels).toString()
|
||||
|
||||
@TypeConverter fun jsonToLabels(json: String) = jsonToLabels(JSONArray(json))
|
||||
|
||||
fun jsonToLabels(jsonArray: JSONArray) = jsonArray.iterable<String>().toList()
|
||||
|
||||
@TypeConverter
|
||||
fun filesToJson(files: List<FileAttachment>): String {
|
||||
val objects =
|
||||
files.map { file ->
|
||||
val jsonObject = JSONObject()
|
||||
jsonObject.put("localName", file.localName)
|
||||
jsonObject.put("originalName", file.originalName)
|
||||
jsonObject.put("mimeType", file.mimeType)
|
||||
}
|
||||
return JSONArray(objects).toString()
|
||||
}
|
||||
|
||||
@TypeConverter fun jsonToFiles(json: String) = jsonToFiles(JSONArray(json))
|
||||
|
||||
fun jsonToFiles(jsonArray: JSONArray): List<FileAttachment> {
|
||||
return jsonArray.iterable<JSONObject>().map { jsonObject ->
|
||||
val localName = getSafeLocalName(jsonObject)
|
||||
val originalName = getSafeOriginalName(jsonObject)
|
||||
val mimeType = jsonObject.getString("mimeType")
|
||||
FileAttachment(localName, originalName, mimeType)
|
||||
}
|
||||
}
|
||||
|
||||
@TypeConverter
|
||||
fun audiosToJson(audios: List<Audio>): String {
|
||||
val objects =
|
||||
audios.map { audio ->
|
||||
val jsonObject = JSONObject()
|
||||
jsonObject.put("name", audio.name)
|
||||
jsonObject.put("duration", audio.duration)
|
||||
jsonObject.put("timestamp", audio.timestamp)
|
||||
}
|
||||
return JSONArray(objects).toString()
|
||||
}
|
||||
|
||||
@TypeConverter fun jsonToAudios(json: String) = jsonToAudios(JSONArray(json))
|
||||
|
||||
fun jsonToAudios(json: JSONArray): List<Audio> {
|
||||
return json.iterable<JSONObject>().map { jsonObject ->
|
||||
val name = jsonObject.getString("name")
|
||||
val duration = jsonObject.getSafeLong("duration")
|
||||
val timestamp = jsonObject.getLong("timestamp")
|
||||
Audio(name, duration, timestamp)
|
||||
}
|
||||
}
|
||||
|
||||
@TypeConverter fun jsonToSpans(json: String) = jsonToSpans(JSONArray(json))
|
||||
|
||||
fun jsonToSpans(jsonArray: JSONArray): List<SpanRepresentation> {
|
||||
return jsonArray
|
||||
.iterable<JSONObject>()
|
||||
.map { jsonObject ->
|
||||
val bold = jsonObject.getSafeBoolean("bold")
|
||||
val link = jsonObject.getSafeBoolean("link")
|
||||
val linkData = jsonObject.getSafeString("linkData")
|
||||
val italic = jsonObject.getSafeBoolean("italic")
|
||||
val monospace = jsonObject.getSafeBoolean("monospace")
|
||||
val strikethrough = jsonObject.getSafeBoolean("strikethrough")
|
||||
try {
|
||||
val start = jsonObject.getInt("start")
|
||||
val end = jsonObject.getInt("end")
|
||||
SpanRepresentation(
|
||||
start,
|
||||
end,
|
||||
bold,
|
||||
link,
|
||||
linkData,
|
||||
italic,
|
||||
monospace,
|
||||
strikethrough,
|
||||
)
|
||||
} catch (e: Exception) {
|
||||
null
|
||||
}
|
||||
}
|
||||
.filterNotNull()
|
||||
}
|
||||
|
||||
@TypeConverter
|
||||
fun spansToJson(list: List<SpanRepresentation>) = spansToJSONArray(list).toString()
|
||||
|
||||
fun spansToJSONArray(list: List<SpanRepresentation>): JSONArray {
|
||||
val objects =
|
||||
list.map { representation ->
|
||||
val jsonObject = JSONObject()
|
||||
jsonObject.put("bold", representation.bold)
|
||||
jsonObject.put("link", representation.link)
|
||||
jsonObject.put("linkData", representation.linkData)
|
||||
jsonObject.put("italic", representation.italic)
|
||||
jsonObject.put("monospace", representation.monospace)
|
||||
jsonObject.put("strikethrough", representation.strikethrough)
|
||||
jsonObject.put("start", representation.start)
|
||||
jsonObject.put("end", representation.end)
|
||||
}
|
||||
return JSONArray(objects)
|
||||
}
|
||||
|
||||
@TypeConverter fun jsonToItems(json: String) = jsonToItems(JSONArray(json))
|
||||
|
||||
fun jsonToItems(json: JSONArray): List<ListItem> {
|
||||
return json.iterable<JSONObject>().map { jsonObject ->
|
||||
val body = jsonObject.getSafeString("body") ?: ""
|
||||
val checked = jsonObject.getSafeBoolean("checked")
|
||||
val isChild = jsonObject.getSafeBoolean("isChild")
|
||||
val order = jsonObject.getSafeInt("order")
|
||||
ListItem(body, checked, isChild, order, mutableListOf())
|
||||
}
|
||||
}
|
||||
|
||||
@TypeConverter fun itemsToJson(list: List<ListItem>) = itemsToJSONArray(list).toString()
|
||||
|
||||
fun itemsToJSONArray(list: List<ListItem>): JSONArray {
|
||||
val objects =
|
||||
list.map { item ->
|
||||
val jsonObject = JSONObject()
|
||||
jsonObject.put("body", item.body)
|
||||
jsonObject.put("checked", item.checked)
|
||||
jsonObject.put("isChild", item.isChild)
|
||||
jsonObject.put("order", item.order)
|
||||
}
|
||||
return JSONArray(objects)
|
||||
}
|
||||
|
||||
@TypeConverter
|
||||
fun remindersToJson(reminders: List<Reminder>) = remindersToJSONArray(reminders).toString()
|
||||
|
||||
fun remindersToJSONArray(reminders: List<Reminder>): JSONArray {
|
||||
val objects =
|
||||
reminders.map { reminder ->
|
||||
JSONObject().apply {
|
||||
put("id", reminder.id) // Store date as long timestamp
|
||||
put("dateTime", reminder.dateTime.time) // Store date as long timestamp
|
||||
put("repetition", reminder.repetition?.let { repetitionToJsonObject(it) })
|
||||
}
|
||||
}
|
||||
return JSONArray(objects)
|
||||
}
|
||||
|
||||
@TypeConverter fun jsonToReminders(json: String) = jsonToReminders(JSONArray(json))
|
||||
|
||||
fun jsonToReminders(jsonArray: JSONArray): List<Reminder> {
|
||||
return jsonArray.iterable<JSONObject>().map { jsonObject ->
|
||||
val id = jsonObject.getLong("id")
|
||||
val dateTime = Date(jsonObject.getLong("dateTime"))
|
||||
val repetition = jsonObject.getSafeString("repetition")?.let { jsonToRepetition(it) }
|
||||
Reminder(id, dateTime, repetition)
|
||||
}
|
||||
}
|
||||
|
||||
@TypeConverter
|
||||
fun repetitionToJson(repetition: Repetition): String {
|
||||
return repetitionToJsonObject(repetition).toString()
|
||||
}
|
||||
|
||||
fun repetitionToJsonObject(repetition: Repetition): JSONObject {
|
||||
val jsonObject = JSONObject()
|
||||
jsonObject.put("value", repetition.value)
|
||||
jsonObject.put("unit", repetition.unit.name) // Store the TimeUnit as a string
|
||||
return jsonObject
|
||||
}
|
||||
|
||||
@TypeConverter
|
||||
fun jsonToRepetition(json: String): Repetition {
|
||||
val jsonObject = JSONObject(json)
|
||||
val value = jsonObject.getInt("value")
|
||||
val unit =
|
||||
RepetitionTimeUnit.valueOf(
|
||||
jsonObject.getString("unit")
|
||||
) // Convert string back to TimeUnit
|
||||
return Repetition(value, unit)
|
||||
}
|
||||
|
||||
private fun getSafeLocalName(jsonObject: JSONObject): String {
|
||||
return try {
|
||||
jsonObject.getString("localName")
|
||||
} catch (e: JSONException) {
|
||||
jsonObject.getString("name")
|
||||
}
|
||||
}
|
||||
|
||||
private fun getSafeOriginalName(jsonObject: JSONObject): String {
|
||||
return try {
|
||||
jsonObject.getString("originalName")
|
||||
} catch (e: JSONException) {
|
||||
getSafeLocalName(jsonObject).substringAfterLast("/")
|
||||
}
|
||||
}
|
||||
|
||||
private fun JSONObject.getSafeBoolean(name: String): Boolean {
|
||||
return try {
|
||||
getBoolean(name)
|
||||
} catch (exception: JSONException) {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
private fun JSONObject.getSafeString(name: String): String? {
|
||||
return try {
|
||||
getString(name)
|
||||
} catch (exception: JSONException) {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
private fun JSONObject.getSafeInt(name: String): Int? {
|
||||
return try {
|
||||
getInt(name)
|
||||
} catch (exception: JSONException) {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
private fun JSONObject.getSafeLong(name: String): Long? {
|
||||
return try {
|
||||
getLong(name)
|
||||
} catch (exception: JSONException) {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
private fun <T> JSONArray.iterable() = Iterable {
|
||||
object : Iterator<T> {
|
||||
var index = 0
|
||||
|
||||
override fun next(): T {
|
||||
val element = get(index)
|
||||
index++
|
||||
return element as T
|
||||
}
|
||||
|
||||
override fun hasNext(): Boolean {
|
||||
return index < length()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
package com.philkes.notallyx.data.model
|
||||
|
||||
import kotlinx.parcelize.Parcelize
|
||||
|
||||
@Parcelize
|
||||
data class FileAttachment(var localName: String, var originalName: String, var mimeType: String) :
|
||||
Attachment
|
|
@ -1,18 +0,0 @@
|
|||
package com.philkes.notallyx.data.model
|
||||
|
||||
import java.io.Serializable
|
||||
|
||||
enum class Folder : Serializable {
|
||||
NOTES,
|
||||
DELETED,
|
||||
ARCHIVED;
|
||||
|
||||
companion object {
|
||||
fun valueOfOrDefault(value: String) =
|
||||
try {
|
||||
valueOf(value)
|
||||
} catch (e: Exception) {
|
||||
NOTES
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,3 +0,0 @@
|
|||
package com.philkes.notallyx.data.model
|
||||
|
||||
class Header(val label: String) : Item
|
|
@ -1,3 +0,0 @@
|
|||
package com.philkes.notallyx.data.model
|
||||
|
||||
sealed interface Item
|
|
@ -1,6 +0,0 @@
|
|||
package com.philkes.notallyx.data.model
|
||||
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
|
||||
@Entity class Label(@PrimaryKey val value: String)
|
|
@ -1,3 +0,0 @@
|
|||
package com.philkes.notallyx.data.model
|
||||
|
||||
class LabelsInBaseNote(val id: Long, val labels: List<String>)
|
|
@ -1,57 +0,0 @@
|
|||
package com.philkes.notallyx.data.model
|
||||
|
||||
data class ListItem(
|
||||
var body: String,
|
||||
var checked: Boolean,
|
||||
var isChild: Boolean,
|
||||
var order: Int?,
|
||||
var children: MutableList<ListItem>,
|
||||
var id: Int = -1,
|
||||
) : Cloneable {
|
||||
|
||||
public override fun clone(): Any {
|
||||
// Deep clone!
|
||||
return ListItem(
|
||||
body,
|
||||
checked,
|
||||
isChild,
|
||||
order,
|
||||
children.map { it.clone() as ListItem }.toMutableList(),
|
||||
id,
|
||||
)
|
||||
}
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this == null && other == null) {
|
||||
return true
|
||||
}
|
||||
if (this != null && other == null) {
|
||||
return false
|
||||
}
|
||||
if (this == null && other != null) {
|
||||
return false
|
||||
}
|
||||
if (other !is ListItem) {
|
||||
return false
|
||||
}
|
||||
return (this.body == other.body &&
|
||||
this.order == other.order &&
|
||||
this.checked == other.checked &&
|
||||
this.isChild == other.isChild)
|
||||
}
|
||||
|
||||
val itemCount: Int
|
||||
get() = children.size + 1
|
||||
|
||||
fun isChildOf(other: ListItem): Boolean {
|
||||
return !other.isChild && other.children.contains(this)
|
||||
}
|
||||
|
||||
override fun toString(): String {
|
||||
return "${if (isChild) " >" else ""}${if (checked) "x" else ""} ${body}${
|
||||
if (children.isNotEmpty()) "(${
|
||||
children.map { it.body }.joinToString(",")
|
||||
})" else ""
|
||||
}"
|
||||
}
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
package com.philkes.notallyx.data.model
|
||||
|
||||
import com.philkes.notallyx.presentation.view.note.listitem.areAllChecked
|
||||
|
||||
operator fun ListItem.plus(list: List<ListItem>): List<ListItem> {
|
||||
return mutableListOf(this) + list
|
||||
}
|
||||
|
||||
fun ListItem.findChild(childId: Int): ListItem? {
|
||||
return this.children.find { child -> child.id == childId }
|
||||
}
|
||||
|
||||
fun ListItem.check(checked: Boolean, checkChildren: Boolean = true) {
|
||||
this.checked = checked
|
||||
if (checkChildren) {
|
||||
this.children.forEach { child -> child.checked = checked }
|
||||
}
|
||||
}
|
||||
|
||||
fun ListItem.shouldParentBeUnchecked(): Boolean {
|
||||
return children.isNotEmpty() && !children.areAllChecked() && checked
|
||||
}
|
||||
|
||||
fun ListItem.shouldParentBeChecked(): Boolean {
|
||||
return children.isNotEmpty() && children.areAllChecked() && !checked
|
||||
}
|
|
@ -1,322 +0,0 @@
|
|||
package com.philkes.notallyx.data.model
|
||||
|
||||
import android.content.Context
|
||||
import android.text.Html
|
||||
import androidx.core.text.toHtml
|
||||
import com.philkes.notallyx.R
|
||||
import com.philkes.notallyx.data.dao.NoteIdReminder
|
||||
import com.philkes.notallyx.data.model.BaseNote.Companion.COLOR_DEFAULT
|
||||
import com.philkes.notallyx.presentation.applySpans
|
||||
import java.text.DateFormat
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Calendar
|
||||
import java.util.Date
|
||||
import java.util.Locale
|
||||
import org.json.JSONArray
|
||||
import org.json.JSONException
|
||||
import org.json.JSONObject
|
||||
|
||||
private const val NOTE_URL_PREFIX = "note://"
|
||||
private val NOTE_URL_POSTFIX_NOTE = "/${Type.NOTE.name}"
|
||||
private val NOTE_URL_POSTFIX_LIST = "/${Type.LIST.name}"
|
||||
|
||||
fun CharSequence?.isNoteUrl(): Boolean {
|
||||
return this?.let { startsWith(NOTE_URL_PREFIX) } ?: false
|
||||
}
|
||||
|
||||
fun Long.createNoteUrl(type: Type): String {
|
||||
val postfix =
|
||||
when (type) {
|
||||
Type.LIST -> NOTE_URL_POSTFIX_LIST
|
||||
Type.NOTE -> NOTE_URL_POSTFIX_NOTE
|
||||
}
|
||||
return "$NOTE_URL_PREFIX$this$postfix"
|
||||
}
|
||||
|
||||
fun String.getNoteIdFromUrl(): Long {
|
||||
return substringAfter(NOTE_URL_PREFIX).substringBefore("/").toLong()
|
||||
}
|
||||
|
||||
fun String.getNoteTypeFromUrl(): Type {
|
||||
return Type.valueOf(substringAfterLast("/"))
|
||||
}
|
||||
|
||||
val FileAttachment.isImage: Boolean
|
||||
get() {
|
||||
return mimeType.isImageMimeType
|
||||
}
|
||||
val String.isImageMimeType: Boolean
|
||||
get() {
|
||||
return startsWith("image/")
|
||||
}
|
||||
val String.isAudioMimeType: Boolean
|
||||
get() {
|
||||
return startsWith("audio/")
|
||||
}
|
||||
|
||||
fun BaseNote.toTxt(includeTitle: Boolean = true, includeCreationDate: Boolean = true) =
|
||||
buildString {
|
||||
val date = DateFormat.getDateInstance(DateFormat.FULL).format(timestamp)
|
||||
val body =
|
||||
when (type) {
|
||||
Type.NOTE -> body
|
||||
Type.LIST -> items.toText()
|
||||
}
|
||||
|
||||
if (title.isNotEmpty() && includeTitle) {
|
||||
append("${title}\n\n")
|
||||
}
|
||||
if (includeCreationDate) {
|
||||
append("$date\n\n")
|
||||
}
|
||||
append(body)
|
||||
return toString()
|
||||
}
|
||||
|
||||
fun BaseNote.toJson(): String {
|
||||
val jsonObject =
|
||||
JSONObject()
|
||||
.put("type", type.name)
|
||||
.put("color", color)
|
||||
.put("title", title)
|
||||
.put("pinned", pinned)
|
||||
.put("timestamp", timestamp)
|
||||
.put("modifiedTimestamp", modifiedTimestamp)
|
||||
.put("labels", JSONArray(labels))
|
||||
|
||||
when (type) {
|
||||
Type.NOTE -> {
|
||||
jsonObject.put("body", body)
|
||||
jsonObject.put("spans", Converters.spansToJSONArray(spans))
|
||||
}
|
||||
|
||||
Type.LIST -> {
|
||||
jsonObject.put("items", Converters.itemsToJSONArray(items))
|
||||
}
|
||||
}
|
||||
jsonObject.put("reminders", Converters.remindersToJSONArray(reminders))
|
||||
jsonObject.put("viewMode", viewMode.name)
|
||||
return jsonObject.toString(2)
|
||||
}
|
||||
|
||||
fun String.toBaseNote(): BaseNote {
|
||||
val jsonObject = JSONObject(this)
|
||||
val id = jsonObject.getLongOrDefault("id", -1L)
|
||||
val type = Type.valueOfOrDefault(jsonObject.getStringOrDefault("type", Type.NOTE.name))
|
||||
val folder = Folder.valueOfOrDefault(jsonObject.getStringOrDefault("folder", Folder.NOTES.name))
|
||||
val color =
|
||||
jsonObject.getStringOrDefault("color", COLOR_DEFAULT).takeIf { it.isValid() }
|
||||
?: COLOR_DEFAULT
|
||||
val title = jsonObject.getStringOrDefault("title", "")
|
||||
val pinned = jsonObject.getBooleanOrDefault("pinned", false)
|
||||
val timestamp = jsonObject.getLongOrDefault("timestamp", System.currentTimeMillis())
|
||||
val modifiedTimestamp = jsonObject.getLongOrDefault("modifiedTimestamp", timestamp)
|
||||
val labels = Converters.jsonToLabels(jsonObject.getArrayOrEmpty("labels"))
|
||||
val body = jsonObject.getStringOrDefault("body", "")
|
||||
val spans = Converters.jsonToSpans(jsonObject.getArrayOrEmpty("spans"))
|
||||
val items = Converters.jsonToItems(jsonObject.getArrayOrEmpty("items"))
|
||||
val images = Converters.jsonToFiles(jsonObject.getArrayOrEmpty("images"))
|
||||
val files = Converters.jsonToFiles(jsonObject.getArrayOrEmpty("files"))
|
||||
val audios = Converters.jsonToAudios(jsonObject.getArrayOrEmpty("audios"))
|
||||
val reminders = Converters.jsonToReminders(jsonObject.getArrayOrEmpty("reminders"))
|
||||
val viewMode = NoteViewMode.valueOfOrDefault(jsonObject.getStringOrDefault("viewMode", ""))
|
||||
return BaseNote(
|
||||
id,
|
||||
type,
|
||||
folder,
|
||||
color,
|
||||
title,
|
||||
pinned,
|
||||
timestamp,
|
||||
modifiedTimestamp,
|
||||
labels,
|
||||
body,
|
||||
spans,
|
||||
items,
|
||||
images,
|
||||
files,
|
||||
audios,
|
||||
reminders,
|
||||
viewMode,
|
||||
)
|
||||
}
|
||||
|
||||
private fun JSONObject.getStringOrDefault(key: String, defaultValue: String): String {
|
||||
return try {
|
||||
getString(key)
|
||||
} catch (exception: JSONException) {
|
||||
defaultValue
|
||||
}
|
||||
}
|
||||
|
||||
private fun JSONObject.getArrayOrEmpty(key: String): JSONArray {
|
||||
return try {
|
||||
getJSONArray(key)
|
||||
} catch (exception: JSONException) {
|
||||
JSONArray("[]")
|
||||
}
|
||||
}
|
||||
|
||||
private fun JSONObject.getBooleanOrDefault(key: String, defaultValue: Boolean): Boolean {
|
||||
return try {
|
||||
getBoolean(key)
|
||||
} catch (exception: JSONException) {
|
||||
defaultValue
|
||||
}
|
||||
}
|
||||
|
||||
private fun JSONObject.getLongOrDefault(key: String, defaultValue: Long): Long {
|
||||
return try {
|
||||
getLong(key)
|
||||
} catch (exception: JSONException) {
|
||||
defaultValue
|
||||
}
|
||||
}
|
||||
|
||||
fun BaseNote.toHtml(showDateCreated: Boolean) = buildString {
|
||||
val date = DateFormat.getDateInstance(DateFormat.FULL).format(timestamp)
|
||||
val title = Html.escapeHtml(title)
|
||||
|
||||
append("<!DOCTYPE html>")
|
||||
append("<html><head>")
|
||||
append("<meta charset=\"UTF-8\"><title>$title</title>")
|
||||
append("</head><body>")
|
||||
append("<h2>$title</h2>")
|
||||
|
||||
if (showDateCreated) {
|
||||
append("<p>$date</p>")
|
||||
}
|
||||
|
||||
when (type) {
|
||||
Type.NOTE -> {
|
||||
val body = body.applySpans(spans).toHtml()
|
||||
append(body)
|
||||
}
|
||||
|
||||
Type.LIST -> {
|
||||
append("<ol style=\"list-style: none; padding: 0;\">")
|
||||
items.forEach { item ->
|
||||
val body = Html.escapeHtml(item.body)
|
||||
val checked = if (item.checked) "checked" else ""
|
||||
val child = if (item.isChild) "style=\"margin-left: 20px\"" else ""
|
||||
append("<li><input type=\"checkbox\" $child $checked>$body</li>")
|
||||
}
|
||||
append("</ol>")
|
||||
}
|
||||
}
|
||||
append("</body></html>")
|
||||
}
|
||||
|
||||
fun List<BaseNote>.toNoteIdReminders() = map { NoteIdReminder(it.id, it.reminders) }
|
||||
|
||||
fun BaseNote.attachmentsDifferFrom(other: BaseNote): Boolean {
|
||||
return files.size != other.files.size ||
|
||||
files.any { file -> other.files.none { it.localName == file.localName } } ||
|
||||
other.files.any { file -> files.none { it.localName == file.localName } } ||
|
||||
images.any { image -> other.images.none { it.localName == image.localName } } ||
|
||||
other.images.any { image -> images.none { it.localName == image.localName } } ||
|
||||
audios.any { audio -> other.audios.none { it.name == audio.name } } ||
|
||||
other.audios.any { audio -> audios.none { it.name == audio.name } }
|
||||
}
|
||||
|
||||
fun Date.toText(): String = SimpleDateFormat("dd.MM.yyyy HH:mm", Locale.getDefault()).format(this)
|
||||
|
||||
fun Repetition.toText(context: Context): String =
|
||||
when {
|
||||
value == 1 && unit == RepetitionTimeUnit.DAYS -> context.getString(R.string.daily)
|
||||
value == 1 && unit == RepetitionTimeUnit.WEEKS -> context.getString(R.string.weekly)
|
||||
value == 1 && unit == RepetitionTimeUnit.MONTHS -> context.getString(R.string.monthly)
|
||||
value == 1 && unit == RepetitionTimeUnit.YEARS -> context.getString(R.string.yearly)
|
||||
else -> "${context.getString(R.string.every)} $value ${unit.toText(context)}"
|
||||
}
|
||||
|
||||
private fun RepetitionTimeUnit.toText(context: Context): String {
|
||||
val resId =
|
||||
when (this) {
|
||||
RepetitionTimeUnit.MINUTES -> R.string.minutes
|
||||
RepetitionTimeUnit.HOURS -> R.string.hours
|
||||
RepetitionTimeUnit.DAYS -> R.string.days
|
||||
RepetitionTimeUnit.WEEKS -> R.string.weeks
|
||||
RepetitionTimeUnit.MONTHS -> R.string.months
|
||||
RepetitionTimeUnit.YEARS -> R.string.years
|
||||
}
|
||||
return context.getString(resId)
|
||||
}
|
||||
|
||||
fun Collection<Reminder>.copy() = map { it.copy() }
|
||||
|
||||
fun RepetitionTimeUnit.toCalendarField(): Int {
|
||||
return when (this) {
|
||||
RepetitionTimeUnit.MINUTES -> Calendar.MINUTE
|
||||
RepetitionTimeUnit.HOURS -> Calendar.HOUR
|
||||
RepetitionTimeUnit.DAYS -> Calendar.DAY_OF_MONTH
|
||||
RepetitionTimeUnit.WEEKS -> Calendar.WEEK_OF_YEAR
|
||||
RepetitionTimeUnit.MONTHS -> Calendar.MONTH
|
||||
RepetitionTimeUnit.YEARS -> Calendar.YEAR
|
||||
}
|
||||
}
|
||||
|
||||
fun Reminder.nextNotification(from: Date = Date()): Date? {
|
||||
if (from.before(dateTime)) {
|
||||
return dateTime
|
||||
}
|
||||
if (repetition == null) {
|
||||
return null
|
||||
}
|
||||
val timeDifferenceMillis: Long = from.time - dateTime.time
|
||||
val intervalsPassed = timeDifferenceMillis / repetition!!.toMillis()
|
||||
val unitsUntilNext = ((repetition!!.value) * (intervalsPassed + 1)).toInt()
|
||||
val reminderStart = dateTime.toCalendar()
|
||||
reminderStart.add(repetition!!.unit.toCalendarField(), unitsUntilNext)
|
||||
return reminderStart.time
|
||||
}
|
||||
|
||||
fun Reminder.nextRepetition(from: Date = Date()): Date? {
|
||||
if (repetition == null) {
|
||||
return null
|
||||
}
|
||||
return nextNotification(from)
|
||||
}
|
||||
|
||||
fun Reminder.hasUpcomingNotification() = !(dateTime.before(Date()) && repetition == null)
|
||||
|
||||
fun Repetition.toMillis(): Long {
|
||||
return Calendar.getInstance()
|
||||
.apply {
|
||||
timeInMillis = 0
|
||||
add(unit.toCalendarField(), value)
|
||||
}
|
||||
.timeInMillis
|
||||
}
|
||||
|
||||
fun Collection<Reminder>.hasAnyUpcomingNotifications(): Boolean {
|
||||
return any { it.hasUpcomingNotification() }
|
||||
}
|
||||
|
||||
fun Collection<Reminder>.findNextNotificationDate(): Date? {
|
||||
return mapNotNull { it.nextNotification() }.minByOrNull { it }
|
||||
}
|
||||
|
||||
fun Date.toCalendar() = Calendar.getInstance().apply { timeInMillis = this@toCalendar.time }
|
||||
|
||||
fun List<ListItem>.toText() = buildString {
|
||||
for (item in this@toText) {
|
||||
val check = if (item.checked) "[✓]" else "[ ]"
|
||||
val childIndentation = if (item.isChild) " " else ""
|
||||
appendLine("$childIndentation$check ${item.body}")
|
||||
}
|
||||
}
|
||||
|
||||
fun Collection<ListItem>.deepCopy() = map { it.copy(children = mutableListOf()) }
|
||||
|
||||
fun ColorString.isValid() =
|
||||
when (this) {
|
||||
COLOR_DEFAULT -> true
|
||||
else ->
|
||||
try {
|
||||
android.graphics.Color.parseColor(this)
|
||||
true
|
||||
} catch (e: Exception) {
|
||||
false
|
||||
}
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
package com.philkes.notallyx.data.model
|
||||
|
||||
import com.philkes.notallyx.R
|
||||
import com.philkes.notallyx.presentation.viewmodel.preference.StaticTextProvider
|
||||
|
||||
enum class NoteViewMode(override val textResId: Int) : StaticTextProvider {
|
||||
READ_ONLY(R.string.read_only),
|
||||
EDIT(R.string.edit);
|
||||
|
||||
companion object {
|
||||
fun valueOfOrDefault(value: String) =
|
||||
try {
|
||||
NoteViewMode.valueOf(value)
|
||||
} catch (e: Exception) {
|
||||
EDIT
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
package com.philkes.notallyx.data.model
|
||||
|
||||
import android.os.Parcelable
|
||||
import java.util.Date
|
||||
import kotlinx.parcelize.Parcelize
|
||||
|
||||
@Parcelize
|
||||
data class Reminder(var id: Long, var dateTime: Date, var repetition: Repetition?) : Parcelable
|
||||
|
||||
@Parcelize data class Repetition(var value: Int, var unit: RepetitionTimeUnit) : Parcelable
|
||||
|
||||
enum class RepetitionTimeUnit {
|
||||
MINUTES,
|
||||
HOURS,
|
||||
DAYS,
|
||||
WEEKS,
|
||||
MONTHS,
|
||||
YEARS,
|
||||
}
|
|
@ -1,36 +0,0 @@
|
|||
package com.philkes.notallyx.data.model
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.Observer
|
||||
import com.philkes.notallyx.data.dao.BaseNoteDao
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
class SearchResult(
|
||||
private val scope: CoroutineScope,
|
||||
var baseNoteDao: BaseNoteDao,
|
||||
transform: (List<BaseNote>) -> List<Item>,
|
||||
) : LiveData<List<Item>>() {
|
||||
|
||||
private var job: Job? = null
|
||||
private var liveData: LiveData<List<BaseNote>>? = null
|
||||
private val observer = Observer<List<BaseNote>> { list -> value = transform(list) }
|
||||
|
||||
init {
|
||||
value = emptyList()
|
||||
}
|
||||
|
||||
fun fetch(keyword: String, folder: Folder, label: String?) {
|
||||
job?.cancel()
|
||||
liveData?.removeObserver(observer)
|
||||
job =
|
||||
scope.launch {
|
||||
liveData = baseNoteDao.getBaseNotesByKeyword(keyword, folder, label)
|
||||
// if (keyword.isNotEmpty())
|
||||
// baseNoteDao.getBaseNotesByKeyword(keyword, folder, label)
|
||||
// else baseNoteDao.getFrom(folder)
|
||||
liveData?.observeForever(observer)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
package com.philkes.notallyx.data.model
|
||||
|
||||
data class SpanRepresentation(
|
||||
var start: Int,
|
||||
var end: Int,
|
||||
var bold: Boolean = false,
|
||||
var link: Boolean = false,
|
||||
var linkData: String? = null,
|
||||
var italic: Boolean = false,
|
||||
var monospace: Boolean = false,
|
||||
var strikethrough: Boolean = false,
|
||||
) {
|
||||
|
||||
fun isNotUseless(): Boolean {
|
||||
return bold || link || italic || monospace || strikethrough
|
||||
}
|
||||
|
||||
fun isEqualInSize(representation: SpanRepresentation): Boolean {
|
||||
return start == representation.start && end == representation.end
|
||||
}
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
package com.philkes.notallyx.data.model
|
||||
|
||||
enum class Type {
|
||||
NOTE,
|
||||
LIST;
|
||||
|
||||
companion object {
|
||||
fun valueOfOrDefault(value: String) =
|
||||
try {
|
||||
Type.valueOf(value)
|
||||
} catch (e: Exception) {
|
||||
NOTE
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,986 +0,0 @@
|
|||
package com.philkes.notallyx.presentation
|
||||
|
||||
import android.Manifest
|
||||
import android.app.Activity
|
||||
import android.app.AlarmManager
|
||||
import android.content.Context
|
||||
import android.content.DialogInterface
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.content.res.ColorStateList
|
||||
import android.content.res.Resources
|
||||
import android.graphics.PorterDuff
|
||||
import android.graphics.Typeface
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.provider.Settings
|
||||
import android.text.Editable
|
||||
import android.text.InputType
|
||||
import android.text.Spannable
|
||||
import android.text.Spanned
|
||||
import android.text.TextWatcher
|
||||
import android.text.style.CharacterStyle
|
||||
import android.text.style.StrikethroughSpan
|
||||
import android.text.style.StyleSpan
|
||||
import android.text.style.SuggestionSpan
|
||||
import android.text.style.TypefaceSpan
|
||||
import android.text.style.URLSpan
|
||||
import android.util.TypedValue
|
||||
import android.view.ContextThemeWrapper
|
||||
import android.view.KeyEvent
|
||||
import android.view.LayoutInflater
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.Window
|
||||
import android.view.WindowManager
|
||||
import android.view.WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE
|
||||
import android.view.inputmethod.EditorInfo
|
||||
import android.view.inputmethod.InputMethodManager
|
||||
import android.widget.Button
|
||||
import android.widget.CompoundButton
|
||||
import android.widget.EditText
|
||||
import android.widget.ImageButton
|
||||
import android.widget.ImageView
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.RadioButton
|
||||
import android.widget.RadioGroup
|
||||
import android.widget.TextView
|
||||
import android.widget.Toast
|
||||
import androidx.activity.result.ActivityResultLauncher
|
||||
import androidx.annotation.AttrRes
|
||||
import androidx.annotation.ColorInt
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.appcompat.widget.AppCompatTextView
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.content.getSystemService
|
||||
import androidx.core.graphics.ColorUtils
|
||||
import androidx.core.graphics.drawable.DrawableCompat
|
||||
import androidx.core.text.getSpans
|
||||
import androidx.core.view.WindowInsetsControllerCompat
|
||||
import androidx.core.view.marginBottom
|
||||
import androidx.core.view.marginTop
|
||||
import androidx.core.view.setPadding
|
||||
import androidx.core.view.updatePadding
|
||||
import androidx.core.widget.TextViewCompat
|
||||
import androidx.core.widget.doAfterTextChanged
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.LifecycleOwner
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MediatorLiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.recyclerview.widget.DividerItemDecoration
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.google.android.material.button.MaterialButton
|
||||
import com.google.android.material.card.MaterialCardView
|
||||
import com.google.android.material.checkbox.MaterialCheckBox
|
||||
import com.google.android.material.chip.Chip
|
||||
import com.google.android.material.chip.ChipGroup
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import com.google.android.material.shape.MaterialShapeDrawable
|
||||
import com.google.android.material.shape.RelativeCornerSize
|
||||
import com.google.android.material.shape.RoundedCornerTreatment
|
||||
import com.google.android.material.shape.ShapeAppearanceModel
|
||||
import com.google.android.material.textfield.MaterialAutoCompleteTextView
|
||||
import com.philkes.notallyx.R
|
||||
import com.philkes.notallyx.data.imports.ImportProgress
|
||||
import com.philkes.notallyx.data.imports.ImportStage
|
||||
import com.philkes.notallyx.data.model.BaseNote
|
||||
import com.philkes.notallyx.data.model.Folder
|
||||
import com.philkes.notallyx.data.model.SpanRepresentation
|
||||
import com.philkes.notallyx.databinding.DialogInputBinding
|
||||
import com.philkes.notallyx.databinding.DialogProgressBinding
|
||||
import com.philkes.notallyx.databinding.LabelBinding
|
||||
import com.philkes.notallyx.presentation.activity.main.MainActivity
|
||||
import com.philkes.notallyx.presentation.view.misc.NotNullLiveData
|
||||
import com.philkes.notallyx.presentation.view.misc.Progress
|
||||
import com.philkes.notallyx.presentation.view.misc.StylableEditTextWithHistory
|
||||
import com.philkes.notallyx.presentation.view.note.listitem.ListManager
|
||||
import com.philkes.notallyx.presentation.view.note.listitem.adapter.ListItemVH
|
||||
import com.philkes.notallyx.presentation.viewmodel.BaseNoteModel
|
||||
import com.philkes.notallyx.presentation.viewmodel.preference.DateFormat
|
||||
import com.philkes.notallyx.presentation.viewmodel.preference.TextSize
|
||||
import com.philkes.notallyx.utils.changehistory.ChangeHistory
|
||||
import com.philkes.notallyx.utils.changehistory.EditTextState
|
||||
import com.philkes.notallyx.utils.changehistory.EditTextWithHistoryChange
|
||||
import com.philkes.notallyx.utils.getUrl
|
||||
import java.util.Date
|
||||
import me.zhanghai.android.fastscroll.FastScrollerBuilder
|
||||
import org.ocpsoft.prettytime.PrettyTime
|
||||
|
||||
/**
|
||||
* For some reason, this method crashes sometimes with an IndexOutOfBoundsException that I've not
|
||||
* been able to replicate. When this happens, to prevent the entire app from crashing and becoming
|
||||
* unusable, the exception is suppressed.
|
||||
*/
|
||||
fun String.applySpans(representations: List<SpanRepresentation>): Editable {
|
||||
val editable = Editable.Factory.getInstance().newEditable(this)
|
||||
representations.forEach { (start, end, bold, link, linkData, italic, monospace, strikethrough)
|
||||
->
|
||||
try {
|
||||
if (bold) {
|
||||
editable.setSpan(StyleSpan(Typeface.BOLD), start, end)
|
||||
}
|
||||
if (italic) {
|
||||
editable.setSpan(StyleSpan(Typeface.ITALIC), start, end)
|
||||
}
|
||||
if (link) {
|
||||
val url = linkData ?: getUrl(start, end)
|
||||
editable.setSpan(URLSpan(url), start, end)
|
||||
}
|
||||
if (monospace) {
|
||||
editable.setSpan(TypefaceSpan("monospace"), start, end)
|
||||
}
|
||||
if (strikethrough) {
|
||||
editable.setSpan(StrikethroughSpan(), start, end)
|
||||
}
|
||||
} catch (exception: Exception) {
|
||||
exception.printStackTrace()
|
||||
}
|
||||
}
|
||||
return editable
|
||||
}
|
||||
|
||||
/**
|
||||
* Adjusts or removes spans based on the selection range.
|
||||
*
|
||||
* @param selectionStart the start index of the selection
|
||||
* @param selectionEnd the end index of the selection
|
||||
*/
|
||||
fun Editable.removeSelectionFromSpans(
|
||||
selectionStart: Int,
|
||||
selectionEnd: Int,
|
||||
spans: Collection<CharacterStyle> =
|
||||
getSpans(selectionStart, selectionEnd, CharacterStyle::class.java).toList(),
|
||||
) {
|
||||
for (span in spans) {
|
||||
val spanStart = getSpanStart(span)
|
||||
val spanEnd = getSpanEnd(span)
|
||||
|
||||
when {
|
||||
// Case 1: Selection is exactly the span's range (remove entire span)
|
||||
selectionStart <= spanStart && selectionEnd >= spanEnd -> {
|
||||
removeSpan(span)
|
||||
}
|
||||
// Case 2: Selection is part of the span (split the span)
|
||||
selectionStart > spanStart && selectionEnd < spanEnd -> {
|
||||
// Remove the original span
|
||||
removeSpan(span)
|
||||
// Reapply two new spans: one for the part before the selection, and one for the
|
||||
// part after
|
||||
setSpan(span, spanStart, selectionStart, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
|
||||
setSpan(span, selectionEnd, spanEnd, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
|
||||
}
|
||||
// Case 3: Selection overlaps the start of the span (trim the span)
|
||||
selectionStart <= spanStart && selectionEnd < spanEnd -> {
|
||||
removeSpan(span)
|
||||
setSpan(span, selectionEnd, spanEnd, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
|
||||
}
|
||||
// Case 4: Selection overlaps the end of the span (trim the span)
|
||||
else -> {
|
||||
removeSpan(span)
|
||||
setSpan(span, spanStart, selectionStart, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun Spannable.setSpan(span: Any, start: Int, end: Int) {
|
||||
if (end <= length) {
|
||||
setSpan(span, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
|
||||
} else setSpan(span, start, length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
|
||||
}
|
||||
|
||||
fun EditText.setOnNextAction(onNext: () -> Unit) {
|
||||
setRawInputType(InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_FLAG_CAP_SENTENCES)
|
||||
|
||||
setOnKeyListener { v, keyCode, event ->
|
||||
if (event.action == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_ENTER) {
|
||||
onNext()
|
||||
return@setOnKeyListener true
|
||||
} else return@setOnKeyListener false
|
||||
}
|
||||
|
||||
setOnEditorActionListener { v, actionId, event ->
|
||||
if (actionId == EditorInfo.IME_ACTION_NEXT) {
|
||||
onNext()
|
||||
return@setOnEditorActionListener true
|
||||
} else return@setOnEditorActionListener false
|
||||
}
|
||||
}
|
||||
|
||||
fun Menu.add(
|
||||
title: Int,
|
||||
drawable: Int,
|
||||
showAsAction: Int = MenuItem.SHOW_AS_ACTION_IF_ROOM,
|
||||
groupId: Int = Menu.NONE,
|
||||
order: Int = Menu.NONE,
|
||||
onClick: (item: MenuItem) -> Unit,
|
||||
): MenuItem {
|
||||
val menuItem =
|
||||
add(groupId, Menu.NONE, order, title).setIcon(drawable).setOnMenuItemClickListener { item ->
|
||||
onClick(item)
|
||||
item.isChecked = true
|
||||
return@setOnMenuItemClickListener false
|
||||
}
|
||||
menuItem.setShowAsAction(showAsAction)
|
||||
return menuItem
|
||||
}
|
||||
|
||||
fun ViewGroup.addIconButton(
|
||||
title: Int,
|
||||
drawable: Int,
|
||||
marginStart: Int = 10,
|
||||
onLongClick: View.OnLongClickListener? = null,
|
||||
onClick: View.OnClickListener? = null,
|
||||
): ImageButton {
|
||||
val view =
|
||||
ImageButton(ContextThemeWrapper(context, R.style.AppTheme)).apply {
|
||||
setImageResource(drawable)
|
||||
contentDescription = context.getString(title)
|
||||
val outValue = TypedValue()
|
||||
context.theme.resolveAttribute(android.R.attr.actionBarItemBackground, outValue, true)
|
||||
setBackgroundResource(outValue.resourceId)
|
||||
setOnLongClickListener(onLongClick)
|
||||
setOnClickListener(onClick)
|
||||
|
||||
scaleType = ImageView.ScaleType.FIT_CENTER
|
||||
adjustViewBounds = true
|
||||
layoutParams =
|
||||
LinearLayout.LayoutParams(
|
||||
LinearLayout.LayoutParams.WRAP_CONTENT,
|
||||
LinearLayout.LayoutParams.MATCH_PARENT,
|
||||
)
|
||||
.apply { setMargins(marginStart.dp, marginTop, 0, marginBottom) }
|
||||
setPadding(8.dp)
|
||||
}
|
||||
addView(view)
|
||||
return view
|
||||
}
|
||||
|
||||
fun TextView.displayFormattedTimestamp(
|
||||
timestamp: Long?,
|
||||
dateFormat: DateFormat,
|
||||
prefixResId: Int? = null,
|
||||
) {
|
||||
if (dateFormat != DateFormat.NONE && timestamp != null) {
|
||||
visibility = View.VISIBLE
|
||||
text =
|
||||
"${prefixResId?.let { getString(it) } ?: ""} ${formatTimestamp(timestamp, dateFormat)}"
|
||||
} else visibility = View.GONE
|
||||
}
|
||||
|
||||
val Int.dp: Int
|
||||
get() = (this * Resources.getSystem().displayMetrics.density + 0.5f).toInt()
|
||||
|
||||
val Float.dp: Int
|
||||
get() = (this * Resources.getSystem().displayMetrics.density + 0.5f).toInt()
|
||||
|
||||
/**
|
||||
* Creates a TextWatcher for an EditText that is part of a list. Everytime the text is changed, a
|
||||
* Change is added to the ChangeHistory.
|
||||
*
|
||||
* @param positionGetter Function to determine the current position of the EditText in the list
|
||||
* (e.g. the current absoluteAdapterPosition when using RecyclerViewer.Adapter)
|
||||
* @param onTextChanged optional text change handler. Returns whether or not the original change
|
||||
* should be ignored or not.
|
||||
*/
|
||||
fun EditText.createListTextWatcherWithHistory(
|
||||
listManager: ListManager,
|
||||
positionGetter: () -> Int,
|
||||
onTextChanged: ((text: CharSequence, start: Int, count: Int) -> Boolean)? = null,
|
||||
) =
|
||||
object : TextWatcher {
|
||||
private var ignoreOriginalChange: Boolean = false
|
||||
private lateinit var textBefore: Editable
|
||||
|
||||
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
|
||||
textBefore = text.clone()
|
||||
}
|
||||
|
||||
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
|
||||
ignoreOriginalChange = onTextChanged?.invoke(s!!, start, count) ?: false
|
||||
}
|
||||
|
||||
override fun afterTextChanged(s: Editable?) {
|
||||
val textAfter = s!!.clone()
|
||||
if (textAfter.hasNotChanged(textBefore)) {
|
||||
return
|
||||
}
|
||||
if (!ignoreOriginalChange) {
|
||||
listManager.changeText(
|
||||
positionGetter.invoke(),
|
||||
EditTextState(textAfter, selectionStart),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun StylableEditTextWithHistory.createTextWatcherWithHistory(
|
||||
changeHistory: ChangeHistory,
|
||||
onTextChanged: ((text: CharSequence, start: Int, count: Int) -> Unit)? = null,
|
||||
updateModel: (text: Editable) -> Unit,
|
||||
) =
|
||||
object : TextWatcher {
|
||||
private lateinit var stateBefore: EditTextState
|
||||
|
||||
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
|
||||
stateBefore = EditTextState(getTextClone(), selectionStart)
|
||||
}
|
||||
|
||||
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
|
||||
onTextChanged?.invoke(s!!, start, count)
|
||||
}
|
||||
|
||||
override fun afterTextChanged(s: Editable?) {
|
||||
val textAfter = requireNotNull(s).clone()
|
||||
if (textAfter.hasNotChanged(stateBefore.text)) {
|
||||
return
|
||||
}
|
||||
updateModel.invoke(textAfter)
|
||||
changeHistory.push(
|
||||
EditTextWithHistoryChange(
|
||||
this@createTextWatcherWithHistory,
|
||||
stateBefore,
|
||||
EditTextState(textAfter, selectionStart),
|
||||
updateModel,
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun Editable.hasNotChanged(before: Editable): Boolean {
|
||||
return toString() == before.toString() && getSpans<SuggestionSpan>().isNotEmpty()
|
||||
}
|
||||
|
||||
fun Editable.clone(): Editable = Editable.Factory.getInstance().newEditable(this)
|
||||
|
||||
fun View.getString(id: Int, vararg formatArgs: String): String {
|
||||
return context.resources.getString(id, *formatArgs)
|
||||
}
|
||||
|
||||
fun View.getQuantityString(id: Int, quantity: Int, vararg formatArgs: Any): String {
|
||||
return context.getQuantityString(id, quantity, *formatArgs)
|
||||
}
|
||||
|
||||
fun Folder.movedToResId(): Int {
|
||||
return when (this) {
|
||||
Folder.DELETED -> R.plurals.deleted_selected_notes
|
||||
Folder.ARCHIVED -> R.plurals.archived_selected_notes
|
||||
Folder.NOTES -> R.plurals.restored_selected_notes
|
||||
}
|
||||
}
|
||||
|
||||
fun RadioGroup.checkedTag(): Any {
|
||||
return this.findViewById<RadioButton?>(this.checkedRadioButtonId).tag
|
||||
}
|
||||
|
||||
fun Context.showKeyboard(view: View) {
|
||||
ContextCompat.getSystemService(this, InputMethodManager::class.java)
|
||||
?.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT)
|
||||
}
|
||||
|
||||
fun Context.hideKeyboard(view: View) {
|
||||
ContextCompat.getSystemService(this, InputMethodManager::class.java)
|
||||
?.hideSoftInputFromWindow(view.windowToken, 0)
|
||||
}
|
||||
|
||||
fun MutableLiveData<out Progress>.setupProgressDialog(activity: Activity, titleId: Int) {
|
||||
setupProgressDialog(activity, activity.layoutInflater, activity as LifecycleOwner, titleId)
|
||||
}
|
||||
|
||||
fun MutableLiveData<out Progress>.setupProgressDialog(fragment: Fragment, titleId: Int) {
|
||||
setupProgressDialog(
|
||||
fragment.requireContext(),
|
||||
fragment.layoutInflater,
|
||||
fragment.viewLifecycleOwner,
|
||||
titleId,
|
||||
)
|
||||
}
|
||||
|
||||
fun MutableLiveData<ImportProgress>.setupImportProgressDialog(fragment: Fragment, titleId: Int) {
|
||||
setupProgressDialog(
|
||||
fragment.requireContext(),
|
||||
fragment.layoutInflater,
|
||||
fragment.viewLifecycleOwner,
|
||||
titleId,
|
||||
) { context, binding, progress ->
|
||||
val stageStr =
|
||||
context.getString(
|
||||
when (progress.stage) {
|
||||
ImportStage.IMPORT_NOTES -> R.string.imported_notes
|
||||
ImportStage.EXTRACT_FILES -> R.string.extracted_files
|
||||
ImportStage.IMPORT_FILES -> R.string.imported_files
|
||||
}
|
||||
)
|
||||
binding.Count.text =
|
||||
"${context.getString(R.string.count, progress.current, progress.total)} $stageStr"
|
||||
}
|
||||
}
|
||||
|
||||
fun <T, C> NotNullLiveData<T>.merge(liveData: NotNullLiveData<C>): MediatorLiveData<Pair<T, C>> {
|
||||
return MediatorLiveData<Pair<T, C>>().apply {
|
||||
addSource(this@merge) { value1 -> value = Pair(value1, liveData.value) }
|
||||
addSource(liveData) { value2 -> value = Pair(this@merge.value, value2) }
|
||||
}
|
||||
}
|
||||
|
||||
fun <T, C> NotNullLiveData<T>.merge(liveData: LiveData<C>): MediatorLiveData<Pair<T, C?>> {
|
||||
return MediatorLiveData<Pair<T, C?>>().apply {
|
||||
addSource(this@merge) { value1 -> value = Pair(value1, liveData.value) }
|
||||
addSource(liveData) { value2 -> value = Pair(this@merge.value, value2) }
|
||||
}
|
||||
}
|
||||
|
||||
private fun <T : Progress> MutableLiveData<T>.setupProgressDialog(
|
||||
context: Context,
|
||||
layoutInflater: LayoutInflater,
|
||||
viewLifecycleOwner: LifecycleOwner,
|
||||
titleId: Int,
|
||||
renderProgress: ((context: Context, binding: DialogProgressBinding, progress: T) -> Unit)? =
|
||||
null,
|
||||
) {
|
||||
val dialogBinding = DialogProgressBinding.inflate(layoutInflater)
|
||||
val dialog =
|
||||
MaterialAlertDialogBuilder(context)
|
||||
.setTitle(titleId)
|
||||
.setView(dialogBinding.root)
|
||||
.setCancelable(false)
|
||||
.create()
|
||||
|
||||
observe(viewLifecycleOwner) { progress ->
|
||||
if (progress.inProgress) {
|
||||
if (progress.indeterminate) {
|
||||
dialogBinding.apply {
|
||||
ProgressBar.isIndeterminate = true
|
||||
Count.setText(R.string.calculating)
|
||||
}
|
||||
} else {
|
||||
dialogBinding.apply {
|
||||
ProgressBar.apply {
|
||||
isIndeterminate = false
|
||||
max = progress.total
|
||||
setProgressCompat(progress.current, true)
|
||||
}
|
||||
if (renderProgress == null) {
|
||||
Count.text =
|
||||
context.getString(R.string.count, progress.current, progress.total)
|
||||
} else renderProgress.invoke(context, this, progress)
|
||||
}
|
||||
}
|
||||
dialog.show()
|
||||
} else dialog.dismiss()
|
||||
}
|
||||
}
|
||||
|
||||
fun Activity.checkNotificationPermission(
|
||||
requestCode: Int,
|
||||
alsoCheckAlarmPermission: Boolean = false,
|
||||
alarmPermissionResultLauncher: ActivityResultLauncher<Intent>? = null,
|
||||
onSuccess: () -> Unit,
|
||||
) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||
val permission = Manifest.permission.POST_NOTIFICATIONS
|
||||
if (checkSelfPermission(permission) != PackageManager.PERMISSION_GRANTED) {
|
||||
if (shouldShowRequestPermissionRationale(permission)) {
|
||||
MaterialAlertDialogBuilder(this)
|
||||
.setMessage(R.string.please_grant_notally_notification)
|
||||
.setCancelButton()
|
||||
.setPositiveButton(R.string.continue_) { _, _ ->
|
||||
requestPermissions(arrayOf(permission), requestCode)
|
||||
}
|
||||
.show()
|
||||
} else requestPermissions(arrayOf(permission), requestCode)
|
||||
} else if (alsoCheckAlarmPermission)
|
||||
checkAlarmPermission(alarmPermissionResultLauncher, onSuccess)
|
||||
else onSuccess()
|
||||
} else if (alsoCheckAlarmPermission)
|
||||
checkAlarmPermission(alarmPermissionResultLauncher, onSuccess)
|
||||
else onSuccess()
|
||||
}
|
||||
|
||||
fun Activity.checkAlarmPermission(
|
||||
resultLauncher: ActivityResultLauncher<Intent>?,
|
||||
onSuccess: () -> Unit,
|
||||
) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
if (getSystemService<AlarmManager>()!!.canScheduleExactAlarms()) {
|
||||
onSuccess()
|
||||
} else {
|
||||
MaterialAlertDialogBuilder(this)
|
||||
.setMessage(R.string.please_grant_notally_alarm)
|
||||
.setCancelButton()
|
||||
.setPositiveButton(R.string.continue_) { _, _ ->
|
||||
val intent = Intent(Settings.ACTION_REQUEST_SCHEDULE_EXACT_ALARM)
|
||||
intent.data = Uri.parse("package:$packageName")
|
||||
if (resultLauncher != null) {
|
||||
resultLauncher.launch(intent)
|
||||
} else {
|
||||
startActivity(intent)
|
||||
}
|
||||
}
|
||||
.show()
|
||||
}
|
||||
} else onSuccess()
|
||||
}
|
||||
|
||||
fun Fragment.displayEditLabelDialog(
|
||||
oldValue: String,
|
||||
model: BaseNoteModel,
|
||||
onUpdateLabel: ((oldLabel: String, newLabel: String) -> Unit)? = null,
|
||||
) {
|
||||
requireContext().displayEditLabelDialog(oldValue, model, layoutInflater, onUpdateLabel)
|
||||
}
|
||||
|
||||
fun Activity.displayEditLabelDialog(
|
||||
oldValue: String,
|
||||
model: BaseNoteModel,
|
||||
onUpdateLabel: ((oldLabel: String, newLabel: String) -> Unit)? = null,
|
||||
) {
|
||||
displayEditLabelDialog(oldValue, model, layoutInflater, onUpdateLabel)
|
||||
}
|
||||
|
||||
fun Context.displayEditLabelDialog(
|
||||
oldValue: String,
|
||||
model: BaseNoteModel,
|
||||
layoutInflater: LayoutInflater,
|
||||
onUpdateLabel: ((oldLabel: String, newLabel: String) -> Unit)? = null,
|
||||
) {
|
||||
val dialogBinding = DialogInputBinding.inflate(layoutInflater)
|
||||
dialogBinding.EditText.setText(oldValue)
|
||||
MaterialAlertDialogBuilder(this)
|
||||
.setView(dialogBinding.root)
|
||||
.setTitle(R.string.edit_label)
|
||||
.setCancelButton()
|
||||
.setPositiveButton(R.string.save) { dialog, _ ->
|
||||
val value = dialogBinding.EditText.text.toString().trim()
|
||||
if (value.isNotEmpty()) {
|
||||
model.updateLabel(oldValue, value) { success ->
|
||||
if (success) {
|
||||
onUpdateLabel?.invoke(oldValue, value)
|
||||
dialog.dismiss()
|
||||
} else showToast(R.string.label_exists)
|
||||
}
|
||||
}
|
||||
}
|
||||
.showAndFocus(dialogBinding.EditText, allowFullSize = true) { positiveButton ->
|
||||
dialogBinding.EditText.doAfterTextChanged { text ->
|
||||
positiveButton.isEnabled = !text.isNullOrEmpty()
|
||||
}
|
||||
positiveButton.isEnabled = oldValue.isNotEmpty()
|
||||
}
|
||||
}
|
||||
|
||||
private fun formatTimestamp(timestamp: Long, dateFormat: DateFormat): String {
|
||||
val date = Date(timestamp)
|
||||
return when (dateFormat) {
|
||||
DateFormat.RELATIVE -> PrettyTime().format(date)
|
||||
else -> java.text.DateFormat.getDateInstance(java.text.DateFormat.FULL).format(date)
|
||||
}
|
||||
}
|
||||
|
||||
fun MaterialAlertDialogBuilder.showAndFocus(
|
||||
viewToFocus: View? = null,
|
||||
selectAll: Boolean = false,
|
||||
allowFullSize: Boolean = false,
|
||||
onShowListener: DialogInterface.OnShowListener? = null,
|
||||
applyToPositiveButton: ((positiveButton: Button) -> Unit)? = null,
|
||||
): AlertDialog {
|
||||
if (allowFullSize) {
|
||||
setBackgroundInsetEnd(0)
|
||||
setBackgroundInsetStart(0)
|
||||
setBackgroundInsetBottom(0)
|
||||
setBackgroundInsetTop(0)
|
||||
}
|
||||
return create().apply {
|
||||
viewToFocus?.requestFocus()
|
||||
if (viewToFocus is EditText) {
|
||||
if (selectAll) {
|
||||
viewToFocus.selectAll()
|
||||
}
|
||||
window?.setSoftInputMode(SOFT_INPUT_STATE_VISIBLE)
|
||||
}
|
||||
if (allowFullSize) {
|
||||
window?.setLayout(
|
||||
WindowManager.LayoutParams.MATCH_PARENT,
|
||||
WindowManager.LayoutParams.WRAP_CONTENT,
|
||||
)
|
||||
}
|
||||
onShowListener?.let { setOnShowListener(it) }
|
||||
show()
|
||||
applyToPositiveButton?.let {
|
||||
getButton(AlertDialog.BUTTON_POSITIVE)?.let { positiveButton -> it(positiveButton) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun Context.getQuantityString(id: Int, quantity: Int, vararg formatArgs: Any): String {
|
||||
return resources.getQuantityString(id, quantity, quantity, *formatArgs)
|
||||
}
|
||||
|
||||
@ColorInt
|
||||
fun @receiver:ColorInt Int.withAlpha(alpha: Float): Int {
|
||||
return android.graphics.Color.argb(
|
||||
(255 * alpha).toInt(),
|
||||
android.graphics.Color.red(this),
|
||||
android.graphics.Color.green(this),
|
||||
android.graphics.Color.blue(this),
|
||||
)
|
||||
}
|
||||
|
||||
fun Context.getColorFromAttr(@AttrRes attr: Int): Int {
|
||||
val typedValue = TypedValue()
|
||||
val resolved = theme.resolveAttribute(attr, typedValue, true)
|
||||
if (!resolved) {
|
||||
throw IllegalArgumentException("Attribute not found in current theme")
|
||||
}
|
||||
return if (typedValue.resourceId != 0) {
|
||||
// It's a reference (@color/something), resolve it properly
|
||||
ContextCompat.getColor(this, typedValue.resourceId)
|
||||
} else {
|
||||
// It's a direct color value
|
||||
typedValue.data
|
||||
}
|
||||
}
|
||||
|
||||
fun View.setControlsContrastColorForAllViews(
|
||||
@ColorInt backgroundColor: Int,
|
||||
overwriteBackground: Boolean = true,
|
||||
) {
|
||||
val controlsColor = context.getContrastFontColor(backgroundColor)
|
||||
setControlsColorForAllViews(controlsColor, backgroundColor, overwriteBackground)
|
||||
}
|
||||
|
||||
var counter = 0
|
||||
|
||||
fun View.setControlsColorForAllViews(
|
||||
@ColorInt controlsColor: Int,
|
||||
@ColorInt backgroundColor: Int,
|
||||
overwriteBackground: Boolean = true,
|
||||
) {
|
||||
if (this is ViewGroup) {
|
||||
for (i in 0 until childCount) {
|
||||
val child = getChildAt(i)
|
||||
child.setControlsColorForAllViews(
|
||||
controlsColor,
|
||||
backgroundColor,
|
||||
overwriteBackground,
|
||||
) // Recursive call for nested layouts
|
||||
}
|
||||
if (this is MaterialCardView) {
|
||||
checkedIconTint = ColorStateList.valueOf(controlsColor)
|
||||
val colorStateList =
|
||||
ColorStateList(
|
||||
arrayOf(intArrayOf(android.R.attr.state_checked), intArrayOf()),
|
||||
intArrayOf(controlsColor, controlsColor.withAlpha(0.3f)),
|
||||
)
|
||||
setStrokeColor(colorStateList)
|
||||
}
|
||||
} else {
|
||||
val controlsStateList =
|
||||
ColorStateList(
|
||||
arrayOf(
|
||||
intArrayOf(android.R.attr.state_enabled),
|
||||
intArrayOf(-android.R.attr.state_enabled),
|
||||
),
|
||||
intArrayOf(controlsColor, controlsColor.withAlpha(0.3f)),
|
||||
)
|
||||
if (this is Chip) {
|
||||
setTextColor(controlsStateList)
|
||||
setLinkTextColor(controlsStateList)
|
||||
chipBackgroundColor = ColorStateList.valueOf(backgroundColor)
|
||||
chipIconTint = controlsStateList
|
||||
chipStrokeColor = controlsStateList
|
||||
return
|
||||
}
|
||||
if (this is TextView) {
|
||||
setCompoundDrawableTint(controlsColor)
|
||||
setTextColor(controlsStateList)
|
||||
setLinkTextColor(controlsStateList)
|
||||
if (isTextSelectable || this is EditText) {
|
||||
val highlight = controlsColor.withAlpha(0.4f)
|
||||
setHintTextColor(highlight)
|
||||
highlightColor = highlight
|
||||
setSelectionHandleColor(controlsColor.withAlpha(0.8f))
|
||||
}
|
||||
}
|
||||
if (this is CompoundButton) {
|
||||
buttonTintList = controlsStateList
|
||||
}
|
||||
if (this is MaterialButton) {
|
||||
iconTint = controlsStateList
|
||||
}
|
||||
if (this is ImageButton) {
|
||||
imageTintList = controlsStateList
|
||||
}
|
||||
if (this is MaterialCheckBox) {
|
||||
buttonIconTintList = ColorStateList.valueOf(backgroundColor)
|
||||
}
|
||||
if (overwriteBackground) {
|
||||
backgroundTintList = ColorStateList.valueOf(controlsColor)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun TextView.setSelectionHandleColor(@ColorInt color: Int) {
|
||||
try {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
textSelectHandleLeft?.withTint(color)?.let { setTextSelectHandleLeft(it) }
|
||||
textSelectHandleRight?.withTint(color)?.let { setTextSelectHandleRight(it) }
|
||||
textSelectHandle?.withTint(color)?.let { setTextSelectHandle(it) }
|
||||
textCursorDrawable?.let { DrawableCompat.setTint(it, color) }
|
||||
} else {
|
||||
setSelectHandleColor(color)
|
||||
}
|
||||
} catch (_: Exception) {}
|
||||
}
|
||||
|
||||
/**
|
||||
* This uses light-graylisted Android APIs. Verified that it works in devices running APIs 21
|
||||
* and 28. Source: https://gist.github.com/carranca/7e3414622ad7fc6ef375c8cd8dc840c9
|
||||
*/
|
||||
private fun TextView.setSelectHandleColor(@ColorInt color: Int) {
|
||||
// Retrieve a reference to this text field's android.widget.Editor
|
||||
val editor = getEditor()
|
||||
|
||||
handles.forEach {
|
||||
// Retrieve the field pointing to the drawable currently being used for the select handle
|
||||
val resourceField = TextView::class.java.getDeclaredField(it.resourceFieldName)
|
||||
resourceField.isAccessible = true
|
||||
|
||||
// Retrieve the drawable resource from that field
|
||||
val drawableId = resourceField.getInt(this)
|
||||
val drawable = ContextCompat.getDrawable(context, drawableId)
|
||||
|
||||
// Apply a filter on that drawable with the desired colour
|
||||
drawable?.setColorFilter(color, PorterDuff.Mode.SRC_IN)
|
||||
|
||||
// Override the drawable being used by the Editor with our coloured drawable
|
||||
val selectHandleField = editor.javaClass.getDeclaredField(it.selectHandleFieldName)
|
||||
selectHandleField.isAccessible = true
|
||||
selectHandleField.set(editor, drawable)
|
||||
}
|
||||
}
|
||||
|
||||
private class HandleDescriptor(val resourceFieldName: String, val selectHandleFieldName: String)
|
||||
|
||||
private val handles =
|
||||
arrayOf(
|
||||
HandleDescriptor(
|
||||
resourceFieldName = "mTextSelectHandleRes",
|
||||
selectHandleFieldName = "mSelectHandleCenter",
|
||||
),
|
||||
HandleDescriptor(
|
||||
resourceFieldName = "mTextSelectHandleLeftRes",
|
||||
selectHandleFieldName = "mSelectHandleLeft",
|
||||
),
|
||||
HandleDescriptor(
|
||||
resourceFieldName = "mTextSelectHandleRightRes",
|
||||
selectHandleFieldName = "mSelectHandleRight",
|
||||
),
|
||||
)
|
||||
|
||||
private fun TextView.getEditor(): Any {
|
||||
val editorField = TextView::class.java.getDeclaredField("mEditor")
|
||||
editorField.isAccessible = true
|
||||
return editorField.get(this)
|
||||
}
|
||||
|
||||
fun TextView.setCompoundDrawableTint(@ColorInt color: Int) {
|
||||
compoundDrawablesRelative.forEach { drawable ->
|
||||
drawable?.let { DrawableCompat.setTint(DrawableCompat.wrap(it), color) }
|
||||
}
|
||||
compoundDrawables.forEach { drawable ->
|
||||
drawable?.let { DrawableCompat.setTint(DrawableCompat.wrap(it), color) }
|
||||
}
|
||||
(background as? MaterialShapeDrawable)?.setStrokeTint(color)
|
||||
}
|
||||
|
||||
fun Drawable.withTint(@ColorInt color: Int): Drawable {
|
||||
val oldDrawable = DrawableCompat.unwrap<Drawable>(this)
|
||||
val newDrawable = oldDrawable.constantState?.newDrawable()?.mutate() ?: oldDrawable.mutate()
|
||||
val wrappedDrawable = DrawableCompat.wrap(newDrawable)
|
||||
DrawableCompat.setTint(wrappedDrawable, color)
|
||||
return wrappedDrawable
|
||||
}
|
||||
|
||||
@ColorInt
|
||||
fun Context.getContrastFontColor(@ColorInt backgroundColor: Int): Int {
|
||||
return if (backgroundColor.isLightColor()) ContextCompat.getColor(this, R.color.TextDark)
|
||||
else ContextCompat.getColor(this, R.color.TextLight)
|
||||
}
|
||||
|
||||
fun @receiver:ColorInt Int.isLightColor() = ColorUtils.calculateLuminance(this) > 0.5
|
||||
|
||||
fun MaterialAlertDialogBuilder.setCancelButton(listener: DialogInterface.OnClickListener? = null) =
|
||||
setNegativeButton(R.string.cancel, listener)
|
||||
|
||||
fun Fragment.showDialog(
|
||||
messageResId: Int,
|
||||
positiveButtonTextResId: Int,
|
||||
onPositiveButtonClickListener: DialogInterface.OnClickListener,
|
||||
) =
|
||||
requireContext()
|
||||
.showDialog(messageResId, positiveButtonTextResId, onPositiveButtonClickListener)
|
||||
|
||||
fun Context.showDialog(
|
||||
messageResId: Int,
|
||||
positiveButtonTextResId: Int,
|
||||
onPositiveButtonClickListener: DialogInterface.OnClickListener,
|
||||
) {
|
||||
MaterialAlertDialogBuilder(this)
|
||||
.setMessage(messageResId)
|
||||
.setPositiveButton(positiveButtonTextResId, onPositiveButtonClickListener)
|
||||
.setCancelButton()
|
||||
.show()
|
||||
}
|
||||
|
||||
fun Fragment.showToast(messageResId: Int) = requireContext().showToast(messageResId)
|
||||
|
||||
fun Context.showToast(messageResId: Int) =
|
||||
ContextCompat.getMainExecutor(this).execute {
|
||||
Toast.makeText(this, messageResId, Toast.LENGTH_LONG).show()
|
||||
}
|
||||
|
||||
fun Context.showToast(message: CharSequence) =
|
||||
ContextCompat.getMainExecutor(this).execute {
|
||||
Toast.makeText(this, message, Toast.LENGTH_LONG).show()
|
||||
}
|
||||
|
||||
fun Context.restartApplication(
|
||||
fragmentIdToOpen: Int? = null,
|
||||
extra: Pair<String, Boolean>? = null,
|
||||
) {
|
||||
val intent = packageManager.getLaunchIntentForPackage(packageName)
|
||||
val componentName = intent!!.component
|
||||
val mainIntent =
|
||||
Intent.makeRestartActivityTask(componentName).apply {
|
||||
fragmentIdToOpen?.let { putExtra(MainActivity.EXTRA_FRAGMENT_TO_OPEN, it) }
|
||||
extra?.let { (key, value) -> putExtra(key, value) }
|
||||
}
|
||||
mainIntent.setPackage(packageName)
|
||||
startActivity(mainIntent)
|
||||
Runtime.getRuntime().exit(0)
|
||||
}
|
||||
|
||||
@ColorInt
|
||||
fun Context.extractColor(color: String): Int {
|
||||
return when (color) {
|
||||
BaseNote.COLOR_DEFAULT -> return getColorFromAttr(R.attr.colorSurface)
|
||||
else -> android.graphics.Color.parseColor(color)
|
||||
}
|
||||
}
|
||||
|
||||
fun ViewGroup.addFastScroll(context: Context) {
|
||||
FastScrollerBuilder(this)
|
||||
.useMd2Style()
|
||||
.setTrackDrawable(ContextCompat.getDrawable(context, R.drawable.scroll_track)!!)
|
||||
.setPadding(0, 0, 2.dp, 0)
|
||||
.build()
|
||||
}
|
||||
|
||||
fun Window.setLightStatusAndNavBar(value: Boolean, view: View = decorView) {
|
||||
val windowInsetsControllerCompat = WindowInsetsControllerCompat(this, view)
|
||||
windowInsetsControllerCompat.isAppearanceLightStatusBars = value
|
||||
windowInsetsControllerCompat.isAppearanceLightNavigationBars = value
|
||||
}
|
||||
|
||||
fun ChipGroup.bindLabels(
|
||||
labels: List<String>,
|
||||
textSize: TextSize,
|
||||
paddingTop: Boolean,
|
||||
color: Int? = null,
|
||||
onClick: ((label: String) -> Unit)? = null,
|
||||
onLongClick: ((label: String) -> Unit)? = null,
|
||||
) {
|
||||
if (labels.isEmpty()) {
|
||||
visibility = View.GONE
|
||||
} else {
|
||||
apply {
|
||||
visibility = View.VISIBLE
|
||||
removeAllViews()
|
||||
updatePadding(top = if (paddingTop) 8.dp else 0)
|
||||
}
|
||||
val inflater = LayoutInflater.from(context)
|
||||
val labelSize = textSize.displayBodySize
|
||||
for (label in labels) {
|
||||
LabelBinding.inflate(inflater, this, true).root.apply {
|
||||
background = getOutlinedDrawable(this@bindLabels.context)
|
||||
setTextSize(TypedValue.COMPLEX_UNIT_SP, labelSize)
|
||||
text = label
|
||||
color?.let { setControlsContrastColorForAllViews(it) }
|
||||
onClick?.let { setOnClickListener { it(label) } }
|
||||
onLongClick?.let {
|
||||
setOnLongClickListener {
|
||||
it(label)
|
||||
true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun getOutlinedDrawable(context: Context): MaterialShapeDrawable {
|
||||
val model =
|
||||
ShapeAppearanceModel.builder()
|
||||
.setAllCorners(RoundedCornerTreatment())
|
||||
.setAllCornerSizes(RelativeCornerSize(0.5f))
|
||||
.build()
|
||||
|
||||
return MaterialShapeDrawable(model).apply {
|
||||
fillColor = ColorStateList.valueOf(0)
|
||||
strokeWidth = context.resources.displayMetrics.density
|
||||
strokeColor = ContextCompat.getColorStateList(context, R.color.chip_stroke)
|
||||
}
|
||||
}
|
||||
|
||||
fun RecyclerView.initListView(context: Context) {
|
||||
setHasFixedSize(true)
|
||||
layoutManager = LinearLayoutManager(context)
|
||||
addItemDecoration(DividerItemDecoration(context, RecyclerView.VERTICAL))
|
||||
setPadding(0, 0, 0, 0)
|
||||
}
|
||||
|
||||
val RecyclerView.focusedViewHolder
|
||||
get() =
|
||||
focusedChild?.let { view ->
|
||||
val position = getChildAdapterPosition(view)
|
||||
if (position == RecyclerView.NO_POSITION) {
|
||||
null
|
||||
} else {
|
||||
findViewHolderForAdapterPosition(position)
|
||||
}
|
||||
}
|
||||
|
||||
fun RecyclerView.showKeyboardOnFocusedItem() {
|
||||
(focusedViewHolder as? ListItemVH)?.let {
|
||||
it.binding.root.context?.showKeyboard(it.binding.EditText)
|
||||
}
|
||||
}
|
||||
|
||||
fun RecyclerView.hideKeyboardOnFocusedItem() {
|
||||
(focusedViewHolder as? ListItemVH)?.let {
|
||||
it.binding.root.context?.hideKeyboard(it.binding.EditText)
|
||||
}
|
||||
}
|
||||
|
||||
fun MaterialAutoCompleteTextView.select(value: CharSequence) {
|
||||
setText(value, false)
|
||||
}
|
||||
|
||||
fun Context.createTextView(textResId: Int, padding: Int = 16.dp): TextView {
|
||||
return AppCompatTextView(this).apply {
|
||||
setText(textResId)
|
||||
TextViewCompat.setTextAppearance(
|
||||
this,
|
||||
android.R.style.TextAppearance_Material_DialogWindowTitle,
|
||||
)
|
||||
updatePadding(padding, padding, padding, padding)
|
||||
maxLines = Integer.MAX_VALUE
|
||||
ellipsize = null
|
||||
}
|
||||
}
|
|
@ -1,43 +0,0 @@
|
|||
package com.philkes.notallyx.presentation.activity
|
||||
|
||||
import android.appwidget.AppWidgetManager
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import com.philkes.notallyx.data.model.BaseNote
|
||||
import com.philkes.notallyx.presentation.activity.note.PickNoteActivity
|
||||
import com.philkes.notallyx.presentation.viewmodel.preference.NotallyXPreferences
|
||||
import com.philkes.notallyx.presentation.widget.WidgetProvider
|
||||
|
||||
class ConfigureWidgetActivity : PickNoteActivity() {
|
||||
|
||||
private val id by lazy {
|
||||
intent.getIntExtra(
|
||||
AppWidgetManager.EXTRA_APPWIDGET_ID,
|
||||
AppWidgetManager.INVALID_APPWIDGET_ID,
|
||||
)
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
val result = Intent()
|
||||
result.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, id)
|
||||
setResult(RESULT_CANCELED, result)
|
||||
}
|
||||
|
||||
override fun onClick(position: Int) {
|
||||
if (position != -1) {
|
||||
val preferences = NotallyXPreferences.getInstance(application)
|
||||
val baseNote = adapter.getItem(position) as BaseNote
|
||||
preferences.updateWidget(id, baseNote.id, baseNote.type)
|
||||
|
||||
val manager = AppWidgetManager.getInstance(this)
|
||||
WidgetProvider.updateWidget(application, manager, id, baseNote.id, baseNote.type)
|
||||
|
||||
val success = Intent()
|
||||
success.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, id)
|
||||
setResult(RESULT_OK, success)
|
||||
finish()
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,139 +0,0 @@
|
|||
package com.philkes.notallyx.presentation.activity
|
||||
|
||||
import android.app.Activity
|
||||
import android.app.KeyguardManager
|
||||
import android.content.Intent
|
||||
import android.hardware.biometrics.BiometricPrompt.BIOMETRIC_ERROR_HW_NOT_PRESENT
|
||||
import android.hardware.biometrics.BiometricPrompt.BIOMETRIC_ERROR_NO_BIOMETRICS
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.provider.Settings
|
||||
import android.view.View.INVISIBLE
|
||||
import android.view.View.VISIBLE
|
||||
import androidx.activity.result.ActivityResultLauncher
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.activity.viewModels
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.viewbinding.ViewBinding
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import com.philkes.notallyx.NotallyXApplication
|
||||
import com.philkes.notallyx.R
|
||||
import com.philkes.notallyx.presentation.showToast
|
||||
import com.philkes.notallyx.presentation.viewmodel.BaseNoteModel
|
||||
import com.philkes.notallyx.presentation.viewmodel.preference.BiometricLock
|
||||
import com.philkes.notallyx.presentation.viewmodel.preference.NotallyXPreferences
|
||||
import com.philkes.notallyx.utils.security.showBiometricOrPinPrompt
|
||||
|
||||
abstract class LockedActivity<T : ViewBinding> : AppCompatActivity() {
|
||||
|
||||
private lateinit var notallyXApplication: NotallyXApplication
|
||||
private lateinit var biometricAuthenticationActivityResultLauncher:
|
||||
ActivityResultLauncher<Intent>
|
||||
|
||||
protected lateinit var binding: T
|
||||
protected lateinit var preferences: NotallyXPreferences
|
||||
val baseModel: BaseNoteModel by viewModels()
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
notallyXApplication = (application as NotallyXApplication)
|
||||
preferences = NotallyXPreferences.getInstance(application)
|
||||
|
||||
biometricAuthenticationActivityResultLauncher =
|
||||
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
|
||||
if (result.resultCode == Activity.RESULT_OK) {
|
||||
unlock()
|
||||
} else {
|
||||
finish()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
if (preferences.biometricLock.value == BiometricLock.ENABLED) {
|
||||
if (hasToAuthenticateWithBiometric()) {
|
||||
hide()
|
||||
showLockScreen()
|
||||
} else {
|
||||
show()
|
||||
}
|
||||
}
|
||||
super.onResume()
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
if (preferences.biometricLock.value == BiometricLock.ENABLED) {
|
||||
hide()
|
||||
}
|
||||
}
|
||||
|
||||
open fun showLockScreen() {
|
||||
showBiometricOrPinPrompt(
|
||||
true,
|
||||
preferences.iv.value!!,
|
||||
biometricAuthenticationActivityResultLauncher,
|
||||
R.string.unlock,
|
||||
onSuccess = { unlock() },
|
||||
) { errorCode ->
|
||||
when (errorCode) {
|
||||
BIOMETRIC_ERROR_NO_BIOMETRICS -> {
|
||||
MaterialAlertDialogBuilder(this)
|
||||
.setMessage(R.string.unlock_with_biometrics_not_setup)
|
||||
.setPositiveButton(R.string.disable) { _, _ ->
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
baseModel.disableBiometricLock()
|
||||
}
|
||||
show()
|
||||
}
|
||||
.setNegativeButton(R.string.tap_to_set_up) { _, _ ->
|
||||
val intent =
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||
Intent(Settings.ACTION_BIOMETRIC_ENROLL)
|
||||
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||
Intent(Settings.ACTION_FINGERPRINT_ENROLL)
|
||||
} else {
|
||||
Intent(Settings.ACTION_SECURITY_SETTINGS)
|
||||
}
|
||||
startActivity(intent)
|
||||
}
|
||||
.show()
|
||||
}
|
||||
|
||||
BIOMETRIC_ERROR_HW_NOT_PRESENT -> {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
baseModel.disableBiometricLock()
|
||||
showToast(R.string.biometrics_disable_success)
|
||||
}
|
||||
show()
|
||||
}
|
||||
|
||||
else -> finish()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun unlock() {
|
||||
notallyXApplication.locked.value = false
|
||||
show()
|
||||
}
|
||||
|
||||
protected fun show() {
|
||||
binding.root.visibility = VISIBLE
|
||||
}
|
||||
|
||||
protected fun hide() {
|
||||
binding.root.visibility = INVISIBLE
|
||||
}
|
||||
|
||||
private fun hasToAuthenticateWithBiometric(): Boolean {
|
||||
return ContextCompat.getSystemService(this, KeyguardManager::class.java)?.let {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
|
||||
(it.isDeviceLocked || notallyXApplication.locked.value)
|
||||
} else {
|
||||
false
|
||||
}
|
||||
} ?: false
|
||||
}
|
||||
}
|
|
@ -1,686 +0,0 @@
|
|||
package com.philkes.notallyx.presentation.activity.main
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.transition.TransitionManager
|
||||
import android.view.Menu
|
||||
import android.view.Menu.CATEGORY_CONTAINER
|
||||
import android.view.Menu.CATEGORY_SYSTEM
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import androidx.activity.OnBackPressedCallback
|
||||
import androidx.activity.result.ActivityResultLauncher
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.core.view.GravityCompat
|
||||
import androidx.core.view.children
|
||||
import androidx.drawerlayout.widget.DrawerLayout
|
||||
import androidx.lifecycle.LifecycleOwner
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.Observer
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.navigation.NavController
|
||||
import androidx.navigation.fragment.NavHostFragment
|
||||
import androidx.navigation.navOptions
|
||||
import androidx.navigation.ui.AppBarConfiguration
|
||||
import androidx.navigation.ui.navigateUp
|
||||
import androidx.navigation.ui.setupActionBarWithNavController
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
import com.google.android.material.transition.platform.MaterialFade
|
||||
import com.philkes.notallyx.R
|
||||
import com.philkes.notallyx.data.NotallyDatabase
|
||||
import com.philkes.notallyx.data.model.BaseNote
|
||||
import com.philkes.notallyx.data.model.Folder
|
||||
import com.philkes.notallyx.databinding.ActivityMainBinding
|
||||
import com.philkes.notallyx.presentation.activity.LockedActivity
|
||||
import com.philkes.notallyx.presentation.activity.main.fragment.DisplayLabelFragment.Companion.EXTRA_DISPLAYED_LABEL
|
||||
import com.philkes.notallyx.presentation.activity.main.fragment.NotallyFragment
|
||||
import com.philkes.notallyx.presentation.activity.note.EditListActivity
|
||||
import com.philkes.notallyx.presentation.activity.note.EditNoteActivity
|
||||
import com.philkes.notallyx.presentation.add
|
||||
import com.philkes.notallyx.presentation.getQuantityString
|
||||
import com.philkes.notallyx.presentation.movedToResId
|
||||
import com.philkes.notallyx.presentation.setCancelButton
|
||||
import com.philkes.notallyx.presentation.view.misc.NotNullLiveData
|
||||
import com.philkes.notallyx.presentation.view.misc.tristatecheckbox.TriStateCheckBox
|
||||
import com.philkes.notallyx.presentation.view.misc.tristatecheckbox.setMultiChoiceTriStateItems
|
||||
import com.philkes.notallyx.presentation.viewmodel.BaseNoteModel
|
||||
import com.philkes.notallyx.presentation.viewmodel.BaseNoteModel.Companion.CURRENT_LABEL_EMPTY
|
||||
import com.philkes.notallyx.presentation.viewmodel.BaseNoteModel.Companion.CURRENT_LABEL_NONE
|
||||
import com.philkes.notallyx.presentation.viewmodel.ExportMimeType
|
||||
import com.philkes.notallyx.presentation.viewmodel.preference.NotallyXPreferences.Companion.START_VIEW_DEFAULT
|
||||
import com.philkes.notallyx.presentation.viewmodel.preference.NotallyXPreferences.Companion.START_VIEW_UNLABELED
|
||||
import com.philkes.notallyx.utils.backup.exportNotes
|
||||
import com.philkes.notallyx.utils.shareNote
|
||||
import com.philkes.notallyx.utils.showColorSelectDialog
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
class MainActivity : LockedActivity<ActivityMainBinding>() {
|
||||
|
||||
private lateinit var navController: NavController
|
||||
private lateinit var configuration: AppBarConfiguration
|
||||
private lateinit var exportFileActivityResultLauncher: ActivityResultLauncher<Intent>
|
||||
private lateinit var exportNotesActivityResultLauncher: ActivityResultLauncher<Intent>
|
||||
|
||||
private var isStartViewFragment = false
|
||||
private val actionModeCancelCallback =
|
||||
object : OnBackPressedCallback(true) {
|
||||
override fun handleOnBackPressed() {
|
||||
baseModel.actionMode.close(true)
|
||||
}
|
||||
}
|
||||
|
||||
var getCurrentFragmentNotes: (() -> Collection<BaseNote>?)? = null
|
||||
|
||||
override fun onSupportNavigateUp(): Boolean {
|
||||
return navController.navigateUp(configuration) || super.onSupportNavigateUp()
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
binding = ActivityMainBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
setSupportActionBar(binding.Toolbar)
|
||||
setupFAB()
|
||||
setupMenu()
|
||||
setupActionMode()
|
||||
setupNavigation()
|
||||
|
||||
setupActivityResultLaunchers()
|
||||
|
||||
val fragmentIdToLoad = intent.getIntExtra(EXTRA_FRAGMENT_TO_OPEN, -1)
|
||||
if (fragmentIdToLoad != -1) {
|
||||
navController.navigate(fragmentIdToLoad, intent.extras)
|
||||
} else if (savedInstanceState == null) {
|
||||
navigateToStartView()
|
||||
}
|
||||
|
||||
onBackPressedDispatcher.addCallback(
|
||||
this,
|
||||
object : OnBackPressedCallback(true) {
|
||||
override fun handleOnBackPressed() {
|
||||
if (baseModel.actionMode.enabled.value) {
|
||||
return
|
||||
}
|
||||
if (
|
||||
!isStartViewFragment &&
|
||||
!intent.getBooleanExtra(EXTRA_SKIP_START_VIEW_ON_BACK, false)
|
||||
) {
|
||||
navigateToStartView()
|
||||
} else {
|
||||
finish()
|
||||
}
|
||||
}
|
||||
},
|
||||
)
|
||||
onBackPressedDispatcher.addCallback(this, actionModeCancelCallback)
|
||||
}
|
||||
|
||||
private fun getStartViewNavigation(): Pair<Int, Bundle> {
|
||||
return when (val startView = preferences.startView.value) {
|
||||
START_VIEW_DEFAULT -> Pair(R.id.Notes, Bundle())
|
||||
START_VIEW_UNLABELED -> Pair(R.id.Unlabeled, Bundle())
|
||||
else -> {
|
||||
val bundle = Bundle().apply { putString(EXTRA_DISPLAYED_LABEL, startView) }
|
||||
Pair(R.id.DisplayLabel, bundle)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun navigateToStartView() {
|
||||
val (id, bundle) = getStartViewNavigation()
|
||||
navController.navigate(id, bundle)
|
||||
}
|
||||
|
||||
private fun setupFAB() {
|
||||
binding.TakeNote.setOnClickListener {
|
||||
val intent = Intent(this, EditNoteActivity::class.java)
|
||||
startActivity(prepareNewNoteIntent(intent))
|
||||
}
|
||||
binding.MakeList.setOnClickListener {
|
||||
val intent = Intent(this, EditListActivity::class.java)
|
||||
startActivity(prepareNewNoteIntent(intent))
|
||||
}
|
||||
}
|
||||
|
||||
private fun prepareNewNoteIntent(intent: Intent): Intent {
|
||||
return supportFragmentManager
|
||||
.findFragmentById(R.id.NavHostFragment)
|
||||
?.childFragmentManager
|
||||
?.fragments
|
||||
?.firstOrNull()
|
||||
?.let { fragment ->
|
||||
return if (fragment is NotallyFragment) {
|
||||
fragment.prepareNewNoteIntent(intent)
|
||||
} else intent
|
||||
} ?: intent
|
||||
}
|
||||
|
||||
private var labelsMenuItems: List<MenuItem> = listOf()
|
||||
private var labelsMoreMenuItem: MenuItem? = null
|
||||
private var labels: List<String> = listOf()
|
||||
private var labelsLiveData: LiveData<List<String>>? = null
|
||||
|
||||
private fun setupMenu() {
|
||||
binding.NavigationView.menu.apply {
|
||||
add(0, R.id.Notes, 0, R.string.notes).setCheckable(true).setIcon(R.drawable.home)
|
||||
|
||||
addStaticLabelsMenuItems()
|
||||
NotallyDatabase.getDatabase(application).observe(this@MainActivity) { database ->
|
||||
labelsLiveData?.removeObservers(this@MainActivity)
|
||||
labelsLiveData =
|
||||
database.getLabelDao().getAll().also {
|
||||
it.observe(this@MainActivity) { labels ->
|
||||
this@MainActivity.labels = labels
|
||||
setupLabelsMenuItems(labels, preferences.maxLabels.value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
add(2, R.id.Deleted, CATEGORY_SYSTEM + 1, R.string.deleted)
|
||||
.setCheckable(true)
|
||||
.setIcon(R.drawable.delete)
|
||||
add(2, R.id.Archived, CATEGORY_SYSTEM + 2, R.string.archived)
|
||||
.setCheckable(true)
|
||||
.setIcon(R.drawable.archive)
|
||||
add(3, R.id.Reminders, CATEGORY_SYSTEM + 3, R.string.reminders)
|
||||
.setCheckable(true)
|
||||
.setIcon(R.drawable.notifications)
|
||||
add(3, R.id.Settings, CATEGORY_SYSTEM + 4, R.string.settings)
|
||||
.setCheckable(true)
|
||||
.setIcon(R.drawable.settings)
|
||||
}
|
||||
baseModel.preferences.labelsHidden.observe(this) { hiddenLabels ->
|
||||
hideLabelsInNavigation(hiddenLabels, baseModel.preferences.maxLabels.value)
|
||||
}
|
||||
baseModel.preferences.maxLabels.observe(this) { maxLabels ->
|
||||
binding.NavigationView.menu.setupLabelsMenuItems(labels, maxLabels)
|
||||
}
|
||||
}
|
||||
|
||||
private fun Menu.addStaticLabelsMenuItems() {
|
||||
add(1, R.id.Unlabeled, CATEGORY_CONTAINER + 1, R.string.unlabeled)
|
||||
.setCheckable(true)
|
||||
.setChecked(baseModel.currentLabel == CURRENT_LABEL_NONE)
|
||||
.setIcon(R.drawable.label_off)
|
||||
add(1, R.id.Labels, CATEGORY_CONTAINER + 2, R.string.labels)
|
||||
.setCheckable(true)
|
||||
.setIcon(R.drawable.label_more)
|
||||
}
|
||||
|
||||
private fun Menu.setupLabelsMenuItems(labels: List<String>, maxLabelsToDisplay: Int) {
|
||||
removeGroup(1)
|
||||
addStaticLabelsMenuItems()
|
||||
labelsMenuItems =
|
||||
labels
|
||||
.mapIndexed { index, label ->
|
||||
add(1, R.id.DisplayLabel, CATEGORY_CONTAINER + index + 3, label)
|
||||
.setCheckable(true)
|
||||
.setChecked(baseModel.currentLabel == label)
|
||||
.setVisible(index < maxLabelsToDisplay)
|
||||
.setIcon(R.drawable.label)
|
||||
.setOnMenuItemClickListener {
|
||||
navigateToLabel(label)
|
||||
false
|
||||
}
|
||||
}
|
||||
.toList()
|
||||
|
||||
labelsMoreMenuItem =
|
||||
if (labelsMenuItems.size > maxLabelsToDisplay) {
|
||||
add(
|
||||
1,
|
||||
R.id.Labels,
|
||||
CATEGORY_CONTAINER + labelsMenuItems.size + 2,
|
||||
getString(R.string.more, labelsMenuItems.size - maxLabelsToDisplay),
|
||||
)
|
||||
.setCheckable(true)
|
||||
.setIcon(R.drawable.label)
|
||||
} else null
|
||||
configuration = AppBarConfiguration(binding.NavigationView.menu, binding.DrawerLayout)
|
||||
setupActionBarWithNavController(navController, configuration)
|
||||
hideLabelsInNavigation(baseModel.preferences.labelsHidden.value, maxLabelsToDisplay)
|
||||
}
|
||||
|
||||
private fun navigateToLabel(label: String) {
|
||||
val bundle = Bundle().apply { putString(EXTRA_DISPLAYED_LABEL, label) }
|
||||
navController.navigate(R.id.DisplayLabel, bundle)
|
||||
}
|
||||
|
||||
private fun hideLabelsInNavigation(hiddenLabels: Set<String>, maxLabelsToDisplay: Int) {
|
||||
var visibleLabels = 0
|
||||
labelsMenuItems.forEach { menuItem ->
|
||||
val visible =
|
||||
!hiddenLabels.contains(menuItem.title) && visibleLabels < maxLabelsToDisplay
|
||||
menuItem.setVisible(visible)
|
||||
if (visible) {
|
||||
visibleLabels++
|
||||
}
|
||||
}
|
||||
labelsMoreMenuItem?.setTitle(getString(R.string.more, labels.size - visibleLabels))
|
||||
}
|
||||
|
||||
private fun setupActionMode() {
|
||||
binding.ActionMode.setNavigationOnClickListener { baseModel.actionMode.close(true) }
|
||||
|
||||
val transition =
|
||||
MaterialFade().apply {
|
||||
secondaryAnimatorProvider = null
|
||||
excludeTarget(binding.NavHostFragment, true)
|
||||
excludeChildren(binding.NavHostFragment, true)
|
||||
excludeTarget(binding.TakeNote, true)
|
||||
excludeTarget(binding.MakeList, true)
|
||||
excludeTarget(binding.NavigationView, true)
|
||||
}
|
||||
|
||||
baseModel.actionMode.enabled.observe(this) { enabled ->
|
||||
TransitionManager.beginDelayedTransition(binding.RelativeLayout, transition)
|
||||
if (enabled) {
|
||||
binding.Toolbar.visibility = View.GONE
|
||||
binding.ActionMode.visibility = View.VISIBLE
|
||||
binding.DrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED)
|
||||
} else {
|
||||
binding.Toolbar.visibility = View.VISIBLE
|
||||
binding.ActionMode.visibility = View.GONE
|
||||
binding.DrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNDEFINED)
|
||||
}
|
||||
actionModeCancelCallback.isEnabled = enabled
|
||||
}
|
||||
|
||||
val menu = binding.ActionMode.menu
|
||||
baseModel.folder.observe(this@MainActivity, ModelFolderObserver(menu, baseModel))
|
||||
baseModel.actionMode.loading.observe(this@MainActivity) { loading ->
|
||||
menu.setGroupEnabled(Menu.NONE, !loading)
|
||||
}
|
||||
}
|
||||
|
||||
private fun moveNotes(folderTo: Folder) {
|
||||
if (baseModel.actionMode.loading.value || baseModel.actionMode.isEmpty()) {
|
||||
return
|
||||
}
|
||||
try {
|
||||
baseModel.actionMode.loading.value = true
|
||||
val folderFrom = baseModel.actionMode.getFirstNote().folder
|
||||
val ids = baseModel.moveBaseNotes(folderTo)
|
||||
Snackbar.make(
|
||||
findViewById(R.id.DrawerLayout),
|
||||
getQuantityString(folderTo.movedToResId(), ids.size),
|
||||
Snackbar.LENGTH_SHORT,
|
||||
)
|
||||
.apply { setAction(R.string.undo) { baseModel.moveBaseNotes(ids, folderFrom) } }
|
||||
.show()
|
||||
} finally {
|
||||
baseModel.actionMode.loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
private fun share() {
|
||||
val baseNote = baseModel.actionMode.getFirstNote()
|
||||
this.shareNote(baseNote)
|
||||
}
|
||||
|
||||
private fun deleteForever() {
|
||||
MaterialAlertDialogBuilder(this)
|
||||
.setMessage(R.string.delete_selected_notes)
|
||||
.setPositiveButton(R.string.delete) { _, _ -> baseModel.deleteSelectedBaseNotes() }
|
||||
.setCancelButton()
|
||||
.show()
|
||||
}
|
||||
|
||||
private fun label() {
|
||||
val baseNotes = baseModel.actionMode.selectedNotes.values
|
||||
lifecycleScope.launch {
|
||||
val labels = baseModel.getAllLabels()
|
||||
if (labels.isNotEmpty()) {
|
||||
displaySelectLabelsDialog(labels, baseNotes)
|
||||
} else {
|
||||
baseModel.actionMode.close(true)
|
||||
navigateWithAnimation(R.id.Labels)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun displaySelectLabelsDialog(labels: Array<String>, baseNotes: Collection<BaseNote>) {
|
||||
val checkedPositions =
|
||||
labels
|
||||
.map { label ->
|
||||
if (baseNotes.all { it.labels.contains(label) }) {
|
||||
TriStateCheckBox.State.CHECKED
|
||||
} else if (baseNotes.any { it.labels.contains(label) }) {
|
||||
TriStateCheckBox.State.PARTIALLY_CHECKED
|
||||
} else {
|
||||
TriStateCheckBox.State.UNCHECKED
|
||||
}
|
||||
}
|
||||
.toTypedArray()
|
||||
|
||||
MaterialAlertDialogBuilder(this)
|
||||
.setTitle(R.string.labels)
|
||||
.setCancelButton()
|
||||
.setMultiChoiceTriStateItems(this, labels, checkedPositions) { idx, state ->
|
||||
checkedPositions[idx] = state
|
||||
}
|
||||
.setPositiveButton(R.string.save) { _, _ ->
|
||||
val checkedLabels =
|
||||
checkedPositions.mapIndexedNotNull { index, checked ->
|
||||
if (checked == TriStateCheckBox.State.CHECKED) {
|
||||
labels[index]
|
||||
} else null
|
||||
}
|
||||
val uncheckedLabels =
|
||||
checkedPositions.mapIndexedNotNull { index, checked ->
|
||||
if (checked == TriStateCheckBox.State.UNCHECKED) {
|
||||
labels[index]
|
||||
} else null
|
||||
}
|
||||
val updatedBaseNotesLabels =
|
||||
baseNotes.map { baseNote ->
|
||||
val noteLabels = baseNote.labels.toMutableList()
|
||||
checkedLabels.forEach { checkedLabel ->
|
||||
if (!noteLabels.contains(checkedLabel)) {
|
||||
noteLabels.add(checkedLabel)
|
||||
}
|
||||
}
|
||||
uncheckedLabels.forEach { uncheckedLabel ->
|
||||
if (noteLabels.contains(uncheckedLabel)) {
|
||||
noteLabels.remove(uncheckedLabel)
|
||||
}
|
||||
}
|
||||
noteLabels
|
||||
}
|
||||
baseNotes.zip(updatedBaseNotesLabels).forEach { (baseNote, updatedLabels) ->
|
||||
baseModel.updateBaseNoteLabels(updatedLabels, baseNote.id)
|
||||
}
|
||||
}
|
||||
.show()
|
||||
}
|
||||
|
||||
private fun exportSelectedNotes(mimeType: ExportMimeType) {
|
||||
exportNotes(
|
||||
mimeType,
|
||||
baseModel.actionMode.selectedNotes.values,
|
||||
exportFileActivityResultLauncher,
|
||||
exportNotesActivityResultLauncher,
|
||||
)
|
||||
}
|
||||
|
||||
private fun setupNavigation() {
|
||||
val navHostFragment =
|
||||
supportFragmentManager.findFragmentById(R.id.NavHostFragment) as NavHostFragment
|
||||
navController = navHostFragment.navController
|
||||
configuration = AppBarConfiguration(binding.NavigationView.menu, binding.DrawerLayout)
|
||||
setupActionBarWithNavController(navController, configuration)
|
||||
|
||||
var fragmentIdToLoad: Int? = null
|
||||
binding.NavigationView.setNavigationItemSelectedListener { item ->
|
||||
fragmentIdToLoad = item.itemId
|
||||
binding.DrawerLayout.closeDrawer(GravityCompat.START)
|
||||
return@setNavigationItemSelectedListener true
|
||||
}
|
||||
|
||||
binding.DrawerLayout.addDrawerListener(
|
||||
object : DrawerLayout.SimpleDrawerListener() {
|
||||
|
||||
override fun onDrawerClosed(drawerView: View) {
|
||||
if (
|
||||
fragmentIdToLoad != null &&
|
||||
navController.currentDestination?.id != fragmentIdToLoad
|
||||
) {
|
||||
navigateWithAnimation(requireNotNull(fragmentIdToLoad))
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
navController.addOnDestinationChangedListener { _, destination, bundle ->
|
||||
fragmentIdToLoad = destination.id
|
||||
when (fragmentIdToLoad) {
|
||||
R.id.DisplayLabel ->
|
||||
bundle?.getString(EXTRA_DISPLAYED_LABEL)?.let {
|
||||
baseModel.currentLabel = it
|
||||
binding.NavigationView.menu.children
|
||||
.find { menuItem -> menuItem.title == it }
|
||||
?.let { menuItem -> menuItem.isChecked = true }
|
||||
}
|
||||
R.id.Unlabeled -> {
|
||||
baseModel.currentLabel = CURRENT_LABEL_NONE
|
||||
binding.NavigationView.setCheckedItem(destination.id)
|
||||
}
|
||||
else -> {
|
||||
baseModel.currentLabel = CURRENT_LABEL_EMPTY
|
||||
binding.NavigationView.setCheckedItem(destination.id)
|
||||
}
|
||||
}
|
||||
when (destination.id) {
|
||||
R.id.Notes,
|
||||
R.id.DisplayLabel,
|
||||
R.id.Unlabeled -> {
|
||||
binding.TakeNote.show()
|
||||
binding.MakeList.show()
|
||||
}
|
||||
|
||||
else -> {
|
||||
binding.TakeNote.hide()
|
||||
binding.MakeList.hide()
|
||||
}
|
||||
}
|
||||
isStartViewFragment = isStartViewFragment(destination.id, bundle)
|
||||
}
|
||||
}
|
||||
|
||||
private fun isStartViewFragment(id: Int, bundle: Bundle?): Boolean {
|
||||
val (startViewId, startViewBundle) = getStartViewNavigation()
|
||||
return startViewId == id &&
|
||||
startViewBundle.getString(EXTRA_DISPLAYED_LABEL) ==
|
||||
bundle?.getString(EXTRA_DISPLAYED_LABEL)
|
||||
}
|
||||
|
||||
private fun navigateWithAnimation(id: Int) {
|
||||
val options = navOptions {
|
||||
launchSingleTop = true
|
||||
anim {
|
||||
exit = androidx.navigation.ui.R.anim.nav_default_exit_anim
|
||||
enter = androidx.navigation.ui.R.anim.nav_default_enter_anim
|
||||
popExit = androidx.navigation.ui.R.anim.nav_default_pop_exit_anim
|
||||
popEnter = androidx.navigation.ui.R.anim.nav_default_pop_enter_anim
|
||||
}
|
||||
popUpTo(navController.graph.startDestinationId) { inclusive = false }
|
||||
}
|
||||
navController.navigate(id, null, options)
|
||||
}
|
||||
|
||||
private fun setupActivityResultLaunchers() {
|
||||
exportFileActivityResultLauncher =
|
||||
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
|
||||
if (result.resultCode == RESULT_OK) {
|
||||
result.data?.data?.let { uri -> baseModel.exportSelectedFileToUri(uri) }
|
||||
}
|
||||
}
|
||||
exportNotesActivityResultLauncher =
|
||||
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
|
||||
if (result.resultCode == RESULT_OK) {
|
||||
result.data?.data?.let { uri -> baseModel.exportSelectedNotesToFolder(uri) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private inner class ModelFolderObserver(
|
||||
private val menu: Menu,
|
||||
private val model: BaseNoteModel,
|
||||
) : Observer<Folder> {
|
||||
override fun onChanged(value: Folder) {
|
||||
menu.clear()
|
||||
model.actionMode.count.removeObservers(this@MainActivity)
|
||||
|
||||
menu.add(
|
||||
R.string.select_all,
|
||||
R.drawable.select_all,
|
||||
showAsAction = MenuItem.SHOW_AS_ACTION_ALWAYS,
|
||||
) {
|
||||
getCurrentFragmentNotes?.invoke()?.let { model.actionMode.add(it) }
|
||||
}
|
||||
when (value) {
|
||||
Folder.NOTES -> {
|
||||
val pinned = menu.addPinned(MenuItem.SHOW_AS_ACTION_ALWAYS)
|
||||
menu.addLabels(MenuItem.SHOW_AS_ACTION_ALWAYS)
|
||||
menu.addDelete(MenuItem.SHOW_AS_ACTION_ALWAYS)
|
||||
menu.add(R.string.archive, R.drawable.archive) { moveNotes(Folder.ARCHIVED) }
|
||||
menu.addChangeColor()
|
||||
val share = menu.addShare()
|
||||
menu.addExportMenu()
|
||||
model.actionMode.count.observeCountAndPinned(this@MainActivity, share, pinned)
|
||||
}
|
||||
|
||||
Folder.ARCHIVED -> {
|
||||
menu.add(
|
||||
R.string.unarchive,
|
||||
R.drawable.unarchive,
|
||||
MenuItem.SHOW_AS_ACTION_ALWAYS,
|
||||
) {
|
||||
moveNotes(Folder.NOTES)
|
||||
}
|
||||
menu.addDelete(MenuItem.SHOW_AS_ACTION_ALWAYS)
|
||||
menu.addExportMenu(MenuItem.SHOW_AS_ACTION_ALWAYS)
|
||||
val pinned = menu.addPinned()
|
||||
menu.addLabels()
|
||||
menu.addChangeColor()
|
||||
val share = menu.addShare()
|
||||
model.actionMode.count.observeCountAndPinned(this@MainActivity, share, pinned)
|
||||
}
|
||||
|
||||
Folder.DELETED -> {
|
||||
menu.add(R.string.restore, R.drawable.restore, MenuItem.SHOW_AS_ACTION_ALWAYS) {
|
||||
moveNotes(Folder.NOTES)
|
||||
}
|
||||
menu.add(
|
||||
R.string.delete_forever,
|
||||
R.drawable.delete,
|
||||
MenuItem.SHOW_AS_ACTION_ALWAYS,
|
||||
) {
|
||||
deleteForever()
|
||||
}
|
||||
menu.addExportMenu()
|
||||
menu.addChangeColor()
|
||||
val share = menu.add(R.string.share, R.drawable.share) { share() }
|
||||
model.actionMode.count.observeCount(this@MainActivity, share)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun Menu.addPinned(showAsAction: Int = MenuItem.SHOW_AS_ACTION_IF_ROOM): MenuItem {
|
||||
return add(R.string.pin, R.drawable.pin, showAsAction) {}
|
||||
}
|
||||
|
||||
private fun Menu.addLabels(showAsAction: Int = MenuItem.SHOW_AS_ACTION_IF_ROOM): MenuItem {
|
||||
return add(R.string.labels, R.drawable.label, showAsAction) { label() }
|
||||
}
|
||||
|
||||
private fun Menu.addChangeColor(
|
||||
showAsAction: Int = MenuItem.SHOW_AS_ACTION_IF_ROOM
|
||||
): MenuItem {
|
||||
return add(R.string.change_color, R.drawable.change_color, showAsAction) {
|
||||
lifecycleScope.launch {
|
||||
val colors =
|
||||
withContext(Dispatchers.IO) {
|
||||
NotallyDatabase.getDatabase(
|
||||
this@MainActivity,
|
||||
observePreferences = false,
|
||||
)
|
||||
.value
|
||||
.getBaseNoteDao()
|
||||
.getAllColors()
|
||||
}
|
||||
// Show color as selected only if all selected notes have the same color
|
||||
val currentColor =
|
||||
model.actionMode.selectedNotes.values
|
||||
.map { it.color }
|
||||
.distinct()
|
||||
.takeIf { it.size == 1 }
|
||||
?.firstOrNull()
|
||||
showColorSelectDialog(
|
||||
colors,
|
||||
currentColor,
|
||||
null,
|
||||
{ selectedColor, oldColor ->
|
||||
if (oldColor != null) {
|
||||
model.changeColor(oldColor, selectedColor)
|
||||
}
|
||||
model.colorBaseNote(selectedColor)
|
||||
},
|
||||
) { colorToDelete, newColor ->
|
||||
model.changeColor(colorToDelete, newColor)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun Menu.addDelete(showAsAction: Int = MenuItem.SHOW_AS_ACTION_IF_ROOM): MenuItem {
|
||||
return add(R.string.delete, R.drawable.delete, showAsAction) {
|
||||
moveNotes(Folder.DELETED)
|
||||
}
|
||||
}
|
||||
|
||||
private fun Menu.addShare(showAsAction: Int = MenuItem.SHOW_AS_ACTION_IF_ROOM): MenuItem {
|
||||
return add(R.string.share, R.drawable.share, showAsAction) { share() }
|
||||
}
|
||||
|
||||
private fun Menu.addExportMenu(
|
||||
showAsAction: Int = MenuItem.SHOW_AS_ACTION_IF_ROOM
|
||||
): MenuItem {
|
||||
return addSubMenu(R.string.export)
|
||||
.apply {
|
||||
setIcon(R.drawable.export)
|
||||
item.setShowAsAction(showAsAction)
|
||||
ExportMimeType.entries.forEach {
|
||||
add(it.name).onClick { exportSelectedNotes(it) }
|
||||
}
|
||||
}
|
||||
.item
|
||||
}
|
||||
|
||||
fun MenuItem.onClick(function: () -> Unit) {
|
||||
setOnMenuItemClickListener {
|
||||
function()
|
||||
return@setOnMenuItemClickListener false
|
||||
}
|
||||
}
|
||||
|
||||
private fun NotNullLiveData<Int>.observeCount(
|
||||
lifecycleOwner: LifecycleOwner,
|
||||
share: MenuItem,
|
||||
onCountChange: ((Int) -> Unit)? = null,
|
||||
) {
|
||||
observe(lifecycleOwner) { count ->
|
||||
binding.ActionMode.title = count.toString()
|
||||
onCountChange?.invoke(count)
|
||||
share.setVisible(count == 1)
|
||||
}
|
||||
}
|
||||
|
||||
private fun NotNullLiveData<Int>.observeCountAndPinned(
|
||||
lifecycleOwner: LifecycleOwner,
|
||||
share: MenuItem,
|
||||
pinned: MenuItem,
|
||||
) {
|
||||
observeCount(lifecycleOwner, share) {
|
||||
val baseNotes = model.actionMode.selectedNotes.values
|
||||
if (baseNotes.any { !it.pinned }) {
|
||||
pinned.setTitle(R.string.pin).setIcon(R.drawable.pin).onClick {
|
||||
model.pinBaseNotes(true)
|
||||
}
|
||||
} else {
|
||||
pinned.setTitle(R.string.unpin).setIcon(R.drawable.unpin).onClick {
|
||||
model.pinBaseNotes(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val EXTRA_FRAGMENT_TO_OPEN = "notallyx.intent.extra.FRAGMENT_TO_OPEN"
|
||||
const val EXTRA_SKIP_START_VIEW_ON_BACK = "notallyx.intent.extra.SKIP_START_VIEW_ON_BACK"
|
||||
}
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
package com.philkes.notallyx.presentation.activity.main.fragment
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import com.philkes.notallyx.R
|
||||
import com.philkes.notallyx.data.model.Folder
|
||||
|
||||
class ArchivedFragment : NotallyFragment() {
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
model.folder.value = Folder.ARCHIVED
|
||||
}
|
||||
|
||||
override fun getBackground() = R.drawable.archive
|
||||
|
||||
override fun getObservable() = model.archivedNotes!!
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
package com.philkes.notallyx.presentation.activity.main.fragment
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.Menu
|
||||
import android.view.MenuInflater
|
||||
import android.view.View
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import com.philkes.notallyx.R
|
||||
import com.philkes.notallyx.data.model.Folder
|
||||
import com.philkes.notallyx.presentation.add
|
||||
import com.philkes.notallyx.presentation.setCancelButton
|
||||
|
||||
class DeletedFragment : NotallyFragment() {
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
model.folder.value = Folder.DELETED
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
|
||||
menu.add(R.string.delete_all, R.drawable.delete_all) { deleteAllNotes() }
|
||||
}
|
||||
|
||||
private fun deleteAllNotes() {
|
||||
MaterialAlertDialogBuilder(requireContext())
|
||||
.setMessage(R.string.delete_all_notes)
|
||||
.setPositiveButton(R.string.delete) { _, _ -> model.deleteAllTrashedBaseNotes() }
|
||||
.setCancelButton()
|
||||
.show()
|
||||
}
|
||||
|
||||
override fun getBackground() = R.drawable.delete
|
||||
|
||||
override fun getObservable() = model.deletedNotes!!
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
package com.philkes.notallyx.presentation.activity.main.fragment
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import androidx.lifecycle.LiveData
|
||||
import com.philkes.notallyx.R
|
||||
import com.philkes.notallyx.data.model.Folder
|
||||
import com.philkes.notallyx.data.model.Item
|
||||
|
||||
class DisplayLabelFragment : NotallyFragment() {
|
||||
|
||||
private lateinit var label: String
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
model.folder.value = Folder.NOTES
|
||||
}
|
||||
|
||||
override fun getBackground() = R.drawable.label
|
||||
|
||||
override fun getObservable(): LiveData<List<Item>> {
|
||||
label = requireNotNull(requireArguments().getString(EXTRA_DISPLAYED_LABEL))
|
||||
return model.getNotesByLabel(label)
|
||||
}
|
||||
|
||||
override fun prepareNewNoteIntent(intent: Intent): Intent {
|
||||
return intent.putExtra(EXTRA_DISPLAYED_LABEL, label)
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val EXTRA_DISPLAYED_LABEL = "notallyx.intent.extra.DISPLAYED_LABEL"
|
||||
}
|
||||
}
|
|
@ -1,151 +0,0 @@
|
|||
package com.philkes.notallyx.presentation.activity.main.fragment
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.Menu
|
||||
import android.view.MenuInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.core.widget.doAfterTextChanged
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.activityViewModels
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import com.philkes.notallyx.R
|
||||
import com.philkes.notallyx.data.model.Label
|
||||
import com.philkes.notallyx.databinding.DialogInputBinding
|
||||
import com.philkes.notallyx.databinding.FragmentNotesBinding
|
||||
import com.philkes.notallyx.presentation.activity.main.fragment.DisplayLabelFragment.Companion.EXTRA_DISPLAYED_LABEL
|
||||
import com.philkes.notallyx.presentation.add
|
||||
import com.philkes.notallyx.presentation.displayEditLabelDialog
|
||||
import com.philkes.notallyx.presentation.initListView
|
||||
import com.philkes.notallyx.presentation.setCancelButton
|
||||
import com.philkes.notallyx.presentation.showAndFocus
|
||||
import com.philkes.notallyx.presentation.showToast
|
||||
import com.philkes.notallyx.presentation.view.main.label.LabelAdapter
|
||||
import com.philkes.notallyx.presentation.view.main.label.LabelData
|
||||
import com.philkes.notallyx.presentation.view.main.label.LabelListener
|
||||
import com.philkes.notallyx.presentation.viewmodel.BaseNoteModel
|
||||
|
||||
class LabelsFragment : Fragment(), LabelListener {
|
||||
|
||||
private var labelAdapter: LabelAdapter? = null
|
||||
private var binding: FragmentNotesBinding? = null
|
||||
|
||||
private val model: BaseNoteModel by activityViewModels()
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
binding = null
|
||||
labelAdapter = null
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
labelAdapter = LabelAdapter(this)
|
||||
|
||||
binding?.MainListView?.apply {
|
||||
initListView(requireContext())
|
||||
adapter = labelAdapter
|
||||
binding?.ImageView?.setImageResource(R.drawable.label)
|
||||
}
|
||||
|
||||
setupObserver()
|
||||
}
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?,
|
||||
): View? {
|
||||
setHasOptionsMenu(true)
|
||||
binding = FragmentNotesBinding.inflate(inflater)
|
||||
return binding?.root
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
|
||||
menu.add(R.string.add_label, R.drawable.add) { displayAddLabelDialog() }
|
||||
}
|
||||
|
||||
override fun onClick(position: Int) {
|
||||
labelAdapter?.currentList?.get(position)?.let { (label, _) ->
|
||||
val bundle = Bundle()
|
||||
bundle.putString(EXTRA_DISPLAYED_LABEL, label)
|
||||
findNavController().navigate(R.id.LabelsToDisplayLabel, bundle)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onEdit(position: Int) {
|
||||
labelAdapter?.currentList?.get(position)?.let { (label, _) ->
|
||||
displayEditLabelDialog(label, model)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDelete(position: Int) {
|
||||
labelAdapter?.currentList?.get(position)?.let { (label, _) -> confirmDeletion(label) }
|
||||
}
|
||||
|
||||
override fun onToggleVisibility(position: Int) {
|
||||
labelAdapter?.currentList?.get(position)?.let { value ->
|
||||
val hiddenLabels = model.preferences.labelsHidden.value.toMutableSet()
|
||||
if (value.visibleInNavigation) {
|
||||
hiddenLabels.add(value.label)
|
||||
} else {
|
||||
hiddenLabels.remove(value.label)
|
||||
}
|
||||
model.savePreference(model.preferences.labelsHidden, hiddenLabels)
|
||||
|
||||
val currentList = labelAdapter!!.currentList.toMutableList()
|
||||
currentList[position] =
|
||||
currentList[position].copy(visibleInNavigation = !value.visibleInNavigation)
|
||||
labelAdapter!!.submitList(currentList)
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupObserver() {
|
||||
model.labels.observe(viewLifecycleOwner) { labels ->
|
||||
val hiddenLabels = model.preferences.labelsHidden.value
|
||||
val labelsData = labels.map { label -> LabelData(label, !hiddenLabels.contains(label)) }
|
||||
labelAdapter?.submitList(labelsData)
|
||||
binding?.ImageView?.isVisible = labels.isEmpty()
|
||||
}
|
||||
}
|
||||
|
||||
private fun displayAddLabelDialog() {
|
||||
val inflater = LayoutInflater.from(requireContext())
|
||||
val dialogBinding = DialogInputBinding.inflate(inflater)
|
||||
|
||||
MaterialAlertDialogBuilder(requireContext())
|
||||
.setTitle(R.string.add_label)
|
||||
.setView(dialogBinding.root)
|
||||
.setCancelButton()
|
||||
.setPositiveButton(R.string.save) { dialog, _ ->
|
||||
val value = dialogBinding.EditText.text.toString().trim()
|
||||
if (value.isNotEmpty()) {
|
||||
val label = Label(value)
|
||||
model.insertLabel(label) { success: Boolean ->
|
||||
if (success) {
|
||||
dialog.dismiss()
|
||||
} else {
|
||||
showToast(R.string.label_exists)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.showAndFocus(dialogBinding.EditText, allowFullSize = true) { positiveButton ->
|
||||
dialogBinding.EditText.doAfterTextChanged { text ->
|
||||
positiveButton.isEnabled = !text.isNullOrEmpty()
|
||||
}
|
||||
positiveButton.isEnabled = false
|
||||
}
|
||||
}
|
||||
|
||||
private fun confirmDeletion(value: String) {
|
||||
MaterialAlertDialogBuilder(requireContext())
|
||||
.setTitle(R.string.delete_label)
|
||||
.setMessage(R.string.your_notes_associated)
|
||||
.setPositiveButton(R.string.delete) { _, _ -> model.deleteLabel(value) }
|
||||
.setCancelButton()
|
||||
.show()
|
||||
}
|
||||
}
|
|
@ -1,310 +0,0 @@
|
|||
package com.philkes.notallyx.presentation.activity.main.fragment
|
||||
|
||||
import android.app.Activity.RESULT_OK
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.activity.result.ActivityResultLauncher
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.core.widget.doAfterTextChanged
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.activityViewModels
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.navigation.findNavController
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.recyclerview.widget.StaggeredGridLayoutManager
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
import com.philkes.notallyx.R
|
||||
import com.philkes.notallyx.data.model.BaseNote
|
||||
import com.philkes.notallyx.data.model.Folder
|
||||
import com.philkes.notallyx.data.model.Item
|
||||
import com.philkes.notallyx.data.model.Type
|
||||
import com.philkes.notallyx.databinding.FragmentNotesBinding
|
||||
import com.philkes.notallyx.presentation.activity.main.MainActivity
|
||||
import com.philkes.notallyx.presentation.activity.main.fragment.SearchFragment.Companion.EXTRA_INITIAL_FOLDER
|
||||
import com.philkes.notallyx.presentation.activity.main.fragment.SearchFragment.Companion.EXTRA_INITIAL_LABEL
|
||||
import com.philkes.notallyx.presentation.activity.note.EditActivity.Companion.EXTRA_FOLDER_FROM
|
||||
import com.philkes.notallyx.presentation.activity.note.EditActivity.Companion.EXTRA_FOLDER_TO
|
||||
import com.philkes.notallyx.presentation.activity.note.EditActivity.Companion.EXTRA_NOTE_ID
|
||||
import com.philkes.notallyx.presentation.activity.note.EditActivity.Companion.EXTRA_SELECTED_BASE_NOTE
|
||||
import com.philkes.notallyx.presentation.activity.note.EditListActivity
|
||||
import com.philkes.notallyx.presentation.activity.note.EditNoteActivity
|
||||
import com.philkes.notallyx.presentation.getQuantityString
|
||||
import com.philkes.notallyx.presentation.hideKeyboard
|
||||
import com.philkes.notallyx.presentation.movedToResId
|
||||
import com.philkes.notallyx.presentation.showKeyboard
|
||||
import com.philkes.notallyx.presentation.view.main.BaseNoteAdapter
|
||||
import com.philkes.notallyx.presentation.view.main.BaseNoteVHPreferences
|
||||
import com.philkes.notallyx.presentation.view.misc.ItemListener
|
||||
import com.philkes.notallyx.presentation.viewmodel.BaseNoteModel
|
||||
import com.philkes.notallyx.presentation.viewmodel.preference.NotesView
|
||||
|
||||
abstract class NotallyFragment : Fragment(), ItemListener {
|
||||
|
||||
private var notesAdapter: BaseNoteAdapter? = null
|
||||
private lateinit var openNoteActivityResultLauncher: ActivityResultLauncher<Intent>
|
||||
private var lastSelectedNotePosition = -1
|
||||
|
||||
internal var binding: FragmentNotesBinding? = null
|
||||
|
||||
internal val model: BaseNoteModel by activityViewModels()
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
binding = null
|
||||
notesAdapter = null
|
||||
}
|
||||
|
||||
override fun onSaveInstanceState(outState: Bundle) {
|
||||
super.onSaveInstanceState(outState)
|
||||
val layoutManager = binding?.MainListView?.layoutManager as? LinearLayoutManager
|
||||
if (layoutManager != null) {
|
||||
val firstVisiblePosition = layoutManager.findFirstVisibleItemPosition()
|
||||
if (firstVisiblePosition != RecyclerView.NO_POSITION) {
|
||||
val firstVisibleView = layoutManager.findViewByPosition(firstVisiblePosition)
|
||||
val offset = firstVisibleView?.top ?: 0
|
||||
outState.putInt(EXTRA_SCROLL_POS, firstVisiblePosition)
|
||||
outState.putInt(EXTRA_SCROLL_OFFSET, offset)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
binding?.ImageView?.setImageResource(getBackground())
|
||||
|
||||
setupAdapter()
|
||||
setupRecyclerView()
|
||||
setupObserver()
|
||||
setupSearch()
|
||||
|
||||
setupActivityResultLaunchers()
|
||||
|
||||
savedInstanceState?.let { bundle ->
|
||||
val scrollPosition = bundle.getInt(EXTRA_SCROLL_POS, -1)
|
||||
val scrollOffset = bundle.getInt(EXTRA_SCROLL_OFFSET, 0)
|
||||
if (scrollPosition > -1) {
|
||||
binding?.MainListView?.post {
|
||||
val layoutManager = binding?.MainListView?.layoutManager as? LinearLayoutManager
|
||||
layoutManager?.scrollToPositionWithOffset(scrollPosition, scrollOffset)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupActivityResultLaunchers() {
|
||||
openNoteActivityResultLauncher =
|
||||
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
|
||||
if (result.resultCode == RESULT_OK) {
|
||||
// If a note has been moved inside of EditActivity
|
||||
// present snackbar to undo it
|
||||
val data = result.data
|
||||
val id = data?.getLongExtra(EXTRA_NOTE_ID, -1)
|
||||
if (id != null) {
|
||||
val folderFrom = Folder.valueOf(data.getStringExtra(EXTRA_FOLDER_FROM)!!)
|
||||
val folderTo = Folder.valueOf(data.getStringExtra(EXTRA_FOLDER_TO)!!)
|
||||
Snackbar.make(
|
||||
binding!!.root,
|
||||
requireContext().getQuantityString(folderTo.movedToResId(), 1),
|
||||
Snackbar.LENGTH_SHORT,
|
||||
)
|
||||
.apply {
|
||||
setAction(R.string.undo) {
|
||||
model.moveBaseNotes(longArrayOf(id), folderFrom)
|
||||
}
|
||||
}
|
||||
.show()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?,
|
||||
): View? {
|
||||
setHasOptionsMenu(true)
|
||||
binding = FragmentNotesBinding.inflate(inflater)
|
||||
return binding?.root
|
||||
}
|
||||
|
||||
// See [RecyclerView.ViewHolder.getAdapterPosition]
|
||||
override fun onClick(position: Int) {
|
||||
if (position != -1) {
|
||||
notesAdapter?.getItem(position)?.let { item ->
|
||||
if (item is BaseNote) {
|
||||
if (model.actionMode.isEnabled()) {
|
||||
handleNoteSelection(item.id, position, item)
|
||||
} else {
|
||||
when (item.type) {
|
||||
Type.NOTE -> goToActivity(EditNoteActivity::class.java, item)
|
||||
Type.LIST -> goToActivity(EditListActivity::class.java, item)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onLongClick(position: Int) {
|
||||
if (position != -1) {
|
||||
if (model.actionMode.selectedNotes.isNotEmpty()) {
|
||||
if (lastSelectedNotePosition > position) {
|
||||
position..lastSelectedNotePosition
|
||||
} else {
|
||||
lastSelectedNotePosition..position
|
||||
}
|
||||
.forEach { pos ->
|
||||
notesAdapter!!.getItem(pos)?.let { item ->
|
||||
if (item is BaseNote) {
|
||||
if (!model.actionMode.selectedNotes.contains(item.id)) {
|
||||
handleNoteSelection(item.id, pos, item)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
notesAdapter?.getItem(position)?.let { item ->
|
||||
if (item is BaseNote) {
|
||||
handleNoteSelection(item.id, position, item)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupSearch() {
|
||||
binding?.EnterSearchKeyword?.apply {
|
||||
setText(model.keyword)
|
||||
val navController = findNavController()
|
||||
navController.addOnDestinationChangedListener { controller, destination, arguments ->
|
||||
if (destination.id == R.id.Search) {
|
||||
// setText("")
|
||||
visibility = View.VISIBLE
|
||||
requestFocus()
|
||||
activity?.showKeyboard(this)
|
||||
} else {
|
||||
// visibility = View.GONE
|
||||
setText("")
|
||||
clearFocus()
|
||||
activity?.hideKeyboard(this)
|
||||
}
|
||||
}
|
||||
doAfterTextChanged { text ->
|
||||
model.keyword = requireNotNull(text).trim().toString()
|
||||
if (
|
||||
model.keyword.isNotEmpty() &&
|
||||
navController.currentDestination?.id != R.id.Search
|
||||
) {
|
||||
val bundle =
|
||||
Bundle().apply {
|
||||
putSerializable(EXTRA_INITIAL_FOLDER, model.folder.value)
|
||||
putSerializable(EXTRA_INITIAL_LABEL, model.currentLabel)
|
||||
}
|
||||
navController.navigate(R.id.Search, bundle)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun handleNoteSelection(id: Long, position: Int, baseNote: BaseNote) {
|
||||
if (model.actionMode.selectedNotes.contains(id)) {
|
||||
model.actionMode.remove(id)
|
||||
} else {
|
||||
model.actionMode.add(id, baseNote)
|
||||
lastSelectedNotePosition = position
|
||||
}
|
||||
notesAdapter?.notifyItemChanged(position, 0)
|
||||
}
|
||||
|
||||
private fun setupAdapter() {
|
||||
notesAdapter =
|
||||
with(model.preferences) {
|
||||
BaseNoteAdapter(
|
||||
model.actionMode.selectedIds,
|
||||
dateFormat.value,
|
||||
notesSorting.value,
|
||||
BaseNoteVHPreferences(
|
||||
textSize.value,
|
||||
maxItems.value,
|
||||
maxLines.value,
|
||||
maxTitle.value,
|
||||
labelTagsHiddenInOverview.value,
|
||||
),
|
||||
model.imageRoot,
|
||||
this@NotallyFragment,
|
||||
)
|
||||
}
|
||||
|
||||
notesAdapter?.registerAdapterDataObserver(
|
||||
object : RecyclerView.AdapterDataObserver() {
|
||||
override fun onItemRangeInserted(positionStart: Int, itemCount: Int) {
|
||||
if (itemCount > 0) {
|
||||
binding?.MainListView?.scrollToPosition(positionStart)
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
binding?.MainListView?.apply {
|
||||
adapter = notesAdapter
|
||||
setHasFixedSize(false)
|
||||
}
|
||||
model.actionMode.addListener = { notesAdapter?.notifyDataSetChanged() }
|
||||
if (activity is MainActivity) {
|
||||
(activity as MainActivity).getCurrentFragmentNotes = {
|
||||
notesAdapter?.currentList?.filterIsInstance<BaseNote>()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupObserver() {
|
||||
getObservable().observe(viewLifecycleOwner) { list ->
|
||||
notesAdapter?.submitList(list)
|
||||
binding?.ImageView?.isVisible = list.isEmpty()
|
||||
}
|
||||
|
||||
model.preferences.notesSorting.observe(viewLifecycleOwner) { notesSort ->
|
||||
notesAdapter?.setNotesSort(notesSort)
|
||||
}
|
||||
|
||||
model.actionMode.closeListener.observe(viewLifecycleOwner) { event ->
|
||||
event.handle { ids ->
|
||||
notesAdapter?.currentList?.forEachIndexed { index, item ->
|
||||
if (item is BaseNote && ids.contains(item.id)) {
|
||||
notesAdapter?.notifyItemChanged(index, 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupRecyclerView() {
|
||||
binding?.MainListView?.layoutManager =
|
||||
if (model.preferences.notesView.value == NotesView.GRID) {
|
||||
StaggeredGridLayoutManager(2, RecyclerView.VERTICAL)
|
||||
} else LinearLayoutManager(requireContext())
|
||||
}
|
||||
|
||||
private fun goToActivity(activity: Class<*>, baseNote: BaseNote) {
|
||||
val intent = Intent(requireContext(), activity)
|
||||
intent.putExtra(EXTRA_SELECTED_BASE_NOTE, baseNote.id)
|
||||
openNoteActivityResultLauncher.launch(intent)
|
||||
}
|
||||
|
||||
abstract fun getBackground(): Int
|
||||
|
||||
abstract fun getObservable(): LiveData<List<Item>>
|
||||
|
||||
open fun prepareNewNoteIntent(intent: Intent): Intent {
|
||||
return intent
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val EXTRA_SCROLL_POS = "notallyx.intent.extra.SCROLL_POS"
|
||||
private const val EXTRA_SCROLL_OFFSET = "notallyx.intent.extra.SCROLL_OFFSET"
|
||||
}
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
package com.philkes.notallyx.presentation.activity.main.fragment
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import com.philkes.notallyx.R
|
||||
import com.philkes.notallyx.data.model.Folder
|
||||
|
||||
class NotesFragment : NotallyFragment() {
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
model.folder.value = Folder.NOTES
|
||||
}
|
||||
|
||||
override fun getObservable() = model.baseNotes!!
|
||||
|
||||
override fun getBackground() = R.drawable.notebook
|
||||
}
|
|
@ -1,84 +0,0 @@
|
|||
package com.philkes.notallyx.presentation.activity.main.fragment
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.activityViewModels
|
||||
import com.philkes.notallyx.R
|
||||
import com.philkes.notallyx.data.dao.NoteReminder
|
||||
import com.philkes.notallyx.data.model.hasAnyUpcomingNotifications
|
||||
import com.philkes.notallyx.databinding.FragmentRemindersBinding
|
||||
import com.philkes.notallyx.presentation.activity.note.reminders.RemindersActivity
|
||||
import com.philkes.notallyx.presentation.initListView
|
||||
import com.philkes.notallyx.presentation.view.main.reminder.NoteReminderAdapter
|
||||
import com.philkes.notallyx.presentation.view.main.reminder.NoteReminderListener
|
||||
import com.philkes.notallyx.presentation.viewmodel.BaseNoteModel
|
||||
import com.philkes.notallyx.utils.getOpenNoteIntent
|
||||
|
||||
class RemindersFragment : Fragment(), NoteReminderListener {
|
||||
|
||||
private var reminderAdapter: NoteReminderAdapter? = null
|
||||
private var binding: FragmentRemindersBinding? = null
|
||||
private lateinit var allReminders: List<NoteReminder>
|
||||
|
||||
private val model: BaseNoteModel by activityViewModels()
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
binding = null
|
||||
reminderAdapter = null
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
reminderAdapter = NoteReminderAdapter(this)
|
||||
|
||||
binding?.MainListView?.apply {
|
||||
initListView(requireContext())
|
||||
adapter = reminderAdapter
|
||||
binding?.ImageView?.setImageResource(R.drawable.notifications)
|
||||
}
|
||||
binding?.ChipGroup?.setOnCheckedStateChangeListener { _, _ -> updateList() }
|
||||
|
||||
model.reminders.observe(viewLifecycleOwner) { reminders ->
|
||||
allReminders = reminders.sortedBy { it.title }
|
||||
updateList()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?,
|
||||
): View? {
|
||||
setHasOptionsMenu(true)
|
||||
binding = FragmentRemindersBinding.inflate(inflater)
|
||||
return binding?.root
|
||||
}
|
||||
|
||||
private fun updateList() {
|
||||
val list =
|
||||
when (binding?.ChipGroup?.checkedChipId) {
|
||||
R.id.Upcoming -> allReminders.filter { it.reminders.hasAnyUpcomingNotifications() }
|
||||
R.id.Past -> allReminders.filter { !it.reminders.hasAnyUpcomingNotifications() }
|
||||
else -> allReminders
|
||||
}
|
||||
reminderAdapter?.submitList(list)
|
||||
binding?.ImageView?.isVisible = list.isEmpty()
|
||||
}
|
||||
|
||||
override fun openReminder(reminder: NoteReminder) {
|
||||
val intent =
|
||||
Intent(requireContext(), RemindersActivity::class.java).apply {
|
||||
putExtra(RemindersActivity.NOTE_ID, reminder.id)
|
||||
}
|
||||
startActivity(intent)
|
||||
}
|
||||
|
||||
override fun openNote(reminder: NoteReminder) {
|
||||
startActivity(requireContext().getOpenNoteIntent(reminder.id, reminder.type))
|
||||
}
|
||||
}
|
|
@ -1,57 +0,0 @@
|
|||
package com.philkes.notallyx.presentation.activity.main.fragment
|
||||
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import androidx.core.os.BundleCompat
|
||||
import androidx.core.view.isVisible
|
||||
import com.philkes.notallyx.R
|
||||
import com.philkes.notallyx.data.model.Folder
|
||||
|
||||
class SearchFragment : NotallyFragment() {
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
// TODO: autofocus and show keyboard
|
||||
val initialFolder =
|
||||
arguments?.let {
|
||||
BundleCompat.getSerializable(it, EXTRA_INITIAL_FOLDER, Folder::class.java)
|
||||
}
|
||||
binding?.ChipGroup?.visibility = View.VISIBLE
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
binding?.MainListView?.scrollIndicators = View.SCROLL_INDICATOR_TOP
|
||||
}
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
val initialLabel = arguments?.getString(EXTRA_INITIAL_LABEL)
|
||||
model.currentLabel = initialLabel
|
||||
if (initialLabel?.isEmpty() == true) {
|
||||
val checked =
|
||||
when (initialFolder ?: model.folder.value) {
|
||||
Folder.NOTES -> R.id.Notes
|
||||
Folder.DELETED -> R.id.Deleted
|
||||
Folder.ARCHIVED -> R.id.Archived
|
||||
}
|
||||
|
||||
binding?.ChipGroup?.apply {
|
||||
setOnCheckedStateChangeListener { _, checkedId ->
|
||||
when (checkedId.first()) {
|
||||
R.id.Notes -> model.folder.value = Folder.NOTES
|
||||
R.id.Deleted -> model.folder.value = Folder.DELETED
|
||||
R.id.Archived -> model.folder.value = Folder.ARCHIVED
|
||||
}
|
||||
}
|
||||
check(checked)
|
||||
isVisible = true
|
||||
}
|
||||
} else binding?.ChipGroup?.isVisible = false
|
||||
}
|
||||
|
||||
override fun getBackground() = R.drawable.search
|
||||
|
||||
override fun getObservable() = model.searchResults!!
|
||||
|
||||
companion object {
|
||||
const val EXTRA_INITIAL_FOLDER = "notallyx.intent.extra.INITIAL_FOLDER"
|
||||
const val EXTRA_INITIAL_LABEL = "notallyx.intent.extra.INITIAL_LABEL"
|
||||
}
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
package com.philkes.notallyx.presentation.activity.main.fragment
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import androidx.lifecycle.LiveData
|
||||
import com.philkes.notallyx.R
|
||||
import com.philkes.notallyx.data.model.Folder
|
||||
import com.philkes.notallyx.data.model.Item
|
||||
|
||||
class UnlabeledFragment : NotallyFragment() {
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
model.folder.value = Folder.NOTES
|
||||
}
|
||||
|
||||
override fun getBackground() = R.drawable.label_off
|
||||
|
||||
override fun getObservable(): LiveData<List<Item>> {
|
||||
return model.getNotesWithoutLabel()
|
||||
}
|
||||
}
|
|
@ -1,559 +0,0 @@
|
|||
package com.philkes.notallyx.presentation.activity.main.fragment.settings
|
||||
|
||||
import android.content.Context
|
||||
import android.hardware.biometrics.BiometricManager
|
||||
import android.net.Uri
|
||||
import android.text.method.PasswordTransformationMethod
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.documentfile.provider.DocumentFile
|
||||
import com.google.android.material.color.DynamicColors
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import com.google.android.material.slider.Slider
|
||||
import com.google.android.material.textfield.TextInputLayout.END_ICON_PASSWORD_TOGGLE
|
||||
import com.philkes.notallyx.R
|
||||
import com.philkes.notallyx.databinding.ChoiceItemBinding
|
||||
import com.philkes.notallyx.databinding.DialogNotesSortBinding
|
||||
import com.philkes.notallyx.databinding.DialogPreferenceBooleanBinding
|
||||
import com.philkes.notallyx.databinding.DialogPreferenceEnumWithToggleBinding
|
||||
import com.philkes.notallyx.databinding.DialogSelectionBoxBinding
|
||||
import com.philkes.notallyx.databinding.DialogTextInputBinding
|
||||
import com.philkes.notallyx.databinding.PreferenceBinding
|
||||
import com.philkes.notallyx.databinding.PreferenceSeekbarBinding
|
||||
import com.philkes.notallyx.presentation.checkedTag
|
||||
import com.philkes.notallyx.presentation.select
|
||||
import com.philkes.notallyx.presentation.setCancelButton
|
||||
import com.philkes.notallyx.presentation.showAndFocus
|
||||
import com.philkes.notallyx.presentation.showToast
|
||||
import com.philkes.notallyx.presentation.view.misc.MenuDialog
|
||||
import com.philkes.notallyx.presentation.viewmodel.BaseNoteModel
|
||||
import com.philkes.notallyx.presentation.viewmodel.preference.BiometricLock
|
||||
import com.philkes.notallyx.presentation.viewmodel.preference.BooleanPreference
|
||||
import com.philkes.notallyx.presentation.viewmodel.preference.Constants.PASSWORD_EMPTY
|
||||
import com.philkes.notallyx.presentation.viewmodel.preference.DateFormat
|
||||
import com.philkes.notallyx.presentation.viewmodel.preference.EnumPreference
|
||||
import com.philkes.notallyx.presentation.viewmodel.preference.IntPreference
|
||||
import com.philkes.notallyx.presentation.viewmodel.preference.NotallyXPreferences.Companion.EMPTY_PATH
|
||||
import com.philkes.notallyx.presentation.viewmodel.preference.NotallyXPreferences.Companion.START_VIEW_DEFAULT
|
||||
import com.philkes.notallyx.presentation.viewmodel.preference.NotallyXPreferences.Companion.START_VIEW_UNLABELED
|
||||
import com.philkes.notallyx.presentation.viewmodel.preference.NotesSort
|
||||
import com.philkes.notallyx.presentation.viewmodel.preference.NotesSortBy
|
||||
import com.philkes.notallyx.presentation.viewmodel.preference.NotesSortPreference
|
||||
import com.philkes.notallyx.presentation.viewmodel.preference.SortDirection
|
||||
import com.philkes.notallyx.presentation.viewmodel.preference.StringPreference
|
||||
import com.philkes.notallyx.presentation.viewmodel.preference.TextProvider
|
||||
import com.philkes.notallyx.presentation.viewmodel.preference.Theme
|
||||
import com.philkes.notallyx.utils.canAuthenticateWithBiometrics
|
||||
import com.philkes.notallyx.utils.toReadablePath
|
||||
|
||||
inline fun <reified T> PreferenceBinding.setup(
|
||||
enumPreference: EnumPreference<T>,
|
||||
value: T,
|
||||
context: Context,
|
||||
crossinline onSave: (newValue: T) -> Unit,
|
||||
) where T : Enum<T>, T : TextProvider {
|
||||
Title.setText(enumPreference.titleResId!!)
|
||||
Value.text = value.getText(context)
|
||||
val enumEntries = T::class.java.enumConstants!!.toList()
|
||||
val entries = enumEntries.map { it.getText(context) }.toTypedArray()
|
||||
val checked = enumEntries.indexOfFirst { it == value }
|
||||
root.setOnClickListener {
|
||||
MaterialAlertDialogBuilder(context)
|
||||
.setTitle(enumPreference.titleResId)
|
||||
.setSingleChoiceItems(entries, checked) { dialog, which ->
|
||||
dialog.cancel()
|
||||
val newValue = enumEntries[which]
|
||||
onSave(newValue)
|
||||
}
|
||||
.setCancelButton()
|
||||
.show()
|
||||
}
|
||||
}
|
||||
|
||||
fun PreferenceBinding.setup(
|
||||
preference: EnumPreference<BiometricLock>,
|
||||
value: BiometricLock,
|
||||
context: Context,
|
||||
model: BaseNoteModel,
|
||||
onEnableSuccess: () -> Unit,
|
||||
onDisableSuccess: () -> Unit,
|
||||
onNotSetup: () -> Unit,
|
||||
) {
|
||||
Title.setText(preference.titleResId!!)
|
||||
|
||||
Value.text = value.getText(context)
|
||||
val enumEntries = BiometricLock.entries
|
||||
val entries = enumEntries.map { context.getString(it.textResId) }.toTypedArray()
|
||||
val checked = enumEntries.indexOfFirst { it == value }
|
||||
|
||||
root.setOnClickListener {
|
||||
MaterialAlertDialogBuilder(context)
|
||||
.setTitle(preference.titleResId)
|
||||
.setSingleChoiceItems(entries, checked) { dialog, which ->
|
||||
dialog.cancel()
|
||||
val newValue = enumEntries[which]
|
||||
if (newValue == value) {
|
||||
return@setSingleChoiceItems
|
||||
}
|
||||
if (newValue == BiometricLock.ENABLED) {
|
||||
when (context.canAuthenticateWithBiometrics()) {
|
||||
BiometricManager.BIOMETRIC_SUCCESS -> onEnableSuccess()
|
||||
BiometricManager.BIOMETRIC_ERROR_NO_HARDWARE -> {
|
||||
context.showToast(R.string.biometrics_no_support)
|
||||
}
|
||||
|
||||
BiometricManager.BIOMETRIC_ERROR_NONE_ENROLLED -> onNotSetup()
|
||||
}
|
||||
} else {
|
||||
when (context.canAuthenticateWithBiometrics()) {
|
||||
BiometricManager.BIOMETRIC_SUCCESS -> onDisableSuccess()
|
||||
BiometricManager.BIOMETRIC_ERROR_NO_HARDWARE -> {
|
||||
context.showToast(R.string.biometrics_no_support)
|
||||
model.savePreference(
|
||||
model.preferences.biometricLock,
|
||||
BiometricLock.DISABLED,
|
||||
)
|
||||
}
|
||||
|
||||
BiometricManager.BIOMETRIC_ERROR_NONE_ENROLLED -> {
|
||||
onNotSetup()
|
||||
model.savePreference(
|
||||
model.preferences.biometricLock,
|
||||
BiometricLock.DISABLED,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.setCancelButton()
|
||||
.show()
|
||||
}
|
||||
}
|
||||
|
||||
fun PreferenceBinding.setup(
|
||||
preference: NotesSortPreference,
|
||||
value: NotesSort,
|
||||
context: Context,
|
||||
layoutInflater: LayoutInflater,
|
||||
model: BaseNoteModel,
|
||||
) {
|
||||
Title.setText(preference.titleResId!!)
|
||||
|
||||
Value.text = value.getText(context)
|
||||
|
||||
root.setOnClickListener {
|
||||
val layout = DialogNotesSortBinding.inflate(layoutInflater, null, false)
|
||||
NotesSortBy.entries.forEachIndexed { idx, notesSortBy ->
|
||||
ChoiceItemBinding.inflate(layoutInflater).root.apply {
|
||||
id = idx
|
||||
text = context.getString(notesSortBy.textResId)
|
||||
tag = notesSortBy
|
||||
layout.NotesSortByRadioGroup.addView(this)
|
||||
setCompoundDrawablesRelativeWithIntrinsicBounds(notesSortBy.iconResId, 0, 0, 0)
|
||||
if (notesSortBy == value.sortedBy) {
|
||||
layout.NotesSortByRadioGroup.check(this.id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SortDirection.entries.forEachIndexed { idx, sortDir ->
|
||||
ChoiceItemBinding.inflate(layoutInflater).root.apply {
|
||||
id = idx
|
||||
text = context.getString(sortDir.textResId)
|
||||
tag = sortDir
|
||||
setCompoundDrawablesRelativeWithIntrinsicBounds(sortDir.iconResId, 0, 0, 0)
|
||||
layout.NotesSortDirectionRadioGroup.addView(this)
|
||||
if (sortDir == value.sortDirection) {
|
||||
layout.NotesSortDirectionRadioGroup.check(this.id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MaterialAlertDialogBuilder(context)
|
||||
.setTitle(preference.titleResId)
|
||||
.setView(layout.root)
|
||||
.setPositiveButton(R.string.save) { dialog, _ ->
|
||||
dialog.cancel()
|
||||
val newSortBy = layout.NotesSortByRadioGroup.checkedTag() as NotesSortBy
|
||||
val newSortDirection =
|
||||
layout.NotesSortDirectionRadioGroup.checkedTag() as SortDirection
|
||||
model.savePreference(
|
||||
model.preferences.notesSorting,
|
||||
NotesSort(newSortBy, newSortDirection),
|
||||
)
|
||||
}
|
||||
.setCancelButton()
|
||||
.show()
|
||||
}
|
||||
}
|
||||
|
||||
fun PreferenceBinding.setup(
|
||||
dateFormatPreference: EnumPreference<DateFormat>,
|
||||
dateFormatValue: DateFormat,
|
||||
applyToNoteViewValue: Boolean,
|
||||
context: Context,
|
||||
layoutInflater: LayoutInflater,
|
||||
onSave: (dateFormat: DateFormat, applyToEditMode: Boolean) -> Unit,
|
||||
) {
|
||||
Title.setText(dateFormatPreference.titleResId!!)
|
||||
|
||||
Value.text = dateFormatValue.getText(context)
|
||||
|
||||
root.setOnClickListener {
|
||||
val layout = DialogPreferenceEnumWithToggleBinding.inflate(layoutInflater, null, false)
|
||||
layout.EnumHint.apply {
|
||||
setText(R.string.date_format_hint)
|
||||
isVisible = true
|
||||
}
|
||||
DateFormat.entries.forEachIndexed { idx, dateFormat ->
|
||||
ChoiceItemBinding.inflate(layoutInflater).root.apply {
|
||||
id = idx
|
||||
text = dateFormat.getText(context)
|
||||
tag = dateFormat
|
||||
layout.EnumRadioGroup.addView(this)
|
||||
if (dateFormat == dateFormatValue) {
|
||||
layout.EnumRadioGroup.check(this.id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
layout.Toggle.apply {
|
||||
setText(R.string.date_format_apply_in_note_view)
|
||||
isChecked = applyToNoteViewValue
|
||||
}
|
||||
|
||||
MaterialAlertDialogBuilder(context)
|
||||
.setTitle(dateFormatPreference.titleResId)
|
||||
.setView(layout.root)
|
||||
.setPositiveButton(R.string.save) { dialog, _ ->
|
||||
dialog.cancel()
|
||||
val dateFormat = layout.EnumRadioGroup.checkedTag() as DateFormat
|
||||
val applyToNoteView = layout.Toggle.isChecked
|
||||
onSave(dateFormat, applyToNoteView)
|
||||
}
|
||||
.setCancelButton()
|
||||
.show()
|
||||
}
|
||||
}
|
||||
|
||||
fun PreferenceBinding.setup(
|
||||
themePreference: EnumPreference<Theme>,
|
||||
themeValue: Theme,
|
||||
useDynamicColorsValue: Boolean,
|
||||
context: Context,
|
||||
layoutInflater: LayoutInflater,
|
||||
onSave: (theme: Theme, useDynamicColors: Boolean) -> Unit,
|
||||
) {
|
||||
Title.setText(themePreference.titleResId!!)
|
||||
|
||||
Value.text = themeValue.getText(context)
|
||||
|
||||
root.setOnClickListener {
|
||||
val layout = DialogPreferenceEnumWithToggleBinding.inflate(layoutInflater, null, false)
|
||||
Theme.entries.forEachIndexed { idx, theme ->
|
||||
ChoiceItemBinding.inflate(layoutInflater).root.apply {
|
||||
id = idx
|
||||
text = theme.getText(context)
|
||||
tag = theme
|
||||
layout.EnumRadioGroup.addView(this)
|
||||
if (theme == themeValue) {
|
||||
layout.EnumRadioGroup.check(this.id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
layout.Toggle.apply {
|
||||
isVisible = DynamicColors.isDynamicColorAvailable()
|
||||
setText(R.string.theme_use_dynamic_colors)
|
||||
isChecked = useDynamicColorsValue
|
||||
}
|
||||
|
||||
MaterialAlertDialogBuilder(context)
|
||||
.setTitle(themePreference.titleResId)
|
||||
.setView(layout.root)
|
||||
.setPositiveButton(R.string.save) { dialog, _ ->
|
||||
dialog.cancel()
|
||||
val theme = layout.EnumRadioGroup.checkedTag() as Theme
|
||||
val useDynamicColors = layout.Toggle.isChecked
|
||||
onSave(theme, useDynamicColors)
|
||||
}
|
||||
.setCancelButton()
|
||||
.show()
|
||||
}
|
||||
}
|
||||
|
||||
fun PreferenceBinding.setup(
|
||||
preference: BooleanPreference,
|
||||
value: Boolean,
|
||||
context: Context,
|
||||
layoutInflater: LayoutInflater,
|
||||
messageResId: Int? = null,
|
||||
enabled: Boolean = true,
|
||||
disabledTextResId: Int? = null,
|
||||
onSave: (newValue: Boolean) -> Unit,
|
||||
) {
|
||||
Title.setText(preference.titleResId!!)
|
||||
|
||||
if (enabled) {
|
||||
Value.setText(if (value) R.string.enabled else R.string.disabled)
|
||||
} else {
|
||||
disabledTextResId?.let { Value.setText(it) }
|
||||
}
|
||||
root.isEnabled = enabled
|
||||
root.setOnClickListener {
|
||||
val layout =
|
||||
DialogPreferenceBooleanBinding.inflate(layoutInflater, null, false).apply {
|
||||
Title.setText(preference.titleResId)
|
||||
messageResId?.let { Message.setText(it) }
|
||||
if (value) {
|
||||
EnabledButton.isChecked = true
|
||||
} else {
|
||||
DisabledButton.isChecked = true
|
||||
}
|
||||
}
|
||||
val dialog =
|
||||
MaterialAlertDialogBuilder(context).setView(layout.root).setCancelButton().show()
|
||||
layout.apply {
|
||||
EnabledButton.setOnClickListener {
|
||||
dialog.cancel()
|
||||
if (!value) {
|
||||
onSave.invoke(true)
|
||||
}
|
||||
}
|
||||
DisabledButton.setOnClickListener {
|
||||
dialog.cancel()
|
||||
if (value) {
|
||||
onSave.invoke(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun PreferenceBinding.setupPeriodicBackup(
|
||||
value: Boolean,
|
||||
context: Context,
|
||||
layoutInflater: LayoutInflater,
|
||||
enabled: Boolean,
|
||||
onSave: (newValue: Boolean) -> Unit,
|
||||
) {
|
||||
Title.setText(R.string.backup_periodic)
|
||||
val enabledText = context.getString(R.string.enabled)
|
||||
val disabledText = context.getString(R.string.disabled)
|
||||
val text =
|
||||
if (enabled) {
|
||||
if (value) enabledText else disabledText
|
||||
} else context.getString(R.string.auto_backups_folder_set)
|
||||
Value.text = text
|
||||
root.isEnabled = enabled
|
||||
root.setOnClickListener {
|
||||
val layout =
|
||||
DialogPreferenceBooleanBinding.inflate(layoutInflater, null, false).apply {
|
||||
Title.setText(R.string.backup_periodic)
|
||||
Message.setText(R.string.backup_periodic_hint)
|
||||
if (value) {
|
||||
EnabledButton.isChecked = true
|
||||
} else {
|
||||
DisabledButton.isChecked = true
|
||||
}
|
||||
}
|
||||
val dialog =
|
||||
MaterialAlertDialogBuilder(context).setView(layout.root).setCancelButton().show()
|
||||
layout.apply {
|
||||
EnabledButton.setOnClickListener {
|
||||
dialog.cancel()
|
||||
if (!value) {
|
||||
onSave.invoke(true)
|
||||
}
|
||||
}
|
||||
DisabledButton.setOnClickListener {
|
||||
dialog.cancel()
|
||||
if (value) {
|
||||
onSave.invoke(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun PreferenceBinding.setupBackupPassword(
|
||||
preference: StringPreference,
|
||||
password: String,
|
||||
context: Context,
|
||||
layoutInflater: LayoutInflater,
|
||||
onSave: (newValue: String) -> Unit,
|
||||
) {
|
||||
Title.setText(preference.titleResId!!)
|
||||
|
||||
Value.transformationMethod =
|
||||
if (password != PASSWORD_EMPTY) PasswordTransformationMethod.getInstance() else null
|
||||
Value.text =
|
||||
if (password != PASSWORD_EMPTY) password else context.getText(R.string.tap_to_set_up)
|
||||
root.setOnClickListener {
|
||||
val layout = DialogTextInputBinding.inflate(layoutInflater, null, false)
|
||||
layout.InputText.apply {
|
||||
if (password != PASSWORD_EMPTY) {
|
||||
setText(password)
|
||||
}
|
||||
transformationMethod = PasswordTransformationMethod.getInstance()
|
||||
}
|
||||
layout.InputTextLayout.endIconMode = END_ICON_PASSWORD_TOGGLE
|
||||
layout.Message.apply {
|
||||
setText(R.string.backup_password_hint)
|
||||
visibility = View.VISIBLE
|
||||
}
|
||||
MaterialAlertDialogBuilder(context)
|
||||
.setTitle(preference.titleResId)
|
||||
.setView(layout.root)
|
||||
.setPositiveButton(R.string.save) { dialog, _ ->
|
||||
dialog.cancel()
|
||||
val updatedPassword = layout.InputText.text.toString()
|
||||
onSave(updatedPassword)
|
||||
}
|
||||
.setCancelButton()
|
||||
.setNeutralButton(R.string.clear) { dialog, _ ->
|
||||
dialog.cancel()
|
||||
onSave(PASSWORD_EMPTY)
|
||||
}
|
||||
.showAndFocus(allowFullSize = true)
|
||||
}
|
||||
}
|
||||
|
||||
fun PreferenceBinding.setupBackupsFolder(
|
||||
value: String,
|
||||
context: Context,
|
||||
chooseBackupFolder: () -> Unit,
|
||||
onDisable: () -> Unit,
|
||||
) {
|
||||
Title.setText(R.string.auto_backups_folder)
|
||||
|
||||
if (value == EMPTY_PATH) {
|
||||
Value.setText(R.string.tap_to_set_up)
|
||||
|
||||
root.setOnClickListener { chooseBackupFolder() }
|
||||
} else {
|
||||
val uri = Uri.parse(value)
|
||||
val folder = requireNotNull(DocumentFile.fromTreeUri(context, uri))
|
||||
if (folder.exists()) {
|
||||
val path = uri.toReadablePath()
|
||||
Value.text = path
|
||||
} else Value.setText(R.string.cant_find_folder)
|
||||
|
||||
root.setOnClickListener {
|
||||
MenuDialog(context)
|
||||
.add(R.string.clear) { onDisable() }
|
||||
.add(R.string.choose_another_folder) { chooseBackupFolder() }
|
||||
.show()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun PreferenceSeekbarBinding.setup(
|
||||
value: Int,
|
||||
titleResId: Int,
|
||||
min: Int,
|
||||
max: Int,
|
||||
context: Context,
|
||||
enabled: Boolean = true,
|
||||
onChange: (newValue: Int) -> Unit,
|
||||
) {
|
||||
Title.setText(titleResId)
|
||||
val valueInBoundaries = (if (value < min) min else if (value > max) max else value).toFloat()
|
||||
Slider.apply {
|
||||
isEnabled = enabled
|
||||
valueTo = max.toFloat()
|
||||
valueFrom = min.toFloat()
|
||||
this@apply.value = valueInBoundaries
|
||||
clearOnSliderTouchListeners()
|
||||
addOnSliderTouchListener(
|
||||
object : Slider.OnSliderTouchListener {
|
||||
override fun onStartTrackingTouch(slider: Slider) {}
|
||||
|
||||
override fun onStopTrackingTouch(slider: Slider) {
|
||||
onChange(slider.value.toInt())
|
||||
}
|
||||
}
|
||||
)
|
||||
contentDescription = context.getString(titleResId)
|
||||
}
|
||||
}
|
||||
|
||||
fun PreferenceSeekbarBinding.setup(
|
||||
preference: IntPreference,
|
||||
context: Context,
|
||||
value: Int = preference.value,
|
||||
onChange: (newValue: Int) -> Unit,
|
||||
) {
|
||||
setup(value, preference.titleResId!!, preference.min, preference.max, context) { newValue ->
|
||||
onChange(newValue)
|
||||
}
|
||||
}
|
||||
|
||||
fun PreferenceSeekbarBinding.setupAutoSaveIdleTime(
|
||||
preference: IntPreference,
|
||||
context: Context,
|
||||
value: Int = preference.value,
|
||||
onChange: (newValue: Int) -> Unit,
|
||||
) {
|
||||
Slider.apply {
|
||||
setLabelFormatter { sliderValue ->
|
||||
if (sliderValue == -1f) {
|
||||
context.getString(R.string.disabled)
|
||||
} else "${sliderValue.toInt()}s"
|
||||
}
|
||||
addOnChangeListener { _, value, _ ->
|
||||
if (value == -1f) {
|
||||
setAlpha(0.6f) // Reduce opacity to make it look disabled
|
||||
} else {
|
||||
setAlpha(1f) // Restore normal appearance
|
||||
}
|
||||
}
|
||||
}
|
||||
setup(preference, context, value, onChange)
|
||||
}
|
||||
|
||||
fun PreferenceBinding.setupStartView(
|
||||
preference: StringPreference,
|
||||
value: String,
|
||||
labels: List<String>?,
|
||||
context: Context,
|
||||
layoutInflater: LayoutInflater,
|
||||
onSave: (value: String) -> Unit,
|
||||
) {
|
||||
Title.setText(preference.titleResId!!)
|
||||
|
||||
val notesText = "${context.getText(R.string.notes)} (${context.getText(R.string.text_default)})"
|
||||
val unlabeledText = context.getText(R.string.unlabeled).toString()
|
||||
val textValue =
|
||||
when (value) {
|
||||
START_VIEW_DEFAULT -> notesText
|
||||
START_VIEW_UNLABELED -> unlabeledText
|
||||
else -> value
|
||||
}
|
||||
Value.text = textValue
|
||||
|
||||
root.setOnClickListener {
|
||||
val layout = DialogSelectionBoxBinding.inflate(layoutInflater, null, false)
|
||||
layout.Message.setText(R.string.start_view_hint)
|
||||
val values =
|
||||
mutableListOf(notesText to START_VIEW_DEFAULT, unlabeledText to START_VIEW_UNLABELED)
|
||||
.apply { labels?.forEach { add(it to it) } }
|
||||
var selected = -1
|
||||
layout.SelectionBox.apply {
|
||||
setSimpleItems(values.map { it.first }.toTypedArray())
|
||||
select(textValue)
|
||||
setOnItemClickListener { _, _, position, _ -> selected = position }
|
||||
}
|
||||
MaterialAlertDialogBuilder(context)
|
||||
.setTitle(preference.titleResId)
|
||||
.setView(layout.root)
|
||||
.setPositiveButton(R.string.save) { dialog, _ ->
|
||||
dialog.cancel()
|
||||
val newValue = values[selected].second
|
||||
onSave(newValue)
|
||||
}
|
||||
.setCancelButton()
|
||||
.showAndFocus(allowFullSize = true)
|
||||
}
|
||||
}
|
|
@ -1,856 +0,0 @@
|
|||
package com.philkes.notallyx.presentation.activity.main.fragment.settings
|
||||
|
||||
import android.Manifest
|
||||
import android.app.Application
|
||||
import android.content.ActivityNotFoundException
|
||||
import android.content.Intent
|
||||
import android.content.Intent.ACTION_OPEN_DOCUMENT_TREE
|
||||
import android.content.pm.PackageManager
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.provider.DocumentsContract
|
||||
import android.provider.Settings
|
||||
import android.text.method.PasswordTransformationMethod
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.activity.result.ActivityResultLauncher
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.appcompat.app.AppCompatActivity.RESULT_OK
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.activityViewModels
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import com.google.android.material.textfield.TextInputLayout.END_ICON_PASSWORD_TOGGLE
|
||||
import com.philkes.notallyx.NotallyXApplication
|
||||
import com.philkes.notallyx.R
|
||||
import com.philkes.notallyx.data.imports.FOLDER_OR_FILE_MIMETYPE
|
||||
import com.philkes.notallyx.data.imports.ImportSource
|
||||
import com.philkes.notallyx.data.imports.txt.APPLICATION_TEXT_MIME_TYPES
|
||||
import com.philkes.notallyx.data.model.toText
|
||||
import com.philkes.notallyx.databinding.DialogTextInputBinding
|
||||
import com.philkes.notallyx.databinding.FragmentSettingsBinding
|
||||
import com.philkes.notallyx.presentation.activity.main.MainActivity
|
||||
import com.philkes.notallyx.presentation.setCancelButton
|
||||
import com.philkes.notallyx.presentation.setupImportProgressDialog
|
||||
import com.philkes.notallyx.presentation.setupProgressDialog
|
||||
import com.philkes.notallyx.presentation.showAndFocus
|
||||
import com.philkes.notallyx.presentation.showDialog
|
||||
import com.philkes.notallyx.presentation.showToast
|
||||
import com.philkes.notallyx.presentation.view.misc.TextWithIconAdapter
|
||||
import com.philkes.notallyx.presentation.viewmodel.BaseNoteModel
|
||||
import com.philkes.notallyx.presentation.viewmodel.preference.Constants.PASSWORD_EMPTY
|
||||
import com.philkes.notallyx.presentation.viewmodel.preference.LongPreference
|
||||
import com.philkes.notallyx.presentation.viewmodel.preference.NotallyXPreferences
|
||||
import com.philkes.notallyx.presentation.viewmodel.preference.NotallyXPreferences.Companion.EMPTY_PATH
|
||||
import com.philkes.notallyx.presentation.viewmodel.preference.PeriodicBackup
|
||||
import com.philkes.notallyx.presentation.viewmodel.preference.PeriodicBackup.Companion.BACKUP_MAX_MIN
|
||||
import com.philkes.notallyx.presentation.viewmodel.preference.PeriodicBackup.Companion.BACKUP_PERIOD_DAYS_MIN
|
||||
import com.philkes.notallyx.presentation.viewmodel.preference.PeriodicBackupsPreference
|
||||
import com.philkes.notallyx.utils.MIME_TYPE_JSON
|
||||
import com.philkes.notallyx.utils.MIME_TYPE_ZIP
|
||||
import com.philkes.notallyx.utils.backup.exportPreferences
|
||||
import com.philkes.notallyx.utils.catchNoBrowserInstalled
|
||||
import com.philkes.notallyx.utils.getExtraBooleanFromBundleOrIntent
|
||||
import com.philkes.notallyx.utils.getLastExceptionLog
|
||||
import com.philkes.notallyx.utils.getLogFile
|
||||
import com.philkes.notallyx.utils.getUriForFile
|
||||
import com.philkes.notallyx.utils.reportBug
|
||||
import com.philkes.notallyx.utils.security.showBiometricOrPinPrompt
|
||||
import com.philkes.notallyx.utils.wrapWithChooser
|
||||
import java.util.Date
|
||||
|
||||
class SettingsFragment : Fragment() {
|
||||
|
||||
private val model: BaseNoteModel by activityViewModels()
|
||||
|
||||
private lateinit var importBackupActivityResultLauncher: ActivityResultLauncher<Intent>
|
||||
private lateinit var importOtherActivityResultLauncher: ActivityResultLauncher<Intent>
|
||||
private lateinit var exportBackupActivityResultLauncher: ActivityResultLauncher<Intent>
|
||||
private lateinit var chooseBackupFolderActivityResultLauncher: ActivityResultLauncher<Intent>
|
||||
private lateinit var setupLockActivityResultLauncher: ActivityResultLauncher<Intent>
|
||||
private lateinit var disableLockActivityResultLauncher: ActivityResultLauncher<Intent>
|
||||
private lateinit var exportSettingsActivityResultLauncher: ActivityResultLauncher<Intent>
|
||||
private lateinit var importSettingsActivityResultLauncher: ActivityResultLauncher<Intent>
|
||||
|
||||
private lateinit var selectedImportSource: ImportSource
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?,
|
||||
): View {
|
||||
val binding = FragmentSettingsBinding.inflate(inflater)
|
||||
model.preferences.apply {
|
||||
setupAppearance(binding)
|
||||
setupContentDensity(binding)
|
||||
setupBackup(binding)
|
||||
setupAutoBackups(binding)
|
||||
setupSecurity(binding)
|
||||
setupSettings(binding)
|
||||
}
|
||||
setupAbout(binding)
|
||||
return binding.root
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
setupActivityResultLaunchers()
|
||||
val showImportBackupsFolder =
|
||||
getExtraBooleanFromBundleOrIntent(
|
||||
savedInstanceState,
|
||||
EXTRA_SHOW_IMPORT_BACKUPS_FOLDER,
|
||||
false,
|
||||
)
|
||||
showImportBackupsFolder.let {
|
||||
if (it) {
|
||||
model.refreshBackupsFolder(
|
||||
requireContext(),
|
||||
askForUriPermissions = ::askForUriPermissions,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onSaveInstanceState(outState: Bundle) {
|
||||
super.onSaveInstanceState(outState)
|
||||
if (model.showRefreshBackupsFolderAfterThemeChange) {
|
||||
outState.putBoolean(EXTRA_SHOW_IMPORT_BACKUPS_FOLDER, true)
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupActivityResultLaunchers() {
|
||||
importBackupActivityResultLauncher =
|
||||
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
|
||||
if (result.resultCode == RESULT_OK) {
|
||||
result.data?.data?.let { importBackup(it) }
|
||||
}
|
||||
}
|
||||
importOtherActivityResultLauncher =
|
||||
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
|
||||
if (result.resultCode == RESULT_OK) {
|
||||
result.data?.data?.let { uri ->
|
||||
model.importFromOtherApp(uri, selectedImportSource)
|
||||
}
|
||||
}
|
||||
}
|
||||
exportBackupActivityResultLauncher =
|
||||
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
|
||||
if (result.resultCode == RESULT_OK) {
|
||||
result.data?.data?.let { uri -> model.exportBackup(uri) }
|
||||
}
|
||||
}
|
||||
chooseBackupFolderActivityResultLauncher =
|
||||
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
|
||||
if (result.resultCode == RESULT_OK) {
|
||||
result.data?.data?.let { uri ->
|
||||
model.setupBackupsFolder(uri)
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||
activity?.let {
|
||||
val permission = Manifest.permission.POST_NOTIFICATIONS
|
||||
if (
|
||||
it.checkSelfPermission(permission) !=
|
||||
PackageManager.PERMISSION_GRANTED
|
||||
) {
|
||||
MaterialAlertDialogBuilder(it)
|
||||
.setMessage(
|
||||
R.string.please_grant_notally_notification_auto_backup
|
||||
)
|
||||
.setNegativeButton(R.string.skip, null)
|
||||
.setPositiveButton(R.string.continue_) { _, _ ->
|
||||
it.requestPermissions(arrayOf(permission), 0)
|
||||
}
|
||||
.show()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
setupLockActivityResultLauncher =
|
||||
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
|
||||
showEnableBiometricLock()
|
||||
}
|
||||
disableLockActivityResultLauncher =
|
||||
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
|
||||
showDisableBiometricLock()
|
||||
}
|
||||
exportSettingsActivityResultLauncher =
|
||||
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
|
||||
if (result.resultCode == RESULT_OK) {
|
||||
result.data?.data?.let { uri ->
|
||||
if (requireContext().exportPreferences(model.preferences, uri)) {
|
||||
showToast(R.string.export_settings_success)
|
||||
} else {
|
||||
showToast(R.string.export_settings_failure)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
importSettingsActivityResultLauncher =
|
||||
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
|
||||
if (result.resultCode == RESULT_OK) {
|
||||
result.data?.data?.let { uri ->
|
||||
model.importPreferences(
|
||||
requireContext(),
|
||||
uri,
|
||||
::askForUriPermissions,
|
||||
{ showToast(R.string.import_settings_success) },
|
||||
) {
|
||||
showToast(R.string.import_settings_failure)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun importBackup(uri: Uri) {
|
||||
when (requireContext().contentResolver.getType(uri)) {
|
||||
"text/xml" -> {
|
||||
model.importXmlBackup(uri)
|
||||
}
|
||||
|
||||
MIME_TYPE_ZIP -> {
|
||||
val layout = DialogTextInputBinding.inflate(layoutInflater, null, false)
|
||||
val password = model.preferences.backupPassword.value
|
||||
layout.InputText.apply {
|
||||
if (password != PASSWORD_EMPTY) {
|
||||
setText(password)
|
||||
}
|
||||
transformationMethod = PasswordTransformationMethod.getInstance()
|
||||
}
|
||||
layout.InputTextLayout.endIconMode = END_ICON_PASSWORD_TOGGLE
|
||||
layout.Message.apply {
|
||||
setText(R.string.import_backup_password_hint)
|
||||
visibility = View.VISIBLE
|
||||
}
|
||||
MaterialAlertDialogBuilder(requireContext())
|
||||
.setTitle(R.string.backup_password)
|
||||
.setView(layout.root)
|
||||
.setPositiveButton(R.string.import_backup) { dialog, _ ->
|
||||
dialog.cancel()
|
||||
val usedPassword = layout.InputText.text.toString()
|
||||
model.importZipBackup(uri, usedPassword)
|
||||
}
|
||||
.setCancelButton()
|
||||
.show()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun NotallyXPreferences.setupAppearance(binding: FragmentSettingsBinding) {
|
||||
notesView.observe(viewLifecycleOwner) { value ->
|
||||
binding.View.setup(notesView, value, requireContext()) { newValue ->
|
||||
model.savePreference(notesView, newValue)
|
||||
}
|
||||
}
|
||||
|
||||
theme.merge(useDynamicColors).observe(viewLifecycleOwner) {
|
||||
(themeValue, useDynamicColorsValue) ->
|
||||
binding.Theme.setup(
|
||||
theme,
|
||||
themeValue,
|
||||
useDynamicColorsValue,
|
||||
requireContext(),
|
||||
layoutInflater,
|
||||
) { newThemeValue, newUseDynamicColorsValue ->
|
||||
model.savePreference(theme, newThemeValue)
|
||||
model.savePreference(useDynamicColors, newUseDynamicColorsValue)
|
||||
val packageManager = requireContext().packageManager
|
||||
val intent = packageManager.getLaunchIntentForPackage(requireContext().packageName)
|
||||
val componentName = intent!!.component
|
||||
val mainIntent =
|
||||
Intent.makeRestartActivityTask(componentName).apply {
|
||||
putExtra(MainActivity.EXTRA_FRAGMENT_TO_OPEN, R.id.Settings)
|
||||
}
|
||||
mainIntent.setPackage(requireContext().packageName)
|
||||
requireContext().startActivity(mainIntent)
|
||||
Runtime.getRuntime().exit(0)
|
||||
}
|
||||
}
|
||||
|
||||
dateFormat.merge(applyDateFormatInNoteView).observe(viewLifecycleOwner) {
|
||||
(dateFormatValue, applyDateFormatInEditNoteValue) ->
|
||||
binding.DateFormat.setup(
|
||||
dateFormat,
|
||||
dateFormatValue,
|
||||
applyDateFormatInEditNoteValue,
|
||||
requireContext(),
|
||||
layoutInflater,
|
||||
) { newDateFormatValue, newApplyDateFormatInEditNote ->
|
||||
model.savePreference(dateFormat, newDateFormatValue)
|
||||
model.savePreference(applyDateFormatInNoteView, newApplyDateFormatInEditNote)
|
||||
}
|
||||
}
|
||||
|
||||
textSize.observe(viewLifecycleOwner) { value ->
|
||||
binding.TextSize.setup(textSize, value, requireContext()) { newValue ->
|
||||
model.savePreference(textSize, newValue)
|
||||
}
|
||||
}
|
||||
|
||||
notesSorting.observe(viewLifecycleOwner) { notesSort ->
|
||||
binding.NotesSortOrder.setup(
|
||||
notesSorting,
|
||||
notesSort,
|
||||
requireContext(),
|
||||
layoutInflater,
|
||||
model,
|
||||
)
|
||||
}
|
||||
|
||||
listItemSorting.observe(viewLifecycleOwner) { value ->
|
||||
binding.CheckedListItemSorting.setup(listItemSorting, value, requireContext()) {
|
||||
newValue ->
|
||||
model.savePreference(listItemSorting, newValue)
|
||||
}
|
||||
}
|
||||
|
||||
binding.MaxLabels.setup(maxLabels, requireContext()) { newValue ->
|
||||
model.savePreference(maxLabels, newValue)
|
||||
}
|
||||
|
||||
startView.merge(model.labels).observe(viewLifecycleOwner) { (startViewValue, labelsValue) ->
|
||||
binding.StartView.setupStartView(
|
||||
startView,
|
||||
startViewValue,
|
||||
labelsValue,
|
||||
requireContext(),
|
||||
layoutInflater,
|
||||
) { newValue ->
|
||||
model.savePreference(startView, newValue)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun NotallyXPreferences.setupContentDensity(binding: FragmentSettingsBinding) {
|
||||
binding.apply {
|
||||
MaxTitle.setup(maxTitle, requireContext()) { newValue ->
|
||||
model.savePreference(maxTitle, newValue)
|
||||
}
|
||||
MaxItems.setup(maxItems, requireContext()) { newValue ->
|
||||
model.savePreference(maxItems, newValue)
|
||||
}
|
||||
|
||||
MaxLines.setup(maxLines, requireContext()) { newValue ->
|
||||
model.savePreference(maxLines, newValue)
|
||||
}
|
||||
MaxLabels.setup(maxLabels, requireContext()) { newValue ->
|
||||
model.savePreference(maxLabels, newValue)
|
||||
}
|
||||
labelTagsHiddenInOverview.observe(viewLifecycleOwner) { value ->
|
||||
binding.LabelsHiddenInOverview.setup(
|
||||
labelTagsHiddenInOverview,
|
||||
value,
|
||||
requireContext(),
|
||||
layoutInflater,
|
||||
R.string.labels_hidden_in_overview,
|
||||
) { enabled ->
|
||||
model.savePreference(labelTagsHiddenInOverview, enabled)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun NotallyXPreferences.setupBackup(binding: FragmentSettingsBinding) {
|
||||
binding.apply {
|
||||
ImportBackup.setOnClickListener {
|
||||
val intent =
|
||||
Intent(Intent.ACTION_OPEN_DOCUMENT)
|
||||
.apply {
|
||||
type = "*/*"
|
||||
putExtra(Intent.EXTRA_MIME_TYPES, arrayOf(MIME_TYPE_ZIP, "text/xml"))
|
||||
addCategory(Intent.CATEGORY_OPENABLE)
|
||||
}
|
||||
.wrapWithChooser(requireContext())
|
||||
importBackupActivityResultLauncher.launch(intent)
|
||||
}
|
||||
ImportOther.setOnClickListener { importFromOtherApp() }
|
||||
ExportBackup.setOnClickListener {
|
||||
val intent =
|
||||
Intent(Intent.ACTION_CREATE_DOCUMENT)
|
||||
.apply {
|
||||
type = MIME_TYPE_ZIP
|
||||
addCategory(Intent.CATEGORY_OPENABLE)
|
||||
putExtra(Intent.EXTRA_TITLE, "NotallyX Backup")
|
||||
}
|
||||
.wrapWithChooser(requireContext())
|
||||
exportBackupActivityResultLauncher.launch(intent)
|
||||
}
|
||||
}
|
||||
model.exportProgress.setupProgressDialog(this@SettingsFragment, R.string.exporting_backup)
|
||||
model.importProgress.setupImportProgressDialog(
|
||||
this@SettingsFragment,
|
||||
R.string.importing_backup,
|
||||
)
|
||||
}
|
||||
|
||||
private fun NotallyXPreferences.setupAutoBackups(binding: FragmentSettingsBinding) {
|
||||
backupsFolder.observe(viewLifecycleOwner) { value ->
|
||||
binding.BackupsFolder.setupBackupsFolder(
|
||||
value,
|
||||
requireContext(),
|
||||
::displayChooseBackupFolderDialog,
|
||||
) {
|
||||
model.disableBackups()
|
||||
}
|
||||
}
|
||||
backupOnSave.merge(backupsFolder).observe(viewLifecycleOwner) { (onSave, backupFolder) ->
|
||||
binding.BackupOnSave.setup(
|
||||
backupOnSave,
|
||||
onSave,
|
||||
requireContext(),
|
||||
layoutInflater,
|
||||
messageResId = R.string.auto_backup_on_save,
|
||||
enabled = backupFolder != EMPTY_PATH,
|
||||
disabledTextResId = R.string.auto_backups_folder_set,
|
||||
) { enabled ->
|
||||
model.savePreference(backupOnSave, enabled)
|
||||
}
|
||||
}
|
||||
periodicBackups.merge(backupsFolder).observe(viewLifecycleOwner) {
|
||||
(periodicBackup, backupFolder) ->
|
||||
setupPeriodicBackup(
|
||||
binding,
|
||||
periodicBackup,
|
||||
backupFolder,
|
||||
periodicBackups,
|
||||
periodicBackupLastExecution,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun importFromOtherApp() {
|
||||
MaterialAlertDialogBuilder(requireContext())
|
||||
.setTitle(R.string.choose_other_app)
|
||||
.setAdapter(
|
||||
TextWithIconAdapter(
|
||||
requireContext(),
|
||||
ImportSource.entries.toMutableList(),
|
||||
{ item -> getString(item.displayNameResId) },
|
||||
ImportSource::iconResId,
|
||||
)
|
||||
) { _, which ->
|
||||
selectedImportSource = ImportSource.entries[which]
|
||||
MaterialAlertDialogBuilder(requireContext())
|
||||
.setMessage(selectedImportSource.helpTextResId)
|
||||
.setPositiveButton(R.string.import_action) { dialog, _ ->
|
||||
dialog.cancel()
|
||||
when (selectedImportSource.mimeType) {
|
||||
FOLDER_OR_FILE_MIMETYPE ->
|
||||
MaterialAlertDialogBuilder(requireContext())
|
||||
.setTitle(selectedImportSource.displayNameResId)
|
||||
.setItems(
|
||||
arrayOf(
|
||||
getString(R.string.folder),
|
||||
getString(R.string.single_file),
|
||||
)
|
||||
) { _, which ->
|
||||
when (which) {
|
||||
0 ->
|
||||
importOtherActivityResultLauncher.launch(
|
||||
Intent(Intent.ACTION_OPEN_DOCUMENT_TREE)
|
||||
.apply {
|
||||
addCategory(Intent.CATEGORY_DEFAULT)
|
||||
}
|
||||
.wrapWithChooser(requireContext())
|
||||
)
|
||||
1 ->
|
||||
importOtherActivityResultLauncher.launch(
|
||||
Intent(Intent.ACTION_OPEN_DOCUMENT)
|
||||
.apply {
|
||||
type = "text/*"
|
||||
addCategory(Intent.CATEGORY_OPENABLE)
|
||||
putExtra(
|
||||
Intent.EXTRA_MIME_TYPES,
|
||||
arrayOf("text/*") +
|
||||
APPLICATION_TEXT_MIME_TYPES,
|
||||
)
|
||||
}
|
||||
.wrapWithChooser(requireContext())
|
||||
)
|
||||
}
|
||||
}
|
||||
.setCancelButton()
|
||||
.show()
|
||||
else ->
|
||||
importOtherActivityResultLauncher.launch(
|
||||
Intent(Intent.ACTION_OPEN_DOCUMENT)
|
||||
.apply {
|
||||
type = "application/*"
|
||||
putExtra(
|
||||
Intent.EXTRA_MIME_TYPES,
|
||||
arrayOf(selectedImportSource.mimeType),
|
||||
)
|
||||
addCategory(Intent.CATEGORY_OPENABLE)
|
||||
}
|
||||
.wrapWithChooser(requireContext())
|
||||
)
|
||||
}
|
||||
}
|
||||
.also {
|
||||
selectedImportSource.documentationUrl?.let<String, Unit> { docUrl ->
|
||||
it.setNegativeButton(R.string.help) { _, _ ->
|
||||
val intent =
|
||||
Intent(Intent.ACTION_VIEW)
|
||||
.apply { data = Uri.parse(docUrl) }
|
||||
.wrapWithChooser(requireContext())
|
||||
startActivity(intent)
|
||||
}
|
||||
}
|
||||
}
|
||||
.setNeutralButton(R.string.cancel) { dialog, _ -> dialog.cancel() }
|
||||
.showAndFocus(allowFullSize = true)
|
||||
}
|
||||
.setCancelButton()
|
||||
.show()
|
||||
}
|
||||
|
||||
private fun setupPeriodicBackup(
|
||||
binding: FragmentSettingsBinding,
|
||||
value: PeriodicBackup,
|
||||
backupFolder: String,
|
||||
preference: PeriodicBackupsPreference,
|
||||
lastExecutionPreference: LongPreference,
|
||||
) {
|
||||
val periodicBackupsEnabled = value.periodInDays > 0 && backupFolder != EMPTY_PATH
|
||||
binding.PeriodicBackups.setupPeriodicBackup(
|
||||
periodicBackupsEnabled,
|
||||
requireContext(),
|
||||
layoutInflater,
|
||||
enabled = backupFolder != EMPTY_PATH,
|
||||
) { enabled ->
|
||||
if (enabled) {
|
||||
val periodInDays =
|
||||
preference.value.periodInDays.let {
|
||||
if (it >= BACKUP_PERIOD_DAYS_MIN) it else BACKUP_PERIOD_DAYS_MIN
|
||||
}
|
||||
val maxBackups =
|
||||
preference.value.maxBackups.let {
|
||||
if (it >= BACKUP_MAX_MIN) it else BACKUP_MAX_MIN
|
||||
}
|
||||
model.savePreference(
|
||||
preference,
|
||||
preference.value.copy(periodInDays = periodInDays, maxBackups = maxBackups),
|
||||
)
|
||||
} else {
|
||||
model.savePreference(preference, preference.value.copy(periodInDays = 0))
|
||||
}
|
||||
}
|
||||
lastExecutionPreference.observe(viewLifecycleOwner) { time ->
|
||||
binding.PeriodicBackupLastExecution.apply {
|
||||
if (time != -1L) {
|
||||
isVisible = true
|
||||
text =
|
||||
"${requireContext().getString(R.string.auto_backup_last)}: ${Date(time).toText()}"
|
||||
} else isVisible = false
|
||||
}
|
||||
}
|
||||
binding.PeriodicBackupsPeriodInDays.setup(
|
||||
value.periodInDays,
|
||||
R.string.backup_period_days,
|
||||
PeriodicBackup.BACKUP_PERIOD_DAYS_MIN,
|
||||
PeriodicBackup.BACKUP_PERIOD_DAYS_MAX,
|
||||
requireContext(),
|
||||
enabled = periodicBackupsEnabled,
|
||||
) { newValue ->
|
||||
model.savePreference(preference, preference.value.copy(periodInDays = newValue))
|
||||
}
|
||||
binding.PeriodicBackupsMax.setup(
|
||||
value.maxBackups,
|
||||
R.string.max_backups,
|
||||
PeriodicBackup.BACKUP_MAX_MIN,
|
||||
PeriodicBackup.BACKUP_MAX_MAX,
|
||||
requireContext(),
|
||||
enabled = periodicBackupsEnabled,
|
||||
) { newValue: Int ->
|
||||
model.savePreference(preference, preference.value.copy(maxBackups = newValue))
|
||||
}
|
||||
}
|
||||
|
||||
private fun NotallyXPreferences.setupSecurity(binding: FragmentSettingsBinding) {
|
||||
biometricLock.observe(viewLifecycleOwner) { value ->
|
||||
binding.BiometricLock.setup(
|
||||
biometricLock,
|
||||
value,
|
||||
requireContext(),
|
||||
model,
|
||||
::showEnableBiometricLock,
|
||||
::showDisableBiometricLock,
|
||||
::showBiometricsNotSetupDialog,
|
||||
)
|
||||
}
|
||||
|
||||
backupPassword.observe(viewLifecycleOwner) { value ->
|
||||
binding.BackupPassword.setupBackupPassword(
|
||||
backupPassword,
|
||||
value,
|
||||
requireContext(),
|
||||
layoutInflater,
|
||||
) { newValue ->
|
||||
model.savePreference(backupPassword, newValue)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun NotallyXPreferences.setupSettings(binding: FragmentSettingsBinding) {
|
||||
binding.apply {
|
||||
ImportSettings.setOnClickListener {
|
||||
showDialog(R.string.import_settings_message, R.string.import_action) { _, _ ->
|
||||
val intent =
|
||||
Intent(Intent.ACTION_OPEN_DOCUMENT)
|
||||
.apply {
|
||||
type = MIME_TYPE_JSON
|
||||
addCategory(Intent.CATEGORY_OPENABLE)
|
||||
putExtra(Intent.EXTRA_TITLE, "NotallyX_Settings.json")
|
||||
}
|
||||
.wrapWithChooser(requireContext())
|
||||
importSettingsActivityResultLauncher.launch(intent)
|
||||
}
|
||||
}
|
||||
ExportSettings.setOnClickListener {
|
||||
showDialog(R.string.export_settings_message, R.string.export) { _, _ ->
|
||||
val intent =
|
||||
Intent(Intent.ACTION_CREATE_DOCUMENT)
|
||||
.apply {
|
||||
type = MIME_TYPE_JSON
|
||||
addCategory(Intent.CATEGORY_OPENABLE)
|
||||
putExtra(Intent.EXTRA_TITLE, "NotallyX_Settings.json")
|
||||
}
|
||||
.wrapWithChooser(requireContext())
|
||||
exportSettingsActivityResultLauncher.launch(intent)
|
||||
}
|
||||
}
|
||||
ResetSettings.setOnClickListener {
|
||||
showDialog(R.string.reset_settings_message, R.string.reset_settings) { _, _ ->
|
||||
model.resetPreferences { _ -> showToast(R.string.reset_settings_success) }
|
||||
}
|
||||
}
|
||||
dataInPublicFolder.observe(viewLifecycleOwner) { value ->
|
||||
binding.DataInPublicFolder.setup(
|
||||
dataInPublicFolder,
|
||||
value,
|
||||
requireContext(),
|
||||
layoutInflater,
|
||||
R.string.data_in_public_message,
|
||||
) { enabled ->
|
||||
if (enabled) {
|
||||
model.enableDataInPublic()
|
||||
} else {
|
||||
model.disableDataInPublic()
|
||||
}
|
||||
}
|
||||
}
|
||||
AutoSaveAfterIdle.setupAutoSaveIdleTime(autoSaveAfterIdleTime, requireContext()) {
|
||||
newValue ->
|
||||
model.savePreference(autoSaveAfterIdleTime, newValue)
|
||||
}
|
||||
|
||||
ClearData.setOnClickListener {
|
||||
MaterialAlertDialogBuilder(requireContext())
|
||||
.setMessage(R.string.clear_data_message)
|
||||
.setPositiveButton(R.string.delete_all) { _, _ -> model.deleteAll() }
|
||||
.setCancelButton()
|
||||
.show()
|
||||
}
|
||||
}
|
||||
model.deletionProgress.setupProgressDialog(this@SettingsFragment, R.string.deleting_files)
|
||||
}
|
||||
|
||||
private fun setupAbout(binding: FragmentSettingsBinding) {
|
||||
binding.apply {
|
||||
SendFeedback.setOnClickListener {
|
||||
val options =
|
||||
arrayOf(
|
||||
getString(R.string.report_bug),
|
||||
getString(R.string.make_feature_request),
|
||||
getString(R.string.send_feedback),
|
||||
)
|
||||
MaterialAlertDialogBuilder(requireContext())
|
||||
.setTitle(R.string.send_feedback)
|
||||
.setItems(options) { _, which ->
|
||||
when (which) {
|
||||
0 -> {
|
||||
val app = requireContext().applicationContext as Application
|
||||
val logs = app.getLastExceptionLog()
|
||||
reportBug(logs)
|
||||
}
|
||||
|
||||
1 ->
|
||||
requireContext().catchNoBrowserInstalled {
|
||||
startActivity(
|
||||
Intent(
|
||||
Intent.ACTION_VIEW,
|
||||
Uri.parse(
|
||||
"https://github.com/PhilKes/NotallyX/issues/new?labels=enhancement&template=feature_request.md"
|
||||
),
|
||||
)
|
||||
.wrapWithChooser(requireContext())
|
||||
)
|
||||
}
|
||||
2 -> {
|
||||
val intent =
|
||||
Intent(Intent.ACTION_SEND)
|
||||
.apply {
|
||||
selector =
|
||||
Intent(Intent.ACTION_SENDTO, Uri.parse("mailto:"))
|
||||
putExtra(
|
||||
Intent.EXTRA_EMAIL,
|
||||
arrayOf("notallyx@yahoo.com"),
|
||||
)
|
||||
putExtra(Intent.EXTRA_SUBJECT, "NotallyX [Feedback]")
|
||||
val app =
|
||||
requireContext().applicationContext as Application
|
||||
val log = app.getLogFile()
|
||||
if (log.exists()) {
|
||||
val uri = app.getUriForFile(log)
|
||||
putExtra(Intent.EXTRA_STREAM, uri)
|
||||
}
|
||||
}
|
||||
.wrapWithChooser(requireContext())
|
||||
try {
|
||||
startActivity(intent)
|
||||
} catch (exception: ActivityNotFoundException) {
|
||||
showToast(R.string.install_an_email)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.setCancelButton()
|
||||
.show()
|
||||
}
|
||||
Rate.setOnClickListener {
|
||||
openLink("https://play.google.com/store/apps/details?id=com.philkes.notallyx")
|
||||
}
|
||||
SourceCode.setOnClickListener { openLink("https://github.com/PhilKes/NotallyX") }
|
||||
Libraries.setOnClickListener {
|
||||
val libraries =
|
||||
arrayOf(
|
||||
"Glide",
|
||||
"Pretty Time",
|
||||
"SwipeDrawer",
|
||||
"Work Manager",
|
||||
"Subsampling Scale ImageView",
|
||||
"Material Components for Android",
|
||||
"SQLCipher",
|
||||
"Zip4J",
|
||||
"AndroidFastScroll",
|
||||
"ColorPickerView",
|
||||
)
|
||||
MaterialAlertDialogBuilder(requireContext())
|
||||
.setTitle(R.string.libraries)
|
||||
.setItems(libraries) { _, which ->
|
||||
when (which) {
|
||||
0 -> openLink("https://github.com/bumptech/glide")
|
||||
1 -> openLink("https://github.com/ocpsoft/prettytime")
|
||||
2 -> openLink("https://leaqi.github.io/SwipeDrawer_en")
|
||||
3 ->
|
||||
openLink(
|
||||
"https://developer.android.com/jetpack/androidx/releases/work"
|
||||
)
|
||||
4 ->
|
||||
openLink(
|
||||
"https://github.com/davemorrissey/subsampling-scale-image-view"
|
||||
)
|
||||
5 ->
|
||||
openLink(
|
||||
"https://github.com/material-components/material-components-android"
|
||||
)
|
||||
6 -> openLink("https://github.com/sqlcipher/sqlcipher")
|
||||
7 -> openLink("https://github.com/srikanth-lingala/zip4j")
|
||||
8 -> openLink("https://github.com/zhanghai/AndroidFastScroll")
|
||||
9 -> openLink("https://github.com/skydoves/ColorPickerView")
|
||||
}
|
||||
}
|
||||
.setCancelButton()
|
||||
.show()
|
||||
}
|
||||
Donate.setOnClickListener { openLink("https://ko-fi.com/philkes") }
|
||||
|
||||
try {
|
||||
val pInfo =
|
||||
requireContext().packageManager.getPackageInfo(requireContext().packageName, 0)
|
||||
val version = pInfo.versionName
|
||||
VersionText.text = "v$version"
|
||||
} catch (_: PackageManager.NameNotFoundException) {}
|
||||
}
|
||||
}
|
||||
|
||||
private fun displayChooseBackupFolderDialog() {
|
||||
showDialog(R.string.auto_backups_folder_hint, R.string.choose_folder) { _, _ ->
|
||||
val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE).wrapWithChooser(requireContext())
|
||||
chooseBackupFolderActivityResultLauncher.launch(intent)
|
||||
}
|
||||
}
|
||||
|
||||
private fun showEnableBiometricLock() {
|
||||
showBiometricOrPinPrompt(
|
||||
false,
|
||||
setupLockActivityResultLauncher,
|
||||
R.string.enable_lock_title,
|
||||
R.string.enable_lock_description,
|
||||
onSuccess = { cipher ->
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
model.enableBiometricLock(cipher)
|
||||
}
|
||||
val app = (activity?.application as NotallyXApplication)
|
||||
app.locked.value = false
|
||||
showToast(R.string.biometrics_setup_success)
|
||||
},
|
||||
) {
|
||||
showBiometricsNotSetupDialog()
|
||||
}
|
||||
}
|
||||
|
||||
private fun showDisableBiometricLock() {
|
||||
showBiometricOrPinPrompt(
|
||||
true,
|
||||
disableLockActivityResultLauncher,
|
||||
R.string.disable_lock_title,
|
||||
R.string.disable_lock_description,
|
||||
model.preferences.iv.value!!,
|
||||
onSuccess = { cipher ->
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
model.disableBiometricLock(cipher)
|
||||
}
|
||||
showToast(R.string.biometrics_disable_success)
|
||||
},
|
||||
) {}
|
||||
}
|
||||
|
||||
private fun showBiometricsNotSetupDialog() {
|
||||
showDialog(R.string.biometrics_not_setup, R.string.tap_to_set_up) { _, _ ->
|
||||
val intent =
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||
Intent(Settings.ACTION_BIOMETRIC_ENROLL)
|
||||
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||
Intent(Settings.ACTION_FINGERPRINT_ENROLL)
|
||||
} else {
|
||||
Intent(Settings.ACTION_SECURITY_SETTINGS)
|
||||
}
|
||||
setupLockActivityResultLauncher.launch(intent)
|
||||
}
|
||||
}
|
||||
|
||||
private fun openLink(link: String) {
|
||||
val uri = Uri.parse(link)
|
||||
val intent = Intent(Intent.ACTION_VIEW, uri).wrapWithChooser(requireContext())
|
||||
startActivity(intent)
|
||||
}
|
||||
|
||||
private fun askForUriPermissions(uri: Uri) {
|
||||
chooseBackupFolderActivityResultLauncher.launch(
|
||||
Intent(ACTION_OPEN_DOCUMENT_TREE).apply {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
putExtra(DocumentsContract.EXTRA_INITIAL_URI, uri)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val EXTRA_SHOW_IMPORT_BACKUPS_FOLDER =
|
||||
"notallyx.intent.extra.SHOW_IMPORT_BACKUPS_FOLDER"
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load diff
|
@ -1,318 +0,0 @@
|
|||
package com.philkes.notallyx.presentation.activity.note
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.recyclerview.widget.SortedList
|
||||
import com.philkes.notallyx.R
|
||||
import com.philkes.notallyx.data.model.ListItem
|
||||
import com.philkes.notallyx.data.model.NoteViewMode
|
||||
import com.philkes.notallyx.data.model.Type
|
||||
import com.philkes.notallyx.presentation.addIconButton
|
||||
import com.philkes.notallyx.presentation.hideKeyboardOnFocusedItem
|
||||
import com.philkes.notallyx.presentation.setOnNextAction
|
||||
import com.philkes.notallyx.presentation.showKeyboardOnFocusedItem
|
||||
import com.philkes.notallyx.presentation.view.note.action.MoreListActions
|
||||
import com.philkes.notallyx.presentation.view.note.action.MoreListBottomSheet
|
||||
import com.philkes.notallyx.presentation.view.note.listitem.HighlightText
|
||||
import com.philkes.notallyx.presentation.view.note.listitem.ListManager
|
||||
import com.philkes.notallyx.presentation.view.note.listitem.adapter.CheckedListItemAdapter
|
||||
import com.philkes.notallyx.presentation.view.note.listitem.adapter.ListItemAdapter
|
||||
import com.philkes.notallyx.presentation.view.note.listitem.adapter.ListItemHighlight
|
||||
import com.philkes.notallyx.presentation.view.note.listitem.adapter.ListItemVH
|
||||
import com.philkes.notallyx.presentation.view.note.listitem.init
|
||||
import com.philkes.notallyx.presentation.view.note.listitem.setItems
|
||||
import com.philkes.notallyx.presentation.view.note.listitem.sorting.ListItemParentSortCallback
|
||||
import com.philkes.notallyx.presentation.view.note.listitem.sorting.SortedItemsList
|
||||
import com.philkes.notallyx.presentation.view.note.listitem.splitByChecked
|
||||
import com.philkes.notallyx.presentation.view.note.listitem.toMutableList
|
||||
import com.philkes.notallyx.presentation.viewmodel.preference.NotallyXPreferences
|
||||
import com.philkes.notallyx.presentation.viewmodel.preference.autoSortByCheckedEnabled
|
||||
import com.philkes.notallyx.utils.findAllOccurrences
|
||||
import com.philkes.notallyx.utils.indices
|
||||
import com.philkes.notallyx.utils.mapIndexed
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
|
||||
class EditListActivity : EditActivity(Type.LIST), MoreListActions {
|
||||
|
||||
private var adapter: ListItemAdapter? = null
|
||||
private var adapterChecked: CheckedListItemAdapter? = null
|
||||
private val items: MutableList<ListItem>
|
||||
get() = adapter!!.items
|
||||
|
||||
private var itemsChecked: SortedItemsList? = null
|
||||
private lateinit var listManager: ListManager
|
||||
|
||||
override fun finish() {
|
||||
notallyModel.setItems(items.toMutableList() + (itemsChecked?.toMutableList() ?: listOf()))
|
||||
super.finish()
|
||||
}
|
||||
|
||||
override fun updateModel() {
|
||||
super.updateModel()
|
||||
notallyModel.setItems(items.toMutableList() + (itemsChecked?.toMutableList() ?: listOf()))
|
||||
}
|
||||
|
||||
override fun onSaveInstanceState(outState: Bundle) {
|
||||
updateModel()
|
||||
binding.MainListView.focusedChild?.let { focusedChild ->
|
||||
val viewHolder = binding.MainListView.findContainingViewHolder(focusedChild)
|
||||
if (viewHolder is ListItemVH) {
|
||||
val itemPos = binding.MainListView.getChildAdapterPosition(focusedChild)
|
||||
if (itemPos > -1) {
|
||||
val (selectionStart, selectionEnd) = viewHolder.getSelection()
|
||||
outState.apply {
|
||||
putInt(EXTRA_ITEM_POS, itemPos)
|
||||
putInt(EXTRA_SELECTION_START, selectionStart)
|
||||
putInt(EXTRA_SELECTION_END, selectionEnd)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
super.onSaveInstanceState(outState)
|
||||
}
|
||||
|
||||
override fun toggleCanEdit(mode: NoteViewMode) {
|
||||
super.toggleCanEdit(mode)
|
||||
when (mode) {
|
||||
NoteViewMode.EDIT -> binding.MainListView.showKeyboardOnFocusedItem()
|
||||
NoteViewMode.READ_ONLY -> binding.MainListView.hideKeyboardOnFocusedItem()
|
||||
}
|
||||
adapter?.viewMode = mode
|
||||
adapterChecked?.viewMode = mode
|
||||
binding.AddItem.visibility =
|
||||
when (mode) {
|
||||
NoteViewMode.EDIT -> View.VISIBLE
|
||||
else -> View.GONE
|
||||
}
|
||||
}
|
||||
|
||||
override fun deleteChecked() {
|
||||
listManager.deleteCheckedItems()
|
||||
}
|
||||
|
||||
override fun checkAll() {
|
||||
listManager.changeCheckedForAll(true)
|
||||
}
|
||||
|
||||
override fun uncheckAll() {
|
||||
listManager.changeCheckedForAll(false)
|
||||
}
|
||||
|
||||
override fun initBottomMenu() {
|
||||
super.initBottomMenu()
|
||||
binding.BottomAppBarRight.apply {
|
||||
removeAllViews()
|
||||
addToggleViewMode()
|
||||
addIconButton(R.string.more, R.drawable.more_vert, marginStart = 0) {
|
||||
MoreListBottomSheet(
|
||||
this@EditListActivity,
|
||||
createNoteTypeActions() + createFolderActions(),
|
||||
colorInt,
|
||||
)
|
||||
.show(supportFragmentManager, MoreListBottomSheet.TAG)
|
||||
}
|
||||
}
|
||||
setBottomAppBarColor(colorInt)
|
||||
}
|
||||
|
||||
private fun SortedList<ListItem>.highlightSearch(
|
||||
search: String,
|
||||
adapter: HighlightText?,
|
||||
resultPosCounter: AtomicInteger,
|
||||
alreadyNotifiedItemPos: MutableSet<Int>,
|
||||
): Int {
|
||||
return mapIndexed { idx, item ->
|
||||
val occurrences = item.body.findAllOccurrences(search)
|
||||
occurrences.onEach { (startIdx, endIdx) ->
|
||||
adapter?.highlightText(
|
||||
ListItemHighlight(
|
||||
idx,
|
||||
resultPosCounter.getAndIncrement(),
|
||||
startIdx,
|
||||
endIdx,
|
||||
false,
|
||||
)
|
||||
)
|
||||
}
|
||||
if (occurrences.isNotEmpty()) {
|
||||
alreadyNotifiedItemPos.add(idx)
|
||||
}
|
||||
occurrences.size
|
||||
}
|
||||
.sum()
|
||||
}
|
||||
|
||||
private fun List<ListItem>.highlightSearch(
|
||||
search: String,
|
||||
adapter: ListItemAdapter?,
|
||||
resultPosCounter: AtomicInteger,
|
||||
alreadyNotifiedItemPos: MutableSet<Int>,
|
||||
): Int {
|
||||
return mapIndexed { idx, item ->
|
||||
val occurrences = item.body.findAllOccurrences(search)
|
||||
occurrences.onEach { (startIdx, endIdx) ->
|
||||
adapter?.highlightText(
|
||||
ListItemHighlight(
|
||||
idx,
|
||||
resultPosCounter.getAndIncrement(),
|
||||
startIdx,
|
||||
endIdx,
|
||||
false,
|
||||
)
|
||||
)
|
||||
}
|
||||
if (occurrences.isNotEmpty()) {
|
||||
alreadyNotifiedItemPos.add(idx)
|
||||
}
|
||||
occurrences.size
|
||||
}
|
||||
.sum()
|
||||
}
|
||||
|
||||
override fun highlightSearchResults(search: String): Int {
|
||||
val resultPosCounter = AtomicInteger(0)
|
||||
val alreadyNotifiedItemPos = mutableSetOf<Int>()
|
||||
adapter?.clearHighlights()
|
||||
adapterChecked?.clearHighlights()
|
||||
val amount =
|
||||
items.highlightSearch(search, adapter, resultPosCounter, alreadyNotifiedItemPos) +
|
||||
(itemsChecked?.highlightSearch(
|
||||
search,
|
||||
adapterChecked,
|
||||
resultPosCounter,
|
||||
alreadyNotifiedItemPos,
|
||||
) ?: 0)
|
||||
items.indices
|
||||
.filter { !alreadyNotifiedItemPos.contains(it) }
|
||||
.forEach { adapter?.notifyItemChanged(it) }
|
||||
itemsChecked
|
||||
?.indices
|
||||
?.filter { !alreadyNotifiedItemPos.contains(it) }
|
||||
?.forEach { adapter?.notifyItemChanged(it) }
|
||||
return amount
|
||||
}
|
||||
|
||||
override fun selectSearchResult(resultPos: Int) {
|
||||
var selectedItemPos = adapter!!.selectHighlight(resultPos)
|
||||
if (selectedItemPos == -1 && adapterChecked != null) {
|
||||
selectedItemPos = adapterChecked!!.selectHighlight(resultPos)
|
||||
if (selectedItemPos != -1) {
|
||||
binding.CheckedListView.scrollToItemPosition(selectedItemPos)
|
||||
}
|
||||
} else if (selectedItemPos != -1) {
|
||||
binding.MainListView.scrollToItemPosition(selectedItemPos)
|
||||
}
|
||||
}
|
||||
|
||||
private fun RecyclerView.scrollToItemPosition(position: Int) {
|
||||
post {
|
||||
findViewHolderForAdapterPosition(position)?.itemView?.let {
|
||||
binding.ScrollView.scrollTo(0, top + it.top)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun configureUI() {
|
||||
binding.EnterTitle.setOnNextAction { listManager.moveFocusToNext(-1) }
|
||||
|
||||
if (notallyModel.isNewNote || notallyModel.items.isEmpty()) {
|
||||
listManager.add(pushChange = false)
|
||||
}
|
||||
}
|
||||
|
||||
override fun setupListeners() {
|
||||
super.setupListeners()
|
||||
binding.AddItem.setOnClickListener { listManager.add() }
|
||||
}
|
||||
|
||||
override fun setStateFromModel(savedInstanceState: Bundle?) {
|
||||
super.setStateFromModel(savedInstanceState)
|
||||
val elevation = resources.displayMetrics.density * 2
|
||||
listManager =
|
||||
ListManager(
|
||||
binding.MainListView,
|
||||
changeHistory,
|
||||
preferences,
|
||||
inputMethodManager,
|
||||
{
|
||||
if (isInSearchMode()) {
|
||||
endSearch()
|
||||
}
|
||||
},
|
||||
) { _ ->
|
||||
if (isInSearchMode() && search.results.value > 0) {
|
||||
updateSearchResults(search.query)
|
||||
}
|
||||
}
|
||||
adapter =
|
||||
ListItemAdapter(
|
||||
colorInt,
|
||||
notallyModel.textSize,
|
||||
elevation,
|
||||
NotallyXPreferences.getInstance(application),
|
||||
listManager,
|
||||
false,
|
||||
binding.ScrollView,
|
||||
)
|
||||
val initializedItems = notallyModel.items.init(true)
|
||||
if (preferences.autoSortByCheckedEnabled) {
|
||||
val (checkedItems, uncheckedItems) = initializedItems.splitByChecked()
|
||||
adapter?.submitList(uncheckedItems.toMutableList())
|
||||
adapterChecked =
|
||||
CheckedListItemAdapter(
|
||||
colorInt,
|
||||
notallyModel.textSize,
|
||||
elevation,
|
||||
NotallyXPreferences.getInstance(application),
|
||||
listManager,
|
||||
true,
|
||||
binding.ScrollView,
|
||||
)
|
||||
itemsChecked =
|
||||
SortedItemsList(ListItemParentSortCallback(adapterChecked!!)).apply {
|
||||
setItems(checkedItems.toMutableList())
|
||||
}
|
||||
adapterChecked?.setList(itemsChecked!!)
|
||||
binding.CheckedListView.adapter = adapterChecked
|
||||
} else {
|
||||
adapter?.submitList(initializedItems.toMutableList())
|
||||
}
|
||||
listManager.init(adapter!!, itemsChecked, adapterChecked)
|
||||
binding.MainListView.adapter = adapter
|
||||
|
||||
savedInstanceState?.let {
|
||||
val itemPos = it.getInt(EXTRA_ITEM_POS, -1)
|
||||
if (itemPos > -1) {
|
||||
binding.MainListView.apply {
|
||||
post {
|
||||
scrollToPosition(itemPos)
|
||||
val viewHolder = findViewHolderForLayoutPosition(itemPos)
|
||||
if (viewHolder is ListItemVH) {
|
||||
val selectionStart = it.getInt(EXTRA_SELECTION_START, -1)
|
||||
val selectionEnd = it.getInt(EXTRA_SELECTION_END, -1)
|
||||
viewHolder.focusEditText(
|
||||
selectionStart,
|
||||
selectionEnd,
|
||||
inputMethodManager,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun setColor() {
|
||||
super.setColor()
|
||||
adapter?.setBackgroundColor(colorInt)
|
||||
adapterChecked?.setBackgroundColor(colorInt)
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val EXTRA_ITEM_POS = "notallyx.intent.extra.ITEM_POS"
|
||||
private const val EXTRA_SELECTION_START = "notallyx.intent.extra.EXTRA_SELECTION_START"
|
||||
private const val EXTRA_SELECTION_END = "notallyx.intent.extra.EXTRA_SELECTION_END"
|
||||
}
|
||||
}
|
|
@ -1,523 +0,0 @@
|
|||
package com.philkes.notallyx.presentation.activity.note
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.graphics.Typeface
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.text.style.StrikethroughSpan
|
||||
import android.text.style.StyleSpan
|
||||
import android.text.style.TypefaceSpan
|
||||
import android.text.style.URLSpan
|
||||
import android.text.style.UnderlineSpan
|
||||
import android.view.ActionMode
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import android.view.View.GONE
|
||||
import android.view.View.VISIBLE
|
||||
import android.widget.LinearLayout
|
||||
import androidx.activity.result.ActivityResultLauncher
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.constraintlayout.widget.ConstraintLayout
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.core.view.updateLayoutParams
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import com.philkes.notallyx.R
|
||||
import com.philkes.notallyx.data.model.NoteViewMode
|
||||
import com.philkes.notallyx.data.model.Type
|
||||
import com.philkes.notallyx.data.model.createNoteUrl
|
||||
import com.philkes.notallyx.data.model.getNoteIdFromUrl
|
||||
import com.philkes.notallyx.data.model.getNoteTypeFromUrl
|
||||
import com.philkes.notallyx.data.model.isNoteUrl
|
||||
import com.philkes.notallyx.databinding.BottomTextFormattingMenuBinding
|
||||
import com.philkes.notallyx.databinding.RecyclerToggleBinding
|
||||
import com.philkes.notallyx.presentation.activity.note.PickNoteActivity.Companion.EXTRA_EXCLUDE_NOTE_ID
|
||||
import com.philkes.notallyx.presentation.activity.note.PickNoteActivity.Companion.EXTRA_PICKED_NOTE_ID
|
||||
import com.philkes.notallyx.presentation.activity.note.PickNoteActivity.Companion.EXTRA_PICKED_NOTE_TITLE
|
||||
import com.philkes.notallyx.presentation.activity.note.PickNoteActivity.Companion.EXTRA_PICKED_NOTE_TYPE
|
||||
import com.philkes.notallyx.presentation.add
|
||||
import com.philkes.notallyx.presentation.addIconButton
|
||||
import com.philkes.notallyx.presentation.dp
|
||||
import com.philkes.notallyx.presentation.hideKeyboard
|
||||
import com.philkes.notallyx.presentation.setControlsContrastColorForAllViews
|
||||
import com.philkes.notallyx.presentation.setOnNextAction
|
||||
import com.philkes.notallyx.presentation.showKeyboard
|
||||
import com.philkes.notallyx.presentation.showToast
|
||||
import com.philkes.notallyx.presentation.view.note.TextFormattingAdapter
|
||||
import com.philkes.notallyx.presentation.view.note.action.AddNoteActions
|
||||
import com.philkes.notallyx.presentation.view.note.action.AddNoteBottomSheet
|
||||
import com.philkes.notallyx.utils.LinkMovementMethod
|
||||
import com.philkes.notallyx.utils.copyToClipBoard
|
||||
import com.philkes.notallyx.utils.findAllOccurrences
|
||||
import com.philkes.notallyx.utils.wrapWithChooser
|
||||
|
||||
class EditNoteActivity : EditActivity(Type.NOTE), AddNoteActions {
|
||||
|
||||
private lateinit var selectedSpan: URLSpan
|
||||
private lateinit var pickNoteNewActivityResultLauncher: ActivityResultLauncher<Intent>
|
||||
private lateinit var pickNoteUpdateActivityResultLauncher: ActivityResultLauncher<Intent>
|
||||
private lateinit var textFormatMenu: View
|
||||
|
||||
private var textFormattingAdapter: TextFormattingAdapter? = null
|
||||
|
||||
private var searchResultIndices: List<Pair<Int, Int>>? = null
|
||||
|
||||
override fun configureUI() {
|
||||
binding.EnterTitle.setOnNextAction { binding.EnterBody.requestFocus() }
|
||||
|
||||
setupEditor()
|
||||
|
||||
if (notallyModel.isNewNote) {
|
||||
binding.EnterBody.requestFocus()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
setupActivityResultLaunchers()
|
||||
}
|
||||
|
||||
override fun toggleCanEdit(mode: NoteViewMode) {
|
||||
super.toggleCanEdit(mode)
|
||||
setupEditor()
|
||||
textFormatMenu.isVisible = mode == NoteViewMode.EDIT
|
||||
when {
|
||||
mode == NoteViewMode.EDIT -> showKeyboard(binding.EnterBody)
|
||||
binding.EnterBody.isFocused -> hideKeyboard(binding.EnterBody)
|
||||
}
|
||||
binding.EnterBody.setCanEdit(mode == NoteViewMode.EDIT)
|
||||
}
|
||||
|
||||
override fun onSaveInstanceState(outState: Bundle) {
|
||||
super.onSaveInstanceState(outState)
|
||||
outState.apply {
|
||||
putInt(EXTRA_SELECTION_START, binding.EnterBody.selectionStart)
|
||||
putInt(EXTRA_SELECTION_END, binding.EnterBody.selectionEnd)
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupActivityResultLaunchers() {
|
||||
pickNoteNewActivityResultLauncher =
|
||||
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
|
||||
if (result.resultCode == RESULT_OK) {
|
||||
try {
|
||||
val (title, url, emptyTitle) = result.data.getPickedNoteData()
|
||||
if (emptyTitle) {
|
||||
binding.EnterBody.showAddLinkDialog(
|
||||
this,
|
||||
presetDisplayText = title,
|
||||
presetUrl = url,
|
||||
isNewUnnamedLink = true,
|
||||
)
|
||||
} else {
|
||||
binding.EnterBody.addSpans(title, listOf(UnderlineSpan(), URLSpan(url)))
|
||||
}
|
||||
} catch (_: IllegalArgumentException) {}
|
||||
}
|
||||
}
|
||||
pickNoteUpdateActivityResultLauncher =
|
||||
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
|
||||
if (result.resultCode == RESULT_OK) {
|
||||
try {
|
||||
val (title, url, emptyTitle) = result.data.getPickedNoteData()
|
||||
val newSpan = URLSpan(url)
|
||||
binding.EnterBody.updateSpan(selectedSpan, newSpan, title)
|
||||
if (emptyTitle) {
|
||||
binding.EnterBody.showEditDialog(newSpan, isNewUnnamedLink = true)
|
||||
}
|
||||
} catch (_: IllegalArgumentException) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun highlightSearchResults(search: String): Int {
|
||||
binding.EnterBody.clearHighlights()
|
||||
if (search.isEmpty()) {
|
||||
return 0
|
||||
}
|
||||
searchResultIndices =
|
||||
notallyModel.body.toString().findAllOccurrences(search).onEach { (startIdx, endIdx) ->
|
||||
binding.EnterBody.highlight(startIdx, endIdx, false)
|
||||
}
|
||||
return searchResultIndices!!.size
|
||||
}
|
||||
|
||||
override fun selectSearchResult(resultPos: Int) {
|
||||
if (resultPos < 0) {
|
||||
binding.EnterBody.unselectHighlight()
|
||||
return
|
||||
}
|
||||
searchResultIndices?.get(resultPos)?.let { (startIdx, endIdx) ->
|
||||
val selectedLineTop = binding.EnterBody.highlight(startIdx, endIdx, true)
|
||||
selectedLineTop?.let { binding.ScrollView.scrollTo(0, it) }
|
||||
}
|
||||
}
|
||||
|
||||
override fun setupListeners() {
|
||||
super.setupListeners()
|
||||
binding.EnterBody.initHistory(changeHistory) { text ->
|
||||
val textChanged = !notallyModel.body.toString().contentEquals(text)
|
||||
notallyModel.body = text
|
||||
if (textChanged) {
|
||||
updateSearchResults(search.query)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun setStateFromModel(savedInstanceState: Bundle?) {
|
||||
super.setStateFromModel(savedInstanceState)
|
||||
updateEditText()
|
||||
savedInstanceState?.let {
|
||||
val selectionStart = it.getInt(EXTRA_SELECTION_START, -1)
|
||||
val selectionEnd = it.getInt(EXTRA_SELECTION_END, -1)
|
||||
if (selectionStart > -1) {
|
||||
binding.EnterBody.focusAndSelect(selectionStart, selectionEnd)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateEditText() {
|
||||
binding.EnterBody.text = notallyModel.body
|
||||
}
|
||||
|
||||
private fun setupEditor() {
|
||||
setupMovementMethod()
|
||||
binding.EnterBody.customSelectionActionModeCallback =
|
||||
if (canEdit) {
|
||||
object : ActionMode.Callback {
|
||||
override fun onPrepareActionMode(mode: ActionMode?, menu: Menu?) = false
|
||||
|
||||
override fun onActionItemClicked(mode: ActionMode?, item: MenuItem?) = false
|
||||
|
||||
override fun onCreateActionMode(mode: ActionMode?, menu: Menu?): Boolean {
|
||||
binding.EnterBody.isActionModeOn = true
|
||||
// Try block is there because this will crash on MiUI as Xiaomi has a broken
|
||||
// ActionMode implementation
|
||||
try {
|
||||
menu?.apply {
|
||||
add(
|
||||
R.string.link,
|
||||
0,
|
||||
showAsAction = MenuItem.SHOW_AS_ACTION_NEVER,
|
||||
) {
|
||||
binding.EnterBody.showAddLinkDialog(
|
||||
this@EditNoteActivity,
|
||||
mode = mode,
|
||||
)
|
||||
}
|
||||
add(
|
||||
R.string.bold,
|
||||
0,
|
||||
showAsAction = MenuItem.SHOW_AS_ACTION_NEVER,
|
||||
) {
|
||||
binding.EnterBody.applySpan(StyleSpan(Typeface.BOLD))
|
||||
mode?.finish()
|
||||
}
|
||||
add(
|
||||
R.string.italic,
|
||||
0,
|
||||
showAsAction = MenuItem.SHOW_AS_ACTION_NEVER,
|
||||
) {
|
||||
binding.EnterBody.applySpan(StyleSpan(Typeface.ITALIC))
|
||||
mode?.finish()
|
||||
}
|
||||
add(
|
||||
R.string.monospace,
|
||||
0,
|
||||
showAsAction = MenuItem.SHOW_AS_ACTION_NEVER,
|
||||
) {
|
||||
binding.EnterBody.applySpan(TypefaceSpan("monospace"))
|
||||
mode?.finish()
|
||||
}
|
||||
add(
|
||||
R.string.strikethrough,
|
||||
0,
|
||||
showAsAction = MenuItem.SHOW_AS_ACTION_NEVER,
|
||||
) {
|
||||
binding.EnterBody.applySpan(StrikethroughSpan())
|
||||
mode?.finish()
|
||||
}
|
||||
add(
|
||||
R.string.clear_formatting,
|
||||
0,
|
||||
showAsAction = MenuItem.SHOW_AS_ACTION_NEVER,
|
||||
) {
|
||||
binding.EnterBody.clearFormatting()
|
||||
mode?.finish()
|
||||
}
|
||||
}
|
||||
} catch (exception: Exception) {
|
||||
exception.printStackTrace()
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onDestroyActionMode(mode: ActionMode?) {
|
||||
binding.EnterBody.isActionModeOn = false
|
||||
}
|
||||
}
|
||||
} else null
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
binding.EnterBody.customInsertionActionModeCallback =
|
||||
if (canEdit) {
|
||||
object : ActionMode.Callback {
|
||||
override fun onPrepareActionMode(mode: ActionMode?, menu: Menu?) = false
|
||||
|
||||
override fun onActionItemClicked(mode: ActionMode?, item: MenuItem?) = false
|
||||
|
||||
override fun onCreateActionMode(mode: ActionMode?, menu: Menu?): Boolean {
|
||||
binding.EnterBody.isActionModeOn = true
|
||||
// Try block is there because this will crash on MiUI as Xiaomi has a
|
||||
// broken
|
||||
// ActionMode implementation
|
||||
try {
|
||||
menu?.apply {
|
||||
add(
|
||||
R.string.link_note,
|
||||
0,
|
||||
order = Menu.CATEGORY_CONTAINER + 1,
|
||||
) {
|
||||
linkNote(pickNoteNewActivityResultLauncher)
|
||||
mode?.finish()
|
||||
}
|
||||
}
|
||||
} catch (exception: Exception) {
|
||||
exception.printStackTrace()
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onDestroyActionMode(mode: ActionMode?) {
|
||||
binding.EnterBody.isActionModeOn = false
|
||||
}
|
||||
}
|
||||
} else null
|
||||
}
|
||||
if (canEdit) {
|
||||
binding.EnterBody.setOnSelectionChange { selStart, selEnd ->
|
||||
if (selEnd - selStart > 0) {
|
||||
if (!textFormatMenu.isEnabled) {
|
||||
initBottomTextFormattingMenu()
|
||||
}
|
||||
textFormatMenu.isEnabled = true
|
||||
textFormattingAdapter?.updateTextFormattingToggles(selStart, selEnd)
|
||||
} else {
|
||||
if (textFormatMenu.isEnabled) {
|
||||
initBottomMenu()
|
||||
}
|
||||
textFormatMenu.isEnabled = false
|
||||
}
|
||||
}
|
||||
} else {
|
||||
binding.EnterBody.setOnSelectionChange { _, _ -> }
|
||||
}
|
||||
binding.ContentLayout.setOnClickListener {
|
||||
binding.EnterBody.apply {
|
||||
requestFocus()
|
||||
if (canEdit) {
|
||||
setSelection(length())
|
||||
showKeyboard(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun initBottomMenu() {
|
||||
super.initBottomMenu()
|
||||
binding.BottomAppBarCenter.visibility = VISIBLE
|
||||
binding.BottomAppBarLeft.apply {
|
||||
removeAllViews()
|
||||
addIconButton(R.string.add_item, R.drawable.add, marginStart = 0) {
|
||||
AddNoteBottomSheet(this@EditNoteActivity, colorInt)
|
||||
.show(supportFragmentManager, AddNoteBottomSheet.TAG)
|
||||
}
|
||||
updateLayoutParams<ConstraintLayout.LayoutParams> { endToStart = -1 }
|
||||
textFormatMenu =
|
||||
addIconButton(R.string.edit, R.drawable.text_format) {
|
||||
initBottomTextFormattingMenu()
|
||||
}
|
||||
.apply { isEnabled = binding.EnterBody.isActionModeOn }
|
||||
}
|
||||
setBottomAppBarColor(colorInt)
|
||||
}
|
||||
|
||||
private fun initBottomTextFormattingMenu() {
|
||||
binding.BottomAppBarCenter.visibility = GONE
|
||||
val extractColor = colorInt
|
||||
binding.BottomAppBarRight.apply {
|
||||
removeAllViews()
|
||||
addView(
|
||||
RecyclerToggleBinding.inflate(layoutInflater, this, false).root.apply {
|
||||
setIconResource(R.drawable.close)
|
||||
contentDescription = context.getString(R.string.cancel)
|
||||
setOnClickListener { initBottomMenu() }
|
||||
|
||||
updateLayoutParams<LinearLayout.LayoutParams> {
|
||||
marginEnd = 0
|
||||
marginStart = 10.dp
|
||||
}
|
||||
setControlsContrastColorForAllViews(extractColor)
|
||||
setBackgroundColor(0)
|
||||
}
|
||||
)
|
||||
}
|
||||
binding.BottomAppBarLeft.apply {
|
||||
removeAllViews()
|
||||
updateLayoutParams<ConstraintLayout.LayoutParams> {
|
||||
endToStart = R.id.BottomAppBarRight
|
||||
}
|
||||
requestLayout()
|
||||
val layout = BottomTextFormattingMenuBinding.inflate(layoutInflater, this, false)
|
||||
layout.MainListView.apply {
|
||||
textFormattingAdapter =
|
||||
TextFormattingAdapter(this@EditNoteActivity, binding.EnterBody, colorInt)
|
||||
adapter = textFormattingAdapter
|
||||
layoutManager = LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false)
|
||||
}
|
||||
addView(layout.root)
|
||||
}
|
||||
}
|
||||
|
||||
override fun linkNote() {
|
||||
linkNote(pickNoteNewActivityResultLauncher)
|
||||
}
|
||||
|
||||
fun linkNote(activityResultLauncher: ActivityResultLauncher<Intent>) {
|
||||
val intent =
|
||||
Intent(this, PickNoteActivity::class.java).apply {
|
||||
putExtra(EXTRA_EXCLUDE_NOTE_ID, notallyModel.id)
|
||||
}
|
||||
activityResultLauncher.launch(intent)
|
||||
}
|
||||
|
||||
private fun setupMovementMethod() {
|
||||
val movementMethod = LinkMovementMethod { span ->
|
||||
val items =
|
||||
if (span.url.isNoteUrl()) {
|
||||
if (canEdit) {
|
||||
arrayOf(
|
||||
getString(R.string.open_note),
|
||||
getString(R.string.remove_link),
|
||||
getString(R.string.change_note),
|
||||
getString(R.string.edit),
|
||||
)
|
||||
} else arrayOf(getString(R.string.open_note))
|
||||
} else {
|
||||
if (canEdit) {
|
||||
arrayOf(
|
||||
getString(R.string.open_link),
|
||||
getString(R.string.copy),
|
||||
getString(R.string.remove_link),
|
||||
getString(R.string.edit),
|
||||
)
|
||||
} else arrayOf(getString(R.string.open_link), getString(R.string.copy))
|
||||
}
|
||||
MaterialAlertDialogBuilder(this)
|
||||
.setTitle(
|
||||
if (span.url.isNoteUrl())
|
||||
"${getString(R.string.note)}: ${
|
||||
binding.EnterBody.getSpanText(span)
|
||||
}"
|
||||
else span.url
|
||||
)
|
||||
.setItems(items) { _, which ->
|
||||
when (which) {
|
||||
0 -> openLink(span)
|
||||
1 ->
|
||||
if (span.url.isNoteUrl()) {
|
||||
removeLink(span)
|
||||
} else copyLink(span)
|
||||
2 ->
|
||||
if (span.url.isNoteUrl()) {
|
||||
changeNoteLink(span)
|
||||
} else removeLink(span)
|
||||
3 -> editLink(span)
|
||||
}
|
||||
}
|
||||
.show()
|
||||
}
|
||||
binding.EnterBody.movementMethod = movementMethod
|
||||
}
|
||||
|
||||
private fun openLink(span: URLSpan) {
|
||||
span.url?.let {
|
||||
if (it.isNoteUrl()) {
|
||||
span.navigateToNote()
|
||||
} else {
|
||||
openLink(span.url)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun editLink(span: URLSpan) {
|
||||
binding.EnterBody.showEditDialog(span)
|
||||
}
|
||||
|
||||
private fun changeNoteLink(span: URLSpan) {
|
||||
selectedSpan = span
|
||||
linkNote(pickNoteUpdateActivityResultLauncher)
|
||||
}
|
||||
|
||||
private fun copyLink(span: URLSpan) {
|
||||
copyToClipBoard(span.url)
|
||||
showToast(R.string.copied_link)
|
||||
}
|
||||
|
||||
private fun removeLink(span: URLSpan) {
|
||||
binding.EnterBody.removeSpanWithHistory(
|
||||
span,
|
||||
span.url.isNoteUrl() || span.url == binding.EnterBody.getSpanText(span),
|
||||
)
|
||||
}
|
||||
|
||||
private fun openLink(url: String) {
|
||||
val uri = Uri.parse(url)
|
||||
val intent = Intent(Intent.ACTION_VIEW, uri).wrapWithChooser(this)
|
||||
try {
|
||||
startActivity(intent)
|
||||
} catch (exception: Exception) {
|
||||
showToast(R.string.cant_open_link)
|
||||
}
|
||||
}
|
||||
|
||||
private fun URLSpan.navigateToNote() {
|
||||
val noteId = url.getNoteIdFromUrl()
|
||||
val noteType = url.getNoteTypeFromUrl()
|
||||
when (noteType) {
|
||||
Type.NOTE -> goToActivity(EditNoteActivity::class.java, noteId)
|
||||
Type.LIST -> goToActivity(EditListActivity::class.java, noteId)
|
||||
}
|
||||
}
|
||||
|
||||
private fun goToActivity(activity: Class<out Activity>, noteId: Long) {
|
||||
val intent = Intent(this, activity)
|
||||
intent.putExtra(EXTRA_SELECTED_BASE_NOTE, noteId)
|
||||
startActivity(intent)
|
||||
}
|
||||
|
||||
private fun Intent?.getPickedNoteData(): Triple<String, String, Boolean> {
|
||||
val noteId = this?.getLongExtra(EXTRA_PICKED_NOTE_ID, -1L)!!
|
||||
if (noteId == -1L) {
|
||||
throw IllegalArgumentException("Invalid note picked!")
|
||||
}
|
||||
var emptyTitle = false
|
||||
val noteTitle =
|
||||
this.getStringExtra(EXTRA_PICKED_NOTE_TITLE)!!.ifEmpty {
|
||||
emptyTitle = true
|
||||
this@EditNoteActivity.getString(R.string.note)
|
||||
}
|
||||
val noteType = Type.valueOf(this.getStringExtra(EXTRA_PICKED_NOTE_TYPE)!!)
|
||||
val noteUrl = noteId.createNoteUrl(noteType)
|
||||
return Triple(noteTitle, noteUrl, emptyTitle)
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val EXTRA_SELECTION_START = "notallyx.intent.extra.EXTRA_SELECTION_START"
|
||||
private const val EXTRA_SELECTION_END = "notallyx.intent.extra.EXTRA_SELECTION_END"
|
||||
}
|
||||
}
|
|
@ -1,112 +0,0 @@
|
|||
package com.philkes.notallyx.presentation.activity.note
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.recyclerview.widget.StaggeredGridLayoutManager
|
||||
import com.philkes.notallyx.R
|
||||
import com.philkes.notallyx.data.NotallyDatabase
|
||||
import com.philkes.notallyx.data.model.BaseNote
|
||||
import com.philkes.notallyx.data.model.Header
|
||||
import com.philkes.notallyx.databinding.ActivityPickNoteBinding
|
||||
import com.philkes.notallyx.presentation.activity.LockedActivity
|
||||
import com.philkes.notallyx.presentation.view.main.BaseNoteAdapter
|
||||
import com.philkes.notallyx.presentation.view.main.BaseNoteVHPreferences
|
||||
import com.philkes.notallyx.presentation.view.misc.ItemListener
|
||||
import com.philkes.notallyx.presentation.viewmodel.BaseNoteModel
|
||||
import com.philkes.notallyx.presentation.viewmodel.preference.NotallyXPreferences
|
||||
import com.philkes.notallyx.presentation.viewmodel.preference.NotesView
|
||||
import com.philkes.notallyx.utils.getExternalImagesDirectory
|
||||
import java.util.Collections
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
open class PickNoteActivity : LockedActivity<ActivityPickNoteBinding>(), ItemListener {
|
||||
|
||||
protected lateinit var adapter: BaseNoteAdapter
|
||||
|
||||
private val excludedNoteId by lazy { intent.getLongExtra(EXTRA_EXCLUDE_NOTE_ID, -1L) }
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
binding = ActivityPickNoteBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
|
||||
val result = Intent()
|
||||
setResult(RESULT_CANCELED, result)
|
||||
|
||||
val preferences = NotallyXPreferences.getInstance(application)
|
||||
|
||||
adapter =
|
||||
with(preferences) {
|
||||
BaseNoteAdapter(
|
||||
Collections.emptySet(),
|
||||
dateFormat.value,
|
||||
notesSorting.value,
|
||||
BaseNoteVHPreferences(
|
||||
textSize.value,
|
||||
maxItems.value,
|
||||
maxLines.value,
|
||||
maxTitle.value,
|
||||
labelTagsHiddenInOverview.value,
|
||||
),
|
||||
application.getExternalImagesDirectory(),
|
||||
this@PickNoteActivity,
|
||||
)
|
||||
}
|
||||
|
||||
binding.MainListView.apply {
|
||||
adapter = this@PickNoteActivity.adapter
|
||||
setHasFixedSize(true)
|
||||
layoutManager =
|
||||
if (preferences.notesView.value == NotesView.GRID) {
|
||||
StaggeredGridLayoutManager(2, RecyclerView.VERTICAL)
|
||||
} else LinearLayoutManager(this@PickNoteActivity)
|
||||
}
|
||||
|
||||
val database = NotallyDatabase.getDatabase(application)
|
||||
|
||||
val pinned = Header(getString(R.string.pinned))
|
||||
val others = Header(getString(R.string.others))
|
||||
val archived = Header(getString(R.string.archived))
|
||||
|
||||
database.observe(this) {
|
||||
lifecycleScope.launch {
|
||||
val notes =
|
||||
withContext(Dispatchers.IO) {
|
||||
val raw =
|
||||
it.getBaseNoteDao().getAllNotes().filter { it.id != excludedNoteId }
|
||||
BaseNoteModel.transform(raw, pinned, others, archived)
|
||||
}
|
||||
adapter.submitList(notes)
|
||||
binding.EmptyView.visibility =
|
||||
if (notes.isEmpty()) android.view.View.VISIBLE else android.view.View.GONE
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onClick(position: Int) {
|
||||
if (position != -1) {
|
||||
val note = (adapter.getItem(position) as BaseNote)
|
||||
val success = Intent()
|
||||
success.putExtra(EXTRA_PICKED_NOTE_ID, note.id)
|
||||
success.putExtra(EXTRA_PICKED_NOTE_TITLE, note.title)
|
||||
success.putExtra(EXTRA_PICKED_NOTE_TYPE, note.type.name)
|
||||
setResult(RESULT_OK, success)
|
||||
finish()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onLongClick(position: Int) {}
|
||||
|
||||
companion object {
|
||||
const val EXTRA_EXCLUDE_NOTE_ID = "notallyx.intent.extra.EXCLUDE_NOTE_ID"
|
||||
|
||||
const val EXTRA_PICKED_NOTE_ID = "notallyx.intent.extra.PICKED_NOTE_ID"
|
||||
const val EXTRA_PICKED_NOTE_TITLE = "notallyx.intent.extra.PICKED_NOTE_TITLE"
|
||||
const val EXTRA_PICKED_NOTE_TYPE = "notallyx.intent.extra.PICKED_NOTE_TYPE"
|
||||
}
|
||||
}
|
|
@ -1,208 +0,0 @@
|
|||
package com.philkes.notallyx.presentation.activity.note
|
||||
|
||||
import android.content.ComponentName
|
||||
import android.content.Intent
|
||||
import android.content.ServiceConnection
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.os.IBinder
|
||||
import android.widget.Toast
|
||||
import androidx.activity.result.ActivityResultLauncher
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.core.content.IntentCompat
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import com.philkes.notallyx.R
|
||||
import com.philkes.notallyx.data.model.Audio
|
||||
import com.philkes.notallyx.databinding.ActivityPlayAudioBinding
|
||||
import com.philkes.notallyx.presentation.activity.LockedActivity
|
||||
import com.philkes.notallyx.presentation.add
|
||||
import com.philkes.notallyx.presentation.setCancelButton
|
||||
import com.philkes.notallyx.utils.audio.AudioPlayService
|
||||
import com.philkes.notallyx.utils.audio.LocalBinder
|
||||
import com.philkes.notallyx.utils.getExternalAudioDirectory
|
||||
import com.philkes.notallyx.utils.getUriForFile
|
||||
import com.philkes.notallyx.utils.wrapWithChooser
|
||||
import java.io.File
|
||||
import java.io.FileInputStream
|
||||
import java.io.FileOutputStream
|
||||
import java.text.DateFormat
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
class PlayAudioActivity : LockedActivity<ActivityPlayAudioBinding>() {
|
||||
|
||||
private var service: AudioPlayService? = null
|
||||
private lateinit var connection: ServiceConnection
|
||||
private lateinit var exportFileActivityResultLauncher: ActivityResultLauncher<Intent>
|
||||
|
||||
private lateinit var audio: Audio
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
binding = ActivityPlayAudioBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
|
||||
audio =
|
||||
requireNotNull(
|
||||
intent?.let { IntentCompat.getParcelableExtra(it, EXTRA_AUDIO, Audio::class.java) }
|
||||
)
|
||||
binding.AudioControlView.setDuration(audio.duration)
|
||||
|
||||
val intent = Intent(this, AudioPlayService::class.java)
|
||||
startService(intent)
|
||||
|
||||
connection =
|
||||
object : ServiceConnection {
|
||||
|
||||
override fun onServiceConnected(name: ComponentName?, binder: IBinder?) {
|
||||
val service = (binder as LocalBinder<AudioPlayService>).getService()
|
||||
service.initialise(audio)
|
||||
service.onStateChange = { updateUI(service) }
|
||||
this@PlayAudioActivity.service = service
|
||||
updateUI(service)
|
||||
}
|
||||
|
||||
override fun onServiceDisconnected(name: ComponentName?) {}
|
||||
}
|
||||
|
||||
bindService(intent, connection, BIND_AUTO_CREATE)
|
||||
|
||||
binding.Play.setOnClickListener { service?.play() }
|
||||
|
||||
audio.duration?.let {
|
||||
binding.AudioControlView.onSeekComplete = { milliseconds ->
|
||||
service?.seek(milliseconds)
|
||||
}
|
||||
}
|
||||
|
||||
setupToolbar(binding)
|
||||
|
||||
exportFileActivityResultLauncher =
|
||||
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
|
||||
if (result.resultCode == RESULT_OK) {
|
||||
result.data?.data?.let { uri -> writeAudioToUri(uri) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
if (service != null) {
|
||||
unbindService(connection)
|
||||
requireNotNull(service).onStateChange = null
|
||||
service = null
|
||||
}
|
||||
if (isFinishing) {
|
||||
val intent = Intent(this, AudioPlayService::class.java)
|
||||
stopService(intent)
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupToolbar(binding: ActivityPlayAudioBinding) {
|
||||
binding.Toolbar.setNavigationOnClickListener { onBackPressed() }
|
||||
|
||||
binding.Toolbar.menu.apply {
|
||||
add(R.string.share, R.drawable.share) { share() }
|
||||
add(R.string.save_to_device, R.drawable.save) { saveToDevice() }
|
||||
add(R.string.delete, R.drawable.delete) { delete() }
|
||||
}
|
||||
}
|
||||
|
||||
private fun share() {
|
||||
val audioRoot = application.getExternalAudioDirectory()
|
||||
val file = if (audioRoot != null) File(audioRoot, audio.name) else null
|
||||
if (file != null && file.exists()) {
|
||||
val uri = getUriForFile(file)
|
||||
val intent =
|
||||
Intent(Intent.ACTION_SEND)
|
||||
.apply {
|
||||
type = "audio/mp4"
|
||||
putExtra(Intent.EXTRA_STREAM, uri)
|
||||
}
|
||||
.wrapWithChooser(this@PlayAudioActivity)
|
||||
startActivity(intent)
|
||||
}
|
||||
}
|
||||
|
||||
private fun delete() {
|
||||
MaterialAlertDialogBuilder(this)
|
||||
.setMessage(R.string.delete_audio_recording_forever)
|
||||
.setCancelButton()
|
||||
.setPositiveButton(R.string.delete) { _, _ ->
|
||||
val intent = Intent()
|
||||
intent.putExtra(EXTRA_AUDIO, audio)
|
||||
setResult(RESULT_OK, intent)
|
||||
finish()
|
||||
}
|
||||
.show()
|
||||
}
|
||||
|
||||
private fun saveToDevice() {
|
||||
val audioRoot = application.getExternalAudioDirectory()
|
||||
val file = if (audioRoot != null) File(audioRoot, audio.name) else null
|
||||
if (file != null && file.exists()) {
|
||||
val intent =
|
||||
Intent(Intent.ACTION_CREATE_DOCUMENT)
|
||||
.apply {
|
||||
type = "audio/mp4"
|
||||
addCategory(Intent.CATEGORY_OPENABLE)
|
||||
}
|
||||
.wrapWithChooser(this)
|
||||
|
||||
val formatter = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.SHORT)
|
||||
val title = formatter.format(audio.timestamp)
|
||||
|
||||
intent.putExtra(Intent.EXTRA_TITLE, title)
|
||||
exportFileActivityResultLauncher.launch(intent)
|
||||
}
|
||||
}
|
||||
|
||||
private fun writeAudioToUri(uri: Uri) {
|
||||
lifecycleScope.launch {
|
||||
withContext(Dispatchers.IO) {
|
||||
val audioRoot = application.getExternalAudioDirectory()
|
||||
val file = if (audioRoot != null) File(audioRoot, audio.name) else null
|
||||
if (file != null && file.exists()) {
|
||||
val output = contentResolver.openOutputStream(uri) as FileOutputStream
|
||||
output.channel.truncate(0)
|
||||
val input = FileInputStream(file)
|
||||
input.copyTo(output)
|
||||
input.close()
|
||||
output.close()
|
||||
}
|
||||
}
|
||||
Toast.makeText(this@PlayAudioActivity, R.string.saved_to_device, Toast.LENGTH_LONG)
|
||||
.show()
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateUI(service: AudioPlayService) {
|
||||
binding.AudioControlView.setCurrentPosition(service.getCurrentPosition())
|
||||
when (service.getState()) {
|
||||
AudioPlayService.PREPARED,
|
||||
AudioPlayService.PAUSED,
|
||||
AudioPlayService.COMPLETED -> {
|
||||
binding.Play.setText(R.string.play)
|
||||
binding.AudioControlView.setStarted(false)
|
||||
}
|
||||
AudioPlayService.STARTED -> {
|
||||
binding.Play.setText(R.string.pause)
|
||||
binding.AudioControlView.setStarted(true)
|
||||
}
|
||||
AudioPlayService.ERROR -> {
|
||||
binding.Error.text =
|
||||
getString(
|
||||
R.string.something_went_wrong_audio,
|
||||
service.getErrorType(),
|
||||
service.getErrorCode(),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val EXTRA_AUDIO = "notallyx.intent.extra.AUDIO"
|
||||
}
|
||||
}
|
|
@ -1,129 +0,0 @@
|
|||
package com.philkes.notallyx.presentation.activity.note
|
||||
|
||||
import android.content.ComponentName
|
||||
import android.content.Intent
|
||||
import android.content.ServiceConnection
|
||||
import android.os.Bundle
|
||||
import android.os.IBinder
|
||||
import androidx.activity.OnBackPressedCallback
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.lifecycle.Observer
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import com.philkes.notallyx.R
|
||||
import com.philkes.notallyx.databinding.ActivityRecordAudioBinding
|
||||
import com.philkes.notallyx.presentation.activity.LockedActivity
|
||||
import com.philkes.notallyx.utils.audio.AudioRecordService
|
||||
import com.philkes.notallyx.utils.audio.LocalBinder
|
||||
import com.philkes.notallyx.utils.audio.Status
|
||||
import com.philkes.notallyx.utils.getTempAudioFile
|
||||
|
||||
@RequiresApi(24)
|
||||
class RecordAudioActivity : LockedActivity<ActivityRecordAudioBinding>() {
|
||||
|
||||
private var service: AudioRecordService? = null
|
||||
private lateinit var connection: ServiceConnection
|
||||
private lateinit var serviceStatusObserver: Observer<Status>
|
||||
private lateinit var cancelRecordCallback: OnBackPressedCallback
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
binding = ActivityRecordAudioBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
|
||||
val intent = Intent(this, AudioRecordService::class.java)
|
||||
startService(intent)
|
||||
|
||||
connection =
|
||||
object : ServiceConnection {
|
||||
override fun onServiceConnected(name: ComponentName, binder: IBinder) {
|
||||
service = (binder as LocalBinder<AudioRecordService>).getService()
|
||||
service?.status?.observe(this@RecordAudioActivity, serviceStatusObserver)
|
||||
}
|
||||
|
||||
override fun onServiceDisconnected(name: ComponentName?) {}
|
||||
}
|
||||
|
||||
bindService(intent, connection, BIND_AUTO_CREATE)
|
||||
|
||||
binding.Main.setOnClickListener {
|
||||
val service = this.service
|
||||
if (service != null) {
|
||||
when (service.status.value) {
|
||||
Status.PAUSED -> service.resume()
|
||||
Status.READY -> service.start()
|
||||
Status.RECORDING -> service.pause()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
binding.Stop.setOnClickListener {
|
||||
val service = this.service
|
||||
if (service != null) {
|
||||
stopRecording(service)
|
||||
}
|
||||
}
|
||||
|
||||
binding.Toolbar.setNavigationOnClickListener { onBackPressedDispatcher.onBackPressed() }
|
||||
|
||||
cancelRecordCallback =
|
||||
object : OnBackPressedCallback(true) {
|
||||
override fun handleOnBackPressed() {
|
||||
MaterialAlertDialogBuilder(this@RecordAudioActivity)
|
||||
.setMessage(R.string.save_recording)
|
||||
.setPositiveButton(R.string.save) { _, _ -> stopRecording(service!!) }
|
||||
.setNegativeButton(R.string.discard) { _, _ -> discard(service!!) }
|
||||
.show()
|
||||
}
|
||||
}
|
||||
onBackPressedDispatcher.addCallback(cancelRecordCallback)
|
||||
serviceStatusObserver = Observer { status ->
|
||||
updateUI(binding, service!!)
|
||||
cancelRecordCallback.isEnabled = status != Status.READY
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
service?.let {
|
||||
unbindService(connection)
|
||||
it.status.removeObserver(serviceStatusObserver)
|
||||
service = null
|
||||
}
|
||||
if (isFinishing) {
|
||||
val intent = Intent(this, AudioRecordService::class.java)
|
||||
stopService(intent)
|
||||
}
|
||||
}
|
||||
|
||||
private fun discard(service: AudioRecordService) {
|
||||
service.stop()
|
||||
getTempAudioFile().delete()
|
||||
finish()
|
||||
}
|
||||
|
||||
private fun stopRecording(service: AudioRecordService) {
|
||||
service.stop()
|
||||
setResult(RESULT_OK)
|
||||
finish()
|
||||
}
|
||||
|
||||
private fun updateUI(binding: ActivityRecordAudioBinding, service: AudioRecordService) {
|
||||
binding.Timer.base = service.getBase()
|
||||
when (service.status.value) {
|
||||
Status.READY -> {
|
||||
binding.Stop.isEnabled = false
|
||||
binding.Main.setText(R.string.start)
|
||||
}
|
||||
Status.RECORDING -> {
|
||||
binding.Timer.start()
|
||||
binding.Stop.isEnabled = true
|
||||
binding.Main.setText(R.string.pause)
|
||||
}
|
||||
Status.PAUSED -> {
|
||||
binding.Timer.stop()
|
||||
binding.Stop.isEnabled = true
|
||||
binding.Main.setText(R.string.resume)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,106 +0,0 @@
|
|||
package com.philkes.notallyx.presentation.activity.note
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import androidx.recyclerview.widget.DividerItemDecoration
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import com.philkes.notallyx.R
|
||||
import com.philkes.notallyx.data.model.Label
|
||||
import com.philkes.notallyx.databinding.ActivityLabelBinding
|
||||
import com.philkes.notallyx.databinding.DialogInputBinding
|
||||
import com.philkes.notallyx.presentation.activity.LockedActivity
|
||||
import com.philkes.notallyx.presentation.add
|
||||
import com.philkes.notallyx.presentation.setCancelButton
|
||||
import com.philkes.notallyx.presentation.showAndFocus
|
||||
import com.philkes.notallyx.presentation.showToast
|
||||
import com.philkes.notallyx.presentation.view.main.label.SelectableLabelAdapter
|
||||
|
||||
class SelectLabelsActivity : LockedActivity<ActivityLabelBinding>() {
|
||||
|
||||
private lateinit var selectedLabels: ArrayList<String>
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
binding = ActivityLabelBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
|
||||
val savedList = savedInstanceState?.getStringArrayList(EXTRA_SELECTED_LABELS)
|
||||
val passedList = requireNotNull(intent.getStringArrayListExtra(EXTRA_SELECTED_LABELS))
|
||||
selectedLabels = savedList ?: passedList
|
||||
|
||||
val result = Intent()
|
||||
result.putExtra(EXTRA_SELECTED_LABELS, selectedLabels)
|
||||
setResult(RESULT_OK, result)
|
||||
|
||||
setupToolbar()
|
||||
setupRecyclerView()
|
||||
}
|
||||
|
||||
override fun onSaveInstanceState(outState: Bundle) {
|
||||
super.onSaveInstanceState(outState)
|
||||
outState.putStringArrayList(EXTRA_SELECTED_LABELS, selectedLabels)
|
||||
}
|
||||
|
||||
private fun setupToolbar() {
|
||||
binding.Toolbar.apply {
|
||||
setNavigationOnClickListener { finish() }
|
||||
menu.add(R.string.add_label, R.drawable.add) { addLabel() }
|
||||
}
|
||||
}
|
||||
|
||||
private fun addLabel() {
|
||||
val binding = DialogInputBinding.inflate(layoutInflater)
|
||||
|
||||
MaterialAlertDialogBuilder(this)
|
||||
.setTitle(R.string.add_label)
|
||||
.setView(binding.root)
|
||||
.setCancelButton()
|
||||
.setPositiveButton(R.string.save) { dialog, _ ->
|
||||
val value = binding.EditText.text.toString().trim()
|
||||
if (value.isNotEmpty()) {
|
||||
val label = Label(value)
|
||||
baseModel.insertLabel(label) { success ->
|
||||
if (success) {
|
||||
dialog.dismiss()
|
||||
} else showToast(R.string.label_exists)
|
||||
}
|
||||
}
|
||||
}
|
||||
.showAndFocus(binding.EditText, allowFullSize = true)
|
||||
}
|
||||
|
||||
private fun setupRecyclerView() {
|
||||
val labelAdapter = SelectableLabelAdapter(selectedLabels)
|
||||
labelAdapter.onChecked = { position, checked ->
|
||||
if (position != -1) {
|
||||
val label = labelAdapter.currentList[position]
|
||||
if (checked) {
|
||||
if (!selectedLabels.contains(label)) {
|
||||
selectedLabels.add(label)
|
||||
}
|
||||
} else selectedLabels.remove(label)
|
||||
}
|
||||
}
|
||||
|
||||
binding.MainListView.apply {
|
||||
setHasFixedSize(true)
|
||||
adapter = labelAdapter
|
||||
addItemDecoration(
|
||||
DividerItemDecoration(this@SelectLabelsActivity, RecyclerView.VERTICAL)
|
||||
)
|
||||
}
|
||||
|
||||
baseModel.labels.observe(this) { labels ->
|
||||
labelAdapter.submitList(labels)
|
||||
if (labels.isEmpty()) {
|
||||
binding.EmptyState.visibility = View.VISIBLE
|
||||
} else binding.EmptyState.visibility = View.INVISIBLE
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val EXTRA_SELECTED_LABELS = "notallyx.intent.extra.SELECTED_LABELS"
|
||||
}
|
||||
}
|
|
@ -1,239 +0,0 @@
|
|||
package com.philkes.notallyx.presentation.activity.note
|
||||
|
||||
import android.content.ClipData
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.widget.Toast
|
||||
import androidx.activity.result.ActivityResultLauncher
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.core.os.BundleCompat
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.PagerSnapHelper
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import com.philkes.notallyx.R
|
||||
import com.philkes.notallyx.data.NotallyDatabase
|
||||
import com.philkes.notallyx.data.model.Converters
|
||||
import com.philkes.notallyx.data.model.FileAttachment
|
||||
import com.philkes.notallyx.databinding.ActivityViewImageBinding
|
||||
import com.philkes.notallyx.presentation.activity.LockedActivity
|
||||
import com.philkes.notallyx.presentation.activity.note.EditActivity.Companion.EXTRA_SELECTED_BASE_NOTE
|
||||
import com.philkes.notallyx.presentation.add
|
||||
import com.philkes.notallyx.presentation.setCancelButton
|
||||
import com.philkes.notallyx.presentation.view.note.image.ImageAdapter
|
||||
import com.philkes.notallyx.utils.getExternalImagesDirectory
|
||||
import com.philkes.notallyx.utils.getUriForFile
|
||||
import com.philkes.notallyx.utils.wrapWithChooser
|
||||
import java.io.File
|
||||
import java.io.FileInputStream
|
||||
import java.io.FileOutputStream
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
class ViewImageActivity : LockedActivity<ActivityViewImageBinding>() {
|
||||
|
||||
private var currentImage: FileAttachment? = null
|
||||
private lateinit var deletedImages: ArrayList<FileAttachment>
|
||||
private lateinit var exportFileActivityResultLauncher: ActivityResultLauncher<Intent>
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
binding = ActivityViewImageBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
|
||||
val savedList =
|
||||
savedInstanceState?.let {
|
||||
BundleCompat.getParcelableArrayList(
|
||||
it,
|
||||
EXTRA_DELETED_IMAGES,
|
||||
FileAttachment::class.java,
|
||||
)
|
||||
}
|
||||
deletedImages = savedList ?: ArrayList()
|
||||
|
||||
val resultIntent = Intent()
|
||||
resultIntent.putExtra(EXTRA_DELETED_IMAGES, deletedImages)
|
||||
setResult(RESULT_OK, resultIntent)
|
||||
|
||||
val savedImage =
|
||||
savedInstanceState?.let {
|
||||
BundleCompat.getParcelable(it, CURRENT_IMAGE, FileAttachment::class.java)
|
||||
}
|
||||
if (savedImage != null) {
|
||||
currentImage = savedImage
|
||||
}
|
||||
|
||||
binding.MainListView.apply {
|
||||
setHasFixedSize(true)
|
||||
layoutManager =
|
||||
LinearLayoutManager(this@ViewImageActivity, RecyclerView.HORIZONTAL, false)
|
||||
PagerSnapHelper().attachToRecyclerView(binding.MainListView)
|
||||
}
|
||||
|
||||
val initial = intent.getIntExtra(EXTRA_POSITION, 0)
|
||||
binding.MainListView.scrollToPosition(initial)
|
||||
|
||||
val database = NotallyDatabase.getDatabase(application)
|
||||
val id = intent.getLongExtra(EXTRA_SELECTED_BASE_NOTE, 0)
|
||||
|
||||
database.observe(this@ViewImageActivity) {
|
||||
lifecycleScope.launch {
|
||||
val json = withContext(Dispatchers.IO) { it.getBaseNoteDao().getImages(id) }
|
||||
val original = Converters.jsonToFiles(json)
|
||||
val images = ArrayList<FileAttachment>(original.size)
|
||||
original.filterNotTo(images) { image -> deletedImages.contains(image) }
|
||||
|
||||
val mediaRoot = application.getExternalImagesDirectory()
|
||||
val adapter = ImageAdapter(mediaRoot, images)
|
||||
binding.MainListView.adapter = adapter
|
||||
setupToolbar(binding, adapter)
|
||||
}
|
||||
}
|
||||
|
||||
exportFileActivityResultLauncher =
|
||||
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
|
||||
if (result.resultCode == RESULT_OK) {
|
||||
result.data?.data?.let { uri -> writeImageToUri(uri) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onSaveInstanceState(outState: Bundle) {
|
||||
super.onSaveInstanceState(outState)
|
||||
outState.apply {
|
||||
putParcelable(CURRENT_IMAGE, currentImage)
|
||||
putParcelableArrayList(EXTRA_DELETED_IMAGES, deletedImages)
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupToolbar(binding: ActivityViewImageBinding, adapter: ImageAdapter) {
|
||||
binding.Toolbar.setNavigationOnClickListener { finish() }
|
||||
|
||||
val layoutManager = binding.MainListView.layoutManager as LinearLayoutManager
|
||||
adapter.registerAdapterDataObserver(
|
||||
object : RecyclerView.AdapterDataObserver() {
|
||||
|
||||
override fun onItemRangeRemoved(positionStart: Int, itemCount: Int) {
|
||||
val position = layoutManager.findFirstVisibleItemPosition()
|
||||
binding.Toolbar.title = "${position + 1} / ${adapter.itemCount}"
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
binding.MainListView.addOnScrollListener(
|
||||
object : RecyclerView.OnScrollListener() {
|
||||
|
||||
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
|
||||
val position = layoutManager.findFirstVisibleItemPosition()
|
||||
binding.Toolbar.title = "${position + 1} / ${adapter.itemCount}"
|
||||
}
|
||||
}
|
||||
)
|
||||
binding.Toolbar.menu.apply {
|
||||
add(R.string.share, R.drawable.share) {
|
||||
val position = layoutManager.findFirstCompletelyVisibleItemPosition()
|
||||
if (position != -1) {
|
||||
val image = adapter.items[position]
|
||||
share(image)
|
||||
}
|
||||
}
|
||||
add(R.string.save_to_device, R.drawable.save) {
|
||||
val position = layoutManager.findFirstCompletelyVisibleItemPosition()
|
||||
if (position != -1) {
|
||||
val image = adapter.items[position]
|
||||
saveToDevice(image)
|
||||
}
|
||||
}
|
||||
add(R.string.delete, R.drawable.delete) {
|
||||
val position = layoutManager.findFirstCompletelyVisibleItemPosition()
|
||||
if (position != -1) {
|
||||
delete(position, adapter)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun share(image: FileAttachment) {
|
||||
val mediaRoot = application.getExternalImagesDirectory()
|
||||
val file = if (mediaRoot != null) File(mediaRoot, image.localName) else null
|
||||
if (file != null && file.exists()) {
|
||||
val uri = getUriForFile(file)
|
||||
val intent =
|
||||
Intent(Intent.ACTION_SEND)
|
||||
.apply {
|
||||
type = image.mimeType
|
||||
putExtra(Intent.EXTRA_STREAM, uri)
|
||||
|
||||
// Necessary for sharesheet to show a preview of the image
|
||||
// Check ->
|
||||
// https://commonsware.com/blog/2021/01/07/action_send-share-sheet-clipdata.html
|
||||
clipData = ClipData.newRawUri(null, uri)
|
||||
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||
}
|
||||
.wrapWithChooser(this@ViewImageActivity)
|
||||
startActivity(intent)
|
||||
}
|
||||
}
|
||||
|
||||
private fun saveToDevice(image: FileAttachment) {
|
||||
val mediaRoot = application.getExternalImagesDirectory()
|
||||
val file = if (mediaRoot != null) File(mediaRoot, image.localName) else null
|
||||
if (file != null && file.exists()) {
|
||||
val intent =
|
||||
Intent(Intent.ACTION_CREATE_DOCUMENT)
|
||||
.apply {
|
||||
type = image.mimeType
|
||||
addCategory(Intent.CATEGORY_OPENABLE)
|
||||
putExtra(Intent.EXTRA_TITLE, "NotallyX Image")
|
||||
}
|
||||
.wrapWithChooser(this)
|
||||
currentImage = image
|
||||
exportFileActivityResultLauncher.launch(intent)
|
||||
}
|
||||
}
|
||||
|
||||
private fun writeImageToUri(uri: Uri) {
|
||||
lifecycleScope.launch {
|
||||
withContext(Dispatchers.IO) {
|
||||
val mediaRoot = application.getExternalImagesDirectory()
|
||||
val file =
|
||||
if (mediaRoot != null) File(mediaRoot, requireNotNull(currentImage).localName)
|
||||
else null
|
||||
if (file != null && file.exists()) {
|
||||
val output = contentResolver.openOutputStream(uri) as FileOutputStream
|
||||
output.channel.truncate(0)
|
||||
val input = FileInputStream(file)
|
||||
input.copyTo(output)
|
||||
input.close()
|
||||
output.close()
|
||||
}
|
||||
}
|
||||
Toast.makeText(this@ViewImageActivity, R.string.saved_to_device, Toast.LENGTH_LONG)
|
||||
.show()
|
||||
}
|
||||
}
|
||||
|
||||
private fun delete(position: Int, adapter: ImageAdapter) {
|
||||
MaterialAlertDialogBuilder(this)
|
||||
.setMessage(R.string.delete_image_forever)
|
||||
.setCancelButton()
|
||||
.setPositiveButton(R.string.delete) { _, _ ->
|
||||
val image = adapter.items.removeAt(position)
|
||||
deletedImages.add(image)
|
||||
adapter.notifyItemRemoved(position)
|
||||
if (adapter.items.isEmpty()) {
|
||||
finish()
|
||||
}
|
||||
}
|
||||
.show()
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val EXTRA_POSITION = "notallyx.intent.extra.POSITION"
|
||||
const val CURRENT_IMAGE = "CURRENT_IMAGE"
|
||||
const val EXTRA_DELETED_IMAGES = "notallyx.intent.extra.DELETED_IMAGES"
|
||||
}
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
package com.philkes.notallyx.presentation.activity.note.reminders
|
||||
|
||||
import android.app.DatePickerDialog
|
||||
import android.app.Dialog
|
||||
import android.os.Bundle
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import com.philkes.notallyx.utils.now
|
||||
import java.util.Calendar
|
||||
import java.util.Date
|
||||
|
||||
class DatePickerFragment(
|
||||
private val date: Date?,
|
||||
private val listener: DatePickerDialog.OnDateSetListener,
|
||||
) : DialogFragment() {
|
||||
|
||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||
val now = now()
|
||||
val c = date?.let { Calendar.getInstance().apply { time = it } } ?: now
|
||||
val year = c.get(Calendar.YEAR)
|
||||
val month = c.get(Calendar.MONTH)
|
||||
val day = c.get(Calendar.DAY_OF_MONTH)
|
||||
return DatePickerDialog(requireContext(), listener, year, month, day)
|
||||
}
|
||||
}
|
|
@ -1,145 +0,0 @@
|
|||
package com.philkes.notallyx.presentation.activity.note.reminders
|
||||
|
||||
import android.app.AlarmManager
|
||||
import android.app.Application
|
||||
import android.app.NotificationManager
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Build
|
||||
import android.util.Log
|
||||
import androidx.core.app.NotificationCompat
|
||||
import androidx.core.content.getSystemService
|
||||
import com.philkes.notallyx.R
|
||||
import com.philkes.notallyx.data.NotallyDatabase
|
||||
import com.philkes.notallyx.data.model.Reminder
|
||||
import com.philkes.notallyx.utils.canScheduleAlarms
|
||||
import com.philkes.notallyx.utils.cancelReminder
|
||||
import com.philkes.notallyx.utils.createChannelIfNotExists
|
||||
import com.philkes.notallyx.utils.getOpenNotePendingIntent
|
||||
import com.philkes.notallyx.utils.scheduleReminder
|
||||
import com.philkes.notallyx.utils.truncate
|
||||
import java.util.Date
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
/**
|
||||
* [BroadcastReceiver] for sending notifications via [NotificationManager] for [Reminder]s.
|
||||
* Reschedules reminders on [Intent.ACTION_BOOT_COMPLETED] or if
|
||||
* [AlarmManager.ACTION_SCHEDULE_EXACT_ALARM_PERMISSION_STATE_CHANGED] has changed and exact alarms
|
||||
* are allowed. For [Reminder] that have [Reminder.repetition] it automatically reschedules the next
|
||||
* alarm.
|
||||
*/
|
||||
class ReminderReceiver : BroadcastReceiver() {
|
||||
override fun onReceive(context: Context?, intent: Intent?) {
|
||||
Log.d(TAG, "onReceive: ${intent?.action}")
|
||||
if (intent == null || context == null) {
|
||||
return
|
||||
}
|
||||
val canScheduleExactAlarms = context.canScheduleAlarms()
|
||||
if (intent.action == null) {
|
||||
if (!canScheduleExactAlarms) {
|
||||
return
|
||||
}
|
||||
val reminderId = intent.getLongExtra(EXTRA_REMINDER_ID, -1L)
|
||||
val noteId = intent.getLongExtra(EXTRA_NOTE_ID, -1L)
|
||||
notify(context, noteId, reminderId)
|
||||
} else {
|
||||
when {
|
||||
canScheduleExactAlarms && intent.action == Intent.ACTION_BOOT_COMPLETED ->
|
||||
rescheduleAlarms(context)
|
||||
|
||||
intent.action ==
|
||||
AlarmManager.ACTION_SCHEDULE_EXACT_ALARM_PERMISSION_STATE_CHANGED -> {
|
||||
if (canScheduleExactAlarms) {
|
||||
rescheduleAlarms(context)
|
||||
} else {
|
||||
cancelAlarms(context)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun notify(context: Context, noteId: Long, reminderId: Long) {
|
||||
Log.d(TAG, "notify: noteId: $noteId reminderId: $reminderId")
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
val database =
|
||||
NotallyDatabase.getDatabase(context.applicationContext as Application, false).value
|
||||
val manager = context.getSystemService<NotificationManager>()!!
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
manager.createChannelIfNotExists(
|
||||
NOTIFICATION_CHANNEL_ID,
|
||||
importance = NotificationManager.IMPORTANCE_HIGH,
|
||||
)
|
||||
}
|
||||
database.getBaseNoteDao().get(noteId)?.let { note ->
|
||||
val notification =
|
||||
NotificationCompat.Builder(context, NOTIFICATION_CHANNEL_ID)
|
||||
.setSmallIcon(R.drawable.notebook)
|
||||
.setContentTitle(note.title) // Set title from intent
|
||||
.setContentText(note.body.truncate(200)) // Set content text from intent
|
||||
.setPriority(NotificationCompat.PRIORITY_HIGH)
|
||||
.addAction(
|
||||
R.drawable.visibility,
|
||||
context.getString(R.string.open_note),
|
||||
context.getOpenNotePendingIntent(note),
|
||||
)
|
||||
.build()
|
||||
note.reminders
|
||||
.find { it.id == reminderId }
|
||||
?.let { reminder: Reminder ->
|
||||
manager.notify(note.id.toString(), reminderId.toInt(), notification)
|
||||
context.scheduleReminder(note.id, reminder, forceRepetition = true)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun rescheduleAlarms(context: Context) {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
val database =
|
||||
NotallyDatabase.getDatabase(context.applicationContext as Application, false).value
|
||||
val now = Date()
|
||||
val noteReminders = database.getBaseNoteDao().getAllReminders()
|
||||
val noteRemindersWithFutureNotify =
|
||||
noteReminders.flatMap { (noteId, reminders) ->
|
||||
reminders
|
||||
.filter { reminder ->
|
||||
reminder.repetition != null || reminder.dateTime.after(now)
|
||||
}
|
||||
.map { reminder -> Pair(noteId, reminder) }
|
||||
}
|
||||
Log.d(TAG, "rescheduleAlarms: ${noteRemindersWithFutureNotify.size} alarms")
|
||||
noteRemindersWithFutureNotify.forEach { (noteId, reminder) ->
|
||||
context.scheduleReminder(noteId, reminder)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun cancelAlarms(context: Context) {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
val database =
|
||||
NotallyDatabase.getDatabase(context.applicationContext as Application, false).value
|
||||
val noteReminders = database.getBaseNoteDao().getAllReminders()
|
||||
val noteRemindersWithFutureNotify =
|
||||
noteReminders.flatMap { (noteId, reminders) ->
|
||||
reminders.map { reminder -> Pair(noteId, reminder.id) }
|
||||
}
|
||||
Log.d(TAG, "cancelAlarms: ${noteRemindersWithFutureNotify.size} alarms")
|
||||
noteRemindersWithFutureNotify.forEach { (noteId, reminderId) ->
|
||||
context.cancelReminder(noteId, reminderId)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val TAG = "ReminderReceiver"
|
||||
|
||||
private const val NOTIFICATION_CHANNEL_ID = "Reminders"
|
||||
|
||||
const val EXTRA_REMINDER_ID = "notallyx.intent.extra.REMINDER_ID"
|
||||
const val EXTRA_NOTE_ID = "notallyx.intent.extra.NOTE_ID"
|
||||
}
|
||||
}
|
|
@ -1,328 +0,0 @@
|
|||
package com.philkes.notallyx.presentation.activity.note.reminders
|
||||
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.Bundle
|
||||
import android.text.Editable
|
||||
import android.view.View
|
||||
import android.widget.Button
|
||||
import android.widget.RadioButton
|
||||
import android.widget.TimePicker
|
||||
import androidx.activity.result.ActivityResultLauncher
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.activity.viewModels
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.core.widget.doAfterTextChanged
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import com.philkes.notallyx.R
|
||||
import com.philkes.notallyx.data.model.Reminder
|
||||
import com.philkes.notallyx.data.model.Repetition
|
||||
import com.philkes.notallyx.data.model.RepetitionTimeUnit
|
||||
import com.philkes.notallyx.data.model.toCalendar
|
||||
import com.philkes.notallyx.data.model.toText
|
||||
import com.philkes.notallyx.databinding.ActivityRemindersBinding
|
||||
import com.philkes.notallyx.databinding.DialogReminderCustomRepetitionBinding
|
||||
import com.philkes.notallyx.databinding.DialogReminderRepetitionBinding
|
||||
import com.philkes.notallyx.presentation.activity.LockedActivity
|
||||
import com.philkes.notallyx.presentation.add
|
||||
import com.philkes.notallyx.presentation.checkAlarmPermission
|
||||
import com.philkes.notallyx.presentation.checkNotificationPermission
|
||||
import com.philkes.notallyx.presentation.initListView
|
||||
import com.philkes.notallyx.presentation.setCancelButton
|
||||
import com.philkes.notallyx.presentation.showAndFocus
|
||||
import com.philkes.notallyx.presentation.view.main.reminder.ReminderAdapter
|
||||
import com.philkes.notallyx.presentation.view.main.reminder.ReminderListener
|
||||
import com.philkes.notallyx.presentation.viewmodel.NotallyModel
|
||||
import com.philkes.notallyx.utils.canScheduleAlarms
|
||||
import com.philkes.notallyx.utils.now
|
||||
import java.util.Calendar
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
class RemindersActivity : LockedActivity<ActivityRemindersBinding>(), ReminderListener {
|
||||
|
||||
private lateinit var alarmPermissionActivityResultLauncher: ActivityResultLauncher<Intent>
|
||||
private val model: NotallyModel by viewModels()
|
||||
private lateinit var reminderAdapter: ReminderAdapter
|
||||
private var selectedReminder: Reminder? = null
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
binding = ActivityRemindersBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
setupToolbar()
|
||||
setupRecyclerView()
|
||||
|
||||
alarmPermissionActivityResultLauncher =
|
||||
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
|
||||
if (canScheduleAlarms()) {
|
||||
showDatePickerDialog(selectedReminder)
|
||||
}
|
||||
}
|
||||
val noteId = intent.getLongExtra(NOTE_ID, 0L)
|
||||
lifecycleScope.launch {
|
||||
model.setState(noteId)
|
||||
if (model.reminders.value.isEmpty()) {
|
||||
showDatePickerDialog()
|
||||
} else if (!canScheduleAlarms()) {
|
||||
checkNotificationPermission(
|
||||
REQUEST_NOTIFICATION_PERMISSION_REQUEST_CODE,
|
||||
alsoCheckAlarmPermission = true,
|
||||
) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onRequestPermissionsResult(
|
||||
requestCode: Int,
|
||||
permissions: Array<out String>,
|
||||
grantResults: IntArray,
|
||||
) {
|
||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
|
||||
when (requestCode) {
|
||||
REQUEST_NOTIFICATION_PERMISSION_ON_OPEN_REQUEST_CODE -> {
|
||||
if (
|
||||
grantResults.isNotEmpty() &&
|
||||
grantResults[0] == PackageManager.PERMISSION_GRANTED
|
||||
) {
|
||||
checkAlarmPermission(alarmPermissionActivityResultLauncher) {
|
||||
showDatePickerDialog(selectedReminder)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupToolbar() {
|
||||
binding.Toolbar.apply {
|
||||
setNavigationOnClickListener { finish() }
|
||||
menu.add(R.string.add_reminder, R.drawable.add) { showDatePickerDialog() }
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupRecyclerView() {
|
||||
reminderAdapter = ReminderAdapter(this)
|
||||
binding.MainListView.apply {
|
||||
initListView(this@RemindersActivity)
|
||||
adapter = reminderAdapter
|
||||
}
|
||||
model.reminders.observe(this) { reminders ->
|
||||
reminderAdapter.submitList(reminders)
|
||||
if (reminders.isEmpty()) {
|
||||
binding.EmptyState.visibility = View.VISIBLE
|
||||
} else binding.EmptyState.visibility = View.INVISIBLE
|
||||
}
|
||||
}
|
||||
|
||||
private fun showDatePickerDialog(reminder: Reminder? = null, calendar: Calendar? = null) {
|
||||
selectedReminder = reminder
|
||||
checkNotificationPermission(
|
||||
REQUEST_NOTIFICATION_PERMISSION_ON_OPEN_REQUEST_CODE,
|
||||
alsoCheckAlarmPermission = true,
|
||||
alarmPermissionResultLauncher = alarmPermissionActivityResultLauncher,
|
||||
) {
|
||||
DatePickerFragment(calendar?.time ?: reminder?.dateTime) { _, year, month, day ->
|
||||
val usedCalendar = calendar ?: reminder?.dateTime?.toCalendar() ?: now()
|
||||
usedCalendar.set(year, month, day)
|
||||
showTimePickerDialog(reminder, usedCalendar)
|
||||
}
|
||||
.show(supportFragmentManager, "reminderDatePicker")
|
||||
}
|
||||
}
|
||||
|
||||
private fun showTimePickerDialog(reminder: Reminder? = null, calendar: Calendar) {
|
||||
TimePickerFragment(
|
||||
calendar,
|
||||
object : TimePickerListener {
|
||||
override fun onBack() {
|
||||
showDatePickerDialog(reminder, calendar)
|
||||
}
|
||||
|
||||
override fun onTimeSet(view: TimePicker?, hourOfDay: Int, minute: Int) {
|
||||
calendar.set(Calendar.HOUR_OF_DAY, hourOfDay)
|
||||
calendar.set(Calendar.MINUTE, minute)
|
||||
showRepetitionDialog(reminder, calendar) { updatedRepetition ->
|
||||
val updatedReminder =
|
||||
Reminder(
|
||||
reminder?.id ?: NEW_REMINDER_ID,
|
||||
calendar.time,
|
||||
updatedRepetition,
|
||||
)
|
||||
if (reminder != null) {
|
||||
lifecycleScope.launch { model.updateReminder(updatedReminder) }
|
||||
} else {
|
||||
lifecycleScope.launch { model.addReminder(updatedReminder) }
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
)
|
||||
.show(supportFragmentManager, "reminderTimePicker")
|
||||
}
|
||||
|
||||
private fun showRepetitionDialog(
|
||||
reminder: Reminder? = null,
|
||||
calendar: Calendar,
|
||||
fromCustomRepetitionDialog: Boolean = false,
|
||||
onRepetitionSelected: (Repetition?) -> Unit,
|
||||
) {
|
||||
val dialogView =
|
||||
DialogReminderRepetitionBinding.inflate(layoutInflater).apply {
|
||||
if (reminder == null && fromCustomRepetitionDialog) {
|
||||
None.isChecked = true
|
||||
} else {
|
||||
reminder?.repetition.apply {
|
||||
when {
|
||||
this == null -> None.isChecked = true
|
||||
value == 1 && unit == RepetitionTimeUnit.DAYS -> Daily.isChecked = true
|
||||
|
||||
value == 1 && unit == RepetitionTimeUnit.WEEKS ->
|
||||
Weekly.isChecked = true
|
||||
|
||||
value == 1 && unit == RepetitionTimeUnit.MONTHS ->
|
||||
Monthly.isChecked = true
|
||||
|
||||
value == 1 && unit == RepetitionTimeUnit.YEARS ->
|
||||
Yearly.isChecked = true
|
||||
|
||||
fromCustomRepetitionDialog -> Custom.isChecked = true
|
||||
else -> {
|
||||
showCustomRepetitionDialog(reminder, calendar, onRepetitionSelected)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val dialog =
|
||||
MaterialAlertDialogBuilder(this)
|
||||
.setTitle(R.string.repetition)
|
||||
.setView(dialogView.root)
|
||||
.setPositiveButton(R.string.save) { _, _ ->
|
||||
val repetition =
|
||||
when (dialogView.RepetitionOptions.checkedRadioButtonId) {
|
||||
R.id.None -> null
|
||||
R.id.Daily -> Repetition(1, RepetitionTimeUnit.DAYS)
|
||||
R.id.Weekly -> Repetition(1, RepetitionTimeUnit.WEEKS)
|
||||
R.id.Monthly -> Repetition(1, RepetitionTimeUnit.MONTHS)
|
||||
R.id.Yearly -> Repetition(1, RepetitionTimeUnit.YEARS)
|
||||
R.id.Custom -> reminder?.repetition?.copy()
|
||||
else -> null
|
||||
}
|
||||
onRepetitionSelected(repetition)
|
||||
}
|
||||
.setNegativeButton(R.string.back) { _, _ ->
|
||||
showTimePickerDialog(reminder, calendar)
|
||||
}
|
||||
.show()
|
||||
val positiveButton = dialog.getButton(AlertDialog.BUTTON_POSITIVE)
|
||||
dialogView.apply {
|
||||
Custom.setOnClickListener {
|
||||
dialog.dismiss()
|
||||
showCustomRepetitionDialog(reminder, calendar, onRepetitionSelected)
|
||||
}
|
||||
None.setOnCheckedEnableButton(positiveButton)
|
||||
Daily.setOnCheckedEnableButton(positiveButton)
|
||||
Weekly.setOnCheckedEnableButton(positiveButton)
|
||||
Monthly.setOnCheckedEnableButton(positiveButton)
|
||||
Yearly.setOnCheckedEnableButton(positiveButton)
|
||||
}
|
||||
}
|
||||
|
||||
private fun showCustomRepetitionDialog(
|
||||
reminder: Reminder? = null,
|
||||
calendar: Calendar,
|
||||
onRepetitionSelected: (Repetition?) -> Unit,
|
||||
) {
|
||||
val dialogView =
|
||||
DialogReminderCustomRepetitionBinding.inflate(layoutInflater).apply {
|
||||
reminder?.repetition?.let {
|
||||
when (it.unit) {
|
||||
RepetitionTimeUnit.MINUTES -> Minutes
|
||||
RepetitionTimeUnit.HOURS -> Hours
|
||||
RepetitionTimeUnit.DAYS -> Days
|
||||
RepetitionTimeUnit.WEEKS -> Weeks
|
||||
RepetitionTimeUnit.MONTHS -> Months
|
||||
RepetitionTimeUnit.YEARS -> Years
|
||||
}.isChecked = true
|
||||
Value.setText(it.value.toString())
|
||||
}
|
||||
}
|
||||
|
||||
val dialog =
|
||||
MaterialAlertDialogBuilder(this)
|
||||
.setTitle(R.string.repetition_custom)
|
||||
.setView(dialogView.root)
|
||||
.setPositiveButton(R.string.save) { _, _ ->
|
||||
val value = dialogView.Value.text.toString().toIntOrNull() ?: 1
|
||||
val selectedTimeUnit =
|
||||
when (dialogView.TimeUnitGroup.checkedRadioButtonId) {
|
||||
R.id.Minutes -> RepetitionTimeUnit.MINUTES
|
||||
R.id.Hours -> RepetitionTimeUnit.HOURS
|
||||
R.id.Days -> RepetitionTimeUnit.DAYS
|
||||
R.id.Weeks -> RepetitionTimeUnit.WEEKS
|
||||
R.id.Months -> RepetitionTimeUnit.MONTHS
|
||||
R.id.Years -> RepetitionTimeUnit.YEARS
|
||||
else -> null
|
||||
}
|
||||
onRepetitionSelected(selectedTimeUnit?.let { Repetition(value, it) })
|
||||
}
|
||||
.setBackgroundInsetBottom(0)
|
||||
.setBackgroundInsetTop(0)
|
||||
.setNegativeButton(R.string.back) { dialog, _ ->
|
||||
dialog.dismiss()
|
||||
showRepetitionDialog(
|
||||
reminder,
|
||||
calendar,
|
||||
fromCustomRepetitionDialog = true,
|
||||
onRepetitionSelected,
|
||||
)
|
||||
}
|
||||
.showAndFocus(dialogView.Value, allowFullSize = true)
|
||||
val positiveButton = dialog.getButton(AlertDialog.BUTTON_POSITIVE)
|
||||
dialogView.Value.doAfterTextChanged { text ->
|
||||
positiveButton.isEnabled = text.hasValueBiggerZero()
|
||||
}
|
||||
positiveButton.isEnabled = reminder?.repetition != null
|
||||
}
|
||||
|
||||
private fun RadioButton.setOnCheckedEnableButton(button: Button) {
|
||||
setOnCheckedChangeListener { _, isChecked ->
|
||||
if (isChecked) {
|
||||
button.isEnabled = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun Editable?.hasValueBiggerZero() =
|
||||
(!isNullOrEmpty() && toString().toIntOrNull()?.let { it > 0 } ?: false)
|
||||
|
||||
private fun confirmDeletion(reminder: Reminder) {
|
||||
MaterialAlertDialogBuilder(this)
|
||||
.setTitle(R.string.delete_reminder)
|
||||
.setMessage(
|
||||
"${reminder.dateTime.toText()}\n${reminder.repetition?.toText(this) ?: getString(R.string.reminder_no_repetition)}"
|
||||
)
|
||||
.setPositiveButton(R.string.delete) { _, _ ->
|
||||
lifecycleScope.launch { model.removeReminder(reminder) }
|
||||
}
|
||||
.setCancelButton()
|
||||
.show()
|
||||
}
|
||||
|
||||
override fun delete(reminder: Reminder) {
|
||||
confirmDeletion(reminder)
|
||||
}
|
||||
|
||||
override fun edit(reminder: Reminder) {
|
||||
showDatePickerDialog(reminder)
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val NOTE_ID = "NOTE_ID"
|
||||
const val REQUEST_NOTIFICATION_PERMISSION_ON_OPEN_REQUEST_CODE = 101
|
||||
const val REQUEST_NOTIFICATION_PERMISSION_REQUEST_CODE = 102
|
||||
const val NEW_REMINDER_ID = -1L
|
||||
}
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
package com.philkes.notallyx.presentation.activity.note.reminders
|
||||
|
||||
import android.app.Dialog
|
||||
import android.app.TimePickerDialog
|
||||
import android.content.DialogInterface
|
||||
import android.os.Bundle
|
||||
import android.text.format.DateFormat
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import com.philkes.notallyx.R
|
||||
import java.util.Calendar
|
||||
|
||||
class TimePickerFragment(private val calendar: Calendar, private val listener: TimePickerListener) :
|
||||
DialogFragment() {
|
||||
|
||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||
val hour = calendar.get(Calendar.HOUR_OF_DAY)
|
||||
val minute = calendar.get(Calendar.MINUTE)
|
||||
val dialog =
|
||||
TimePickerDialog(activity, listener, hour, minute, DateFormat.is24HourFormat(activity))
|
||||
dialog.setButton(
|
||||
DialogInterface.BUTTON_NEGATIVE,
|
||||
requireContext().getText(R.string.back),
|
||||
) { _, _ ->
|
||||
listener.onBack()
|
||||
}
|
||||
return dialog
|
||||
}
|
||||
}
|
||||
|
||||
interface TimePickerListener : TimePickerDialog.OnTimeSetListener {
|
||||
fun onBack()
|
||||
}
|
|
@ -1,130 +0,0 @@
|
|||
package com.philkes.notallyx.presentation.view.main
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.recyclerview.widget.SortedList
|
||||
import androidx.recyclerview.widget.SortedListAdapterCallback
|
||||
import com.philkes.notallyx.data.model.BaseNote
|
||||
import com.philkes.notallyx.data.model.Header
|
||||
import com.philkes.notallyx.data.model.Item
|
||||
import com.philkes.notallyx.databinding.RecyclerBaseNoteBinding
|
||||
import com.philkes.notallyx.databinding.RecyclerHeaderBinding
|
||||
import com.philkes.notallyx.presentation.view.main.sorting.BaseNoteColorSort
|
||||
import com.philkes.notallyx.presentation.view.main.sorting.BaseNoteCreationDateSort
|
||||
import com.philkes.notallyx.presentation.view.main.sorting.BaseNoteModifiedDateSort
|
||||
import com.philkes.notallyx.presentation.view.main.sorting.BaseNoteTitleSort
|
||||
import com.philkes.notallyx.presentation.view.misc.ItemListener
|
||||
import com.philkes.notallyx.presentation.viewmodel.preference.DateFormat
|
||||
import com.philkes.notallyx.presentation.viewmodel.preference.NotesSort
|
||||
import com.philkes.notallyx.presentation.viewmodel.preference.NotesSortBy
|
||||
import java.io.File
|
||||
|
||||
class BaseNoteAdapter(
|
||||
private val selectedIds: Set<Long>,
|
||||
private val dateFormat: DateFormat,
|
||||
private var notesSort: NotesSort,
|
||||
private val preferences: BaseNoteVHPreferences,
|
||||
private val imageRoot: File?,
|
||||
private val listener: ItemListener,
|
||||
) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
|
||||
|
||||
private var list = SortedList(Item::class.java, notesSort.createCallback())
|
||||
|
||||
override fun getItemViewType(position: Int): Int {
|
||||
return when (list[position]) {
|
||||
is Header -> 0
|
||||
is BaseNote -> 1
|
||||
}
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
return list.size()
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
|
||||
when (val item = list[position]) {
|
||||
is Header -> (holder as HeaderVH).bind(item)
|
||||
is BaseNote ->
|
||||
(holder as BaseNoteVH).bind(
|
||||
item,
|
||||
imageRoot,
|
||||
selectedIds.contains(item.id),
|
||||
notesSort.sortedBy,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(
|
||||
holder: RecyclerView.ViewHolder,
|
||||
position: Int,
|
||||
payloads: MutableList<Any>,
|
||||
) {
|
||||
if (payloads.isEmpty()) {
|
||||
onBindViewHolder(holder, position)
|
||||
} else handleCheck(holder, position)
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
|
||||
val inflater = LayoutInflater.from(parent.context)
|
||||
return when (viewType) {
|
||||
0 -> {
|
||||
val binding = RecyclerHeaderBinding.inflate(inflater, parent, false)
|
||||
HeaderVH(binding)
|
||||
}
|
||||
else -> {
|
||||
val binding = RecyclerBaseNoteBinding.inflate(inflater, parent, false)
|
||||
BaseNoteVH(binding, dateFormat, preferences, listener)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun setNotesSort(notesSort: NotesSort) {
|
||||
this.notesSort = notesSort
|
||||
replaceSortCallback(notesSort.createCallback())
|
||||
}
|
||||
|
||||
fun getItem(position: Int): Item? {
|
||||
return list[position]
|
||||
}
|
||||
|
||||
val currentList: List<Item>
|
||||
get() = list.toList()
|
||||
|
||||
fun submitList(items: List<Item>) {
|
||||
list.replaceAll(items)
|
||||
}
|
||||
|
||||
private fun NotesSort.createCallback() =
|
||||
when (sortedBy) {
|
||||
NotesSortBy.TITLE -> BaseNoteTitleSort(this@BaseNoteAdapter, sortDirection)
|
||||
NotesSortBy.MODIFIED_DATE ->
|
||||
BaseNoteModifiedDateSort(this@BaseNoteAdapter, sortDirection)
|
||||
NotesSortBy.CREATION_DATE ->
|
||||
BaseNoteCreationDateSort(this@BaseNoteAdapter, sortDirection)
|
||||
NotesSortBy.COLOR -> BaseNoteColorSort(this@BaseNoteAdapter, sortDirection)
|
||||
}
|
||||
|
||||
private fun replaceSortCallback(sortCallback: SortedListAdapterCallback<Item>) {
|
||||
val mutableList = mutableListOf<Item>()
|
||||
for (i in 0 until list.size()) {
|
||||
mutableList.add(list[i])
|
||||
}
|
||||
list.clear()
|
||||
list = SortedList(Item::class.java, sortCallback)
|
||||
list.addAll(mutableList)
|
||||
}
|
||||
|
||||
private fun handleCheck(holder: RecyclerView.ViewHolder, position: Int) {
|
||||
val baseNote = list[position] as BaseNote
|
||||
(holder as BaseNoteVH).updateCheck(selectedIds.contains(baseNote.id), baseNote.color)
|
||||
}
|
||||
|
||||
private fun <T> SortedList<T>.toList(): List<T> {
|
||||
val mutableList = mutableListOf<T>()
|
||||
for (i in 0 until this.size()) {
|
||||
mutableList.add(this[i])
|
||||
}
|
||||
return mutableList.toList()
|
||||
}
|
||||
}
|
|
@ -1,319 +0,0 @@
|
|||
package com.philkes.notallyx.presentation.view.main
|
||||
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.util.TypedValue
|
||||
import android.view.View.GONE
|
||||
import android.view.View.VISIBLE
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.TextView
|
||||
import androidx.core.view.children
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.core.view.updateLayoutParams
|
||||
import androidx.core.view.updatePadding
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.bumptech.glide.Glide
|
||||
import com.bumptech.glide.load.DataSource
|
||||
import com.bumptech.glide.load.engine.DiskCacheStrategy
|
||||
import com.bumptech.glide.load.engine.GlideException
|
||||
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
|
||||
import com.bumptech.glide.request.RequestListener
|
||||
import com.bumptech.glide.request.target.Target
|
||||
import com.philkes.notallyx.R
|
||||
import com.philkes.notallyx.data.model.BaseNote
|
||||
import com.philkes.notallyx.data.model.FileAttachment
|
||||
import com.philkes.notallyx.data.model.ListItem
|
||||
import com.philkes.notallyx.data.model.SpanRepresentation
|
||||
import com.philkes.notallyx.data.model.Type
|
||||
import com.philkes.notallyx.data.model.hasUpcomingNotification
|
||||
import com.philkes.notallyx.databinding.RecyclerBaseNoteBinding
|
||||
import com.philkes.notallyx.presentation.applySpans
|
||||
import com.philkes.notallyx.presentation.bindLabels
|
||||
import com.philkes.notallyx.presentation.displayFormattedTimestamp
|
||||
import com.philkes.notallyx.presentation.dp
|
||||
import com.philkes.notallyx.presentation.extractColor
|
||||
import com.philkes.notallyx.presentation.getQuantityString
|
||||
import com.philkes.notallyx.presentation.setControlsContrastColorForAllViews
|
||||
import com.philkes.notallyx.presentation.view.misc.ItemListener
|
||||
import com.philkes.notallyx.presentation.viewmodel.preference.DateFormat
|
||||
import com.philkes.notallyx.presentation.viewmodel.preference.NotesSortBy
|
||||
import com.philkes.notallyx.presentation.viewmodel.preference.TextSize
|
||||
import java.io.File
|
||||
|
||||
data class BaseNoteVHPreferences(
|
||||
val textSize: TextSize,
|
||||
val maxItems: Int,
|
||||
val maxLines: Int,
|
||||
val maxTitleLines: Int,
|
||||
val hideLabels: Boolean,
|
||||
)
|
||||
|
||||
class BaseNoteVH(
|
||||
private val binding: RecyclerBaseNoteBinding,
|
||||
private val dateFormat: DateFormat,
|
||||
private val preferences: BaseNoteVHPreferences,
|
||||
listener: ItemListener,
|
||||
) : RecyclerView.ViewHolder(binding.root) {
|
||||
|
||||
init {
|
||||
val title = preferences.textSize.displayTitleSize
|
||||
val body = preferences.textSize.displayBodySize
|
||||
|
||||
binding.apply {
|
||||
Title.setTextSize(TypedValue.COMPLEX_UNIT_SP, title)
|
||||
Date.setTextSize(TypedValue.COMPLEX_UNIT_SP, body)
|
||||
Note.setTextSize(TypedValue.COMPLEX_UNIT_SP, body)
|
||||
|
||||
LinearLayout.children.forEach { view ->
|
||||
view as TextView
|
||||
view.setTextSize(TypedValue.COMPLEX_UNIT_SP, body)
|
||||
}
|
||||
|
||||
Title.maxLines = preferences.maxTitleLines
|
||||
Note.maxLines = preferences.maxLines
|
||||
|
||||
root.setOnClickListener { listener.onClick(absoluteAdapterPosition) }
|
||||
|
||||
root.setOnLongClickListener {
|
||||
listener.onLongClick(absoluteAdapterPosition)
|
||||
return@setOnLongClickListener true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun updateCheck(checked: Boolean, color: String) {
|
||||
if (checked) {
|
||||
binding.root.strokeWidth = 3.dp
|
||||
} else {
|
||||
binding.root.strokeWidth = if (color == BaseNote.COLOR_DEFAULT) 1.dp else 0
|
||||
}
|
||||
binding.root.isChecked = checked
|
||||
}
|
||||
|
||||
fun bind(baseNote: BaseNote, imageRoot: File?, checked: Boolean, sortBy: NotesSortBy) {
|
||||
updateCheck(checked, baseNote.color)
|
||||
|
||||
when (baseNote.type) {
|
||||
Type.NOTE -> bindNote(baseNote.body, baseNote.spans, baseNote.title.isEmpty())
|
||||
Type.LIST -> bindList(baseNote.items, baseNote.title.isEmpty())
|
||||
}
|
||||
val (date, datePrefixResId) =
|
||||
when (sortBy) {
|
||||
NotesSortBy.CREATION_DATE -> Pair(baseNote.timestamp, R.string.creation_date)
|
||||
NotesSortBy.MODIFIED_DATE ->
|
||||
Pair(baseNote.modifiedTimestamp, R.string.modified_date)
|
||||
else -> Pair(null, null)
|
||||
}
|
||||
binding.Date.displayFormattedTimestamp(date, dateFormat, datePrefixResId)
|
||||
|
||||
setImages(baseNote.images, imageRoot)
|
||||
setFiles(baseNote.files)
|
||||
|
||||
binding.Title.apply {
|
||||
text = baseNote.title
|
||||
isVisible = baseNote.title.isNotEmpty()
|
||||
updatePadding(
|
||||
bottom =
|
||||
if (baseNote.hasNoContents() || shouldOnlyDisplayTitle(baseNote)) 0 else 8.dp
|
||||
)
|
||||
setCompoundDrawablesWithIntrinsicBounds(
|
||||
if (baseNote.type == Type.LIST && preferences.maxItems < 1)
|
||||
R.drawable.checkbox_small
|
||||
else 0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
)
|
||||
}
|
||||
|
||||
if (preferences.hideLabels) {
|
||||
binding.LabelGroup.visibility = GONE
|
||||
} else {
|
||||
binding.LabelGroup.bindLabels(
|
||||
baseNote.labels,
|
||||
preferences.textSize,
|
||||
binding.Note.isVisible || binding.Title.isVisible,
|
||||
)
|
||||
}
|
||||
|
||||
if (baseNote.isEmpty()) {
|
||||
binding.Title.apply {
|
||||
setText(baseNote.getEmptyMessage())
|
||||
isVisible = true
|
||||
}
|
||||
}
|
||||
setColor(baseNote.color)
|
||||
|
||||
binding.RemindersView.isVisible = baseNote.reminders.any { it.hasUpcomingNotification() }
|
||||
}
|
||||
|
||||
private fun bindNote(body: String, spans: List<SpanRepresentation>, isTitleEmpty: Boolean) {
|
||||
binding.LinearLayout.visibility = GONE
|
||||
|
||||
binding.Note.apply {
|
||||
text = body.applySpans(spans)
|
||||
if (preferences.maxLines < 1) {
|
||||
isVisible = isTitleEmpty
|
||||
maxLines = if (isTitleEmpty) 1 else preferences.maxLines
|
||||
} else {
|
||||
isVisible = body.isNotEmpty()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun bindList(items: List<ListItem>, isTitleEmpty: Boolean) {
|
||||
binding.apply {
|
||||
Note.visibility = GONE
|
||||
if (items.isEmpty()) {
|
||||
LinearLayout.visibility = GONE
|
||||
} else {
|
||||
LinearLayout.visibility = VISIBLE
|
||||
val forceShowFirstItem = preferences.maxItems < 1 && isTitleEmpty
|
||||
val filteredList = items.take(if (forceShowFirstItem) 1 else preferences.maxItems)
|
||||
LinearLayout.children.forEachIndexed { index, view ->
|
||||
if (view.id != R.id.ItemsRemaining) {
|
||||
if (index < filteredList.size) {
|
||||
val item = filteredList[index]
|
||||
(view as TextView).apply {
|
||||
text = item.body
|
||||
handleChecked(this, item.checked)
|
||||
visibility = VISIBLE
|
||||
if (item.isChild) {
|
||||
updateLayoutParams<LinearLayout.LayoutParams> {
|
||||
marginStart = 20.dp
|
||||
}
|
||||
}
|
||||
if (index == filteredList.lastIndex) {
|
||||
updatePadding(bottom = 0)
|
||||
}
|
||||
}
|
||||
} else view.visibility = GONE
|
||||
}
|
||||
}
|
||||
|
||||
if (preferences.maxItems > 0 && items.size > preferences.maxItems) {
|
||||
ItemsRemaining.apply {
|
||||
visibility = VISIBLE
|
||||
text = (items.size - preferences.maxItems).toString()
|
||||
}
|
||||
} else ItemsRemaining.visibility = GONE
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun setColor(color: String) {
|
||||
binding.root.apply {
|
||||
val colorInt = context.extractColor(color)
|
||||
setCardBackgroundColor(colorInt)
|
||||
setControlsContrastColorForAllViews(colorInt)
|
||||
}
|
||||
}
|
||||
|
||||
private fun setImages(images: List<FileAttachment>, mediaRoot: File?) {
|
||||
|
||||
binding.apply {
|
||||
if (images.isNotEmpty()) {
|
||||
ImageView.visibility = VISIBLE
|
||||
Message.visibility = GONE
|
||||
|
||||
val image = images[0]
|
||||
val file = if (mediaRoot != null) File(mediaRoot, image.localName) else null
|
||||
|
||||
Glide.with(ImageView)
|
||||
.load(file)
|
||||
.centerCrop()
|
||||
.transition(DrawableTransitionOptions.withCrossFade())
|
||||
.diskCacheStrategy(DiskCacheStrategy.NONE)
|
||||
.listener(
|
||||
object : RequestListener<Drawable> {
|
||||
|
||||
override fun onLoadFailed(
|
||||
e: GlideException?,
|
||||
model: Any?,
|
||||
target: Target<Drawable>?,
|
||||
isFirstResource: Boolean,
|
||||
): Boolean {
|
||||
Message.visibility = VISIBLE
|
||||
return false
|
||||
}
|
||||
|
||||
override fun onResourceReady(
|
||||
resource: Drawable?,
|
||||
model: Any?,
|
||||
target: Target<Drawable>?,
|
||||
dataSource: DataSource?,
|
||||
isFirstResource: Boolean,
|
||||
): Boolean {
|
||||
return false
|
||||
}
|
||||
}
|
||||
)
|
||||
.into(ImageView)
|
||||
if (images.size > 1) {
|
||||
ImageViewMore.apply {
|
||||
text = images.size.toString()
|
||||
visibility = VISIBLE
|
||||
}
|
||||
} else {
|
||||
ImageViewMore.visibility = GONE
|
||||
}
|
||||
} else {
|
||||
ImageView.visibility = GONE
|
||||
Message.visibility = GONE
|
||||
ImageViewMore.visibility = GONE
|
||||
Glide.with(ImageView).clear(ImageView)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun setFiles(files: List<FileAttachment>) {
|
||||
binding.apply {
|
||||
if (files.isNotEmpty()) {
|
||||
FileViewLayout.visibility = VISIBLE
|
||||
FileView.text = files[0].originalName
|
||||
if (files.size > 1) {
|
||||
FileViewMore.apply {
|
||||
text = getQuantityString(R.plurals.more_files, files.size - 1)
|
||||
visibility = VISIBLE
|
||||
}
|
||||
} else {
|
||||
FileViewMore.visibility = GONE
|
||||
}
|
||||
} else {
|
||||
FileViewLayout.visibility = GONE
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun shouldOnlyDisplayTitle(baseNote: BaseNote) =
|
||||
when (baseNote.type) {
|
||||
Type.NOTE -> preferences.maxLines < 1
|
||||
Type.LIST -> preferences.maxItems < 1
|
||||
}
|
||||
|
||||
private fun BaseNote.isEmpty() = title.isBlank() && hasNoContents() && images.isEmpty()
|
||||
|
||||
private fun BaseNote.hasNoContents() = body.isEmpty() && items.isEmpty()
|
||||
|
||||
private fun BaseNote.getEmptyMessage() =
|
||||
when (type) {
|
||||
Type.NOTE -> R.string.empty_note
|
||||
Type.LIST -> R.string.empty_list
|
||||
}
|
||||
|
||||
private fun handleChecked(textView: TextView, checked: Boolean) {
|
||||
if (checked) {
|
||||
textView.setCompoundDrawablesRelativeWithIntrinsicBounds(
|
||||
R.drawable.checkbox_16,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
)
|
||||
} else
|
||||
textView.setCompoundDrawablesRelativeWithIntrinsicBounds(
|
||||
R.drawable.checkbox_outline_16,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
)
|
||||
}
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
package com.philkes.notallyx.presentation.view.main
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.philkes.notallyx.databinding.RecyclerColorBinding
|
||||
import com.philkes.notallyx.presentation.view.misc.ItemListener
|
||||
|
||||
class ColorAdapter(
|
||||
private val colors: List<String>,
|
||||
private val selectedColor: String?,
|
||||
private val listener: ItemListener,
|
||||
) : RecyclerView.Adapter<ColorVH>() {
|
||||
|
||||
override fun getItemCount() = colors.size
|
||||
|
||||
override fun onBindViewHolder(holder: ColorVH, position: Int) {
|
||||
val color = colors[position]
|
||||
holder.bind(color, color == selectedColor)
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ColorVH {
|
||||
val inflater = LayoutInflater.from(parent.context)
|
||||
val binding = RecyclerColorBinding.inflate(inflater, parent, false)
|
||||
return ColorVH(binding, listener)
|
||||
}
|
||||
}
|
|
@ -1,56 +0,0 @@
|
|||
package com.philkes.notallyx.presentation.view.main
|
||||
|
||||
import android.content.res.ColorStateList
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.philkes.notallyx.R
|
||||
import com.philkes.notallyx.data.model.BaseNote
|
||||
import com.philkes.notallyx.databinding.RecyclerColorBinding
|
||||
import com.philkes.notallyx.presentation.dp
|
||||
import com.philkes.notallyx.presentation.extractColor
|
||||
import com.philkes.notallyx.presentation.getColorFromAttr
|
||||
import com.philkes.notallyx.presentation.getContrastFontColor
|
||||
import com.philkes.notallyx.presentation.view.misc.ItemListener
|
||||
|
||||
class ColorVH(private val binding: RecyclerColorBinding, listener: ItemListener) :
|
||||
RecyclerView.ViewHolder(binding.root) {
|
||||
|
||||
init {
|
||||
binding.CardView.setOnClickListener { listener.onClick(absoluteAdapterPosition) }
|
||||
binding.CardView.setOnLongClickListener {
|
||||
listener.onLongClick(absoluteAdapterPosition)
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
fun bind(color: String, isSelected: Boolean) {
|
||||
val showAddIcon = color == BaseNote.COLOR_NEW
|
||||
val context = binding.root.context
|
||||
val value =
|
||||
if (showAddIcon) context.getColorFromAttr(R.attr.colorOnSurface)
|
||||
else context.extractColor(color)
|
||||
val controlsColor = context.getContrastFontColor(value)
|
||||
binding.apply {
|
||||
CardView.apply {
|
||||
setCardBackgroundColor(value)
|
||||
contentDescription = color
|
||||
if (isSelected) {
|
||||
strokeWidth = 4.dp
|
||||
strokeColor = controlsColor
|
||||
} else {
|
||||
strokeWidth = 1.dp
|
||||
strokeColor = controlsColor
|
||||
}
|
||||
}
|
||||
CardIcon.apply {
|
||||
if (showAddIcon) {
|
||||
setImageResource(R.drawable.add)
|
||||
} else if (isSelected) {
|
||||
setImageResource(R.drawable.checked_circle)
|
||||
}
|
||||
imageTintList = ColorStateList.valueOf(controlsColor)
|
||||
isVisible = showAddIcon || isSelected
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
package com.philkes.notallyx.presentation.view.main
|
||||
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.recyclerview.widget.StaggeredGridLayoutManager
|
||||
import com.philkes.notallyx.data.model.Header
|
||||
import com.philkes.notallyx.databinding.RecyclerHeaderBinding
|
||||
|
||||
class HeaderVH(private val binding: RecyclerHeaderBinding) : RecyclerView.ViewHolder(binding.root) {
|
||||
|
||||
init {
|
||||
val params = binding.root.layoutParams
|
||||
if (params is StaggeredGridLayoutManager.LayoutParams) {
|
||||
params.isFullSpan = true
|
||||
}
|
||||
}
|
||||
|
||||
fun bind(header: Header) {
|
||||
binding.root.text = header.label
|
||||
}
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
package com.philkes.notallyx.presentation.view.main.label
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.DiffUtil
|
||||
import androidx.recyclerview.widget.ListAdapter
|
||||
import com.philkes.notallyx.databinding.RecyclerLabelBinding
|
||||
|
||||
class LabelAdapter(private val listener: LabelListener) :
|
||||
ListAdapter<LabelData, LabelVH>(DiffCallback) {
|
||||
|
||||
override fun onBindViewHolder(holder: LabelVH, position: Int) {
|
||||
val label = getItem(position)
|
||||
holder.bind(label)
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): LabelVH {
|
||||
val inflater = LayoutInflater.from(parent.context)
|
||||
val binding = RecyclerLabelBinding.inflate(inflater, parent, false)
|
||||
return LabelVH(binding, listener)
|
||||
}
|
||||
}
|
||||
|
||||
data class LabelData(val label: String, var visibleInNavigation: Boolean)
|
||||
|
||||
private object DiffCallback : DiffUtil.ItemCallback<LabelData>() {
|
||||
|
||||
override fun areItemsTheSame(oldItem: LabelData, newItem: LabelData): Boolean {
|
||||
return oldItem == newItem
|
||||
}
|
||||
|
||||
override fun areContentsTheSame(oldItem: LabelData, newItem: LabelData): Boolean {
|
||||
return oldItem == newItem
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue