Skip to content

Commit

Permalink
Profile Image added at Action Bar
Browse files Browse the repository at this point in the history
  • Loading branch information
Satellite-system committed Jan 4, 2022
1 parent 6db167e commit 93cdf98
Show file tree
Hide file tree
Showing 10 changed files with 236 additions and 71 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Multi-user-Real-Time-Chat-Application-master/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@

public class ChatAdapter extends ArrayAdapter<Message> {



public ChatAdapter(Context context, int resource, List<Message> objects){
super(context,resource,objects);
}
Expand All @@ -43,6 +41,7 @@ public View getView(int position, @Nullable View convertView, @NonNull ViewGroup

String user = Objects.requireNonNull(FirebaseAuth.getInstance().getCurrentUser()).getDisplayName();


boolean isPhotoAvailable = message.getPhotoUrl()!=null;
boolean isTimeAvailable = message.getTime()!=null;

Expand All @@ -69,6 +68,7 @@ public View getView(int position, @Nullable View convertView, @NonNull ViewGroup
timeTxtView.setText(message.getTime());
} else timeTxtView.setVisibility(View.GONE);


AuthorTxtView.setText(message.getName());

return convertView;
Expand Down
49 changes: 30 additions & 19 deletions app/src/main/java/com/assistant/android/bolchal/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.recyclerview.widget.RecyclerView;
Expand Down Expand Up @@ -59,7 +60,7 @@
import java.util.Objects;
import java.util.concurrent.TimeUnit;

public class MainActivity extends Activity {
public class MainActivity extends AppCompatActivity {

private ListView mListView;
private ConstraintLayout sendLayout;
Expand Down Expand Up @@ -95,6 +96,12 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

this.getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
getSupportActionBar().setDisplayShowCustomEnabled(true);
getSupportActionBar().setCustomView(R.layout.main_action_bar);
//getSupportActionBar().setElevation(0);
View view = getSupportActionBar().getCustomView();

mUserName = ANONYMOUS;

mListView = findViewById(R.id.recycleView);
Expand Down Expand Up @@ -144,6 +151,7 @@ public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
mChatAdapter = new ChatAdapter(this,R.layout.chat_layout_page,arrayList);
mListView.setAdapter(mChatAdapter);


/**
* When Text changes in message Box
*/
Expand Down Expand Up @@ -245,25 +253,28 @@ public void onCancelled(@NonNull DatabaseError error) {
mMessageDatabaseReference.addChildEventListener(mChildEventListener);

//logout when settingIcon is clicked
settingImg.setOnClickListener(view -> {
PopupMenu popupMenu = new PopupMenu(MainActivity.this,settingImg);
MainActivity.this.getMenuInflater().inflate(R.menu.main_page_menu, popupMenu.getMenu());

popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem menuItem) {
switch (menuItem.getItemId()){
case R.id.sign_out:
//signOut
FirebaseAuth.getInstance().signOut();
startActivity(new Intent(MainActivity.this,LogIn_page.class));
return true;
default:
return false;
settingImg.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
PopupMenu popupMenu = new PopupMenu(MainActivity.this, settingImg);
MainActivity.this.getMenuInflater().inflate(R.menu.main_page_menu, popupMenu.getMenu());

popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem menuItem) {
switch (menuItem.getItemId()) {
case R.id.sign_out:
//signOut
FirebaseAuth.getInstance().signOut();
startActivity(new Intent(MainActivity.this, LogIn_page.class));
return true;
default:
return false;
}
}
}
});
popupMenu.show();
});
popupMenu.show();
}
});

}
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/ic_baseline_settings_24.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector android:height="124dp" android:tint="#FFFFFF"
android:viewportHeight="24" android:viewportWidth="24"
android:width="124dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M19.14,12.94c0.04,-0.3 0.06,-0.61 0.06,-0.94c0,-0.32 -0.02,-0.64 -0.07,-0.94l2.03,-1.58c0.18,-0.14 0.23,-0.41 0.12,-0.61l-1.92,-3.32c-0.12,-0.22 -0.37,-0.29 -0.59,-0.22l-2.39,0.96c-0.5,-0.38 -1.03,-0.7 -1.62,-0.94L14.4,2.81c-0.04,-0.24 -0.24,-0.41 -0.48,-0.41h-3.84c-0.24,0 -0.43,0.17 -0.47,0.41L9.25,5.35C8.66,5.59 8.12,5.92 7.63,6.29L5.24,5.33c-0.22,-0.08 -0.47,0 -0.59,0.22L2.74,8.87C2.62,9.08 2.66,9.34 2.86,9.48l2.03,1.58C4.84,11.36 4.8,11.69 4.8,12s0.02,0.64 0.07,0.94l-2.03,1.58c-0.18,0.14 -0.23,0.41 -0.12,0.61l1.92,3.32c0.12,0.22 0.37,0.29 0.59,0.22l2.39,-0.96c0.5,0.38 1.03,0.7 1.62,0.94l0.36,2.54c0.05,0.24 0.24,0.41 0.48,0.41h3.84c0.24,0 0.44,-0.17 0.47,-0.41l0.36,-2.54c0.59,-0.24 1.13,-0.56 1.62,-0.94l2.39,0.96c0.22,0.08 0.47,0 0.59,-0.22l1.92,-3.32c0.12,-0.22 0.07,-0.47 -0.12,-0.61L19.14,12.94zM12,15.6c-1.98,0 -3.6,-1.62 -3.6,-3.6s1.62,-3.6 3.6,-3.6s3.6,1.62 3.6,3.6S13.98,15.6 12,15.6z"/>
</vector>
38 changes: 19 additions & 19 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,38 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<include
android:layout_width="match_parent"
android:layout_height="wrap_content"
layout="@layout/main_action_bar"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" />

