From 72f3a67d4f741c98510d6e6a201331ffe85d14b0 Mon Sep 17 00:00:00 2001 From: fsergio101 Date: Sun, 10 Apr 2016 17:22:52 +0200 Subject: [PATCH] feedback response management feedback response management --- .../applvsdklib/domain/BaseInteractor.java | 5 ++ .../domain/feedback/FeedbackInteractor.java | 11 ++-- .../applvsdklib/domain/model/ErrorObject.java | 6 ++ .../domain/model/UserFeedback.java | 9 ++- .../network/api/requests/FeedbackRequest.java | 7 +- .../network/api/requests/ServerRequest.java | 3 +- .../mappers/ApiFeedbackResponseMapper.java | 66 +++++++++++++++++++ .../api/responses/ApiFeedbackResponse.java | 4 +- .../views/feedback/UserFeedbackPresenter.java | 5 +- 9 files changed, 103 insertions(+), 13 deletions(-) create mode 100644 applvsdklib/src/main/java/com/applivery/applvsdklib/network/api/requests/mappers/ApiFeedbackResponseMapper.java diff --git a/applvsdklib/src/main/java/com/applivery/applvsdklib/domain/BaseInteractor.java b/applvsdklib/src/main/java/com/applivery/applvsdklib/domain/BaseInteractor.java index 51b49f5..a4c8188 100644 --- a/applvsdklib/src/main/java/com/applivery/applvsdklib/domain/BaseInteractor.java +++ b/applvsdklib/src/main/java/com/applivery/applvsdklib/domain/BaseInteractor.java @@ -52,6 +52,11 @@ protected void receivedResponse(BusinessObject obj, Class responseClass) { @Override public void run() { Message message = new Message(); message.obj = performRequest(); + + if (message.obj == null){ + message.obj = new ErrorObject(); + } + handler.sendMessage(message); } diff --git a/applvsdklib/src/main/java/com/applivery/applvsdklib/domain/feedback/FeedbackInteractor.java b/applvsdklib/src/main/java/com/applivery/applvsdklib/domain/feedback/FeedbackInteractor.java index 3d5d5cf..901b95d 100644 --- a/applvsdklib/src/main/java/com/applivery/applvsdklib/domain/feedback/FeedbackInteractor.java +++ b/applvsdklib/src/main/java/com/applivery/applvsdklib/domain/feedback/FeedbackInteractor.java @@ -29,6 +29,7 @@ import com.applivery.applvsdklib.network.api.requests.FeedbackRequest; import com.applivery.applvsdklib.tools.androidimplementations.AndroidCurrentAppInfo; import com.applivery.applvsdklib.tools.androidimplementations.AndroidDeviceDetailsInfo; +import com.applivery.applvsdklib.ui.views.feedback.UserFeedbackPresenter; /** * Created by Sergio Martinez Rodriguez @@ -41,11 +42,12 @@ public class FeedbackInteractor extends BaseInteractor { private final FeedbackWrapper feedbackWrapper; public FeedbackInteractor(AppliveryApiService appliveryApiService, Feedback feedback, - CurrentAppInfo currentAppInfo, DeviceDetailsInfo deviceDetailsInfo) { + CurrentAppInfo currentAppInfo, DeviceDetailsInfo deviceDetailsInfo, + InteractorCallback interactorCallback) { this.feedbackWrapper = FeedbackWrapper.createWrapper(feedback, currentAppInfo, deviceDetailsInfo); this.feedbackRequest = new FeedbackRequest(appliveryApiService, feedbackWrapper); - this.feedbackCallback = new FeedbackInteractorCallback(); + this.feedbackCallback = interactorCallback; } @Override protected void receivedResponse(BusinessObject result) { @@ -64,13 +66,14 @@ public FeedbackInteractor(AppliveryApiService appliveryApiService, Feedback feed return feedbackRequest.execute(); } - public static Runnable getInstance(AppliveryApiService service, Feedback feedback) { + public static Runnable getInstance(AppliveryApiService service, Feedback feedback, UserFeedbackPresenter + userFeedbackPresenter) { CurrentAppInfo currentAppInfo = new AndroidCurrentAppInfo(AppliverySdk.getApplicationContext()); DeviceDetailsInfo deviceDetailsInfo = new AndroidDeviceDetailsInfo(); FeedbackInteractor feedbackInteractor = new FeedbackInteractor(service, feedback, - currentAppInfo, deviceDetailsInfo); + currentAppInfo, deviceDetailsInfo, userFeedbackPresenter); return feedbackInteractor; } diff --git a/applvsdklib/src/main/java/com/applivery/applvsdklib/domain/model/ErrorObject.java b/applvsdklib/src/main/java/com/applivery/applvsdklib/domain/model/ErrorObject.java index 1eb4426..d7e5190 100644 --- a/applvsdklib/src/main/java/com/applivery/applvsdklib/domain/model/ErrorObject.java +++ b/applvsdklib/src/main/java/com/applivery/applvsdklib/domain/model/ErrorObject.java @@ -34,6 +34,12 @@ public ErrorObject(ApiAppliveryServerErrorResponse serverResponse) { isBusinessError = serverResponse.isBusinessError(); } + public ErrorObject() { + businessCode = -99; + message = "Unknown Error"; + isBusinessError = false; + } + @Override public ErrorObject getObject() { return this; } diff --git a/applvsdklib/src/main/java/com/applivery/applvsdklib/domain/model/UserFeedback.java b/applvsdklib/src/main/java/com/applivery/applvsdklib/domain/model/UserFeedback.java index 68ee6e8..706a220 100644 --- a/applvsdklib/src/main/java/com/applivery/applvsdklib/domain/model/UserFeedback.java +++ b/applvsdklib/src/main/java/com/applivery/applvsdklib/domain/model/UserFeedback.java @@ -25,7 +25,7 @@ public class UserFeedback implements Feedback { private FeedBackType feedBackType; - private boolean screenshotAttached; + private boolean screenshotAttached = true; private String feedbackMessage; private ScreenCapture screenCapture; @@ -54,7 +54,12 @@ public class UserFeedback implements Feedback { } @Override public String getBase64ScreenCapture() { - return screenCapture.getBase64(); + if (screenCapture!=null){ + return screenCapture.getBase64(); + }else{ + return null; + } + } @Override public FeedBackType getType() { diff --git a/applvsdklib/src/main/java/com/applivery/applvsdklib/network/api/requests/FeedbackRequest.java b/applvsdklib/src/main/java/com/applivery/applvsdklib/network/api/requests/FeedbackRequest.java index b916f03..95cda88 100644 --- a/applvsdklib/src/main/java/com/applivery/applvsdklib/network/api/requests/FeedbackRequest.java +++ b/applvsdklib/src/main/java/com/applivery/applvsdklib/network/api/requests/FeedbackRequest.java @@ -16,9 +16,9 @@ package com.applivery.applvsdklib.network.api.requests; +import com.applivery.applvsdklib.network.api.requests.mappers.ApiFeedbackResponseMapper; import com.applivery.applvsdklib.network.api.AppliveryApiService; import com.applivery.applvsdklib.domain.model.BusinessObject; -import com.applivery.applvsdklib.domain.model.FeedbackResult; import com.applivery.applvsdklib.domain.model.FeedbackWrapper; import com.applivery.applvsdklib.network.api.model.ApiFeedbackData; import com.applivery.applvsdklib.network.api.requests.mappers.ApiDeviceInfoRequestMapper; @@ -38,10 +38,12 @@ public class FeedbackRequest extends ServerRequest { private final AppliveryApiService apiService; private final FeedbackWrapper feedbackWrapper; private final ApiFeedbackRequestMapper apiFeedbackRequestMapper; + private final ApiFeedbackResponseMapper apiFeedbackResponseMapper; public FeedbackRequest(AppliveryApiService apiService, FeedbackWrapper feedbackWrapper) { this.apiService = apiService; this.feedbackWrapper = feedbackWrapper; + this.apiFeedbackResponseMapper = new ApiFeedbackResponseMapper(); this.apiFeedbackRequestMapper = createMappers(); } @@ -62,7 +64,8 @@ private ApiFeedbackRequestMapper createMappers() { ApiFeedbackData apiFeedbackData = apiFeedbackRequestMapper.modelToData(feedbackWrapper); Call response = apiService.sendFeedback(apiFeedbackData); ApiFeedbackResponse apiFeedbackResponse = super.performRequest(response); - return new FeedbackResult(apiFeedbackResponse.getStatus()); + BusinessObject businessObject = apiFeedbackResponseMapper.map(apiFeedbackResponse); + return businessObject; } } diff --git a/applvsdklib/src/main/java/com/applivery/applvsdklib/network/api/requests/ServerRequest.java b/applvsdklib/src/main/java/com/applivery/applvsdklib/network/api/requests/ServerRequest.java index 94cc146..33f15c1 100644 --- a/applvsdklib/src/main/java/com/applivery/applvsdklib/network/api/requests/ServerRequest.java +++ b/applvsdklib/src/main/java/com/applivery/applvsdklib/network/api/requests/ServerRequest.java @@ -28,7 +28,8 @@ public abstract class ServerRequest { public final BusinessObject execute() { try { - return performRequest(); + BusinessObject businessObject = performRequest(); + return businessObject; }catch (RequestHttpException re){ return new ErrorObject(re.getServerResponse().getError()); } diff --git a/applvsdklib/src/main/java/com/applivery/applvsdklib/network/api/requests/mappers/ApiFeedbackResponseMapper.java b/applvsdklib/src/main/java/com/applivery/applvsdklib/network/api/requests/mappers/ApiFeedbackResponseMapper.java new file mode 100644 index 0000000..c8fc7ff --- /dev/null +++ b/applvsdklib/src/main/java/com/applivery/applvsdklib/network/api/requests/mappers/ApiFeedbackResponseMapper.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2016 Applivery + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.applivery.applvsdklib.network.api.requests.mappers; + +import com.applivery.applvsdklib.domain.model.BusinessObject; +import com.applivery.applvsdklib.domain.model.FeedbackResult; +import com.applivery.applvsdklib.network.api.responses.ApiFeedbackResponse; + +/** + * Created by Sergio Martinez Rodriguez + * Date 10/4/16. + */ +public class ApiFeedbackResponseMapper extends BaseMapper { + + public ApiFeedbackResponseMapper() { + } + + public BusinessObject map(ApiFeedbackResponse apiFeedbackResponse) { + return super.map(apiFeedbackResponse); + } + + @Override protected FeedbackResult mapBusinessObject(Object serverResponse) { + FeedbackResult feedbackResult = new FeedbackResult(true); + return feedbackResult; + } + + //@Override protected AppConfig mapBusinessObject(ApiAppConfigData apiAppConfigData) { + // + // AppConfig appConfig = new AppConfig(); + // + // appConfig.setBuildsCount(apiAppConfigData.getBuildsCount()); + // + // appConfig.setCreated(DateUtils.stringToDateWithFormat(apiAppConfigData.getCreated(), + // DateFormatConstants.DATE_FORMAT)); + // + // appConfig.setModified(DateUtils.stringToDateWithFormat(apiAppConfigData.getModified(), + // DateFormatConstants.DATE_FORMAT)); + // + // appConfig.setDescription(apiAppConfigData.getDescription()); + // appConfig.setId(apiAppConfigData.getId()); + // appConfig.setName(apiAppConfigData.getName()); + // appConfig.setTotalDownloads(apiAppConfigData.getTotalDownloads()); + // appConfig.setCrashesCount(apiAppConfigData.getCrashesCount()); + // appConfig.setFeedBackCount(apiAppConfigData.getFeedbackCount()); + // appConfig.setSitesCount(apiAppConfigData.getSitesCount()); + // appConfig.setSo(apiAppConfigData.getSo()); + // appConfig.setTotalDownloads(apiAppConfigData.getTotalDownloads()); + // appConfig.setSdk(sdkMapper.dataToModel(apiAppConfigData.getSdk())); + // + // return appConfig; + //} +} diff --git a/applvsdklib/src/main/java/com/applivery/applvsdklib/network/api/responses/ApiFeedbackResponse.java b/applvsdklib/src/main/java/com/applivery/applvsdklib/network/api/responses/ApiFeedbackResponse.java index 9e48969..cfedf35 100644 --- a/applvsdklib/src/main/java/com/applivery/applvsdklib/network/api/responses/ApiFeedbackResponse.java +++ b/applvsdklib/src/main/java/com/applivery/applvsdklib/network/api/responses/ApiFeedbackResponse.java @@ -16,11 +16,9 @@ package com.applivery.applvsdklib.network.api.responses; -import com.applivery.applvsdklib.network.api.model.ApiFeedbackData; - /** * Created by Sergio Martinez Rodriguez * Date 2/1/16. */ -public class ApiFeedbackResponse extends ServerResponse { +public class ApiFeedbackResponse extends ServerResponse { } diff --git a/applvsdklib/src/main/java/com/applivery/applvsdklib/ui/views/feedback/UserFeedbackPresenter.java b/applvsdklib/src/main/java/com/applivery/applvsdklib/ui/views/feedback/UserFeedbackPresenter.java index a666b37..f3c991f 100644 --- a/applvsdklib/src/main/java/com/applivery/applvsdklib/ui/views/feedback/UserFeedbackPresenter.java +++ b/applvsdklib/src/main/java/com/applivery/applvsdklib/ui/views/feedback/UserFeedbackPresenter.java @@ -94,9 +94,12 @@ public void sendFeedbackInfo(String feedbackMessage) { if (feedback.mustAttachScreenshot()){ feedback.setScreenCapture(screenCapture); + }else{ + feedback.setScreenCapture(null); } - AppliverySdk.getExecutor().execute(FeedbackInteractor.getInstance(appliveryApiService, feedback)); + AppliverySdk.getExecutor().execute(FeedbackInteractor.getInstance(appliveryApiService, + feedback, this)); }