Skip to content

Commit

Permalink
Merge pull request #5 from geekymon2/donotdisturb
Browse files Browse the repository at this point in the history
Donotdisturb removed
  • Loading branch information
geekymon2 authored Jun 5, 2024
2 parents d09d98d + ce46395 commit 9a78083
Show file tree
Hide file tree
Showing 10 changed files with 218 additions and 321 deletions.
416 changes: 208 additions & 208 deletions docs/assets/NOTICES

Large diffs are not rendered by default.

20 changes: 0 additions & 20 deletions lib/pages/options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -339,23 +339,6 @@ class _LanguageItem extends StatelessWidget {
}
}

class _DoNotDisturbItem extends StatelessWidget {
const _DoNotDisturbItem();

@override
Widget build(BuildContext context) {
return _BooleanItem(
'Do Not Disturb',
'Requires Notification Permission',
StoreProvider.of<AppState>(context).state.options.doNotDisturb == true,
(bool value) {
StoreProvider.of<AppState>(context).dispatch(ToggleDNDAction(value,
StoreProvider.of<AppState>(context).state.options.hasNPAccess));
},
switchKey: const Key('dnd'),
);
}
}

class OptionsPage extends StatelessWidget {
const OptionsPage({
Expand Down Expand Up @@ -389,9 +372,6 @@ class OptionsPage extends StatelessWidget {
const _Heading('Gurbani'),
_LanguageItem(readerMode),
_SaveScrollPosItem(),
(defaultTargetPlatform == TargetPlatform.android)
? _DoNotDisturbItem()
: Container(),
];

//define all widgets including all options widgets first.
Expand Down
19 changes: 1 addition & 18 deletions lib/pages/readerscreen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -323,20 +323,6 @@ class _MyReaderPageState extends State<ReaderScreen> {
),
),
),
Expanded(
flex: 1,
child: Text(
(vm.dnd) ? "DND" : "",
textAlign: TextAlign.right,
style: new TextStyle(
fontFamily:
AppConstants.STATUSBAR_FONT_FAMILY,
fontSize: AppConstants
.STATUSBAR_FONT_SIZE_SMALL,
fontWeight: FontWeight.normal,
),
),
),
Expanded(
flex: (defaultTargetPlatform ==
TargetPlatform.android)
Expand Down Expand Up @@ -407,7 +393,6 @@ class _ViewModel {
final double scrollOffset;
final double maxOffset;
final bool saveScrollPosition;
final bool dnd;

_ViewModel(
{required this.onToggleReaderOptions,
Expand All @@ -420,8 +405,7 @@ class _ViewModel {
required this.nitnemPathTitle,
required this.scrollOffset,
required this.maxOffset,
required this.saveScrollPosition,
required this.dnd});
required this.saveScrollPosition});

static _ViewModel fromStore(Store<AppState> store) {
return _ViewModel(
Expand All @@ -438,7 +422,6 @@ class _ViewModel {
scrollOffset: scrollOffsetSelector(store.state),
maxOffset: maxOffsetSelector(store.state),
saveScrollPosition: saveScrollPositionSelector(store.state),
dnd: dndStatusSelector(store.state),
);
}

Expand Down
6 changes: 0 additions & 6 deletions lib/redux/actions/actions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,6 @@ class ToggleBoldAction {
ToggleBoldAction(this.isBold);
}

class ToggleDNDAction {
final bool isDnd;
final bool hasNPAccess;
ToggleDNDAction(this.isDnd, this.hasNPAccess);
}

class ToggleStatusAction {
final bool showStatus;
ToggleStatusAction(this.showStatus);
Expand Down
17 changes: 1 addition & 16 deletions lib/redux/middleware/middleware.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import 'dart:async';
import 'dart:convert';
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart' show rootBundle;
//import 'package:flutter_dnd/flutter_dnd.dart';
import 'package:nitnem/common/printmessage.dart';
import 'package:nitnem/constants/appconstants.dart';
import 'package:nitnem/models/language.dart';
Expand Down Expand Up @@ -34,12 +32,6 @@ void storeOptionsMiddleware(
saveOptionsToPrefs(state.options);
}

if (action is ToggleDNDAction) {
state = state.copyWith(
options: state.options.copyWith(doNotDisturb: action.isDnd));
saveOptionsToPrefs(state.options);
}

if (action is UpdateStatusScrollPercentageAction) {
Map<String, ScrollInfo> scrollPos = state.options.scrollOffset;
scrollPos.update(
Expand Down Expand Up @@ -124,12 +116,7 @@ void saveOptionsToPrefs(AppOptions options) async {
}

Future<AppOptions> loadOptionsFromPrefs() async {
bool hasNPAccess = false;
AppOptions options = AppOptions.initial();
if (defaultTargetPlatform == TargetPlatform.android) {
//TODO: need to fix DND
//hasNPAccess = (await FlutterDnd.isNotificationPolicyAccessGranted)!;
}
SharedPreferences preferences = await SharedPreferences.getInstance();
var stateString = preferences.getString(AppConstants.OPTIONS_SHAREDPREF_KEY);
if (stateString != null) {
Expand All @@ -143,9 +130,7 @@ Future<AppOptions> loadOptionsFromPrefs() async {
languageName: prefs["languageName"],
screenAwake: prefs["screenAwake"],
saveScrollPosition: prefs["saveScrollPosition"],
scrollOffset: constructScrollPosMap(prefs["scrollOffset"]),
doNotDisturb: prefs["doNotDisturb"],
hasNPAccess: hasNPAccess);
scrollOffset: constructScrollPosMap(prefs["scrollOffset"]));
}

printInfoMessage('[OPTIONS LOADED: ${options.toString()}');
Expand Down
6 changes: 1 addition & 5 deletions lib/redux/reducers/app_state_reducer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import 'languagereducer.dart';
import 'statusreducer.dart';
import 'textscalereducer.dart';
import 'themereducer.dart';
import 'dndreducer.dart';

AppState appReducer(AppState state, dynamic action) {
AppState newState = state.copyWith();
Expand All @@ -37,8 +36,7 @@ AppState appReducer(AppState state, dynamic action) {
action is UpdateStatusScrollPercentageAction ||
action is ToggleScreenAwakeAction ||
action is ClearReaderOptionsToggleAction ||
action is ToggleReadingPositionSaveAction ||
action is ToggleDNDAction) {
action is ToggleReadingPositionSaveAction) {
newState = AppState(
options: AppOptions(
themeName: themeReducer(state.options.themeName, action),
Expand All @@ -50,8 +48,6 @@ AppState appReducer(AppState state, dynamic action) {
saveScrollPosition:
saveScrollPosReducer(state.options.saveScrollPosition, action),
scrollOffset: scrollPercReducer(state.options.scrollOffset, action),
doNotDisturb: dndReducer(state.options.doNotDisturb, action),
hasNPAccess: state.options.hasNPAccess,
),
showReaderOptions: readerOptionsReducer(state.showReaderOptions, action),
pathData: pathDataReducer(state.pathData, action),
Expand Down
25 changes: 0 additions & 25 deletions lib/redux/reducers/dndreducer.dart

This file was deleted.

1 change: 0 additions & 1 deletion lib/redux/selectors/selectors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ double maxOffsetSelector(AppState state) =>
getMaxOffsetForThisPath(state.options.scrollOffset, state.pathId);
bool saveScrollPositionSelector(AppState state) =>
state.options.saveScrollPosition;
bool dndStatusSelector(AppState state) => state.options.doNotDisturb;

double getScrollOffsetForThisPath(Map<String, ScrollInfo> scrollPos, int id) {
//set scroll position for path with does not exist previously in saved options.
Expand Down
27 changes: 6 additions & 21 deletions lib/state/appoptions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ class AppOptions {
required this.languageName,
required this.screenAwake,
required this.saveScrollPosition,
required this.scrollOffset,
required this.doNotDisturb,
required this.hasNPAccess});
required this.scrollOffset});

final String themeName;
final bool bold;
Expand All @@ -31,8 +29,6 @@ class AppOptions {
final bool screenAwake;
final bool saveScrollPosition;
final Map<String, ScrollInfo> scrollOffset;
final bool doNotDisturb;
final bool hasNPAccess;

factory AppOptions.initial() => AppOptions(
themeName: ThemeName.Default.toString(),
Expand All @@ -44,9 +40,7 @@ class AppOptions {
saveScrollPosition: false,
scrollOffset: new Map.fromIterable(PathTileData.items,
key: (v) => v.id.toString(),
value: (v) => new ScrollInfo(v.id, 0.0, 0.0)),
doNotDisturb: false,
hasNPAccess: false);
value: (v) => new ScrollInfo(v.id, 0.0, 0.0)));

AppOptions copyWith(
{String? themeName,
Expand All @@ -56,9 +50,7 @@ class AppOptions {
String? languageName,
bool? screenAwake,
bool? saveScrollPosition,
Map<String, ScrollInfo>? scrollOffset,
bool? doNotDisturb,
bool? hasNPAccess}) {
Map<String, ScrollInfo>? scrollOffset}) {
return AppOptions(
themeName: themeName ?? this.themeName,
bold: bold ?? this.bold,
Expand All @@ -67,9 +59,7 @@ class AppOptions {
languageName: languageName ?? this.languageName,
screenAwake: screenAwake ?? this.screenAwake,
saveScrollPosition: saveScrollPosition ?? this.saveScrollPosition,
scrollOffset: scrollOffset ?? this.scrollOffset,
doNotDisturb: doNotDisturb ?? this.doNotDisturb,
hasNPAccess: hasNPAccess ?? this.hasNPAccess);
scrollOffset: scrollOffset ?? this.scrollOffset);
}

@override
Expand All @@ -83,9 +73,7 @@ class AppOptions {
languageName == typedOther.languageName &&
screenAwake == typedOther.screenAwake &&
saveScrollPosition == typedOther.saveScrollPosition &&
scrollOffset == typedOther.scrollOffset &&
doNotDisturb == typedOther.doNotDisturb &&
hasNPAccess == typedOther.hasNPAccess;
scrollOffset == typedOther.scrollOffset;
}

@override
Expand All @@ -98,8 +86,6 @@ class AppOptions {
screenAwake,
saveScrollPosition,
scrollOffset,
doNotDisturb,
hasNPAccess
]);

Map<String, dynamic> toJson() {
Expand All @@ -112,7 +98,6 @@ class AppOptions {
map["screenAwake"] = this.screenAwake;
map["saveScrollPosition"] = this.saveScrollPosition;
map["scrollOffset"] = json.encode(this.scrollOffset);
map["doNotDisturb"] = this.doNotDisturb;
return map;
}

Expand All @@ -122,6 +107,6 @@ class AppOptions {
String pos = "";
scrollOffset.forEach((k, v) => pos += "$k: ${v.scrollOffset}, ");

return '[theme: $themeName, bold: $bold, status: $showStatus, scale: $textScaleValue, lang: $languageName, awake: $screenAwake, savepos: $saveScrollPosition, pos: $pos], dnd: $doNotDisturb';
return '[theme: $themeName, bold: $bold, status: $showStatus, scale: $textScaleValue, lang: $languageName, awake: $screenAwake, savepos: $saveScrollPosition, pos: $pos]';
}
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ dependencies:
provider: ^6.1.2
cupertino_icons: ^1.0.2
wakelock_plus: ^1.2.5
# flutter_dnd: ^0.1.4+1
flutter_local_notifications: ^17.1.2

dev_dependencies:
flutter_launcher_icons: ^0.13.1
Expand Down

0 comments on commit 9a78083

Please sign in to comment.