Skip to content

Commit

Permalink
fixed admob policy violation
Browse files Browse the repository at this point in the history
  • Loading branch information
LiquidatorCoder committed Sep 21, 2020
1 parent 4c70b80 commit 09b418e
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 21 deletions.
50 changes: 43 additions & 7 deletions lib/screens/home.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:flutter/services.dart';
import 'package:ggsipu_notice/keys.dart';
import 'package:firebase_admob/firebase_admob.dart';
import 'package:flutter/cupertino.dart';
Expand All @@ -9,6 +10,7 @@ import 'package:ggsipu_notice/ui/noticetile.dart';
import 'package:ggsipu_notice/ui/themeswitch.dart';
import 'package:http/http.dart' as http;
import 'dart:async';
import 'package:url_launcher/url_launcher.dart';

class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
Expand All @@ -30,25 +32,43 @@ class _MyHomePageState extends State<MyHomePage> {
);
InterstitialAd _interstitialAd;

InterstitialAd createInterstitialAd() {
InterstitialAd createInterstitialAd(int index) {
return InterstitialAd(
// adUnitId: InterstitialAd.testAdUnitId,
adUnitId: adUnitId,
targetingInfo: targetingInfo,
listener: (MobileAdEvent event) {
print("InterstitialAd event $event");
if (event == MobileAdEvent.closed) {
print('Interstitial closed');
if (index != null) {
String link = "http://www.ipu.ac.in${lists[index]["url"]}";
_launchURL(link);
}
}
},
);
}

@override
void initState() {
FirebaseAdMob.instance.initialize(appId: appId);
_timerForInter = Timer.periodic(Duration(seconds: 20), (result) {
_interstitialAd = createInterstitialAd()
..load()
..show();
});
if (this.mounted) {
Future.delayed(Duration(seconds: 3)).then(
(value) {
_interstitialAd = createInterstitialAd(null)
..load()
..show();
},
);
}
// _timerForInter = Timer.periodic(Duration(seconds: 20), (result) {
// if (this.mounted) {
// _interstitialAd = createInterstitialAd()
// ..load()
// ..show();
// }
// });
super.initState();
}

Expand Down Expand Up @@ -109,7 +129,15 @@ class _MyHomePageState extends State<MyHomePage> {
return new SliverList(
delegate: SliverChildBuilderDelegate(
(BuildContext context, int index) {
return NoticeTile(lists: lists, index: index);
return NoticeTile(
lists: lists,
index: index,
func: () {
HapticFeedback.vibrate();
_interstitialAd = createInterstitialAd(index)
..load()
..show();
});
},
childCount: lists.length,
),
Expand Down Expand Up @@ -141,4 +169,12 @@ class _MyHomePageState extends State<MyHomePage> {
),
);
}

_launchURL(String url) async {
if (await canLaunch(url)) {
await launch(url);
} else {
throw 'Could not launch $url';
}
}
}
17 changes: 4 additions & 13 deletions lib/ui/noticetile.dart
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_neumorphic/flutter_neumorphic.dart';
import 'package:url_launcher/url_launcher.dart';

class NoticeTile extends StatelessWidget {
const NoticeTile({
Key key,
@required this.lists,
@required this.index,
@required this.func,
}) : super(key: key);

final List lists;
final int index;
final Function func;

@override
Widget build(BuildContext context) {
Expand All @@ -27,8 +28,7 @@ class NoticeTile extends StatelessWidget {
boxShape: NeumorphicBoxShape.roundRect(BorderRadius.circular(15)),
child: ListTile(
onTap: () {
String link = "http://www.ipu.ac.in${lists[index]["url"]}";
_launchURL(link);
func();
},
contentPadding: EdgeInsets.fromLTRB(20, 10, 5, 10),
leading: Container(
Expand Down Expand Up @@ -68,19 +68,10 @@ class NoticeTile extends StatelessWidget {
child: Icon(Icons.keyboard_arrow_right,
color: NeumorphicTheme.defaultTextColor(context), size: 30.0),
onClick: () {
String link = "http://www.ipu.ac.in${lists[index]["url"]}";
_launchURL(link);
func();
},
)),
),
);
}

_launchURL(String url) async {
if (await canLaunch(url)) {
await launch(url);
} else {
throw 'Could not launch $url';
}
}
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ description: A new Flutter project.
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.3+3
version: 1.0.3+4

environment:
sdk: ">=2.1.0 <3.0.0"
Expand Down

0 comments on commit 09b418e

Please sign in to comment.