Skip to content

Commit

Permalink
Add push & kedama summer games topic
Browse files Browse the repository at this point in the history
Signed-off-by: paizi <[email protected]>
  • Loading branch information
paizi committed Apr 9, 2020
1 parent 19fa205 commit 3c22e54
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 5 deletions.
8 changes: 8 additions & 0 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ android {
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
ndk {
abiFilters 'armeabi', 'armeabi-v7a', 'x86', 'x86_64', 'mips', 'mips64', 'arm64-v8a'
}
manifestPlaceholders = [
JPUSH_PKGNAME : applicationId,
JPUSH_APPKEY : "f952c64c120ec11db6225536",
JPUSH_CHANNEL : "developer-default",
]
}

buildTypes {
Expand Down
108 changes: 103 additions & 5 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import 'package:flutter/rendering.dart' show debugPaintSizeEnabled;
import 'package:flutter/services.dart';
import 'package:webview_flutter/webview_flutter.dart';
import 'package:share/share.dart';
import 'package:jpush_flutter/jpush_flutter.dart';
import 'package:fluttertoast/fluttertoast.dart';

void main() {
debugPaintSizeEnabled = false;
Expand Down Expand Up @@ -91,16 +93,42 @@ class _MyHomePageState extends State<MyHomePage> {
),
new PopupMenuButton<String>(
itemBuilder: (BuildContext context) => <PopupMenuItem<String>>[
new PopupMenuItem(value: "1", child: new Text("反馈")),
new PopupMenuItem(value: '2', child: new Text("退出"))
new PopupMenuItem(value: 'open_push', child: new Text("开启推送")),
new PopupMenuItem(value: 'close_push', child: new Text("关闭推送")),
new PopupMenuItem(value: "feedback", child: new Text("反馈")),
new PopupMenuItem(value: 'exit', child: new Text("退出"))
],
onSelected: (String value) {
if (value == '1') {
if (value == 'feedback') {
_controller.loadUrl('https://bbs.craft.moe/d/521-app/');
}
if (value == '2') {
if (value == 'exit') {
SystemChannels.platform.invokeMethod('SystemNavigator.pop');
}
if (value == 'open_push') {
jpush.resumePush();
Fluttertoast.showToast(
msg: "推送已开启",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
timeInSecForIosWeb: 1,
backgroundColor: Colors.black,
textColor: Colors.white,
fontSize: 16.0
);
}
if (value == 'close_push') {
jpush.stopPush();
Fluttertoast.showToast(
msg: "推送已关闭",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
timeInSecForIosWeb: 1,
backgroundColor: Colors.black,
textColor: Colors.white,
fontSize: 16.0
);
}
},
),
],
Expand Down Expand Up @@ -167,6 +195,14 @@ class _MyHomePageState extends State<MyHomePage> {
_controller.loadUrl('https://labs.blw.moe/kedama');
},
),
ListTile(
leading: Icon(Icons.directions_bike),
title: Text("毛运会专题"),
onTap: () {
Navigator.of(context).pop();
_controller.loadUrl('https://ksg.blw.moe');
},
),
ListTile(
leading: Icon(Icons.settings_input_svideo),
title: Text("调试工具"),
Expand All @@ -191,4 +227,66 @@ class _MyHomePageState extends State<MyHomePage> {
],
);
}
}
Future<void> initPlatformState() async {
String platformVersion;
try {
jpush.addEventHandler(
onReceiveNotification: (Map<String, dynamic> message) async {
print("flutter onReceiveNotification: $message");
setState(() {
debugLable = "flutter onReceiveNotification: $message";
});
}, onOpenNotification: (Map<String, dynamic> message) async {
print("flutter onOpenNotification: $message");
setState(() {
debugLable = "flutter onOpenNotification: $message";
});
}, onReceiveMessage: (Map<String, dynamic> message) async {
print("flutter onReceiveMessage: $message");
setState(() {
debugLable = "flutter onReceiveMessage: $message";
});
}, onReceiveNotificationAuthorization:
(Map<String, dynamic> message) async {
print("flutter onReceiveNotificationAuthorization: $message");
setState(() {
debugLable = "flutter onReceiveNotificationAuthorization: $message";
});
});
} on PlatformException {
platformVersion = 'Failed to get platform version.';
}

jpush.setup(
appKey: "f952c64c120ec11db6225536", //你自己应用的 AppKey
channel: "theChannel",
production: false,
debug: true,
);
jpush.applyPushAuthority(
new NotificationSettingsIOS(sound: true, alert: true, badge: true));

// Platform messages may fail, so we use a try/catch PlatformException.
jpush.getRegistrationID().then((rid) {
print("flutter get registration id : $rid");
setState(() {
debugLable = "flutter getRegistrationID: $rid";
});
});

// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
if (!mounted) return;

setState(() {
debugLable = platformVersion;
});
}
String debugLable = 'Unknown';
final JPush jpush = new JPush();
@override
void initState() {
super.initState();
initPlatformState();}
}
2 changes: 2 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ dependencies:
git:
url: git://github.com/paizi/plugins.git
path: packages/webview_flutter
jpush_flutter: 0.5.3
fluttertoast: ^4.0.0

dev_dependencies:
flutter_test:
Expand Down

0 comments on commit 3c22e54

Please sign in to comment.