Commit a21a9ec0 authored by Tiago Cunha's avatar Tiago Cunha

Initial clean up

parent 7418dce9
......@@ -214,11 +214,9 @@ public class RoomFragment extends AbstractChatRoomFragment
}
private void setupMessageComposer() {
final FloatingActionButton fabCompose =
(FloatingActionButton) rootView.findViewById(R.id.fab_compose);
final MessageComposer messageComposer =
(MessageComposer) rootView.findViewById(R.id.message_composer);
messageComposerManager = new MessageComposerManager(fabCompose, messageComposer);
messageComposerManager = new MessageComposerManager(messageComposer);
messageComposerManager.setSendMessageCallback(messageText ->
realmHelper.executeTransaction(realm ->
realm.createOrUpdateObjectFromJson(Message.class, new JSONObject()
......@@ -227,23 +225,18 @@ public class RoomFragment extends AbstractChatRoomFragment
.put("ts", System.currentTimeMillis())
.put("rid", roomId)
.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() {
rootView.findViewById(R.id.fab_upload_file).setOnClickListener(view -> {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture to Upload"), RC_UPL);
});
// change this to a more actions chooser
// uses bottom sheet to list options
// starts with only file upload (we already have it)
// rootView.findViewById(R.id.fab_upload_file).setOnClickListener(view -> {
// Intent intent = new Intent();
// intent.setType("image/*");
// intent.setAction(Intent.ACTION_GET_CONTENT);
// startActivityForResult(Intent.createChooser(intent, "Select Picture to Upload"), RC_UPL);
// });
}
@Override
......@@ -366,6 +359,6 @@ public class RoomFragment extends AbstractChatRoomFragment
@Override
public boolean onBackPressed() {
return closeSideMenuIfNeeded() || messageComposerManager.hideMessageComposerIfNeeded();
return closeSideMenuIfNeeded();
}
}
package chat.rocket.android.layouthelper.chatroom;
import android.support.design.widget.FloatingActionButton;
import bolts.Task;
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.
*/
public class MessageComposerManager {
private final FloatingActionButton fabCompose;
private final MessageComposer messageComposer;
private SendMessageCallback sendMessageCallback;
private VisibilityChangedListener visibilityChangedListener;
public MessageComposerManager(FloatingActionButton fabCompose, MessageComposer messageComposer) {
this.fabCompose = fabCompose;
public MessageComposerManager(MessageComposer messageComposer) {
this.messageComposer = messageComposer;
init();
}
private void init() {
fabCompose.setOnClickListener(view -> {
setMessageComposerVisibility(true);
});
messageComposer.setOnActionListener(new MessageComposer.ActionListener() {
@Override
public void onSubmit(String message) {
......@@ -42,56 +33,19 @@ public class MessageComposerManager {
@Override
public void onCancel() {
setMessageComposerVisibility(false);
}
});
setMessageComposerVisibility(false);
}
public void setSendMessageCallback(SendMessageCallback sendMessageCallback) {
this.sendMessageCallback = sendMessageCallback;
}
public void setVisibilityChangedListener(VisibilityChangedListener listener) {
this.visibilityChangedListener = listener;
}
public void clearComposingText() {
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 {
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"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
android:layout_height="match_parent" />
<chat.rocket.android.widget.message.MessageComposer
android:id="@+id/message_composer"
......@@ -18,25 +14,5 @@
android:layout_height="wrap_content"
android:theme="@style/Theme.AppCompat.Light"
android:layout_gravity="bottom"
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"
/>
android:background="@android:color/white" />
</FrameLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout 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_height="match_parent"
android:orientation="vertical"
>
android:orientation="vertical">
<chat.rocket.android.widget.DividerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
android:layout_height="wrap_content" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
android:orientation="horizontal">
<EditText
android:id="@+id/editor"
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_weight="1"
android:maxLines="3"
/>
android:maxLines="3" />
<ImageButton
android:id="@+id/btn_submit"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
app:srcCompat="@drawable/ic_send_black_24dp"
/>
app:srcCompat="@drawable/ic_send_black_24dp" />
</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