Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

<!-- Chat demo -->
<activity
android:name=".ChatActivity"
android:name=".database.ChatActivity"
android:label="@string/name_chat" />

<!-- Auth UI demo -->
Expand All @@ -33,4 +33,4 @@
android:label="@string/name_auth_ui" />
</application>

</manifest>
</manifest>
1 change: 1 addition & 0 deletions app/src/main/java/com/firebase/uidemo/ChooserActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import android.widget.TextView;

import com.firebase.uidemo.auth.AuthUiActivity;
import com.firebase.uidemo.database.ChatActivity;

import butterknife.BindView;
import butterknife.ButterKnife;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* limitations under the License.
*/

package com.firebase.uidemo;
package com.firebase.uidemo.database;

import android.graphics.PorterDuff;
import android.graphics.drawable.GradientDrawable;
Expand All @@ -35,6 +35,7 @@
import android.widget.Toast;

import com.firebase.ui.database.FirebaseRecyclerAdapter;
import com.firebase.uidemo.R;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
Expand All @@ -45,7 +46,7 @@
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.Query;

public class ChatActivity extends AppCompatActivity {
public class ChatActivity extends AppCompatActivity implements FirebaseAuth.AuthStateListener {

public static final String TAG = "RecyclerViewDemo";

Expand All @@ -65,12 +66,7 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_chat);

mAuth = FirebaseAuth.getInstance();
mAuth.addAuthStateListener(new FirebaseAuth.AuthStateListener() {
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
updateUI();
}
});
mAuth.addAuthStateListener(this);

mSendButton = (Button) findViewById(R.id.sendButton);
mMessageEdit = (EditText) findViewById(R.id.messageEdit);
Expand Down Expand Up @@ -129,6 +125,19 @@ public void onStop() {
}
}

@Override
public void onDestroy() {
super.onDestroy();
if (mAuth != null) {
mAuth.removeAuthStateListener(this);
}
}

@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
updateUI();
}

private void attachRecyclerViewAdapter() {
Query lastFifty = mChatRef.limitToLast(50);
mRecyclerViewAdapter = new FirebaseRecyclerAdapter<Chat, ChatHolder>(
Expand Down Expand Up @@ -236,13 +245,13 @@ public void setIsSender(Boolean isSender) {

left_arrow.setVisibility(View.GONE);
right_arrow.setVisibility(View.VISIBLE);
messageContainer.setGravity(Gravity.RIGHT);
messageContainer.setGravity(Gravity.END);
} else {
color = ContextCompat.getColor(mView.getContext(), R.color.material_grey_300);
color = ContextCompat.getColor(mView.getContext(), R.color.material_gray_300);

left_arrow.setVisibility(View.VISIBLE);
right_arrow.setVisibility(View.GONE);
messageContainer.setGravity(Gravity.LEFT);
messageContainer.setGravity(Gravity.START);
}

((GradientDrawable) message.getBackground()).setColor(color);
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_chat.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"

tools:context=".ChatActivity">
tools:context=".database.ChatActivity">

<android.support.v7.widget.RecyclerView
android:id="@+id/messagesList"
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<resources>
<resources xmlns:tools="http://schemas.android.com/tools">
<color name="colorPrimary">#039BE5</color>
<color name="colorPrimaryDark">#0288D1</color>
<color name="colorAccent">#FFA000</color>
Expand All @@ -14,7 +14,7 @@
<color name="material_green_300">#AED581</color>
<color name="material_green_a200">#69F0AE</color>

<color name="material_grey_300">#E0E0E0</color>
<color name="material_gray_300">#E0E0E0</color>

<color name="material_lime_50">#F9FBE7</color>
<color name="material_lime_a700">#AEEA00</color>
Expand All @@ -23,4 +23,4 @@
<color name="material_purple_a700">#AA00FF</color>

<color name="material_red_a200">#FF5252</color>
</resources>
</resources>