浏览代码

Add an option to hide from recents

Vishnu Mohandas 4 年之前
父节点
当前提交
ea28fd046a
共有 4 个文件被更改,包括 135 次插入27 次删除
  1. 13 0
      lib/core/configuration.dart
  2. 114 27
      lib/ui/settings_page.dart
  3. 7 0
      pubspec.lock
  4. 1 0
      pubspec.yaml

+ 13 - 0
lib/core/configuration.dart

@@ -43,6 +43,7 @@ class Configuration {
   static const keyAttributesKey = "key_attributes";
   static const keyShouldBackupOverMobileData = "should_backup_over_mobile_data";
   static const keyShouldShowLockScreen = "should_show_lock_screen";
+  static const keyShouldHideFromRecents = "should_hide_from_recents";
   static const lastTempFolderClearTimeKey = "last_temp_folder_clear_time";
 
   SharedPreferences _preferences;
@@ -349,4 +350,16 @@ class Configuration {
   Future<void> setShouldShowLockScreen(bool value) {
     return _preferences.setBool(keyShouldShowLockScreen, value);
   }
+
+  bool shouldHideFromRecents() {
+    if (_preferences.containsKey(keyShouldHideFromRecents)) {
+      return _preferences.getBool(keyShouldHideFromRecents);
+    } else {
+      return false;
+    }
+  }
+
+  Future<void> setShouldHideFromRecents(bool value) {
+    return _preferences.setBool(keyShouldHideFromRecents, value);
+  }
 }

+ 114 - 27
lib/ui/settings_page.dart

@@ -7,6 +7,7 @@ import 'package:flutter/material.dart';
 import 'package:flutter/widgets.dart';
 import 'package:flutter_email_sender/flutter_email_sender.dart';
 import 'package:flutter_sodium/flutter_sodium.dart';
+import 'package:flutter_windowmanager/flutter_windowmanager.dart';
 import 'package:package_info_plus/package_info_plus.dart';
 import 'package:path_provider/path_provider.dart';
 import 'package:photos/core/constants.dart';
@@ -284,35 +285,121 @@ class _SecuritySectionWidgetState extends State<SecuritySectionWidget> {
 
   @override
   Widget build(BuildContext context) {
-    return Container(
-      child: Column(
-        children: [
-          SettingsSectionTitle("security"),
-          Container(
-            height: 36,
-            child: Row(
-              mainAxisAlignment: MainAxisAlignment.spaceBetween,
-              children: [
-                Text("lockscreen"),
-                Switch(
-                  value: Configuration.instance.shouldShowLockScreen(),
-                  onChanged: (value) async {
-                    AppLock.of(context).disable();
-                    final result = await requestAuthentication();
-                    if (result) {
-                      AppLock.of(context).setEnabled(value);
-                      Configuration.instance.setShouldShowLockScreen(value);
-                      setState(() {});
-                    } else {
-                      AppLock.of(context).setEnabled(
-                          Configuration.instance.shouldShowLockScreen());
-                    }
-                  },
-                ),
-              ],
+    final List<Widget> children = [];
+    children.addAll([
+      SettingsSectionTitle("security"),
+      Container(
+        height: 36,
+        child: Row(
+          mainAxisAlignment: MainAxisAlignment.spaceBetween,
+          children: [
+            Text("lockscreen"),
+            Switch(
+              value: Configuration.instance.shouldShowLockScreen(),
+              onChanged: (value) async {
+                AppLock.of(context).disable();
+                final result = await requestAuthentication();
+                if (result) {
+                  AppLock.of(context).setEnabled(value);
+                  Configuration.instance.setShouldShowLockScreen(value);
+                  setState(() {});
+                } else {
+                  AppLock.of(context).setEnabled(
+                      Configuration.instance.shouldShowLockScreen());
+                }
+              },
             ),
+          ],
+        ),
+      ),
+    ]);
+    if (Platform.isAndroid) {
+      children.addAll([
+        Padding(padding: EdgeInsets.all(4)),
+        Divider(height: 4),
+        Padding(padding: EdgeInsets.all(4)),
+        Container(
+          height: 36,
+          child: Row(
+            mainAxisAlignment: MainAxisAlignment.spaceBetween,
+            children: [
+              Text("hide from recents"),
+              Switch(
+                value: Configuration.instance.shouldHideFromRecents(),
+                onChanged: (value) async {
+                  if (value) {
+                    AlertDialog alert = AlertDialog(
+                      title: Text("hide from recents?"),
+                      content: SingleChildScrollView(
+                        child: Column(
+                          mainAxisAlignment: MainAxisAlignment.start,
+                          crossAxisAlignment: CrossAxisAlignment.start,
+                          children: [
+                            Text(
+                              "hiding from the task switcher will prevent you from taking screenshots in this app.",
+                              style: TextStyle(
+                                height: 1.5,
+                              ),
+                            ),
+                            Padding(padding: EdgeInsets.all(8)),
+                            Text(
+                              "are you sure?",
+                              style: TextStyle(
+                                height: 1.5,
+                              ),
+                            ),
+                          ],
+                        ),
+                      ),
+                      actions: [
+                        TextButton(
+                          child:
+                              Text("no", style: TextStyle(color: Colors.white)),
+                          onPressed: () {
+                            Navigator.of(context, rootNavigator: true)
+                                .pop('dialog');
+                          },
+                        ),
+                        TextButton(
+                          child: Text("yes",
+                              style: TextStyle(
+                                  color: Colors.white.withOpacity(0.8))),
+                          onPressed: () async {
+                            Navigator.of(context, rootNavigator: true)
+                                .pop('dialog');
+                            await Configuration.instance
+                                .setShouldHideFromRecents(true);
+                            await FlutterWindowManager.addFlags(
+                                FlutterWindowManager.FLAG_SECURE);
+                            setState(() {});
+                          },
+                        ),
+                      ],
+                    );
+
+                    showDialog(
+                      context: context,
+                      builder: (BuildContext context) {
+                        return alert;
+                      },
+                    );
+                  } else {
+                    await Configuration.instance
+                        .setShouldHideFromRecents(false);
+                    await FlutterWindowManager.clearFlags(
+                        FlutterWindowManager.FLAG_SECURE);
+                    setState(() {});
+                  }
+                },
+              ),
+            ],
           ),
-        ],
+        ),
+      ]);
+    }
+    return Container(
+      child: Column(
+        children: children,
       ),
     );
   }

+ 7 - 0
pubspec.lock

@@ -338,6 +338,13 @@ packages:
       url: "https://pub.dartlang.org"
     source: hosted
     version: "0.3.11"
+  flutter_windowmanager:
+    dependency: "direct main"
+    description:
+      name: flutter_windowmanager
+      url: "https://pub.dartlang.org"
+    source: hosted
+    version: "0.0.2"
   fluttercontactpicker:
     dependency: "direct main"
     description:

+ 1 - 0
pubspec.yaml

@@ -78,6 +78,7 @@ dependencies:
     git: https://github.com/deakjahn/huge_listview.git
   package_info_plus: ^0.6.4
   local_auth: ^1.1.0
+  flutter_windowmanager: ^0.0.2
 
 dev_dependencies:
   flutter_test: