Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: 홈 화면 진입 시 피드 검색 페이지 최초 피드 20개 이미지 프리 캐싱처리 #237

Merged
merged 3 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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