Improve session view design and move some things around

This commit is contained in:
Nutcake 2023-05-29 20:16:23 +02:00
parent 1a5114a217
commit a3ecbfe281
26 changed files with 527 additions and 308 deletions

View file

@ -1,7 +1,7 @@
import 'dart:convert';
import 'package:contacts_plus_plus/clients/api_client.dart';
import 'package:contacts_plus_plus/models/friend.dart';
import 'package:contacts_plus_plus/models/users/friend.dart';
class FriendApi {
static Future<List<Friend>> getFriendsList(ApiClient client, {DateTime? lastStatusUpdate}) async {

13
lib/apis/session_api.dart Normal file
View file

@ -0,0 +1,13 @@
import 'dart:convert';
import 'package:contacts_plus_plus/clients/api_client.dart';
import 'package:contacts_plus_plus/models/session.dart';
class SessionApi {
static Future<Session> getSession(ApiClient client, {required String sessionId}) async {
final response = await client.get("/sessions/$sessionId");
client.checkResponse(response);
final body = jsonDecode(response.body);
return Session.fromMap(body);
}
}

View file

@ -1,10 +1,12 @@
import 'dart:convert';
import 'package:contacts_plus_plus/clients/api_client.dart';
import 'package:contacts_plus_plus/models/friend.dart';
import 'package:contacts_plus_plus/models/users/friend.dart';
import 'package:contacts_plus_plus/models/personal_profile.dart';
import 'package:contacts_plus_plus/models/user.dart';
import 'package:contacts_plus_plus/models/user_profile.dart';
import 'package:contacts_plus_plus/models/users/user.dart';
import 'package:contacts_plus_plus/models/users/user_profile.dart';
import 'package:contacts_plus_plus/models/users/friend_status.dart';
import 'package:contacts_plus_plus/models/users/user_status.dart';
import 'package:package_info_plus/package_info_plus.dart';
class UserApi {

View file

@ -11,7 +11,7 @@ import 'package:contacts_plus_plus/apis/friend_api.dart';
import 'package:contacts_plus_plus/apis/message_api.dart';
import 'package:contacts_plus_plus/apis/user_api.dart';
import 'package:contacts_plus_plus/clients/notification_client.dart';
import 'package:contacts_plus_plus/models/friend.dart';
import 'package:contacts_plus_plus/models/users/friend.dart';
import 'package:contacts_plus_plus/clients/api_client.dart';
import 'package:contacts_plus_plus/config.dart';
import 'package:contacts_plus_plus/models/message.dart';

View file

@ -1,234 +0,0 @@
import 'package:contacts_plus_plus/auxiliary.dart';
import 'package:contacts_plus_plus/models/session.dart';
import 'package:contacts_plus_plus/models/user_profile.dart';
import 'package:flutter/material.dart';
class Friend implements Comparable {
static const _emptyId = "-1";
static const _neosBotId = "U-Neos";
final String id;
final String username;
final String ownerId;
final UserStatus userStatus;
final UserProfile userProfile;
final FriendStatus friendStatus;
final DateTime latestMessageTime;
const Friend({required this.id, required this.username, required this.ownerId, required this.userStatus, required this.userProfile,
required this.friendStatus, required this.latestMessageTime,
});
bool get isHeadless => userStatus.activeSessions.any((session) => session.headlessHost == true && session.hostUserId == id);
factory Friend.fromMap(Map map) {
final userStatus = UserStatus.fromMap(map["userStatus"]);
return Friend(
id: map["id"],
username: map["friendUsername"],
ownerId: map["ownerId"] ?? map["id"],
// Neos bot status is always offline but should be displayed as online
userStatus: map["id"] == _neosBotId ? userStatus.copyWith(onlineStatus: OnlineStatus.online) : userStatus,
userProfile: UserProfile.fromMap(map["profile"] ?? {}),
friendStatus: FriendStatus.fromString(map["friendStatus"]),
latestMessageTime: map["latestMessageTime"] == null
? DateTime.fromMillisecondsSinceEpoch(0) : DateTime.parse(map["latestMessageTime"]),
);
}
static Friend? fromMapOrNull(Map? map) {
if (map == null) return null;
return Friend.fromMap(map);
}
factory Friend.empty() {
return Friend(
id: _emptyId,
username: "",
ownerId: "",
userStatus: UserStatus.empty(),
userProfile: UserProfile.empty(),
friendStatus: FriendStatus.none,
latestMessageTime: DateTimeX.epoch
);
}
bool get isEmpty => id == _emptyId;
Friend copyWith({
String? id, String? username, String? ownerId, UserStatus? userStatus, UserProfile? userProfile,
FriendStatus? friendStatus, DateTime? latestMessageTime}) {
return Friend(
id: id ?? this.id,
username: username ?? this.username,
ownerId: ownerId ?? this.ownerId,
userStatus: userStatus ?? this.userStatus,
userProfile: userProfile ?? this.userProfile,
friendStatus: friendStatus ?? this.friendStatus,
latestMessageTime: latestMessageTime ?? this.latestMessageTime,
);
}
Map toMap({bool shallow=false}) {
return {
"id": id,
"username": username,
"ownerId": ownerId,
"userStatus": userStatus.toMap(shallow: shallow),
"profile": userProfile.toMap(),
"friendStatus": friendStatus.name,
"latestMessageTime": latestMessageTime.toIso8601String(),
};
}
@override
int compareTo(covariant Friend other) {
return username.compareTo(other.username);
}
}
enum FriendStatus {
none,
searchResult,
requested,
ignored,
blocked,
accepted;
factory FriendStatus.fromString(String text) {
return FriendStatus.values.firstWhere((element) => element.name.toLowerCase() == text.toLowerCase(),
orElse: () => FriendStatus.none,
);
}
}
enum OnlineStatus {
offline,
invisible,
away,
busy,
online;
static final List<Color> _colors = [
Colors.transparent,
Colors.transparent,
Colors.yellow,
Colors.red,
Colors.green,
];
Color color(BuildContext context) => this == OnlineStatus.offline || this == OnlineStatus.invisible ? Theme.of(context).colorScheme.onSurface : _colors[index];
factory OnlineStatus.fromString(String? text) {
return OnlineStatus.values.firstWhere((element) => element.name.toLowerCase() == text?.toLowerCase(),
orElse: () => OnlineStatus.offline,
);
}
int compareTo(OnlineStatus other) {
if (this == other) return 0;
if (this == OnlineStatus.online) return -1;
if (other == OnlineStatus.online) return 1;
if (this == OnlineStatus.away) return -1;
if (other == OnlineStatus.away) return 1;
if (this == OnlineStatus.busy) return -1;
if (other == OnlineStatus.busy) return 1;
return 0;
}
}
class UserStatus {
final OnlineStatus onlineStatus;
final DateTime lastStatusChange;
final int currentSessionAccessLevel;
final bool currentSessionHidden;
final bool currentHosting;
final Session currentSession;
final List<Session> activeSessions;
final String neosVersion;
final String outputDevice;
final bool isMobile;
final String compatibilityHash;
const UserStatus(
{required this.onlineStatus, required this.lastStatusChange, required this.currentSession,
required this.currentSessionAccessLevel, required this.currentSessionHidden, required this.currentHosting,
required this.activeSessions, required this.neosVersion, required this.outputDevice, required this.isMobile,
required this.compatibilityHash,
});
factory UserStatus.empty() =>
UserStatus(
onlineStatus: OnlineStatus.offline,
lastStatusChange: DateTime.now(),
currentSessionAccessLevel: 0,
currentSessionHidden: false,
currentHosting: false,
currentSession: Session.none(),
activeSessions: [],
neosVersion: "",
outputDevice: "Unknown",
isMobile: false,
compatibilityHash: "",
);
factory UserStatus.fromMap(Map map) {
final statusString = map["onlineStatus"] as String?;
final status = OnlineStatus.fromString(statusString);
return UserStatus(
onlineStatus: status,
lastStatusChange: DateTime.parse(map["lastStatusChange"]),
currentSessionAccessLevel: map["currentSessionAccessLevel"] ?? 0,
currentSessionHidden: map["currentSessionHidden"] ?? false,
currentHosting: map["currentHosting"] ?? false,
currentSession: Session.fromMap(map["currentSession"]),
activeSessions: (map["activeSessions"] as List? ?? []).map((e) => Session.fromMap(e)).toList(),
neosVersion: map["neosVersion"] ?? "",
outputDevice: map["outputDevice"] ?? "Unknown",
isMobile: map["isMobile"] ?? false,
compatibilityHash: map["compatabilityHash"] ?? ""
);
}
Map toMap({bool shallow = false}) {
return {
"onlineStatus": onlineStatus.index,
"lastStatusChange": lastStatusChange.toIso8601String(),
"currentSessionAccessLevel": currentSessionAccessLevel,
"currentSessionHidden": currentSessionHidden,
"currentHosting": currentHosting,
"currentSession": currentSession.isNone || shallow ? null : currentSession.toMap(),
"activeSessions": shallow ? [] : activeSessions.map((e) => e.toMap(),).toList(),
"neosVersion": neosVersion,
"outputDevice": outputDevice,
"isMobile": isMobile,
"compatibilityHash": compatibilityHash,
};
}
UserStatus copyWith({
OnlineStatus? onlineStatus,
DateTime? lastStatusChange,
int? currentSessionAccessLevel,
bool? currentSessionHidden,
bool? currentHosting,
Session? currentSession,
List<Session>? activeSessions,
String? neosVersion,
String? outputDevice,
bool? isMobile,
String? compatibilityHash,
}) =>
UserStatus(
onlineStatus: onlineStatus ?? this.onlineStatus,
lastStatusChange: lastStatusChange ?? this.lastStatusChange,
currentSessionAccessLevel: currentSessionAccessLevel ?? this.currentSessionAccessLevel,
currentSessionHidden: currentSessionHidden ?? this.currentSessionHidden,
currentHosting: currentHosting ?? this.currentHosting,
currentSession: currentSession ?? this.currentSession,
activeSessions: activeSessions ?? this.activeSessions,
neosVersion: neosVersion ?? this.neosVersion,
outputDevice: outputDevice ?? this.outputDevice,
isMobile: isMobile ?? this.isMobile,
compatibilityHash: compatibilityHash ?? this.compatibilityHash,
);
}

View file

@ -1,4 +1,4 @@
import 'package:contacts_plus_plus/models/user_profile.dart';
import 'package:contacts_plus_plus/models/users/user_profile.dart';
class PersonalProfile {
final String id;

View file

@ -1,7 +1,7 @@
import 'dart:convert';
import 'package:contacts_plus_plus/models/friend.dart';
import 'package:contacts_plus_plus/models/sem_ver.dart';
import 'package:contacts_plus_plus/models/users/online_status.dart';
import 'package:flutter/material.dart';
import 'package:uuid/uuid.dart';

View file

@ -0,0 +1,88 @@
import 'package:contacts_plus_plus/auxiliary.dart';
import 'package:contacts_plus_plus/models/users/user_profile.dart';
import 'package:contacts_plus_plus/models/users/friend_status.dart';
import 'package:contacts_plus_plus/models/users/online_status.dart';
import 'package:contacts_plus_plus/models/users/user_status.dart';
class Friend implements Comparable {
static const _emptyId = "-1";
static const _neosBotId = "U-Neos";
final String id;
final String username;
final String ownerId;
final UserStatus userStatus;
final UserProfile userProfile;
final FriendStatus friendStatus;
final DateTime latestMessageTime;
const Friend({required this.id, required this.username, required this.ownerId, required this.userStatus, required this.userProfile,
required this.friendStatus, required this.latestMessageTime,
});
bool get isHeadless => userStatus.activeSessions.any((session) => session.headlessHost == true && session.hostUserId == id);
factory Friend.fromMap(Map map) {
final userStatus = UserStatus.fromMap(map["userStatus"]);
return Friend(
id: map["id"],
username: map["friendUsername"],
ownerId: map["ownerId"] ?? map["id"],
// Neos bot status is always offline but should be displayed as online
userStatus: map["id"] == _neosBotId ? userStatus.copyWith(onlineStatus: OnlineStatus.online) : userStatus,
userProfile: UserProfile.fromMap(map["profile"] ?? {}),
friendStatus: FriendStatus.fromString(map["friendStatus"]),
latestMessageTime: map["latestMessageTime"] == null
? DateTime.fromMillisecondsSinceEpoch(0) : DateTime.parse(map["latestMessageTime"]),
);
}
static Friend? fromMapOrNull(Map? map) {
if (map == null) return null;
return Friend.fromMap(map);
}
factory Friend.empty() {
return Friend(
id: _emptyId,
username: "",
ownerId: "",
userStatus: UserStatus.empty(),
userProfile: UserProfile.empty(),
friendStatus: FriendStatus.none,
latestMessageTime: DateTimeX.epoch
);
}
bool get isEmpty => id == _emptyId;
Friend copyWith({
String? id, String? username, String? ownerId, UserStatus? userStatus, UserProfile? userProfile,
FriendStatus? friendStatus, DateTime? latestMessageTime}) {
return Friend(
id: id ?? this.id,
username: username ?? this.username,
ownerId: ownerId ?? this.ownerId,
userStatus: userStatus ?? this.userStatus,
userProfile: userProfile ?? this.userProfile,
friendStatus: friendStatus ?? this.friendStatus,
latestMessageTime: latestMessageTime ?? this.latestMessageTime,
);
}
Map toMap({bool shallow=false}) {
return {
"id": id,
"username": username,
"ownerId": ownerId,
"userStatus": userStatus.toMap(shallow: shallow),
"profile": userProfile.toMap(),
"friendStatus": friendStatus.name,
"latestMessageTime": latestMessageTime.toIso8601String(),
};
}
@override
int compareTo(covariant Friend other) {
return username.compareTo(other.username);
}
}

View file

@ -0,0 +1,14 @@
enum FriendStatus {
none,
searchResult,
requested,
ignored,
blocked,
accepted;
factory FriendStatus.fromString(String text) {
return FriendStatus.values.firstWhere((element) => element.name.toLowerCase() == text.toLowerCase(),
orElse: () => FriendStatus.none,
);
}
}

View file

@ -0,0 +1,36 @@
import 'package:flutter/material.dart';
enum OnlineStatus {
offline,
invisible,
away,
busy,
online;
static final List<Color> _colors = [
Colors.transparent,
Colors.transparent,
Colors.yellow,
Colors.red,
Colors.green,
];
Color color(BuildContext context) => this == OnlineStatus.offline || this == OnlineStatus.invisible ? Theme.of(context).colorScheme.onSurface : _colors[index];
factory OnlineStatus.fromString(String? text) {
return OnlineStatus.values.firstWhere((element) => element.name.toLowerCase() == text?.toLowerCase(),
orElse: () => OnlineStatus.offline,
);
}
int compareTo(OnlineStatus other) {
if (this == other) return 0;
if (this == OnlineStatus.online) return -1;
if (other == OnlineStatus.online) return 1;
if (this == OnlineStatus.away) return -1;
if (other == OnlineStatus.away) return 1;
if (this == OnlineStatus.busy) return -1;
if (other == OnlineStatus.busy) return 1;
return 0;
}
}

View file

@ -1,4 +1,4 @@
import 'package:contacts_plus_plus/models/user_profile.dart';
import 'package:contacts_plus_plus/models/users/user_profile.dart';
class User {
final String id;

View file

@ -0,0 +1,99 @@
import 'package:contacts_plus_plus/models/session.dart';
import 'package:contacts_plus_plus/models/users/online_status.dart';
class UserStatus {
final OnlineStatus onlineStatus;
final DateTime lastStatusChange;
final int currentSessionAccessLevel;
final bool currentSessionHidden;
final bool currentHosting;
final Session currentSession;
final List<Session> activeSessions;
final String neosVersion;
final String outputDevice;
final bool isMobile;
final String compatibilityHash;
const UserStatus(
{required this.onlineStatus, required this.lastStatusChange, required this.currentSession,
required this.currentSessionAccessLevel, required this.currentSessionHidden, required this.currentHosting,
required this.activeSessions, required this.neosVersion, required this.outputDevice, required this.isMobile,
required this.compatibilityHash,
});
factory UserStatus.empty() =>
UserStatus(
onlineStatus: OnlineStatus.offline,
lastStatusChange: DateTime.now(),
currentSessionAccessLevel: 0,
currentSessionHidden: false,
currentHosting: false,
currentSession: Session.none(),
activeSessions: [],
neosVersion: "",
outputDevice: "Unknown",
isMobile: false,
compatibilityHash: "",
);
factory UserStatus.fromMap(Map map) {
final statusString = map["onlineStatus"] as String?;
final status = OnlineStatus.fromString(statusString);
return UserStatus(
onlineStatus: status,
lastStatusChange: DateTime.parse(map["lastStatusChange"]),
currentSessionAccessLevel: map["currentSessionAccessLevel"] ?? 0,
currentSessionHidden: map["currentSessionHidden"] ?? false,
currentHosting: map["currentHosting"] ?? false,
currentSession: Session.fromMap(map["currentSession"]),
activeSessions: (map["activeSessions"] as List? ?? []).map((e) => Session.fromMap(e)).toList(),
neosVersion: map["neosVersion"] ?? "",
outputDevice: map["outputDevice"] ?? "Unknown",
isMobile: map["isMobile"] ?? false,
compatibilityHash: map["compatabilityHash"] ?? ""
);
}
Map toMap({bool shallow = false}) {
return {
"onlineStatus": onlineStatus.index,
"lastStatusChange": lastStatusChange.toIso8601String(),
"currentSessionAccessLevel": currentSessionAccessLevel,
"currentSessionHidden": currentSessionHidden,
"currentHosting": currentHosting,
"currentSession": currentSession.isNone || shallow ? null : currentSession.toMap(),
"activeSessions": shallow ? [] : activeSessions.map((e) => e.toMap(),).toList(),
"neosVersion": neosVersion,
"outputDevice": outputDevice,
"isMobile": isMobile,
"compatibilityHash": compatibilityHash,
};
}
UserStatus copyWith({
OnlineStatus? onlineStatus,
DateTime? lastStatusChange,
int? currentSessionAccessLevel,
bool? currentSessionHidden,
bool? currentHosting,
Session? currentSession,
List<Session>? activeSessions,
String? neosVersion,
String? outputDevice,
bool? isMobile,
String? compatibilityHash,
}) =>
UserStatus(
onlineStatus: onlineStatus ?? this.onlineStatus,
lastStatusChange: lastStatusChange ?? this.lastStatusChange,
currentSessionAccessLevel: currentSessionAccessLevel ?? this.currentSessionAccessLevel,
currentSessionHidden: currentSessionHidden ?? this.currentSessionHidden,
currentHosting: currentHosting ?? this.currentHosting,
currentSession: currentSession ?? this.currentSession,
activeSessions: activeSessions ?? this.activeSessions,
neosVersion: neosVersion ?? this.neosVersion,
outputDevice: outputDevice ?? this.outputDevice,
isMobile: isMobile ?? this.isMobile,
compatibilityHash: compatibilityHash ?? this.compatibilityHash,
);
}

View file

@ -1,6 +1,6 @@
import 'package:contacts_plus_plus/auxiliary.dart';
import 'package:contacts_plus_plus/clients/messaging_client.dart';
import 'package:contacts_plus_plus/models/friend.dart';
import 'package:contacts_plus_plus/models/users/friend.dart';
import 'package:contacts_plus_plus/models/message.dart';
import 'package:contacts_plus_plus/widgets/formatted_text.dart';
import 'package:contacts_plus_plus/widgets/friends/friend_online_status_indicator.dart';
@ -83,7 +83,7 @@ class FriendListTile extends StatelessWidget {
MaterialPageRoute(
builder: (context) => ChangeNotifierProvider<MessagingClient>.value(
value: mClient,
child: MessagesList(),
child: const MessagesList(),
),
),
);

View file

@ -1,4 +1,5 @@
import 'package:contacts_plus_plus/models/friend.dart';
import 'package:contacts_plus_plus/models/users/online_status.dart';
import 'package:contacts_plus_plus/models/users/user_status.dart';
import 'package:flutter/material.dart';
class FriendOnlineStatusIndicator extends StatelessWidget {

View file

@ -3,7 +3,8 @@ import 'dart:async';
import 'package:contacts_plus_plus/apis/user_api.dart';
import 'package:contacts_plus_plus/client_holder.dart';
import 'package:contacts_plus_plus/clients/messaging_client.dart';
import 'package:contacts_plus_plus/models/friend.dart';
import 'package:contacts_plus_plus/models/users/online_status.dart';
import 'package:contacts_plus_plus/models/users/user_status.dart';
import 'package:contacts_plus_plus/widgets/default_error_widget.dart';
import 'package:contacts_plus_plus/widgets/friends/expanding_input_fab.dart';
import 'package:contacts_plus_plus/widgets/friends/friend_list_tile.dart';

View file

@ -1,7 +1,7 @@
import 'package:contacts_plus_plus/apis/user_api.dart';
import 'package:contacts_plus_plus/auxiliary.dart';
import 'package:contacts_plus_plus/client_holder.dart';
import 'package:contacts_plus_plus/models/user.dart';
import 'package:contacts_plus_plus/models/users/user.dart';
import 'package:contacts_plus_plus/widgets/generic_avatar.dart';
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';

View file

@ -3,7 +3,7 @@ import 'dart:async';
import 'package:contacts_plus_plus/apis/user_api.dart';
import 'package:contacts_plus_plus/client_holder.dart';
import 'package:contacts_plus_plus/clients/messaging_client.dart';
import 'package:contacts_plus_plus/models/user.dart';
import 'package:contacts_plus_plus/models/users/user.dart';
import 'package:contacts_plus_plus/widgets/default_error_widget.dart';
import 'package:contacts_plus_plus/widgets/friends/user_list_tile.dart';
import 'package:flutter/material.dart';

View file

@ -7,7 +7,7 @@ import 'package:contacts_plus_plus/auxiliary.dart';
import 'package:contacts_plus_plus/client_holder.dart';
import 'package:contacts_plus_plus/clients/api_client.dart';
import 'package:contacts_plus_plus/clients/messaging_client.dart';
import 'package:contacts_plus_plus/models/friend.dart';
import 'package:contacts_plus_plus/models/users/friend.dart';
import 'package:contacts_plus_plus/models/message.dart';
import 'package:contacts_plus_plus/widgets/messages/message_attachment_list.dart';
import 'package:file_picker/file_picker.dart';

View file

@ -7,6 +7,7 @@ import 'package:contacts_plus_plus/widgets/formatted_text.dart';
import 'package:contacts_plus_plus/widgets/generic_avatar.dart';
import 'package:contacts_plus_plus/widgets/messages/messages_session_header.dart';
import 'package:contacts_plus_plus/widgets/messages/message_state_indicator.dart';
import 'package:contacts_plus_plus/widgets/session_view.dart';
import 'package:flutter/material.dart';
class MessageSessionInvite extends StatelessWidget {
@ -22,7 +23,7 @@ class MessageSessionInvite extends StatelessWidget {
constraints: const BoxConstraints(maxWidth: 300),
child: TextButton(
onPressed: () {
showDialog(context: context, builder: (context) => SessionPopup(session: sessionInfo));
Navigator.of(context).push(MaterialPageRoute(builder: (context) => SessionView(session: sessionInfo)));
},
style: TextButton.styleFrom(padding: EdgeInsets.zero),
child: Container(
@ -44,7 +45,7 @@ class MessageSessionInvite extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.center,
children: [
GenericAvatar(
imageUri: Aux.neosDbToHttp(Aux.neosDbToHttp(sessionInfo.thumbnail)),
imageUri: Aux.neosDbToHttp(sessionInfo.thumbnail),
placeholderIcon: Icons.no_photography,
foregroundColor: foregroundColor,
),

View file

@ -1,6 +1,6 @@
import 'package:contacts_plus_plus/clients/audio_cache_client.dart';
import 'package:contacts_plus_plus/clients/messaging_client.dart';
import 'package:contacts_plus_plus/models/friend.dart';
import 'package:contacts_plus_plus/models/users/friend.dart';
import 'package:contacts_plus_plus/widgets/default_error_widget.dart';
import 'package:contacts_plus_plus/widgets/friends/friend_online_status_indicator.dart';
import 'package:contacts_plus_plus/widgets/messages/message_input_bar.dart';
@ -21,7 +21,7 @@ class _MessagesListState extends State<MessagesList> with SingleTickerProviderSt
final ScrollController _sessionListScrollController = ScrollController();
bool _showSessionListScrollChevron = false;
bool _sessionListOpen = false;
bool _sessionListOpen = true;
double get _shevronOpacity => _showSessionListScrollChevron ? 1.0 : 0.0;

View file

@ -3,6 +3,7 @@ import 'package:contacts_plus_plus/auxiliary.dart';
import 'package:contacts_plus_plus/models/session.dart';
import 'package:contacts_plus_plus/widgets/formatted_text.dart';
import 'package:contacts_plus_plus/widgets/generic_avatar.dart';
import 'package:contacts_plus_plus/widgets/session_view.dart';
import 'package:flutter/material.dart';
class SessionPopup extends StatelessWidget {
@ -39,7 +40,7 @@ class SessionPopup extends StatelessWidget {
style: Theme.of(context).textTheme.labelMedium,
softWrap: true,
),
Text("Access: ${session.accessLevel.toReadableString()}"),
Text("Access: ${session.accessLevel.toReadableString()}", style: Theme.of(context).textTheme.labelMedium),
Text("Users: ${session.sessionUsers.length}", style: Theme.of(context).textTheme.labelMedium),
Text("Maximum users: ${session.maxUsers}", style: Theme.of(context).textTheme.labelMedium),
Text("Headless: ${session.headlessHost ? "Yes" : "No"}", style: Theme.of(context).textTheme.labelMedium),
@ -119,7 +120,7 @@ class SessionTile extends StatelessWidget {
Widget build(BuildContext context) {
return TextButton(
onPressed: () {
showDialog(context: context, builder: (context) => SessionPopup(session: session));
Navigator.of(context).push(MaterialPageRoute(builder: (context) => SessionView(session: session)));
},
child: Row(
mainAxisAlignment: MainAxisAlignment.center,

View file

@ -0,0 +1,185 @@
import 'package:cached_network_image/cached_network_image.dart';
import 'package:contacts_plus_plus/auxiliary.dart';
import 'package:contacts_plus_plus/models/session.dart';
import 'package:contacts_plus_plus/widgets/formatted_text.dart';
import 'package:contacts_plus_plus/widgets/settings_page.dart';
import 'package:flutter/material.dart';
import 'package:photo_view/photo_view.dart';
class SessionView extends StatelessWidget {
const SessionView({required this.session, super.key});
final Session session;
@override
Widget build(BuildContext context) {
return Scaffold(
body: CustomScrollView(
physics: const BouncingScrollPhysics(decelerationRate: ScrollDecelerationRate.fast),
slivers: [
SliverAppBar(
leading: IconButton(
icon: const Icon(
Icons.arrow_back_outlined,
),
onPressed: () {
Navigator.of(context).pop();
},
),
pinned: true,
snap: false,
floating: false,
expandedHeight: 192,
surfaceTintColor: Theme.of(context).colorScheme.surfaceVariant,
centerTitle: true,
title: FormattedText(
session.formattedName,
maxLines: 1,
style: Theme.of(context).textTheme.titleLarge,
),
bottom: PreferredSize(
preferredSize: const Size.fromHeight(1),
child: Row(
children: [
Expanded(
child: Container(
width: double.infinity,
height: 1,
color: Colors.black,
)),
],
),
),
flexibleSpace: FlexibleSpaceBar(
collapseMode: CollapseMode.pin,
background: CachedNetworkImage(
imageUrl: Aux.neosDbToHttp(session.thumbnail),
imageBuilder: (context, image) {
return InkWell(
onTap: () async {
await Navigator.push(
context,
MaterialPageRoute(
builder: (context) => PhotoView(
minScale: PhotoViewComputedScale.contained,
imageProvider: image,
heroAttributes: PhotoViewHeroAttributes(tag: session.id),
),
),
);
},
child: Hero(
tag: session.id,
child: Image(
image: image,
fit: BoxFit.cover,
),
),
);
},
errorWidget: (context, url, error) => const Icon(
Icons.broken_image,
size: 64,
),
placeholder: (context, uri) => const Center(child: CircularProgressIndicator()),
),
),
),
SliverToBoxAdapter(
child: Padding(
padding: const EdgeInsets.only(top: 12),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.only(left: 16.0, right: 16.0, bottom: 8),
child: session.formattedDescription.isEmpty
? Text("No description", style: Theme.of(context).textTheme.labelLarge)
: FormattedText(
session.formattedDescription,
style: Theme.of(context).textTheme.titleLarge,
),
),
const ListSectionHeader(
leadingText: "Tags:",
showLine: false,
),
Padding(
padding: const EdgeInsets.only(left: 16.0, right: 16.0, bottom: 8.0),
child: Text(
session.tags.isEmpty ? "None" : session.tags.join(", "),
style: Theme.of(context).textTheme.labelMedium,
textAlign: TextAlign.start,
softWrap: true,
),
),
const ListSectionHeader(
leadingText: "Details:",
showLine: false,
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
"Access: ",
style: Theme.of(context).textTheme.labelLarge,
),
Text(
session.accessLevel.toReadableString(),
style: Theme.of(context).textTheme.labelMedium,
),
],
),
),
Padding(
padding: const EdgeInsets.only(left: 16.0, right: 16.0, bottom: 8),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
"Headless: ",
style: Theme.of(context).textTheme.labelLarge,
),
Text(
session.headlessHost ? "Yes" : "No",
style: Theme.of(context).textTheme.labelMedium,
),
],
),
),
ListSectionHeader(
leadingText: "Users",
trailingText:
"${session.sessionUsers.length.toString().padLeft(2, "0")}/${session.maxUsers.toString().padLeft(2, "0")}",
showLine: false,
),
],
),
),
),
SliverList(
delegate: SliverChildBuilderDelegate(
(BuildContext context, int index) {
final user = session.sessionUsers[index % session.sessionUsers.length];
return ListTile(
dense: true,
title: Text(
user.username,
textAlign: TextAlign.start,
),
subtitle: Text(
user.isPresent ? "Active" : "Inactive",
textAlign: TextAlign.start,
),
);
},
childCount: session.sessionUsers.length * 4,
),
)
],
),
);
}
}

View file

@ -23,21 +23,25 @@ class SettingsPage extends StatelessWidget {
),
body: ListView(
children: [
const ListSectionHeader(name: "Notifications"),
const ListSectionHeader(leadingText: "Notifications"),
BooleanSettingsTile(
title: "Enable Notifications",
initialState: !sClient.currentSettings.notificationsDenied.valueOrDefault,
onChanged: (value) async => await sClient.changeSettings(sClient.currentSettings.copyWith(notificationsDenied: !value)),
onChanged: (value) async =>
await sClient.changeSettings(sClient.currentSettings.copyWith(notificationsDenied: !value)),
),
const ListSectionHeader(name: "Appearance"),
const ListSectionHeader(leadingText: "Appearance"),
ListTile(
trailing: StatefulBuilder(
builder: (context, setState) {
trailing: StatefulBuilder(builder: (context, setState) {
return DropdownButton<ThemeMode>(
items: ThemeMode.values.map((mode) => DropdownMenuItem<ThemeMode>(
items: ThemeMode.values
.map((mode) => DropdownMenuItem<ThemeMode>(
value: mode,
child: Text("${toBeginningOfSentenceCase(mode.name)}",),
)).toList(),
child: Text(
"${toBeginningOfSentenceCase(mode.name)}",
),
))
.toList(),
value: ThemeMode.values[sClient.currentSettings.themeMode.valueOrDefault],
onChanged: (ThemeMode? value) async {
final currentSetting = sClient.currentSettings.themeMode.value;
@ -50,23 +54,21 @@ class SettingsPage extends StatelessWidget {
setState(() {});
},
);
}
),
}),
title: const Text("Theme Mode"),
),
const ListSectionHeader(name: "Other"),
const ListSectionHeader(leadingText: "Other"),
ListTile(
trailing: const Icon(Icons.logout),
title: const Text("Sign out"),
onTap: () {
showDialog(
context: context,
builder: (context) =>
AlertDialog(
title: Text("Are you sure you want to sign out?", style: Theme
.of(context)
.textTheme
.titleLarge,),
builder: (context) => AlertDialog(
title: Text(
"Are you sure you want to sign out?",
style: Theme.of(context).textTheme.titleLarge,
),
actions: [
TextButton(onPressed: () => Navigator.of(context).pop(), child: const Text("No")),
TextButton(
@ -89,9 +91,11 @@ class SettingsPage extends StatelessWidget {
applicationVersion: (await PackageInfo.fromPlatform()).version,
applicationIcon: InkWell(
onTap: () async {
if (!await launchUrl(Uri.parse("https://github.com/Nutcake/contacts-plus-plus"), mode: LaunchMode.externalApplication)) {
if (!await launchUrl(Uri.parse("https://github.com/Nutcake/contacts-plus-plus"),
mode: LaunchMode.externalApplication)) {
if (context.mounted) {
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text("Failed to open link.")));
ScaffoldMessenger.of(context)
.showSnackBar(const SnackBar(content: Text("Failed to open link.")));
}
}
},
@ -112,26 +116,35 @@ class SettingsPage extends StatelessWidget {
}
class ListSectionHeader extends StatelessWidget {
const ListSectionHeader({required this.name, super.key});
const ListSectionHeader({required this.leadingText, this.trailingText, this.showLine = true, super.key});
final String name;
final String leadingText;
final String? trailingText;
final bool showLine;
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final textTheme = Theme.of(context).textTheme.labelSmall?.copyWith(
color: Theme.of(context).colorScheme.onSurfaceVariant,
);
return Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(name, style: theme.textTheme.labelSmall?.copyWith(color: theme.colorScheme.onSurfaceVariant)),
Text(leadingText, style: textTheme),
Expanded(
child: Container(
margin: const EdgeInsets.symmetric(horizontal: 8),
color: Colors.white12,
height: 1,
height: showLine ? 1 : 0,
),
),
if (trailingText != null)
Text(
trailingText!,
style: textTheme,
),
)
],
),
);
@ -173,5 +186,4 @@ class _BooleanSettingsTileState extends State<BooleanSettingsTile> {
},
);
}
}

View file

@ -998,5 +998,5 @@ packages:
source: hosted
version: "6.3.0"
sdks:
dart: ">=3.0.0 <4.0.0"
dart: ">=3.0.1 <4.0.0"
flutter: ">=3.4.0-17.0.pre"

View file

@ -16,10 +16,10 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
# In Windows, build-name is used as the major, minor, and patch parts
# of the product and file versions while build-number is used as the build suffix.
version: 1.3.1+1
version: 1.3.2+1
environment:
sdk: '>=3.0.0'
sdk: '>=3.0.1'
# Dependencies specify other packages that your package needs in order to work.
# To automatically upgrade your package dependencies to the latest versions