Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_news_app_mobile_client_full_source_code/account/bloc/available_countries_bloc.dart';
import 'package:flutter_news_app_mobile_client_full_source_code/app/bloc/app_bloc.dart';
import 'package:flutter_news_app_mobile_client_full_source_code/l10n/l10n.dart';
import 'package:flutter_news_app_mobile_client_full_source_code/shared/services/content_limitation_service.dart';
import 'package:flutter_news_app_mobile_client_full_source_code/shared/widgets/content_limitation_bottom_sheet.dart';
import 'package:ui_kit/ui_kit.dart';

/// {@template add_country_to_follow_page}
Expand Down Expand Up @@ -150,29 +152,61 @@ class AddCountryToFollowPage extends StatelessWidget {
? l10n.unfollowCountryTooltip(country.name)
: l10n.followCountryTooltip(country.name),
onPressed: () {
// Ensure user preferences are available before
// proceeding.
if (userContentPreferences == null) return;

// Create a mutable copy of the followed countries list.
final updatedFollowedCountries = List<Country>.from(
followedCountries,
);

// If the user is unfollowing, always allow it.
if (isFollowed) {
updatedFollowedCountries.removeWhere(
(c) => c.id == country.id,
);
final updatedPreferences = userContentPreferences
.copyWith(
followedCountries: updatedFollowedCountries,
);

context.read<AppBloc>().add(
AppUserContentPreferencesChanged(
preferences: updatedPreferences,
),
);
} else {
updatedFollowedCountries.add(country);
}
// If the user is following, check the limit first.
final limitationService = context
.read<ContentLimitationService>();
final status = limitationService.checkAction(
ContentAction.followCountry,
);

final updatedPreferences = userContentPreferences
.copyWith(
followedCountries: updatedFollowedCountries,
);
if (status == LimitationStatus.allowed) {
updatedFollowedCountries.add(country);
final updatedPreferences =
userContentPreferences.copyWith(
followedCountries:
updatedFollowedCountries,
);

context.read<AppBloc>().add(
AppUserContentPreferencesChanged(
preferences: updatedPreferences,
),
);
context.read<AppBloc>().add(
AppUserContentPreferencesChanged(
preferences: updatedPreferences,
),
);
} else {
// If the limit is reached, show the bottom sheet.
showModalBottomSheet<void>(
context: context,
builder: (_) => ContentLimitationBottomSheet(
status: status,
),
);
}
}
},
),
contentPadding: const EdgeInsets.symmetric(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_news_app_mobile_client_full_source_code/account/bloc/available_sources_bloc.dart';
import 'package:flutter_news_app_mobile_client_full_source_code/app/bloc/app_bloc.dart';
import 'package:flutter_news_app_mobile_client_full_source_code/l10n/l10n.dart';
import 'package:flutter_news_app_mobile_client_full_source_code/shared/services/content_limitation_service.dart';
import 'package:flutter_news_app_mobile_client_full_source_code/shared/widgets/content_limitation_bottom_sheet.dart';
import 'package:ui_kit/ui_kit.dart';

/// {@template add_source_to_follow_page}
Expand Down Expand Up @@ -80,29 +82,60 @@ class AddSourceToFollowPage extends StatelessWidget {
? l10n.unfollowSourceTooltip(source.name)
: l10n.followSourceTooltip(source.name),
onPressed: () {
// Ensure user preferences are available before
// proceeding.
if (userContentPreferences == null) return;

// Create a mutable copy of the followed sources list.
final updatedFollowedSources = List<Source>.from(
followedSources,
);

// If the user is unfollowing, always allow it.
if (isFollowed) {
updatedFollowedSources.removeWhere(
(s) => s.id == source.id,
);
final updatedPreferences = userContentPreferences
.copyWith(
followedSources: updatedFollowedSources,
);

context.read<AppBloc>().add(
AppUserContentPreferencesChanged(
preferences: updatedPreferences,
),
);
} else {
updatedFollowedSources.add(source);
}
// If the user is following, check the limit first.
final limitationService = context
.read<ContentLimitationService>();
final status = limitationService.checkAction(
ContentAction.followSource,
);

final updatedPreferences = userContentPreferences
.copyWith(
followedSources: updatedFollowedSources,
);
if (status == LimitationStatus.allowed) {
updatedFollowedSources.add(source);
final updatedPreferences =
userContentPreferences.copyWith(
followedSources: updatedFollowedSources,
);

context.read<AppBloc>().add(
AppUserContentPreferencesChanged(
preferences: updatedPreferences,
),
);
context.read<AppBloc>().add(
AppUserContentPreferencesChanged(
preferences: updatedPreferences,
),
);
} else {
// If the limit is reached, show the bottom sheet.
showModalBottomSheet<void>(
context: context,
builder: (_) => ContentLimitationBottomSheet(
status: status,
),
);
}
}
},
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_news_app_mobile_client_full_source_code/account/bloc/available_topics_bloc.dart';
import 'package:flutter_news_app_mobile_client_full_source_code/app/bloc/app_bloc.dart';
import 'package:flutter_news_app_mobile_client_full_source_code/l10n/l10n.dart';
import 'package:flutter_news_app_mobile_client_full_source_code/shared/services/content_limitation_service.dart';
import 'package:flutter_news_app_mobile_client_full_source_code/shared/widgets/content_limitation_bottom_sheet.dart';
import 'package:ui_kit/ui_kit.dart';

/// {@template add_topic_to_follow_page}
Expand Down Expand Up @@ -149,29 +151,60 @@ class AddTopicToFollowPage extends StatelessWidget {
? l10n.unfollowTopicTooltip(topic.name)
: l10n.followTopicTooltip(topic.name),
onPressed: () {
// Ensure user preferences are available before
// proceeding.
if (userContentPreferences == null) return;

// Create a mutable copy of the followed topics list.
final updatedFollowedTopics = List<Topic>.from(
followedTopics,
);

// If the user is unfollowing, always allow it.
if (isFollowed) {
updatedFollowedTopics.removeWhere(
(t) => t.id == topic.id,
);
final updatedPreferences = userContentPreferences
.copyWith(
followedTopics: updatedFollowedTopics,
);

context.read<AppBloc>().add(
AppUserContentPreferencesChanged(
preferences: updatedPreferences,
),
);
} else {
updatedFollowedTopics.add(topic);
}
// If the user is following, check the limit first.
final limitationService = context
.read<ContentLimitationService>();
final status = limitationService.checkAction(
ContentAction.followTopic,
);

final updatedPreferences = userContentPreferences
.copyWith(
followedTopics: updatedFollowedTopics,
);
if (status == LimitationStatus.allowed) {
updatedFollowedTopics.add(topic);
final updatedPreferences =
userContentPreferences.copyWith(
followedTopics: updatedFollowedTopics,
);

context.read<AppBloc>().add(
AppUserContentPreferencesChanged(
preferences: updatedPreferences,
),
);
context.read<AppBloc>().add(
AppUserContentPreferencesChanged(
preferences: updatedPreferences,
),
);
} else {
// If the limit is reached, show the bottom sheet.
showModalBottomSheet<void>(
context: context,
builder: (_) => ContentLimitationBottomSheet(
status: status,
),
);
}
}
},
),
contentPadding: const EdgeInsets.symmetric(
Expand Down
Loading