mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-09-15 16:03:34 +08:00

This reverts commit 303192d9d575b26a77a00f7a62212f310ec1e329. This reverts commit cd9d128b47ed523036f7ae1232ec7adcf04ed8a9. GitJournal is used by non-English speakers (a lot in China and Russia) and while we don't support those languages completely, we do support them a little bit. I don't want to loose this functionality. It would be better for us to fix the bug in intl.
156 lines
3.7 KiB
Dart
156 lines
3.7 KiB
Dart
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:gitjournal/core/sorting_mode.dart';
|
|
import 'package:gitjournal/folder_views/list_view.dart';
|
|
|
|
import 'package:intl/intl.dart';
|
|
|
|
import 'package:gitjournal/core/note.dart';
|
|
import 'package:gitjournal/core/notes_folder.dart';
|
|
|
|
enum StandardViewHeader {
|
|
TitleOrFileName,
|
|
FileName,
|
|
TitleGenerated,
|
|
}
|
|
|
|
class StandardView extends StatelessWidget {
|
|
final NoteSelectedFunction noteSelectedFunction;
|
|
final NotesFolder folder;
|
|
final String emptyText;
|
|
|
|
final StandardViewHeader headerType;
|
|
final bool showSummary;
|
|
|
|
static final _dateFormat = DateFormat('dd MMM, yyyy');
|
|
|
|
StandardView({
|
|
@required this.folder,
|
|
@required this.noteSelectedFunction,
|
|
@required this.emptyText,
|
|
@required this.headerType,
|
|
@required this.showSummary,
|
|
});
|
|
|
|
@override
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return FolderListView(
|
|
folder: folder,
|
|
emptyText: emptyText,
|
|
noteTileBuilder: _buildRow,
|
|
);
|
|
}
|
|
|
|
Widget _buildRow(BuildContext context, Note note) {
|
|
var textTheme = Theme.of(context).textTheme;
|
|
|
|
String title;
|
|
switch (headerType) {
|
|
case StandardViewHeader.TitleOrFileName:
|
|
title = note.title;
|
|
if (title == null || title.isEmpty) {
|
|
title = note.fileName;
|
|
}
|
|
break;
|
|
|
|
case StandardViewHeader.FileName:
|
|
title = note.fileName;
|
|
break;
|
|
|
|
case StandardViewHeader.TitleGenerated:
|
|
title = note.title;
|
|
if (title == null || title.isEmpty) {
|
|
title = note.summary;
|
|
}
|
|
break;
|
|
|
|
default:
|
|
assert(false, "StandardViewHeader must not be null");
|
|
}
|
|
|
|
Widget titleWidget = Text(
|
|
title,
|
|
style: textTheme.headline6,
|
|
overflow: TextOverflow.ellipsis,
|
|
);
|
|
Widget trailing = Container();
|
|
|
|
DateTime date;
|
|
var sortingMode = folder.config.sortingMode;
|
|
if (sortingMode == SortingMode.Modified) {
|
|
date = note.modified;
|
|
} else if (sortingMode == SortingMode.Created) {
|
|
date = note.created;
|
|
}
|
|
|
|
if (date != null) {
|
|
var dateStr = _dateFormat.format(date);
|
|
trailing = Text(dateStr, style: textTheme.caption);
|
|
}
|
|
|
|
var titleRow = Row(
|
|
children: <Widget>[Expanded(child: titleWidget), trailing],
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
crossAxisAlignment: CrossAxisAlignment.baseline,
|
|
textBaseline: TextBaseline.alphabetic,
|
|
);
|
|
|
|
ListTile tile;
|
|
if (showSummary) {
|
|
var summary = <Widget>[
|
|
const SizedBox(height: 8.0),
|
|
Text(
|
|
note.summary + '\n', // no minLines option
|
|
maxLines: 3,
|
|
overflow: TextOverflow.ellipsis,
|
|
style: textTheme.bodyText2,
|
|
),
|
|
];
|
|
|
|
tile = ListTile(
|
|
isThreeLine: true,
|
|
title: titleRow,
|
|
subtitle: Column(
|
|
children: summary,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
),
|
|
onTap: () => noteSelectedFunction(note),
|
|
);
|
|
} else {
|
|
tile = ListTile(
|
|
isThreeLine: false,
|
|
title: titleRow,
|
|
onTap: () => noteSelectedFunction(note),
|
|
);
|
|
}
|
|
|
|
var dc = Theme.of(context).dividerColor;
|
|
var divider = Container(
|
|
height: 1.0,
|
|
child: Divider(color: dc.withOpacity(dc.opacity / 3)),
|
|
);
|
|
|
|
if (!showSummary) {
|
|
return Column(
|
|
children: <Widget>[
|
|
divider,
|
|
tile,
|
|
divider,
|
|
],
|
|
);
|
|
}
|
|
|
|
return Column(
|
|
children: <Widget>[
|
|
divider,
|
|
Padding(
|
|
padding: const EdgeInsets.only(top: 16.0, bottom: 16.0),
|
|
child: tile,
|
|
),
|
|
divider,
|
|
],
|
|
);
|
|
}
|
|
}
|