Commit c2e0bd37 authored by Varun Patil's avatar Varun Patil

Add show contact number to settings

parent 0c4a31cf
...@@ -18,6 +18,7 @@ import app.insti.api.request.ComplaintCreateRequest; ...@@ -18,6 +18,7 @@ import app.insti.api.request.ComplaintCreateRequest;
import app.insti.api.request.EventCreateRequest; import app.insti.api.request.EventCreateRequest;
import app.insti.api.request.ImageUploadRequest; import app.insti.api.request.ImageUploadRequest;
import app.insti.api.request.UserFCMPatchRequest; import app.insti.api.request.UserFCMPatchRequest;
import app.insti.api.request.UserShowContactPatchRequest;
import app.insti.api.response.ComplaintCreateResponse; import app.insti.api.response.ComplaintCreateResponse;
import app.insti.api.response.EventCreateResponse; import app.insti.api.response.EventCreateResponse;
import app.insti.api.response.ExploreResponse; import app.insti.api.response.ExploreResponse;
...@@ -87,6 +88,9 @@ public interface RetrofitInterface { ...@@ -87,6 +88,9 @@ public interface RetrofitInterface {
@PATCH("user-me") @PATCH("user-me")
Call<User> patchUserMe(@Header("Cookie") String sessionID, @Body UserFCMPatchRequest userFCMPatchRequest); Call<User> patchUserMe(@Header("Cookie") String sessionID, @Body UserFCMPatchRequest userFCMPatchRequest);
@PATCH("user-me")
Call<User> patchUserMe(@Header("Cookie") String sessionID, @Body UserShowContactPatchRequest userShowContactPatchRequest);
@GET("user-me/ues/{eventID}") @GET("user-me/ues/{eventID}")
Call<Void> updateUserEventStatus(@Header("Cookie") String sessionID, @Path("eventID") String eventID, @Query("status") int status); Call<Void> updateUserEventStatus(@Header("Cookie") String sessionID, @Path("eventID") String eventID, @Query("status") int status);
......
...@@ -35,6 +35,9 @@ public class User implements CardInterface { ...@@ -35,6 +35,9 @@ public class User implements CardInterface {
@SerializedName("contact_no") @SerializedName("contact_no")
private String userContactNumber; private String userContactNumber;
@SerializedName("show_contact_no")
private Boolean showContactNumber;
@SerializedName("about") @SerializedName("about")
private String userAbout; private String userAbout;
...@@ -64,7 +67,7 @@ public class User implements CardInterface { ...@@ -64,7 +67,7 @@ public class User implements CardInterface {
private String currentRole; private String currentRole;
public User(@NonNull String userID, String userName, String userProfilePictureUrl, List<Event> userInterestedEvents, List<Event> userGoingEvents, String userEmail, String userRollNumber, String userContactNumber, String userAbout, List<Body> userFollowedBodies, List<String> userFollowedBodiesID, List<Role> userRoles, List<Role> userInstituteRoles, List<Role> userFormerRoles, String userWebsiteURL, String userLDAPId, String hostel) { public User(@NonNull String userID, String userName, String userProfilePictureUrl, List<Event> userInterestedEvents, List<Event> userGoingEvents, String userEmail, String userRollNumber, String userContactNumber, Boolean showContactNumber, String userAbout, List<Body> userFollowedBodies, List<String> userFollowedBodiesID, List<Role> userRoles, List<Role> userInstituteRoles, List<Role> userFormerRoles, String userWebsiteURL, String userLDAPId, String hostel, String currentRole) {
this.userID = userID; this.userID = userID;
this.userName = userName; this.userName = userName;
this.userProfilePictureUrl = userProfilePictureUrl; this.userProfilePictureUrl = userProfilePictureUrl;
...@@ -73,6 +76,7 @@ public class User implements CardInterface { ...@@ -73,6 +76,7 @@ public class User implements CardInterface {
this.userEmail = userEmail; this.userEmail = userEmail;
this.userRollNumber = userRollNumber; this.userRollNumber = userRollNumber;
this.userContactNumber = userContactNumber; this.userContactNumber = userContactNumber;
this.showContactNumber = showContactNumber;
this.userAbout = userAbout; this.userAbout = userAbout;
this.userFollowedBodies = userFollowedBodies; this.userFollowedBodies = userFollowedBodies;
this.userFollowedBodiesID = userFollowedBodiesID; this.userFollowedBodiesID = userFollowedBodiesID;
...@@ -82,6 +86,7 @@ public class User implements CardInterface { ...@@ -82,6 +86,7 @@ public class User implements CardInterface {
this.userWebsiteURL = userWebsiteURL; this.userWebsiteURL = userWebsiteURL;
this.userLDAPId = userLDAPId; this.userLDAPId = userLDAPId;
this.hostel = hostel; this.hostel = hostel;
this.currentRole = currentRole;
} }
public static User fromString(String json) { public static User fromString(String json) {
...@@ -225,6 +230,14 @@ public class User implements CardInterface { ...@@ -225,6 +230,14 @@ public class User implements CardInterface {
this.hostel = hostel; this.hostel = hostel;
} }
public Boolean getShowContactNumber() {
return showContactNumber;
}
public void setShowContactNumber(Boolean showContactNumber) {
this.showContactNumber = showContactNumber;
}
public String getCurrentRole() { public String getCurrentRole() {
return currentRole; return currentRole;
} }
......
package app.insti.api.request;
import com.google.gson.annotations.SerializedName;
public class UserShowContactPatchRequest {
@SerializedName("show_contact_no")
private Boolean showContactNumber;
public UserShowContactPatchRequest(Boolean showContactNumber) {
this.showContactNumber = showContactNumber;
}
}
...@@ -10,7 +10,9 @@ import android.view.LayoutInflater; ...@@ -10,7 +10,9 @@ import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.Button; import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.Switch;
import android.widget.TextView; import android.widget.TextView;
import com.squareup.picasso.Picasso; import com.squareup.picasso.Picasso;
...@@ -23,6 +25,7 @@ import app.insti.activity.LoginActivity; ...@@ -23,6 +25,7 @@ import app.insti.activity.LoginActivity;
import app.insti.activity.MainActivity; import app.insti.activity.MainActivity;
import app.insti.api.RetrofitInterface; import app.insti.api.RetrofitInterface;
import app.insti.api.model.User; import app.insti.api.model.User;
import app.insti.api.request.UserShowContactPatchRequest;
import retrofit2.Call; import retrofit2.Call;
import retrofit2.Callback; import retrofit2.Callback;
import retrofit2.Response; import retrofit2.Response;
...@@ -64,6 +67,7 @@ public class SettingsFragment extends Fragment { ...@@ -64,6 +67,7 @@ public class SettingsFragment extends Fragment {
if (response.isSuccessful()) { if (response.isSuccessful()) {
user = response.body(); user = response.body();
populateUserCard(); populateUserCard();
setupContactSwitch(user);
} }
} }
...@@ -74,6 +78,37 @@ public class SettingsFragment extends Fragment { ...@@ -74,6 +78,37 @@ public class SettingsFragment extends Fragment {
}); });
} }
private void setupContactSwitch(User user) {
final Switch showContactSwitch = getView().findViewById(R.id.show_contact_switch);
showContactSwitch.setVisibility(View.VISIBLE);
showContactSwitch.setChecked(user.getShowContactNumber());
showContactSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, final boolean isChecked) {
showContactSwitch.setEnabled(false);
RetrofitInterface retrofitInterface = Utils.getRetrofitInterface();
retrofitInterface.patchUserMe(Utils.getSessionIDHeader(), new UserShowContactPatchRequest(isChecked)).enqueue(new Callback<User>() {
@Override
public void onResponse(Call<User> call, Response<User> response) {
if (response.isSuccessful()) {
showContactSwitch.setEnabled(true);
} else {
showContactSwitch.setChecked(!isChecked);
showContactSwitch.setEnabled(true);
}
}
@Override
public void onFailure(Call<User> call, Throwable t) {
showContactSwitch.setChecked(!isChecked);
showContactSwitch.setEnabled(true);
}
});
}
});
}
private void populateUserCard() { private void populateUserCard() {
if (getActivity() == null || getView() == null) { if (getActivity() == null || getView() == null) {
return; return;
......
...@@ -43,6 +43,18 @@ ...@@ -43,6 +43,18 @@
</LinearLayout> </LinearLayout>
</android.support.v7.widget.CardView> </android.support.v7.widget.CardView>
<Switch
android:id="@+id/show_contact_switch"
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Show contact no"
android:textSize="20sp"
android:gravity="center_vertical"
android:textAllCaps="false"
android:padding="16dp"
android:visibility="gone" />
<Button <Button
android:id="@+id/settings_update_profile" android:id="@+id/settings_update_profile"
style="@style/Widget.AppCompat.Button.Borderless" style="@style/Widget.AppCompat.Button.Borderless"
......
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