Skip to content

Commit ae25e06

Browse files
committed
change colors of owner and host
1 parent 7ab8351 commit ae25e06

20 files changed

+187
-173
lines changed

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/src/main/AndroidManifest.xml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
android:label="@string/app_name"
1616
android:roundIcon="@mipmap/ic_launcher_round"
1717
android:supportsRtl="true"
18-
android:theme="@style/AppTheme.NoAppBar">
18+
android:theme="@style/AppTheme">
1919

2020
<!--
2121
The API key for Google Maps-based APIs is defined as a string resource.
@@ -35,14 +35,16 @@
3535
android:theme="@style/AppTheme.TransparentStatusBar"/>
3636
<activity android:name=".main.ui.MainActivity"/>
3737
<activity android:name=".party.ui.PartyActivity" />
38-
<activity android:name=".login.ui.LoginActivity">
38+
<activity android:name=".login.ui.LoginActivity"
39+
android:theme="@style/AppTheme.NoAppBar">
3940
<intent-filter>
4041
<action android:name="android.intent.action.MAIN" />
4142

4243
<category android:name="android.intent.category.LAUNCHER" />
4344
</intent-filter>
4445
</activity>
45-
<activity android:name=".quickstart.ui.QuickStartActivity"/>
46+
<activity android:name=".quickstart.ui.QuickStartActivity"
47+
android:theme="@style/AppTheme.NoAppBar"/>
4648
</application>
4749

4850
</manifest>

