Commit b78325e3 authored by Varun Patil's avatar Varun Patil Committed by GitHub

Merge pull request #267 from wncc/patch15

Fix up some stuff
parents cbf41dbc 88aef255
......@@ -28,7 +28,7 @@ ext {
okhttpVersion = '3.11.0'
picassoVersion = '2.71828'
circleImageViewVersion = '2.2.0'
markwonVersion = '1.0.6'
markwonVersion = '2.0.1'
tagViewVersion = '1.3'
circleIndicatorVersion = '1.2.2@aar'
firebaseVersion = '17.3.4'
......
......@@ -17,7 +17,8 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:name="app.insti.InstiAppApplication">
android:name="app.insti.InstiAppApplication"
android:networkSecurityConfig="@xml/network_security_config">
<meta-data
android:name="com.google.android.gms.version"
......
......@@ -339,7 +339,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
openEventFragment(id);
return;
case DATA_TYPE_NEWS:
updateFragment(new NewsFragment());
updateFragment((new NewsFragment()).withId(id));
return;
}
Log.e("NOTIFICATIONS", "Server sent invalid notification?");
......@@ -355,9 +355,9 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
switch (type) {
case DATA_TYPE_PT:
if (extra.contains("/trainingblog")) {
openTrainingBlog();
openTrainingBlog(id);
} else {
openPlacementBlog();
openPlacementBlog(id);
}
return;
}
......@@ -586,8 +586,13 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
* Open placement blog fragment
*/
private void openPlacementBlog() {
openPlacementBlog(null);
}
private void openPlacementBlog(String id) {
if (session.isLoggedIn()) {
PlacementBlogFragment placementBlogFragment = new PlacementBlogFragment();
if (id != null) placementBlogFragment.withId(id);
updateFragment(placementBlogFragment);
} else {
Toast.makeText(this, Constants.LOGIN_MESSAGE, Toast.LENGTH_LONG).show();
......@@ -595,8 +600,13 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
}
private void openTrainingBlog() {
openTrainingBlog(null);
}
private void openTrainingBlog(String id) {
if (session.isLoggedIn()) {
TrainingBlogFragment trainingBlogFragment = new TrainingBlogFragment();
if (id != null) trainingBlogFragment.withId(id);
updateFragment(trainingBlogFragment);
} else {
Toast.makeText(this, Constants.LOGIN_MESSAGE, Toast.LENGTH_LONG).show();
......
......@@ -12,6 +12,7 @@ import app.insti.Utils;
import app.insti.api.EmptyCallback;
import app.insti.api.RetrofitInterface;
import app.insti.api.model.Event;
import app.insti.api.model.NewsArticle;
import app.insti.api.model.Notification;
import app.insti.api.model.PlacementBlogPost;
import app.insti.fragment.NewsFragment;
......@@ -37,22 +38,26 @@ public class NotificationsAdapter extends CardAdapter<Notification> {
/* Close the bottom sheet */
notificationsFragment.dismiss();
Gson gson = Utils.gson;
/* Open event */
if (notification.isEvent()) {
Gson gson = new Gson();
Event event = gson.fromJson(gson.toJson(notification.getNotificationActor()), Event.class) ;
Utils.openEventFragment(event, fragmentActivity);
} else if (notification.isNews()) {
NewsFragment newsFragment = new NewsFragment();
NewsArticle newsArticle = gson.fromJson(gson.toJson(notification.getNotificationActor()), NewsArticle.class) ;
newsFragment.withId(newsArticle.getId());
Utils.updateFragment(newsFragment, fragmentActivity);
} else if (notification.isBlogPost()) {
Gson gson = new Gson();
PlacementBlogPost post = gson.fromJson(gson.toJson(notification.getNotificationActor()), PlacementBlogPost.class);
Fragment fragment;
if (post.getLink().contains("training")) {
Utils.updateFragment(new TrainingBlogFragment(), fragmentActivity);
fragment = (new TrainingBlogFragment()).withId(post.getId());
} else {
Utils.updateFragment(new PlacementBlogFragment(), fragmentActivity);
fragment = (new PlacementBlogFragment()).withId(post.getId());
}
Utils.updateFragment(fragment, fragmentActivity);
}
}
......
......@@ -18,6 +18,7 @@ import app.insti.api.request.ComplaintCreateRequest;
import app.insti.api.request.EventCreateRequest;
import app.insti.api.request.ImageUploadRequest;
import app.insti.api.request.UserFCMPatchRequest;
import app.insti.api.request.UserShowContactPatchRequest;
import app.insti.api.response.ComplaintCreateResponse;
import app.insti.api.response.EventCreateResponse;
import app.insti.api.response.ExploreResponse;
......@@ -87,6 +88,9 @@ public interface RetrofitInterface {
@PATCH("user-me")
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}")
Call<Void> updateUserEventStatus(@Header("Cookie") String sessionID, @Path("eventID") String eventID, @Query("status") int status);
......
......@@ -41,6 +41,8 @@ public class NewsArticle implements Clickable {
this.body = body;
}
public String getId() { return articleID; }
public String getArticleID() {
return articleID;
}
......
......@@ -37,6 +37,8 @@ public class PlacementBlogPost implements Clickable {
this.published = published;
}
public String getId() { return postID; }
public String getPostID() {
return postID;
}
......
......@@ -37,6 +37,8 @@ public class TrainingBlogPost implements Clickable {
this.published = published;
}
public String getId() { return postID; }
public String getPostID() {
return postID;
}
......
......@@ -35,6 +35,9 @@ public class User implements CardInterface {
@SerializedName("contact_no")
private String userContactNumber;
@SerializedName("show_contact_no")
private Boolean showContactNumber;
@SerializedName("about")
private String userAbout;
......@@ -64,7 +67,7 @@ public class User implements CardInterface {
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.userName = userName;
this.userProfilePictureUrl = userProfilePictureUrl;
......@@ -73,6 +76,7 @@ public class User implements CardInterface {
this.userEmail = userEmail;
this.userRollNumber = userRollNumber;
this.userContactNumber = userContactNumber;
this.showContactNumber = showContactNumber;
this.userAbout = userAbout;
this.userFollowedBodies = userFollowedBodies;
this.userFollowedBodiesID = userFollowedBodiesID;
......@@ -82,6 +86,7 @@ public class User implements CardInterface {
this.userWebsiteURL = userWebsiteURL;
this.userLDAPId = userLDAPId;
this.hostel = hostel;
this.currentRole = currentRole;
}
public static User fromString(String json) {
......@@ -225,6 +230,14 @@ public class User implements CardInterface {
this.hostel = hostel;
}
public Boolean getShowContactNumber() {
return showContactNumber;
}
public void setShowContactNumber(Boolean showContactNumber) {
this.showContactNumber = showContactNumber;
}
public String getCurrentRole() {
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;
}
}
package app.insti.fragment;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.LinearSmoothScroller;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.SearchView;
import android.text.TextUtils;
......@@ -42,6 +41,12 @@ public abstract class RecyclerViewFragment<T extends Clickable, S extends Recycl
private S adapter = null;
boolean loading = false;
private boolean allLoaded = false;
private String initId = null;
public RecyclerViewFragment<T, S> withId(String id) {
initId = id;
return this;
}
/** Update the data clearing existing */
protected void updateData() {
......@@ -89,6 +94,11 @@ public abstract class RecyclerViewFragment<T extends Clickable, S extends Recycl
if (adapter == null || recyclerView.getAdapter() != adapter) {
initAdapter(result);
/* Scroll to current post */
if (initId != null) {
scrollToPosition(getPosition(result, initId));
}
} else {
adapter.setPosts(result);
adapter.notifyDataSetChanged();
......@@ -97,6 +107,29 @@ public abstract class RecyclerViewFragment<T extends Clickable, S extends Recycl
getActivity().findViewById(R.id.loadingPanel).setVisibility(GONE);
}
/** Set position of id in list of clickables */
private int getPosition(List<T> result, String id) {
for (int i = 0; i < result.size(); i++) {
if (result.get(i).getId().equals(id)) {
return i;
}
}
return -1;
}
/** Scroll the recyclerview to position */
private void scrollToPosition(int i) {
if (i < 0) return;
RecyclerView.SmoothScroller smoothScroller = new LinearSmoothScroller(getContext()) {
@Override protected int getVerticalSnapPreference() {
return LinearSmoothScroller.SNAP_TO_START;
}
};
smoothScroller.setTargetPosition(i);
recyclerView.getLayoutManager().startSmoothScroll(smoothScroller);
}
/** Initialize the adapter */
private void initAdapter(final List<T> result) {
try {
......
......@@ -10,7 +10,9 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.Switch;
import android.widget.TextView;
import com.squareup.picasso.Picasso;
......@@ -23,6 +25,7 @@ import app.insti.activity.LoginActivity;
import app.insti.activity.MainActivity;
import app.insti.api.RetrofitInterface;
import app.insti.api.model.User;
import app.insti.api.request.UserShowContactPatchRequest;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
......@@ -64,6 +67,7 @@ public class SettingsFragment extends Fragment {
if (response.isSuccessful()) {
user = response.body();
populateUserCard();
setupContactSwitch(user);
}
}
......@@ -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() {
if (getActivity() == null || getView() == null) {
return;
......
......@@ -4,5 +4,7 @@ import android.content.Context;
import android.view.View.OnClickListener;
public interface Clickable {
String getId();
OnClickListener getOnClickListener(Context context);
}
......@@ -43,6 +43,18 @@
</LinearLayout>
</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
android:id="@+id/settings_update_profile"
style="@style/Widget.AppCompat.Button.Borderless"
......
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">gymkhana.iitb.ac.in</domain>
</domain-config>
</network-security-config>
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