Skip to content

Commit

Permalink
feat: ability to access debug logs from login screen
Browse files Browse the repository at this point in the history
  • Loading branch information
muety committed Aug 29, 2020
1 parent b5219d4 commit dd57acf
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 50 deletions.
4 changes: 2 additions & 2 deletions android/local.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
sdk.dir=/opt/android/sdk
flutter.sdk=/opt/flutter
flutter.versionName=1.1.2
flutter.versionName=1.1.3
flutter.buildMode=debug
flutter.versionCode=24
flutter.versionCode=25
1 change: 1 addition & 0 deletions fastlane/metadata/android/en-US/changelogs/113.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
– Add ability to view debug logs from login screen
115 changes: 68 additions & 47 deletions lib/pages/login_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import 'package:f_logs/f_logs.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';

import 'about_page.dart';
import 'logs_page.dart';

class LoginPage extends StatefulWidget {
static const String routeName = '/login';
final AppState appState;
Expand All @@ -31,11 +34,24 @@ class _LoginPageState extends AnchrState<LoginPage> with AnchrActions {

_LoginPageState(AppState appState) : super(appState);

List<Widget> _getAppBarActions() {
List<Widget> widgetList = [
PopupMenuButton(
onSelected: (val) => _onOptionSelected(val, context),
itemBuilder: (ctx) => [
PopupMenuItem(value: 0, child: const Text(Strings.labelLogsButton)),
PopupMenuItem(value: 1, child: const Text(Strings.labelAboutButton)),
PopupMenuItem(value: 2, child: const Text(Strings.labelLicensesButton))
],
)
];

return widgetList;
}

@override
Widget build(BuildContext context) {
final Size screenSize = MediaQuery
.of(context)
.size;
final Size screenSize = MediaQuery.of(context).size;

appState.currentContext = _scaffoldKey.currentContext;
appState.currentState = _scaffoldKey.currentState;
Expand All @@ -44,6 +60,7 @@ class _LoginPageState extends AnchrState<LoginPage> with AnchrActions {
key: _scaffoldKey,
appBar: AppBar(
title: Text(Strings.titleLoginPage),
actions: _getAppBarActions(),
),
body: Form(
key: _formKey,
Expand Down Expand Up @@ -86,20 +103,15 @@ class _LoginPageState extends AnchrState<LoginPage> with AnchrActions {
),
obscureText: true,
onSaved: (val) => userPassword = val.trim(),
validator: (val) =>
val
.trim()
.isNotEmpty ? null : Strings.errorNoPassword),
validator: (val) => val.trim().isNotEmpty ? null : Strings.errorNoPassword),
),
Container(
width: screenSize.width,
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 8),
child: RaisedButton(
child: const Text(Strings.labelLoginButton, style: TextStyle(color: Colors.white)),
color: Theme
.of(context)
.primaryColor,
color: Theme.of(context).primaryColor,
onPressed: _submit,
),
),
Expand All @@ -108,20 +120,12 @@ class _LoginPageState extends AnchrState<LoginPage> with AnchrActions {
padding: const EdgeInsets.only(top: 16),
child: RichText(
text: TextSpan(children: <TextSpan>[
TextSpan(text: Strings.msgSignUp, style: TextStyle(color: Theme
.of(context)
.textTheme
.body1
.color)),
TextSpan(
text: ' github.com/muety/anchr.',
style: TextStyle(color: Theme
.of(context)
.primaryColor, fontWeight: FontWeight.bold),
recognizer: TapGestureRecognizer()
..onTap = () => Utils.launchURL(Strings.urlAnchrGithub))
]
)),
TextSpan(text: Strings.msgSignUp, style: TextStyle(color: Theme.of(context).textTheme.body1.color)),
TextSpan(
text: ' github.com/muety/anchr.',
style: TextStyle(color: Theme.of(context).primaryColor, fontWeight: FontWeight.bold),
recognizer: TapGestureRecognizer()..onTap = () => Utils.launchURL(Strings.urlAnchrGithub))
])),
)
],
),
Expand All @@ -135,29 +139,46 @@ class _LoginPageState extends AnchrState<LoginPage> with AnchrActions {
if (this._formKey.currentState.validate()) {
_formKey.currentState.save();

login(serverUrl, userMail, userPassword)
.then((_) {

deviceInfo.androidInfo.then((info) {
StringBuffer sb = StringBuffer();
sb.writeln("SDK Version: ${info.version.sdkInt}");
sb.writeln("Android ID: ${info.androidId}");
sb.writeln("Brand: ${info.brand}");
sb.writeln("Device: ${info.device}");
sb.writeln("Manufacturer: ${info.manufacturer}");
sb.writeln("Model: ${info.model}");
sb.writeln("Physical device: ${info.isPhysicalDevice}");

FLog.info(text: "Device Info:\n${sb.toString()}");
});


FLog.info(text: "User $userMail logged in.");
Navigator.pushReplacementNamed(context, CollectionsPage.routeName);
})
.catchError((e) { FLog.error(text: "User $userMail failed to log in.", exception: e); showSnackbar(Strings.errorLoginUnauthorized); }, test: (Object o) => o is UnauthorizedException)
.catchError((e) { FLog.error(text: "User $userMail failed to log in.", exception: e); showSnackbar(Strings.errorLoginNoConnection); }, test: (Object o) => o is SocketException)
.catchError((e) { FLog.error(text: "User $userMail failed to log in.", exception: e); showSnackbar(Strings.errorLogin); });
login(serverUrl, userMail, userPassword).then((_) {
deviceInfo.androidInfo.then((info) {
StringBuffer sb = StringBuffer();
sb.writeln("SDK Version: ${info.version.sdkInt}");
sb.writeln("Android ID: ${info.androidId}");
sb.writeln("Brand: ${info.brand}");
sb.writeln("Device: ${info.device}");
sb.writeln("Manufacturer: ${info.manufacturer}");
sb.writeln("Model: ${info.model}");
sb.writeln("Physical device: ${info.isPhysicalDevice}");

FLog.info(text: "Device Info:\n${sb.toString()}");
});

FLog.info(text: "User $userMail logged in.");
Navigator.pushReplacementNamed(context, CollectionsPage.routeName);
}).catchError((e) {
FLog.error(text: "User $userMail failed to log in.", exception: e);
showSnackbar(Strings.errorLoginUnauthorized);
}, test: (Object o) => o is UnauthorizedException).catchError((e) {
FLog.error(text: "User $userMail failed to log in.", exception: e);
showSnackbar(Strings.errorLoginNoConnection);
}, test: (Object o) => o is SocketException).catchError((e) {
FLog.error(text: "User $userMail failed to log in.", exception: e);
showSnackbar(Strings.errorLogin);
});
}
}

_onOptionSelected(int val, BuildContext ctx) {
switch (val) {
case 0:
Navigator.of(ctx).pushNamed(LogsPage.routeName);
break;
case 1:
Navigator.of(ctx).pushNamed(AboutPage.routeName);
break;
case 2:
showLicensePage(context: ctx);
break;
}
}
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: anchr_android
description: Android client for Anchr.io link collections

version: 1.1.2+24
version: 1.1.3+25

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

0 comments on commit dd57acf

Please sign in to comment.