188 lines
6.1 KiB
Dart
188 lines
6.1 KiB
Dart
// Author: fengshengxiong
|
|
// Date: 2024/6/21
|
|
// Description: 首页单曲Item
|
|
|
|
import 'package:background_downloader/background_downloader.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:tone_snap/components/base_easyloading.dart';
|
|
import 'package:tone_snap/components/dialog/remind_dialog.dart';
|
|
import 'package:tone_snap/components/network_image_widget.dart';
|
|
import 'package:tone_snap/data/models/music_model.dart';
|
|
import 'package:tone_snap/data/storage/offline_box.dart';
|
|
import 'package:tone_snap/generated/assets.dart';
|
|
import 'package:tone_snap/global/download_manager.dart';
|
|
import 'package:tone_snap/modules/sideb/controllers/music_player_controller.dart';
|
|
import 'package:tone_snap/modules/sideb/more_bottom_sheet/more_bottom_sheet_view.dart';
|
|
import 'package:tone_snap/modules/sideb/offline/offline_controller.dart';
|
|
import 'package:tone_snap/modules/sideb/personal_music_library/personal_music_library_controller.dart';
|
|
import 'package:tone_snap/modules/sideb/widgets/music_item_marquee_text.dart';
|
|
import 'package:tone_snap/res/themes/app_colors.dart';
|
|
import 'package:tone_snap/utils/obj_util.dart';
|
|
|
|
class BrowseItemAtv extends StatelessWidget {
|
|
const BrowseItemAtv({super.key, required this.musicModel, required this.onTap});
|
|
|
|
final MusicModel musicModel;
|
|
final Function() onTap;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return ClipRRect(
|
|
borderRadius: BorderRadius.circular(8).r,
|
|
child: Material(
|
|
color: Colors.transparent,
|
|
child: InkWell(
|
|
onTap: onTap,
|
|
child: SizedBox(
|
|
height: 60.w,
|
|
child: Row(
|
|
children: [
|
|
_buildCover(),
|
|
_buildContent(),
|
|
_buildDownload(),
|
|
_buildMore(),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildCover() {
|
|
return NetworkImageWidget(
|
|
url: musicModel.coverUrl,
|
|
width: 60.w,
|
|
height: 60.w,
|
|
radius: 8.r,
|
|
);
|
|
}
|
|
|
|
Widget _buildContent() {
|
|
return Expanded(
|
|
child: Padding(
|
|
padding: const EdgeInsets.only(left: 12).w,
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Obx(() {
|
|
return MusicItemMarqueeText(
|
|
text: musicModel.title,
|
|
showMarquee: MusicPlayerController.to.getMusicModel()?.videoId == musicModel.videoId && ObjUtil.isNotEmpty(musicModel.videoId),
|
|
);
|
|
}),
|
|
SizedBox(height: 4.h),
|
|
Obx(() {
|
|
return MusicItemMarqueeText(
|
|
text: musicModel.subtitle,
|
|
isTitle: false,
|
|
showMarquee: MusicPlayerController.to.getMusicModel()?.videoId == musicModel.videoId && ObjUtil.isNotEmpty(musicModel.videoId),
|
|
);
|
|
}),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildDownload() {
|
|
return ClipOval(
|
|
child: Material(
|
|
color: Colors.transparent,
|
|
child: InkWell(
|
|
onTap: onTapDownload,
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(4).w,
|
|
child: SizedBox(
|
|
width: 24.w,
|
|
height: 24.w,
|
|
child: GetBuilder<DownloadManager>(
|
|
id: DownloadManager.to.downloadStateId,
|
|
builder: (_) {
|
|
if (OfflineBox().checkDownloaded(musicModel.videoId)) {
|
|
return Image.asset(Assets.sideBDownloaded);
|
|
} else {
|
|
if (DownloadManager.to.getMusicModel(musicModel.videoId)?.taskStatus == TaskStatus.enqueued) {
|
|
return CircularProgressIndicator(
|
|
color: seedColor,
|
|
strokeWidth: 2.w,
|
|
);
|
|
} else if (DownloadManager.to.getMusicModel(musicModel.videoId)?.taskStatus == TaskStatus.running) {
|
|
return CircularProgressIndicator(
|
|
value: DownloadManager.to.getMusicModel(musicModel.videoId)?.progress,
|
|
backgroundColor: seedColor.withOpacity(0.2),
|
|
valueColor: const AlwaysStoppedAnimation<Color>(seedColor),
|
|
strokeWidth: 2.w,
|
|
);
|
|
} else {
|
|
return Image.asset(Assets.sideBNotDownload2);
|
|
}
|
|
}
|
|
},
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildMore() {
|
|
return ClipOval(
|
|
child: Material(
|
|
color: Colors.transparent,
|
|
child: InkWell(
|
|
onTap: onTapMore,
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(4).w,
|
|
child: Image.asset(
|
|
Assets.sideBMore,
|
|
width: 24.w,
|
|
height: 24.w,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
void onTapDownload() {
|
|
if (OfflineBox().checkDownloaded(musicModel.videoId)) {
|
|
Get.dialog(
|
|
RemindDialog(
|
|
content: 'Confirm to remove this song?',
|
|
confirmOnTap: () async {
|
|
await OfflineBox().delete(musicModel.videoId!);
|
|
DownloadManager.to.updateDownloadState();
|
|
BaseEasyLoading.toast('Removed');
|
|
if (Get.isRegistered<PersonalMusicLibraryController>()) {
|
|
PersonalMusicLibraryController.to.refreshOffline();
|
|
}
|
|
if (Get.isRegistered<OfflineController>()) {
|
|
OfflineController.to.getOfflineList();
|
|
}
|
|
},
|
|
),
|
|
);
|
|
} else {
|
|
if (DownloadManager.to.getMusicModel(musicModel.videoId)?.taskStatus == TaskStatus.enqueued
|
|
|| DownloadManager.to.getMusicModel(musicModel.videoId)?.taskStatus == TaskStatus.running) {
|
|
DownloadManager.to.cancelDownload(musicModel.videoId);
|
|
} else {
|
|
DownloadManager.to.downloadMusic(musicModel);
|
|
}
|
|
}
|
|
}
|
|
|
|
void onTapMore() {
|
|
Get.bottomSheet(
|
|
MoreBottomSheetView(
|
|
musicModel: musicModel,
|
|
),
|
|
);
|
|
}
|
|
}
|