Commit 039cbe39 authored by Yusuke Iwaki's avatar Yusuke Iwaki

implement "sending..." and resend feature.

parent 0f02b39b
...@@ -6,6 +6,7 @@ import android.support.design.widget.FloatingActionButton; ...@@ -6,6 +6,7 @@ import android.support.design.widget.FloatingActionButton;
import android.support.v4.view.GravityCompat; import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout; import android.support.v4.widget.DrawerLayout;
import android.support.v4.widget.SlidingPaneLayout; import android.support.v4.widget.SlidingPaneLayout;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.view.View; import android.view.View;
...@@ -16,12 +17,14 @@ import chat.rocket.android.helper.LogcatIfError; ...@@ -16,12 +17,14 @@ import chat.rocket.android.helper.LogcatIfError;
import chat.rocket.android.helper.OnBackPressListener; import chat.rocket.android.helper.OnBackPressListener;
import chat.rocket.android.layouthelper.chatroom.MessageComposerManager; import chat.rocket.android.layouthelper.chatroom.MessageComposerManager;
import chat.rocket.android.layouthelper.chatroom.MessageListAdapter; import chat.rocket.android.layouthelper.chatroom.MessageListAdapter;
import chat.rocket.android.layouthelper.chatroom.PairedMessage;
import chat.rocket.android.model.ServerConfig; import chat.rocket.android.model.ServerConfig;
import chat.rocket.android.model.SyncState; import chat.rocket.android.model.SyncState;
import chat.rocket.android.model.ddp.Message; import chat.rocket.android.model.ddp.Message;
import chat.rocket.android.model.ddp.RoomSubscription; import chat.rocket.android.model.ddp.RoomSubscription;
import chat.rocket.android.model.internal.LoadMessageProcedure; import chat.rocket.android.model.internal.LoadMessageProcedure;
import chat.rocket.android.realm_helper.RealmHelper; import chat.rocket.android.realm_helper.RealmHelper;
import chat.rocket.android.realm_helper.RealmModelListAdapter;
import chat.rocket.android.realm_helper.RealmObjectObserver; import chat.rocket.android.realm_helper.RealmObjectObserver;
import chat.rocket.android.realm_helper.RealmStore; import chat.rocket.android.realm_helper.RealmStore;
import chat.rocket.android.service.RocketChatService; import chat.rocket.android.service.RocketChatService;
...@@ -36,7 +39,8 @@ import timber.log.Timber; ...@@ -36,7 +39,8 @@ import timber.log.Timber;
/** /**
* Chat room screen. * Chat room screen.
*/ */
public class RoomFragment extends AbstractChatRoomFragment implements OnBackPressListener { public class RoomFragment extends AbstractChatRoomFragment
implements OnBackPressListener, RealmModelListAdapter.OnItemClickListener<PairedMessage> {
private String serverConfigId; private String serverConfigId;
private RealmHelper realmHelper; private RealmHelper realmHelper;
...@@ -93,12 +97,14 @@ public class RoomFragment extends AbstractChatRoomFragment implements OnBackPres ...@@ -93,12 +97,14 @@ public class RoomFragment extends AbstractChatRoomFragment implements OnBackPres
@Override protected void onSetupView() { @Override protected void onSetupView() {
RecyclerView listView = (RecyclerView) rootView.findViewById(R.id.recyclerview); RecyclerView listView = (RecyclerView) rootView.findViewById(R.id.recyclerview);
listView.setAdapter(realmHelper.createListAdapter(getContext(), MessageListAdapter adapter = (MessageListAdapter) realmHelper.createListAdapter(getContext(),
realm -> realm.where(Message.class) realm -> realm.where(Message.class)
.equalTo("rid", roomId) .equalTo("rid", roomId)
.findAllSorted("ts", Sort.DESCENDING), .findAllSorted("ts", Sort.DESCENDING),
context -> new MessageListAdapter(context, hostname) context -> new MessageListAdapter(context, hostname)
)); );
listView.setAdapter(adapter);
adapter.setOnItemClickListener(this);
LinearLayoutManager layoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager layoutManager = new LinearLayoutManager(getContext(),
LinearLayoutManager.VERTICAL, true); LinearLayoutManager.VERTICAL, true);
...@@ -115,6 +121,32 @@ public class RoomFragment extends AbstractChatRoomFragment implements OnBackPres ...@@ -115,6 +121,32 @@ public class RoomFragment extends AbstractChatRoomFragment implements OnBackPres
setupMessageComposer(); setupMessageComposer();
} }
@Override public void onItemClick(PairedMessage pairedMessage) {
if (pairedMessage.target != null) {
final int syncstate = pairedMessage.target.getSyncstate();
if (syncstate == SyncState.FAILED) {
final String messageId = pairedMessage.target.get_id();
new AlertDialog.Builder(getContext())
.setPositiveButton(R.string.resend, (dialog, which) -> {
realmHelper.executeTransaction(realm ->
realm.createOrUpdateObjectFromJson(Message.class, new JSONObject()
.put("_id", messageId)
.put("syncstate", SyncState.NOT_SYNCED))
).continueWith(new LogcatIfError());
})
.setNegativeButton(android.R.string.cancel, null)
.setNeutralButton(R.string.discard, (dialog, which) -> {
realmHelper.executeTransaction(realm ->
realm.where(Message.class)
.equalTo("_id", messageId).findAll().deleteAllFromRealm()
).continueWith(new LogcatIfError());;
})
.show();
}
}
}
private void setupSideMenu() { private void setupSideMenu() {
View sidemenu = rootView.findViewById(R.id.room_side_menu); View sidemenu = rootView.findViewById(R.id.room_side_menu);
sidemenu.findViewById(R.id.btn_users).setOnClickListener(view -> { sidemenu.findViewById(R.id.btn_users).setOnClickListener(view -> {
......
...@@ -7,6 +7,7 @@ import android.widget.TextView; ...@@ -7,6 +7,7 @@ import android.widget.TextView;
import chat.rocket.android.R; import chat.rocket.android.R;
import chat.rocket.android.helper.DateTime; import chat.rocket.android.helper.DateTime;
import chat.rocket.android.helper.TextUtils; import chat.rocket.android.helper.TextUtils;
import chat.rocket.android.model.SyncState;
import chat.rocket.android.realm_helper.RealmModelViewHolder; import chat.rocket.android.realm_helper.RealmModelViewHolder;
import chat.rocket.android.renderer.MessageRenderer; import chat.rocket.android.renderer.MessageRenderer;
import chat.rocket.android.widget.message.RocketChatMessageLayout; import chat.rocket.android.widget.message.RocketChatMessageLayout;
...@@ -49,6 +50,15 @@ public class MessageViewHolder extends RealmModelViewHolder<PairedMessage> { ...@@ -49,6 +50,15 @@ public class MessageViewHolder extends RealmModelViewHolder<PairedMessage> {
.timestampInto(timestamp) .timestampInto(timestamp)
.bodyInto(body); .bodyInto(body);
if (pairedMessage.target != null) {
int syncstate = pairedMessage.target.getSyncstate();
if (syncstate == SyncState.NOT_SYNCED || syncstate == SyncState.SYNCING) {
itemView.setAlpha(0.6f);
} else {
itemView.setAlpha(1.0f);
}
}
renderNewDayAndSequential(pairedMessage); renderNewDayAndSequential(pairedMessage);
} }
......
...@@ -7,7 +7,7 @@ import chat.rocket.android.model.ddp.Message; ...@@ -7,7 +7,7 @@ import chat.rocket.android.model.ddp.Message;
* View Model for messages in chatroom. * View Model for messages in chatroom.
*/ */
public class PairedMessage { public class PairedMessage {
final Message target; public final Message target;
final Message nextSibling; final Message nextSibling;
public PairedMessage(Message target, Message nextSibling) { public PairedMessage(Message target, Message nextSibling) {
......
...@@ -3,7 +3,9 @@ package chat.rocket.android.renderer; ...@@ -3,7 +3,9 @@ package chat.rocket.android.renderer;
import android.content.Context; import android.content.Context;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import chat.rocket.android.R;
import chat.rocket.android.helper.DateTime; import chat.rocket.android.helper.DateTime;
import chat.rocket.android.model.SyncState;
import chat.rocket.android.model.ddp.Message; import chat.rocket.android.model.ddp.Message;
import chat.rocket.android.widget.message.RocketChatMessageLayout; import chat.rocket.android.widget.message.RocketChatMessageLayout;
...@@ -23,7 +25,14 @@ public class MessageRenderer extends AbstractRenderer<Message> { ...@@ -23,7 +25,14 @@ public class MessageRenderer extends AbstractRenderer<Message> {
* show Avatar image. * show Avatar image.
*/ */
public MessageRenderer avatarInto(ImageView imageView, String hostname) { public MessageRenderer avatarInto(ImageView imageView, String hostname) {
userRenderer.avatarInto(imageView, hostname); switch (object.getSyncstate()) {
case SyncState.FAILED:
imageView.setImageResource(R.drawable.ic_error_outline_black_24dp);
break;
default:
userRenderer.avatarInto(imageView, hostname);
break;
}
return this; return this;
} }
...@@ -43,7 +52,15 @@ public class MessageRenderer extends AbstractRenderer<Message> { ...@@ -43,7 +52,15 @@ public class MessageRenderer extends AbstractRenderer<Message> {
return this; return this;
} }
textView.setText(DateTime.fromEpocMs(object.getTs(), DateTime.Format.TIME)); switch (object.getSyncstate()) {
case SyncState.NOT_SYNCED:
case SyncState.SYNCING:
textView.setText(R.string.sending);
break;
default:
textView.setText(DateTime.fromEpocMs(object.getTs(), DateTime.Format.TIME));
break;
}
return this; return this;
} }
......
<vector android:alpha="0.78" android:height="24dp"
android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M11,15h2v2h-2zM11,7h2v6h-2zM11.99,2C6.47,2 2,6.48 2,12s4.47,10 9.99,10C17.52,22 22,17.52 22,12S17.52,2 11.99,2zM12,20c-4.42,0 -8,-3.58 -8,-8s3.58,-8 8,-8 8,3.58 8,8 -3.58,8 -8,8z"/>
</vector>
...@@ -11,4 +11,7 @@ ...@@ -11,4 +11,7 @@
<string name="start_of_conversation">Start of conversation</string> <string name="start_of_conversation">Start of conversation</string>
<string name="users_of_room_title">Members List</string> <string name="users_of_room_title">Members List</string>
<string name="fmt_room_user_count">Total: %,d users</string> <string name="fmt_room_user_count">Total: %,d users</string>
<string name="sending">Sending...</string>
<string name="resend">Resend</string>
<string name="discard">Discard</string>
</resources> </resources>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment