Skip to content

Commit

Permalink
Support slide options;remove tile layout
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert-Stackflow committed Sep 5, 2024
1 parent 8b4944b commit 8ad8918
Show file tree
Hide file tree
Showing 37 changed files with 4,154 additions and 49 deletions.
2 changes: 1 addition & 1 deletion lib/Resources/theme_color_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class ThemeColorData {
dividerColor: const Color(0xFFF5F5F5),
tagBackground: const Color(0xFFF5F5F5),
tagColor: const Color(0xFFBDBDBD),
cardBackground: const Color(0xFFF5F5F5),
cardBackground: const Color(0x119E9E9E),
),
ThemeColorData(
id: "freshGreen",
Expand Down
16 changes: 16 additions & 0 deletions lib/Screens/Setting/setting_operation_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class _OperationSettingScreenState extends State<OperationSettingScreen>
bool clipToCopy = HiveUtil.getBool(HiveUtil.clickToCopyKey);
bool autoCopyNextCode = HiveUtil.getBool(HiveUtil.autoCopyNextCodeKey);
bool autoDisplayNextCode = HiveUtil.getBool(HiveUtil.autoDisplayNextCodeKey);
bool autoFocusSearchBar = HiveUtil.getBool(HiveUtil.autoFocusSearchBarKey,defaultValue: false);
bool autoMinimizeAfterClickToCopy = HiveUtil.getBool(
HiveUtil.autoMinimizeAfterClickToCopyKey,
defaultValue: false);
Expand Down Expand Up @@ -208,6 +209,21 @@ class _OperationSettingScreenState extends State<OperationSettingScreen>
);
},
),
const SizedBox(height: 10),
ItemBuilder.buildRadioItem(
context: context,
value: autoFocusSearchBar,
title: S.current.autoFocusSearchBar,
description: S.current.autoFocusSearchBarTip,
topRadius: true,
bottomRadius: true,
onTap: () {
setState(() {
autoFocusSearchBar = !autoFocusSearchBar;
HiveUtil.put(HiveUtil.autoFocusSearchBarKey, autoFocusSearchBar);
});
},
),
];
}
}
40 changes: 20 additions & 20 deletions lib/Screens/Token/import_export_token_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -276,26 +276,6 @@ class _ImportExportTokenScreenState extends State<ImportExportTokenScreen>
}
},
),
ItemBuilder.buildEntryItem(
context: context,
title: S.current.exportQrcode,
description: S.current.exportQrcodeHint,
onTap: () async {
List<String>? qrCodes = await ExportTokenUtil.exportToQrcodes();
if (qrCodes != null && qrCodes.isNotEmpty) {
DialogBuilder.showQrcodesDialog(
context,
title: S.current.exportQrcode,
message: S.current.exportQrcodeMessage,
qrcodes: qrCodes,
);
} else if (qrCodes != null && qrCodes.isEmpty) {
IToast.showTop(S.current.exportQrcodeNoData);
} else {
IToast.showTop(S.current.exportFailed);
}
},
),
ItemBuilder.buildEntryItem(
context: context,
title: S.current.exportUriFile,
Expand Down Expand Up @@ -325,6 +305,26 @@ class _ImportExportTokenScreenState extends State<ImportExportTokenScreen>
);
},
),
ItemBuilder.buildEntryItem(
context: context,
title: S.current.exportQrcode,
description: S.current.exportQrcodeHint,
onTap: () async {
List<String>? qrCodes = await ExportTokenUtil.exportToQrcodes();
if (qrCodes != null && qrCodes.isNotEmpty) {
DialogBuilder.showQrcodesDialog(
context,
title: S.current.exportQrcode,
message: S.current.exportQrcodeMessage,
qrcodes: qrCodes,
);
} else if (qrCodes != null && qrCodes.isEmpty) {
IToast.showTop(S.current.exportQrcodeNoData);
} else {
IToast.showTop(S.current.exportFailed);
}
},
),
// const SizedBox(height: 10),
// ItemBuilder.buildCaptionItem(
// context: context, title: S.current.exportToThirdParty),
Expand Down
113 changes: 109 additions & 4 deletions lib/Screens/Token/token_layout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import 'package:cloudotp/Widgets/Item/item_builder.dart';
import 'package:context_menus/context_menus.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_slidable/flutter_slidable.dart';
import 'package:move_to_background/move_to_background.dart';
import 'package:provider/provider.dart';
import 'package:window_manager/window_manager.dart';
Expand Down Expand Up @@ -204,18 +205,122 @@ class TokenLayoutState extends State<TokenLayout>
);
}

