Skip to content

Commit

Permalink
Merge pull request #1779 from bitmark-inc/use_cache_pub
Browse files Browse the repository at this point in the history
Use cache pub
  • Loading branch information
phuocbitmark authored Jun 24, 2024
2 parents c40d037 + 3af4923 commit 07cebb8
Show file tree
Hide file tree
Showing 25 changed files with 401 additions and 197 deletions.
3 changes: 3 additions & 0 deletions lib/common/injector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,12 @@ import 'package:autonomy_flutter/service/tezos_beacon_service.dart';
import 'package:autonomy_flutter/service/tezos_service.dart';
import 'package:autonomy_flutter/service/versions_service.dart';
import 'package:autonomy_flutter/service/wc2_service.dart';
import 'package:autonomy_flutter/util/au_file_service.dart';
import 'package:autonomy_flutter/util/dio_interceptors.dart';
import 'package:autonomy_flutter/util/dio_util.dart';
import 'package:autonomy_flutter/util/log.dart';
import 'package:dio/dio.dart';
import 'package:flutter_cache_manager/flutter_cache_manager.dart';
import 'package:get_it/get_it.dart';
import 'package:http/http.dart';
import 'package:logging/logging.dart';
Expand Down Expand Up @@ -185,6 +187,7 @@ Future<void> setup() async {
.registerLazySingleton<MetricClientService>(() => MetricClientService());
injector.registerLazySingleton<MixPanelClientService>(
() => MixPanelClientService(injector(), injector()));
injector.registerLazySingleton<CacheManager>(() => AUImageCacheManage());
injector.registerLazySingleton<AccountService>(() => AccountServiceImpl(
cloudDB,
injector(),
Expand Down
2 changes: 2 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import 'package:autonomy_flutter/service/metric_client_service.dart';
import 'package:autonomy_flutter/service/navigation_service.dart';
import 'package:autonomy_flutter/service/notification_service.dart';
import 'package:autonomy_flutter/service/remote_config_service.dart';
import 'package:autonomy_flutter/util/au_file_service.dart';
import 'package:autonomy_flutter/util/custom_route_observer.dart';
import 'package:autonomy_flutter/util/device.dart';
import 'package:autonomy_flutter/util/error_handler.dart';
Expand Down Expand Up @@ -93,6 +94,7 @@ Future<void> runFeralFileApp() async {
_registerHiveAdapter();

FlutterDownloader.registerCallback(downloadCallback);
await AuFileService().setup();

OneSignal.shared.setLogLevel(OSLogLevel.error, OSLogLevel.none);
OneSignal.shared.setAppId(Environment.onesignalAppID);
Expand Down
8 changes: 4 additions & 4 deletions lib/screen/chat/chat_thread_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ import 'package:autonomy_flutter/util/style.dart';
import 'package:autonomy_flutter/view/back_appbar.dart';
import 'package:autonomy_flutter/view/postcard_chat.dart';
import 'package:autonomy_flutter/view/responsive.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:feralfile_app_theme/extensions/theme_extension/moma_sans.dart';
import 'package:feralfile_app_theme/feral_file_app_theme.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_chat_types/flutter_chat_types.dart' as types;
import 'package:flutter_chat_ui/flutter_chat_ui.dart';

//ignore: implementation_imports
import 'package:flutter_chat_ui/src/models/date_header.dart';
import 'package:flutter_svg/flutter_svg.dart';
Expand Down Expand Up @@ -581,9 +581,9 @@ class UserAvatar extends StatelessWidget {
Widget build(BuildContext context) => SizedBox(
width: 41,
height: 41,
child: Image.network(
url,
errorBuilder: (context, url, error) =>
child: CachedNetworkImage(
imageUrl: url,
errorWidget: (context, url, error) =>
SvgPicture.asset('assets/images/default_avatar.svg'),
));
}
Expand Down
36 changes: 18 additions & 18 deletions lib/screen/exhibitions/exhibitions_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ import 'package:autonomy_flutter/util/style.dart';
import 'package:autonomy_flutter/view/back_appbar.dart';
import 'package:autonomy_flutter/view/header.dart';
import 'package:autonomy_flutter/view/primary_button.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:feralfile_app_theme/feral_file_app_theme.dart';
import 'package:feralfile_app_tv_proto/feralfile_app_tv_proto.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_cache_manager/flutter_cache_manager.dart';
import 'package:flutter_svg/flutter_svg.dart';

class ExhibitionsPage extends StatefulWidget {
Expand Down Expand Up @@ -176,26 +178,24 @@ class ExhibitionsPageState extends State<ExhibitionsPage> with RouteAware {
),
),
)
: Image.network(
exhibition.coverUrl,
: CachedNetworkImage(
imageUrl: exhibition.coverUrl,
height: estimatedHeight,
cacheWidth: estimatedWidth.toInt(),
cacheHeight: estimatedHeight.toInt(),
loadingBuilder: (context, child, loadingProgress) {
if (loadingProgress == null) {
return child;
}
return SizedBox(
height: estimatedHeight,
child: const Center(
child: CircularProgressIndicator(
color: Colors.white,
backgroundColor: AppColor.auQuickSilver,
strokeWidth: 2,
),
maxWidthDiskCache: estimatedWidth.toInt(),
memCacheWidth: estimatedWidth.toInt(),
memCacheHeight: estimatedHeight.toInt(),
maxHeightDiskCache: estimatedHeight.toInt(),
cacheManager: injector<CacheManager>(),
placeholder: (context, url) => SizedBox(
height: estimatedHeight,
child: const Center(
child: CircularProgressIndicator(
color: Colors.white,
backgroundColor: AppColor.auQuickSilver,
strokeWidth: 2,
),
);
},
),
),
fit: BoxFit.fitWidth,
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import 'package:autonomy_flutter/util/number_formater.dart';
import 'package:autonomy_flutter/util/style.dart';
import 'package:autonomy_flutter/view/skeleton.dart';
import 'package:autonomy_flutter/view/tappable_forward_row.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:feralfile_app_theme/extensions/theme_extension/moma_sans.dart';
import 'package:feralfile_app_theme/feral_file_app_theme.dart';
Expand Down Expand Up @@ -182,8 +183,8 @@ class _PostcardLeaderboardViewState extends State<PostcardLeaderboardView> {
SizedBox(
height: 65,
width: 85,
child: Image.network(
leaderBoardItem.previewUrl,
child: CachedNetworkImage(
imageUrl: leaderBoardItem.previewUrl,
fit: BoxFit.fitWidth,
),
),
Expand Down
7 changes: 4 additions & 3 deletions lib/screen/irl_screen/sign_message_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import 'package:autonomy_flutter/util/wallet_storage_ext.dart';
import 'package:autonomy_flutter/view/back_appbar.dart';
import 'package:autonomy_flutter/view/primary_button.dart';
import 'package:autonomy_flutter/view/responsive.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:collection/collection.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:feralfile_app_theme/feral_file_app_theme.dart';
Expand Down Expand Up @@ -244,11 +245,11 @@ class _IRLSignMessageScreenState extends State<IRLSignMessageScreen> {
? Row(
children: [
if (icons != null && icons.isNotEmpty) ...[
Image.network(
icons.first,
CachedNetworkImage(
imageUrl: icons.first,
width: 64,
height: 64,
errorBuilder: (context, url, error) => const SizedBox(
errorWidget: (context, url, error) => const SizedBox(
width: 64,
height: 64,
),
Expand Down
15 changes: 9 additions & 6 deletions lib/screen/playlists/list_playlists/list_playlists.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ import 'package:autonomy_flutter/screen/playlists/view_playlist/view_playlist.da
import 'package:autonomy_flutter/service/configuration_service.dart';
import 'package:autonomy_flutter/util/au_icons.dart';
import 'package:autonomy_flutter/util/collection_ext.dart';
import 'package:autonomy_flutter/view/image_background.dart';
import 'package:autonomy_flutter/view/artwork_common_widget.dart';
import 'package:autonomy_flutter/view/stream_common_widget.dart';
import 'package:autonomy_flutter/view/title_text.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:feralfile_app_theme/feral_file_app_theme.dart';
import 'package:feralfile_app_tv_proto/feralfile_app_tv_proto.dart';
import 'package:flutter/material.dart';
import 'package:flutter_cache_manager/flutter_cache_manager.dart';

class ListPlaylistsScreen extends StatefulWidget {
final ValueNotifier<List<PlayListModel>?> playlists;
Expand Down Expand Up @@ -220,12 +222,13 @@ class _PlaylistItemState extends State<PlaylistItem> {
height: double.infinity,
color: theme.disableColor,
)
: Image.network(
thumbnailURL,
: CachedNetworkImage(
imageUrl: thumbnailURL,
fit: BoxFit.cover,
loadingBuilder: (context, child, loadingProgress) =>
ImageBackground(child: child),
errorBuilder: (context, url, error) => Container(
cacheManager: injector<CacheManager>(),
placeholder: (context, url) =>
const GalleryThumbnailPlaceholder(),
errorWidget: (context, url, error) => Container(
width: double.infinity,
height: double.infinity,
color: theme.disableColor,
Expand Down
5 changes: 3 additions & 2 deletions lib/screen/settings/data_management/data_management_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import 'package:autonomy_flutter/screen/bloc/identity/identity_bloc.dart';
import 'package:autonomy_flutter/screen/settings/forget_exist/forget_exist_bloc.dart';
import 'package:autonomy_flutter/screen/settings/forget_exist/forget_exist_view.dart';
import 'package:autonomy_flutter/service/client_token_service.dart';
import 'package:autonomy_flutter/util/cache_manager.dart';
import 'package:autonomy_flutter/util/error_handler.dart';
import 'package:autonomy_flutter/util/style.dart';
import 'package:autonomy_flutter/util/ui_helper.dart';
Expand All @@ -24,6 +23,7 @@ import 'package:easy_localization/easy_localization.dart';
import 'package:feralfile_app_theme/feral_file_app_theme.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_cache_manager/flutter_cache_manager.dart';
import 'package:nft_collection/nft_collection.dart';
import 'package:nft_collection/services/tokens_service.dart';

Expand Down Expand Up @@ -129,7 +129,8 @@ class _DataManagementPageState extends State<DataManagementPage> {
'rebuild'.tr(),
() async {
await injector<TokensService>().purgeCachedGallery();
CacheManager.cleanCache();
await injector<CacheManager>().emptyCache();
await DefaultCacheManager().emptyCache();
await injector<ClientTokenService>().refreshTokens(syncAddresses: true);
NftCollectionBloc.eventController
.add(GetTokensByOwnerEvent(pageKey: PageKey.init()));
Expand Down
5 changes: 3 additions & 2 deletions lib/screen/settings/forget_exist/forget_exist_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ import 'package:autonomy_flutter/service/auth_service.dart';
import 'package:autonomy_flutter/service/autonomy_service.dart';
import 'package:autonomy_flutter/service/configuration_service.dart';
import 'package:autonomy_flutter/service/metric_client_service.dart';
import 'package:autonomy_flutter/util/cache_manager.dart';
import 'package:autonomy_flutter/util/migration/migration_util.dart';
import 'package:autonomy_flutter/util/notification_util.dart';
import 'package:flutter/material.dart';
import 'package:flutter_cache_manager/flutter_cache_manager.dart';
import 'package:nft_collection/database/nft_collection_database.dart';
import 'package:package_info_plus/package_info_plus.dart';

Expand Down Expand Up @@ -74,7 +74,8 @@ class ForgetExistBloc extends AuBloc<ForgetExistEvent, ForgetExistState> {
await _configurationService.removeAll();

_authService.reset();
CacheManager.cleanCache();
unawaited(injector<CacheManager>().emptyCache());
unawaited(DefaultCacheManager().emptyCache());
unawaited(injector<MetricClientService>().mixPanelClient.reset());
memoryValues = MemoryValues(
branchDeeplinkData: ValueNotifier(null),
Expand Down
27 changes: 13 additions & 14 deletions lib/screen/settings/hidden_artworks/hidden_artworks_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ import 'package:autonomy_flutter/util/style.dart';
import 'package:autonomy_flutter/util/ui_helper.dart';
import 'package:autonomy_flutter/view/artwork_common_widget.dart';
import 'package:autonomy_flutter/view/back_appbar.dart';
import 'package:autonomy_flutter/view/image_background.dart';
import 'package:autonomy_flutter/view/responsive.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:feralfile_app_theme/feral_file_app_theme.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_cache_manager/flutter_cache_manager.dart';
import 'package:nft_collection/models/asset_token.dart';
import 'package:nft_collection/nft_collection.dart';
import 'package:nft_rendering/nft_rendering.dart';
Expand Down Expand Up @@ -162,15 +163,18 @@ class _HiddenArtworksPageState extends State<HiddenArtworksPage> {
unsupportWidgetBuilder: (context) =>
const GalleryUnSupportThumbnailWidget(),
)
: Image.network(
thumbnailUrl,
: CachedNetworkImage(
imageUrl: thumbnailUrl,
width: double.infinity,
height: double.infinity,
fit: BoxFit.cover,
cacheHeight: _cachedImageSize,
cacheWidth: _cachedImageSize,
loadingBuilder: _loadingBuilder,
errorBuilder: (context, url, error) =>
cacheManager: injector<CacheManager>(),
maxHeightDiskCache: _cachedImageSize,
maxWidthDiskCache: _cachedImageSize,
memCacheHeight: _cachedImageSize,
memCacheWidth: _cachedImageSize,
placeholder: _loadingBuilder,
errorWidget: (context, url, error) =>
const GalleryThumbnailErrorWidget(),
),
),
Expand Down Expand Up @@ -218,11 +222,6 @@ class _HiddenArtworksPageState extends State<HiddenArtworksPage> {
);
}

Widget _loadingBuilder(
BuildContext context, Widget child, ImageChunkEvent? loadingProgress) {
if (loadingProgress == null) {
return ImageBackground(child: child);
}
return const GalleryThumbnailPlaceholder();
}
Widget _loadingBuilder(BuildContext context, url) =>
const GalleryThumbnailPlaceholder();
}
7 changes: 4 additions & 3 deletions lib/screen/tezos_beacon/au_sign_message_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import 'package:autonomy_flutter/util/wc2_ext.dart';
import 'package:autonomy_flutter/view/back_appbar.dart';
import 'package:autonomy_flutter/view/primary_button.dart';
import 'package:autonomy_flutter/view/responsive.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:feralfile_app_theme/feral_file_app_theme.dart';
import 'package:flutter/material.dart';
Expand Down Expand Up @@ -215,11 +216,11 @@ class _AUSignMessagePageState extends State<AUSignMessagePage> {
? Row(
children: [
if (proposer.icons.isNotEmpty) ...[
Image.network(
proposer.icons.first,
CachedNetworkImage(
imageUrl: proposer.icons.first,
width: 64,
height: 64,
errorBuilder: (context, url, error) => SizedBox(
errorWidget: (context, url, error) => SizedBox(
width: 64,
height: 64,
child: SvgPicture.asset(
Expand Down
7 changes: 4 additions & 3 deletions lib/screen/tezos_beacon/tb_sign_message_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import 'package:autonomy_flutter/util/wallet_storage_ext.dart';
import 'package:autonomy_flutter/view/back_appbar.dart';
import 'package:autonomy_flutter/view/primary_button.dart';
import 'package:autonomy_flutter/view/responsive.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:collection/collection.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:feralfile_app_theme/feral_file_app_theme.dart';
Expand Down Expand Up @@ -230,11 +231,11 @@ class _TBSignMessagePageState extends State<TBSignMessagePage> {
return Row(
children: [
if (request.icon != null)
Image.network(
request.icon!,
CachedNetworkImage(
imageUrl: request.icon!,
width: 64,
height: 64,
errorBuilder: (context, url, error) => SvgPicture.asset(
errorWidget: (context, url, error) => SvgPicture.asset(
'assets/images/tezos_social_icon.svg',
width: 64,
height: 64,
Expand Down
7 changes: 4 additions & 3 deletions lib/screen/wallet_connect/v2/wc2_permission_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import 'package:autonomy_flutter/view/back_appbar.dart';
import 'package:autonomy_flutter/view/list_address_account.dart';
import 'package:autonomy_flutter/view/primary_button.dart';
import 'package:autonomy_flutter/view/responsive.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:collection/collection.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:feralfile_app_theme/feral_file_app_theme.dart';
Expand Down Expand Up @@ -191,11 +192,11 @@ class _Wc2RequestPageState extends State<Wc2RequestPage>
return Row(
children: [
if (peerMeta.icons.isNotEmpty) ...[
Image.network(
peerMeta.icons.first,
CachedNetworkImage(
imageUrl: peerMeta.icons.first,
width: 64,
height: 64,
errorBuilder: (context, url, error) => SizedBox(
errorWidget: (context, url, error) => SizedBox(
width: 64,
height: 64,
child: Image.asset(
Expand Down
Loading

0 comments on commit 07cebb8

Please sign in to comment.