refactor: perform clean up
This commit is contained in:
parent
e57da88272
commit
6b70116a63
5 changed files with 48 additions and 20 deletions
|
|
@ -6,7 +6,7 @@ plugins {
|
||||||
|
|
||||||
android {
|
android {
|
||||||
namespace = "com.slrpg.app"
|
namespace = "com.slrpg.app"
|
||||||
compileSdk = 36
|
compileSdk = 35
|
||||||
|
|
||||||
compileOptions {
|
compileOptions {
|
||||||
sourceCompatibility = JavaVersion.VERSION_17
|
sourceCompatibility = JavaVersion.VERSION_17
|
||||||
|
|
@ -21,7 +21,7 @@ android {
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId = "com.slrpg.app"
|
applicationId = "com.slrpg.app"
|
||||||
minSdk = flutter.minSdkVersion
|
minSdk = flutter.minSdkVersion
|
||||||
targetSdk = 36
|
targetSdk = 35
|
||||||
versionCode = 1
|
versionCode = 1
|
||||||
versionName = "1.0.0"
|
versionName = "1.0.0"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,23 +23,30 @@ void main() async {
|
||||||
DeviceOrientation.portraitDown,
|
DeviceOrientation.portraitDown,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
final notificationService = NotificationService();
|
|
||||||
await notificationService.init();
|
|
||||||
|
|
||||||
final database = AppDatabase();
|
final database = AppDatabase();
|
||||||
|
|
||||||
final authStore = PbAuthStore();
|
final authStore = PbAuthStore();
|
||||||
await authStore.loadFromStorage();
|
await authStore.loadFromStorage();
|
||||||
|
|
||||||
|
final container = ProviderContainer(
|
||||||
|
overrides: [
|
||||||
|
appDatabaseProvider.overrideWithValue(database),
|
||||||
|
apiClientProvider
|
||||||
|
.overrideWith((ref) => ApiClient(authStore: authStore)),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
|
try {
|
||||||
|
log('Initializing NotificationService...');
|
||||||
|
container.read(notificationServiceProvider).init();
|
||||||
|
} catch (e) {
|
||||||
|
log('Error triggering NotificationService: $e');
|
||||||
|
}
|
||||||
|
|
||||||
log("Auth loaded. Valid? ${authStore.isValid}");
|
log("Auth loaded. Valid? ${authStore.isValid}");
|
||||||
|
|
||||||
runApp(
|
runApp(
|
||||||
ProviderScope(
|
UncontrolledProviderScope(
|
||||||
overrides: [
|
container: container,
|
||||||
appDatabaseProvider.overrideWithValue(database),
|
|
||||||
apiClientProvider
|
|
||||||
.overrideWith((ref) => ApiClient(authStore: authStore)),
|
|
||||||
],
|
|
||||||
child: const SLRPGApp(),
|
child: const SLRPGApp(),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,8 @@ class ErrorHandler {
|
||||||
return l10n.errorEntryNotUnique;
|
return l10n.errorEntryNotUnique;
|
||||||
}
|
}
|
||||||
// PocketBase specific error for failed login
|
// PocketBase specific error for failed login
|
||||||
if (e.contains('Failed to authenticate') || e.contains('identity or password')) {
|
if (e.contains('Failed to authenticate') ||
|
||||||
|
e.contains('identity or password')) {
|
||||||
return l10n.errorAuthenticationFailed;
|
return l10n.errorAuthenticationFailed;
|
||||||
}
|
}
|
||||||
return l10n.errorIllegalRequest;
|
return l10n.errorIllegalRequest;
|
||||||
|
|
@ -50,8 +51,8 @@ class ErrorHandler {
|
||||||
backgroundColor: AppTheme.errorColor,
|
backgroundColor: AppTheme.errorColor,
|
||||||
behavior: SnackBarBehavior.floating,
|
behavior: SnackBarBehavior.floating,
|
||||||
duration: const Duration(seconds: 4),
|
duration: const Duration(seconds: 4),
|
||||||
dismissDirection: DismissDirection.horizontal, // Easier to swipe away
|
dismissDirection: DismissDirection.horizontal,
|
||||||
margin: const EdgeInsets.fromLTRB(16, 16, 16, 60), // Move it up to not block navigation
|
margin: const EdgeInsets.fromLTRB(16, 16, 16, 60),
|
||||||
action: SnackBarAction(
|
action: SnackBarAction(
|
||||||
label: 'OK',
|
label: 'OK',
|
||||||
textColor: Colors.white,
|
textColor: Colors.white,
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ class NotificationService {
|
||||||
tz.initializeTimeZones();
|
tz.initializeTimeZones();
|
||||||
|
|
||||||
const AndroidInitializationSettings initializationSettingsAndroid =
|
const AndroidInitializationSettings initializationSettingsAndroid =
|
||||||
AndroidInitializationSettings('@mipmap/ic_launcher');
|
AndroidInitializationSettings('ic_launcher');
|
||||||
|
|
||||||
const DarwinInitializationSettings initializationSettingsDarwin =
|
const DarwinInitializationSettings initializationSettingsDarwin =
|
||||||
DarwinInitializationSettings(
|
DarwinInitializationSettings(
|
||||||
|
|
@ -47,8 +47,17 @@ class NotificationService {
|
||||||
final androidImplementation =
|
final androidImplementation =
|
||||||
_notifications.resolvePlatformSpecificImplementation<
|
_notifications.resolvePlatformSpecificImplementation<
|
||||||
AndroidFlutterLocalNotificationsPlugin>();
|
AndroidFlutterLocalNotificationsPlugin>();
|
||||||
await androidImplementation?.requestNotificationsPermission();
|
|
||||||
await androidImplementation?.requestExactAlarmsPermission();
|
if (androidImplementation != null) {
|
||||||
|
// Request notification permission (Android 13+)
|
||||||
|
await androidImplementation.requestNotificationsPermission();
|
||||||
|
|
||||||
|
// requestExactAlarmsPermission is typically for SCHEDULE_EXACT_ALARM.
|
||||||
|
// Since we use USE_EXACT_ALARM in the manifest for newer versions,
|
||||||
|
// we only request this if absolutely necessary or on older versions if supported.
|
||||||
|
// On Android 13+, USE_EXACT_ALARM is granted at install time.
|
||||||
|
await androidImplementation.requestExactAlarmsPermission();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||||
|
import '../../../shared/data/repositories/user_repository.dart';
|
||||||
|
import '../../../core/utils/notification_service.dart';
|
||||||
|
|
||||||
part 'rest_timer_service.g.dart';
|
part 'rest_timer_service.g.dart';
|
||||||
|
|
||||||
|
|
@ -75,12 +77,21 @@ class RestTimer extends _$RestTimer {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void complete() {
|
void complete() async {
|
||||||
cancel();
|
cancel();
|
||||||
state = state.copyWith(
|
state = state.copyWith(
|
||||||
isActive: false,
|
isActive: false,
|
||||||
remainingSeconds: 0,
|
remainingSeconds: 0,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
final userRepo = ref.read(userRepositoryProvider);
|
||||||
|
final user = await userRepo.getLocalUser();
|
||||||
|
final settings = user?.notificationSettings ?? {};
|
||||||
|
final restEnabled = settings['rest_finished_enabled'] ?? true;
|
||||||
|
|
||||||
|
if (restEnabled) {
|
||||||
|
ref.read(notificationServiceProvider).showRestFinishedNotification();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void cancel() {
|
void cancel() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue