Skip to content

Commit

Permalink
fix: 本地曲库各项菜单过滤掉没有的歌曲
Browse files Browse the repository at this point in the history
  • Loading branch information
zhushenwudi committed Aug 8, 2023
1 parent a11690c commit 63f8cea
Show file tree
Hide file tree
Showing 15 changed files with 61 additions and 52 deletions.
3 changes: 3 additions & 0 deletions lib/dao/music_dao.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ abstract class MusicDao {
@Query("SELECT * FROM Music WHERE albumId = :albumId")
Future<List<Music>> findAllMusicsByAlbumId(String albumId);

@Query("SELECT * FROM Music WHERE albumId = :albumId AND `existFile` = 1")
Future<List<Music>> findAllExistMusicsByAlbumId(String albumId);

@Query('SELECT * FROM Music WHERE musicId = :musicId')
Future<Music?> findMusicByUId(String musicId);

Expand Down
39 changes: 23 additions & 16 deletions lib/global/global_db.dart
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ class DBLogic extends SuperController with GetSingleTickerProviderStateMixin {

GlobalLogic.to.databaseInitOver.value = true;
} catch (e) {
Log4f.e(msg: e.toString());
Log4f.i(msg: e.toString());
}
try {
scrollToTop(HomeController.scrollController1);
Expand Down Expand Up @@ -293,7 +293,7 @@ class DBLogic extends SuperController with GetSingleTickerProviderStateMixin {
await musicDao.updateMusic(music);
}
} catch (e) {
Log4f.e(msg: e.toString());
Log4f.i(msg: e.toString());
}
}

Expand All @@ -318,6 +318,10 @@ class DBLogic extends SuperController with GetSingleTickerProviderStateMixin {
'SELECT * FROM Music WHERE musicId IN (${arr.join(",")}) ORDER BY INSTR($joinStr)');
final musicArr = <Music>[];
for (var row in tempList) {
final existFile = (row['existFile'] as int?) == 1;
if (!remoteHttp.isEnableHttp() && !existFile) {
continue;
}
final music = Music(
musicId: row['musicId'] as String?,
musicName: row['musicName'] as String?,
Expand All @@ -335,7 +339,7 @@ class DBLogic extends SuperController with GetSingleTickerProviderStateMixin {
timestamp: row['timestamp'] as int,
isLove: (row['isLove'] as int) == 1,
neteaseId: row['neteaseId'] as String?,
existFile: (row['existFile'] as int?) == 1);
existFile: existFile);
musicArr.add(music);
}
return musicArr;
Expand All @@ -355,7 +359,7 @@ class DBLogic extends SuperController with GetSingleTickerProviderStateMixin {
await musicDao.deleteAllMusics();
await artistDao.deleteAllArtists();
} catch (e) {
Log4f.e(msg: e.toString());
Log4f.i(msg: e.toString());
}
}

Expand Down Expand Up @@ -389,13 +393,16 @@ class DBLogic extends SuperController with GetSingleTickerProviderStateMixin {
await splashDao.deleteAllSplashUrls();
await playListMusicDao.deleteAllPlayListMusics();
} catch (e) {
Log4f.e(msg: e.toString());
Log4f.i(msg: e.toString());
}
}

/// 通过albumId获取专辑下的全部歌曲
Future<List<Music>> findAllMusicsByAlbumId(String albumId) async {
return await musicDao.findAllMusicsByAlbumId(albumId);
if (remoteHttp.isEnableHttp()) {
return await musicDao.findAllMusicsByAlbumId(albumId);
}
return await musicDao.findAllExistMusicsByAlbumId(albumId);
}

/// 通过musicUId获取歌曲
Expand Down Expand Up @@ -465,7 +472,7 @@ class DBLogic extends SuperController with GetSingleTickerProviderStateMixin {
await findAllMenuList();
return true;
} catch (e) {
Log4f.e(msg: e.toString());
Log4f.i(msg: e.toString());
}
return false;
}
Expand Down Expand Up @@ -498,7 +505,7 @@ class DBLogic extends SuperController with GetSingleTickerProviderStateMixin {
await findAllMenuList();
return true;
} catch (e) {
Log4f.e(msg: e.toString());
Log4f.i(msg: e.toString());
}
return false;
}
Expand All @@ -513,7 +520,7 @@ class DBLogic extends SuperController with GetSingleTickerProviderStateMixin {
await findAllMenuList();
}
} catch (e) {
Log4f.e(msg: e.toString());
Log4f.i(msg: e.toString());
}
}

Expand Down Expand Up @@ -549,7 +556,7 @@ class DBLogic extends SuperController with GetSingleTickerProviderStateMixin {
return 1;
}
} catch (e) {
Log4f.e(msg: e.toString());
Log4f.i(msg: e.toString());
}
return -1;
}
Expand All @@ -560,7 +567,7 @@ class DBLogic extends SuperController with GetSingleTickerProviderStateMixin {
await menuDao.deleteMenuById(menuId);
await findAllMenuList();
} catch (e) {
Log4f.e(msg: e.toString());
Log4f.i(msg: e.toString());
}
}

