Commit 73133568 authored by Sajal Narang's avatar Sajal Narang

Add ProfileFragment, fix #61

parent 09ef8cff
......@@ -34,6 +34,7 @@ ext {
}
dependencies {
implementation 'com.android.support:support-v4:26.1.0'
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
......
......@@ -3,4 +3,5 @@ package in.ac.iitb.gymkhana.iitbapp;
public class Constants {
public static final String NOTIFICATIONS_RESPONSE_JSON = "notifications_json";
public static final String EVENT_JSON = "event_json";
public static final java.lang.String USER_ID = "user_id";
}
......@@ -42,6 +42,7 @@ import in.ac.iitb.gymkhana.iitbapp.fragment.MyEventsFragment;
import in.ac.iitb.gymkhana.iitbapp.fragment.NotificationsFragment;
import in.ac.iitb.gymkhana.iitbapp.fragment.PTCellFragment;
import in.ac.iitb.gymkhana.iitbapp.fragment.PeopleFragment;
import in.ac.iitb.gymkhana.iitbapp.fragment.ProfileFragment;
import in.ac.iitb.gymkhana.iitbapp.fragment.TimetableFragment;
import retrofit2.Call;
import retrofit2.Callback;
......@@ -91,6 +92,16 @@ public class MainActivity extends AppCompatActivity
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
View header = navigationView.getHeaderView(0);
header.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Bundle bundle = new Bundle();
bundle.putString(Constants.USER_ID, currentUser.getUserID());
ProfileFragment profileFragment = new ProfileFragment();
profileFragment.setArguments(bundle);
updateFragment(profileFragment);
}
});
TextView nameTextView = header.findViewById(R.id.user_name_nav_header);
TextView rollNoTextView = header.findViewById(R.id.user_rollno_nav_header);
ImageView profilePictureImageView = header.findViewById(R.id.user_profile_picture_nav_header);
......
......@@ -8,6 +8,7 @@ import in.ac.iitb.gymkhana.iitbapp.api.model.LoginResponse;
import in.ac.iitb.gymkhana.iitbapp.api.model.NewsFeedResponse;
import in.ac.iitb.gymkhana.iitbapp.api.model.NotificationsRequest;
import in.ac.iitb.gymkhana.iitbapp.api.model.NotificationsResponse;
import in.ac.iitb.gymkhana.iitbapp.data.User;
import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.GET;
......@@ -25,6 +26,9 @@ public interface RetrofitInterface {
@GET("users/{uuid}/followed_bodies_events")
Call<NewsFeedResponse> getNewsFeed(@Path("uuid") String uuid);
@GET("users/{uuid}")
Call<User> getUser(@Path("uuid") String uuid);
@POST("getNotifications/")
Call<NotificationsResponse> getNotifications(@Body NotificationsRequest notificationsRequest);
......
package in.ac.iitb.gymkhana.iitbapp.fragment;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.squareup.picasso.Picasso;
import in.ac.iitb.gymkhana.iitbapp.Constants;
import in.ac.iitb.gymkhana.iitbapp.R;
import in.ac.iitb.gymkhana.iitbapp.api.RetrofitInterface;
import in.ac.iitb.gymkhana.iitbapp.api.ServiceGenerator;
import in.ac.iitb.gymkhana.iitbapp.data.User;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
/**
* A simple {@link Fragment} subclass.
*/
public class ProfileFragment extends Fragment {
User user;
public ProfileFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_profile, container, false);
}
@Override
public void onStart() {
super.onStart();
Bundle bundle = getArguments();
String userID = bundle.getString(Constants.USER_ID);
RetrofitInterface retrofitInterface = ServiceGenerator.createService(RetrofitInterface.class);
retrofitInterface.getUser(userID).enqueue(new Callback<User>() {
@Override
public void onResponse(Call<User> call, Response<User> response) {
if (response.isSuccessful()) {
user = response.body();
populateViews();
}
}
@Override
public void onFailure(Call<User> call, Throwable t) {
}
});
}
private void populateViews() {
ImageView userProfilePictureImageView = getActivity().findViewById(R.id.user_profile_picture_profile);
TextView userNameTextView = getActivity().findViewById(R.id.user_name_profile);
TextView userRollNumberTextView = getActivity().findViewById(R.id.user_rollno_profile);
TextView userEmailIDTextView = getActivity().findViewById(R.id.user_email_profile);
TextView userContactNumberTextView = getActivity().findViewById(R.id.user_contact_no_profile);
Picasso.with(getContext()).load(user.getUserProfilePictureUrl()).into(userProfilePictureImageView);
userNameTextView.setText(user.getUserName());
userRollNumberTextView.setText(user.getUserRollNumber());
userEmailIDTextView.setText(user.getUserEmail());
userContactNumberTextView.setText(user.getUserContactNumber());
}
}
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
tools:context="in.ac.iitb.gymkhana.iitbapp.fragment.ProfileFragment">
<ImageView
android:id="@+id/user_profile_picture_profile"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/user_name_profile"
android:textStyle="bold"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/user_rollno_profile"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/user_email_profile"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/user_contact_no_profile"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment