Skip to content

Commit

Permalink
replace removeWhere function, reduce state change
Browse files Browse the repository at this point in the history
  • Loading branch information
shaan-mephobic committed Nov 5, 2021
1 parent 06934cb commit 9f91ee2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
17 changes: 9 additions & 8 deletions lib/src/beginning/utilities/page_backend/albums_back.dart
Original file line number Diff line number Diff line change
Expand Up @@ -116,16 +116,17 @@ gettinSongArts() async {
allSongIds.sort();
cachedIds.sort();
bool hasNewInCustom(List small, List big) {
List extras = small;
big.removeWhere((item) => big.contains(item));
if (extras.isEmpty) return false;
return true;
for (int i = 0; i < small.length; i++) {
if (!big.contains(small[i])) return true;
}
return false;
}

List nowList = allSongIds;
if (listEquals(allSongIds, cachedIds) ||
(((musicBox.get("customScan") ?? false) ||
(musicBox.get("clutterFree") ?? false)) &&
!hasNewInCustom(allSongIds, cachedIds))) {
!hasNewInCustom(nowList, cachedIds))) {
List allArtworksName = [];
if ((musicBox.get("customScan") ?? false) ||
(musicBox.get("clutterFree") ?? false)) {
Expand All @@ -144,8 +145,7 @@ gettinSongArts() async {
"${applicationFileDirectory.path}/artworks/songarts/${allArtworksName[i]}.jpeg")
.readAsBytes();
}
}
else {
} else {
bool isDuplicate(Uint8List? artwork, int id) {
List artworkKeys = artworksData.values.toList();
for (int a = 0; a < artworkKeys.length; a++) {
Expand Down Expand Up @@ -197,12 +197,14 @@ gettinSongArts() async {
}
musicBox.put("artworksPointer", artworksPointer);
musicBox.put("artworksName", allImageNames);
refresh = true;
} else {
debugPrint("dirty-cache");
artworksPointer = musicBox.get("artworksPointer");
List newIds =
allSongIds.where((element) => !cachedIds.contains(element)).toList();
for (int i = 0; i < newIds.length; i++) {
refresh = true;
Uint8List? artwork = await OnAudioQuery()
.queryArtwork(newIds[i], ArtworkType.AUDIO, size: 350);
if (artwork == null) {
Expand Down Expand Up @@ -244,7 +246,6 @@ gettinSongArts() async {
.readAsBytes();
}
}
refresh = true;
}
allSongIds = musicBox.get("artworksName");
}
2 changes: 1 addition & 1 deletion lib/src/beginning/utilities/scraping/image_scrape.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ isolatedArtistScrapeInit() async {
File file = File(
"${applicationFileDirectory.path}/artists/${allArtists[i]}.jpg");
await file.writeAsBytes(response.bodyBytes);
rootState.provideman();
}
}
}
rootState.provideman();
if (neverDone.isNotEmpty) {
debugPrint("isolate##");
try {
Expand Down

0 comments on commit 9f91ee2

Please sign in to comment.