Expand All @@ -587,7 +594,7 @@ class DBLogic extends SuperController with GetSingleTickerProviderStateMixin {
mIndex: willPlayMusicIndex, needPlay: false);
}
} catch (e) {
Log4f.e(msg: e.toString());
Log4f.i(msg: e.toString());
}
}

Expand All @@ -599,7 +606,7 @@ class DBLogic extends SuperController with GetSingleTickerProviderStateMixin {
await playListMusicDao.insertAllPlayListMusics(playMusics);
}
} catch (e) {
Log4f.e(msg: e.toString());
Log4f.i(msg: e.toString());
}
}

Expand All @@ -613,14 +620,14 @@ class DBLogic extends SuperController with GetSingleTickerProviderStateMixin {
if (group == Const.groupAll || music.group == group) {
final isLove = (await loveDao.findLoveById(music.musicId!) != null);
music.isLove = isLove;
if (isLove) {
if ((remoteHttp.isEnableHttp() || (music.existFile == true)) && isLove) {
loveList.add(music);
}
}
});
GlobalLogic.to.loveList.value = loveList;
} catch (e) {
Log4f.e(msg: e.toString());
Log4f.i(msg: e.toString());
}
}

Expand All @@ -643,7 +650,7 @@ class DBLogic extends SuperController with GetSingleTickerProviderStateMixin {
.isLove = music.isLove;
return music;
} catch (e) {
Log4f.e(msg: e.toString());
Log4f.i(msg: e.toString());
}
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/global/global_global.dart
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ class GlobalLogic extends SuperController
controller.animateTo(0,
duration: const Duration(milliseconds: 200), curve: Curves.ease);
} catch (e) {
Log4f.e(msg: e.toString());
Log4f.i(msg: e.toString());
}
}

Expand Down
8 changes: 4 additions & 4 deletions lib/global/global_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ class PlayerLogic extends SuperController
mPlayer.playbackEventStream.listen((event) {},
onError: (Object e, StackTrace st) {
if (e is PlayerException) {
Log4f.e(msg: 'player error code: ${e.code}');
Log4f.e(msg: 'player error message: ${e.message}');
Log4f.i(msg: 'player error code: ${e.code}');
Log4f.i(msg: 'player error message: ${e.message}');
} else {
Log4f.e(msg: e.toString());
Log4f.i(msg: e.toString());
}
});

Expand Down Expand Up @@ -259,7 +259,7 @@ class PlayerLogic extends SuperController
getLrc(false);
SmartDialog.compatible.dismiss();
} catch (e) {
Log4f.e(msg: e.toString());
Log4f.i(msg: e.toString());
} finally {
GlobalLogic.to.isHandlePlay = false;
}
Expand Down
17 changes: 8 additions & 9 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,17 @@ InAppLocalhostServer? localhostServer;
late RemoteHttp remoteHttp;

void main() async {
void reportErrorAndLog(FlutterErrorDetails details) {
if (details
.exceptionAsString()
.contains("ScrollController not attached to any scroll views")) {
Future<void> reportErrorAndLog(FlutterErrorDetails details) async {
final errorStr = details.exceptionAsString();
if (errorStr.contains("ScrollController not attached to any scroll views")) {
return;
}
final errorMsg = {
"exception": details.exceptionAsString(),
"exception": errorStr,
"stackTrace": details.stack.toString(),
};
if (kDebugMode) {
Log4f.e(msg: "$errorMsg");
Log4f.i(msg: "$errorMsg");
}
}

Expand Down Expand Up @@ -192,7 +191,7 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
AppUtils.handleShare(uri);
}
} catch (err) {
Log4f.e(msg: err.toString());
Log4f.i(msg: err.toString());
}
}
}
Expand All @@ -204,7 +203,7 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
AppUtils.handleShare(uri);
}
}, onError: (Object err) {
Log4f.e(msg: err.toString());
Log4f.i(msg: err.toString());
});
}

Expand Down Expand Up @@ -381,7 +380,7 @@ addAllSplashPhoto(InitConfig config) {
/// GetX 日志重定向
void defaultLogWriterCallback(String value, {bool isError = false}) {
if (isError && !value.contains("already removed")) {
Log4f.e(msg: value);
Log4f.i(msg: value);
}
}

Expand Down
4 changes: 2 additions & 2 deletions lib/modules/drawer/drawer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ class _DrawerPageState extends State<DrawerPage> {
SmartDialog.compatible.showToast('data_error'.tr);
}
}, error: (err) {
Log4f.e(msg: err);
Log4f.i(msg: err);
SmartDialog.compatible.dismiss(status: SmartStatus.loading);
SmartDialog.compatible.showToast('fetch_songs_fail'.tr);
}, isShowDialog: false);
Expand All @@ -306,7 +306,7 @@ class _DrawerPageState extends State<DrawerPage> {
SmartDialog.compatible.showToast('data_error'.tr);
}
}, error: (err) {
Log4f.e(msg: err);
Log4f.i(msg: err);
SmartDialog.compatible.dismiss(status: SmartStatus.loading);
SmartDialog.compatible.showToast('fetch_songs_fail'.tr);
}, isShowDialog: false);
Expand Down
2 changes: 1 addition & 1 deletion lib/pages/data_sync/data_sync.dart
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ class _DataSyncState extends State<DataSync> {
}
}, onError: (e) {
SmartDialog.compatible.showToast('connect_fail'.tr);
Log4f.e(msg: e.toString());
Log4f.i(msg: e.toString());
}, cancelOnError: true);
isConnected = true;
setState(() {});
Expand Down
14 changes: 7 additions & 7 deletions lib/pages/details/menu_details/view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class MenuDetailsPage extends StatefulWidget {
}

