Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
JohannesPertl committed Jan 2, 2022
2 parents 40d02da + ec46455 commit f8e2864
Show file tree
Hide file tree
Showing 23 changed files with 411 additions and 129 deletions.
11 changes: 11 additions & 0 deletions cloud-functions/firebase.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,16 @@
"firestore": {
"rules": "firestore.rules",
"indexes": "firestore.indexes.json"
},
"functions": {
"source": "functions"
},
"emulators": {
"functions": {
"port": 5001
},
"ui": {
"enabled": true
}
}
}
285 changes: 206 additions & 79 deletions cloud-functions/functions/index.js

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions cloud-functions/functions/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions cloud-functions/functions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"main": "index.js",
"dependencies": {
"axios": "^0.24.0",
"dayjs": "^1.10.7",
"firebase-admin": "^9.8.0",
"firebase-functions": "^3.14.1"
},
Expand Down
7 changes: 7 additions & 0 deletions cloud-functions/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"dependencies": {
"axios": "^0.24.0",
"dayjs": "^1.10.7",
"firebase-functions": "^3.16.0"
}
}
167 changes: 124 additions & 43 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,25 @@ import 'package:flutter/material.dart';
import 'package:cloud_functions/cloud_functions.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:video_player/video_player.dart';

import 'notification.dart';

const String _nasaUrl =
const String _currentStepURL =
'https://www.jwst.nasa.gov/content/webbLaunch/whereIsWebb.html';


const String _allStepsURL =
'https://www.jwst.nasa.gov/content/webbLaunch/deploymentExplorer.html';
const String _twitterUrl = 'https://twitter.com/NASAWebb';

const yellow = Color(0xFFFFCC00);
const grey = Color(0xFF1D1D1D);
const background = Colors.black;
const turquoise = Color(0xFF41EAD4);
const pink = Color(0xFFFF206E);


bool _isSnackbarActive = false ;

