diff --git a/lib/pages/statuses_page.dart b/lib/pages/statuses_page.dart index bcc4703..ef8a1ba 100644 --- a/lib/pages/statuses_page.dart +++ b/lib/pages/statuses_page.dart @@ -11,14 +11,11 @@ class StatusesPage extends StatefulWidget { } class _StatusesPageState extends State { + bool? isWhatsappInstalled; + bool? isPermissionGranted; List _statusFiles = []; Future> getFileList() async { - final bool permissionStatus = - await Permission.manageExternalStorage.isGranted; - if (!permissionStatus) { - await Permission.manageExternalStorage.request(); - } Directory dir = Directory( '/storage/emulated/0/Android/media/com.whatsapp/Whatsapp/Media/.Statuses/'); List fileList = await dir.list(recursive: false).toList(); @@ -34,6 +31,23 @@ class _StatusesPageState extends State { } Future _init() async { + isPermissionGranted = await Permission.manageExternalStorage.isGranted; + if (!isPermissionGranted!) { + await Permission.manageExternalStorage.request(); + } + + if (!await Directory( + '/storage/emulated/0/Android/media/com.whatsapp/Whatsapp/Media/.Statuses/') + .exists()) { + setState(() { + isWhatsappInstalled = false; + }); + return; + } + setState(() { + isWhatsappInstalled = true; + }); + List statusFiles = await getFileList(); setState(() { _statusFiles = statusFiles; @@ -42,24 +56,98 @@ class _StatusesPageState extends State { @override Widget build(BuildContext context) { - return Scaffold( - body: RefreshIndicator( - backgroundColor: Theme.of(context).scaffoldBackgroundColor, - onRefresh: _init, - child: GridView.count( - crossAxisCount: 2, - children: [ - for (int i = 0; i < _statusFiles.length; i++) - Padding( - padding: const EdgeInsets.all(8.0), - child: WhatsappStatusCard( - elevation: 10, - file: _statusFiles[i], + if (isWhatsappInstalled == null || isPermissionGranted == null) { + return const Center( + child: CircularProgressIndicator(), + ); + } else if (!isPermissionGranted!) { + return GestureDetector( + onTap: () async { + PermissionStatus permissionStatus = + await Permission.manageExternalStorage.request(); + if (permissionStatus == PermissionStatus.granted) { + await _init(); + } + }, + child: Center( + child: Padding( + padding: const EdgeInsets.all(20), + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + const Icon(Icons.error_outline, size: 64), + const Text( + 'Permission denied', + style: TextStyle(fontSize: 32), + ), + const Text( + 'Please toggle that "Allow access to manage all files" to ON after clicking this', + textAlign: TextAlign.center, ), + Text( + 'tap anywhere to give permission', + style: TextStyle( + color: Theme.of(context).primaryColor, + ), + ), + ], + ), + ), + ), + ); + } else if (isWhatsappInstalled == false) { + return Scaffold( + body: Center( + child: Column( + mainAxisSize: MainAxisSize.min, + children: const [ + Icon( + Icons.error, + size: 200, ), - ], + Text( + 'Looks like whatsapp is not installed', + style: TextStyle(fontSize: 20), + ), + Text('if you have whatsapp pls report this issue'), + Text('at Settings > About > Report a bug'), + ], + ), + ), + ); + } else { + return Scaffold( + body: RefreshIndicator( + backgroundColor: Theme.of(context).scaffoldBackgroundColor, + onRefresh: _init, + child: _statusFiles.isEmpty + ? Column( + mainAxisAlignment: MainAxisAlignment.center, + children: const [ + Icon( + Icons.explore_rounded, + size: 200, + ), + Center( + child: Text('Looks like there is nothing'), + ), + ], + ) + : GridView.count( + crossAxisCount: 2, + children: [ + for (int i = 0; i < _statusFiles.length; i++) + Padding( + padding: const EdgeInsets.all(8.0), + child: WhatsappStatusCard( + elevation: 10, + file: _statusFiles[i], + ), + ), + ], + ), ), - ), - ); + ); + } } } diff --git a/lib/provider/theme_provider.dart b/lib/provider/theme_provider.dart index dc80cda..0111c15 100644 --- a/lib/provider/theme_provider.dart +++ b/lib/provider/theme_provider.dart @@ -6,7 +6,7 @@ class ThemeProvider extends ChangeNotifier { _init(); } - ThemeMode themeMode = ThemeMode.dark; + ThemeMode themeMode = ThemeMode.system; late final SharedPreferences _prefs; void _init() async { diff --git a/pubspec.yaml b/pubspec.yaml index 76caed9..05b1e57 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -16,7 +16,7 @@ publish_to: "none" # Remove this line if you wish to publish to pub.dev # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. # Read more about iOS versioning at # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html -version: 1.0.3+2 +version: 1.0.3+3 environment: sdk: ">=2.16.2 <3.0.0"