-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Использование GitHub для скачивания загрузочных экранов (#373)
- Loading branch information
Showing
18 changed files
with
553 additions
and
23 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
31 changes: 31 additions & 0 deletions
31
lib/core/services/implementations/feed_file_downloader_impl.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,31 @@ | ||
import 'package:unn_mobile/core/constants/api_url_strings.dart'; | ||
import 'package:unn_mobile/core/constants/session_identifier_strings.dart'; | ||
import 'package:unn_mobile/core/services/implementations/authorisation_service_impl.dart'; | ||
import 'package:unn_mobile/core/services/interfaces/base_file_downloader.dart'; | ||
import 'package:unn_mobile/core/services/interfaces/logger_service.dart'; | ||
|
||
class FeedFileDownloaderImpl extends BaseFileDownloaderService { | ||
final AuthorizationServiceImpl _authorisationService; | ||
FeedFileDownloaderImpl( | ||
LoggerService loggerService, | ||
AuthorizationServiceImpl authorisationService, | ||
) : _authorisationService = authorisationService, | ||
super( | ||
loggerService, | ||
ApiPaths.unnHost, | ||
cookies: { | ||
SessionIdentifierStrings.sessionIdCookieKey: | ||
authorisationService.sessionId ?? '', | ||
}, | ||
) { | ||
_authorisationService.addListener(_updateCookies); | ||
} | ||
|
||
void _updateCookies() { | ||
final newCookie = { | ||
SessionIdentifierStrings.sessionIdCookieKey: | ||
_authorisationService.sessionId ?? '', | ||
}; | ||
super.updateCookies(newCookie); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
lib/core/services/implementations/loading_page/last_commit_sha_impl.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,51 @@ | ||
import 'dart:convert'; | ||
import 'dart:io'; | ||
|
||
import 'package:unn_mobile/core/constants/api_url_strings.dart'; | ||
import 'package:unn_mobile/core/misc/http_helper.dart'; | ||
import 'package:unn_mobile/core/services/interfaces/loading_page/last_commit_sha.dart'; | ||
import 'package:unn_mobile/core/services/interfaces/logger_service.dart'; | ||
|
||
class LastCommitShaImpl implements LastCommitShaService { | ||
final _path = 'repos/${ApiPaths.gitRepository}/commits/main?per_page=1'; | ||
final LoggerService _loggerService; | ||
|
||
LastCommitShaImpl(this._loggerService); | ||
|
||
@override | ||
Future<String?> getSha() async { | ||
final requestSender = HttpRequestSender( | ||
host: ApiPaths.gitHubApiHost, | ||
path: _path, | ||
); | ||
|
||
HttpClientResponse response; | ||
try { | ||
response = await requestSender.get(); | ||
} catch (error, stackTrace) { | ||
_loggerService.log('Exception: $error\nStackTrace: $stackTrace'); | ||
return null; | ||
} | ||
|
||
final statusCode = response.statusCode; | ||
|
||
if (statusCode != 200) { | ||
_loggerService.log( | ||
'statusCode = $statusCode;', | ||
); | ||
return null; | ||
} | ||
|
||
Map<String, dynamic> jsonMap; | ||
|
||
try { | ||
jsonMap = | ||
jsonDecode(await HttpRequestSender.responseToStringBody(response)); | ||
} catch (error, stackTrace) { | ||
_loggerService.logError(error, stackTrace); | ||
return null; | ||
} | ||
|
||
return jsonMap['sha']; | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
lib/core/services/implementations/loading_page/last_commit_sha_provider_impl.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,44 @@ | ||
import 'package:unn_mobile/core/services/interfaces/loading_page/last_commit_sha_provider.dart'; | ||
import 'package:unn_mobile/core/services/interfaces/storage_service.dart'; | ||
|
||
class _LastCommitShaKeys { | ||
static const shaKey = 'sha_key'; | ||
} | ||
|
||
class LastCommitShaProviderImpl implements LastCommitShaProvider { | ||
final StorageService _storage; | ||
|
||
LastCommitShaProviderImpl(this._storage); | ||
|
||
@override | ||
Future<String?> getData() async { | ||
if (!(await isContained())) { | ||
return null; | ||
} | ||
|
||
final sha = await _storage.read( | ||
key: _LastCommitShaKeys.shaKey, | ||
); | ||
|
||
return sha; | ||
} | ||
|
||
@override | ||
Future<void> saveData(String? sha) async { | ||
if (sha == null) { | ||
return; | ||
} | ||
|
||
await _storage.write( | ||
key: _LastCommitShaKeys.shaKey, | ||
value: sha, | ||
); | ||
} | ||
|
||
@override | ||
Future<bool> isContained() async { | ||
return await _storage.containsKey( | ||
key: _LastCommitShaKeys.shaKey, | ||
); | ||
} | ||
} |
Oops, something went wrong.