|
6 | 6 | import androidx.constraintlayout.widget.ConstraintLayout;
|
7 | 7 | import androidx.recyclerview.widget.RecyclerView;
|
8 | 8 |
|
| 9 | +import android.app.Activity; |
9 | 10 | import android.content.Intent;
|
10 | 11 | import android.net.Uri;
|
11 | 12 | import android.os.Bundle;
|
|
21 | 22 | import android.widget.EditText;
|
22 | 23 | import android.widget.ImageView;
|
23 | 24 | import android.widget.ListView;
|
| 25 | +import android.widget.PopupMenu; |
| 26 | +import android.widget.TextView; |
24 | 27 | import android.widget.Toast;
|
25 | 28 |
|
| 29 | +import com.bumptech.glide.Glide; |
26 | 30 | import com.firebase.ui.auth.AuthUI;
|
27 | 31 | import com.google.android.gms.tasks.OnFailureListener;
|
28 | 32 | import com.google.android.gms.tasks.OnSuccessListener;
|
|
42 | 46 | import com.google.firebase.storage.FirebaseStorage;
|
43 | 47 | import com.google.firebase.storage.StorageReference;
|
44 | 48 | import com.google.firebase.storage.UploadTask;
|
| 49 | +import com.mikhaellopez.circularimageview.CircularImageView; |
45 | 50 |
|
46 | 51 | import java.net.URI;
|
47 | 52 | import java.net.URL;
|
|
54 | 59 | import java.util.Objects;
|
55 | 60 | import java.util.concurrent.TimeUnit;
|
56 | 61 |
|
57 |
| -public class MainActivity extends AppCompatActivity { |
| 62 | +public class MainActivity extends Activity { |
58 | 63 |
|
59 | 64 | private ListView mListView;
|
60 | 65 | private ConstraintLayout sendLayout;
|
61 | 66 | private ImageView addImage;
|
62 | 67 | private EditText msgEditView;
|
63 | 68 | private ImageView sendImg;
|
64 | 69 | private ChatAdapter mChatAdapter;
|
| 70 | + private TextView userNameTxtView; |
| 71 | + private CircularImageView userProfilePic; |
| 72 | + private ImageView settingImg; |
65 | 73 |
|
66 | 74 | private String mUserName;
|
67 | 75 | private static final String TAG = "MainActivity";
|
@@ -94,6 +102,9 @@ protected void onCreate(Bundle savedInstanceState) {
|
94 | 102 | addImage = findViewById(R.id.addImageExtra);
|
95 | 103 | msgEditView = (EditText)findViewById(R.id.typingMsgTextView);
|
96 | 104 | sendImg = findViewById(R.id.sendImageView);
|
| 105 | + userNameTxtView = findViewById(R.id.userName); |
| 106 | + userProfilePic = findViewById(R.id.userProfileImg); |
| 107 | + settingImg = findViewById(R.id.action_menu_presenter); |
97 | 108 |
|
98 | 109 | mFirebaseDatabase = FirebaseDatabase.getInstance();
|
99 | 110 | mMessageDatabaseReference = mFirebaseDatabase.getReference().child("messages");
|
@@ -156,6 +167,13 @@ public void afterTextChanged(Editable editable) {
|
156 | 167 | });
|
157 | 168 | msgEditView.setFilters(new InputFilter[]{new InputFilter.LengthFilter(DEFAULT_MSG_LENGTH_LIMIT)});
|
158 | 169 |
|
| 170 | + /** |
| 171 | + * Set UserName And Profile pic at the headinning of page |
| 172 | + */ |
| 173 | + userNameTxtView.setText(mFirebaseAuth.getCurrentUser().getDisplayName()); |
| 174 | + Glide.with(userProfilePic.getContext()).load(mFirebaseAuth.getCurrentUser().getPhotoUrl()) |
| 175 | + .placeholder(R.drawable.profile_placeholder).into(userProfilePic); |
| 176 | + |
159 | 177 | /**
|
160 | 178 | * Photo/Resource pickup Intent to Select a image for a message
|
161 | 179 | */
|
@@ -226,36 +244,30 @@ public void onCancelled(@NonNull DatabaseError error) {
|
226 | 244 | };
|
227 | 245 | mMessageDatabaseReference.addChildEventListener(mChildEventListener);
|
228 | 246 |
|
229 |
| - /* |
230 |
| - PhoneAuthProvider.OnVerificationStateChangedCallbacks mCallbacks = new PhoneAuthProvider.OnVerificationStateChangedCallbacks() { |
231 |
| - @Override |
232 |
| - public void onVerificationCompleted(@NonNull PhoneAuthCredential phoneAuthCredential) { |
233 |
| - Toast.makeText(MainActivity.this,"Code Verified",Toast.LENGTH_SHORT).show(); |
234 |
| -
|
235 |
| - sign |
236 |
| - } |
237 |
| -
|
238 |
| - @Override |
239 |
| - public void onVerificationFailed(@NonNull FirebaseException e) { |
240 |
| - Toast.makeText(MainActivity.this,"Unsucessfull",Toast.LENGTH_SHORT).show(); |
241 |
| - } |
242 |
| - }; |
| 247 | + //logout when settingIcon is clicked |
| 248 | + settingImg.setOnClickListener(view -> { |
| 249 | + PopupMenu popupMenu = new PopupMenu(MainActivity.this,settingImg); |
| 250 | + MainActivity.this.getMenuInflater().inflate(R.menu.main_page_menu, popupMenu.getMenu()); |
243 | 251 |
|
244 |
| - PhoneAuthOptions options = |
245 |
| - PhoneAuthOptions.newBuilder(mFirebaseAuth) |
246 |
| - .setPhoneNumber("+91 5555 962 304") // Phone number to verify |
247 |
| - .setTimeout(60L, TimeUnit.SECONDS) // Timeout and unit |
248 |
| - .setActivity(this) // Activity (for callback binding) |
249 |
| - .setCallbacks(mCallbacks) // OnVerificationStateChangedCallbacks |
250 |
| - .build(); |
251 |
| - PhoneAuthProvider.verifyPhoneNumber(options); |
252 |
| -*/ |
| 252 | + popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { |
| 253 | + @Override |
| 254 | + public boolean onMenuItemClick(MenuItem menuItem) { |
| 255 | + switch (menuItem.getItemId()){ |
| 256 | + case R.id.sign_out: |
| 257 | + //signOut |
| 258 | + FirebaseAuth.getInstance().signOut(); |
| 259 | + startActivity(new Intent(MainActivity.this,LogIn_page.class)); |
| 260 | + return true; |
| 261 | + default: |
| 262 | + return false; |
| 263 | + } |
| 264 | + } |
| 265 | + }); |
| 266 | + popupMenu.show(); |
| 267 | + }); |
253 | 268 |
|
254 | 269 | }
|
255 | 270 |
|
256 |
| - /** |
257 |
| - * TODO : Edit rules of real Time Firebase |
258 |
| - */ |
259 | 271 |
|
260 | 272 | private void onSignedInIntialize(String displayName) {
|
261 | 273 | mUserName = displayName;
|
@@ -364,25 +376,6 @@ public void onFailure(@NonNull Exception e) {
|
364 | 376 | }
|
365 | 377 | }
|
366 | 378 |
|
367 |
| - @Override |
368 |
| - public boolean onCreateOptionsMenu(Menu menu) { |
369 |
| - MenuInflater inflater = getMenuInflater(); |
370 |
| - inflater.inflate(R.menu.main_page_menu, menu); |
371 |
| - return true; |
372 |
| - } |
373 |
| - |
374 |
| - @Override |
375 |
| - public boolean onOptionsItemSelected(MenuItem item) { |
376 |
| - switch (item.getItemId()){ |
377 |
| - case R.id.sign_out: |
378 |
| - //signOut |
379 |
| - FirebaseAuth.getInstance().signOut(); |
380 |
| - startActivity(new Intent(MainActivity.this,LogIn_page.class)); |
381 |
| - return true; |
382 |
| - default: |
383 |
| - return super.onOptionsItemSelected(item); |
384 |
| - } |
385 |
| - } |
386 | 379 | @Override
|
387 | 380 | protected void onPause() {
|
388 | 381 | super.onPause();
|
|
0 commit comments