1212 * limitations under the License.
1313 */
1414
15- package com .firebase .uidemo ;
15+ package com .firebase .uidemo . database ;
1616
1717import android .graphics .PorterDuff ;
1818import android .graphics .drawable .GradientDrawable ;
3535import android .widget .Toast ;
3636
3737import com .firebase .ui .database .FirebaseRecyclerAdapter ;
38+ import com .firebase .uidemo .R ;
3839import com .google .android .gms .tasks .OnCompleteListener ;
3940import com .google .android .gms .tasks .Task ;
4041import com .google .firebase .auth .AuthResult ;
4546import com .google .firebase .database .FirebaseDatabase ;
4647import com .google .firebase .database .Query ;
4748
48- public class ChatActivity extends AppCompatActivity {
49+ public class ChatActivity extends AppCompatActivity implements FirebaseAuth . AuthStateListener {
4950
5051 public static final String TAG = "RecyclerViewDemo" ;
5152
@@ -65,12 +66,7 @@ protected void onCreate(Bundle savedInstanceState) {
6566 setContentView (R .layout .activity_chat );
6667
6768 mAuth = FirebaseAuth .getInstance ();
68- mAuth .addAuthStateListener (new FirebaseAuth .AuthStateListener () {
69- @ Override
70- public void onAuthStateChanged (@ NonNull FirebaseAuth firebaseAuth ) {
71- updateUI ();
72- }
73- });
69+ mAuth .addAuthStateListener (this );
7470
7571 mSendButton = (Button ) findViewById (R .id .sendButton );
7672 mMessageEdit = (EditText ) findViewById (R .id .messageEdit );
@@ -129,6 +125,19 @@ public void onStop() {
129125 }
130126 }
131127
128+ @ Override
129+ public void onDestroy () {
130+ super .onDestroy ();
131+ if (mAuth != null ) {
132+ mAuth .removeAuthStateListener (this );
133+ }
134+ }
135+
136+ @ Override
137+ public void onAuthStateChanged (@ NonNull FirebaseAuth firebaseAuth ) {
138+ updateUI ();
139+ }
140+
132141 private void attachRecyclerViewAdapter () {
133142 Query lastFifty = mChatRef .limitToLast (50 );
134143 mRecyclerViewAdapter = new FirebaseRecyclerAdapter <Chat , ChatHolder >(
@@ -236,13 +245,13 @@ public void setIsSender(Boolean isSender) {
236245
237246 left_arrow .setVisibility (View .GONE );
238247 right_arrow .setVisibility (View .VISIBLE );
239- messageContainer .setGravity (Gravity .RIGHT );
248+ messageContainer .setGravity (Gravity .END );
240249 } else {
241- color = ContextCompat .getColor (mView .getContext (), R .color .material_grey_300 );
250+ color = ContextCompat .getColor (mView .getContext (), R .color .material_gray_300 );
242251
243252 left_arrow .setVisibility (View .VISIBLE );
244253 right_arrow .setVisibility (View .GONE );
245- messageContainer .setGravity (Gravity .LEFT );
254+ messageContainer .setGravity (Gravity .START );
246255 }
247256
248257 ((GradientDrawable ) message .getBackground ()).setColor (color );
0 commit comments