11import 'dart:io' ;
22import 'package:flutter/material.dart' ;
33import 'package:shared_preferences/shared_preferences.dart' ;
4+ import 'package:launch_r/models/gesture_models.dart' ;
45import 'package:launch_r/models/launcher_models.dart' ;
56import 'package:launch_r/services/font_service.dart' ;
67import 'package:launch_r/theme/app_fonts.dart' ;
@@ -21,6 +22,8 @@ class LauncherSettings extends ChangeNotifier {
2122 bool _drawerAutoSearch = false ;
2223 bool _swipeUpHome = false ;
2324 bool _swipeUpSearch = false ;
25+ HomeGesture _swipeLeft = const HomeGesture ();
26+ HomeGesture _swipeRight = const HomeGesture ();
2427 bool _fuzzySearch = true ;
2528 bool _showVoiceButton = true ;
2629 bool _showClearButton = true ;
@@ -59,6 +62,10 @@ class LauncherSettings extends ChangeNotifier {
5962 bool get drawerAutoSearch => _drawerAutoSearch;
6063 bool get swipeUpHome => _swipeUpHome;
6164 bool get swipeUpSearch => _swipeUpSearch;
65+ HomeGesture get swipeLeft => _swipeLeft;
66+ HomeGesture get swipeRight => _swipeRight;
67+ HomeGesture gestureFor (GestureSide side) =>
68+ side == GestureSide .left ? _swipeLeft : _swipeRight;
6269 bool get fuzzySearch => _fuzzySearch;
6370 bool get showVoiceButton => _showVoiceButton;
6471 bool get showClearButton => _showClearButton;
@@ -125,6 +132,8 @@ class LauncherSettings extends ChangeNotifier {
125132 _swipeUpSearch = false ;
126133 await p.setBool ('swipe_up_search' , false );
127134 }
135+ _swipeLeft = _readGesture (p, 'gesture_left' );
136+ _swipeRight = _readGesture (p, 'gesture_right' );
128137 _fuzzySearch = p.getBool ('fuzzy_search' ) ?? true ;
129138 _showVoiceButton = p.getBool ('show_voice_button' ) ?? true ;
130139 _showClearButton = p.getBool ('show_clear_button' ) ?? true ;
@@ -345,6 +354,39 @@ class LauncherSettings extends ChangeNotifier {
345354 if (turnedOffOther) await _prefs? .setBool ('swipe_up_home' , false );
346355 }
347356
357+ static HomeGesture _readGesture (SharedPreferences p, String key) =>
358+ HomeGesture (
359+ action: GestureAction .fromName (p.getString ('${key }_action' )),
360+ pkg: p.getString ('${key }_app' ),
361+ label: p.getString ('${key }_app_label' ),
362+ );
363+
364+ Future <void > setGesture (
365+ GestureSide side, {
366+ GestureAction ? action,
367+ String ? pkg,
368+ String ? label,
369+ }) async {
370+ final isLeft = side == GestureSide .left;
371+ final next = (isLeft ? _swipeLeft : _swipeRight).copyWith (
372+ action: action,
373+ pkg: pkg,
374+ label: label,
375+ );
376+ if (isLeft) {
377+ _swipeLeft = next;
378+ } else {
379+ _swipeRight = next;
380+ }
381+ notifyListeners ();
382+ final p = _prefs;
383+ if (p == null ) return ;
384+ final key = isLeft ? 'gesture_left' : 'gesture_right' ;
385+ await p.setString ('${key }_action' , next.action.name);
386+ if (next.pkg != null ) await p.setString ('${key }_app' , next.pkg! );
387+ if (next.label != null ) await p.setString ('${key }_app_label' , next.label! );
388+ }
389+
348390 Future <void > setFuzzySearch (bool v) async {
349391 if (v == _fuzzySearch) return ;
350392 _fuzzySearch = v;
0 commit comments