Add share button for items and public folders to inventory

Closes #9
This commit is contained in:
Nutcake 2023-10-12 18:33:04 +02:00
parent fcd34d4fb1
commit fca7ffda93
7 changed files with 61 additions and 11 deletions

View file

@ -218,8 +218,12 @@ class Record {
bool get isRoot => this == _rootRecord; bool get isRoot => this == _rootRecord;
bool get isLink => assetUri.startsWith("resrec");
bool get isItem => assetUri.startsWith("resdb");
String get linkRecordId { String get linkRecordId {
if (!assetUri.startsWith("resrec")) { if (!isLink) {
throw "Record is not a link."; throw "Record is not a link.";
} }

View file

@ -2,6 +2,9 @@ import 'dart:async';
import 'package:cached_network_image/cached_network_image.dart'; import 'package:cached_network_image/cached_network_image.dart';
import 'package:collection/collection.dart'; import 'package:collection/collection.dart';
import 'package:flutter/material.dart';
import 'package:photo_view/photo_view.dart';
import 'package:provider/provider.dart';
import 'package:recon/auxiliary.dart'; import 'package:recon/auxiliary.dart';
import 'package:recon/clients/inventory_client.dart'; import 'package:recon/clients/inventory_client.dart';
import 'package:recon/models/inventory/resonite_directory.dart'; import 'package:recon/models/inventory/resonite_directory.dart';
@ -9,9 +12,6 @@ import 'package:recon/models/records/record.dart';
import 'package:recon/widgets/default_error_widget.dart'; import 'package:recon/widgets/default_error_widget.dart';
import 'package:recon/widgets/inventory/object_inventory_tile.dart'; import 'package:recon/widgets/inventory/object_inventory_tile.dart';
import 'package:recon/widgets/inventory/path_inventory_tile.dart'; import 'package:recon/widgets/inventory/path_inventory_tile.dart';
import 'package:flutter/material.dart';
import 'package:photo_view/photo_view.dart';
import 'package:provider/provider.dart';
class InventoryBrowser extends StatefulWidget { class InventoryBrowser extends StatefulWidget {
const InventoryBrowser({super.key}); const InventoryBrowser({super.key});
@ -130,13 +130,20 @@ class _InventoryBrowserState extends State<InventoryBrowser> with AutomaticKeepA
maxCrossAxisExtent: 256, maxCrossAxisExtent: 256,
childAspectRatio: 3.5, childAspectRatio: 3.5,
crossAxisSpacing: 0, crossAxisSpacing: 0,
mainAxisSpacing: 0), mainAxisSpacing: 0,
),
itemBuilder: (context, index) { itemBuilder: (context, index) {
final record = paths[index]; final record = paths[index];
return PathInventoryTile( return PathInventoryTile(
record: record, record: record,
selected: iClient.isRecordSelected(record),
onLongPress: () async {
iClient.toggleRecordSelected(record);
},
onTap: iClient.isAnyRecordSelected onTap: iClient.isAnyRecordSelected
? () {} ? () {
iClient.toggleRecordSelected(record);
}
: () async { : () async {
try { try {
await iClient.navigateTo(record); await iClient.navigateTo(record);

View file

@ -1,13 +1,14 @@
import 'dart:isolate'; import 'dart:isolate';
import 'dart:ui'; import 'dart:ui';
import 'package:recon/auxiliary.dart';
import 'package:recon/clients/inventory_client.dart';
import 'package:file_picker/file_picker.dart'; import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_downloader/flutter_downloader.dart'; import 'package:flutter_downloader/flutter_downloader.dart';
import 'package:path/path.dart'; import 'package:path/path.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:recon/auxiliary.dart';
import 'package:recon/clients/inventory_client.dart';
import 'package:share_plus/share_plus.dart';
class InventoryBrowserAppBar extends StatefulWidget { class InventoryBrowserAppBar extends StatefulWidget {
const InventoryBrowserAppBar({super.key}); const InventoryBrowserAppBar({super.key});
@ -71,6 +72,15 @@ class _InventoryBrowserAppBarState extends State<InventoryBrowserAppBar> {
icon: const Icon(Icons.close), icon: const Icon(Icons.close),
), ),
actions: [ actions: [
if (iClient.selectedRecordCount == 1 &&
(iClient.selectedRecords.firstOrNull?.isLink == true ||
iClient.selectedRecords.firstOrNull?.isItem == true))
IconButton(
onPressed: () {
Share.share(iClient.selectedRecords.first.assetUri);
},
icon: const Icon(Icons.share),
),
if (iClient.onlyFilesSelected) if (iClient.onlyFilesSelected)
IconButton( IconButton(
onPressed: () async { onPressed: () async {

View file

@ -504,6 +504,14 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "1.9.1" version: "1.9.1"
mime:
dependency: transitive
description:
name: mime
sha256: e4ff8e8564c03f255408decd16e7899da1733852a9110a58fe6d1b817684a63e
url: "https://pub.dev"
source: hosted
version: "1.0.4"
nested: nested:
dependency: transitive dependency: transitive
description: description:
@ -752,6 +760,22 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "0.27.7" version: "0.27.7"
share_plus:
dependency: "direct main"
description:
name: share_plus
sha256: "6cec740fa0943a826951223e76218df002804adb588235a8910dc3d6b0654e11"
url: "https://pub.dev"
source: hosted
version: "7.1.0"
share_plus_platform_interface:
dependency: transitive
description:
name: share_plus_platform_interface
sha256: "357412af4178d8e11d14f41723f80f12caea54cf0d5cd29af9dcdab85d58aea7"
url: "https://pub.dev"
source: hosted
version: "3.3.0"
sky_engine: sky_engine:
dependency: transitive dependency: transitive
description: flutter description: flutter

View file

@ -63,6 +63,7 @@ dependencies:
permission_handler: ^10.2.0 permission_handler: ^10.2.0
flutter_downloader: ^1.10.4 flutter_downloader: ^1.10.4
flutter_cube: ^0.1.1 flutter_cube: ^0.1.1
share_plus: ^7.1.0
dev_dependencies: dev_dependencies:
flutter_test: flutter_test:

View file

@ -10,6 +10,7 @@
#include <flutter_secure_storage_windows/flutter_secure_storage_windows_plugin.h> #include <flutter_secure_storage_windows/flutter_secure_storage_windows_plugin.h>
#include <permission_handler_windows/permission_handler_windows_plugin.h> #include <permission_handler_windows/permission_handler_windows_plugin.h>
#include <record_windows/record_windows_plugin_c_api.h> #include <record_windows/record_windows_plugin_c_api.h>
#include <share_plus/share_plus_windows_plugin_c_api.h>
#include <url_launcher_windows/url_launcher_windows.h> #include <url_launcher_windows/url_launcher_windows.h>
void RegisterPlugins(flutter::PluginRegistry* registry) { void RegisterPlugins(flutter::PluginRegistry* registry) {
@ -21,6 +22,8 @@ void RegisterPlugins(flutter::PluginRegistry* registry) {
registry->GetRegistrarForPlugin("PermissionHandlerWindowsPlugin")); registry->GetRegistrarForPlugin("PermissionHandlerWindowsPlugin"));
RecordWindowsPluginCApiRegisterWithRegistrar( RecordWindowsPluginCApiRegisterWithRegistrar(
registry->GetRegistrarForPlugin("RecordWindowsPluginCApi")); registry->GetRegistrarForPlugin("RecordWindowsPluginCApi"));
SharePlusWindowsPluginCApiRegisterWithRegistrar(
registry->GetRegistrarForPlugin("SharePlusWindowsPluginCApi"));
UrlLauncherWindowsRegisterWithRegistrar( UrlLauncherWindowsRegisterWithRegistrar(
registry->GetRegistrarForPlugin("UrlLauncherWindows")); registry->GetRegistrarForPlugin("UrlLauncherWindows"));
} }

View file

@ -7,6 +7,7 @@ list(APPEND FLUTTER_PLUGIN_LIST
flutter_secure_storage_windows flutter_secure_storage_windows
permission_handler_windows permission_handler_windows
record_windows record_windows
share_plus
url_launcher_windows url_launcher_windows
) )