Accept review comments

This commit is contained in:
vishnukvmd 2021-11-24 11:10:07 +05:30
parent e55b440ac8
commit e30f038395
4 changed files with 44 additions and 45 deletions

View file

@ -52,24 +52,33 @@ class Session {
final String token; final String token;
final int creationTime; final int creationTime;
final String ip; final String ip;
final String userAgent; final String ua;
final String prettyUA;
final int lastUsedTime; final int lastUsedTime;
Session(this.token, this.creationTime, this.ip, this.userAgent, Session(
this.lastUsedTime); this.token,
this.creationTime,
this.ip,
this.ua,
this.prettyUA,
this.lastUsedTime,
);
Session copyWith({ Session copyWith({
String token, String token,
int creationTime, int creationTime,
String ip, String ip,
String userAgent, String ua,
String prettyUA,
int lastUsedTime, int lastUsedTime,
}) { }) {
return Session( return Session(
token ?? this.token, token ?? this.token,
creationTime ?? this.creationTime, creationTime ?? this.creationTime,
ip ?? this.ip, ip ?? this.ip,
userAgent ?? this.userAgent, ua ?? this.ua,
prettyUA ?? this.prettyUA,
lastUsedTime ?? this.lastUsedTime, lastUsedTime ?? this.lastUsedTime,
); );
} }
@ -79,7 +88,8 @@ class Session {
'token': token, 'token': token,
'creationTime': creationTime, 'creationTime': creationTime,
'ip': ip, 'ip': ip,
'userAgent': userAgent, 'ua': ua,
'prettyUA': prettyUA,
'lastUsedTime': lastUsedTime, 'lastUsedTime': lastUsedTime,
}; };
} }
@ -89,7 +99,8 @@ class Session {
map['token'], map['token'],
map['creationTime'], map['creationTime'],
map['ip'], map['ip'],
map['userAgent'], map['ua'],
map['prettyUA'],
map['lastUsedTime'], map['lastUsedTime'],
); );
} }
@ -101,7 +112,7 @@ class Session {
@override @override
String toString() { String toString() {
return 'Session(token: $token, creationTime: $creationTime, ip: $ip, userAgent: $userAgent, lastUsedTime: $lastUsedTime)'; return 'Session(token: $token, creationTime: $creationTime, ip: $ip, ua: $ua, prettyUA: $prettyUA, lastUsedTime: $lastUsedTime)';
} }
@override @override
@ -112,7 +123,8 @@ class Session {
other.token == token && other.token == token &&
other.creationTime == creationTime && other.creationTime == creationTime &&
other.ip == ip && other.ip == ip &&
other.userAgent == userAgent && other.ua == ua &&
other.prettyUA == prettyUA &&
other.lastUsedTime == lastUsedTime; other.lastUsedTime == lastUsedTime;
} }
@ -121,7 +133,8 @@ class Session {
return token.hashCode ^ return token.hashCode ^
creationTime.hashCode ^ creationTime.hashCode ^
ip.hashCode ^ ip.hashCode ^
userAgent.hashCode ^ ua.hashCode ^
prettyUA.hashCode ^
lastUsedTime.hashCode; lastUsedTime.hashCode;
} }
} }

View file

@ -1,13 +1,11 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'package:logging/logging.dart';
import 'package:photos/core/configuration.dart'; import 'package:photos/core/configuration.dart';
import 'package:photos/models/sessions.dart'; import 'package:photos/models/sessions.dart';
import 'package:photos/services/user_service.dart'; import 'package:photos/services/user_service.dart';
import 'package:photos/ui/loading_widget.dart'; import 'package:photos/ui/loading_widget.dart';
import 'package:photos/utils/date_time_util.dart'; import 'package:photos/utils/date_time_util.dart';
import 'package:photos/utils/dialog_util.dart'; import 'package:photos/utils/dialog_util.dart';
import 'package:user_agent_parser/user_agent_parser.dart';
class SessionsPage extends StatefulWidget { class SessionsPage extends StatefulWidget {
SessionsPage({Key key}) : super(key: key); SessionsPage({Key key}) : super(key: key);
@ -17,7 +15,6 @@ class SessionsPage extends StatefulWidget {
} }
class _SessionsPageState extends State<SessionsPage> { class _SessionsPageState extends State<SessionsPage> {
final _userAgentParser = UserAgentParser();
Sessions _sessions; Sessions _sessions;
@override @override
@ -44,7 +41,11 @@ class _SessionsPageState extends State<SessionsPage> {
for (final session in _sessions.sessions) { for (final session in _sessions.sessions) {
rows.add(_getSessionWidget(session)); rows.add(_getSessionWidget(session));
} }
return Column(children: rows); return SingleChildScrollView(
child: Column(
children: rows,
),
);
} }
Widget _getSessionWidget(Session session) { Widget _getSessionWidget(Session session) {
@ -58,23 +59,30 @@ class _SessionsPageState extends State<SessionsPage> {
}, },
child: Padding( child: Padding(
padding: const EdgeInsets.all(16), padding: const EdgeInsets.all(16),
child: Row( child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Column( _getUAWidget(session),
crossAxisAlignment: CrossAxisAlignment.start, Padding(padding: EdgeInsets.all(4)),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
_getUAWidget(session),
Padding(padding: EdgeInsets.all(4)),
Text( Text(
session.ip, session.ip,
style: TextStyle( style: TextStyle(
color: Colors.white.withOpacity(0.8), color: Colors.white.withOpacity(0.8),
fontSize: 14,
),
),
Text(
getFormattedTime(lastUsedTime),
style: TextStyle(
color: Colors.white.withOpacity(0.8),
fontSize: 12,
), ),
), ),
], ],
), ),
Text(getFormattedTime(lastUsedTime)),
], ],
), ),
), ),
@ -117,7 +125,7 @@ class _SessionsPageState extends State<SessionsPage> {
), ),
Padding(padding: EdgeInsets.all(8)), Padding(padding: EdgeInsets.all(8)),
Text( Text(
session.userAgent, session.ua,
style: TextStyle( style: TextStyle(
color: Colors.white.withOpacity(0.7), color: Colors.white.withOpacity(0.7),
fontSize: 14, fontSize: 14,
@ -181,20 +189,6 @@ class _SessionsPageState extends State<SessionsPage> {
), ),
); );
} }
if (session.userAgent.contains("ente")) { return Text(session.prettyUA);
return Text("Desktop");
}
final parsedUA = _userAgentParser.parseResult(session.userAgent);
if (parsedUA.browser == null) {
if (session.userAgent.contains("Android")) {
return Text("Android");
}
if (session.userAgent.contains("iPhone")) {
return Text("iPhone");
}
return Text("Mobile");
} else {
return Text("Browser (" + parsedUA.browser.name + ")");
}
} }
} }

View file

@ -1189,13 +1189,6 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.0.0" version: "2.0.0"
user_agent_parser:
dependency: "direct main"
description:
name: user_agent_parser
url: "https://pub.dartlang.org"
source: hosted
version: "0.0.1+2"
uuid: uuid:
dependency: "direct main" dependency: "direct main"
description: description:

View file

@ -97,7 +97,6 @@ dependencies:
syncfusion_flutter_sliders: ^19.2.49 syncfusion_flutter_sliders: ^19.2.49
uni_links: ^0.5.1 uni_links: ^0.5.1
url_launcher: ^6.0.3 url_launcher: ^6.0.3
user_agent_parser: ^0.0.1+2
uuid: ^3.0.4 uuid: ^3.0.4
video_player: video_player:
path: thirdparty/plugins/packages/video_player/video_player path: thirdparty/plugins/packages/video_player/video_player