2024-08-02 09:14:23 +00:00
|
|
|
import 'dart:convert';
|
|
|
|
|
|
|
|
import 'package:avatar_stack/avatar_stack.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
2024-09-07 09:45:44 +00:00
|
|
|
import 'package:gap/gap.dart';
|
2024-08-02 09:14:23 +00:00
|
|
|
import 'package:get/get.dart';
|
|
|
|
import 'package:solian/models/account.dart';
|
|
|
|
import 'package:solian/models/call.dart';
|
|
|
|
import 'package:solian/models/channel.dart';
|
|
|
|
import 'package:solian/providers/call.dart';
|
2024-08-19 17:10:15 +00:00
|
|
|
import 'package:solian/theme.dart';
|
2024-09-10 13:53:05 +00:00
|
|
|
import 'package:solian/widgets/auto_cache_image.dart';
|
2024-08-02 09:14:23 +00:00
|
|
|
import 'package:solian/widgets/chat/call/call_prejoin.dart';
|
|
|
|
|
|
|
|
class ChannelCallIndicator extends StatelessWidget {
|
|
|
|
final Channel channel;
|
|
|
|
final Call ongoingCall;
|
2024-08-19 17:10:15 +00:00
|
|
|
final Function onJoin;
|
2024-08-02 09:14:23 +00:00
|
|
|
|
2024-08-19 17:10:15 +00:00
|
|
|
const ChannelCallIndicator({
|
|
|
|
super.key,
|
|
|
|
required this.channel,
|
|
|
|
required this.ongoingCall,
|
|
|
|
required this.onJoin,
|
|
|
|
});
|
2024-08-02 09:14:23 +00:00
|
|
|
|
|
|
|
void _showCallPrejoin(BuildContext context) {
|
|
|
|
showModalBottomSheet(
|
|
|
|
useRootNavigator: true,
|
|
|
|
context: context,
|
|
|
|
builder: (context) => ChatCallPrejoinPopup(
|
|
|
|
ongoingCall: ongoingCall,
|
|
|
|
channel: channel,
|
2024-08-19 17:19:18 +00:00
|
|
|
onJoin: onJoin,
|
2024-08-02 09:14:23 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final ChatCallProvider call = Get.find();
|
|
|
|
|
|
|
|
return MaterialBanner(
|
|
|
|
padding: const EdgeInsets.only(left: 16, top: 4, bottom: 4),
|
|
|
|
leading: const Icon(Icons.call_received),
|
|
|
|
backgroundColor: Theme.of(context).colorScheme.surfaceContainer,
|
|
|
|
dividerColor: Colors.transparent,
|
|
|
|
content: Row(
|
|
|
|
children: [
|
2024-08-19 17:10:15 +00:00
|
|
|
Obx(() {
|
|
|
|
if (call.isInitialized.value) {
|
|
|
|
return Text('callOngoingJoined'.trParams({
|
|
|
|
'duration': call.lastDuration.value,
|
|
|
|
}));
|
2024-09-08 08:03:50 +00:00
|
|
|
} else if (ongoingCall.participants!.isEmpty) {
|
2024-08-19 17:10:15 +00:00
|
|
|
return Text('callOngoingEmpty'.tr);
|
|
|
|
} else {
|
|
|
|
return Text('callOngoingParticipants'.trParams({
|
2024-09-08 08:03:50 +00:00
|
|
|
'count': ongoingCall.participants!.length.toString(),
|
2024-08-19 17:10:15 +00:00
|
|
|
}));
|
|
|
|
}
|
|
|
|
}),
|
2024-09-07 09:45:44 +00:00
|
|
|
const Gap(6),
|
2024-08-19 17:10:15 +00:00
|
|
|
Obx(() {
|
|
|
|
if (call.isInitialized.value) {
|
2024-09-07 09:48:07 +00:00
|
|
|
return const SizedBox.shrink();
|
2024-08-19 17:10:15 +00:00
|
|
|
}
|
2024-09-08 08:03:50 +00:00
|
|
|
if (ongoingCall.participants!.isNotEmpty) {
|
2024-08-19 17:10:15 +00:00
|
|
|
return Container(
|
2024-08-02 09:14:23 +00:00
|
|
|
height: 28,
|
2024-08-19 17:10:15 +00:00
|
|
|
constraints: const BoxConstraints(maxWidth: 120),
|
|
|
|
child: AvatarStack(
|
|
|
|
height: 28,
|
|
|
|
borderWidth: 0,
|
2024-09-08 08:03:50 +00:00
|
|
|
avatars: ongoingCall.participants!.map((x) {
|
2024-08-19 17:10:15 +00:00
|
|
|
final userinfo =
|
|
|
|
Account.fromJson(jsonDecode(x['metadata']));
|
2024-09-10 13:53:05 +00:00
|
|
|
return AutoCacheImage.provider(userinfo.avatar);
|
2024-08-19 17:10:15 +00:00
|
|
|
}).toList(),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
2024-09-07 09:48:07 +00:00
|
|
|
return const SizedBox.shrink();
|
2024-08-19 17:10:15 +00:00
|
|
|
})
|
2024-08-02 09:14:23 +00:00
|
|
|
],
|
|
|
|
),
|
|
|
|
actions: [
|
|
|
|
Obx(() {
|
2024-08-19 17:10:15 +00:00
|
|
|
if (call.isBusy.value) {
|
|
|
|
return const SizedBox(
|
|
|
|
height: 20,
|
|
|
|
width: 20,
|
|
|
|
child: CircularProgressIndicator(strokeWidth: 3),
|
|
|
|
).paddingAll(16);
|
|
|
|
} else if (call.current.value == null) {
|
2024-08-02 09:14:23 +00:00
|
|
|
return TextButton(
|
|
|
|
onPressed: () => _showCallPrejoin(context),
|
|
|
|
child: Text('callJoin'.tr),
|
|
|
|
);
|
2024-08-19 17:10:15 +00:00
|
|
|
} else if (call.channel.value?.id == channel.id &&
|
|
|
|
!SolianTheme.isLargeScreen(context)) {
|
2024-08-02 09:14:23 +00:00
|
|
|
return TextButton(
|
2024-08-19 17:10:15 +00:00
|
|
|
onPressed: () => onJoin(),
|
2024-08-02 09:14:23 +00:00
|
|
|
child: Text('callResume'.tr),
|
|
|
|
);
|
2024-08-19 17:10:15 +00:00
|
|
|
} else if (!SolianTheme.isLargeScreen(context)) {
|
2024-08-02 09:14:23 +00:00
|
|
|
return TextButton(
|
|
|
|
onPressed: null,
|
|
|
|
child: Text('callJoin'.tr),
|
|
|
|
);
|
|
|
|
}
|
2024-09-07 09:48:07 +00:00
|
|
|
return const SizedBox.shrink();
|
2024-08-02 09:14:23 +00:00
|
|
|
})
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|