Skip to content

Commit

Permalink
new icon for linked sheet and auto delete linked file
Browse files Browse the repository at this point in the history
  • Loading branch information
kkdlau committed Aug 4, 2021
1 parent 4eb57c5 commit 1eb5106
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 9 deletions.
18 changes: 15 additions & 3 deletions lib/action_sheet/action_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ class ActionSheet {
if (actions == null) actions = [];
}

/// Removes the sheet from file system.
static removeFromDisk(String alias) async {
String path = await Utils.fullPathToSheet(alias);
var file = File(path);
if (file.existsSync()) {
file.delete();
Utils.prefs.remove(alias);
}
}

/// Returns [ActionDescription] list in Plain Map foramt.
List<Map<String, String>> getPlainActionList() {
List<Map<String, String>> actionList = [];
Expand Down Expand Up @@ -74,11 +84,13 @@ class ActionSheet {
/// If the sheet is linked to another video file (i.e. [linked] is true),
/// then inside SharedPreferences the path will be used as a key to mark this sheet as linked.
Future<File> saveTo(String path) async {
File f = File(path);

if (this.linked) {
SharedPreferences prefs = await SharedPreferences.getInstance();
prefs.setBool(path, true);
Utils.prefs.setBool(f.alias, true);
}
return File(path).writeAsString(json.encode(this.toMap()));

return f.writeAsString(json.encode(this.toMap()));
}

/// Convert the whole action sheet into subtitle format.
Expand Down
5 changes: 4 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:Tracker/define.dart';
import 'package:Tracker/guideline.dart';
import 'package:Tracker/utils.dart';
import 'package:Tracker/video_recording/video_recording_page.dart';
import 'package:camera/camera.dart';
import 'package:flutter/material.dart';
Expand All @@ -10,10 +11,12 @@ List<CameraDescription> cameras = [];
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();

await Guideline.loadInstructions(INSTRUCTION_PATH);
// await Guideline.loadInstructions(INSTRUCTION_PATH);

// SystemChrome.setEnabledSystemUIOverlays([]);

await Utils.initialize();

try {
cameras = await availableCameras();
} on CameraException catch (e) {
Expand Down
24 changes: 24 additions & 0 deletions lib/recording_manager/comfirm_delete_dialog.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class ConfirmDeleteDialog extends StatelessWidget {
const ConfirmDeleteDialog({Key key}) : super(key: key);

@override
Widget build(BuildContext context) {
return CupertinoAlertDialog(
title: Text('Delete File'),
content: Text('The linked sheet will be also deleted'),
actions: [
CupertinoButton(
child: Text('OK'),
onPressed: () => Navigator.of(context).pop(true)),
CupertinoTheme(
data: CupertinoThemeData(primaryColor: Colors.red),
child: CupertinoButton(
child: Text('NO'),
onPressed: () => Navigator.of(context).pop(false)))
],
);
}
}
6 changes: 4 additions & 2 deletions lib/recording_manager/recording_manager_page.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:io';
import 'dart:typed_data';

import 'package:Tracker/action_sheet/action_sheet.dart';
import 'package:Tracker/action_video_player/action_video_player.dart';
import 'package:Tracker/file_manager/file_manager_page.dart';
import 'package:Tracker/file_manager/info_card/card_config.dart';
Expand Down Expand Up @@ -88,7 +89,7 @@ class _RecordingManagerPageState extends State<RecordingManagerPage> {
break;
case INFO_CARD_ACTION.DELETE:
// TODO: delete video with sheet record
removeVideoFile(file);
removeVideoAndLinkedFile(file);
break;
case INFO_CARD_ACTION.SELECT:
Navigator.push(context, MaterialPageRoute(builder: (_) {
Expand All @@ -109,8 +110,9 @@ class _RecordingManagerPageState extends State<RecordingManagerPage> {
}
}

void removeVideoFile(File f) {
void removeVideoAndLinkedFile(File f) {
_listNode.currentState.removeFile(f);
ActionSheet.removeFromDisk(f.alias); // also delete the linked file
}

@override
Expand Down
31 changes: 28 additions & 3 deletions lib/sheet_manager/sheet_magaer_page.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'dart:io';
import 'dart:math';

import 'package:Tracker/action_sheet/action_sheet.dart';
import 'package:Tracker/action_sheet/action_sheet_decoder.dart';
Expand All @@ -7,10 +8,12 @@ import 'package:Tracker/file_manager/file_manager_page.dart';
import 'package:Tracker/file_manager/info_card/card_config.dart';
import 'package:Tracker/file_manager/info_card/info_card.dart';
import 'package:Tracker/sheet_editor/sheet_editor.dart';
import 'package:Tracker/utils.dart';
import 'package:Tracker/video_recording/video_recording_page.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:share/share.dart';
import 'package:shared_preferences/shared_preferences.dart';

class SheetManagerPage extends StatefulWidget {
const SheetManagerPage({Key key}) : super(key: key);
Expand All @@ -34,9 +37,9 @@ class _SheetManagerPageState extends State<SheetManagerPage> {
config: const CardConfiguration(),
heading: Padding(
padding: const EdgeInsets.only(right: 15.0, left: 15.0),
child: Icon(Icons.description,
color: Colors.lightGreen,
size: Theme.of(context).textTheme.headline4.fontSize),
child: Utils.prefs.containsKey(f.alias)
? linkedDocumentIcon(Colors.lightBlue)
: documentIcon(Colors.lightGreen),
),
onActionSelected: (actionType) {
infoCardPressedHandler(actionType, f);
Expand All @@ -46,6 +49,28 @@ class _SheetManagerPageState extends State<SheetManagerPage> {
);
}

/// Returns a colored document icon with a link logo.
Widget linkedDocumentIcon(Color color) {
return Stack(
children: [
documentIcon(color),
Transform.translate(
offset: const Offset(15, -10),
child: Transform.rotate(
angle: pi / 4,
child: Icon(Icons.link,
color: Theme.of(context).textTheme.headline6.color,
size: Theme.of(context).textTheme.headline5.fontSize),
),
),
],
);
}

/// Returns a document icon with given [color].
Widget documentIcon(Color color) => Icon(Icons.description,
color: color, size: Theme.of(context).textTheme.headline4.fontSize);

@override
Widget build(BuildContext context) {
return FileManagerPage(
Expand Down
7 changes: 7 additions & 0 deletions lib/utils.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import 'dart:io';

import 'package:path_provider/path_provider.dart';
import 'package:shared_preferences/shared_preferences.dart';

import 'define.dart';

class Utils {
static SharedPreferences prefs;

static Future<void> initialize() async {
prefs = await SharedPreferences.getInstance();
}

/// Returns path of Application Document Directory.
static Future<String> getDocumentRootPath() async {
return (await getApplicationDocumentsDirectory()).path;
Expand Down

0 comments on commit 1eb5106

Please sign in to comment.