-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reapply "feat: ad settings and ad query (#229)"
This reverts commit 6763f38.
- Loading branch information
Showing
9 changed files
with
364 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import 'package:amity_sdk/amity_sdk.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_social_sample_app/core/widget/advertiser_row_widget.dart'; | ||
import 'package:url_launcher/url_launcher.dart'; | ||
|
||
class AdWidget extends StatelessWidget { | ||
final AmityAd amityAd; | ||
|
||
const AdWidget({Key? key, required this.amityAd}) : super(key: key); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final themeData = Theme.of(context); | ||
return Container( | ||
padding: const EdgeInsets.all(16), | ||
child: Expanded( | ||
child: Column( | ||
crossAxisAlignment: CrossAxisAlignment.start, | ||
mainAxisSize: MainAxisSize.min, | ||
children: [ | ||
AdvertiserRowWidget( | ||
advertiserId: amityAd.advertiserId ?? '', | ||
companyName: amityAd.advertiser?.companyName, | ||
advertiserAvatar: amityAd.advertiser?.avatar), | ||
Text( | ||
'Ad id - ${amityAd.adId}', | ||
style: themeData.textTheme.bodySmall, | ||
), | ||
Text( | ||
'Target - ${amityAd.adTarget}', | ||
style: themeData.textTheme.bodySmall, | ||
), | ||
Text( | ||
'Placements - ${amityAd.placements}', | ||
style: themeData.textTheme.bodySmall, | ||
), | ||
Text( | ||
'Start at - ${amityAd.startAt ?? 'N/A'}', | ||
style: themeData.textTheme.bodySmall, | ||
), | ||
Text( | ||
'End at - ${amityAd.endAt ?? 'forever'}', | ||
style: themeData.textTheme.bodySmall, | ||
), | ||
Text( | ||
'Name - ${amityAd.name}', | ||
style: themeData.textTheme.titleMedium, | ||
), | ||
Text( | ||
'Headline - ${amityAd.headline ?? 'N/A - Headline is not available'}', | ||
style: themeData.textTheme.titleLarge, | ||
), | ||
Text( | ||
'Description - ${amityAd.description ?? 'N/A - Description is not available'}', | ||
style: themeData.textTheme.bodyMedium, | ||
), | ||
Row( | ||
crossAxisAlignment: CrossAxisAlignment.start, | ||
mainAxisSize: MainAxisSize.min, | ||
children: [ | ||
Container( | ||
margin: const EdgeInsets.all(4), | ||
color: Colors.blueGrey.withOpacity(.25), | ||
width: 130, | ||
height: 130, | ||
child: (amityAd.image1_1 != null) | ||
? Image.network( | ||
amityAd.image1_1!.getUrl(AmityImageSize.MEDIUM), | ||
fit: BoxFit.cover, | ||
) | ||
: const Align( | ||
alignment: Alignment.center, | ||
child: Text( | ||
"1:1 Ad image is not available", | ||
textAlign: TextAlign.center, | ||
), | ||
), | ||
), | ||
Container( | ||
margin: const EdgeInsets.all(4), | ||
color: Colors.blueGrey.withOpacity(.25), | ||
width: 130, | ||
height: 130, | ||
child: (amityAd.image9_16 != null) | ||
? Image.network( | ||
amityAd.image9_16!.getUrl(AmityImageSize.MEDIUM), | ||
fit: BoxFit.fitWidth, | ||
) | ||
: const Align( | ||
alignment: Alignment.center, | ||
child: Text( | ||
"9:16 Ad image is not available", | ||
textAlign: TextAlign.center, | ||
), | ||
)) | ||
]), | ||
], | ||
), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import 'package:amity_sdk/amity_sdk.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
class AdvertiserRowWidget extends StatelessWidget { | ||
const AdvertiserRowWidget( | ||
{Key? key, | ||
required this.advertiserId, | ||
this.companyName, | ||
this.advertiserAvatar}) | ||
: super(key: key); | ||
|
||
final String advertiserId; | ||
final AmityImage? advertiserAvatar; | ||
final String? companyName; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final themeData = Theme.of(context); | ||
return Container( | ||
padding: const EdgeInsets.all(8), | ||
decoration: BoxDecoration( | ||
borderRadius: BorderRadius.circular(8), | ||
color: Colors.white, | ||
), | ||
child: Row( | ||
crossAxisAlignment: CrossAxisAlignment.start, | ||
mainAxisSize: MainAxisSize.min, | ||
children: [ | ||
Container( | ||
width: 48, | ||
height: 48, | ||
decoration: BoxDecoration( | ||
shape: BoxShape.circle, | ||
color: Colors.grey.withOpacity( | ||
.3, | ||
), | ||
), | ||
clipBehavior: Clip.antiAliasWithSaveLayer, | ||
child: advertiserAvatar != null | ||
? Image.network( | ||
advertiserAvatar!.getUrl(AmityImageSize.MEDIUM), | ||
fit: BoxFit.fill, | ||
) | ||
: Image.asset('assets/user_placeholder.png'), | ||
), | ||
const SizedBox(width: 18), | ||
Expanded( | ||
child: Column( | ||
crossAxisAlignment: CrossAxisAlignment.start, | ||
mainAxisSize: MainAxisSize.min, | ||
children: [ | ||
Text( | ||
companyName ?? 'company name is not available', | ||
style: themeData.textTheme.titleLarge, | ||
), | ||
Text( | ||
'advertiserId: $advertiserId', | ||
style: themeData.textTheme.bodySmall, | ||
), | ||
], | ||
), | ||
), | ||
const Spacer() | ||
], | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import 'package:amity_sdk/amity_sdk.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_social_sample_app/core/widget/ad_widget.dart'; | ||
|
||
class AdsListScreen extends StatefulWidget { | ||
const AdsListScreen({Key? key}) : super(key: key); | ||
@override | ||
State<AdsListScreen> createState() => _AdsListScreenState(); | ||
} | ||
|
||
final ScrollController scrollController = ScrollController(); | ||
|
||
class _AdsListScreenState extends State<AdsListScreen> { | ||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
appBar: AppBar( | ||
title: const Text('Ads List 👩🚀'), | ||
), | ||
body: Container( | ||
width: double.maxFinite, | ||
decoration: BoxDecoration( | ||
color: Colors.white, | ||
border: Border.all( | ||
color: Colors.black26, | ||
width: 1, | ||
), | ||
), | ||
child: Column( | ||
children: [ | ||
Expanded( | ||
child: FutureBuilder<AmityNetworkAds>( | ||
future: AmityCoreClient.newAdRepository().getNetworkAds(), | ||
builder: (context, snapshot) { | ||
if (snapshot.hasData && | ||
(snapshot.data?.ads?.isNotEmpty ?? false)) { | ||
List<AmityAd> networkAds = snapshot.data!.ads!; | ||
return ListView.builder( | ||
controller: ScrollController(), | ||
physics: const AlwaysScrollableScrollPhysics(), | ||
itemCount: networkAds.length, | ||
itemBuilder: (context, index) { | ||
final networkAd = networkAds[index]; | ||
return AdWidget(key: UniqueKey(), amityAd: networkAd); | ||
}); | ||
} else if (snapshot.hasError) { | ||
return Center( | ||
child: Text(snapshot.error.toString()), | ||
); | ||
} else { | ||
return const Center( | ||
child: CircularProgressIndicator(), | ||
); | ||
} | ||
}, | ||
), | ||
), | ||
], | ||
), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import 'package:amity_sdk/amity_sdk.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
class AdsSettingsScreen extends StatefulWidget { | ||
const AdsSettingsScreen({Key? key}) : super(key: key); | ||
@override | ||
State<AdsSettingsScreen> createState() => _AdsSettingsScreenState(); | ||
} | ||
|
||
final ScrollController scrollController = ScrollController(); | ||
|
||
class _AdsSettingsScreenState extends State<AdsSettingsScreen> { | ||
@override | ||
Widget build(BuildContext context) { | ||
final themeData = Theme.of(context); | ||
return Scaffold( | ||
appBar: AppBar( | ||
title: const Text('Ads Settings ⚙️'), | ||
), | ||
body: Container( | ||
width: double.maxFinite, | ||
decoration: BoxDecoration( | ||
color: Colors.white, | ||
border: Border.all( | ||
color: Colors.black26, | ||
width: 1, | ||
), | ||
), | ||
child: Column( | ||
children: [ | ||
Expanded( | ||
child: FutureBuilder<AmityNetworkAds>( | ||
future: AmityCoreClient.newAdRepository().getNetworkAds(), | ||
builder: (context, snapshot) { | ||
if (snapshot.hasData && (snapshot.data?.settings != null)) { | ||
AmityAdsSettings settings = snapshot.data!.settings!; | ||
return Expanded( | ||
child: Expanded( | ||
child: Column( | ||
crossAxisAlignment: CrossAxisAlignment.start, | ||
mainAxisSize: MainAxisSize.min, | ||
children: [ | ||
Text( | ||
'Is enabled - ${settings.isEnabled ?? 'N/A'}', | ||
style: themeData.textTheme.bodyMedium, | ||
), | ||
Text( | ||
'Max active - ${settings.maxActiveAds ?? 'N/A'}', | ||
style: themeData.textTheme.bodyMedium, | ||
), | ||
Text( | ||
'Feed frequency- ${settings.getFrequency()?.getFeedAdFrequency().type ?? 'N/A'} ${settings.getFrequency()?.getFeedAdFrequency().value ?? 'N/A'}', | ||
style: themeData.textTheme.bodyMedium, | ||
), | ||
Text( | ||
'Story frequency- ${settings.getFrequency()?.getStoryAdFrequency().type ?? 'N/A'} ${settings.getFrequency()?.getStoryAdFrequency().value ?? 'N/A'}', | ||
style: themeData.textTheme.bodyMedium, | ||
), | ||
Text( | ||
'Comment frequency- ${settings.getFrequency()?.getCommentAdFrequency().type ?? 'N/A'} ${settings.getFrequency()?.getCommentAdFrequency().value ?? 'N/A'}', | ||
style: themeData.textTheme.bodyMedium, | ||
), | ||
], | ||
), | ||
)); | ||
} else if (snapshot.hasError) { | ||
return Center( | ||
child: Text(snapshot.error.toString()), | ||
); | ||
} else { | ||
return const Center( | ||
child: CircularProgressIndicator(), | ||
); | ||
} | ||
}, | ||
), | ||
), | ||
], | ||
), | ||
), | ||
); | ||
} | ||
} |
Oops, something went wrong.