-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from muslimpack/dependency-injection
Dependency injection
- Loading branch information
Showing
28 changed files
with
580 additions
and
392 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import 'package:alazkar/src/core/constants/const.dart'; | ||
import 'package:alazkar/src/core/helpers/bookmarks_helper.dart'; | ||
import 'package:alazkar/src/core/manager/volume_button_manager.dart'; | ||
import 'package:alazkar/src/features/home/presentation/controller/home/home_bloc.dart'; | ||
import 'package:alazkar/src/features/quran/data/repository/uthmani_repository.dart'; | ||
import 'package:alazkar/src/features/search/presentation/controller/cubit/search_cubit.dart'; | ||
import 'package:alazkar/src/features/settings/data/repository/settings_storage.dart'; | ||
import 'package:alazkar/src/features/settings/data/repository/zikr_text_repo.dart'; | ||
import 'package:alazkar/src/features/settings/presentation/controller/cubit/settings_cubit.dart'; | ||
import 'package:alazkar/src/features/share_as_image/data/repository/share_image_repo.dart'; | ||
import 'package:alazkar/src/features/share_as_image/presentation/controller/share_as_image/share_as_image_bloc.dart'; | ||
import 'package:alazkar/src/features/theme/domain/repository/theme_storage.dart'; | ||
import 'package:alazkar/src/features/theme/presentation/controller/cubit/theme_cubit.dart'; | ||
import 'package:alazkar/src/features/ui/data/repository/ui_repo.dart'; | ||
import 'package:alazkar/src/features/zikr_content_viewer/presentation/controller/bloc/zikr_content_viewer_bloc.dart'; | ||
import 'package:alazkar/src/features/zikr_source_filter/data/repository/zikr_filter_storage.dart'; | ||
import 'package:alazkar/src/features/zikr_source_filter/presentation/controller/cubit/zikr_source_filter_cubit.dart'; | ||
import 'package:get_it/get_it.dart'; | ||
import 'package:get_storage/get_storage.dart'; | ||
|
||
final sl = GetIt.instance; | ||
|
||
Future<void> initSL() async { | ||
///MARK: Init storages | ||
sl.registerLazySingleton(() => GetStorage(kGetStorageName)); | ||
sl.registerLazySingleton(() => UIRepo(sl())); | ||
sl.registerLazySingleton(() => ThemeStorage(sl())); | ||
sl.registerLazySingleton(() => ZikrFilterStorage(sl())); | ||
sl.registerLazySingleton(() => SettingsStorage(sl())); | ||
sl.registerLazySingleton(() => ShareAsImageRepo(sl())); | ||
sl.registerLazySingleton(() => ZikrTextRepo(sl())); | ||
|
||
///MARK: Init Repo | ||
sl.registerLazySingleton(() => UthmaniRepository()); | ||
sl.registerLazySingleton(() => BookmarksDBHelper()); | ||
|
||
///MARK: Init Manager | ||
sl.registerFactory(() => VolumeButtonManager()); | ||
|
||
///MARK: Init BLOC | ||
/// Singleton BLoC | ||
sl.registerLazySingleton(() => ThemeCubit(sl(), sl())); | ||
sl.registerLazySingleton(() => HomeBloc(sl(), sl())); | ||
sl.registerLazySingleton(() => SearchCubit(sl(), sl())); | ||
sl.registerLazySingleton(() => SettingsCubit(sl())); | ||
sl.registerLazySingleton(() => ZikrSourceFilterCubit(sl())); | ||
|
||
/// Factory BLoC | ||
sl.registerFactory(() => ShareAsImageBloc(sl())); | ||
sl.registerFactory( | ||
() => ZikrContentViewerBloc(sl(), sl(), sl()), | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 5 additions & 38 deletions
43
alazkar/lib/src/features/settings/data/repository/settings_storage.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,22 @@ | ||
import 'dart:convert'; | ||
|
||
import 'package:alazkar/src/core/constants/const.dart'; | ||
import 'package:alazkar/src/core/utils/app_print.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:get_storage/get_storage.dart'; | ||
|
||
class SettingsStorage { | ||
static final _box = GetStorage(kGetStorageName); | ||
final GetStorage _box; | ||
SettingsStorage(this._box); | ||
|
||
static const String _settingsPrefixNameKey = "SettingsStorage"; | ||
|
||
/// Titles Freq filters | ||
/// showTextInBrackets | ||
static const String _showTextInBrackets = | ||
"${_settingsPrefixNameKey}showTextInBrackets"; | ||
|
||
/// Filters for zikr source | ||
static bool showTextInBrackets() { | ||
bool showTextInBrackets() { | ||
final bool? data = _box.read(_showTextInBrackets); | ||
|
||
return data ?? true; | ||
} | ||
|
||
/// Filters for zikr source | ||
static Future setShowTextInBrackets(bool showTextInBrackets) async { | ||
Future setShowTextInBrackets(bool showTextInBrackets) async { | ||
return _box.write(_showTextInBrackets, showTextInBrackets); | ||
} | ||
|
||
///* ******* desktop Window Size ******* */ | ||
static const String desktopWindowSizeKey = "desktopWindowSize"; | ||
static Size? get desktopWindowSize { | ||
try { | ||
final data = | ||
jsonDecode(_box.read(desktopWindowSizeKey) as String? ?? "{}") | ||
as Map<String, dynamic>; | ||
|
||
final double width = (data['width'] as num).toDouble(); | ||
final double height = (data['height'] as num).toDouble(); | ||
|
||
return Size(width, height); | ||
} catch (e) { | ||
appPrint(e); | ||
} | ||
return const Size(400, 800); | ||
} | ||
|
||
static Future<void> changeDesktopWindowSize(Size value) async { | ||
final screenSize = { | ||
'width': value.width, | ||
'height': value.height, | ||
}; | ||
final String data = jsonEncode(screenSize); | ||
return _box.write(desktopWindowSizeKey, data); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
alazkar/lib/src/features/settings/data/repository/zikr_text_repo.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import 'package:alazkar/src/core/constants/const.dart'; | ||
import 'package:get_storage/get_storage.dart'; | ||
|
||
class ZikrTextRepo { | ||
final GetStorage box; | ||
ZikrTextRepo(this.box); | ||
|
||
///MARK: Font | ||
/* ******* Font Size ******* */ | ||
static const String fontSizeKey = 'ThemeFontSize'; | ||
double get fontSize => box.read<double>(fontSizeKey) ?? kFontDefault; | ||
|
||
Future<void> changFontSize(double value) async { | ||
final double tempValue = value.clamp(kFontMin, kFontMax); | ||
await box.write(fontSizeKey, tempValue); | ||
} | ||
|
||
void resetFontSize() { | ||
changFontSize(kFontDefault); | ||
} | ||
|
||
void increaseFontSize() { | ||
changFontSize(fontSize + kFontChangeBy); | ||
} | ||
|
||
void decreaseFontSize() { | ||
changFontSize(fontSize - kFontChangeBy); | ||
} | ||
|
||
/* ******* Diacritics ******* */ | ||
|
||
bool get showDiacritics => box.read('showDiacritics') ?? true; | ||
|
||
Future<void> changDiacriticsStatus({required bool value}) async => | ||
box.write('tashkel_status', value); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.