| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373 |
- //
- // MOLiveList.m
- //
- // Created by SuperCabbage on 2023/10/18
- // Copyright (c) 2023 __MyCompanyName__. All rights reserved.
- //
- #import "MOLiveList.h"
- #import "MOUserProfile.h"
- #import "MOConfigList.h"
- #import "MOLiveBadge.h"
- NSString *const kLiveListLiveTag = @"liveTag";
- NSString *const kLiveListLiveType = @"liveType";
- NSString *const kLiveListId = @"id";
- NSString *const kLiveListActiveTag = @"activeTag";
- NSString *const kLiveListRoomType = @"roomType";
- NSString *const kLiveListLogo = @"logo";
- NSString *const kLiveListName = @"name";
- NSString *const kLiveListVisitNum = @"visitNum";
- NSString *const kLiveListAnchorUser = @"anchorUser";
- NSString *const kLiveListAtmosphere = @"atmosphere";
- NSString *const kLiveListOpenTime = @"openTime";
- NSString *const kLiveListWeScore = @"weScore";
- NSString *const kLiveListOppScore = @"oppScore";
- NSString *const kLiveListPkStartTime = @"pkStartTime";
- NSString *const kLiveListSettleTime = @"settleTime";
- NSString *const kLiveListPkEndTime = @"pkEndTime";
- NSString *const kLiveListPkStatus = @"pkStatus";
- NSString *const kLiveListRoomId = @"roomId";
- NSString *const kLiveListPkRtcToken = @"pkRtcToken";
- NSString *const kLiveListWeTops = @"weTops";
- NSString *const kLiveListOppoTops = @"oppoTops";
- NSString *const kLiveListLiveBadge = @"liveBadge";
- NSString *const kLiveListFansClubId = @"fansClubId";
- NSString *const kLiveListMultiple = @"multiple";
- NSString *const kLiveListPk= @"pk";
- NSString *const kLiveListRedEnvelope = @"redEnvelope";
- NSString *const kLiveListBgBorder = @"bgBorder";
- @interface MOLiveList ()
- - (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;
- @end
- @implementation MOLiveList
- @synthesize liveTag = _liveTag;
- @synthesize liveType = _liveType;
- @synthesize id = _id;
- @synthesize activeTag = _activeTag;
- @synthesize roomType = _roomType;
- @synthesize logo = _logo;
- @synthesize name = _name;
- @synthesize visitNum = _visitNum;
- @synthesize anchorUser = _anchorUser;
- @synthesize atmosphere = _atmosphere;
- @synthesize openTime = _openTime;
- @synthesize weScore = _weScore;
- @synthesize oppScore = _oppScore;
- @synthesize pkStartTime = _pkStartTime;
- @synthesize settleTime = _settleTime;
- @synthesize pkEndTime = _pkEndTime;
- @synthesize pkStatus = _pkStatus;
- @synthesize roomId = _roomId;
- @synthesize pkRtcToken = _pkRtcToken;
- @synthesize weTops = _weTops;
- @synthesize oppoTops = _oppoTops;
- @synthesize liveBadge = _liveBadge;
- @synthesize fansClubId = _fansClubId;
- @synthesize multiple = _multiple;
- @synthesize pk = _pk;
- @synthesize redEnvelope = _redEnvelope;
- @synthesize bgBorder = _bgBorder;
- + (instancetype)modelObjectWithDictionary:(NSDictionary *)dict {
- return [[self alloc] initWithDictionary:dict];
- }
- - (instancetype)initWithDictionary:(NSDictionary *)dict {
- self = [super init];
-
- // This check serves to make sure that a non-NSDictionary object
- // passed into the model class doesn't break the parsing.
- if (self && [dict isKindOfClass:[NSDictionary class]]) {
-
- self.liveTag = [MOConfigList modelObjectWithDictionary:[dict objectForKey:kLiveListLiveTag]];
- self.liveType = [[self objectOrNilForKey:kLiveListLiveType fromDictionary:dict] doubleValue];
- self.id = [self objectOrNilForKey:kLiveListId fromDictionary:dict];
-
- self.activeTag = [MOConfigList modelObjectWithDictionary:[dict objectForKey:kLiveListActiveTag]];
- self.roomType = [[self objectOrNilForKey:kLiveListRoomType fromDictionary:dict] doubleValue];
- self.logo = [self objectOrNilForKey:kLiveListLogo fromDictionary:dict];
- self.name = [self objectOrNilForKey:kLiveListName fromDictionary:dict];
- self.anchorUser = [MOUserProfile modelObjectWithDictionary:[dict objectForKey:kLiveListAnchorUser]];
- self.visitNum = [[self objectOrNilForKey:kLiveListVisitNum fromDictionary:dict] doubleValue];
- self.atmosphere = [[self objectOrNilForKey:kLiveListAtmosphere fromDictionary:dict] doubleValue];
- self.openTime = [[self objectOrNilForKey:kLiveListOpenTime fromDictionary:dict] doubleValue];
-
- self.weScore = [[self objectOrNilForKey:kLiveListWeScore fromDictionary:dict] doubleValue];
- self.oppScore = [[self objectOrNilForKey:kLiveListOppScore fromDictionary:dict] doubleValue];
- self.pkStartTime = [[self objectOrNilForKey:kLiveListPkStartTime fromDictionary:dict] doubleValue];
- self.settleTime = [[self objectOrNilForKey:kLiveListSettleTime fromDictionary:dict] doubleValue];
- self.pkEndTime = [[self objectOrNilForKey:kLiveListPkEndTime fromDictionary:dict] doubleValue];
- self.pkStatus = [[self objectOrNilForKey:kLiveListPkStatus fromDictionary:dict] doubleValue];
- self.roomId = [self objectOrNilForKey:kLiveListRoomId fromDictionary:dict];
- self.pkRtcToken = [self objectOrNilForKey:kLiveListPkRtcToken fromDictionary:dict];
- self.liveBadge = [MOLiveBadge modelObjectWithDictionary:[dict objectForKey:kLiveListLiveBadge]];
-
- self.fansClubId = [self objectOrNilForKey:kLiveListFansClubId fromDictionary:dict];
-
- NSObject *receivedMOWeTops = [dict objectForKey:kLiveListWeTops];
- NSMutableArray *parsedMOWeTops = [NSMutableArray array];
-
- if ([receivedMOWeTops isKindOfClass:[NSArray class]]) {
- for (NSDictionary *item in (NSArray *)receivedMOWeTops) {
- if ([item isKindOfClass:[NSDictionary class]]) {
- [parsedMOWeTops addObject:[MOUserProfile modelObjectWithDictionary:item]];
- }
- }
- } else if ([receivedMOWeTops isKindOfClass:[NSDictionary class]]) {
- [parsedMOWeTops addObject:[MOUserProfile modelObjectWithDictionary:(NSDictionary *)receivedMOWeTops]];
- }
- self.weTops = [NSArray arrayWithArray:parsedMOWeTops];
-
- NSObject *receivedMOOppoTops = [dict objectForKey:kLiveListOppoTops];
- NSMutableArray *parsedMOOppoTops = [NSMutableArray array];
-
- if ([receivedMOOppoTops isKindOfClass:[NSArray class]]) {
- for (NSDictionary *item in (NSArray *)receivedMOOppoTops) {
- if ([item isKindOfClass:[NSDictionary class]]) {
- [parsedMOOppoTops addObject:[MOUserProfile modelObjectWithDictionary:item]];
- }
- }
- } else if ([receivedMOOppoTops isKindOfClass:[NSDictionary class]]) {
- [parsedMOOppoTops addObject:[MOUserProfile modelObjectWithDictionary:(NSDictionary *)receivedMOOppoTops]];
- }
- self.oppoTops = [NSArray arrayWithArray:parsedMOOppoTops];
-
- self.multiple = [[self objectOrNilForKey:kLiveListMultiple fromDictionary:dict] boolValue];
-
- self.pk = [[self objectOrNilForKey:kLiveListPk fromDictionary:dict] boolValue];
- self.redEnvelope = [[self objectOrNilForKey:kLiveListRedEnvelope fromDictionary:dict] boolValue];
-
- self.bgBorder = [self objectOrNilForKey:kLiveListBgBorder fromDictionary:dict];
- }
-
- return self;
-
- }
- - (NSDictionary *)dictionaryRepresentation {
- NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
- [mutableDict setValue:[self.liveTag dictionaryRepresentation] forKey:kLiveListLiveTag];
- [mutableDict setValue:[NSNumber numberWithDouble:self.liveType] forKey:kLiveListLiveType];
- [mutableDict setValue:self.id forKey:kLiveListId];
- [mutableDict setValue:[self.activeTag dictionaryRepresentation] forKey:kLiveListActiveTag];
- [mutableDict setValue:[NSNumber numberWithDouble:self.roomType] forKey:kLiveListRoomType];
- [mutableDict setValue:self.logo forKey:kLiveListLogo];
- [mutableDict setValue:self.name forKey:kLiveListName];
- [mutableDict setValue:[self.anchorUser dictionaryRepresentation] forKey:kLiveListAnchorUser];
- [mutableDict setValue:[NSNumber numberWithDouble:self.visitNum] forKey:kLiveListVisitNum];
- [mutableDict setValue:[NSNumber numberWithDouble:self.atmosphere] forKey:kLiveListAtmosphere];
- [mutableDict setValue:[NSNumber numberWithDouble:self.openTime] forKey:kLiveListOpenTime];
-
- [mutableDict setValue:[NSNumber numberWithDouble:self.weScore] forKey:kLiveListWeScore];
- [mutableDict setValue:[NSNumber numberWithDouble:self.oppScore] forKey:kLiveListOppScore];
- [mutableDict setValue:[NSNumber numberWithDouble:self.pkStartTime] forKey:kLiveListPkStartTime];
- [mutableDict setValue:[NSNumber numberWithDouble:self.settleTime] forKey:kLiveListSettleTime];
- [mutableDict setValue:[NSNumber numberWithDouble:self.pkEndTime] forKey:kLiveListPkEndTime];
- [mutableDict setValue:[NSNumber numberWithDouble:self.pkStatus] forKey:kLiveListPkStatus];
- [mutableDict setValue:self.roomId forKey:kLiveListRoomId];
- [mutableDict setValue:self.pkRtcToken forKey:kLiveListPkRtcToken];
-
- [mutableDict setValue:self.fansClubId forKey:kLiveListFansClubId];
-
- [mutableDict setValue:[self.liveBadge dictionaryRepresentation] forKey:kLiveListLiveBadge];
-
- NSMutableArray *tempArrayForWeTops = [NSMutableArray array];
-
- for (NSObject *subArrayObject in self.weTops) {
- if ([subArrayObject respondsToSelector:@selector(dictionaryRepresentation)]) {
- // This class is a model object
- [tempArrayForWeTops addObject:[subArrayObject performSelector:@selector(dictionaryRepresentation)]];
- } else {
- // Generic object
- [tempArrayForWeTops addObject:subArrayObject];
- }
- }
- [mutableDict setValue:[NSArray arrayWithArray:tempArrayForWeTops] forKey:kLiveListWeTops];
-
- NSMutableArray *tempArrayForOppoTops= [NSMutableArray array];
-
- for (NSObject *subArrayObject in self.oppoTops) {
- if ([subArrayObject respondsToSelector:@selector(dictionaryRepresentation)]) {
- // This class is a model object
- [tempArrayForOppoTops addObject:[subArrayObject performSelector:@selector(dictionaryRepresentation)]];
- } else {
- // Generic object
- [tempArrayForOppoTops addObject:subArrayObject];
- }
- }
- [mutableDict setValue:[NSArray arrayWithArray:tempArrayForOppoTops] forKey:kLiveListOppoTops];
-
- [mutableDict setValue:[NSNumber numberWithBool:self.multiple] forKey:kLiveListMultiple];
-
- [mutableDict setValue:[NSNumber numberWithBool:self.pk] forKey:kLiveListPk];
- [mutableDict setValue:[NSNumber numberWithBool:self.redEnvelope] forKey:kLiveListRedEnvelope];
-
- [mutableDict setValue:self.bgBorder forKey:kLiveListBgBorder];
-
- return [NSDictionary dictionaryWithDictionary:mutableDict];
- }
- - (NSString *)description {
- return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
- }
- #pragma mark - Helper Method
- - (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict {
- id object = [dict objectForKey:aKey];
- return [object isEqual:[NSNull null]] ? nil : object;
- }
- #pragma mark - NSCoding Methods
- - (id)initWithCoder:(NSCoder *)aDecoder {
- self = [super init];
- self.liveTag = [aDecoder decodeObjectForKey:kLiveListLiveTag];
- self.liveType = [aDecoder decodeDoubleForKey:kLiveListLiveType];
- self.id = [aDecoder decodeObjectForKey:kLiveListId];
- self.activeTag = [aDecoder decodeObjectForKey:kLiveListActiveTag];
- self.roomType = [aDecoder decodeDoubleForKey:kLiveListRoomType];
- self.logo = [aDecoder decodeObjectForKey:kLiveListLogo];
- self.name = [aDecoder decodeObjectForKey:kLiveListName];
- self.anchorUser = [aDecoder decodeObjectForKey:kLiveListAnchorUser];
- self.visitNum = [aDecoder decodeDoubleForKey:kLiveListVisitNum];
- self.atmosphere = [aDecoder decodeDoubleForKey:kLiveListAtmosphere];
- self.openTime = [aDecoder decodeDoubleForKey:kLiveListOpenTime];
-
- self.weScore = [aDecoder decodeDoubleForKey:kLiveListWeScore];
- self.oppScore = [aDecoder decodeDoubleForKey:kLiveListOppScore];
- self.pkStartTime = [aDecoder decodeDoubleForKey:kLiveListPkStartTime];
- self.settleTime = [aDecoder decodeDoubleForKey:kLiveListSettleTime];
- self.pkEndTime = [aDecoder decodeDoubleForKey:kLiveListPkEndTime];
- self.pkStatus = [aDecoder decodeDoubleForKey:kLiveListPkStatus];
- self.roomId = [aDecoder decodeObjectForKey:kLiveListRoomId];
- self.pkRtcToken = [aDecoder decodeObjectForKey:kLiveListPkRtcToken];
-
- self.fansClubId = [aDecoder decodeObjectForKey:kLiveListFansClubId];
-
- self.weTops = [aDecoder decodeObjectForKey:kLiveListWeTops];
- self.oppoTops = [aDecoder decodeObjectForKey:kLiveListOppoTops];
-
- self.liveBadge = [aDecoder decodeObjectForKey:kLiveListLiveBadge];
-
- self.multiple = [aDecoder decodeBoolForKey:kLiveListMultiple];
-
- self.pk = [aDecoder decodeBoolForKey:kLiveListPk];
- self.redEnvelope = [aDecoder decodeBoolForKey:kLiveListRedEnvelope];
-
- self.bgBorder = [aDecoder decodeObjectForKey:kLiveListBgBorder];
-
- return self;
- }
- - (void)encodeWithCoder:(NSCoder *)aCoder
- {
- [aCoder encodeObject:_liveTag forKey:kLiveListLiveTag];
- [aCoder encodeDouble:_liveType forKey:kLiveListLiveType];
- [aCoder encodeObject:_id forKey:kLiveListId];
- [aCoder encodeObject:_activeTag forKey:kLiveListActiveTag];
- [aCoder encodeDouble:_roomType forKey:kLiveListRoomType];
- [aCoder encodeObject:_logo forKey:kLiveListLogo];
- [aCoder encodeObject:_name forKey:kLiveListName];
- [aCoder encodeObject:_anchorUser forKey:kLiveListAnchorUser];
- [aCoder encodeDouble:_visitNum forKey:kLiveListVisitNum];
- [aCoder encodeDouble:_atmosphere forKey:kLiveListAtmosphere];
- [aCoder encodeDouble:_openTime forKey:kLiveListOpenTime];
-
- [aCoder encodeDouble:_weScore forKey:kLiveListWeScore];
- [aCoder encodeDouble:_oppScore forKey:kLiveListOppScore];
- [aCoder encodeDouble:_pkStartTime forKey:kLiveListPkStartTime];
- [aCoder encodeDouble:_settleTime forKey:kLiveListSettleTime];
- [aCoder encodeDouble:_pkEndTime forKey:kLiveListPkEndTime];
- [aCoder encodeDouble:_pkStatus forKey:kLiveListPkStatus];
- [aCoder encodeObject:_roomId forKey:kLiveListRoomId];
- [aCoder encodeObject:_pkRtcToken forKey:kLiveListPkRtcToken];
-
- [aCoder encodeObject:_fansClubId forKey:kLiveListFansClubId];
-
- [aCoder encodeObject:_weTops forKey:kLiveListWeTops];
- [aCoder encodeObject:_oppoTops forKey:kLiveListOppoTops];
-
- [aCoder encodeObject:_liveBadge forKey:kLiveListLiveBadge];
-
- [aCoder encodeBool:_multiple forKey:kLiveListMultiple];
-
- [aCoder encodeBool:_pk forKey:kLiveListPk];
- [aCoder encodeBool:_redEnvelope forKey:kLiveListRedEnvelope];
-
- [aCoder encodeObject:_bgBorder forKey:kLiveListBgBorder];
- }
- - (id)copyWithZone:(NSZone *)zone {
- MOLiveList *copy = [[MOLiveList alloc] init];
-
-
-
- if (copy) {
- copy.liveTag = [self.liveTag copyWithZone:zone];
- copy.liveType = self.liveType;
- copy.id = [self.id copyWithZone:zone];
- copy.activeTag = [self.activeTag copyWithZone:zone];
- copy.roomType = self.roomType;
- copy.logo = [self.logo copyWithZone:zone];
- copy.name = [self.name copyWithZone:zone];
- copy.anchorUser = [self.anchorUser copyWithZone:zone];
- copy.visitNum = self.visitNum;
- copy.atmosphere = self.atmosphere;
- copy.openTime = self.openTime;
-
- copy.weScore = self.weScore;
- copy.oppScore = self.oppScore;
- copy.pkStartTime = self.pkStartTime;
- copy.settleTime = self.settleTime;
- copy.pkEndTime = self.pkEndTime;
- copy.pkStatus = self.pkStatus;
- copy.roomId = [self.roomId copyWithZone:zone];
- copy.pkRtcToken = [self.pkRtcToken copyWithZone:zone];
-
- copy.fansClubId = [self.fansClubId copyWithZone:zone];
-
- copy.weTops = [self.weTops copyWithZone:zone];
- copy.oppoTops = [self.oppoTops copyWithZone:zone];
-
- copy.liveBadge = [self.liveBadge copyWithZone:zone];
- copy.isViewSelect = self.isViewSelect;
- copy.multiple = self.multiple;
-
- copy.pk = self.pk;
- copy.redEnvelope = self.redEnvelope;
-
- copy.bgBorder = [self.bgBorder copyWithZone:zone];
- }
-
- return copy;
- }
- @end
|