Commit a21a9ec0 authored by Tiago Cunha's avatar Tiago Cunha

Initial clean up

parent 7418dce9
...@@ -214,11 +214,9 @@ public class RoomFragment extends AbstractChatRoomFragment ...@@ -214,11 +214,9 @@ public class RoomFragment extends AbstractChatRoomFragment
} }
private void setupMessageComposer() { private void setupMessageComposer() {
final FloatingActionButton fabCompose =
(FloatingActionButton) rootView.findViewById(R.id.fab_compose);
final MessageComposer messageComposer = final MessageComposer messageComposer =
(MessageComposer) rootView.findViewById(R.id.message_composer); (MessageComposer) rootView.findViewById(R.id.message_composer);
messageComposerManager = new MessageComposerManager(fabCompose, messageComposer); messageComposerManager = new MessageComposerManager(messageComposer);
messageComposerManager.setSendMessageCallback(messageText -> messageComposerManager.setSendMessageCallback(messageText ->
realmHelper.executeTransaction(realm -> realmHelper.executeTransaction(realm ->
realm.createOrUpdateObjectFromJson(Message.class, new JSONObject() realm.createOrUpdateObjectFromJson(Message.class, new JSONObject()
...@@ -227,23 +225,18 @@ public class RoomFragment extends AbstractChatRoomFragment ...@@ -227,23 +225,18 @@ public class RoomFragment extends AbstractChatRoomFragment
.put("ts", System.currentTimeMillis()) .put("ts", System.currentTimeMillis())
.put("rid", roomId) .put("rid", roomId)
.put("msg", messageText)))); .put("msg", messageText))));
messageComposerManager.setVisibilityChangedListener(shown -> {
FloatingActionButton fab = (FloatingActionButton) rootView.findViewById(R.id.fab_upload_file);
if (shown) {
fab.hide();
} else {
fab.show();
}
});
} }
private void setupFileUploader() { private void setupFileUploader() {
rootView.findViewById(R.id.fab_upload_file).setOnClickListener(view -> { // change this to a more actions chooser
Intent intent = new Intent(); // uses bottom sheet to list options
intent.setType("image/*"); // starts with only file upload (we already have it)
intent.setAction(Intent.ACTION_GET_CONTENT); // rootView.findViewById(R.id.fab_upload_file).setOnClickListener(view -> {
startActivityForResult(Intent.createChooser(intent, "Select Picture to Upload"), RC_UPL); // Intent intent = new Intent();
}); // intent.setType("image/*");
// intent.setAction(Intent.ACTION_GET_CONTENT);
// startActivityForResult(Intent.createChooser(intent, "Select Picture to Upload"), RC_UPL);
// });
} }
@Override @Override
...@@ -366,6 +359,6 @@ public class RoomFragment extends AbstractChatRoomFragment ...@@ -366,6 +359,6 @@ public class RoomFragment extends AbstractChatRoomFragment
@Override @Override
public boolean onBackPressed() { public boolean onBackPressed() {
return closeSideMenuIfNeeded() || messageComposerManager.hideMessageComposerIfNeeded(); return closeSideMenuIfNeeded();
} }
} }
package chat.rocket.android.layouthelper.chatroom; package chat.rocket.android.layouthelper.chatroom;
import android.support.design.widget.FloatingActionButton;
import bolts.Task; import bolts.Task;
import chat.rocket.android.widget.message.MessageComposer; import chat.rocket.android.widget.message.MessageComposer;
...@@ -9,22 +7,15 @@ import chat.rocket.android.widget.message.MessageComposer; ...@@ -9,22 +7,15 @@ import chat.rocket.android.widget.message.MessageComposer;
* handling visibility of FAB-compose and MessageComposer. * handling visibility of FAB-compose and MessageComposer.
*/ */
public class MessageComposerManager { public class MessageComposerManager {
private final FloatingActionButton fabCompose;
private final MessageComposer messageComposer; private final MessageComposer messageComposer;
private SendMessageCallback sendMessageCallback; private SendMessageCallback sendMessageCallback;
private VisibilityChangedListener visibilityChangedListener;
public MessageComposerManager(FloatingActionButton fabCompose, MessageComposer messageComposer) { public MessageComposerManager(MessageComposer messageComposer) {
this.fabCompose = fabCompose;
this.messageComposer = messageComposer; this.messageComposer = messageComposer;
init(); init();
} }
private void init() { private void init() {
fabCompose.setOnClickListener(view -> {
setMessageComposerVisibility(true);
});
messageComposer.setOnActionListener(new MessageComposer.ActionListener() { messageComposer.setOnActionListener(new MessageComposer.ActionListener() {
@Override @Override
public void onSubmit(String message) { public void onSubmit(String message) {
...@@ -42,56 +33,19 @@ public class MessageComposerManager { ...@@ -42,56 +33,19 @@ public class MessageComposerManager {
@Override @Override
public void onCancel() { public void onCancel() {
setMessageComposerVisibility(false);
} }
}); });
setMessageComposerVisibility(false);
} }
public void setSendMessageCallback(SendMessageCallback sendMessageCallback) { public void setSendMessageCallback(SendMessageCallback sendMessageCallback) {
this.sendMessageCallback = sendMessageCallback; this.sendMessageCallback = sendMessageCallback;
} }
public void setVisibilityChangedListener(VisibilityChangedListener listener) {
this.visibilityChangedListener = listener;
}
public void clearComposingText() { public void clearComposingText() {
messageComposer.setText(""); messageComposer.setText("");
} }
private void setMessageComposerVisibility(boolean show) {
if (show) {
fabCompose.hide();
messageComposer.show(() -> {
if (visibilityChangedListener != null) {
visibilityChangedListener.onVisibilityChanged(true);
}
});
} else {
messageComposer.hide(() -> {
fabCompose.show();
if (visibilityChangedListener != null) {
visibilityChangedListener.onVisibilityChanged(false);
}
});
}
}
public boolean hideMessageComposerIfNeeded() {
if (messageComposer.isShown()) {
setMessageComposerVisibility(false);
return true;
}
return false;
}
public interface SendMessageCallback { public interface SendMessageCallback {
Task<Void> onSubmit(String messageText); Task<Void> onSubmit(String messageText);
} }
public interface VisibilityChangedListener {
void onVisibilityChanged(boolean shown);
}
} }
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M16.5,6v11.5c0,2.21 -1.79,4 -4,4s-4,-1.79 -4,-4V5c0,-1.38 1.12,-2.5 2.5,-2.5s2.5,1.12 2.5,2.5v10.5c0,0.55 -0.45,1 -1,1s-1,-0.45 -1,-1V6H10v9.5c0,1.38 1.12,2.5 2.5,2.5s2.5,-1.12 2.5,-2.5V5c0,-2.21 -1.79,-4 -4,-4S7,2.79 7,5v12.5c0,3.04 2.46,5.5 5.5,5.5s5.5,-2.46 5.5,-5.5V6h-1.5z"/>
</vector>
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<FrameLayout <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent">
>
<android.support.v7.widget.RecyclerView <android.support.v7.widget.RecyclerView
android:id="@+id/recyclerview" android:id="@+id/recyclerview"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent" />
/>
<chat.rocket.android.widget.message.MessageComposer <chat.rocket.android.widget.message.MessageComposer
android:id="@+id/message_composer" android:id="@+id/message_composer"
...@@ -18,25 +14,5 @@ ...@@ -18,25 +14,5 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:theme="@style/Theme.AppCompat.Light" android:theme="@style/Theme.AppCompat.Light"
android:layout_gravity="bottom" android:layout_gravity="bottom"
android:background="@android:color/white" android:background="@android:color/white" />
/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab_upload_file"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start|bottom"
android:layout_margin="@dimen/margin_16"
app:fabSize="mini"
app:srcCompat="@drawable/ic_insert_photo_white_24dp"
/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab_compose"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_margin="@dimen/margin_16"
app:srcCompat="@drawable/ic_compose_white_24dp"
/>
</FrameLayout> </FrameLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical" android:orientation="vertical">
>
<chat.rocket.android.widget.DividerView <chat.rocket.android.widget.DividerView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content" />
/>
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="horizontal" android:orientation="horizontal">
>
<EditText <EditText
android:id="@+id/editor" android:id="@+id/editor"
android:layout_width="0px" android:layout_width="0px"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
android:maxLines="3" android:maxLines="3" />
/>
<ImageButton <ImageButton
android:id="@+id/btn_submit" android:id="@+id/btn_submit"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
app:srcCompat="@drawable/ic_send_black_24dp" app:srcCompat="@drawable/ic_send_black_24dp" />
/>
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>
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