_buildSlidable({
required Widget child,
bool simple = false,
double startExtentRatio = 0.16,
double endExtentRatio = 0.64,
}) {
return Slidable(
groupTag: "TokenLayout",
enabled: !ResponsiveUtil.isWideLandscape(),
startActionPane: ActionPane(
extentRatio: startExtentRatio,
motion: const ScrollMotion(),
children: [
SlidableAction(
onPressed: (context) => _processPin(),
backgroundColor: widget.token.pinned
? Theme.of(context).primaryColor
: Theme.of(context).cardColor,
borderRadius: const BorderRadius.all(Radius.circular(12)),
foregroundColor: Theme.of(context).primaryColor,
icon: widget.token.pinned
? Icons.push_pin_rounded
: Icons.push_pin_outlined,
label: widget.token.pinned
? S.current.unPinTokenShort
: S.current.pinTokenShort,
simple: simple,
spacing: 8,
padding: const EdgeInsets.symmetric(horizontal: 4),
iconAndTextColor: widget.token.pinned ? Colors.white : null,
),
const SizedBox(width: 6),
],
),
endActionPane: ActionPane(
extentRatio: endExtentRatio,
motion: const ScrollMotion(),
children: [
const SizedBox(width: 6),
SlidableAction(
onPressed: (context) => _processViewQrCode(),
backgroundColor: Theme.of(context).cardColor,
borderRadius: const BorderRadius.all(Radius.circular(12)),
foregroundColor: Theme.of(context).primaryColor,
icon: Icons.qr_code_rounded,
label: S.current.viewTokenQrCodeShort,
spacing: 8,
simple: simple,
padding: const EdgeInsets.symmetric(horizontal: 4),
),
const SizedBox(width: 6),
SlidableAction(
onPressed: (context) => _processEdit(),
backgroundColor: Theme.of(context).cardColor,
borderRadius: const BorderRadius.all(Radius.circular(12)),
foregroundColor: Theme.of(context).primaryColor,
icon: Icons.edit_outlined,
padding: const EdgeInsets.symmetric(horizontal: 4),
label: S.current.editTokenShort,
simple: simple,
spacing: 8,
),
const SizedBox(width: 6),
SlidableAction(
onPressed: (context) => showContextMenu(),
backgroundColor: Theme.of(context).cardColor,
borderRadius: const BorderRadius.all(Radius.circular(12)),
foregroundColor: Theme.of(context).primaryColor,
icon: Icons.more_vert_rounded,
padding: const EdgeInsets.symmetric(horizontal: 4),
label: S.current.moreOptionShort,
simple: simple,
spacing: 8,
),
const SizedBox(width: 6),
SlidableAction(
onPressed: (context) => _processDelete(),
backgroundColor: Colors.red,
borderRadius: const BorderRadius.all(Radius.circular(12)),
foregroundColor: Theme.of(context).primaryColor,
icon: Icons.delete,
simple: simple,
label: S.current.deleteTokenShort,
padding: const EdgeInsets.symmetric(horizontal: 4),
spacing: 8,
iconAndTextColor: Colors.white,
),
],
),
child: child,
);
}

