mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-29 02:07:39 +08:00
GitSetup: Add a screen to choose a subFolder
This is only shows if there are subFolders with '.md' files. This feature is super important for me as it allows me to finally dogfood this app and use it This patch just adds the screen, but the subFolder selection currently doesn't do anything.
This commit is contained in:
@ -13,6 +13,7 @@ class AppState {
|
|||||||
bool onBoardingCompleted = false;
|
bool onBoardingCompleted = false;
|
||||||
|
|
||||||
// FIXME: Make final
|
// FIXME: Make final
|
||||||
|
/// This is the directory where all the git repos are stored
|
||||||
String gitBaseDirectory = "";
|
String gitBaseDirectory = "";
|
||||||
|
|
||||||
bool isLoadingFromDisk;
|
bool isLoadingFromDisk;
|
||||||
|
76
lib/screens/githostsetup_folder.dart
Normal file
76
lib/screens/githostsetup_folder.dart
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
import 'githostsetup_button.dart';
|
||||||
|
|
||||||
|
class GitHostSetupFolderPage extends StatelessWidget {
|
||||||
|
final List<String> folders;
|
||||||
|
final Function rootFolderSelected;
|
||||||
|
final Function subFolderSelected;
|
||||||
|
|
||||||
|
GitHostSetupFolderPage({
|
||||||
|
@required this.folders,
|
||||||
|
@required this.rootFolderSelected,
|
||||||
|
@required this.subFolderSelected,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
var columns = Column(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: <Widget>[
|
||||||
|
Text(
|
||||||
|
'Would you like to store your journal entries in an existing folder?',
|
||||||
|
style: Theme.of(context).textTheme.title,
|
||||||
|
),
|
||||||
|
SizedBox(height: 32.0),
|
||||||
|
FolderListWidget(
|
||||||
|
folders: folders,
|
||||||
|
onSelected: subFolderSelected,
|
||||||
|
),
|
||||||
|
SizedBox(height: 16.0),
|
||||||
|
GitHostSetupButton(
|
||||||
|
text: "Ignore",
|
||||||
|
onPressed: rootFolderSelected,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
|
return Center(
|
||||||
|
child: SingleChildScrollView(
|
||||||
|
child: columns,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIXME: This needs to be made much much prettier!
|
||||||
|
class FolderListWidget extends StatelessWidget {
|
||||||
|
final List<String> folders;
|
||||||
|
final Function onSelected;
|
||||||
|
|
||||||
|
FolderListWidget({
|
||||||
|
@required this.folders,
|
||||||
|
@required this.onSelected,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
var buttons = <Widget>[];
|
||||||
|
for (var folderName in folders) {
|
||||||
|
var button = GitHostSetupButton(
|
||||||
|
text: folderName,
|
||||||
|
onPressed: () {
|
||||||
|
onSelected(folderName);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
buttons.add(button);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Column(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: buttons,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -14,6 +14,7 @@ import 'githostsetup_autoconfigure.dart';
|
|||||||
import 'githostsetup_button.dart';
|
import 'githostsetup_button.dart';
|
||||||
import 'githostsetup_clone.dart';
|
import 'githostsetup_clone.dart';
|
||||||
import 'githostsetup_clone_url.dart';
|
import 'githostsetup_clone_url.dart';
|
||||||
|
import 'githostsetup_folder.dart';
|
||||||
import 'githostsetup_sshkey.dart';
|
import 'githostsetup_sshkey.dart';
|
||||||
|
|
||||||
class GitHostSetupScreen extends StatefulWidget {
|
class GitHostSetupScreen extends StatefulWidget {
|
||||||
@ -38,17 +39,16 @@ class GitHostSetupScreenState extends State<GitHostSetupScreen> {
|
|||||||
PageChoice1.Unknown,
|
PageChoice1.Unknown,
|
||||||
];
|
];
|
||||||
|
|
||||||
GitHostType _gitHostType = GitHostType.Unknown;
|
var _gitHostType = GitHostType.Unknown;
|
||||||
|
|
||||||
var _gitCloneUrl = "";
|
var _gitCloneUrl = "";
|
||||||
String gitCloneErrorMessage = "";
|
var gitCloneErrorMessage = "";
|
||||||
|
var publicKey = "";
|
||||||
String publicKey = "";
|
var _subFolders = <String>[];
|
||||||
|
|
||||||
var pageController = PageController();
|
var pageController = PageController();
|
||||||
int _currentPageIndex = 0;
|
int _currentPageIndex = 0;
|
||||||
|
|
||||||
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
|
final _scaffoldKey = GlobalKey<ScaffoldState>();
|
||||||
|
|
||||||
Widget _buildPage(BuildContext context, int pos) {
|
Widget _buildPage(BuildContext context, int pos) {
|
||||||
print("_buildPage " + pos.toString());
|
print("_buildPage " + pos.toString());
|
||||||
@ -186,11 +186,35 @@ class GitHostSetupScreenState extends State<GitHostSetupScreen> {
|
|||||||
assert(false);
|
assert(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(_pageChoice[0] != PageChoice0.CustomProvider);
|
|
||||||
|
|
||||||
if (pos == 4) {
|
if (pos == 4) {
|
||||||
|
if (_pageChoice[0] == PageChoice0.CustomProvider) {
|
||||||
|
return GitHostSetupFolderPage(
|
||||||
|
folders: _subFolders,
|
||||||
|
subFolderSelected: _subFolderSelected,
|
||||||
|
rootFolderSelected: _finish,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (_pageChoice[1] == PageChoice1.Manual) {
|
if (_pageChoice[1] == PageChoice1.Manual) {
|
||||||
return GitHostSetupGitClone(errorMessage: gitCloneErrorMessage);
|
return GitHostSetupGitClone(errorMessage: gitCloneErrorMessage);
|
||||||
|
} else if (_pageChoice[1] == PageChoice1.Auto) {
|
||||||
|
return GitHostSetupFolderPage(
|
||||||
|
folders: _subFolders,
|
||||||
|
subFolderSelected: _subFolderSelected,
|
||||||
|
rootFolderSelected: _finish,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
assert(_pageChoice[0] != PageChoice0.CustomProvider);
|
||||||
|
|
||||||
|
if (pos == 5) {
|
||||||
|
if (_pageChoice[1] == PageChoice1.Manual) {
|
||||||
|
return GitHostSetupFolderPage(
|
||||||
|
folders: _subFolders,
|
||||||
|
subFolderSelected: _subFolderSelected,
|
||||||
|
rootFolderSelected: _finish,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -371,14 +395,21 @@ class GitHostSetupScreenState extends State<GitHostSetupScreen> {
|
|||||||
);
|
);
|
||||||
gitCloneErrorMessage = error;
|
gitCloneErrorMessage = error;
|
||||||
});
|
});
|
||||||
} else {
|
return;
|
||||||
getAnalytics().logEvent(
|
|
||||||
name: "onboarding_complete",
|
|
||||||
parameters: <String, dynamic>{},
|
|
||||||
);
|
|
||||||
Navigator.pop(context);
|
|
||||||
this.widget.onCompletedFunction();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<String> subFolders = await _getSubFoldersWithMdFiles(basePath);
|
||||||
|
if (subFolders.isEmpty) {
|
||||||
|
print("Found no subfolders with md files");
|
||||||
|
_finish();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setState(() {
|
||||||
|
_subFolders = subFolders;
|
||||||
|
_pageCount += 1;
|
||||||
|
_nextPage();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Future _removeExistingClone(String baseDirPath) async {
|
Future _removeExistingClone(String baseDirPath) async {
|
||||||
@ -391,6 +422,54 @@ class GitHostSetupScreenState extends State<GitHostSetupScreen> {
|
|||||||
await baseDir.create();
|
await baseDir.create();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<List<String>> _getSubFoldersWithMdFiles(String baseDirPath) async {
|
||||||
|
var subFolders = <String>[];
|
||||||
|
|
||||||
|
var gitRootDir = Directory(p.join(baseDirPath, "journal"));
|
||||||
|
var lister = gitRootDir.list(recursive: false);
|
||||||
|
await for (var fileEntity in lister) {
|
||||||
|
if (fileEntity is! Directory) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
Directory dir = fileEntity;
|
||||||
|
var hasMdFiles = await _hasMdFiles(dir);
|
||||||
|
if (hasMdFiles) {
|
||||||
|
subFolders.add(p.basename(dir.path));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return subFolders;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<bool> _hasMdFiles(Directory dir) async {
|
||||||
|
var lister = dir.list(recursive: false);
|
||||||
|
await for (var fileEntity in lister) {
|
||||||
|
if (fileEntity is! File) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fileEntity.path.toLowerCase().endsWith('.md')) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void _finish() {
|
||||||
|
getAnalytics().logEvent(
|
||||||
|
name: "onboarding_complete",
|
||||||
|
parameters: <String, dynamic>{},
|
||||||
|
);
|
||||||
|
Navigator.pop(context);
|
||||||
|
this.widget.onCompletedFunction();
|
||||||
|
}
|
||||||
|
|
||||||
|
void _subFolderSelected(String folder) {
|
||||||
|
_finish();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class GitHostChoicePage extends StatelessWidget {
|
class GitHostChoicePage extends StatelessWidget {
|
||||||
|
Reference in New Issue
Block a user