Skip to content

Commit

Permalink
New note navigation view
Browse files Browse the repository at this point in the history
  • Loading branch information
FliegendeWurst committed Feb 16, 2025
1 parent 1d0c52c commit 08e0136
Show file tree
Hide file tree
Showing 23 changed files with 605 additions and 12 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ dependencies {
implementation "com.squareup.okhttp3:okhttp:4.12.0"
implementation "com.squareup.okhttp3:okhttp-tls:4.12.0"
// implementation "com.github.skydoves:colorpickerview:2.3.0"
implementation 'com.google.android.flexbox:flexbox:3.0.0'

implementation "org.wordpress:aztec:v2.1.4"

Expand Down
133 changes: 133 additions & 0 deletions app/src/main/assets/mindMap_TPL.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
<!DOCTYPE html>
<!-- derived from https://github.com/TriliumNext/Notes/blob/develop/src/public/app/widgets/type_widgets/mind_map.ts -->
<div class="note-detail-mind-map note-detail-printable">
<div class="mind-map-container">
</div>

<style>
.note-detail-mind-map {
height: 100%;
overflow: hidden !important;
}

.note-detail-mind-map .mind-map-container {
height: 100%;
}

.mind-elixir .node-menu {
position: absolute;
top: 60px;
right: 20px;
bottom: 80px;
overflow: auto;
background: var(--panel-bgcolor);
color: var(--main-color);
border-radius: 5px;
box-shadow: 0 1px 2px #0003;
width: 240px;
box-sizing: border-box;
padding: 0 15px 15px;
transition: .3s all
}

.mind-elixir .node-menu.close {
height: 29px;
width: 46px;
overflow: hidden
}

.mind-elixir .node-menu .button-container {
padding: 3px 0;
direction: rtl
}

.mind-elixir .node-menu #nm-tag {
margin-top: 20px
}

.mind-elixir .node-menu .nm-fontsize-container {
display: flex;
justify-content: space-around;
margin-bottom: 20px
}

.mind-elixir .node-menu .nm-fontsize-container div {
height: 36px;
width: 36px;
display: flex;
align-items: center;
justify-content: center;
box-shadow: 0 1px 2px #0003;
background-color: #fff;
color: tomato;
border-radius: 100%
}

.mind-elixir .node-menu .nm-fontcolor-container {
margin-bottom: 10px
}

.mind-elixir .node-menu input,
.mind-elixir .node-menu textarea {
background: var(--input-background-color);
border: 1px solid var(--panel-border-color);
border-radius: var(--bs-border-radius);
color: var(--main-color);
padding: 5px;
margin: 10px 0;
width: 100%;
box-sizing: border-box;
}

.mind-elixir .node-menu textarea {
resize: none
}

.mind-elixir .node-menu .split6 {
display: inline-block;
width: 16.66%;
margin-bottom: 5px
}

.mind-elixir .node-menu .palette {
border-radius: 100%;
width: 21px;
height: 21px;
border: 1px solid #edf1f2;
margin: auto
}

.mind-elixir .node-menu .nmenu-selected,
.mind-elixir .node-menu .palette:hover {
box-shadow: tomato 0 0 0 2px;
background-color: #c7e9fa
}

.mind-elixir .node-menu .size-selected {
background-color: tomato !important;
border-color: tomato;
fill: #fff;
color: #fff
}

.mind-elixir .node-menu .size-selected svg {
color: #fff
}

.mind-elixir .node-menu .bof {
text-align: center
}

.mind-elixir .node-menu .bof span {
display: inline-block;
font-size: 14px;
border-radius: 4px;
padding: 2px 5px
}

.mind-elixir .node-menu .bof .selected {
background-color: tomato;
color: #fff
}
</style>
</div>
30 changes: 26 additions & 4 deletions app/src/main/kotlin/eu/fliegendewurst/triliumdroid/Cache.kt
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,13 @@ object Cache {
} else {
null
}
val branch = Branch(branchId, lastId, parentId, notePosition, prefix, expanded)
l.add(branch)
if (branches.containsKey(branchId)) {
l.add(branches[branchId]!!)
} else {
val branch =
Branch(branchId, lastId, parentId, notePosition, prefix, expanded)
l.add(branch)
}
if (parentId == "none") {
return l
}
Expand Down Expand Up @@ -411,7 +416,10 @@ object Cache {
}

