Skip to content

Commit 960a7af

Browse files
committed
UI clean-up
1 parent d0c621a commit 960a7af

File tree

10 files changed

+234
-136
lines changed

10 files changed

+234
-136
lines changed

app/src/main/java/com/firebase/uidemo/RecyclerViewDemoActivity.java

Lines changed: 81 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
11
package com.firebase.uidemo;
22

3+
import android.graphics.Color;
4+
import android.graphics.drawable.Drawable;
5+
import android.graphics.drawable.GradientDrawable;
6+
import android.graphics.drawable.LayerDrawable;
7+
import android.graphics.drawable.ShapeDrawable;
8+
import android.graphics.drawable.shapes.Shape;
39
import android.os.Bundle;
410
import android.support.v7.widget.LinearLayoutManager;
511
import android.support.v7.widget.RecyclerView;
612
import android.util.Log;
13+
import android.view.Gravity;
714
import android.view.Menu;
815
import android.view.MenuInflater;
916
import android.view.MenuItem;
1017
import android.view.View;
1118
import android.widget.Button;
1219
import android.widget.EditText;
20+
import android.widget.FrameLayout;
21+
import android.widget.LinearLayout;
1322
import android.widget.TextView;
1423

1524
import com.firebase.client.AuthData;
@@ -23,12 +32,15 @@ public class RecyclerViewDemoActivity extends FirebaseLoginBaseActivity {
2332

2433
public static String TAG = "FirebaseUI.chat";
2534
private Firebase mRef;
35+
private Query mChatRef;
2636
private AuthData mAuthData;
2737
private String name;
2838
private String uid;
2939
private Button mSendButton;
3040
private EditText mMessageEdit;
3141

42+
private RecyclerView mMessages;
43+
3244
@Override
3345
protected void onCreate(Bundle savedInstanceState) {
3446
super.onCreate(savedInstanceState);
@@ -38,58 +50,55 @@ protected void onCreate(Bundle savedInstanceState) {
3850
mMessageEdit = (EditText) findViewById(R.id.messageEdit);
3951

4052
mRef = new Firebase("https://firebaseui.firebaseio.com/chat_3");
53+
mChatRef = mRef.limitToLast(50);
4154

4255
mSendButton.setOnClickListener(new View.OnClickListener() {
4356
@Override
4457
public void onClick(View v) {
45-
Chat chat = new Chat(name, mAuthData.getUid(), mMessageEdit.getText().toString());
46-
mRef.push().setValue(chat, new Firebase.CompletionListener() {
47-
@Override
48-
public void onComplete(FirebaseError firebaseError, Firebase firebase) {
49-
if (firebaseError != null) {
50-
Log.e(TAG, firebaseError.toString());
51-
}
58+
Chat chat = new Chat(name, mAuthData.getUid(), mMessageEdit.getText().toString());
59+
mRef.push().setValue(chat, new Firebase.CompletionListener() {
60+
@Override
61+
public void onComplete(FirebaseError firebaseError, Firebase firebase) {
62+
if (firebaseError != null) {
63+
Log.e(TAG, firebaseError.toString());
5264
}
53-
});
54-
mMessageEdit.setText("");
65+
}
66+
});
67+
mMessageEdit.setText("");
5568
}
5669
});
5770

58-
updateChat();
59-
}
60-
61-
protected void updateChat() {
62-
final RecyclerView messages = (RecyclerView) findViewById(R.id.messagesList);
71+
mMessages = (RecyclerView) findViewById(R.id.messagesList);
6372

6473
LinearLayoutManager manager = new LinearLayoutManager(this);
6574
manager.setStackFromEnd(true);
6675

67-
messages.setHasFixedSize(true);
68-
messages.setLayoutManager(manager);
76+
mMessages.setHasFixedSize(true);
77+
mMessages.setLayoutManager(manager);
78+
6979

70-
Query recentMessages = mRef.limitToLast(50);
71-
FirebaseRecyclerViewAdapter<Chat, ChatHolder> adapter = new FirebaseRecyclerViewAdapter<Chat, ChatHolder>(Chat.class, R.layout.incoming_message, ChatHolder.class, recentMessages) {
80+
updateChat();
81+
}
82+
83+
protected void updateChat() {
84+
FirebaseRecyclerViewAdapter<Chat, ChatHolder> adapter = new FirebaseRecyclerViewAdapter<Chat, ChatHolder>(Chat.class, R.layout.message, ChatHolder.class, mChatRef) {
7285
@Override
7386
public void populateViewHolder(ChatHolder chatView, Chat chat) {
74-
chatView.textView.setText(chat.getText());
75-
// chatView.textView.setPadding(30, 30, 30, 0);
76-
chatView.nameView.setText(chat.getName());
77-
// chatView.nameView.setPadding(30, 0, 30, 30);
78-
// chatView.textView.setTextColor(Color.parseColor("#000000"));
79-
// chatView.textView.setTypeface(null, Typeface.NORMAL);
87+
88+
chatView.setName(chat.getName());
89+
chatView.setText(chat.getText());
90+
8091
if (mAuthData != null && chat.getUid().equals(mAuthData.getUid())) {
81-
// chatView.textView.setGravity(Gravity.END);
82-
// chatView.nameView.setGravity(Gravity.END);
83-
// chatView.nameView.setTextColor(Color.parseColor("#AAAAAA"));
84-
// chatView.itemView.setBackground(getDrawable(R.drawable.outgoing_message));
92+
// Is me
93+
chatView.setSender(true);
8594
} else {
86-
// chatView.nameView.setTextColor(Color.parseColor("#00BCD4"));
87-
// chatView.itemView.setBackground(getDrawable(R.drawable.incoming_message));
95+
chatView.setSender(false);
96+
// Isn't me
8897
}
8998
}
9099
};
91100

92-
messages.setAdapter(adapter);
101+
mMessages.setAdapter(adapter);
93102
}
94103

95104
@Override
@@ -122,10 +131,6 @@ public boolean onOptionsItemSelected(MenuItem item) {
122131
return super.onOptionsItemSelected(item);
123132
}
124133

125-
126-
127-
// Start of FirebaseLoginBaseActivity
128-
129134
@Override
130135
public void onFirebaseLoginSuccess(AuthData authData) {
131136
Log.i(TAG, "Logged in to " + authData.getProvider().toString());
@@ -168,8 +173,6 @@ public Firebase getFirebaseRef() {
168173
return mRef;
169174
}
170175

171-
// End of FirebaseLoginBaseActivity
172-
173176
public static class Chat {
174177
String name;
175178
String text;
@@ -198,14 +201,50 @@ public String getText() {
198201
}
199202

200203
public static class ChatHolder extends RecyclerView.ViewHolder {
201-
TextView nameView, textView;
202-
View itemView;
204+
View mView;
203205

204206
public ChatHolder(View itemView) {
205207
super(itemView);
206-
this.itemView = itemView;
207-
nameView = (TextView) itemView.findViewById(R.id.name_text);
208-
textView = (TextView) itemView.findViewById(R.id.message_text);
208+
mView = itemView;
209+
}
210+
211+
public void setSender(Boolean isSender) {
212+
FrameLayout arrow;
213+
214+
if (isSender) {
215+
arrow = (FrameLayout) mView.findViewById(R.id.left_arrow);
216+
} else {
217+
arrow = (FrameLayout) mView.findViewById(R.id.right_arrow);
218+
219+
View messageBox = mView.findViewById(R.id.message);
220+
View messageArrow = mView.findViewById(R.id.left_arrow);
221+
222+
// LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams();
223+
// lp.gravity= Gravity.RIGHT;
224+
// mView.setLayoutParams(lp);
225+
226+
227+
228+
229+
230+
//GradientDrawable messageBoxBackground= (GradientDrawable) (messageBox.getBackground());
231+
//messageBoxBackground.setColor(Color.MAGENTA);
232+
//GradientDrawable messageArrowBackground = (GradientDrawable) (messageArrow.getBackground());
233+
//messageArrowBackground.setColor(Color.MAGENTA);
234+
235+
}
236+
237+
arrow.setVisibility(View.GONE);
238+
}
239+
240+
public void setName(String name) {
241+
TextView field = (TextView) mView.findViewById(R.id.name_text);
242+
field.setText(name);
243+
}
244+
245+
public void setText(String text) {
246+
TextView field = (TextView) mView.findViewById(R.id.message_text);
247+
field.setText(text);
209248
}
210249
}
211250
}
Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
3-
<item >
4-
<rotate
5-
android:fromDegrees="45"
6-
android:toDegrees="45"
7-
android:pivotX="-40%"
8-
android:pivotY="87%" >
9-
<shape
10-
android:shape="rectangle" >
11-
<stroke android:color="@android:color/transparent" android:width="10dp"/>
12-
<solid
13-
android:color="#BEE1ED" />
14-
</shape>
15-
</rotate>
16-
</item>
17-
</layer-list>
2+
<rotate
3+
xmlns:android="http://schemas.android.com/apk/res/android"
4+
android:fromDegrees="45"
5+
android:toDegrees="45"
6+
android:pivotX="-40%"
7+
android:pivotY="87%" >
8+
<shape
9+
android:shape="rectangle" >
10+
<stroke android:color="@android:color/transparent" android:width="10dp"/>
11+
<solid
12+
android:color="#BEE1ED" />
13+
</shape>
14+
</rotate>
Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
3-
<item>
4-
<shape android:shape="rectangle">
5-
<corners android:radius="4dp" android:topLeftRadius="0dp"/>
6-
<solid android:color="#BEE1ED" />
7-
</shape>
8-
</item>
9-
</layer-list>
2+
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
3+
<corners android:radius="4dp"/>
4+
<solid android:color="#BEE1ED" />
5+
</shape>

app/src/main/res/drawable/incoming_message.xml

Lines changed: 0 additions & 10 deletions
This file was deleted.

app/src/main/res/drawable/outgoing_message.xml

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
33
android:layout_height="wrap_content"
4-
android:layout_width="match_parent">
4+
android:layout_width="match_parent"
5+
android:gravity="right">
56

6-
<ImageView
7-
android:layout_width="38dp"
8-
android:layout_height="38dp"
9-
android:id="@+id/profile_image"
10-
android:scaleType="fitXY"/>
11-
12-
<RelativeLayout
13-
android:id="@+id/arrow"
7+
<FrameLayout
8+
android:id="@+id/left_arrow"
149
android:layout_width="50dp"
1510
android:layout_height="50dp"
1611
android:background="@drawable/chat_message_arrow"
1712
android:rotation="180"
18-
android:layout_marginLeft="6dp"/>
13+
android:layout_marginLeft="2dp"/>
14+
1915

2016
<LinearLayout
2117
android:layout_height="match_parent"
@@ -28,12 +24,6 @@
2824
android:layout_marginRight="26dp"
2925
android:layout_marginBottom="10dp">
3026

31-
<!--<TextView android:id="@+id/text1"-->
32-
<!--android:textStyle="bold"-->
33-
<!--android:layout_width="fill_parent"-->
34-
<!--android:layout_height="0dp"-->
35-
<!--android:layout_weight="1"/>-->
36-
3727
<TextView android:id="@+id/message_text"
3828
android:layout_width="fill_parent"
3929
android:layout_height="0dp"
@@ -47,4 +37,15 @@
4737
android:layout_weight="1" />
4838
</LinearLayout>
4939

40+
<FrameLayout
41+
android:id="@+id/right_arrow"
42+
android:layout_width="50dp"
43+
android:layout_height="50dp"
44+
android:background="@drawable/chat_message_arrow"
45+
android:rotation="180"
46+
android:layout_alignParentTop="true"
47+
android:layout_alignRight="@+id/message"
48+
android:layout_alignEnd="@+id/message"
49+
android:layout_marginRight="-25dp"/>
50+
5051
</RelativeLayout>

app/src/main/res/values/strings.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<resources>
22
<string name="app_name">FirebaseUI Chat</string>
33
<!-- FirebaseUI Configuration -->
4-
<string name="facebook_app_id">547033782072218</string>
5-
<string name="twitter_app_key">mbX13kp9wqi3JzmwXwATvciAZ</string>
6-
<string name="twitter_app_secret">8QObfaBn0YxzvZ0RiyoW8BUL8o3LBSfeElRHPR5ppvkFRqEMTq</string>
4+
<string name="facebook_app_id"></string>
5+
<string name="twitter_app_key"></string>
6+
<string name="twitter_app_secret"></string>
77
</resources>

0 commit comments

Comments
 (0)