Initial commit
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
//
|
||||
// UMComTopicDataController.h
|
||||
// UMCommunity
|
||||
//
|
||||
// Created by umeng on 16/7/1.
|
||||
// Copyright © 2016年 Umeng. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <UMCommunitySDK/UMComDataRequestManager.h>
|
||||
|
||||
@class UMComTopic;
|
||||
@interface UMComTopicDataController : NSObject
|
||||
|
||||
@property (nonatomic, strong) UMComTopic *topic;
|
||||
|
||||
+ (UMComTopicDataController *)dataControllerWithTopic:(UMComTopic *)topic;
|
||||
|
||||
+ (void )getTopicWithTopicId:(NSString *)topicID completion:(UMComDataRequestCompletion)completion;
|
||||
|
||||
- (void)followOrDisfollowCompletion:(UMComDataRequestCompletion)completion;
|
||||
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,65 @@
|
||||
//
|
||||
// UMComTopicDataController.m
|
||||
// UMCommunity
|
||||
//
|
||||
// Created by umeng on 16/7/1.
|
||||
// Copyright © 2016年 Umeng. All rights reserved.
|
||||
//
|
||||
|
||||
#import "UMComTopicDataController.h"
|
||||
#import <UMComDataStorage/UMComTopic.h>
|
||||
#import <UMComNetwork/UMComHttpCode.h>
|
||||
#import "UMComDataOperationErrorHandler.h"
|
||||
#import <UMCommunitySDK/UMComDataTypeDefine.h>
|
||||
|
||||
@implementation UMComTopicDataController
|
||||
|
||||
+ (UMComTopicDataController *)dataControllerWithTopic:(UMComTopic *)topic
|
||||
{
|
||||
UMComTopicDataController *dataController = [[UMComTopicDataController alloc] init];
|
||||
dataController.topic = topic;
|
||||
return dataController;
|
||||
}
|
||||
|
||||
+ (void )getTopicWithTopicId:(NSString *)topicID completion:(UMComDataRequestCompletion)completion
|
||||
{
|
||||
UMComTopic* umComTopic = [UMComTopic objectWithObjectId:topicID];
|
||||
if (umComTopic && completion) {
|
||||
|
||||
completion(umComTopic,nil);
|
||||
}
|
||||
else{
|
||||
[[UMComDataRequestManager defaultManager] fetchTopicWithTopicId:topicID completion:^(NSDictionary *responseObject, NSError *error) {
|
||||
UMComTopic *topic = nil;
|
||||
if ([responseObject isKindOfClass:[NSDictionary class]] && [responseObject valueForKey:UMComModelDataKey]) {
|
||||
topic = [responseObject valueForKey:UMComModelDataKey];
|
||||
}
|
||||
if (completion) {
|
||||
completion(topic, error);
|
||||
}
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)followOrDisfollowCompletion:(UMComDataRequestCompletion)completion
|
||||
{
|
||||
__weak typeof(self) weakSelf = self;
|
||||
BOOL isFollow = ![self.topic.is_focused boolValue];
|
||||
[[UMComDataRequestManager defaultManager] topicFollowerWithTopicID:self.topic.topicID isFollow:isFollow completion:^(NSDictionary *responseObject, NSError *error) {
|
||||
if (!error) {
|
||||
if (isFollow) {
|
||||
weakSelf.topic.is_focused = @1;
|
||||
}else{
|
||||
weakSelf.topic.is_focused = @0;
|
||||
}
|
||||
}else{
|
||||
__strong typeof(weakSelf) strongSelf = weakSelf;
|
||||
[UMComDataOperationErrorHandler handleTopicErrorWithTopic:strongSelf.topic error:error];
|
||||
}
|
||||
if (completion) {
|
||||
completion(weakSelf.topic, error);
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
@end
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
//
|
||||
// UMComTopicGroupDataController.h
|
||||
// UMCommunity
|
||||
//
|
||||
// Created by umeng on 16/5/5.
|
||||
// Copyright © 2016年 Umeng. All rights reserved.
|
||||
//
|
||||
|
||||
#import "UMComListDataController.h"
|
||||
|
||||
@interface UMComTopicGroupDataController : UMComListDataController
|
||||
|
||||
@end
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
//
|
||||
// UMComTopicGroupDataController.m
|
||||
// UMCommunity
|
||||
//
|
||||
// Created by umeng on 16/5/5.
|
||||
// Copyright © 2016年 Umeng. All rights reserved.
|
||||
//
|
||||
|
||||
#import "UMComTopicGroupDataController.h"
|
||||
#import <UMComDataStorage/UMComTopicType.h>
|
||||
#import <UMCommunitySDK/UMComDataTypeDefine.h>
|
||||
|
||||
@implementation UMComTopicGroupDataController
|
||||
|
||||
- (instancetype)initWithCount:(NSInteger)count
|
||||
{
|
||||
self = [super initWithRequestType:UMComRequestType_TopicGroups count:count];
|
||||
if (self) {
|
||||
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)refreshNewDataCompletion:(UMComDataListRequestCompletion)completion
|
||||
{
|
||||
__weak typeof(self) weakself = self;
|
||||
[[UMComDataRequestManager defaultManager] fetchTopicGroupdsWithCount:self.count completion:^(NSDictionary *responseObject, NSError *error) {
|
||||
//[weakself handleResponse:responseObject withError:error withRequestCompletion:completion];
|
||||
[weakself handleNewData:responseObject error:error completion:completion];
|
||||
}];
|
||||
|
||||
}
|
||||
|
||||
@end
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
//
|
||||
// UMComTopicListDataController.h
|
||||
// UMCommunity
|
||||
//
|
||||
// Created by umeng on 16/5/5.
|
||||
// Copyright © 2016年 Umeng. All rights reserved.
|
||||
//
|
||||
|
||||
#import "UMComListDataController.h"
|
||||
|
||||
@class UMComTopic;
|
||||
|
||||
|
||||
@interface UMComTopicListDataController : UMComListDataController
|
||||
|
||||
- (void)followOrDisfollowTopic:(UMComTopic *)topic completion:(UMComDataRequestCompletion)completion;
|
||||
|
||||
|
||||
@end
|
||||
|
||||
/**
|
||||
*全部话题列表
|
||||
*/
|
||||
@interface UMComTopicsAllDataController : UMComTopicListDataController
|
||||
|
||||
@end
|
||||
|
||||
/**
|
||||
*推荐话题列表
|
||||
*/
|
||||
@interface UMComTopicsRecommendDataController : UMComTopicListDataController
|
||||
|
||||
@end
|
||||
|
||||
/**
|
||||
*我关注的话题列表
|
||||
*/
|
||||
@interface UMComTopicsFocusDataController : UMComTopicListDataController
|
||||
|
||||
- (instancetype)initWithCount:(NSInteger)count withUID:(NSString*)uid;
|
||||
|
||||
@property(nonatomic, copy)NSString* uid;
|
||||
|
||||
@end
|
||||
|
||||
/**
|
||||
*搜索话题
|
||||
*/
|
||||
@interface UMComTopicsSearchDataController : UMComTopicListDataController
|
||||
|
||||
- (instancetype)initWithCount:(NSInteger)count withKeyWord:(NSString*)keyWord;
|
||||
|
||||
@property(nonatomic, copy)NSString* keyWord;
|
||||
@end
|
||||
|
||||
/**
|
||||
*话题组下的话题列表
|
||||
*/
|
||||
@interface UMComGroupTopicDataController : UMComTopicListDataController
|
||||
|
||||
- (instancetype)initWithCount:(NSInteger)count withGroupID:(NSString*)groupID;
|
||||
|
||||
@property(nonatomic, copy)NSString* groupID;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
|
||||
+250
@@ -0,0 +1,250 @@
|
||||
//
|
||||
// UMComTopicListDataController.m
|
||||
// UMCommunity
|
||||
//
|
||||
// Created by umeng on 16/5/5.
|
||||
// Copyright © 2016年 Umeng. All rights reserved.
|
||||
//
|
||||
|
||||
#import "UMComTopicListDataController.h"
|
||||
#import "UMComResouceDefines.h"
|
||||
#import <UMComDataStorage/UMComTopic.h>
|
||||
#import <UMCommunitySDK/UMComDataTypeDefine.h>
|
||||
#import <UMComNetwork/UMComHttpCode.h>
|
||||
#import "UMComTopicDataController.h"
|
||||
|
||||
|
||||
|
||||
@interface UMComTopicListDataController ()
|
||||
|
||||
@property (nonatomic, strong) UMComTopicDataController *topicDataController;
|
||||
|
||||
-(void)handleResponse:(NSDictionary*)responseObject withError:(NSError*)error withRequestCompletion:(UMComDataListRequestCompletion)completion;
|
||||
@end
|
||||
|
||||
@implementation UMComTopicListDataController
|
||||
|
||||
|
||||
|
||||
- (void)followOrDisfollowTopic:(UMComTopic *)topic completion:(UMComDataRequestCompletion)completion
|
||||
{
|
||||
self.topicDataController = [UMComTopicDataController dataControllerWithTopic:topic];
|
||||
[self.topicDataController followOrDisfollowCompletion:^(id responseObject, NSError *error) {
|
||||
if (completion) {
|
||||
completion(topic, error);
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
|
||||
-(void)handleResponse:(NSDictionary*)responseObject withError:(NSError*)error withRequestCompletion:(UMComDataListRequestCompletion)completion
|
||||
{
|
||||
if (error)
|
||||
{
|
||||
completion(nil,error);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (responseObject && [responseObject isKindOfClass:[NSDictionary class]]) {
|
||||
self.nextPageUrl = [responseObject valueForKey:UMComModelDataNextPageUrlKey];
|
||||
NSNumber* visit = [responseObject valueForKey:UMComModelDataVisitKey];
|
||||
if(visit.integerValue == 0){
|
||||
self.canVisitNextPage = NO;
|
||||
}
|
||||
else if(visit.integerValue == 1){
|
||||
self.canVisitNextPage = YES;
|
||||
}
|
||||
else{
|
||||
self.canVisitNextPage = YES;
|
||||
}
|
||||
|
||||
NSArray* topicArray = [responseObject valueForKey:UMComModelDataKey];
|
||||
if (topicArray && [topicArray isKindOfClass:[NSArray class]]) {
|
||||
self.dataArray = [NSMutableArray arrayWithArray:topicArray];
|
||||
if (completion) {
|
||||
completion(self.dataArray,nil);
|
||||
}
|
||||
|
||||
}
|
||||
else{
|
||||
if (completion) {
|
||||
completion(nil,error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
/**
|
||||
*全部话题列表
|
||||
*/
|
||||
@implementation UMComTopicsAllDataController
|
||||
|
||||
- (instancetype)initWithCount:(NSInteger)count
|
||||
{
|
||||
self = [super initWithRequestType:UMComRequestType_AllTopic count:count];
|
||||
if (self) {
|
||||
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)refreshNewDataCompletion:(UMComDataListRequestCompletion)completion
|
||||
{
|
||||
__weak typeof(self) weakself = self;
|
||||
[[UMComDataRequestManager defaultManager] fetchTopicsAllWithCount:self.count completion:^(NSDictionary *responseObject, NSError *error) {
|
||||
[weakself handleNewData:responseObject error:error completion:completion];
|
||||
}];
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
|
||||
/**
|
||||
*推荐话题列表
|
||||
*/
|
||||
@implementation UMComTopicsRecommendDataController
|
||||
|
||||
- (instancetype)initWithCount:(NSInteger)count
|
||||
{
|
||||
self = [super initWithRequestType:UMComRequestType_RecommendTopic count:count];
|
||||
if (self) {
|
||||
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)refreshNewDataCompletion:(UMComDataListRequestCompletion)completion
|
||||
{
|
||||
|
||||
__weak typeof(self) weakself = self;
|
||||
[[UMComDataRequestManager defaultManager] fetchTopicsRecommendWithCount:self.count completion:^(NSDictionary *responseObject, NSError *error) {
|
||||
[weakself handleNewData:responseObject error:error completion:completion];
|
||||
}];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
/**
|
||||
*我关注的话题列表
|
||||
*/
|
||||
@implementation UMComTopicsFocusDataController
|
||||
|
||||
- (instancetype)initWithCount:(NSInteger)count
|
||||
{
|
||||
self = [super initWithRequestType:UMComRequestType_FocusedTopic count:count];
|
||||
if (self) {
|
||||
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (instancetype)initWithCount:(NSInteger)count withUID:(NSString*)uid
|
||||
{
|
||||
self = [self initWithCount:count];
|
||||
if (self) {
|
||||
self.uid = uid;
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
- (void)refreshNewDataCompletion:(UMComDataListRequestCompletion)completion
|
||||
{
|
||||
__weak typeof(self) weakself = self;
|
||||
[[UMComDataRequestManager defaultManager] fetchTopicsUserFocusWithUid:self.uid count:self.count completion:^(NSDictionary *responseObject, NSError *error) {
|
||||
[weakself handleNewData:responseObject error:error completion:completion];
|
||||
}];
|
||||
}
|
||||
|
||||
-(void)fetchLocalDataWithCompletion:(UMComDataListRequestCompletion)localfetchcompletion
|
||||
{
|
||||
__weak typeof(self) weakSelf = self;
|
||||
[[UMComDataBaseManager shareManager] fetchASyncRelatedTopicIDWithUID:self.uid withCompleteBlock:^(NSArray* dataArray, NSError * error) {
|
||||
[weakSelf handleLocalData:dataArray error:error completion:localfetchcompletion];
|
||||
}];
|
||||
}
|
||||
|
||||
-(void)saveLocalDataWithDataArray:(NSArray*)dataArray
|
||||
{
|
||||
[[UMComDataBaseManager shareManager] saveRelatedTopicIDWithUID:self.uid withTopics:dataArray];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
/**
|
||||
*搜索话题
|
||||
*/
|
||||
@implementation UMComTopicsSearchDataController
|
||||
|
||||
- (instancetype)initWithCount:(NSInteger)count
|
||||
{
|
||||
self = [super initWithRequestType:UMComRequestType_FocusedTopic count:count];
|
||||
if (self) {
|
||||
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (instancetype)initWithCount:(NSInteger)count withKeyWord:(NSString *)keyWord
|
||||
{
|
||||
self = [super initWithCount:count];
|
||||
if (self) {
|
||||
self.keyWord = keyWord;
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
- (void)refreshNewDataCompletion:(UMComDataListRequestCompletion)completion
|
||||
{
|
||||
__weak typeof(self) weakself = self;
|
||||
[[UMComDataRequestManager defaultManager] fetchTopicsSearchWithKeywords:self.keyWord count:self.count completion:^(NSDictionary *responseObject, NSError *error) {
|
||||
[weakself handleNewData:responseObject error:error completion:completion];
|
||||
//[weakself handleResponse:responseObject withError:error withRequestCompletion:completion];
|
||||
}];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
/**
|
||||
*话题组下的话题列表
|
||||
*/
|
||||
@implementation UMComGroupTopicDataController
|
||||
|
||||
- (instancetype)initWithCount:(NSInteger)count
|
||||
{
|
||||
self = [super initWithRequestType:UMComRequestType_GroupsTopic count:count];
|
||||
if (self) {
|
||||
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (instancetype)initWithCount:(NSInteger)count withGroupID:(NSString*)groupID
|
||||
{
|
||||
self = [super initWithCount:count];
|
||||
if (self) {
|
||||
self.groupID = groupID;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)refreshNewDataCompletion:(UMComDataListRequestCompletion)completion
|
||||
{
|
||||
|
||||
__weak typeof(self) weakself = self;
|
||||
[[UMComDataRequestManager defaultManager] fetchTopicsWithTopicGroupID:self.groupID count:self.count completion:^(NSDictionary *responseObject, NSError *error) {
|
||||
[weakself handleNewData:responseObject error:error completion:completion];
|
||||
}];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user