void main() async {
await init();
runApp(const MyApp());
Expand All @@ -26,6 +31,7 @@ void main() async {
Future init() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
// FirebaseFunctions.instance.useFunctionsEmulator('localhost', 5001);
await FirebaseMessaging.instance.subscribeToTopic('new_deployment_step');
}

Expand All @@ -44,7 +50,7 @@ class MyApp extends StatelessWidget {
return MaterialApp(
title: 'Where is Webb?',
theme: new ThemeData(
scaffoldBackgroundColor: grey,
scaffoldBackgroundColor: background,
primaryColor: yellow,
textTheme: const TextTheme(
headline2: TextStyle(
Expand All @@ -66,15 +72,41 @@ class HomePage extends StatefulWidget {
}

class _HomePageState extends State<HomePage> with WidgetsBindingObserver {
late VideoPlayerController _controller;
late Future<void> _initializeVideoPlayerFuture;

String stepName = "Loading..";
String stepDescription = "";
String stepNumber = "";
String stepOneliner = "";
String stepVideoURL = "";
String status = "";

void showDeploymentStep() {
getCurrentDeploymentStep().then((dynamic result) {
setState(() {
stepName = result['step_name'];
stepOneliner = result['oneliner'];
String step = (result['step'] + 1).toString();
stepDescription = "Step $step of 28";
stepNumber = "Step $step of 28";
if (result['status'] == 'success') {
status = "SUCCESS";
} else {
status = "FAILURE";
}

if (result['video_local_url'] != null && result['video_local_url'] != stepVideoURL) {
stepVideoURL = result['video_local_url'];
_controller = VideoPlayerController.asset(
stepVideoURL,
videoPlayerOptions: VideoPlayerOptions(
mixWithOthers: true,
),
);
_initializeVideoPlayerFuture = _controller.initialize();
_controller.setLooping(true);
_controller.setVolume(0.0);
_controller.play();
}
});
}).timeout(Duration(seconds: 10));
}
Expand All @@ -86,14 +118,13 @@ class _HomePageState extends State<HomePage> with WidgetsBindingObserver {
text: TextSpan(
children: [
WidgetSpan(
child: FaIcon(FontAwesomeIcons.solidBell, size: 20),
child: FaIcon(FontAwesomeIcons.solidBell, size: 17),
),
TextSpan(
text:
" You will be notified as soon as a new step is reached",
text: " You will be notified about the next deployment",
style: TextStyle(
color: grey,
fontSize: 18.0,
color: background,
fontSize: 15.0,
fontWeight: FontWeight.bold,
),
),
Expand All @@ -103,22 +134,30 @@ class _HomePageState extends State<HomePage> with WidgetsBindingObserver {
),
duration: Duration(seconds: duration),
);
Future.delayed(const Duration(seconds: 1), () {
ScaffoldMessenger.of(context).showSnackBar(snackBar);
});
if (!_isSnackbarActive) {
_isSnackbarActive = true;
Future.delayed(const Duration(seconds: 1), () {
ScaffoldMessenger.of(context).showSnackBar(snackBar)
.closed
.then((SnackBarClosedReason reason) {
_isSnackbarActive = false ;
});
});
}
}

@override
void dispose() {
WidgetsBinding.instance!.removeObserver(this);
_controller.dispose();
super.dispose();
}

@override
void didChangeAppLifecycleState(AppLifecycleState state) {
if (state == AppLifecycleState.resumed) {
showDeploymentStep();
showInfoSnackbar(7);
showInfoSnackbar(5);
}
}

Expand All @@ -138,7 +177,7 @@ class _HomePageState extends State<HomePage> with WidgetsBindingObserver {
}

_changeStep(String msg) => setState(() {
stepDescription = msg;
stepNumber = msg;
});

_changeStepName(String msg) => setState(() {
Expand All @@ -151,67 +190,111 @@ class _HomePageState extends State<HomePage> with WidgetsBindingObserver {
color: Colors.white,
fontWeight: FontWeight.bold,
),
// textAlign: TextAlign.center,
),
action: SnackBarAction(
textColor: grey,
textColor: background,
label: 'Close',
onPressed: () {},
),
duration: Duration(days: 365),
);

Future(() {
ScaffoldMessenger.of(context).showSnackBar(snackBar);
_isSnackbarActive = true;
ScaffoldMessenger.of(context).showSnackBar(snackBar)
.closed
.then((SnackBarClosedReason reason) {
_isSnackbarActive = false ;
});
});
});

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(
'Where is Webb?',
style: TextStyle(
fontSize: 35.0, fontWeight: FontWeight.bold, color: yellow),
textAlign: TextAlign.center,
),
backgroundColor: background,
elevation: 0,
centerTitle: true,
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Flexible(
flex: 2,
child: Text(
'Where\nis\nWebb?',
style: TextStyle(
fontSize: 72.0, fontWeight: FontWeight.bold, color: yellow),
textAlign: TextAlign.center,
),
),
Column(
children: [
Text(
stepDescription,
// "test",
stepNumber,
style: TextStyle(
fontSize: 20.0,
fontSize: 18.0,
fontWeight: FontWeight.bold,
color: Colors.white),
textAlign: TextAlign.center,
),
Text(
stepName,
style: TextStyle(
fontSize: 30.0,
fontSize: 22.0,
fontWeight: FontWeight.bold,
color: turquoise),
textAlign: TextAlign.center,
),
],
),
if (stepVideoURL != "")
FutureBuilder(
future: _initializeVideoPlayerFuture,
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
return Flexible(
flex: 2,
child: AspectRatio(
aspectRatio: _controller.value.aspectRatio,
child: VideoPlayer(_controller),
),
);
} else {
return const Center(
child: CircularProgressIndicator(),
);
}
},
),
RichText(
text: TextSpan(
children: [
TextSpan(
text: "Deployment status: ",
style: TextStyle(
color: Colors.white,
fontSize: 20,
),
),
TextSpan(
text: "$status",
style: TextStyle(
color: Colors.lightGreenAccent,
fontSize: 25,
fontWeight: FontWeight.bold,
),
),
],
),
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
ElevatedButton(
// Change color of button
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all<Color>(pink),
minimumSize: MaterialStateProperty.all<Size>(
Size(0, 45)),
minimumSize: MaterialStateProperty.all<Size>(Size(0, 45)),
),
child: RichText(
text: TextSpan(
Expand All @@ -220,8 +303,7 @@ class _HomePageState extends State<HomePage> with WidgetsBindingObserver {
child: FaIcon(FontAwesomeIcons.rocket, size: 20),
),
TextSpan(
text:
" More info",
text: " More info ",
style: TextStyle(
color: Colors.white,
fontSize: 20,
Expand All @@ -232,24 +314,23 @@ class _HomePageState extends State<HomePage> with WidgetsBindingObserver {
),
textAlign: TextAlign.center,
),
onPressed: () => _launchURL(_nasaUrl),
onPressed: () => _launchURL(_currentStepURL),
),
ElevatedButton(
// Change color of button
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all<Color>(Color(0xFF1D9BF0)),
minimumSize: MaterialStateProperty.all<Size>(
Size(0, 45)),
backgroundColor:
MaterialStateProperty.all<Color>(Color(0xFF1D9BF0)),
minimumSize: MaterialStateProperty.all<Size>(Size(0, 45)),
),
child: RichText(
text: TextSpan(
children: [
WidgetSpan(
child: FaIcon(FontAwesomeIcons.twitter, size: 20),
child: FaIcon(FontAwesomeIcons.twitter, size: 18),
),
TextSpan(
text:
" @NASAWebb",
text: " NASAWebb",
style: TextStyle(
color: Colors.white,
fontSize: 20,
Expand Down
Loading

0 comments on commit f8e2864

Please sign in to comment.