Skip to content

Commit

Permalink
Merge pull request #12 from Fernthedev/feat/sidebar-navigation
Browse files Browse the repository at this point in the history
Sidebar navigation
  • Loading branch information
Fernthedev authored Apr 3, 2024
2 parents 8ae09ec + 71fa519 commit a99b6bf
Show file tree
Hide file tree
Showing 8 changed files with 344 additions and 168 deletions.
24 changes: 16 additions & 8 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:desktop_adb_file_browser/pages/browser.dart';
import 'package:desktop_adb_file_browser/pages/devices.dart';
import 'package:desktop_adb_file_browser/pages/logger.dart';
import 'package:desktop_adb_file_browser/pages/main/browser.dart';
import 'package:desktop_adb_file_browser/pages/main/devices.dart';
import 'package:desktop_adb_file_browser/pages/main/logger.dart';
import 'package:desktop_adb_file_browser/pages/main_page.dart';
import 'package:desktop_adb_file_browser/src/pigeon_impl.dart';
import 'package:flex_color_scheme/flex_color_scheme.dart';
import 'package:flutter/foundation.dart';
Expand All @@ -13,10 +14,16 @@ import 'package:trace/trace.dart';
import 'package:path/path.dart' as path;

final routes = RouteMap(routes: {
'/': (_) => const Redirect('/devices'),

'/devices': (_) =>
const MaterialPage(key: ValueKey("devices"), child: DevicesPage()),
'/': (_) => const MaterialPage(
key: ValueKey("main"),
child: MainPage(),
),

'/devices': (_) => const MaterialPage(
key: ValueKey("devices"),
child: DevicesPage(
canNavigate: true,
)),

'/browser/:device/:path': (info) => MaterialPage(
key: const ValueKey("browser"),
Expand Down Expand Up @@ -45,6 +52,8 @@ void main() async {
yield LicenseEntryWithLineBreaks(['google_fonts'], license);
});

WidgetsFlutterBinding.ensureInitialized();

final ConsoleLogger logger = ConsoleLogger(
filter: DefaultLogFilter(
LogLevel.verbose,
Expand All @@ -68,7 +77,6 @@ void main() async {
} catch (e) {
Trace.error("Suffered error while setting up file logger: $e");
}
WidgetsFlutterBinding.ensureInitialized();
final token = ServicesBinding.rootIsolateToken;
BackgroundIsolateBinaryMessenger.ensureInitialized(token!);

Expand Down
45 changes: 22 additions & 23 deletions lib/pages/browser.dart → lib/pages/main/browser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import 'package:desktop_adb_file_browser/utils/storage.dart';
import 'package:desktop_adb_file_browser/widgets/browser/file_data.dart';
import 'package:desktop_adb_file_browser/widgets/browser/file_table.dart';
import 'package:desktop_adb_file_browser/widgets/browser/file_widget.dart';
import 'package:desktop_adb_file_browser/widgets/browser/upload_file.dart';
import 'package:desktop_adb_file_browser/widgets/progress_snackbar.dart';
import 'package:desktop_adb_file_browser/widgets/shortcuts.dart';
import 'package:desktop_adb_file_browser/widgets/watchers.dart';
import 'package:desktop_drop/desktop_drop.dart';
Expand Down Expand Up @@ -111,18 +111,21 @@ class _DeviceBrowserPageState extends State<DeviceBrowserPage> {
),
);

var conditionalExitButton =
Routemaster.of(context).history.canGoBack ? exitButton : null;

return Focus(
autofocus: true,
canRequestFocus: false,
descendantsAreFocusable: true,
skipTraversal: true,
onKey: _onKeyHandler,
onKeyEvent: _onKeyHandler,
child: DefaultTabController(
initialIndex: 0,
length: 2,
child: Scaffold(
appBar: AppBar(
elevation: 0.8,
elevation: 2.8,
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
title: _AppBarActions(
Expand All @@ -131,10 +134,11 @@ class _DeviceBrowserPageState extends State<DeviceBrowserPage> {
serial: widget.serial,
onUpload: _uploadFiles,
),
leading: exitButton,
leading: conditionalExitButton,
automaticallyImplyLeading: true,
actions: [listViewButton],
),
body: _buildBody(context),
body: _buildBody(),
bottomNavigationBar: SizedBox(
height: Theme.of(context).buttonTheme.height,
child: _PathBreadCumbs(
Expand All @@ -147,7 +151,7 @@ class _DeviceBrowserPageState extends State<DeviceBrowserPage> {
);
}

MultiSplitViewTheme _buildBody(BuildContext context) {
MultiSplitViewTheme _buildBody() {
return MultiSplitViewTheme(
data: MultiSplitViewThemeData(dividerThickness: 5.5),
child: MultiSplitView(
Expand All @@ -158,7 +162,7 @@ class _DeviceBrowserPageState extends State<DeviceBrowserPage> {
serial: widget.serial,
onWatchAdd: onWatchAdd,
),
Center(child: _fileListContainer(context))
Center(child: _fileListContainer())
],
dividerBuilder:
(axis, index, resizable, dragging, highlighted, themeData) =>
Expand All @@ -185,7 +189,7 @@ class _DeviceBrowserPageState extends State<DeviceBrowserPage> {
return KeyEventResult.ignored;
}

DropTarget _fileListContainer(BuildContext context) {
DropTarget _fileListContainer() {
return DropTarget(
onDragDone: (detail) => _uploadFiles(detail.files.map((e) => e.path)),
onDragEntered: (detail) {
Expand Down Expand Up @@ -226,8 +230,9 @@ class _DeviceBrowserPageState extends State<DeviceBrowserPage> {
files: list,
key: ValueKey(list),
filterController: _filterController,
builder: (context, filteredFiles) =>
_viewAsListMode ? _viewAsList(filteredFiles) : _viewAsGrid(filteredFiles),
builder: (context, filteredFiles) => _viewAsListMode
? _viewAsList(filteredFiles)
: _viewAsGrid(filteredFiles),
);
}

Expand Down Expand Up @@ -300,22 +305,16 @@ class _DeviceBrowserPageState extends State<DeviceBrowserPage> {
return Adb.uploadFile(widget.serial, path, dest);
});

// this is so scuffed
// I do this to automatically update the snack bar progress
var tasksDone = 0;
var notifier = ValueNotifier<double>(0);

Future.forEach(tasks, (e) async {
tasksDone++;
notifier.value = tasksDone / tasks.length;
});

// Snack bar
var snackBar = ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: UploadingFilesWidget(
progressIndications: notifier,
taskAmount: tasks.length,
content: Padding(
padding: const EdgeInsets.all(8.0),
child: ProgressSnackbar(
futures: tasks,
stringBuilder: (futureCount, futureRemaining) =>
"Uploading files! ${(futureCount - futureRemaining) / futureCount * 100}%",
),
),
duration: const Duration(days: 365), // year old snackbar
width: 680.0, // Width of the SnackBar.
Expand Down
34 changes: 26 additions & 8 deletions lib/pages/devices.dart → lib/pages/main/devices.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import 'package:desktop_adb_file_browser/pages/adb_check.dart';
import 'package:desktop_adb_file_browser/routes.dart';
import 'package:desktop_adb_file_browser/utils/adb.dart';
import 'package:desktop_adb_file_browser/widgets/device_card.dart';
import 'package:fluentui_system_icons/fluentui_system_icons.dart';
import 'package:flutter/material.dart';
import 'package:routemaster/routemaster.dart';

class DevicesPage extends StatefulWidget {
const DevicesPage({super.key});
const DevicesPage(
{super.key, this.serialSelector, required this.canNavigate});

static const String title = "Devices";
final ValueNotifier<String?>? serialSelector;
final bool canNavigate;

@override
State<DevicesPage> createState() => _DevicesPageState();
Expand Down Expand Up @@ -43,7 +46,7 @@ class _DevicesPageState extends State<DevicesPage> {
appBar: AppBar(
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
title: const Text(DevicesPage.title),
title: const Text("Devices"),
automaticallyImplyLeading: Routemaster.of(context).history.canGoBack,
actions: [
IconButton(
Expand All @@ -53,9 +56,10 @@ class _DevicesPageState extends State<DevicesPage> {
],
),
body: Center(
// Center is a layout widget. It takes a single child and positions it
// in the middle of the parent.
child: _loadDevices()),
// Center is a layout widget. It takes a single child and positions it
// in the middle of the parent.
child: _loadDevices(),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
_refreshDevices();
Expand Down Expand Up @@ -110,8 +114,22 @@ class _DevicesPageState extends State<DevicesPage> {

return ListView(
padding: const EdgeInsets.all(4.0),
children:
devices.map((e) => DeviceCard(device: e)).toList(growable: false));
children: devices
.map((e) => DeviceCard(
device: e,
onTap: _onDeviceSelect,
showLogButton: widget.canNavigate,
selected: widget.serialSelector?.value == e.serialName,
))
.toList(growable: false));
}

void _onDeviceSelect(Device device) {
widget.serialSelector?.value = device.serialName;

if (widget.canNavigate) {
Routes.browse(context, device.serialName);
}
}

Future<void> _connectDialog() async {
Expand Down
Loading

0 comments on commit a99b6bf

Please sign in to comment.