diff --git a/lib/src/constants/config.dart b/lib/src/constants/config.dart index f433d31..74c5c18 100644 --- a/lib/src/constants/config.dart +++ b/lib/src/constants/config.dart @@ -4,24 +4,10 @@ class AppConfig { static const int databaseVersion = 1; static const String databaseVersionKey = "isarVersionKey"; - /// keys static const Duration maxCacheAge = Duration(minutes: 5); //30 - static const String dioCacheForceRefreshKey = 'dio_cache_force_refresh_key'; static const String dioNeedToCacheKey = 'dio_need_to_cache_key'; - // Theme key to store and retrieve user preferred theme - static const String themeModeKey = "theme"; - // Appcolor key to store and retrieve user preferred appcolor - static const String appColorKey = "appColor"; - /// API url static const String baseUrl = 'https://shikimori.me/api/'; static const String staticUrl = 'https://shikimori.me'; - //final kStaticUrl = Uri.parse('https://shikimori.one'); - - // static const String trendingUrl = "trending"; - // static const String popularUrl = "popular"; - // static const String searchUrl = "advanced-search"; - // static const String infoUrl = "info"; - // static const String watchUrl = "watch"; } diff --git a/lib/src/constants/hive_keys.dart b/lib/src/constants/hive_keys.dart index 06160d9..81f306a 100644 --- a/lib/src/constants/hive_keys.dart +++ b/lib/src/constants/hive_keys.dart @@ -4,7 +4,3 @@ const String dynamicThemeKey = 'key_dynamic_color'; const String oledModeKey = 'key_oled_mode'; const String playerDiscordRpc = 'key_player_discord_rpc'; - -const String userNameKey = 'user_name_key'; -const String userIntroKey = 'user_intro_key'; -const String userImageKey = 'user_image_key'; diff --git a/lib/src/presentation/widgets/app_theme_builder.dart b/lib/src/presentation/widgets/app_theme_builder.dart index 540bd0f..2a92636 100644 --- a/lib/src/presentation/widgets/app_theme_builder.dart +++ b/lib/src/presentation/widgets/app_theme_builder.dart @@ -38,12 +38,5 @@ class AppThemeBuilder extends ConsumerWidget { ); }, ); - // final appTheme = ref.watch(appThemeDataProvider); - // return DynamicColorBuilder( - // builder: (light, dark) => builder( - // context, - // appTheme.fillWith(light: light, dark: dark, useMonet: true), - // ), - // ); } } diff --git a/lib/src/services/anime_database/anime_database_service.dart b/lib/src/services/anime_database/anime_database_service.dart index c6bf525..1c0d451 100644 --- a/lib/src/services/anime_database/anime_database_service.dart +++ b/lib/src/services/anime_database/anime_database_service.dart @@ -19,7 +19,6 @@ class LocalAnimeDatabaseImpl implements LocalAnimeDatabaseRepo { LocalAnimeDatabaseImpl(this.isardb); static Future initialization() async { - //final appDocDir = await path_prov.getApplicationDocumentsDirectory(); final appDocDir = await path_prov.getApplicationSupportDirectory(); return LocalAnimeDatabaseImpl( await Isar.open( @@ -33,8 +32,6 @@ class LocalAnimeDatabaseImpl implements LocalAnimeDatabaseRepo { @override Stream> getLocalAnimes() { - // Query animeList = - // isardb.animeDatabases.where(sort: Sort.asc).build(); Query animeList = isardb.animeDatabases.where().sortByLastUpdateDesc().build(); return animeList.watch(fireImmediately: true); diff --git a/lib/src/services/http/dio_service.dart b/lib/src/services/http/dio_service.dart index 6b20099..cc5b8ce 100644 --- a/lib/src/services/http/dio_service.dart +++ b/lib/src/services/http/dio_service.dart @@ -50,7 +50,6 @@ class DioHttpService implements HttpService { // }, // )); // } - //dio.interceptors.add(DioNetworkLogger()); dio.interceptors.add(RetryInterceptor( dio: dio, logPrint: log, @@ -60,7 +59,6 @@ class DioHttpService implements HttpService { ], )); - //dio.interceptors.add(CustomInterceptors()); dio.interceptors.add(CacheInterceptor(storageService)); dio.interceptors.add(RefreshTokenInterceptor(dio)); dio.interceptors.add(RequestInterceptors(dio)); @@ -84,15 +82,10 @@ class DioHttpService implements HttpService { //dio.addSentry(); } - /// Storage service used for caching http responses final CacheStorageRepo storageService; - - /// The Dio Http client late final Dio dio; - /// The Dio base options BaseOptions get baseOptions => BaseOptions( - //receiveDataWhenStatusError: true, baseUrl: baseUrl, headers: headers, connectTimeout: const Duration(seconds: 12), @@ -104,19 +97,13 @@ class DioHttpService implements HttpService { @override String get baseUrl => AppConfig.baseUrl; - // Default headers @override Map headers = { - //'User-Agent': 'Shikimori Flutter App', - //'User-Agent': 'Shikimori Flutter Windows App', 'User-Agent': TargetP.instance.userAgent, - //'accept': 'application/json', - //'content-type': 'application/json' }; /// GET method @override - // Future> get(String endpoint, Future get(String endpoint, {Map? queryParameters, Options? options, @@ -130,11 +117,6 @@ class DioHttpService implements HttpService { endpoint, queryParameters: queryParameters, options: options, - // options: Options( - // headers: { - // 'Authorization': 'Bearer $token', - // }, - // ), cancelToken: cancelToken, ); return response.data; @@ -217,18 +199,6 @@ class DioHttpService implements HttpService { .delete(endpoint, options: options) .then((value) => value.statusCode?.clamp(200, 299) == value.statusCode) .onError((_, __) => false); - // try { - // var response = await dio.delete( - // endpoint, - // data: data, - // queryParameters: queryParameters, - // options: options, - // cancelToken: cancelToken, - // ); - // return response.data; - // } catch (e) { - // rethrow; - // } } } diff --git a/lib/src/services/http/interceptors/cache_interceptor.dart b/lib/src/services/http/interceptors/cache_interceptor.dart index 3cdfb41..6d6a695 100644 --- a/lib/src/services/http/interceptors/cache_interceptor.dart +++ b/lib/src/services/http/interceptors/cache_interceptor.dart @@ -60,20 +60,20 @@ class CacheInterceptor implements Interceptor { ); if (options.extra[AppConfig.dioNeedToCacheKey] == false) { - log('(onRequest) Does not need caching', name: 'CacheInterceptor'); + //log('(onRequest) Does not need caching', name: 'CacheInterceptor'); if (cacheStorageService.has(storageKey)) { - log('(onRequest) Delete responce from caching', - name: 'CacheInterceptor'); + // log('(onRequest) Delete responce from caching', + // name: 'CacheInterceptor'); cacheStorageService.remove(storageKey); } return handler.next(options); } if (options.extra[AppConfig.dioCacheForceRefreshKey] == true) { - log('(onRequest) Cache Force Refresh', name: 'CacheInterceptor'); + //log('(onRequest) Cache Force Refresh', name: 'CacheInterceptor'); if (cacheStorageService.has(storageKey)) { - log('(onRequest) Delete responce from caching', - name: 'CacheInterceptor'); + // log('(onRequest) Delete responce from caching', + // name: 'CacheInterceptor'); cacheStorageService.remove(storageKey); } return handler.next(options); @@ -82,7 +82,7 @@ class CacheInterceptor implements Interceptor { if (cacheStorageService.has(storageKey)) { final cachedResponse = _getCachedResponse(storageKey); if (cachedResponse != null) { - log('(onRequest) Get response from cache', name: 'CacheInterceptor'); + //log('(onRequest) Get response from cache', name: 'CacheInterceptor'); final response = cachedResponse.buildResponse(options); return handler.resolve(response); } @@ -118,7 +118,7 @@ class CacheInterceptor implements Interceptor { ResponseInterceptorHandler handler, ) { if (response.requestOptions.extra[AppConfig.dioNeedToCacheKey] == false) { - log('(onResponse) Does not need caching', name: 'CacheInterceptor'); + //log('(onResponse) Does not need caching', name: 'CacheInterceptor'); return handler.next(response); } @@ -131,7 +131,7 @@ class CacheInterceptor implements Interceptor { if (response.requestOptions.extra[AppConfig.dioCacheForceRefreshKey] == true) { - log('(onResponse) Cache Force Refresh', name: 'CacheInterceptor'); + //log('(onResponse) Cache Force Refresh', name: 'CacheInterceptor'); return handler.next(response); } @@ -144,7 +144,7 @@ class CacheInterceptor implements Interceptor { age: DateTime.now(), statusCode: response.statusCode!, ); - log('Save response to cache', name: 'CacheInterceptor'); + //log('Save response to cache', name: 'CacheInterceptor'); cacheStorageService.set(storageKey, cachedResponse.toJson()); } return handler.next(response); @@ -159,12 +159,12 @@ class CacheInterceptor implements Interceptor { if (cachedResponse.isValid) { return cachedResponse; } else { - log('Cache is outdated, deleting it...', name: 'CacheInterceptor'); + //log('Cache is outdated, deleting it...', name: 'CacheInterceptor'); cacheStorageService.remove(storageKey); return null; } } catch (e) { - log('Error retrieving response from cache', name: 'CacheInterceptor'); + //log('Error retrieving response from cache', name: 'CacheInterceptor'); log('e: $e'); return null; } diff --git a/lib/src/services/http/interceptors/refresh_token_interceptor.dart b/lib/src/services/http/interceptors/refresh_token_interceptor.dart index 8350288..f0c82af 100644 --- a/lib/src/services/http/interceptors/refresh_token_interceptor.dart +++ b/lib/src/services/http/interceptors/refresh_token_interceptor.dart @@ -18,7 +18,7 @@ class RefreshTokenInterceptor extends Interceptor { return handler.next(err); } if (err.response!.statusCode == 401) { - log('RefreshTokenInterceptor:: statusCode == 401'); + //log('RefreshTokenInterceptor:: statusCode == 401'); var res = await refreshToken(); if (res != null) { await _retry(err.requestOptions, res); @@ -29,49 +29,25 @@ class RefreshTokenInterceptor extends Interceptor { GoRouter.of(ctx!).go('/login'); } } - //super.onError(err, handler); return handler.next(err); } - /// Api to get new token from refresh token - /// Future refreshToken() async { - log('RefreshTokenInterceptor:: refreshToken'); + //log('RefreshTokenInterceptor:: refreshToken'); - ///call your refesh token api here final token = await OAuthService.instance.refreshToken(); return token; - - // if (await OAuthService.instance.refreshToken()) { - // return true; - // } - // return null; } - /// For retrying request with new token - /// Future> _retry( RequestOptions requestOptions, String newToken) async { log('RefreshTokenInterceptor:: _retry'); - // final options = Options( - // method: requestOptions.method, - // headers: requestOptions.headers, - // ); - - // final options = requestOptions.copyWith( - // headers: { - // 'User-Agent': 'Shikimori Flutter App', - // 'Authorization': 'Bearer $newToken', - // }, - // ); final options = Options( method: requestOptions.method, responseType: requestOptions.responseType, headers: { - //'User-Agent': 'Shikimori Flutter App', - //'User-Agent': 'Shikimori Flutter Windows App', 'User-Agent': TargetP.instance.userAgent, 'Authorization': 'Bearer $newToken', }, diff --git a/lib/src/services/http/interceptors/request_interceptor.dart b/lib/src/services/http/interceptors/request_interceptor.dart index 97ce907..a241eed 100644 --- a/lib/src/services/http/interceptors/request_interceptor.dart +++ b/lib/src/services/http/interceptors/request_interceptor.dart @@ -12,34 +12,15 @@ class RequestInterceptors extends Interceptor { void onRequest( RequestOptions options, RequestInterceptorHandler handler) async { ConnectivityResult connectivity = await Connectivity().checkConnectivity(); - if (connectivity == ConnectivityResult.none - //&& - // options.extra[AppConfig.dioNeedToCacheKey] == false - ) { + if (connectivity == ConnectivityResult.none) { handler.reject( NoInternetConnectionException(options), - // DioError( - // requestOptions: options, - // message: 'No internet connection detected', - // type: DioErrorType.connectionError), ); return; - //throw NoInternetConnectionException(options); } super.onRequest(options, handler); - //return handler.next(options); } - // @override - // void onResponse( - // Response response, - // ResponseInterceptorHandler handler, - // ) { - // final code = response.statusCode; - // log('::onResponse -> code: $code'); - // return handler.next(response); - // } - @override void onError(DioError err, ErrorInterceptorHandler handler) { switch (err.type) { @@ -85,7 +66,6 @@ class BadResponceErrorException extends DioError { @override String toString() { - // return 'Host or unknown error'; return 'Код ошибки 422 (Bad Responce)'; } } @@ -95,7 +75,6 @@ class UnknownErrorException extends DioError { @override String toString() { - // return 'Host or unknown error'; return 'Скорее всего Shikimori недоступен, попробуй позже'; } } @@ -141,7 +120,6 @@ class NotFoundException extends DioError { @override String toString() { - // return 'The requested information could not be found bebra'; return 'Ошибка 404. Ничего не найдено'; } } diff --git a/lib/src/services/oauth/oauth_service.dart b/lib/src/services/oauth/oauth_service.dart index 2271741..3e348f9 100644 --- a/lib/src/services/oauth/oauth_service.dart +++ b/lib/src/services/oauth/oauth_service.dart @@ -11,12 +11,7 @@ import '../secure_storage/secure_storage_service.dart'; class OAuthService { static OAuthService instance = OAuthService(); - // String userAgent = TargetP.instance.isDesktop - // ? 'Shikimori Flutter Windows App' - // : 'Shikimori Flutter App'; - Map headers = { - //'User-Agent': 'Shikimori Flutter App', 'User-Agent': TargetP.instance.isDesktop ? 'Shikimori Flutter Windows App' : 'Shikimori Flutter App', @@ -72,8 +67,6 @@ class OAuthService { '/oauth/token', { 'grant_type': 'refresh_token', - // 'client_id': kShikiClientId, - // 'client_secret': kShikiClientSecret, 'client_id': TargetP.instance.isDesktop ? kShikiClientIdDesktop : kShikiClientId, @@ -116,8 +109,6 @@ class OAuthService { final Uri userUrl = Uri.https('shikimori.me', 'api/users/whoami'); final Map headers = { - //'User-Agent': 'Shikimori Flutter App', - //'User-Agent': 'Shikimori Flutter Windows App', 'User-Agent': TargetP.instance.isDesktop ? 'Shikimori Flutter Windows App' : 'Shikimori Flutter App',