use of com.fanap.podchat.util.PodChatException in project pod-chat-android-sdk by FanapSoft.
the class PodUploader method uploadPublicImageToPodSpace.
private static Subscription uploadPublicImageToPodSpace(String uniqueId, String fileServer, String token, int tokenIssuer, String xC, String yC, String hC, String wC, boolean isPublic, IPodUploadFileToPodSpace listener, String mimeType, File file, long fileSize) throws FileNotFoundException {
int width = 0;
int height = 0;
String nWidth = "";
String nHeight = "";
try {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(file.getAbsolutePath(), options);
width = options.outWidth;
height = options.outHeight;
nWidth = !Util.isNullOrEmpty(wC) && Long.parseLong(wC) > 0 ? wC : String.valueOf(width);
nHeight = !Util.isNullOrEmpty(hC) && Long.parseLong(hC) > 0 ? hC : String.valueOf(height);
} catch (Exception e) {
throw new FileNotFoundException("Invalid image!");
}
listener.onUploadStarted(mimeType, file, fileSize);
RetrofitHelperFileServer retrofitHelperFileServer = new RetrofitHelperFileServer(fileServer);
FileApi fileApi = retrofitHelperFileServer.getService(FileApi.class);
RequestBody namePart = RequestBody.create(MediaType.parse("multipart/form-data"), file.getName());
RequestBody xCPart = RequestBody.create(MediaType.parse("multipart/form-data"), !Util.isNullOrEmpty(xC) ? xC : "0");
RequestBody yCPart = RequestBody.create(MediaType.parse("multipart/form-data"), !Util.isNullOrEmpty(yC) ? yC : "0");
RequestBody hCPart = RequestBody.create(MediaType.parse("multipart/form-data"), nWidth);
RequestBody wCPart = RequestBody.create(MediaType.parse("multipart/form-data"), nHeight);
ProgressRequestBody requestFile = new ProgressRequestBody(file, mimeType, uniqueId, new ProgressRequestBody.UploadCallbacks() {
@Override
public void onProgress(String uniqueId, int progress, int totalBytesSent, int totalBytesToSend) {
if (progress < 95)
listener.onProgressUpdate(progress, totalBytesSent, totalBytesToSend);
}
});
MultipartBody.Part filePart = MultipartBody.Part.createFormData("file", file.getName(), requestFile);
Observable<Response<UploadToPodSpaceResponse>> uploadObservable = fileApi.uploadPublicImageToPodSpace(filePart, token, tokenIssuer, namePart, xCPart, yCPart, wCPart, hCPart, isPublic);
int finalWidth = width;
int finalHeight = height;
String finalNWidth = nWidth;
String finalNHeight = nHeight;
return uploadObservable.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).doOnError(error -> listener.onFailure(error.getMessage(), error)).subscribe(response -> {
if (response.isSuccessful() && response.body() != null) {
if (response.body().isHasError()) {
listener.onFailure(response.body().getMessage(), new PodChatException(response.body().getMessage(), uniqueId, token));
return;
}
listener.onProgressUpdate(100, (int) fileSize, 0);
listener.onSuccess(response.body().getUploadToPodSpaceResult(), file, mimeType, fileSize, finalWidth, finalHeight, Integer.parseInt(finalNWidth), Integer.parseInt(finalNHeight));
} else {
try {
if (response.errorBody() != null) {
listener.onFailure(response.errorBody().string(), new PodChatException(response.errorBody().string(), uniqueId, token));
} else {
listener.onFailure(response.message(), new PodChatException(response.message(), uniqueId, token));
}
} catch (IOException e) {
e.printStackTrace();
}
}
}, error -> listener.onFailure(error.getMessage(), error));
}
use of com.fanap.podchat.util.PodChatException in project pod-chat-android-sdk by FanapSoft.
the class PodUploader method uploadPublicFileToPodSpace.
private static Subscription uploadPublicFileToPodSpace(String uniqueId, String fileServer, String token, int tokenIssuer, boolean isPublic, IPodUploadFileToPodSpace listener, String mimeType, File file, long fileSize) {
listener.onUploadStarted(mimeType, file, fileSize);
RetrofitHelperFileServer retrofitHelperFileServer = new RetrofitHelperFileServer(fileServer);
FileApi fileApi = retrofitHelperFileServer.getService(FileApi.class);
RequestBody namePart = RequestBody.create(MediaType.parse("multipart/form-data"), file.getName());
ProgressRequestBody requestFile = new ProgressRequestBody(file, mimeType, uniqueId, new ProgressRequestBody.UploadCallbacks() {
@Override
public void onProgress(String uniqueId, int progress, int totalBytesSent, int totalBytesToSend) {
if (progress < 95)
listener.onProgressUpdate(progress, totalBytesSent, totalBytesToSend);
}
});
MultipartBody.Part filePart = MultipartBody.Part.createFormData("file", file.getName(), requestFile);
Observable<Response<UploadToPodSpaceResponse>> uploadObservable = fileApi.uploadPublicFileToPodSpace(filePart, token, tokenIssuer, namePart, isPublic);
return uploadObservable.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).doOnError(error -> listener.onFailure(error.getMessage(), error)).subscribe(response -> {
if (response.isSuccessful() && response.body() != null) {
if (response.body().isHasError()) {
listener.onFailure(response.body().getMessage(), new PodChatException(response.body().getMessage(), uniqueId, token));
return;
}
listener.onProgressUpdate(100, (int) fileSize, 0);
listener.onSuccess(response.body().getUploadToPodSpaceResult(), file, mimeType, fileSize);
} else {
try {
if (response.errorBody() != null) {
listener.onFailure(response.errorBody().string(), new PodChatException(response.errorBody().string(), uniqueId, token));
} else {
listener.onFailure(response.message(), new PodChatException(response.message(), uniqueId, token));
}
} catch (IOException e) {
e.printStackTrace();
}
}
}, error -> listener.onFailure(error.getMessage(), error));
}
use of com.fanap.podchat.util.PodChatException in project pod-chat-android-sdk by FanapSoft.
the class MapManager method searchMap.
public static Observable<OutPutMapNeshan> searchMap(String apiKey, String api, String searchTerm, double latitude, double longitude) {
return Observable.create(subscriber -> {
RetrofitHelperMap retrofitHelperMap = new RetrofitHelperMap(api);
MapApi mapApi = retrofitHelperMap.getService(MapApi.class);
Observable<Response<MapNeshan>> observable = mapApi.mapSearch(apiKey, searchTerm, latitude, longitude);
observable.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(mapNeshanResponse -> {
OutPutMapNeshan outPutMapNeshan = new OutPutMapNeshan();
if (mapNeshanResponse.isSuccessful()) {
MapNeshan mapNeshan = mapNeshanResponse.body();
if (mapNeshan == null) {
subscriber.onError(new PodChatException(mapNeshanResponse.message(), mapNeshanResponse.code()));
return;
}
outPutMapNeshan = new OutPutMapNeshan();
outPutMapNeshan.setCount(mapNeshan.getCount());
ResultMap resultMap = new ResultMap();
resultMap.setMaps(mapNeshan.getItems());
outPutMapNeshan.setResult(resultMap);
subscriber.onNext(outPutMapNeshan);
} else {
subscriber.onError(new PodChatException(mapNeshanResponse.message(), mapNeshanResponse.code()));
}
}, subscriber::onError);
});
}
use of com.fanap.podchat.util.PodChatException in project pod-chat-android-sdk by FanapSoft.
the class CallAsyncRequestsManager method createCallClientErrorsRequestMessage.
public static String createCallClientErrorsRequestMessage(CallClientErrorsRequest request, String uniqueId) throws PodChatException {
if (request.getCallId() <= 0)
throw new PodChatException("Invalid call id", ChatConstant.ERROR_CODE_INVALID_THREAD_ID, uniqueId);
AsyncMessage message = new AsyncMessage();
JsonObject contentObj = new JsonObject();
contentObj.addProperty("code", request.getErrorCode());
message.setType(ChatMessageType.Constants.CALL_CLIENT_ERRORS);
message.setContent(contentObj.toString());
message.setToken(CoreConfig.token);
message.setTokenIssuer(CoreConfig.tokenIssuer);
message.setUniqueId(uniqueId);
message.setSubjectId(request.getCallId());
message.setTypeCode(Util.isNotNullOrEmpty(request.getTypeCode()) ? request.getTypeCode() : CoreConfig.typeCode);
JsonObject messageObj = (JsonObject) App.getGson().toJsonTree(message);
return messageObj.toString();
}
use of com.fanap.podchat.util.PodChatException in project pod-chat-android-sdk by FanapSoft.
the class CallAsyncRequestsManager method createUnMuteCallParticipantMessage.
public static String createUnMuteCallParticipantMessage(MuteUnMuteCallParticipantRequest request, String uniqueId) throws PodChatException {
if (request.getCallId() <= 0)
throw new PodChatException(ChatConstant.ERROR_INVALID_THREAD_ID, ChatConstant.ERROR_CODE_INVALID_THREAD_ID);
if (Util.isNullOrEmpty(request.getParticipantsIds()))
throw new PodChatException(ChatConstant.MUTE_USER_LIST_IS_EMPTY, ChatConstant.ERROR_CODE_INVALID_DATA);
String content = App.getGson().toJson(request.getParticipantsIds());
AsyncMessage message = new AsyncMessage();
message.setContent(content);
message.setType(ChatMessageType.Constants.UN_MUTE_CALL_PARTICIPANT);
message.setToken(CoreConfig.token);
message.setSubjectId(request.getCallId());
message.setTokenIssuer(CoreConfig.tokenIssuer);
message.setUniqueId(uniqueId);
message.setTypeCode(Util.isNullOrEmpty(request.getTypeCode()) ? request.getTypeCode() : CoreConfig.typeCode);
JsonObject a = (JsonObject) App.getGson().toJsonTree(message);
return a.toString();
}
Aggregations