mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-29 02:07:39 +08:00
FolderListing: Show the actual folders
Also don't load hidden folders
This commit is contained in:
@ -1,6 +1,7 @@
|
|||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
import 'package:fimber/fimber.dart';
|
import 'package:fimber/fimber.dart';
|
||||||
import 'package:gitjournal/note.dart';
|
import 'package:gitjournal/note.dart';
|
||||||
|
import 'package:gitjournal/note_folder.dart';
|
||||||
|
|
||||||
class AppState {
|
class AppState {
|
||||||
//
|
//
|
||||||
@ -27,6 +28,7 @@ class AppState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
List<Note> notes = [];
|
List<Note> notes = [];
|
||||||
|
NoteFolder noteFolder;
|
||||||
|
|
||||||
AppState(SharedPreferences pref) {
|
AppState(SharedPreferences pref) {
|
||||||
localGitRepoConfigured = pref.getBool("localGitRepoConfigured") ?? false;
|
localGitRepoConfigured = pref.getBool("localGitRepoConfigured") ?? false;
|
||||||
|
@ -57,14 +57,19 @@ class NoteFolder {
|
|||||||
|
|
||||||
// FIXME: This asynchronously loads everything. Maybe it should just list them, and the individual entities
|
// FIXME: This asynchronously loads everything. Maybe it should just list them, and the individual entities
|
||||||
// should be loaded as required?
|
// should be loaded as required?
|
||||||
Future<void> load() async {
|
// FIXME: This should not reconstruct the Notes or NotesFolders once constructed.
|
||||||
|
Future<void> loadRecursively() async {
|
||||||
final dir = Directory(folderPath);
|
final dir = Directory(folderPath);
|
||||||
|
entities = [];
|
||||||
|
|
||||||
var lister = dir.list(recursive: false, followLinks: false);
|
var lister = dir.list(recursive: false, followLinks: false);
|
||||||
await for (var fsEntity in lister) {
|
await for (var fsEntity in lister) {
|
||||||
if (fsEntity is Directory) {
|
if (fsEntity is Directory) {
|
||||||
var subFolder = NoteFolder(fsEntity.path);
|
var subFolder = NoteFolder(fsEntity.path);
|
||||||
await subFolder.load();
|
if (subFolder.name.startsWith('.')) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
await subFolder.loadRecursively();
|
||||||
|
|
||||||
var noteFSEntity = NoteFSEntity(this, folder: subFolder);
|
var noteFSEntity = NoteFSEntity(this, folder: subFolder);
|
||||||
entities.add(noteFSEntity);
|
entities.add(noteFSEntity);
|
||||||
|
@ -2,29 +2,21 @@ import 'package:flutter/material.dart';
|
|||||||
|
|
||||||
import 'package:gitjournal/widgets/app_bar_menu_button.dart';
|
import 'package:gitjournal/widgets/app_bar_menu_button.dart';
|
||||||
import 'package:gitjournal/widgets/app_drawer.dart';
|
import 'package:gitjournal/widgets/app_drawer.dart';
|
||||||
|
import 'package:gitjournal/state_container.dart';
|
||||||
|
|
||||||
|
import 'package:gitjournal/note_folder.dart';
|
||||||
|
|
||||||
typedef void ParentSelectChanged(bool isSelected);
|
typedef void ParentSelectChanged(bool isSelected);
|
||||||
|
|
||||||
/// # Tree View
|
|
||||||
///
|
|
||||||
/// Creates a tree view widget. The widget is a List View with a [List] of
|
|
||||||
/// [Parent] widgets. The [TreeView] is nested inside a [Scrollbar] if the
|
|
||||||
/// [TreeView.hasScrollBar] property is true.
|
|
||||||
class TreeView extends StatelessWidget {
|
class TreeView extends StatelessWidget {
|
||||||
final List<Parent> parentList;
|
final List<Parent> parentList;
|
||||||
final bool hasScrollBar;
|
|
||||||
|
|
||||||
TreeView({
|
TreeView({
|
||||||
this.parentList = const <Parent>[],
|
this.parentList = const <Parent>[],
|
||||||
this.hasScrollBar = false,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return hasScrollBar ? Scrollbar(child: _getTreeList()) : _getTreeList();
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _getTreeList() {
|
|
||||||
return ListView.builder(
|
return ListView.builder(
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
return parentList[index];
|
return parentList[index];
|
||||||
@ -130,28 +122,11 @@ class ChildList extends StatelessWidget {
|
|||||||
class FolderListingScreen extends StatelessWidget {
|
class FolderListingScreen extends StatelessWidget {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
final container = StateContainer.of(context);
|
||||||
|
final appState = container.appState;
|
||||||
|
|
||||||
var treeView = TreeView(
|
var treeView = TreeView(
|
||||||
parentList: [
|
parentList: _constructParentList(appState.noteFolder.entities),
|
||||||
Parent(
|
|
||||||
parent: _buildFolderTile("Desktop"),
|
|
||||||
childList: ChildList(
|
|
||||||
children: <Widget>[
|
|
||||||
Parent(
|
|
||||||
parent: _buildFolderTile('documents'),
|
|
||||||
childList: ChildList(
|
|
||||||
children: <Widget>[
|
|
||||||
_buildFolderTile('Resume.docx'),
|
|
||||||
_buildFolderTile('Billing-Info.docx'),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
_buildFolderTile('MeetingReport.xls'),
|
|
||||||
_buildFolderTile('MeetingReport.pdf'),
|
|
||||||
_buildFolderTile('Demo.zip'),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
);
|
||||||
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
@ -164,6 +139,43 @@ class FolderListingScreen extends StatelessWidget {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<Parent> _constructParentList(List<NoteFSEntity> entities) {
|
||||||
|
var parents = <Parent>[];
|
||||||
|
entities.forEach((entity) {
|
||||||
|
if (entity.isNote) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var folder = entity.folder;
|
||||||
|
var p = Parent(
|
||||||
|
parent: _buildFolderTile(folder.name),
|
||||||
|
childList: _constructChildList(folder.entities),
|
||||||
|
);
|
||||||
|
|
||||||
|
parents.add(p);
|
||||||
|
});
|
||||||
|
return parents;
|
||||||
|
}
|
||||||
|
|
||||||
|
ChildList _constructChildList(List<NoteFSEntity> entities) {
|
||||||
|
var children = <Widget>[];
|
||||||
|
entities.forEach((entity) {
|
||||||
|
if (entity.isNote) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var folder = entity.folder;
|
||||||
|
var p = Parent(
|
||||||
|
parent: _buildFolderTile(folder.name),
|
||||||
|
childList: _constructChildList(folder.entities),
|
||||||
|
);
|
||||||
|
|
||||||
|
children.add(p);
|
||||||
|
});
|
||||||
|
|
||||||
|
return ChildList(children: children);
|
||||||
|
}
|
||||||
|
|
||||||
Widget _buildFolderTile(String name) {
|
Widget _buildFolderTile(String name) {
|
||||||
// FIXME: The trailing icon should change based on if it is expanded or not
|
// FIXME: The trailing icon should change based on if it is expanded or not
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ import 'package:gitjournal/analytics.dart';
|
|||||||
import 'package:gitjournal/apis/git_migration.dart';
|
import 'package:gitjournal/apis/git_migration.dart';
|
||||||
import 'package:gitjournal/appstate.dart';
|
import 'package:gitjournal/appstate.dart';
|
||||||
import 'package:gitjournal/note.dart';
|
import 'package:gitjournal/note.dart';
|
||||||
|
import 'package:gitjournal/note_folder.dart';
|
||||||
import 'package:gitjournal/note_fileName.dart';
|
import 'package:gitjournal/note_fileName.dart';
|
||||||
import 'package:gitjournal/storage/git_storage.dart';
|
import 'package:gitjournal/storage/git_storage.dart';
|
||||||
import 'package:path/path.dart' as p;
|
import 'package:path/path.dart' as p;
|
||||||
@ -56,6 +57,7 @@ class StateContainerState extends State<StateContainer> {
|
|||||||
dirName: appState.localGitRepoPath,
|
dirName: appState.localGitRepoPath,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
appState.noteFolder = NoteFolder(noteRepo.notesBasePath);
|
||||||
|
|
||||||
// Just a fail safe
|
// Just a fail safe
|
||||||
if (!appState.remoteGitRepoConfigured) {
|
if (!appState.remoteGitRepoConfigured) {
|
||||||
@ -77,9 +79,17 @@ class StateContainerState extends State<StateContainer> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<List<Note>> _loadNotes() async {
|
||||||
|
await appState.noteFolder.loadRecursively();
|
||||||
|
var notes = appState.noteFolder.getAllNotes();
|
||||||
|
notes.sort((a, b) => b.compareTo(a));
|
||||||
|
|
||||||
|
return notes;
|
||||||
|
}
|
||||||
|
|
||||||
void _loadNotesFromDisk() {
|
void _loadNotesFromDisk() {
|
||||||
Fimber.d("Loading Notes From Disk");
|
Fimber.d("Loading Notes From Disk");
|
||||||
noteRepo.listNotes().then((loadedNotes) {
|
_loadNotes().then((loadedNotes) {
|
||||||
setState(() {
|
setState(() {
|
||||||
appState.notes = loadedNotes;
|
appState.notes = loadedNotes;
|
||||||
|
|
||||||
@ -114,7 +124,7 @@ class StateContainerState extends State<StateContainer> {
|
|||||||
await noteRepo.sync();
|
await noteRepo.sync();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var loadedNotes = await noteRepo.listNotes();
|
var loadedNotes = await _loadNotes();
|
||||||
setState(() {
|
setState(() {
|
||||||
appState.notes = loadedNotes;
|
appState.notes = loadedNotes;
|
||||||
});
|
});
|
||||||
@ -161,17 +171,6 @@ class StateContainerState extends State<StateContainer> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
String _getGitDir(BuildContext context) {
|
|
||||||
var state = StateContainer.of(context).appState;
|
|
||||||
if (state.remoteGitRepoConfigured) {
|
|
||||||
return state.remoteGitRepoFolderName;
|
|
||||||
} else {
|
|
||||||
return state.localGitRepoPath;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
void undoRemoveNote(Note note, int index) {
|
void undoRemoveNote(Note note, int index) {
|
||||||
setState(() {
|
setState(() {
|
||||||
appState.notes.insert(index, note);
|
appState.notes.insert(index, note);
|
||||||
@ -226,6 +225,7 @@ class StateContainerState extends State<StateContainer> {
|
|||||||
baseDirectory: appState.gitBaseDirectory,
|
baseDirectory: appState.gitBaseDirectory,
|
||||||
dirName: appState.remoteGitRepoFolderName,
|
dirName: appState.remoteGitRepoFolderName,
|
||||||
);
|
);
|
||||||
|
appState.noteFolder = NoteFolder(noteRepo.notesBasePath);
|
||||||
|
|
||||||
await _persistConfig();
|
await _persistConfig();
|
||||||
_loadNotesFromDisk();
|
_loadNotesFromDisk();
|
||||||
|
@ -4,7 +4,6 @@ import 'package:fimber/fimber.dart';
|
|||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:gitjournal/apis/git.dart';
|
import 'package:gitjournal/apis/git.dart';
|
||||||
import 'package:gitjournal/note.dart';
|
import 'package:gitjournal/note.dart';
|
||||||
import 'package:gitjournal/note_folder.dart';
|
|
||||||
import 'package:gitjournal/settings.dart';
|
import 'package:gitjournal/settings.dart';
|
||||||
import 'package:path/path.dart' as p;
|
import 'package:path/path.dart' as p;
|
||||||
|
|
||||||
@ -73,15 +72,6 @@ class GitNoteRepository {
|
|||||||
return _addNote(note, "Edited Journal Entry");
|
return _addNote(note, "Edited Journal Entry");
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<List<Note>> listNotes() async {
|
|
||||||
var noteFolder = NoteFolder(notesBasePath);
|
|
||||||
await noteFolder.load();
|
|
||||||
var notes = noteFolder.getAllNotes();
|
|
||||||
notes.sort((a, b) => b.compareTo(a));
|
|
||||||
|
|
||||||
return notes;
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<bool> sync() async {
|
Future<bool> sync() async {
|
||||||
try {
|
try {
|
||||||
await _gitRepo.pull();
|
await _gitRepo.pull();
|
||||||
|
Reference in New Issue
Block a user