Skip to content

Commit

Permalink
code: refactor hashCodes
Browse files Browse the repository at this point in the history
  • Loading branch information
MSOB7YY committed Nov 5, 2024
1 parent b541bfe commit 11597e3
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 19 deletions.
17 changes: 10 additions & 7 deletions lib/class/lyrics.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,17 @@ class LyricsModel {

@override
bool operator ==(covariant LyricsModel other) {
return lyrics == other.lyrics &&
synced == other.synced &&
isInCache == other.isInCache &&
fromInternet == other.fromInternet &&
isEmbedded == other.isEmbedded &&
file == other.file;
if (identical(this, other)) return true;
return other.lyrics == lyrics &&
other.synced == synced &&
other.isInCache == isInCache &&
other.fromInternet == fromInternet &&
other.isEmbedded == isEmbedded &&
other.file == file;
}

@override
int get hashCode => "$lyrics$synced$isInCache$fromInternet$isEmbedded$file".hashCode;
int get hashCode {
return lyrics.hashCode ^ synced.hashCode ^ isInCache.hashCode ^ fromInternet.hashCode ^ isEmbedded.hashCode ^ file.hashCode;
}
}
5 changes: 3 additions & 2 deletions lib/class/route.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,12 @@ abstract class NamidaRoute {

@override
bool operator ==(covariant NamidaRoute other) {
return route == other.route && name == other.name;
if (identical(this, other)) return true;
return other.route == route && other.name == name;
}

@override
int get hashCode => "$route$name".hashCode;
int get hashCode => route.hashCode ^ name.hashCode;
}

extension NamidaRouteWidgetUtils on NamidaRouteWidget {
Expand Down
5 changes: 3 additions & 2 deletions lib/class/track.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,12 @@ class TrackWithDate extends Selectable<Map<String, dynamic>> implements ItemWith

@override
bool operator ==(covariant TrackWithDate other) {
return dateAdded == other.dateAdded && source == other.source && track == other.track;
if (identical(this, other)) return true;
return other.dateAdded == dateAdded && other._track == _track && other.source == source;
}

@override
int get hashCode => "$track$source$dateAdded".hashCode;
int get hashCode => dateAdded.hashCode ^ _track.hashCode ^ source.hashCode;

@override
String toString() => "track: ${track.toString()}, source: $source, dateAdded: $dateAdded";
Expand Down
5 changes: 3 additions & 2 deletions lib/class/video.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,12 @@ class YTWatch {

@override
bool operator ==(covariant YTWatch other) {
return _date == other._date && isYTMusic == other.isYTMusic;
if (identical(this, other)) return true;
return other.dateNull == dateNull && other.isYTMusic == isYTMusic;
}

@override
int get hashCode => "${_date}_$isYTMusic".hashCode;
int get hashCode => dateNull.hashCode ^ isYTMusic.hashCode;
}

class NamidaVideo {
Expand Down
7 changes: 5 additions & 2 deletions lib/controller/json_to_history_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1204,9 +1204,12 @@ class _MissingListenEntry {

@override
bool operator ==(covariant _MissingListenEntry other) {
return youtubeID == other.youtubeID && source == other.source && title == other.title && artistOrChannel == other.artistOrChannel;
if (identical(this, other)) return true;
return other.dateMSSE == dateMSSE && other.source == source && other.youtubeID == youtubeID && other.title == title && other.artistOrChannel == artistOrChannel;
}

@override
int get hashCode => "$youtubeID$source$title$artistOrChannel".hashCode;
int get hashCode {
return dateMSSE.hashCode ^ source.hashCode ^ youtubeID.hashCode ^ title.hashCode ^ artistOrChannel.hashCode;
}
}
2 changes: 1 addition & 1 deletion lib/youtube/class/youtube_id.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class YoutubeID implements Playable<Map<String, dynamic>>, ItemWithDate {
}

@override
int get hashCode => "${id}_${_date.millisecondsSinceEpoch}".hashCode;
int get hashCode => id.hashCode ^ _date.hashCode;

@override
String toString() => "YoutubeID(id: $id, addedDate: $_date, playlistID: $playlistID)";
Expand Down
7 changes: 5 additions & 2 deletions lib/youtube/class/youtube_subscription.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,14 @@ class YoutubeSubscription {

@override
bool operator ==(covariant YoutubeSubscription other) {
return title == other.title && channelID == other.channelID && subscribed == other.subscribed && lastFetched == other.lastFetched;
if (identical(this, other)) return true;
return other.title == title && other.channelID == channelID && other.subscribed == subscribed && other.lastFetched == lastFetched;
}

@override
int get hashCode => "${title}_${channelID}_${subscribed}_$lastFetched".hashCode;
int get hashCode {
return title.hashCode ^ channelID.hashCode ^ subscribed.hashCode ^ lastFetched.hashCode;
}

@override
String toString() => "YoutubeSubscription(title: $title, channelID: $channelID, subscribed: $subscribed, lastFetched: $lastFetched)";
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: namida
description: A Beautiful and Feature-rich Music Player, With YouTube & Video Support Built in Flutter
publish_to: "none"
version: 4.6.51-beta+241105195
version: 4.6.52-beta+241105196

environment:
sdk: ">=3.4.0 <4.0.0"
Expand Down

0 comments on commit 11597e3

Please sign in to comment.