fun moveBranch(branch: Branch, newParent: Branch, newPosition: Int) {
Log.i(TAG, "moving branch ${branch.id} to new parent ${newParent.note}, pos: ${branch.position} -> $newPosition")
Log.i(
TAG,
"moving branch ${branch.id} to new parent ${newParent.note}, pos: ${branch.position} -> $newPosition"
)
if (branch.parentNote == newParent.note && branch.position == newPosition) {
return // no action needed
}
Expand Down Expand Up @@ -752,12 +760,26 @@ object Cache {
}
parentNote.children!!.add(b)
} else {
Log.d(TAG, "failed to find $parentNoteId in ${notes.size} notes")
Log.w(TAG, "getTreeData() failed to find $parentNoteId in ${notes.size} notes")
}
}
}
db!!.rawQuery(
"SELECT notes.noteId, attributes.value " +
"FROM attributes INNER JOIN notes USING (noteId) INNER JOIN branches USING (noteId) WHERE notes.isDeleted = 0 AND attributes.isDeleted = 0 AND attributes.name = 'iconClass' AND attributes.type = 'label' $filter",
arrayOf()
).use {
while (it.moveToNext()) {
val noteId = it.getString(0)
val noteIcon = it.getString(1)
notes[noteId]!!.icon = noteIcon
}
}
}

