GUI
This commit is contained in:
@@ -33,8 +33,8 @@ android {
|
||||
applicationId "de.beyondsoft.ownchat"
|
||||
minSdkVersion 16
|
||||
targetSdkVersion 25
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
versionCode 2
|
||||
versionName "1.1"
|
||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
signingConfigs {
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package de.beyondsoft.ownchat.data.api.services;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import de.beyondsoft.ownchat.data.api.responses.GroupResponse;
|
||||
import de.beyondsoft.ownchat.data.api.responses.MessageResponse;
|
||||
import de.beyondsoft.ownchat.data.api.responses.MessagesResponse;
|
||||
@@ -30,7 +28,7 @@ public interface ChatService {
|
||||
@Query("page") int page);
|
||||
|
||||
@GET("api/chat/message/{oid}")
|
||||
Observable<JsonObject> getMessage(@Path("oid") String messageId);
|
||||
Observable<MessageResponse> getMessage(@Path("oid") String messageId);
|
||||
|
||||
@Multipart
|
||||
@POST("api/chat/messages/send")
|
||||
|
||||
@@ -6,6 +6,9 @@ import com.google.gson.JsonObject;
|
||||
|
||||
import de.beyondsoft.ownchat.R;
|
||||
import de.beyondsoft.ownchat.data.AppPrefsConstants;
|
||||
import de.beyondsoft.ownchat.data.api.common.ErrorHandlingResponseConverter;
|
||||
import de.beyondsoft.ownchat.data.api.responses.MessageResponse;
|
||||
import de.beyondsoft.ownchat.data.api.responses.MessagesResponse;
|
||||
import de.beyondsoft.ownchat.data.api.services.ChatService;
|
||||
import de.beyondsoft.ownchat.data.prefs.LongPreference;
|
||||
import de.beyondsoft.ownchat.data.repository.GroupRealmRepository;
|
||||
@@ -19,7 +22,9 @@ import de.beyondsoft.ownchat.page.main.MainActivity;
|
||||
import de.beyondsoft.ownchat.utils.Constants;
|
||||
import de.beyondsoft.ownchat.utils.LoggedOutUtils;
|
||||
import de.beyondsoft.ownchat.utils.rx.RxUtils;
|
||||
import rx.Observable;
|
||||
import rx.Subscriber;
|
||||
import rx.functions.Func1;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Notification;
|
||||
@@ -42,6 +47,7 @@ import android.os.Bundle;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
import android.support.v4.app.RemoteInput;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
@@ -105,43 +111,31 @@ public class HandleMessagesService extends FirebaseMessagingService {
|
||||
|
||||
mChatService.getMessage(messageId)
|
||||
.compose(RxUtils.provideDefaultTransformer())
|
||||
.subscribe(new Subscriber<JsonObject>() {
|
||||
.flatMap(new ErrorHandlingResponseConverter<>())
|
||||
.flatMap(new Func1<MessageResponse, Observable<Message>>() {
|
||||
@Override
|
||||
public void onCompleted() {}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
e.printStackTrace();
|
||||
public Observable<Message> call(MessageResponse messageResponse) {
|
||||
return Observable.just(messageResponse.response.message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(JsonObject remoteMessage) {
|
||||
notifyTheUser(remoteMessage);
|
||||
}
|
||||
});
|
||||
})
|
||||
.subscribe(this::getMessageSuccess, this::getMessageError);
|
||||
}
|
||||
|
||||
private String getJsonString(JsonObject object, String memberName) {
|
||||
return object.get(memberName).isJsonNull() ? null : object.get(memberName).getAsString();
|
||||
}
|
||||
|
||||
private void notifyTheUser(JsonObject remoteMessage) {
|
||||
private void getMessageSuccess(Message message) {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(Constants.MESSAGE_ID, getJsonString(remoteMessage, Constants.MESSAGE_ID));
|
||||
bundle.putLong(Constants.GROUP_ID, remoteMessage.get(Constants.GROUP_ID).getAsLong());
|
||||
bundle.putLong(Constants.CREATED_AT, remoteMessage.get(Constants.CREATED_AT).getAsLong());
|
||||
bundle.putString(Constants.MESSAGE_TEXT, getJsonString(remoteMessage, Constants.MESSAGE_TEXT));
|
||||
bundle.putString(Constants.FILE, getJsonString(remoteMessage, Constants.FILE));
|
||||
|
||||
bundle.putString(Constants.SMALLER_IMAGE, getJsonString(remoteMessage, Constants.SMALLER_IMAGE));
|
||||
bundle.putString(Constants.MESSAGE_ID, message.id);
|
||||
bundle.putLong(Constants.GROUP_ID, message.groupId);
|
||||
bundle.putLong(Constants.CREATED_AT, message.createdAt);
|
||||
bundle.putString(Constants.MESSAGE_TEXT, message.message);
|
||||
bundle.putString(Constants.FILE, message.filePath);
|
||||
bundle.putString(Constants.SMALLER_IMAGE, message.smallerImage);
|
||||
bundle.putString(Constants.FILENAME, message.originalFilename);
|
||||
bundle.putLong(Constants.USER_ID, message.senderId);
|
||||
bundle.putString(Constants.USERNAME, message.senderName);
|
||||
bundle.putString(Constants.USER_AVATAR, message.senderAvatar);
|
||||
|
||||
bundle.putString(Constants.FILENAME, getJsonString(remoteMessage, Constants.FILENAME));
|
||||
|
||||
bundle.putLong(Constants.USER_ID, remoteMessage.get(Constants.USER_ID).getAsLong());
|
||||
bundle.putString(Constants.USERNAME, getJsonString(remoteMessage, Constants.USERNAME));
|
||||
bundle.putString(Constants.USER_AVATAR, getJsonString(remoteMessage, Constants.USER_AVATAR));
|
||||
|
||||
final Bitmap bitmap = getBitmapFromUrl(remoteMessage.get(Constants.USER_AVATAR).getAsString());
|
||||
final Bitmap bitmap = getBitmapFromUrl(message.senderAvatar);
|
||||
Intent intent = new Intent();
|
||||
intent.putExtra(Constants.MESSAGE, bundle);
|
||||
intent.setAction(Constants.NOTIFICATION_BROADCAST);
|
||||
@@ -153,7 +147,7 @@ public class HandleMessagesService extends FirebaseMessagingService {
|
||||
|
||||
if (!results.getBoolean(CHAT_IS_ALREADY_OPEN, false)) {
|
||||
int groupId = (int) bundle.getLong(Constants.GROUP_ID);
|
||||
int numberOfUsers = remoteMessage.get(Constants.GROUP_NR_USERS).getAsInt();
|
||||
int numberOfUsers = message.numberOfGroupUsers;
|
||||
intent = MainActivity.createIntent(context, bundle, numberOfUsers, groupId);
|
||||
|
||||
PendingIntent pendingIntent = PendingIntent.getActivity(context,
|
||||
@@ -170,10 +164,10 @@ public class HandleMessagesService extends FirebaseMessagingService {
|
||||
|
||||
NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
|
||||
.setSmallIcon(getNotificationIcon())
|
||||
.setContentTitle(remoteMessage.get(Constants.USERNAME).getAsString() + (numberOfUsers > 2 ? " @ " +remoteMessage.get(Constants.GROUP_NAME).getAsString() : ""))
|
||||
.setContentText(getTextFromNotification(remoteMessage))
|
||||
.setContentTitle(setNotificationTitle(message, message.numberOfGroupUsers))
|
||||
.setContentText(getTextFromNotification(message))
|
||||
.setAutoCancel(true)
|
||||
.setStyle(new NotificationCompat.BigTextStyle().bigText(getTextFromNotification(remoteMessage)))
|
||||
.setStyle(new NotificationCompat.BigTextStyle().bigText(getTextFromNotification(message)))
|
||||
.setPriority(Notification.PRIORITY_MAX)
|
||||
.setContentIntent(pendingIntent)
|
||||
.setLargeIcon(getCircleBitmap(bitmapToDisplay))
|
||||
@@ -211,6 +205,10 @@ public class HandleMessagesService extends FirebaseMessagingService {
|
||||
}, null, Activity.RESULT_OK, null, null);
|
||||
}
|
||||
|
||||
private void getMessageError(Throwable throwable) {
|
||||
throwable.printStackTrace();
|
||||
}
|
||||
|
||||
private Bitmap getCircleBitmap(Bitmap bitmap) {
|
||||
final Bitmap output = Bitmap.createBitmap(bitmap.getWidth(),
|
||||
bitmap.getHeight(), Bitmap.Config.ARGB_8888);
|
||||
@@ -247,11 +245,11 @@ public class HandleMessagesService extends FirebaseMessagingService {
|
||||
mMessageRealmRepository.update(Collections.singletonList(message), messageByIdSpecification).subscribe();
|
||||
}
|
||||
|
||||
private String setNotificationTitle(Map<String, String> data, int numberOfUsers) {
|
||||
private String setNotificationTitle(Message message, int numberOfUsers) {
|
||||
if (numberOfUsers > 2) {
|
||||
return String.valueOf(data.get(Constants.USERNAME) + " @ " + data.get(Constants.GROUP_NAME));
|
||||
return message.senderName + " @ " + message.groupName;
|
||||
} else {
|
||||
return String.valueOf(data.get(Constants.USERNAME));
|
||||
return message.senderName;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -278,18 +276,18 @@ public class HandleMessagesService extends FirebaseMessagingService {
|
||||
.build();
|
||||
}
|
||||
|
||||
private String getTextFromNotification(JsonObject jsonObject) {
|
||||
String message = null;
|
||||
private String getTextFromNotification(Message message) {
|
||||
String text = null;
|
||||
|
||||
if (!jsonObject.get(Constants.MESSAGE_TEXT).isJsonNull()) {
|
||||
message = jsonObject.get(Constants.MESSAGE_TEXT).getAsString();
|
||||
if(message.message != null) {
|
||||
text = message.message;
|
||||
}
|
||||
|
||||
if (!jsonObject.get(Constants.FILE).isJsonNull() && !jsonObject.get(Constants.FILE).getAsString().equals("")) {
|
||||
message = getString(R.string.chat_file_received);
|
||||
if(!TextUtils.isEmpty(message.originalFilename)) {
|
||||
text = getString(R.string.chat_file_received);
|
||||
}
|
||||
|
||||
return message;
|
||||
return text;
|
||||
}
|
||||
|
||||
public static int getNotificationIcon() {
|
||||
|
||||
@@ -37,6 +37,12 @@ public class Message {
|
||||
@SerializedName("created_at")
|
||||
public long createdAt;
|
||||
|
||||
@SerializedName("group_nb_users")
|
||||
public int numberOfGroupUsers;
|
||||
|
||||
@SerializedName("groupname")
|
||||
public String groupName;
|
||||
|
||||
public Status status;
|
||||
public String uri;
|
||||
public boolean isRead;
|
||||
|
||||
@@ -200,31 +200,36 @@ public class LoginPresenter extends MVPAbstractPresenter<LoginView> implements L
|
||||
return;
|
||||
}
|
||||
|
||||
ErrorThrowable errorThrowable = (ErrorThrowable) throwable;
|
||||
try {
|
||||
ErrorThrowable errorThrowable = (ErrorThrowable) throwable;
|
||||
|
||||
switch(ErrorUtils.getErrorType(throwable)) {
|
||||
case DATA_INPUT:
|
||||
if (errorThrowable.getError().loginFailed != null && errorThrowable.getError().loginFailed.size() > 0) {
|
||||
getView().showError(R.string.error_invalid_login_credentials);
|
||||
return;
|
||||
}
|
||||
case WRONG_CHATCODE:
|
||||
if (errorThrowable.getError().chatCodeFailed != null && errorThrowable.getError().chatCodeFailed.size() > 0) {
|
||||
getView().showError(R.string.error_wrong_chat_code);
|
||||
return;
|
||||
}
|
||||
case DEACTIVATED_CHATCODE:
|
||||
if (errorThrowable.getError().chatCodeInactive != null && errorThrowable.getError().chatCodeInactive.size() > 0) {
|
||||
getView().showError(R.string.error_deactivated_chat_code);
|
||||
return;
|
||||
}
|
||||
case CHATCODE_TOO_SHORT:
|
||||
if (errorThrowable.getError().chatCodeTooShort != null && errorThrowable.getError().chatCodeTooShort.size() > 0) {
|
||||
getView().showError(R.string.error_chat_code_too_short);
|
||||
return;
|
||||
}
|
||||
default:
|
||||
getView().showError(R.string.error_something_went_wrong);
|
||||
switch(ErrorUtils.getErrorType(throwable)) {
|
||||
case DATA_INPUT:
|
||||
if (errorThrowable.getError().loginFailed != null && errorThrowable.getError().loginFailed.size() > 0) {
|
||||
getView().showError(R.string.error_invalid_login_credentials);
|
||||
return;
|
||||
}
|
||||
case WRONG_CHATCODE:
|
||||
if (errorThrowable.getError().chatCodeFailed != null && errorThrowable.getError().chatCodeFailed.size() > 0) {
|
||||
getView().showError(R.string.error_wrong_chat_code);
|
||||
return;
|
||||
}
|
||||
case DEACTIVATED_CHATCODE:
|
||||
if (errorThrowable.getError().chatCodeInactive != null && errorThrowable.getError().chatCodeInactive.size() > 0) {
|
||||
getView().showError(R.string.error_deactivated_chat_code);
|
||||
return;
|
||||
}
|
||||
case CHATCODE_TOO_SHORT:
|
||||
if (errorThrowable.getError().chatCodeTooShort != null && errorThrowable.getError().chatCodeTooShort.size() > 0) {
|
||||
getView().showError(R.string.error_chat_code_too_short);
|
||||
return;
|
||||
}
|
||||
default:
|
||||
getView().showError(R.string.error_something_went_wrong);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
getView().showError(R.string.login_service_type_is_undefined);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -78,7 +78,7 @@
|
||||
android:visibility="gone"
|
||||
custom:donut_finished_color="@color/colorDefault"
|
||||
custom:donut_text_color="@color/colorBlack"
|
||||
tools:visibility="visible"/>
|
||||
/>
|
||||
|
||||
<hani.momanii.supernova_emoji_library.Helper.EmojiconTextView
|
||||
android:id="@+id/chat_item_message"
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
android:paddingRight="40dp"
|
||||
android:layout_marginTop="6dp"
|
||||
android:layout_marginBottom="6dp"
|
||||
android:paddingTop="13dp">
|
||||
>
|
||||
|
||||
<RelativeLayout
|
||||
style="@style/LeftChatItemRelativeLayout"
|
||||
|
||||
Reference in New Issue
Block a user