Skip to content

Commit

Permalink
Merge pull request #237 from Team-Weather/226-ui-common-image-renderi…
Browse files Browse the repository at this point in the history
…ng-improve

Feat: 홈 화면 진입 시 피드 검색 페이지 최초 피드 20개 이미지 프리 캐싱처리
  • Loading branch information
hoogom88 authored Jun 6, 2024
2 parents a6a2611 + 9afb89c commit 9f756f2
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 13 deletions.
2 changes: 2 additions & 0 deletions lib/core/di/di_setup.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:weaco/core/di/user/user_di_setup.dart';
import 'package:weaco/core/di/weather/weather_di_setup.dart';
import 'package:weaco/domain/feed/use_case/get_my_page_feeds_use_case.dart';
import 'package:weaco/domain/feed/use_case/get_recommended_feeds_use_case.dart';
import 'package:weaco/domain/feed/use_case/get_search_feeds_use_case.dart';
import 'package:weaco/domain/feed/use_case/remove_my_page_feed_use_case.dart';
import 'package:weaco/domain/user/repository/user_auth_repository.dart';
import 'package:weaco/domain/user/use_case/get_my_profile_use_case.dart';
Expand Down Expand Up @@ -61,6 +62,7 @@ void diSetup() {
getDailyLocationWeatherUseCase: getIt<GetDailyLocationWeatherUseCase>(),
getBackgroundImageListUseCase: getIt<GetBackgroundImageListUseCase>(),
getRecommendedFeedsUseCase: getIt<GetRecommendedFeedsUseCase>(),
getSearchFeedsUseCase: getIt<GetSearchFeedsUseCase>(),
),
);

Expand Down
1 change: 1 addition & 0 deletions lib/presentation/common/component/cached_image_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class CachedImageWidget extends StatelessWidget {
return CachedNetworkImage(
fit: _boxFit ?? BoxFit.cover,
imageUrl: _imageUrl,
// Flip Card 위젯 높이와 동일 = 16 * 35
memCacheHeight: (16 * 35).cacheSize(context),
progressIndicatorBuilder: (context, url, downloadProgress) =>
_progressIndicatorBuilder ??
Expand Down
22 changes: 9 additions & 13 deletions lib/presentation/home/component/recommend_ootd_list_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,17 @@ class RecommendOotdListWidget extends StatelessWidget {
),
)
: Expanded(
child: ListView.builder(
child: ListView(
scrollDirection: Axis.horizontal,
itemCount: feedList.length,
itemBuilder: (context, index) {
return GestureDetector(
onTap: () => RouterStatic.pushToOotdDetail(
children: feedList.indexed.map((e) => GestureDetector(
onTap: () => RouterStatic.pushToOotdDetail(
context,
feed: feedList[index]
),
child: RecommendOotdWidget(
feedList: feedList,
index: index,
),
);
},
feed: e.$2),
child: RecommendOotdWidget(
feedList: feedList,
index: e.$1,
),
)).toList()
),
),
],
Expand Down
8 changes: 8 additions & 0 deletions lib/presentation/home/screen/home_screen.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:weaco/core/util/reaction_util.dart';
import 'package:weaco/domain/feed/model/feed.dart';
import 'package:weaco/presentation/common/style/image_path.dart';
import 'package:weaco/core/enum/weather_code.dart';
import 'package:weaco/presentation/common/enum/exception_alert.dart';
Expand All @@ -26,6 +28,12 @@ class _HomeScreenState extends State<HomeScreen> {
Future.microtask(
() async {
await context.read<HomeScreenViewModel>().initHomeScreen();
if (mounted) {
final tmp = context.read<HomeScreenViewModel>().precacheList;
for (Feed e in tmp) {
await precacheImage(CachedNetworkImageProvider(e.thumbnailImagePath), context);
}
}
},
);
}
Expand Down
6 changes: 6 additions & 0 deletions lib/presentation/home/view_model/home_screen_view_model.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:weaco/domain/feed/use_case/get_search_feeds_use_case.dart';
import 'package:weaco/presentation/common/style/image_path.dart';
import 'package:weaco/core/enum/weather_code.dart';
import 'package:weaco/domain/feed/model/feed.dart';
Expand Down Expand Up @@ -26,16 +27,19 @@ class HomeScreenViewModel with ChangeNotifier {
required this.getDailyLocationWeatherUseCase,
required this.getBackgroundImageListUseCase,
required this.getRecommendedFeedsUseCase,
required this.getSearchFeedsUseCase,
});

final GetDailyLocationWeatherUseCase getDailyLocationWeatherUseCase;
final GetBackgroundImageListUseCase getBackgroundImageListUseCase;
final GetRecommendedFeedsUseCase getRecommendedFeedsUseCase;
final GetSearchFeedsUseCase getSearchFeedsUseCase;

DailyLocationWeather? _dailyLocationWeather;
Weather? _currentWeather;
List<Weather> _weatherByTimeList = [];
List<Feed> _feedList = [];
List<Feed> _precacheList = [];
HomeScreenStatus _status = HomeScreenStatus.idle;
// 전일 대비 온도차
double? _temperatureGap;
Expand All @@ -45,6 +49,7 @@ class HomeScreenViewModel with ChangeNotifier {
Weather? get currentWeather => _currentWeather;
double? get temperatureGap => _temperatureGap ?? 0;
List<Feed> get feedList => _feedList;
List<Feed> get precacheList => _precacheList;
HomeScreenStatus get status => _status;
String get backgroundImagePath =>
_weatherBackgroundImage ?? ImagePath.homeBackgroundSunny;
Expand All @@ -62,6 +67,7 @@ class HomeScreenViewModel with ChangeNotifier {
_feedList = await getRecommendedFeedsUseCase.execute(
dailyLocationWeather: _dailyLocationWeather!,
);
_precacheList = await getSearchFeedsUseCase.execute();

if (_dailyLocationWeather != null) {
// 현재 시간에 맞는 날씨 예보 빼내기
Expand Down

0 comments on commit 9f756f2

Please sign in to comment.