mirror of
https://github.com/hamaluik/timecop.git
synced 2025-05-18 01:06:17 +08:00
change db export button into import/export menu
This commit is contained in:
1
android/settings_aar.gradle
Normal file
1
android/settings_aar.gradle
Normal file
@ -0,0 +1 @@
|
|||||||
|
include ':app'
|
@ -80,6 +80,8 @@ class FluentL10NProvider extends L10NProvider {
|
|||||||
@override
|
@override
|
||||||
String get export => _bundle.format("export", errors: _errors);
|
String get export => _bundle.format("export", errors: _errors);
|
||||||
@override
|
@override
|
||||||
|
String get import => _bundle.format("import", errors: _errors) ?? "import";
|
||||||
|
@override
|
||||||
String get filter => _bundle.format("filter", errors: _errors);
|
String get filter => _bundle.format("filter", errors: _errors);
|
||||||
@override
|
@override
|
||||||
String get from => _bundle.format("from", errors: _errors);
|
String get from => _bundle.format("from", errors: _errors);
|
||||||
|
@ -33,6 +33,7 @@ abstract class L10NProvider {
|
|||||||
String get editTimer;
|
String get editTimer;
|
||||||
String get endTime;
|
String get endTime;
|
||||||
String get export;
|
String get export;
|
||||||
|
String get import;
|
||||||
String get filter;
|
String get filter;
|
||||||
String get from;
|
String get from;
|
||||||
String get logoSemantics;
|
String get logoSemantics;
|
||||||
|
@ -14,7 +14,6 @@
|
|||||||
|
|
||||||
import 'dart:collection';
|
import 'dart:collection';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
import 'package:path/path.dart' as p;
|
|
||||||
import 'package:flutter_share/flutter_share.dart';
|
import 'package:flutter_share/flutter_share.dart';
|
||||||
import 'package:csv/csv.dart';
|
import 'package:csv/csv.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
@ -24,7 +23,6 @@ import 'package:flutter_slidable/flutter_slidable.dart';
|
|||||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
import 'package:path_provider/path_provider.dart';
|
import 'package:path_provider/path_provider.dart';
|
||||||
import 'package:sqflite/sqflite.dart';
|
|
||||||
import 'package:timecop/blocs/projects/projects_bloc.dart';
|
import 'package:timecop/blocs/projects/projects_bloc.dart';
|
||||||
import 'package:timecop/blocs/settings/bloc.dart';
|
import 'package:timecop/blocs/settings/bloc.dart';
|
||||||
import 'package:timecop/blocs/settings/settings_bloc.dart';
|
import 'package:timecop/blocs/settings/settings_bloc.dart';
|
||||||
@ -34,6 +32,7 @@ import 'package:timecop/l10n.dart';
|
|||||||
import 'package:timecop/models/project.dart';
|
import 'package:timecop/models/project.dart';
|
||||||
import 'package:timecop/models/project_description_pair.dart';
|
import 'package:timecop/models/project_description_pair.dart';
|
||||||
import 'package:timecop/models/timer_entry.dart';
|
import 'package:timecop/models/timer_entry.dart';
|
||||||
|
import 'package:timecop/screens/export/components/ExportMenu.dart';
|
||||||
|
|
||||||
class ExportScreen extends StatefulWidget {
|
class ExportScreen extends StatefulWidget {
|
||||||
ExportScreen({Key key}) : super(key: key);
|
ExportScreen({Key key}) : super(key: key);
|
||||||
@ -84,38 +83,7 @@ class _ExportScreenState extends State<ExportScreen> {
|
|||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: Text(L10N.of(context).tr.export),
|
title: Text(L10N.of(context).tr.export),
|
||||||
actions: <Widget>[
|
actions: <Widget>[
|
||||||
IconButton(
|
ExportMenu(dateFormat: _dateFormat, scaffoldKey: _scaffoldKey),
|
||||||
icon: Icon(FontAwesomeIcons.database),
|
|
||||||
onPressed: () async {
|
|
||||||
var databasesPath = await getDatabasesPath();
|
|
||||||
var dbPath = p.join(databasesPath, 'timecop.db');
|
|
||||||
|
|
||||||
try {
|
|
||||||
// on android, copy it somewhere where it can be shared
|
|
||||||
if (Platform.isAndroid) {
|
|
||||||
Directory directory = await getExternalStorageDirectory();
|
|
||||||
File copiedDB = await File(dbPath)
|
|
||||||
.copy(p.join(directory.path, "timecop.db"));
|
|
||||||
dbPath = copiedDB.path;
|
|
||||||
}
|
|
||||||
await FlutterShare.shareFile(
|
|
||||||
title: L10N
|
|
||||||
.of(context)
|
|
||||||
.tr
|
|
||||||
.timeCopDatabase(_dateFormat.format(DateTime.now())),
|
|
||||||
filePath: dbPath);
|
|
||||||
} on Exception catch (e) {
|
|
||||||
_scaffoldKey.currentState.showSnackBar(SnackBar(
|
|
||||||
backgroundColor: Theme.of(context).errorColor,
|
|
||||||
content: Text(
|
|
||||||
e.toString(),
|
|
||||||
style: TextStyle(color: Colors.white),
|
|
||||||
),
|
|
||||||
duration: Duration(seconds: 5),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
},
|
|
||||||
)
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
body: ListView(
|
body: ListView(
|
||||||
|
103
lib/screens/export/components/ExportMenu.dart
Normal file
103
lib/screens/export/components/ExportMenu.dart
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
// Copyright 2020 Kenton Hamaluik
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
import 'dart:collection';
|
||||||
|
import 'dart:io';
|
||||||
|
import 'package:path/path.dart' as p;
|
||||||
|
import 'package:flutter_share/flutter_share.dart';
|
||||||
|
import 'package:csv/csv.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:flutter_datetime_picker/flutter_datetime_picker.dart';
|
||||||
|
import 'package:flutter_slidable/flutter_slidable.dart';
|
||||||
|
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||||
|
import 'package:intl/intl.dart';
|
||||||
|
import 'package:path_provider/path_provider.dart';
|
||||||
|
import 'package:sqflite/sqflite.dart';
|
||||||
|
import 'package:timecop/l10n.dart';
|
||||||
|
|
||||||
|
enum ExportMenuItem {
|
||||||
|
import,
|
||||||
|
export,
|
||||||
|
}
|
||||||
|
|
||||||
|
class ExportMenu extends StatelessWidget {
|
||||||
|
final DateFormat dateFormat;
|
||||||
|
final GlobalKey<ScaffoldState> scaffoldKey;
|
||||||
|
const ExportMenu({Key key, this.dateFormat, this.scaffoldKey})
|
||||||
|
: super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return PopupMenuButton<ExportMenuItem>(
|
||||||
|
key: Key("exportMenuButton"),
|
||||||
|
icon: Icon(FontAwesomeIcons.database),
|
||||||
|
onSelected: (ExportMenuItem item) async {
|
||||||
|
switch (item) {
|
||||||
|
case ExportMenuItem.import:
|
||||||
|
break;
|
||||||
|
case ExportMenuItem.export:
|
||||||
|
var databasesPath = await getDatabasesPath();
|
||||||
|
var dbPath = p.join(databasesPath, 'timecop.db');
|
||||||
|
|
||||||
|
try {
|
||||||
|
// on android, copy it somewhere where it can be shared
|
||||||
|
if (Platform.isAndroid) {
|
||||||
|
Directory directory = await getExternalStorageDirectory();
|
||||||
|
File copiedDB = await File(dbPath)
|
||||||
|
.copy(p.join(directory.path, "timecop.db"));
|
||||||
|
dbPath = copiedDB.path;
|
||||||
|
}
|
||||||
|
await FlutterShare.shareFile(
|
||||||
|
title: L10N
|
||||||
|
.of(context)
|
||||||
|
.tr
|
||||||
|
.timeCopDatabase(dateFormat.format(DateTime.now())),
|
||||||
|
filePath: dbPath);
|
||||||
|
} on Exception catch (e) {
|
||||||
|
scaffoldKey.currentState.showSnackBar(SnackBar(
|
||||||
|
backgroundColor: Theme.of(context).errorColor,
|
||||||
|
content: Text(
|
||||||
|
e.toString(),
|
||||||
|
style: TextStyle(color: Colors.white),
|
||||||
|
),
|
||||||
|
duration: Duration(seconds: 5),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
itemBuilder: (BuildContext context) {
|
||||||
|
return [
|
||||||
|
PopupMenuItem(
|
||||||
|
key: Key("exportMenuImport"),
|
||||||
|
child: ListTile(
|
||||||
|
leading: Icon(FontAwesomeIcons.fileImport),
|
||||||
|
title: Text(L10N.of(context).tr.import),
|
||||||
|
),
|
||||||
|
value: ExportMenuItem.import,
|
||||||
|
),
|
||||||
|
PopupMenuItem(
|
||||||
|
key: Key("exportMenuExport"),
|
||||||
|
child: ListTile(
|
||||||
|
leading: Icon(FontAwesomeIcons.fileExport),
|
||||||
|
title: Text(L10N.of(context).tr.export),
|
||||||
|
),
|
||||||
|
value: ExportMenuItem.export,
|
||||||
|
),
|
||||||
|
];
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user