_buildBody() {
switch (widget.layoutType) {
case LayoutType.Simple:
return _buildSimpleLayout();
case LayoutType.Compact:
return _buildCompactLayout();
case LayoutType.Tile:
return _buildTileLayout();
// case LayoutType.Tile:
// return _buildSlidable(
// startExtentRatio: 0.23,
// endExtentRatio: 0.9,
// child: _buildTileLayout(),
// );
case LayoutType.List:
return _buildListLayout();
return _buildSlidable(
simple: true,
child: _buildListLayout(),
);
case LayoutType.Spotlight:
return _buildSpotlightLayout();
return _buildSlidable(
startExtentRatio: 0.21,
endExtentRatio: 0.8,
child: _buildSpotlightLayout(),
);
}
}

Expand Down
23 changes: 15 additions & 8 deletions lib/Screens/home_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import 'package:cloudotp/Widgets/Item/item_builder.dart';
import 'package:context_menus/context_menus.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_slidable/flutter_slidable.dart';
import 'package:move_to_background/move_to_background.dart';
import 'package:package_info_plus/package_info_plus.dart';
import 'package:provider/provider.dart';
Expand Down Expand Up @@ -104,6 +105,13 @@ class HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
value: 1,
duration: const Duration(milliseconds: 300),
);
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
if (!ResponsiveUtil.isLandscape() &&
HiveUtil.getBool(HiveUtil.autoFocusSearchBarKey,
defaultValue: false)) {
changeSearchBar(true);
}
});
}

initAppName() {
Expand Down Expand Up @@ -754,7 +762,7 @@ class HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
],
)
: gridView;
return body;
return SlidableAutoCloseBehavior(child:body);
}

