Skip to content

Commit

Permalink
🧭 Implemented Sorting Modes.
Browse files Browse the repository at this point in the history
Now Power Mode, supports sorting in Newest-First and Oldest-First modes.
  • Loading branch information
omegaui committed Dec 29, 2023
1 parent 1ac7d9a commit 727cdb6
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 9 deletions.
2 changes: 2 additions & 0 deletions lib/app/powermode/domain/entity/typedefs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ enum PowerImageFilterType {
i8By5,
i5By8,
}

enum SortingMode { NewestFirst, OldestFirst }
32 changes: 23 additions & 9 deletions lib/app/powermode/presentation/panels/search_panel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,14 @@ class _SearchPanelState extends State<SearchPanel> {
}

Widget _buildEntityInfo() {
String message = PowerDataHandler.hoveringEntity == null
? "Hover on any card to view when it was used recently"
: "${DateFormat.yMMMMEEEEd('en_us').format(PowerDataHandler.hoveringEntity!.time)} ${DateFormat('K:mm:ss a').format(PowerDataHandler.hoveringEntity!.time)}";
if (PowerDataHandler.hoveringEntity == null) {
return SizedBox(
key: ValueKey('hidden-state-${DateTime.now().toString()}'));
}
String message =
"${DateFormat.yMMMMEEEEd('en_us').format(PowerDataHandler.hoveringEntity!.time)} ${DateFormat('K:mm:ss a').format(PowerDataHandler.hoveringEntity!.time)}";
return Row(
key: ValueKey('entity-info-${DateTime.now().toString()}'),
mainAxisSize: MainAxisSize.min,
children: [
Icon(
Expand Down Expand Up @@ -85,7 +89,10 @@ class _SearchPanelState extends State<SearchPanel> {
const Gap(11),
const PowerSearchField(),
const Gap(11),
_buildEntityInfo(),
AnimatedSwitcher(
duration: const Duration(milliseconds: 250),
child: _buildEntityInfo(),
),
Expanded(
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
Expand All @@ -112,11 +119,18 @@ class _SearchPanelState extends State<SearchPanel> {
const Gap(8),
IconButton(
onPressed: () {
if (isBackgroundServiceAlive) {
showPowerSettings(context);
} else {
showDaemonManagerDialog(context);
}
PowerDataHandler.toggleSortMode();
},
icon: Image.asset(
AppIcons.filter,
width: 24,
),
),
const Gap(8),
IconButton(
tooltip: "Toggle Sorting Mode",
onPressed: () {
PowerDataHandler.toggleSortMode();
},
icon: Icon(
isBackgroundServiceAlive ? Icons.settings : Icons.warning,
Expand Down
28 changes: 28 additions & 0 deletions lib/core/powermode/power_data_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ import 'package:cliptopia/app/powermode/domain/entity/image_entity.dart';
import 'package:cliptopia/app/powermode/domain/entity/recent_emoji_entity.dart';
import 'package:cliptopia/app/powermode/domain/entity/text_entity.dart';
import 'package:cliptopia/app/powermode/domain/entity/typedefs.dart';
import 'package:cliptopia/app/powermode/presentation/power_mode_app.dart';
import 'package:cliptopia/constants/typedefs.dart';
import 'package:cliptopia/core/logger.dart';
import 'package:cliptopia/core/powermode/power_data_store.dart';
import 'package:cliptopia/core/powermode/power_utils.dart';
import 'package:cliptopia/core/storage/json_configurator.dart';
import 'package:cliptopia/core/storage/storage.dart';
import 'package:cliptopia/core/utils.dart';
import 'package:cliptopia/widgets/message_bird.dart';
import 'package:flutter/material.dart';
import 'package:flutter_emoji/flutter_emoji.dart';

Expand All @@ -32,6 +34,8 @@ class PowerDataHandler {

static PowerSearchType searchType = PowerSearchType.Text;

static SortingMode sortingMode = SortingMode.NewestFirst;

static String searchText = "";

static PowerDateFilterType dateFilterType = PowerDateFilterType.last7Days;
Expand Down Expand Up @@ -87,6 +91,30 @@ class PowerDataHandler {
}
}

static void _sort(List<dynamic> list) {
if (sortingMode == SortingMode.OldestFirst) {
list.sort((a, b) => a.entity.time.compareTo(b.entity.time));
} else {
list.sort((a, b) => b.entity.time.compareTo(a.entity.time));
}
}

static void toggleSortMode() {
if (sortingMode == SortingMode.NewestFirst) {
sortingMode = SortingMode.OldestFirst;
} else {
sortingMode = SortingMode.NewestFirst;
}
Messenger.show("Changed Sorting Mode to ${sortingMode.name}");
_sort(_images);
_sort(_colors);
_sort(_texts);
_sort(_recentEmojis);
_sort(_commands);
_sort(_files);
rebuildView(message: "Switched to SortingMode.${sortingMode.name}");
}

static void searchTypeUpdate(PowerSearchType type) {
searchType = type;
Future.delayed(const Duration(milliseconds: 100), () {
Expand Down

0 comments on commit 727cdb6

Please sign in to comment.