tools:context=".MainActivity"
android:paddingTop="16dp"
android:paddingBottom="16dp"
android:paddingStart="6dp"
android:paddingEnd="6dp">

<ListView
android:id="@+id/recycleView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_height="match_parent"
android:divider="@android:color/transparent"
android:stackFromBottom="true"
app:layout_constraintBottom_toTopOf="@+id/bottomLayout"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:transcriptMode="alwaysScroll"/>
android:transcriptMode="alwaysScroll"
android:layout_above="@id/l2"/>

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/l2"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true">

<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/bottomLayout"
android:layout_width="0dp"
app:layout_constraintHorizontal_weight="1"
android:layout_height="54dp"
android:layout_margin="10dp"
android:layout_marginEnd="10dp"
android:background="@drawable/rounded_border_rectangular_box"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/sendContainerView"
Expand Down Expand Up @@ -86,5 +85,6 @@
app:layout_constraintTop_toTopOf="@id/sendContainerView" />

</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

</androidx.constraintlayout.widget.ConstraintLayout>
</RelativeLayout>
83 changes: 53 additions & 30 deletions app/src/main/res/layout/chat_layout_page.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
Expand All @@ -9,39 +9,62 @@
android:layout_marginEnd="16dp"
android:padding="2dp">

<TextView
android:id="@+id/nameTextView"
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:textAppearance="?android:attr/textAppearanceSmall"
tools:text="Name"/>
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:background="#d4d1cb"
android:padding="6dp">

<ImageView
android:id="@+id/photoImageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:contentDescription="@string/image_sent"
android:layout_below="@id/nameTextView"/>
<TextView
android:id="@+id/nameTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:textAppearance="?android:attr/textAppearanceSmall"
tools:text="Name"
android:textColor="@color/teal_700"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>

<TextView
android:id="@+id/messageTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:textAppearance="?android:attr/textAppearanceLarge"
tools:text="Message"
android:layout_below="@id/nameTextView"/>
<ImageView
android:id="@+id/photoImageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:contentDescription="@string/image_sent"
android:layout_below="@id/nameTextView"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/nameTextView"/>

<TextView
android:id="@+id/messageTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:textAppearance="?android:attr/textAppearanceLarge"
tools:text="Message"
android:layout_below="@id/nameTextView"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/nameTextView"/>

<TextView
android:id="@+id/timeTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
tools:text="12:25 AM"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@id/messageTextView"/>


</androidx.constraintlayout.widget.ConstraintLayout>

<TextView
android:id="@+id/timeTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
tools:text="12:25 AM"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"/>


</RelativeLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
44 changes: 44 additions & 0 deletions app/src/main/res/layout/main_action_bar.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="48dp"
android:paddingStart="12dp"
android:paddingEnd="12dp"
android:paddingBottom = "5dp">

<com.mikhaellopez.circularimageview.CircularImageView
android:id="@+id/userProfileImg"
app:civ_border_width="2dp"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginEnd="15dp"
android:src="@drawable/placeholder"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/userName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="15dp"
android:textColor="@color/white"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@id/userProfileImg"
app:layout_constraintTop_toTopOf="parent"
tools:text="User_Name" />

<ImageView
android:id="@+id/action_menu_presenter"
android:layout_width="30dp"
android:layout_height="30dp"
android:src="@drawable/ic_baseline_settings_24"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
/>

</androidx.constraintlayout.widget.ConstraintLayout>
Loading

0 comments on commit 93cdf98

Please sign in to comment.