/**
* Use [Note.computeChildren] instead
*/
fun getChildren(noteId: String) {
getTreeData("AND (branches.parentNoteId = \"${noteId}\" OR branches.noteId = \"${noteId}\")")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package eu.fliegendewurst.triliumdroid.activity.main
import eu.fliegendewurst.triliumdroid.fragment.NoteEditFragment
import eu.fliegendewurst.triliumdroid.data.Branch
import eu.fliegendewurst.triliumdroid.data.Note
import eu.fliegendewurst.triliumdroid.fragment.NavigationFragment
import eu.fliegendewurst.triliumdroid.fragment.NoteMapFragment

/**
Expand Down Expand Up @@ -93,3 +94,25 @@ class NoteMapItem(val note: Note?) : HistoryItem() {
override fun setBranch(branch: Branch) {
}
}

class NavigationItem(private val note: Note, private var branchStart: Branch) : HistoryItem() {
override fun restore(activity: MainActivity): Boolean {
val frag = NavigationFragment()
activity.showFragment(frag, true)
frag.showFor(note, branchStart)
return true
}

override fun noteId(): String {
return note.id
}

override fun branch(): Branch {
return branchStart
}

override fun setBranch(branch: Branch) {
// not exactly applicable
branchStart = branch
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,14 @@ import eu.fliegendewurst.triliumdroid.data.Relation
import eu.fliegendewurst.triliumdroid.databinding.ActivityMainBinding
import eu.fliegendewurst.triliumdroid.dialog.AskForNameDialog
import eu.fliegendewurst.triliumdroid.dialog.ConfigureFabsDialog
import eu.fliegendewurst.triliumdroid.dialog.ConfigureFabsDialog.NOTE_NAVIGATION
import eu.fliegendewurst.triliumdroid.dialog.CreateNewNoteDialog
import eu.fliegendewurst.triliumdroid.dialog.JumpToNoteDialog
import eu.fliegendewurst.triliumdroid.dialog.ModifyLabelsDialog
import eu.fliegendewurst.triliumdroid.dialog.ModifyRelationsDialog
import eu.fliegendewurst.triliumdroid.dialog.SelectNoteDialog
import eu.fliegendewurst.triliumdroid.fragment.EmptyFragment
import eu.fliegendewurst.triliumdroid.fragment.NavigationFragment
import eu.fliegendewurst.triliumdroid.fragment.NoteMapFragment
import eu.fliegendewurst.triliumdroid.fragment.NoteRelatedFragment
import eu.fliegendewurst.triliumdroid.fragment.NoteTreeFragment
Expand Down Expand Up @@ -467,6 +469,10 @@ class MainActivity : AppCompatActivity() {
JumpToNoteDialog.showDialog(this)
}

NOTE_NAVIGATION -> {
showNoteNavigation()
}

"editNote" -> {
doMenuAction(R.id.action_edit)
}
Expand All @@ -489,6 +495,18 @@ class MainActivity : AppCompatActivity() {
}
}

private fun showNoteNavigation() {
val item = noteHistory.last()
var note = Cache.getNote(item.noteId())!!
var branch = item.branch() ?: note.branches[0]
if (note.computeChildren().isEmpty()) {
note = Cache.getNote(branch.parentNote)!!
branch = note.branches[0] // TODO
}
noteHistory.add(NavigationItem(note, branch))
noteHistory.last().restore(this)
}

private var loadedNoteId: String? = null

override fun onPause() {
Expand Down Expand Up @@ -880,6 +898,7 @@ class MainActivity : AppCompatActivity() {
}

private fun scrollTreeToBranch(branch: Branch) {
Log.d(TAG, "scrolling to ${branch.cachedTreeIndex}")
val pos = branch.cachedTreeIndex ?: return
val frag = supportFragmentManager.findFragmentByTag("f0") ?: return
((frag as NoteTreeFragment).binding.treeList.layoutManager!! as LinearLayoutManager).scrollToPositionWithOffset(
Expand All @@ -895,8 +914,7 @@ class MainActivity : AppCompatActivity() {
private fun refreshTitle(note: Note?) {
Log.d(TAG, "refreshing title")
binding.toolbarTitle.text = note?.title ?: "(nothing loaded)"
binding.toolbarIcon.text =
Icon.getUnicodeCharacter(note?.getLabel("iconClass") ?: "bx bx-file-blank")
binding.toolbarIcon.text = Icon.getUnicodeCharacter(note?.icon() ?: "bx bx-file-blank")
}

fun refreshWidgets(noteContent: Note) {
Expand Down Expand Up @@ -1134,7 +1152,7 @@ class MainActivity : AppCompatActivity() {
}

fun load(note: Note, branch: Branch?) {
Log.i(TAG, "loading note ${note.id}")
Log.i(TAG, "loading note ${note.id} @ branch ${branch?.id}")
prefs.edit().putString(LAST_NOTE, note.id).apply()
// make sure note is visible
val path = Cache.getNotePath(note.id)
Expand Down Expand Up @@ -1177,7 +1195,7 @@ class MainActivity : AppCompatActivity() {
private fun getFragment(): Fragment {
val hostFragment =
supportFragmentManager.findFragmentById(R.id.fragment_container)
return if (hostFragment is NoteFragment || hostFragment is NoteEditFragment || hostFragment is EmptyFragment || hostFragment is NoteMapFragment) {
return if (hostFragment is NoteFragment || hostFragment is NoteEditFragment || hostFragment is EmptyFragment || hostFragment is NoteMapFragment || hostFragment is NavigationFragment) {
hostFragment
} else {
val frags = (hostFragment as NavHostFragment).childFragmentManager.fragments
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class Note(
private var inheritedLabels: List<Label>? = null
private var inheritedRelations: List<Relation>? = null
var children: SortedSet<Branch>? = null
var icon: String? = null

/**
* Note clones for this note.
Expand All @@ -32,6 +33,10 @@ class Note(
*/
var incomingRelations: List<Relation>? = null

fun icon(): String {
return icon ?: "bx bx-file-blank"
}

fun getLabel(name: String): String? {
return getLabelValue(name)?.value
}
Expand Down Expand Up @@ -207,4 +212,4 @@ class Note(
override fun toString(): String {
return "Note($id)"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@ import eu.fliegendewurst.triliumdroid.activity.SetupActivity
import eu.fliegendewurst.triliumdroid.util.ListAdapter

object ConfigureFabsDialog {
const val NOTE_NAVIGATION: String = "noteNavigation"

/**
* See [eu.fliegendewurst.triliumdroid.activity.main.MainActivity.performAction].
* See [eu.fliegendewurst.triliumdroid.activity.main.MainActivity.performAction],
* and string array "fabs"
*/
val actions = listOf(
"showNoteTree",
"jumpToNote",
NOTE_NAVIGATION,
"editNote",
"shareNote",
"deleteNote",
Expand All @@ -38,6 +42,10 @@ object ConfigureFabsDialog {
setPref(prefs, action, left = false, right = true, show = false)
}

NOTE_NAVIGATION -> {
setPref(prefs, action, left = false, right = false, show = false)
}

else -> {
setPref(prefs, action, left = false, right = false, show = true)
}
Expand Down Expand Up @@ -191,6 +199,10 @@ object ConfigureFabsDialog {
return R.drawable.bx_send
}

NOTE_NAVIGATION -> {
return R.drawable.bx_globe_alt
}

"editNote" -> {
return R.drawable.bx_edit_alt
}
Expand Down
Loading

0 comments on commit 08e0136

Please sign in to comment.