Skip to content

Commit 1c7f348

Browse files
committed
Re-organize sample and clear memory leaks
Change-Id: I56d8d2ab1b1fa32c15bfcd8fcdc61f20f4973949
1 parent 7927184 commit 1c7f348

File tree

5 files changed

+27
-17
lines changed

5 files changed

+27
-17
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
<!-- Chat demo -->
2222
<activity
23-
android:name=".ChatActivity"
23+
android:name=".database.ChatActivity"
2424
android:label="@string/name_chat" />
2525

2626
<!-- Auth UI demo -->
@@ -33,4 +33,4 @@
3333
android:label="@string/name_auth_ui" />
3434
</application>
3535

36-
</manifest>
36+
</manifest>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import android.widget.TextView;
2727

2828
import com.firebase.uidemo.auth.AuthUiActivity;
29+
import com.firebase.uidemo.database.ChatActivity;
2930

3031
import butterknife.BindView;
3132
import butterknife.ButterKnife;

app/src/main/java/com/firebase/uidemo/ChatActivity.java renamed to app/src/main/java/com/firebase/uidemo/database/ChatActivity.java

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* limitations under the License.
1313
*/
1414

15-
package com.firebase.uidemo;
15+
package com.firebase.uidemo.database;
1616

1717
import android.graphics.PorterDuff;
1818
import android.graphics.drawable.GradientDrawable;
@@ -35,6 +35,7 @@
3535
import android.widget.Toast;
3636

3737
import com.firebase.ui.database.FirebaseRecyclerAdapter;
38+
import com.firebase.uidemo.R;
3839
import com.google.android.gms.tasks.OnCompleteListener;
3940
import com.google.android.gms.tasks.Task;
4041
import com.google.firebase.auth.AuthResult;
@@ -45,7 +46,7 @@
4546
import com.google.firebase.database.FirebaseDatabase;
4647
import 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);

app/src/main/res/layout/activity_chat.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
android:layout_width="match_parent"
55
android:layout_height="match_parent"
66

7-
tools:context=".ChatActivity">
7+
tools:context=".database.ChatActivity">
88

99
<android.support.v7.widget.RecyclerView
1010
android:id="@+id/messagesList"

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<resources>
1+
<resources xmlns:tools="http://schemas.android.com/tools">
22
<color name="colorPrimary">#039BE5</color>
33
<color name="colorPrimaryDark">#0288D1</color>
44
<color name="colorAccent">#FFA000</color>
@@ -14,7 +14,7 @@
1414
<color name="material_green_300">#AED581</color>
1515
<color name="material_green_a200">#69F0AE</color>
1616

17-
<color name="material_grey_300">#E0E0E0</color>
17+
<color name="material_gray_300">#E0E0E0</color>
1818

1919
<color name="material_lime_50">#F9FBE7</color>
2020
<color name="material_lime_a700">#AEEA00</color>
@@ -23,4 +23,4 @@
2323
<color name="material_purple_a700">#AA00FF</color>
2424

2525
<color name="material_red_a200">#FF5252</color>
26-
</resources>
26+
</resources>

0 commit comments

Comments
 (0)