fix(ad): 스크린샷 모드에서 네이티브 광고 비활성화

This commit is contained in:
JiWoong Sul
2025-12-04 16:29:32 +09:00
parent 04b1c3e987
commit bcc26f5e79
11 changed files with 1037 additions and 230 deletions

View File

@@ -1,3 +1,5 @@
import 'dart:math';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:lunchpick/domain/entities/recommendation_record.dart';
import 'package:lunchpick/domain/entities/restaurant.dart';
@@ -25,6 +27,76 @@ final todayRecommendationCountProvider = FutureProvider<int>((ref) async {
return repository.getTodayRecommendationCount();
});
Future<bool> _isScreenshotModeEnabled(Ref ref) async {
try {
return await ref.read(screenshotModeEnabledProvider.future);
} catch (_) {
return false;
}
}
Restaurant _buildScreenshotRestaurant() {
final now = DateTime.now();
final random = Random();
final templates = [
(
id: 'screenshot-basil-bistro',
name: 'Basil Breeze Bistro',
category: '양식',
subCategory: '파스타 · 그릴',
description: '바질 향이 가득한 파스타와 스테이크를 즐길 수 있는 다이닝.',
phoneNumber: '02-1234-5678',
roadAddress: '서울 중구 세종대로 110',
jibunAddress: '서울 중구 태평로1가 31',
latitude: 37.5665,
longitude: 126.9780,
),
(
id: 'screenshot-komorebi-sushi',
name: 'Komorebi Sushi',
category: '일식',
subCategory: '스시 · 사시미',
description: '제철 재료로 선보이는 오마카세 콘셉트 스시 바.',
phoneNumber: '02-2468-1357',
roadAddress: '서울 강남구 테헤란로 311',
jibunAddress: '서울 강남구 역삼동 647-9',
latitude: 37.5009,
longitude: 127.0365,
),
(
id: 'screenshot-brunch-lab',
name: 'Sunny Brunch Lab',
category: '카페/디저트',
subCategory: '브런치 · 디저트',
description: '스크램블 에그와 시그니처 라떼가 인기인 브런치 카페.',
phoneNumber: '02-9753-8642',
roadAddress: '서울 마포구 독막로 12길 5',
jibunAddress: '서울 마포구 합정동 374-6',
latitude: 37.5509,
longitude: 126.9143,
),
];
final template = templates[random.nextInt(templates.length)];
return Restaurant(
id: '${template.id}-${now.millisecondsSinceEpoch}',
name: template.name,
category: template.category,
subCategory: template.subCategory,
description: template.description,
phoneNumber: template.phoneNumber,
roadAddress: template.roadAddress,
jibunAddress: template.jibunAddress,
latitude: template.latitude,
longitude: template.longitude,
source: DataSource.PRESET,
createdAt: now,
updatedAt: now,
needsAddressVerification: false,
);
}
/// 추천 설정 모델
class RecommendationSettings {
final int daysToExclude;
@@ -59,6 +131,13 @@ class RecommendationNotifier extends StateNotifier<AsyncValue<Restaurant?>> {
state = const AsyncValue.loading();
try {
final screenshotModeEnabled = await _isScreenshotModeEnabled(_ref);
if (screenshotModeEnabled) {
final mock = _buildScreenshotRestaurant();
state = AsyncValue.data(mock);
return mock;
}
final selectedRestaurant = await _generateCandidate(
maxDistance: maxDistance,
selectedCategories: selectedCategories,
@@ -142,8 +221,19 @@ class RecommendationNotifier extends StateNotifier<AsyncValue<Restaurant?>> {
DateTime? recommendationTime,
bool visited = false,
}) async {
final screenshotModeEnabled = await _isScreenshotModeEnabled(_ref);
final now = DateTime.now();
if (screenshotModeEnabled) {
return RecommendationRecord(
id: 'screenshot-${now.millisecondsSinceEpoch}',
restaurantId: restaurant.id,
recommendationDate: recommendationTime ?? now,
visited: visited,
createdAt: now,
);
}
final record = RecommendationRecord(
id: const Uuid().v4(),
restaurantId: restaurant.id,
@@ -258,6 +348,11 @@ class EnhancedRecommendationNotifier
Future<void> rerollRecommendation() async {
if (state.currentRecommendation == null) return;
if (await _isScreenshotModeEnabled(_ref)) {
await generateRecommendation();
return;
}
// 현재 추천을 제외 목록에 추가
final excluded = [
...state.excludedRestaurants,
@@ -276,6 +371,17 @@ class EnhancedRecommendationNotifier
state = state.copyWith(isLoading: true);
try {
if (await _isScreenshotModeEnabled(_ref)) {
final mock = _buildScreenshotRestaurant();
state = state.copyWith(
currentRecommendation: mock,
excludedRestaurants: const [],
isLoading: false,
error: null,
);
return;
}
// 현재 위치 가져오기
final location = await _ref.read(currentLocationProvider.future);
if (location == null) {