app/src/main/java/com/annguyen/android/parti/main/ui/MainActivity.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ public class MainActivity extends AppCompatActivity implements MainView {
4343
private static final int PERMISSIONS_REQUEST_ACCESS_FINE_LOCATION = 1808;
4444
public static final int REQUEST_MAP_PICK = 1401;
4545

46-
@BindView(R.id.main_toolbar)
47-
Toolbar mainToolbar;
4846
@BindView(R.id.profile_avatar)
4947
ImageView profileAvatar;
5048
@BindView(R.id.edit_group_message)
@@ -71,7 +69,6 @@ protected void onCreate(Bundle savedInstanceState) {
7169
ButterKnife.bind(this);
7270
initInjection();
7371
presenter.start();
74-
setSupportActionBar(mainToolbar);
7572

7673
//check for location permission first then get current location
7774
getLocation();

app/src/main/java/com/annguyen/android/parti/party/PartyModelImpl.java

Lines changed: 27 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@
1717

1818
import org.greenrobot.eventbus.EventBus;
1919

20-
import java.util.ArrayList;
2120
import java.util.HashMap;
22-
import java.util.List;
2321
import java.util.Map;
2422

2523
/**
@@ -31,14 +29,12 @@ public class PartyModelImpl implements PartyModel {
3129
private String currentPartyKey;
3230
private String currentUserName;
3331
private String currentUserId;
32+
private String currentHostId;
3433

3534
private ChildEventListener membersListener;
3635
private ChildEventListener messagesListener;
3736
private ChildEventListener partiesListener;
3837

39-
// private List<Message> tmpMessageList;
40-
// private List<User> tmpUserList;
41-
4238
EventBus eventBus;
4339
private FirebaseAuth auth;
4440
private DatabaseReference dataRef;
@@ -47,8 +43,6 @@ public PartyModelImpl() {
4743
eventBus = EventBus.getDefault();
4844
auth = FirebaseAuth.getInstance();
4945
dataRef = FirebaseDatabase.getInstance().getReference();
50-
// tmpMessageList = new ArrayList<>();
51-
// tmpUserList = new ArrayList<>();
5246
}
5347

5448
@Override
@@ -65,7 +59,7 @@ public void onDataChange(DataSnapshot dataSnapshot) {
6559
String userName = (String) dataSnapshot.getValue();
6660
if (userName != null) {
6761
currentUserName = userName;
68-
participateWithName();
62+
getHostId();
6963
}
7064
else {
7165
eventBus.post(new PartyEvent(PartyEvent.REQUEST_USER_NAME_FAIL));
@@ -79,6 +73,28 @@ public void onCancelled(DatabaseError databaseError) {
7973
});
8074
}
8175

76+
private void getHostId() {
77+
dataRef.child("parties").child(currentPartyKey).child("host")
78+
.addListenerForSingleValueEvent(new ValueEventListener() {
79+
@Override
80+
public void onDataChange(DataSnapshot dataSnapshot) {
81+
String hostId = (String) dataSnapshot.getValue();
82+
if (hostId != null) {
83+
currentHostId = hostId;
84+
participateWithName();
85+
}
86+
else {
87+
eventBus.post(new PartyEvent(PartyEvent.REQUEST_HOST_ID_FAIL));
88+
}
89+
}
90+
91+
@Override
92+
public void onCancelled(DatabaseError databaseError) {
93+
eventBus.post(new PartyEvent(PartyEvent.REQUEST_HOST_ID_FAIL));
94+
}
95+
});
96+
}
97+
8298
private void participateWithName() {
8399
dataRef.child("members").child(currentPartyKey).child(currentUserId)
84100
.setValue(currentUserName)
@@ -89,7 +105,8 @@ public void onComplete(@NonNull Task<Void> task) {
89105
listenToMembers();
90106
listenToMessages();
91107
listenToPartyRemoval();
92-
eventBus.post(new PartyEvent(PartyEvent.FINISH_PARTICIPATE, currentUserId));
108+
eventBus.post(new PartyEvent(PartyEvent.FINISH_PARTICIPATE,
109+
currentUserId, currentHostId));
93110
}
94111
else {
95112
eventBus.post(new PartyEvent(PartyEvent.PARTICIPATE_FAIL));
@@ -98,47 +115,6 @@ public void onComplete(@NonNull Task<Void> task) {
98115
});
99116
}
100117

101-
// private void getMemberList() {
102-
// dataRef.child("members").child(currentPartyKey)
103-
// .addListenerForSingleValueEvent(new ValueEventListener() {
104-
// @Override
105-
// public void onDataChange(DataSnapshot dataSnapshot) {
106-
// for (DataSnapshot member : dataSnapshot.getChildren()) {
107-
// User memUser = new User((String) member.getValue());
108-
// memUser.setKey(member.getKey());
109-
// tmpUserList.add(memUser);
110-
// }
111-
// getMessageList();
112-
// }
113-
//
114-
// @Override
115-
// public void onCancelled(DatabaseError databaseError) {
116-
// eventBus.post(new PartyEvent(PartyEvent.GET_MEMBERS_FAIL));
117-
// }
118-
// });
119-
// }
120-
//
121-
// private void getMessageList() {
122-
// dataRef.child("messages").child(currentPartyKey)
123-
// .addListenerForSingleValueEvent(new ValueEventListener() {
124-
// @Override
125-
// public void onDataChange(DataSnapshot dataSnapshot) {
126-
// for (DataSnapshot msgSnap : dataSnapshot.getChildren()) {
127-
// Message message = msgSnap.getValue(Message.class);
128-
// if (message != null) {
129-
// message.setMsgKey(msgSnap.getKey());
130-
// }
131-
// tmpMessageList.add(message);
132-
// }
133-
// }
134-
//
135-
// @Override
136-
// public void onCancelled(DatabaseError databaseError) {
137-
// eventBus.post(new PartyEvent(PartyEvent.GET_MESSAGES_FAIL));
138-
// }
139-
// });
140-
// }
141-
142118
@Override
143119
public void sendMsg(String msg) {
144120
Message message = new Message(currentUserId, currentUserName, msg);
@@ -281,7 +257,7 @@ public void onChildRemoved(DataSnapshot dataSnapshot) {
281257
stopListenToMembers();
282258
stopListenToMessages();
283259
stopListenToPartyRemoval();
284-
eventBus.post(new PartyEvent(PartyEvent.PARTY_REMOVE));
260+
eventBus.post(new PartyEvent(PartyEvent.PARTY_REMOVED));
285261
}
286262
}
287263

app/src/main/java/com/annguyen/android/parti/party/PartyPresenterImpl.java

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public void stop() {
4242

4343
@Override
4444
public void sendMsg(String msg) {
45+
partyView.clearMsgInput();
4546
partyModel.sendMsg(msg);
4647
}
4748

@@ -55,20 +56,9 @@ void onPartyEvent(PartyEvent partyEvent) {
5556
switch (partyEvent.getEventCode()) {
5657
case PartyEvent.FINISH_PARTICIPATE: {
5758
partyView.setCurrentUserId(partyEvent.getUserKey());
59+
partyView.setHostId(partyEvent.getHostKey());
5860
partyView.hideProgressBar();
5961
partyView.showInput();
60-
// partyView.injectMembers(partyEvent.getUserList());
61-
// partyView.injectMessages(partyEvent.getMessageList());
62-
break;
63-
}
64-
case PartyEvent.GET_MEMBERS_FAIL: {
65-
break;
66-
}
67-
case PartyEvent.GET_MESSAGES_FAIL: {
68-
break;
69-
}
70-
case PartyEvent.HOST_LEAVE_SUCCESS: {
71-
partyView.goToMain();
7262
break;
7363
}
7464
case PartyEvent.NEW_MEMBER: {
@@ -79,22 +69,28 @@ void onPartyEvent(PartyEvent partyEvent) {
7969
partyView.addNewMessage(partyEvent.getNewMessage());
8070
break;
8171
}
82-
case PartyEvent.PARTICIPATE_FAIL: {
72+
case PartyEvent.USER_REMOVED: {
73+
partyView.removeMember(partyEvent.getUserKey());
8374
break;
8475
}
85-
case PartyEvent.PARTY_REMOVE: {
76+
case PartyEvent.PARTY_REMOVED: {
8677
partyView.goToMain();
8778
break;
8879
}
89-
case PartyEvent.REQUEST_USER_NAME_FAIL: {
80+
case PartyEvent.USER_LEAVE_SUCCESS: {
81+
partyView.goToMain();
9082
break;
9183
}
92-
case PartyEvent.USER_LEAVE_SUCCESS: {
84+
case PartyEvent.HOST_LEAVE_SUCCESS: {
9385
partyView.goToMain();
94-
86+
break;
9587
}
96-
case PartyEvent.USER_REMOVED: {
97-
partyView.removeMember(partyEvent.getUserKey());
88+
case PartyEvent.REQUEST_USER_NAME_FAIL: {
89+
partyView.goToMain();
90+
break;
91+
}
92+
case PartyEvent.PARTICIPATE_FAIL: {
93+
partyView.goToMain();
9894
break;
9995
}
10096
}

app/src/main/java/com/annguyen/android/parti/party/adapters/MemberListAdapter.java

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.annguyen.android.parti.party.adapters;
22

3+
import android.content.Context;
4+
import android.support.v7.content.res.AppCompatResources;
35
import android.support.v7.widget.CardView;
46
import android.support.v7.widget.RecyclerView;
57
import android.view.LayoutInflater;
@@ -22,14 +24,20 @@
2224

2325
public class MemberListAdapter extends RecyclerView.Adapter<MemberListAdapter.CustomViewHolder>{
2426

25-
List<User> userList;
27+
private String hostKey;
28+
private String userKey;
29+
private List<User> userList;
30+
private Context context;
2631

2732
public MemberListAdapter() {
2833
userList = new ArrayList<>();
2934
}
3035

3136
@Override
3237
public CustomViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
38+
39+
context = parent.getContext();
40+
3341
View memberListView = LayoutInflater.from(parent.getContext())
3442
.inflate(R.layout.member_bubble, parent, false);
3543

@@ -38,8 +46,22 @@ public CustomViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
3846

3947
@Override
4048
public void onBindViewHolder(CustomViewHolder holder, int position) {
41-
String userName = userList.get(position).getName();
42-
holder.memberName.setText(userName);
49+
User user = userList.get(position);
50+
holder.memberName.setText(user.getName());
51+
52+
if (user.getKey().equals(userKey)) {
53+
holder.memberContainer.setBackgroundTintList(
54+
AppCompatResources.getColorStateList(context, R.color.bubble_owner_color));
55+
holder.memberName.setTextColor(
56+
AppCompatResources.getColorStateList(context, R.color.text_owner_color));
57+
}
58+
59+
if (user.getKey().equals(hostKey)) {
60+
holder.memberContainer.setBackgroundTintList(
61+
AppCompatResources.getColorStateList(context, R.color.bubble_host_color));
62+
holder.memberName.setTextColor(
63+
AppCompatResources.getColorStateList(context, R.color.text_host_color));
64+
}
4365
}
4466

4567
@Override
@@ -79,4 +101,12 @@ public CustomViewHolder(View itemView) {
79101
ButterKnife.bind(this, itemView);
80102
}
81103
}
104+
105+
public void setHostKey(String hostKey) {
106+
this.hostKey = hostKey;
107+
}
108+
109+
public void setUserKey(String userKey) {
110+
this.userKey = userKey;
111+
}
82112
}

0 commit comments

Comments
 (0)