class _MenuDetailsPageState extends State<MenuDetailsPage> {
final music = <Music>[];
final musicList = <Music>[];
Menu? menu;
late Widget bottom;

Expand All @@ -37,12 +37,12 @@ class _MenuDetailsPageState extends State<MenuDetailsPage> {
refreshData() {
Future.delayed(Duration.zero, () async {
menu = await DBLogic.to.menuDao.findMenuById(NestedController.to.menuId);
final musicList = menu?.music;
music.clear();
if (musicList != null && musicList.isNotEmpty) {
music.addAll(await DBLogic.to.findMusicByMusicIds(musicList));
final tempList = menu?.music;
musicList.clear();
if (tempList != null && tempList.isNotEmpty) {
musicList.addAll(await DBLogic.to.findMusicByMusicIds(tempList));
}
DetailController.to.state.items = music;
DetailController.to.state.items = musicList;
setState(() {});
});
}
Expand All @@ -58,7 +58,7 @@ class _MenuDetailsPageState extends State<MenuDetailsPage> {
return DetailsBody(
logic: logic,
buildCover: Hero(tag: "menu${menu?.id}", child: _buildCover()),
music: music,
music: musicList,
isMenu: true,
onRemove: (List<String> musicIds) async {
if (menu == null || menu!.id == 0) {
Expand Down
2 changes: 1 addition & 1 deletion lib/pages/music_trans/music_transform.dart
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ class _MusicTransformState extends State<MusicTransform> {
}
}, onError: (e) {
SmartDialog.compatible.showToast('connect_fail'.tr);
Log4f.e(msg: e.toString());
Log4f.i(msg: e.toString());
}, cancelOnError: true);
isConnected = true;
setState(() {});
Expand Down
4 changes: 2 additions & 2 deletions lib/utils/android_back_desktop.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ class AndroidBackDesktop {
try {
await platform.invokeMethod(eventBackDesktop);
} on PlatformException catch (e) {
Log4f.w(msg: "通信失败,设置回退到安卓手机桌面失败");
Log4f.e(msg: e.toString());
Log4f.i(msg: "通信失败,设置回退到安卓手机桌面失败");
Log4f.i(msg: e.toString());
}
return Future.value(false);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/utils/app_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,8 @@ class AppUtils {
ShareSDKPlatforms.qq);
SharesdkPlugin.share(ShareSDKPlatforms.qq, sdkMap, (SSDKResponseState state,
dynamic userdata, dynamic contentEntity, SSDKError error) {
Log4f.e(msg: "错误码: ${error.code}");
Log4f.e(msg: "错误原因: ${error.rawData}");
Log4f.i(msg: "错误码: ${error.code}");
Log4f.i(msg: "错误原因: ${error.rawData}");
SmartDialog.compatible.showToast(error.rawData);
});
}
Expand Down
8 changes: 4 additions & 4 deletions lib/utils/sd_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class SDUtils {
file.createSync(recursive: true);
}
} catch (e) {
Log4f.e(msg: e.toString());
Log4f.i(msg: e.toString());
}
}

Expand All @@ -97,7 +97,7 @@ class SDUtils {
file.createSync(recursive: true);
}
} catch (e) {
Log4f.e(msg: e.toString());
Log4f.i(msg: e.toString());
}
}

Expand All @@ -113,7 +113,7 @@ class SDUtils {
SpUtil.put(Const.spBackgroundPhoto, fileName);
GlobalLogic.to.setBgPhoto(filePath);
} catch (e) {
Log4f.e(msg: e.toString());
Log4f.i(msg: e.toString());
}
}

Expand All @@ -130,7 +130,7 @@ class SDUtils {
});
}
} catch (e) {
Log4f.e(msg: e.toString());
Log4f.i(msg: e.toString());
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/widgets/bottom_bar1.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class BottomBar extends StatelessWidget {
controller.animateTo(0,
duration: const Duration(milliseconds: 200), curve: Curves.ease);
} catch (e) {
Log4f.e(msg: e.toString());
Log4f.i(msg: e.toString());
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/widgets/bottom_bar2.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class BottomBar2 extends StatelessWidget {
controller.animateTo(0,
duration: const Duration(milliseconds: 200), curve: Curves.ease);
} catch (e) {
Log4f.e(msg: e.toString());
Log4f.i(msg: e.toString());
}
}

Expand Down
Loading

0 comments on commit 63f8cea

Please sign in to comment.