|
|
@ -59,888 +59,77 @@ public class SocialModel implements SocialContract.SocialModel { |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void getPrivateFeeds(final SocialContract.SocialListener socialListener, final String userId, final boolean personal, final String after) { |
|
|
|
if (!Utils.isNetworkConnected(context)) { |
|
|
|
if (personal) { |
|
|
|
socialListener.onNoInternetConnection(PRIVATEFEED); |
|
|
|
} else { |
|
|
|
socialListener.onNoInternetConnection(PUBLICFEED); |
|
|
|
} |
|
|
|
} else { |
|
|
|
Call<Feeds> call = new RestApi(context).apiEndpoints.getPrivateFeeds(userId, personal, after, "10"); |
|
|
|
call.enqueue(new Callback<Feeds>() { |
|
|
|
@Override |
|
|
|
public void onResponse(Call<Feeds> call, Response<Feeds> response) { |
|
|
|
if (response.isSuccessful()) { |
|
|
|
Headers headers = response.headers(); |
|
|
|
// get header value |
|
|
|
String cookie = response.headers().get("Set-Cookie"); |
|
|
|
String date = response.headers().get("date"); |
|
|
|
Log.i("cookie", cookie + " ---"); |
|
|
|
Log.i("date", date + " ---"); |
|
|
|
Log.i("social private", new Gson().toJson(response.body())); |
|
|
|
if (personal) { |
|
|
|
socialListener.onSuccessPrivateFeed(response.body()); |
|
|
|
} else { |
|
|
|
socialListener.onSuccessPublicFeed(response.body()); |
|
|
|
} |
|
|
|
} else if (response.code() == 401) { |
|
|
|
RefreshModal modal = new RefreshModal(context); |
|
|
|
|
|
|
|
modal.performTokenRefresh(new OnRefreshCallback() { |
|
|
|
@Override |
|
|
|
public void onRefreshSuccess() { |
|
|
|
new RestApi(context); |
|
|
|
getPrivateFeeds(socialListener, userId, personal, after); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onRefreshUnknown(APIRequestErrorReturn errorReturn) { |
|
|
|
if (personal) { |
|
|
|
socialListener.onFailurePrivateFeed(errorReturn.message); |
|
|
|
} else { |
|
|
|
socialListener.onFailurePublicFeed(errorReturn.message); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onRefreshFailure(Throwable t) { |
|
|
|
if (personal) { |
|
|
|
socialListener.onFailurePrivateFeed(t.getMessage()); |
|
|
|
} else { |
|
|
|
socialListener.onFailurePublicFeed(t.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
} else if (response.code() == 403) { |
|
|
|
RefreshModal modal = new RefreshModal(context); |
|
|
|
modal.performLogout(); |
|
|
|
} else { |
|
|
|
Gson gson = new GsonBuilder().create(); |
|
|
|
APIRequestErrorReturn statusErrorReturn = new APIRequestErrorReturn(); |
|
|
|
try { |
|
|
|
statusErrorReturn = gson.fromJson(response.errorBody().string(), APIRequestErrorReturn.class); |
|
|
|
// socialListener.onFailurePrivateFeed(statusErrorReturn.message); |
|
|
|
if (personal) { |
|
|
|
socialListener.onFailurePrivateFeed(statusErrorReturn.message); |
|
|
|
} else { |
|
|
|
socialListener.onFailurePublicFeed(statusErrorReturn.message); |
|
|
|
} |
|
|
|
} catch (IOException e) { |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onFailure(Call<Feeds> call, Throwable t) { |
|
|
|
Log.e("NOW ", "FROM HERE 1"); |
|
|
|
if (personal) { |
|
|
|
socialListener.onFailurePrivateFeed((t instanceof IOException) ? "Connection Lost" : t.getMessage()); |
|
|
|
} else { |
|
|
|
socialListener.onFailurePublicFeed((t instanceof IOException) ? "Connection Lost" : t.getMessage()); |
|
|
|
} |
|
|
|
t.printStackTrace(); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
public void getPrivateFeeds(SocialContract.SocialListener socialListener, String userId, boolean personal, String after) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void uploadImage(final SocialContract.SocialListener socialListener, final String userId, final Uri fileUri) { |
|
|
|
File file = FileUtils.getFile(context, fileUri); |
|
|
|
|
|
|
|
|
|
|
|
ContentResolver cR = context.getContentResolver(); |
|
|
|
MimeTypeMap mime = MimeTypeMap.getSingleton(); |
|
|
|
String type = mime.getExtensionFromMimeType(cR.getType(fileUri)); |
|
|
|
|
|
|
|
// create RequestBody instance from file |
|
|
|
RequestBody requestFile = RequestBody.create(MediaType.parse("image/*"), file); |
|
|
|
|
|
|
|
// MultipartBody.Part is used to send also the actual file name |
|
|
|
MultipartBody.Part body = MultipartBody.Part.createFormData("file", file.getName(), requestFile); |
|
|
|
|
|
|
|
// add another part within the multipart request |
|
|
|
RequestBody userid = RequestBody.create(okhttp3.MultipartBody.FORM, userId); |
|
|
|
|
|
|
|
if (!Utils.isNetworkConnected(context)) { |
|
|
|
socialListener.onNoInternetConnection(NEWFEED); |
|
|
|
} else { |
|
|
|
Call<UploadImageResponse> call = new RestApi(context).apiEndpoints.uploadImage(userid, body); |
|
|
|
call.enqueue(new Callback<UploadImageResponse>() { |
|
|
|
@Override |
|
|
|
public void onResponse(Call<UploadImageResponse> call, Response<UploadImageResponse> response) { |
|
|
|
if (response.isSuccessful()) { |
|
|
|
Log.i("Image Upload", new Gson().toJson(response.body())); |
|
|
|
socialListener.onSuccessImageUpload(response.body()); |
|
|
|
} else if (response.code() == 401) { |
|
|
|
RefreshModal modal = new RefreshModal(context); |
|
|
|
|
|
|
|
modal.performTokenRefresh(new OnRefreshCallback() { |
|
|
|
@Override |
|
|
|
public void onRefreshSuccess() { |
|
|
|
new RestApi(context); |
|
|
|
uploadImage(socialListener, userId, fileUri); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onRefreshUnknown(APIRequestErrorReturn errorReturn) { |
|
|
|
socialListener.onFailureImageUpload(errorReturn.message); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onRefreshFailure(Throwable t) { |
|
|
|
socialListener.onFailureImageUpload(t.getMessage()); |
|
|
|
} |
|
|
|
}); |
|
|
|
} else if (response.code() == 403) { |
|
|
|
RefreshModal modal = new RefreshModal(context); |
|
|
|
modal.performLogout(); |
|
|
|
} else { |
|
|
|
Gson gson = new GsonBuilder().create(); |
|
|
|
APIRequestErrorReturn statusErrorReturn = new APIRequestErrorReturn(); |
|
|
|
try { |
|
|
|
statusErrorReturn = gson.fromJson(response.errorBody().string(), APIRequestErrorReturn.class); |
|
|
|
socialListener.onFailureImageUpload(statusErrorReturn.message); |
|
|
|
} catch (IOException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onFailure(Call<UploadImageResponse> call, Throwable t) { |
|
|
|
Log.e("NOW ", "FROM HERE 2"); |
|
|
|
socialListener.onFailureImageUpload((t instanceof IOException) ? "Connection Lost" : t.getMessage()); |
|
|
|
t.printStackTrace(); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
public void uploadImage(SocialContract.SocialListener socialListener, String userId, Uri fileUri) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void createNewFeed(final SocialContract.SocialListener socialListener, final NewFeedRequest newFeedRequest) { |
|
|
|
if (!Utils.isNetworkConnected(context)) { |
|
|
|
socialListener.onNoInternetConnection(NEWFEED); |
|
|
|
} else { |
|
|
|
Call<FeedData> call = new RestApi(context).apiEndpoints.createFeed(newFeedRequest); |
|
|
|
call.enqueue(new Callback<FeedData>() { |
|
|
|
@Override |
|
|
|
public void onResponse(Call<FeedData> call, Response<FeedData> response) { |
|
|
|
if (response.isSuccessful()) { |
|
|
|
Log.i("Image Upload", new Gson().toJson(response.body())); |
|
|
|
socialListener.onSuccessCreateFeed(response.body()); |
|
|
|
} else if (response.code() == 401) { |
|
|
|
RefreshModal modal = new RefreshModal(context); |
|
|
|
|
|
|
|
modal.performTokenRefresh(new OnRefreshCallback() { |
|
|
|
@Override |
|
|
|
public void onRefreshSuccess() { |
|
|
|
new RestApi(context); |
|
|
|
createNewFeed(socialListener, newFeedRequest); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onRefreshUnknown(APIRequestErrorReturn errorReturn) { |
|
|
|
socialListener.onFailureCreateFeed(errorReturn.message); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onRefreshFailure(Throwable t) { |
|
|
|
socialListener.onFailureCreateFeed(t.getMessage()); |
|
|
|
} |
|
|
|
}); |
|
|
|
} else if (response.code() == 403) { |
|
|
|
RefreshModal modal = new RefreshModal(context); |
|
|
|
modal.performLogout(); |
|
|
|
} else { |
|
|
|
Gson gson = new GsonBuilder().create(); |
|
|
|
APIRequestErrorReturn statusErrorReturn = new APIRequestErrorReturn(); |
|
|
|
try { |
|
|
|
statusErrorReturn = gson.fromJson(response.errorBody().string(), APIRequestErrorReturn.class); |
|
|
|
socialListener.onFailureCreateFeed(statusErrorReturn.message); |
|
|
|
} catch (IOException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onFailure(Call<FeedData> call, Throwable t) { |
|
|
|
Log.e("NOW ", "FROM HERE 3"); |
|
|
|
socialListener.onFailureCreateFeed((t instanceof IOException) ? "Connection Lost" : t.getMessage()); |
|
|
|
t.printStackTrace(); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
public void createNewFeed(SocialContract.SocialListener socialListener, NewFeedRequest newFeedRequest) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void updateFeed(final SocialContract.SocialListener socialListener, final NewFeedRequest newFeedRequest, final String feedId) { |
|
|
|
if (!Utils.isNetworkConnected(context)) { |
|
|
|
socialListener.onNoInternetConnection(NEWFEED); |
|
|
|
} else { |
|
|
|
Call<FeedData> call = new RestApi(context).apiEndpoints.updateFeed(newFeedRequest, feedId); |
|
|
|
call.enqueue(new Callback<FeedData>() { |
|
|
|
@Override |
|
|
|
public void onResponse(Call<FeedData> call, Response<FeedData> response) { |
|
|
|
if (response.isSuccessful()) { |
|
|
|
Log.i("Update Feed", new Gson().toJson(response.body())); |
|
|
|
socialListener.onSuccessCreateFeed(response.body()); |
|
|
|
} else if (response.code() == 401) { |
|
|
|
RefreshModal modal = new RefreshModal(context); |
|
|
|
|
|
|
|
modal.performTokenRefresh(new OnRefreshCallback() { |
|
|
|
@Override |
|
|
|
public void onRefreshSuccess() { |
|
|
|
new RestApi(context); |
|
|
|
updateFeed(socialListener, newFeedRequest, feedId); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onRefreshUnknown(APIRequestErrorReturn errorReturn) { |
|
|
|
socialListener.onFailureCreateFeed(errorReturn.message); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onRefreshFailure(Throwable t) { |
|
|
|
socialListener.onFailureCreateFeed(t.getMessage()); |
|
|
|
} |
|
|
|
}); |
|
|
|
} else if (response.code() == 403) { |
|
|
|
RefreshModal modal = new RefreshModal(context); |
|
|
|
modal.performLogout(); |
|
|
|
} else { |
|
|
|
Gson gson = new GsonBuilder().create(); |
|
|
|
APIRequestErrorReturn statusErrorReturn = new APIRequestErrorReturn(); |
|
|
|
try { |
|
|
|
statusErrorReturn = gson.fromJson(response.errorBody().string(), APIRequestErrorReturn.class); |
|
|
|
socialListener.onFailureCreateFeed(statusErrorReturn.message); |
|
|
|
} catch (IOException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onFailure(Call<FeedData> call, Throwable t) { |
|
|
|
Log.e("NOW ", "FROM HERE 4"); |
|
|
|
socialListener.onFailureCreateFeed((t instanceof IOException) ? "Connection Lost" : t.getMessage()); |
|
|
|
t.printStackTrace(); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
public void updateFeed(SocialContract.SocialListener socialListener, NewFeedRequest newFeedRequest, String feedId) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void updateAccessType(final SocialContract.SocialListener socialListener, final NewFeedRequest newFeedRequest, final String feedId, final String wall) { |
|
|
|
if (!Utils.isNetworkConnected(context)) { |
|
|
|
if (wall.equalsIgnoreCase("private")) { |
|
|
|
socialListener.onNoInternetConnection(PRIVATEFEED); |
|
|
|
} else { |
|
|
|
socialListener.onNoInternetConnection(PUBLICFEED); |
|
|
|
} |
|
|
|
} else { |
|
|
|
Call<FeedData> call = new RestApi(context).apiEndpoints.updateFeed(newFeedRequest, feedId); |
|
|
|
call.enqueue(new Callback<FeedData>() { |
|
|
|
@Override |
|
|
|
public void onResponse(Call<FeedData> call, Response<FeedData> response) { |
|
|
|
if (response.isSuccessful()) { |
|
|
|
Log.i("Update Feed", new Gson().toJson(response.body())); |
|
|
|
socialListener.onSuccessAccessTyped(response.body()); |
|
|
|
} else if (response.code() == 401) { |
|
|
|
RefreshModal modal = new RefreshModal(context); |
|
|
|
|
|
|
|
modal.performTokenRefresh(new OnRefreshCallback() { |
|
|
|
@Override |
|
|
|
public void onRefreshSuccess() { |
|
|
|
new RestApi(context); |
|
|
|
updateAccessType(socialListener, newFeedRequest, feedId, wall); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onRefreshUnknown(APIRequestErrorReturn errorReturn) { |
|
|
|
socialListener.onFailuerAccessTyped(errorReturn.message); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onRefreshFailure(Throwable t) { |
|
|
|
socialListener.onFailuerAccessTyped(t.getMessage()); |
|
|
|
} |
|
|
|
}); |
|
|
|
} else if (response.code() == 403) { |
|
|
|
RefreshModal modal = new RefreshModal(context); |
|
|
|
modal.performLogout(); |
|
|
|
} else { |
|
|
|
Gson gson = new GsonBuilder().create(); |
|
|
|
APIRequestErrorReturn statusErrorReturn = new APIRequestErrorReturn(); |
|
|
|
try { |
|
|
|
statusErrorReturn = gson.fromJson(response.errorBody().string(), APIRequestErrorReturn.class); |
|
|
|
socialListener.onFailuerAccessTyped(statusErrorReturn.message); |
|
|
|
} catch (IOException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onFailure(Call<FeedData> call, Throwable t) { |
|
|
|
Log.e("NOW ", "FROM HERE 5"); |
|
|
|
socialListener.onFailuerAccessTyped((t instanceof IOException) ? "Connection Lost" : t.getMessage()); |
|
|
|
t.printStackTrace(); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
public void updateAccessType(SocialContract.SocialListener socialListener, NewFeedRequest newFeedRequest, String feedId, String wall) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void likeFeed(final String feedId, final String userId) { |
|
|
|
Call<ResponseBody> call = new RestApi(context).apiEndpoints.likeFeed(feedId, userId); |
|
|
|
call.enqueue(new Callback<ResponseBody>() { |
|
|
|
@Override |
|
|
|
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) { |
|
|
|
if (response.isSuccessful()) { |
|
|
|
Log.i("Update Feed", new Gson().toJson(response.body())); |
|
|
|
} else if (response.code() == 401) { |
|
|
|
RefreshModal modal = new RefreshModal(context); |
|
|
|
|
|
|
|
modal.performTokenRefresh(new OnRefreshCallback() { |
|
|
|
@Override |
|
|
|
public void onRefreshSuccess() { |
|
|
|
new RestApi(context); |
|
|
|
likeFeed(feedId, userId); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onRefreshUnknown(APIRequestErrorReturn errorReturn) { |
|
|
|
// socialListener.onFailuerAccessTyped(errorReturn.message); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onRefreshFailure(Throwable t) { |
|
|
|
// socialListener.onFailuerAccessTyped(t.getMessage()); |
|
|
|
} |
|
|
|
}); |
|
|
|
} else if (response.code() == 403) { |
|
|
|
RefreshModal modal = new RefreshModal(context); |
|
|
|
modal.performLogout(); |
|
|
|
} else { |
|
|
|
Gson gson = new GsonBuilder().create(); |
|
|
|
APIRequestErrorReturn statusErrorReturn = new APIRequestErrorReturn(); |
|
|
|
try { |
|
|
|
statusErrorReturn = gson.fromJson(response.errorBody().string(), APIRequestErrorReturn.class); |
|
|
|
// socialListener.onFailuerAccessTyped(statusErrorReturn.message); |
|
|
|
} catch (IOException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onFailure(Call<ResponseBody> call, Throwable t) { |
|
|
|
// socialListener.onFailuerAccessTyped(t.getMessage()); |
|
|
|
t.printStackTrace(); |
|
|
|
} |
|
|
|
}); |
|
|
|
public void likeFeed(String feedId, String userId) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void dislikeFeed(final String feedId, final String userId) { |
|
|
|
Call<ResponseBody> call = new RestApi(context).apiEndpoints.dislikeFeed(feedId, userId); |
|
|
|
call.enqueue(new Callback<ResponseBody>() { |
|
|
|
@Override |
|
|
|
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) { |
|
|
|
if (response.isSuccessful()) { |
|
|
|
Log.i("Update Feed", new Gson().toJson(response.body())); |
|
|
|
} else if (response.code() == 401) { |
|
|
|
RefreshModal modal = new RefreshModal(context); |
|
|
|
|
|
|
|
modal.performTokenRefresh(new OnRefreshCallback() { |
|
|
|
@Override |
|
|
|
public void onRefreshSuccess() { |
|
|
|
new RestApi(context); |
|
|
|
dislikeFeed(feedId, userId); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onRefreshUnknown(APIRequestErrorReturn errorReturn) { |
|
|
|
// socialListener.onFailuerAccessTyped(errorReturn.message); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onRefreshFailure(Throwable t) { |
|
|
|
// socialListener.onFailuerAccessTyped(t.getMessage()); |
|
|
|
} |
|
|
|
}); |
|
|
|
} else if (response.code() == 403) { |
|
|
|
RefreshModal modal = new RefreshModal(context); |
|
|
|
modal.performLogout(); |
|
|
|
} else { |
|
|
|
Gson gson = new GsonBuilder().create(); |
|
|
|
APIRequestErrorReturn statusErrorReturn = new APIRequestErrorReturn(); |
|
|
|
try { |
|
|
|
statusErrorReturn = gson.fromJson(response.errorBody().string(), APIRequestErrorReturn.class); |
|
|
|
// socialListener.onFailuerAccessTyped(statusErrorReturn.message); |
|
|
|
} catch (IOException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onFailure(Call<ResponseBody> call, Throwable t) { |
|
|
|
// socialListener.onFailuerAccessTyped(t.getMessage()); |
|
|
|
t.printStackTrace(); |
|
|
|
} |
|
|
|
}); |
|
|
|
public void dislikeFeed(String feedId, String userId) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void getAllLikes(final SocialContract.SocialListener socialListener, final String feedId) { |
|
|
|
if (!Utils.isNetworkConnected(context)) { |
|
|
|
socialListener.onNoInternetConnection(Constants.AllLikes); |
|
|
|
} else { |
|
|
|
Call<List<LikeData>> call = new RestApi(context).apiEndpoints.getAllLikes(feedId); |
|
|
|
call.enqueue(new Callback<List<LikeData>>() { |
|
|
|
@Override |
|
|
|
public void onResponse(Call<List<LikeData>> call, Response<List<LikeData>> response) { |
|
|
|
if (response.isSuccessful()) { |
|
|
|
Log.i("get Feed", new Gson().toJson(response.body())); |
|
|
|
socialListener.onSuccessAllLikes(response.body()); |
|
|
|
} else if (response.code() == 401) { |
|
|
|
RefreshModal modal = new RefreshModal(context); |
|
|
|
|
|
|
|
modal.performTokenRefresh(new OnRefreshCallback() { |
|
|
|
@Override |
|
|
|
public void onRefreshSuccess() { |
|
|
|
new RestApi(context); |
|
|
|
getAllLikes(socialListener, feedId); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onRefreshUnknown(APIRequestErrorReturn errorReturn) { |
|
|
|
socialListener.onFailureAllLikes(errorReturn.message); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onRefreshFailure(Throwable t) { |
|
|
|
socialListener.onFailureAllLikes(t.getMessage()); |
|
|
|
} |
|
|
|
}); |
|
|
|
} else if (response.code() == 403) { |
|
|
|
RefreshModal modal = new RefreshModal(context); |
|
|
|
modal.performLogout(); |
|
|
|
} else { |
|
|
|
Gson gson = new GsonBuilder().create(); |
|
|
|
APIRequestErrorReturn statusErrorReturn = new APIRequestErrorReturn(); |
|
|
|
try { |
|
|
|
statusErrorReturn = gson.fromJson(response.errorBody().string(), APIRequestErrorReturn.class); |
|
|
|
socialListener.onFailureAllLikes(statusErrorReturn.message); |
|
|
|
} catch (IOException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onFailure(Call<List<LikeData>> call, Throwable t) { |
|
|
|
socialListener.onFailureAllLikes((t instanceof IOException) ? "Connection Lost" : t.getMessage()); |
|
|
|
t.printStackTrace(); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
public void getAllLikes(SocialContract.SocialListener socialListener, String feedId) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void deleteFeed(final SocialContract.SocialListener socialListener, final String feedId, final String userId) { |
|
|
|
if (!Utils.isNetworkConnected(context)) { |
|
|
|
socialListener.onNoInternetConnection(PUBLICFEED); |
|
|
|
} else { |
|
|
|
Call<ResponseBody> call = new RestApi(context).apiEndpoints.deleteFeed(feedId, userId); |
|
|
|
call.enqueue(new Callback<ResponseBody>() { |
|
|
|
@Override |
|
|
|
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) { |
|
|
|
if (response.isSuccessful()) { |
|
|
|
Log.i("get Feed", new Gson().toJson(response.body())); |
|
|
|
socialListener.onSuccessDeleteFeed(); |
|
|
|
} else if (response.code() == 401) { |
|
|
|
RefreshModal modal = new RefreshModal(context); |
|
|
|
|
|
|
|
modal.performTokenRefresh(new OnRefreshCallback() { |
|
|
|
@Override |
|
|
|
public void onRefreshSuccess() { |
|
|
|
new RestApi(context); |
|
|
|
deleteFeed(socialListener, feedId, userId); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onRefreshUnknown(APIRequestErrorReturn errorReturn) { |
|
|
|
socialListener.onFailureDeleteFeed(errorReturn.message); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onRefreshFailure(Throwable t) { |
|
|
|
socialListener.onFailureDeleteFeed(t.getMessage()); |
|
|
|
} |
|
|
|
}); |
|
|
|
} else if (response.code() == 403) { |
|
|
|
RefreshModal modal = new RefreshModal(context); |
|
|
|
modal.performLogout(); |
|
|
|
} else { |
|
|
|
Gson gson = new GsonBuilder().create(); |
|
|
|
APIRequestErrorReturn statusErrorReturn = new APIRequestErrorReturn(); |
|
|
|
try { |
|
|
|
statusErrorReturn = gson.fromJson(response.errorBody().string(), APIRequestErrorReturn.class); |
|
|
|
socialListener.onFailureDeleteFeed(statusErrorReturn.message); |
|
|
|
} catch (IOException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onFailure(Call<ResponseBody> call, Throwable t) { |
|
|
|
socialListener.onFailureDeleteFeed((t instanceof IOException) ? "Connection Lost" : t.getMessage()); |
|
|
|
t.printStackTrace(); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
public void deleteFeed(SocialContract.SocialListener socialListener, String feedId, String userId) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void getAllComments(final SocialContract.SocialListener socialListener, final String feedId, final String after) { |
|
|
|
if (!Utils.isNetworkConnected(context)) { |
|
|
|
socialListener.onNoInternetConnection(Constants.COMMENT); |
|
|
|
} else { |
|
|
|
Call<CommentResponse> call = new RestApi(context).apiEndpoints.getAllComments(feedId, after, "10"); |
|
|
|
call.enqueue(new Callback<CommentResponse>() { |
|
|
|
@Override |
|
|
|
public void onResponse(Call<CommentResponse> call, Response<CommentResponse> response) { |
|
|
|
if (response.isSuccessful()) { |
|
|
|
Log.i("get Feed", new Gson().toJson(response.body())); |
|
|
|
socialListener.onSuccessAllComments(response.body()); |
|
|
|
} else if (response.code() == 401) { |
|
|
|
RefreshModal modal = new RefreshModal(context); |
|
|
|
|
|
|
|
modal.performTokenRefresh(new OnRefreshCallback() { |
|
|
|
@Override |
|
|
|
public void onRefreshSuccess() { |
|
|
|
new RestApi(context); |
|
|
|
getAllComments(socialListener, feedId, after); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onRefreshUnknown(APIRequestErrorReturn errorReturn) { |
|
|
|
socialListener.onFailureAllComments(errorReturn.message); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onRefreshFailure(Throwable t) { |
|
|
|
socialListener.onFailureAllComments(t.getMessage()); |
|
|
|
} |
|
|
|
}); |
|
|
|
} else if (response.code() == 403) { |
|
|
|
RefreshModal modal = new RefreshModal(context); |
|
|
|
modal.performLogout(); |
|
|
|
} else { |
|
|
|
Gson gson = new GsonBuilder().create(); |
|
|
|
APIRequestErrorReturn statusErrorReturn = new APIRequestErrorReturn(); |
|
|
|
try { |
|
|
|
statusErrorReturn = gson.fromJson(response.errorBody().string(), APIRequestErrorReturn.class); |
|
|
|
socialListener.onFailureAllComments(statusErrorReturn.message); |
|
|
|
} catch (IOException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onFailure(Call<CommentResponse> call, Throwable t) { |
|
|
|
socialListener.onFailureAllComments((t instanceof IOException) ? "Connection Lost" : t.getMessage()); |
|
|
|
t.printStackTrace(); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
public void getAllComments(SocialContract.SocialListener socialListener, String feedId, String after) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void addComment(final SocialContract.SocialListener socialListener, final CommentUpdateRequest commentUpdateRequest, final String feedId) { |
|
|
|
if (!Utils.isNetworkConnected(context)) { |
|
|
|
socialListener.onNoInternetConnection(Constants.COMMENT); |
|
|
|
} else { |
|
|
|
Call<Comments> call = new RestApi(context).apiEndpoints.addComment(commentUpdateRequest, feedId); |
|
|
|
call.enqueue(new Callback<Comments>() { |
|
|
|
@Override |
|
|
|
public void onResponse(Call<Comments> call, Response<Comments> response) { |
|
|
|
if (response.isSuccessful()) { |
|
|
|
Log.i("updateComment", new Gson().toJson(response.body())); |
|
|
|
socialListener.onSuccessAddComment(response.body()); |
|
|
|
} else if (response.code() == 401) { |
|
|
|
RefreshModal modal = new RefreshModal(context); |
|
|
|
|
|
|
|
modal.performTokenRefresh(new OnRefreshCallback() { |
|
|
|
@Override |
|
|
|
public void onRefreshSuccess() { |
|
|
|
new RestApi(context); |
|
|
|
addComment(socialListener, commentUpdateRequest, feedId); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onRefreshUnknown(APIRequestErrorReturn errorReturn) { |
|
|
|
socialListener.onFailureAddComment(errorReturn.message); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onRefreshFailure(Throwable t) { |
|
|
|
socialListener.onFailureAddComment(t.getMessage()); |
|
|
|
} |
|
|
|
}); |
|
|
|
} else if (response.code() == 403) { |
|
|
|
RefreshModal modal = new RefreshModal(context); |
|
|
|
modal.performLogout(); |
|
|
|
} else { |
|
|
|
Gson gson = new GsonBuilder().create(); |
|
|
|
APIRequestErrorReturn statusErrorReturn = new APIRequestErrorReturn(); |
|
|
|
try { |
|
|
|
statusErrorReturn = gson.fromJson(response.errorBody().string(), APIRequestErrorReturn.class); |
|
|
|
socialListener.onFailureAddComment(statusErrorReturn.message); |
|
|
|
} catch (IOException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onFailure(Call<Comments> call, Throwable t) { |
|
|
|
socialListener.onFailureAddComment((t instanceof IOException) ? "Connection Lost" : t.getMessage()); |
|
|
|
t.printStackTrace(); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
public void addComment(SocialContract.SocialListener socialListener, CommentUpdateRequest commentUpdateRequest, String feedId) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void updateComment(final SocialContract.SocialListener socialListener, final CommentUpdateRequest commentUpdateRequest, final String feedId, final String commentId) { |
|
|
|
if (!Utils.isNetworkConnected(context)) { |
|
|
|
socialListener.onNoInternetConnection(Constants.UPDATE_COMMENT); |
|
|
|
} else { |
|
|
|
Call<Comments> call = new RestApi(context).apiEndpoints.updateComment(commentUpdateRequest, feedId, commentId); |
|
|
|
call.enqueue(new Callback<Comments>() { |
|
|
|
@Override |
|
|
|
public void onResponse(Call<Comments> call, Response<Comments> response) { |
|
|
|
if (response.isSuccessful()) { |
|
|
|
Log.i("updateComment", new Gson().toJson(response.body())); |
|
|
|
socialListener.onSuccessUpdateComment(response.body()); |
|
|
|
} else if (response.code() == 401) { |
|
|
|
RefreshModal modal = new RefreshModal(context); |
|
|
|
|
|
|
|
modal.performTokenRefresh(new OnRefreshCallback() { |
|
|
|
@Override |
|
|
|
public void onRefreshSuccess() { |
|
|
|
new RestApi(context); |
|
|
|
updateComment(socialListener, commentUpdateRequest, feedId, commentId); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onRefreshUnknown(APIRequestErrorReturn errorReturn) { |
|
|
|
socialListener.onFailureUpdateComment(errorReturn.message); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onRefreshFailure(Throwable t) { |
|
|
|
socialListener.onFailureUpdateComment(t.getMessage()); |
|
|
|
} |
|
|
|
}); |
|
|
|
} else if (response.code() == 403) { |
|
|
|
RefreshModal modal = new RefreshModal(context); |
|
|
|
modal.performLogout(); |
|
|
|
} else { |
|
|
|
Gson gson = new GsonBuilder().create(); |
|
|
|
APIRequestErrorReturn statusErrorReturn = new APIRequestErrorReturn(); |
|
|
|
try { |
|
|
|
statusErrorReturn = gson.fromJson(response.errorBody().string(), APIRequestErrorReturn.class); |
|
|
|
socialListener.onFailureUpdateComment(statusErrorReturn.message); |
|
|
|
} catch (IOException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onFailure(Call<Comments> call, Throwable t) { |
|
|
|
socialListener.onFailureUpdateComment((t instanceof IOException) ? "Connection Lost" : t.getMessage()); |
|
|
|
t.printStackTrace(); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
public void updateComment(SocialContract.SocialListener socialListener, CommentUpdateRequest commentUpdateRequest, String feedId, String commentId) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void deleteComment(final SocialContract.SocialListener socialListener, final String feedId, final String commentId, final String userId) { |
|
|
|
if (!Utils.isNetworkConnected(context)) { |
|
|
|
socialListener.onNoInternetConnection(Constants.COMMENT); |
|
|
|
} else { |
|
|
|
Call<Comments> call = new RestApi(context).apiEndpoints.deleteComment(feedId, commentId, userId); |
|
|
|
call.enqueue(new Callback<Comments>() { |
|
|
|
@Override |
|
|
|
public void onResponse(Call<Comments> call, Response<Comments> response) { |
|
|
|
if (response.isSuccessful()) { |
|
|
|
Log.i("updateComment", new Gson().toJson(response.body())); |
|
|
|
socialListener.onSuccessDeleteComment(); |
|
|
|
} else if (response.code() == 401) { |
|
|
|
RefreshModal modal = new RefreshModal(context); |
|
|
|
|
|
|
|
modal.performTokenRefresh(new OnRefreshCallback() { |
|
|
|
@Override |
|
|
|
public void onRefreshSuccess() { |
|
|
|
new RestApi(context); |
|
|
|
deleteComment(socialListener, feedId, commentId, userId); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onRefreshUnknown(APIRequestErrorReturn errorReturn) { |
|
|
|
socialListener.onFailureDeleteComment(errorReturn.message); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onRefreshFailure(Throwable t) { |
|
|
|
socialListener.onFailureDeleteComment(t.getMessage()); |
|
|
|
} |
|
|
|
}); |
|
|
|
} else if (response.code() == 403) { |
|
|
|
RefreshModal modal = new RefreshModal(context); |
|
|
|
modal.performLogout(); |
|
|
|
} else { |
|
|
|
Gson gson = new GsonBuilder().create(); |
|
|
|
APIRequestErrorReturn statusErrorReturn = new APIRequestErrorReturn(); |
|
|
|
try { |
|
|
|
statusErrorReturn = gson.fromJson(response.errorBody().string(), APIRequestErrorReturn.class); |
|
|
|
socialListener.onFailureDeleteComment(statusErrorReturn.message); |
|
|
|
} catch (IOException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onFailure(Call<Comments> call, Throwable t) { |
|
|
|
socialListener.onFailureDeleteComment((t instanceof IOException) ? "Connection Lost" : t.getMessage()); |
|
|
|
t.printStackTrace(); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
public void deleteComment(SocialContract.SocialListener socialListener, String feedId, String commentId, String userId) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void reportFeed(final SocialContract.SocialListener socialListener, final String feedId, final ReportRequest reportRequest) { |
|
|
|
if (!Utils.isNetworkConnected(context)) { |
|
|
|
socialListener.onNoInternetConnection(PUBLICFEED); |
|
|
|
} else { |
|
|
|
Call<ResponseBody> call = new RestApi(context).apiEndpoints.reportFeed(feedId, reportRequest); |
|
|
|
call.enqueue(new Callback<ResponseBody>() { |
|
|
|
@Override |
|
|
|
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) { |
|
|
|
if (response.isSuccessful()) { |
|
|
|
Log.i("updateComment", new Gson().toJson(response.body())); |
|
|
|
socialListener.onSuccessReportFeed(); |
|
|
|
} else if (response.code() == 401) { |
|
|
|
RefreshModal modal = new RefreshModal(context); |
|
|
|
|
|
|
|
modal.performTokenRefresh(new OnRefreshCallback() { |
|
|
|
@Override |
|
|
|
public void onRefreshSuccess() { |
|
|
|
new RestApi(context); |
|
|
|
reportFeed(socialListener, feedId, reportRequest); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onRefreshUnknown(APIRequestErrorReturn errorReturn) { |
|
|
|
socialListener.onFailureReportFeed(errorReturn.message); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onRefreshFailure(Throwable t) { |
|
|
|
socialListener.onFailureReportFeed(t.getMessage()); |
|
|
|
} |
|
|
|
}); |
|
|
|
} else if (response.code() == 403) { |
|
|
|
RefreshModal modal = new RefreshModal(context); |
|
|
|
modal.performLogout(); |
|
|
|
} else { |
|
|
|
Gson gson = new GsonBuilder().create(); |
|
|
|
APIRequestErrorReturn statusErrorReturn = new APIRequestErrorReturn(); |
|
|
|
try { |
|
|
|
statusErrorReturn = gson.fromJson(response.errorBody().string(), APIRequestErrorReturn.class); |
|
|
|
socialListener.onFailureReportFeed(statusErrorReturn.message); |
|
|
|
} catch (IOException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onFailure(Call<ResponseBody> call, Throwable t) { |
|
|
|
socialListener.onFailureReportFeed((t instanceof IOException) ? "Connection Lost" : t.getMessage()); |
|
|
|
t.printStackTrace(); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
public void reportFeed(SocialContract.SocialListener socialListener, String feedId, ReportRequest reportRequest) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void getSingleFeed(final SocialContract.SocialListener socialListener, final String feedId, final String userId) { |
|
|
|
if (!Utils.isNetworkConnected(context)) { |
|
|
|
socialListener.onNoInternetConnection(Constants.COMMENT); |
|
|
|
} else { |
|
|
|
Call<FeedData> call = new RestApi(context).apiEndpoints.getFeed(feedId, userId); |
|
|
|
call.enqueue(new Callback<FeedData>() { |
|
|
|
@Override |
|
|
|
public void onResponse(Call<FeedData> call, Response<FeedData> response) { |
|
|
|
if (response.isSuccessful()) { |
|
|
|
socialListener.onSuccessSingleFeed(response.body()); |
|
|
|
} else if (response.code() == 401) { |
|
|
|
RefreshModal modal = new RefreshModal(context); |
|
|
|
|
|
|
|
modal.performTokenRefresh(new OnRefreshCallback() { |
|
|
|
@Override |
|
|
|
public void onRefreshSuccess() { |
|
|
|
new RestApi(context); |
|
|
|
getSingleFeed(socialListener, feedId, userId); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onRefreshUnknown(APIRequestErrorReturn errorReturn) { |
|
|
|
socialListener.onFailureSingleFeed(errorReturn.message); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onRefreshFailure(Throwable t) { |
|
|
|
socialListener.onFailureSingleFeed(t.getMessage()); |
|
|
|
} |
|
|
|
}); |
|
|
|
} else if (response.code() == 403) { |
|
|
|
RefreshModal modal = new RefreshModal(context); |
|
|
|
modal.performLogout(); |
|
|
|
} else { |
|
|
|
Gson gson = new GsonBuilder().create(); |
|
|
|
APIRequestErrorReturn statusErrorReturn = new APIRequestErrorReturn(); |
|
|
|
try { |
|
|
|
statusErrorReturn = gson.fromJson(response.errorBody().string(), APIRequestErrorReturn.class); |
|
|
|
socialListener.onFailureSingleFeed(statusErrorReturn.message); |
|
|
|
} catch (IOException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void onFailure(Call<FeedData> call, Throwable t) { |
|
|
|
socialListener.onFailureSingleFeed((t instanceof IOException) ? "Connection Lost" : t.getMessage()); |
|
|
|
t.printStackTrace(); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
public void getSingleFeed(SocialContract.SocialListener socialListener, String feedId, String userId) { |
|
|
|
|
|
|
|
} |
|
|
|
} |