Skip to content

Commit

Permalink
create dummy AdCard
Browse files Browse the repository at this point in the history
  • Loading branch information
frankpepermans authored and joecks committed Jul 20, 2022
1 parent 40082f0 commit 1367220
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ class AdCardInjectionUseCase extends UseCase<Set<Card>, Set<Card>> {

@override
Stream<Set<Card>> transaction(Set<Card> param) async* {
if (!featureManager.areAdsEnabled) yield param;
if (!featureManager.areAdsEnabled) {
yield param;
return;
}

final documents = param
.where((it) => it.type == CardType.document)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,10 @@ abstract class BaseDiscoveryManager extends Cubit<DiscoveryState>

void handleSurveyTapped() => handleSurveyBannerClickedUseCase(none);

void handleAdTapped() {
throw UnimplementedError('handleAdTapped was not implemented');
}

void handleLoadMore();

void handleShowPaywallIfNeeded(SubscriptionStatus subscriptionStatus);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import 'package:xayn_discovery_app/presentation/base_discovery/manager/discovery
import 'package:xayn_discovery_app/presentation/constants/keys.dart';
import 'package:xayn_discovery_app/presentation/constants/r.dart';
import 'package:xayn_discovery_app/presentation/discovery_card/manager/card_managers_cache.dart';
import 'package:xayn_discovery_app/presentation/discovery_card/widget/custom_card/ad_card.dart';
import 'package:xayn_discovery_app/presentation/discovery_card/widget/custom_card/survey_card.dart';
import 'package:xayn_discovery_app/presentation/discovery_card/widget/dicovery_feed_card.dart';
import 'package:xayn_discovery_app/presentation/discovery_card/widget/discovery_card.dart';
Expand Down Expand Up @@ -276,21 +277,11 @@ abstract class BaseDiscoveryFeedState<T extends BaseDiscoveryManager,
)
: GestureDetector(
onTap: isPrimary ? onTapPrimary : onTapSecondary,
child: document != null
? DiscoveryFeedCard(
isPrimary: isPrimary,
document: document,
primaryCardShader: ShaderFactory.fromType(shaderType!),
onTtsData: (it) => setState(() => ttsData =
ttsData.enabled ? TtsData.disabled() : it),
feedType: manager.feedType,
)
: SurveyCard(
cardType: card.type,
onPressed: manager.handleSurveyTapped,
primaryCardShader:
ShaderFactory.fromType(ShaderType.static),
),
child: _buildCard(
card: card,
isPrimary: isPrimary,
shaderType: shaderType,
),
);

return Semantics(
Expand All @@ -315,6 +306,32 @@ abstract class BaseDiscoveryFeedState<T extends BaseDiscoveryManager,
: cardWidget);
};

Widget _buildCard({
required item_renderer.Card card,
bool isPrimary = false,
ShaderType? shaderType,
}) {
switch (card.type) {
case item_renderer.CardType.document:
return DiscoveryFeedCard(
isPrimary: isPrimary,
document: card.requireDocument,
primaryCardShader: ShaderFactory.fromType(shaderType!),
onTtsData: (it) => setState(
() => ttsData = ttsData.enabled ? TtsData.disabled() : it),
feedType: manager.feedType,
);
case item_renderer.CardType.survey:
return SurveyCard(
onPressed: manager.handleSurveyTapped,
);
case item_renderer.CardType.ad:
return AdCard(
onPressed: manager.handleAdTapped,
);
}
}

ShaderType _getShaderType(NewsResource newsResource) {
// A document doesn't have a unique 'index',
// and also, the index within the feed is not static, as older
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import 'package:flutter/widgets.dart';
import 'package:xayn_design/xayn_design.dart';
import 'package:xayn_discovery_app/presentation/constants/r.dart';
import 'package:xayn_discovery_app/presentation/images/widget/cached_image.dart';
import 'package:xayn_discovery_app/presentation/images/widget/shader/shader.dart';
import 'package:xayn_discovery_app/presentation/images/widget/shader/static/static_painter.dart';
import 'package:xayn_discovery_app/presentation/widget/animation_player.dart';

class AdCard extends StatelessWidget {
late final ShaderBuilder primaryCardShader =
ShaderFactory.fromType(ShaderType.static);
final VoidCallback onPressed;

AdCard({
Key? key,
required this.onPressed,
}) : super(key: key);

@override
Widget build(BuildContext context) {
final children = <Widget>[
SizedBox(height: R.dimen.unit),
Expanded(child: _buildAnimation()),
SizedBox(height: R.dimen.unit2),
Text(
'Buy buy buy!',
textAlign: TextAlign.center,
style: R.styles.lBoldStyle.copyWith(color: R.colors.brightText),
),
SizedBox(height: R.dimen.unit2),
Text(
'click this ad for great success!!',
textAlign: TextAlign.center,
style: R.styles.mStyle.copyWith(color: R.colors.brightText),
),
SizedBox(height: R.dimen.unit2_5),
_buildTakeSurveyBtn(),
];

return Stack(
children: [
Positioned.fill(
child: CustomPaint(
painter: StaticPainter(
shadowColor: R.colors.shadow,
),
),
),
Padding(
padding: EdgeInsets.symmetric(
horizontal: R.dimen.unit4,
vertical: R.dimen.unit6,
),
child: Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: children,
),
),
],
);
}

Widget _buildAnimation() =>
AnimationPlayer.assetUnrestrictedSize(R.assets.lottie.bookmarkClick);

Widget _buildTakeSurveyBtn() => SizedBox(
width: double.maxFinite,
child: AppRaisedButton.text(
text: 'OMG I WANT THIS NOW!!!',
onPressed: onPressed,
),
);
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
import 'package:flutter/widgets.dart';
import 'package:xayn_design/xayn_design.dart';
import 'package:xayn_discovery_app/domain/item_renderer/card.dart';
import 'package:xayn_discovery_app/presentation/constants/r.dart';
import 'package:xayn_discovery_app/presentation/images/widget/cached_image.dart';
import 'package:xayn_discovery_app/presentation/images/widget/shader/shader.dart';
import 'package:xayn_discovery_app/presentation/images/widget/shader/static/static_painter.dart';
import 'package:xayn_discovery_app/presentation/widget/animation_player.dart';

class SurveyCard extends StatelessWidget {
final CardType cardType;
final ShaderBuilder primaryCardShader;
late final ShaderBuilder primaryCardShader =
ShaderFactory.fromType(ShaderType.static);
final VoidCallback onPressed;

SurveyCard({
Key? key,
required this.cardType,
required this.onPressed,
ShaderBuilder? primaryCardShader,
}) : primaryCardShader =
primaryCardShader ?? ShaderFactory.fromType(ShaderType.static),
super(key: key);
}) : super(key: key);

@override
Widget build(BuildContext context) {
Expand Down

0 comments on commit 1367220

Please sign in to comment.