_buildTabBar([EdgeInsetsGeometry? padding]) {
Expand Down Expand Up @@ -1067,18 +1075,17 @@ class HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin {
enum LayoutType {
Simple,
Compact,
Tile,
List,
Spotlight;
Spotlight,
List;

double get maxCrossAxisExtent {
switch (this) {
case LayoutType.Simple:
return 250;
case LayoutType.Compact:
return 250;
case LayoutType.Tile:
return 420;
// case LayoutType.Tile:
// return 420;
case LayoutType.List:
return 480;
case LayoutType.Spotlight:
Expand All @@ -1092,8 +1099,8 @@ enum LayoutType {
return 108;
case LayoutType.Compact:
return 108;
case LayoutType.Tile:
return 114;
// case LayoutType.Tile:
// return 114;
case LayoutType.List:
return 60;
case LayoutType.Spotlight:
Expand Down
19 changes: 11 additions & 8 deletions lib/Screens/main_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ import '../Utils/itoast.dart';
import '../Utils/lottie_util.dart';
import '../Utils/route_util.dart';
import '../Utils/utils.dart';
import '../Widgets/BottomSheet/bottom_sheet_builder.dart';
import '../Widgets/BottomSheet/import_from_third_party_bottom_sheet.dart';
import '../Widgets/Custom/loading_icon.dart';
import '../Widgets/Dialog/custom_dialog.dart';
Expand Down Expand Up @@ -185,6 +184,10 @@ class MainScreenState extends State<MainScreen>
autoForward: !Utils.isDark(context),
controller: darkModeController,
);
if (HiveUtil.getBool(HiveUtil.autoFocusSearchBarKey,
defaultValue: false)) {
searchFocusNode.requestFocus();
}
});
initGlobalConfig();
searchController.addListener(() {
Expand Down Expand Up @@ -432,13 +435,13 @@ class MainScreenState extends State<MainScreen>
homeScreenState?.changeLayoutType(LayoutType.Compact);
},
),
ContextMenuButtonConfig.checkbox(
S.current.tileLayoutType,
checked: homeScreenState?.layoutType == LayoutType.Tile,
onPressed: () {
homeScreenState?.changeLayoutType(LayoutType.Tile);
},
),
// ContextMenuButtonConfig.checkbox(
// S.current.tileLayoutType,
// checked: homeScreenState?.layoutType == LayoutType.Tile,
// onPressed: () {
// homeScreenState?.changeLayoutType(LayoutType.Tile);
// },
// ),
ContextMenuButtonConfig.checkbox(
S.current.listLayoutType,
checked: homeScreenState?.layoutType == LayoutType.List,
Expand Down
3 changes: 3 additions & 0 deletions lib/TokenUtils/import_token_util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:cloudotp/Database/token_dao.dart';
import 'package:cloudotp/Models/opt_token.dart';
import 'package:cloudotp/TokenUtils/Backup/backup_encrypt_old.dart';
import 'package:cloudotp/TokenUtils/otp_token_parser.dart';
import 'package:cloudotp/TokenUtils/token_image_util.dart';
import 'package:cloudotp/Utils/app_provider.dart';
import 'package:cloudotp/Utils/itoast.dart';
import 'package:cloudotp/Utils/responsive_util.dart';
Expand Down Expand Up @@ -648,6 +649,8 @@ class ImportTokenUtil {
List<OtpToken> already = await TokenDao.listTokens();
List<OtpToken> newTokenList = [];
for (OtpToken otpToken in tokenList) {
if (otpToken.issuer.isEmpty) otpToken.issuer = otpToken.account;
otpToken.imagePath = TokenImageUtil.matchBrandLogo(otpToken) ?? "";
OtpToken? alreadyToken = checkTokenExist(otpToken, already);
if (alreadyToken == null &&
checkTokenExist(otpToken, newTokenList) == null) {
Expand Down
2 changes: 2 additions & 0 deletions lib/Utils/hive_util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class HiveUtil {
static const String inappWebviewKey = "inappWebview";

static const String clickToCopyKey = "clickToCopy";
static const String autoFocusSearchBarKey = "autoFocusSearchBar";
static const String autoCopyNextCodeKey = "autoCopyNextCode";
static const String autoDisplayNextCodeKey = "autoDisplayNextCode";
static const String autoMinimizeAfterClickToCopyKey =
Expand Down Expand Up @@ -108,6 +109,7 @@ class HiveUtil {
await HiveUtil.put(HiveUtil.inappWebviewKey, true);
await HiveUtil.put(HiveUtil.layoutTypeKey, LayoutType.Compact.index);
await HiveUtil.put(HiveUtil.enableSafeModeKey, true);
await HiveUtil.put(HiveUtil.autoFocusSearchBarKey, false);
await HiveUtil.put(HiveUtil.maxBackupsCountKey, defaultMaxBackupCount);
await HiveUtil.put(HiveUtil.backupPathKey, await FileUtil.getBackupDir());
await HiveUtil.put(HiveUtil.dragToReorderKey, !ResponsiveUtil.isMobile());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ class ImportFromThirdPartyBottomSheetState
.titleMedium
?.apply(fontWeightDelta: 2),
),
center: !ResponsiveUtil.isLandscape(),
actions: ResponsiveUtil.isLandscape()
? []
: [
Expand Down Expand Up @@ -226,6 +225,12 @@ class ImportFromThirdPartyBottomSheetState
Function(String)? onImport,
bool useImport = true,
}) {
final allowedExtensionsInAndroid = ['txt', 'json', 'zip'];
bool containUnsupportExt = false;
for (var ext in allowedExtensions) {
if (!allowedExtensionsInAndroid.contains(ext)) containUnsupportExt = true;
}
containUnsupportExt = containUnsupportExt && ResponsiveUtil.isAndroid();
return Material(
color: Theme.of(context).canvasColor,
borderRadius: BorderRadius.circular(10),
Expand All @@ -234,8 +239,9 @@ class ImportFromThirdPartyBottomSheetState
? () async {
FilePickerResult? result = await FileUtil.pickFiles(
dialogTitle: dialogTitle,
type: FileType.custom,
allowedExtensions: allowedExtensions,
type: containUnsupportExt ? FileType.any : FileType.custom,
allowedExtensions:
containUnsupportExt ? [] : allowedExtensions,
lockParentWindow: true,
);
if (result != null) {
Expand Down
Loading

0 comments on commit 8ad8918

Please sign in to comment.