Commit 2263accc authored by Sajal Narang's avatar Sajal Narang Committed by GitHub

Merge pull request #249 from wncc/anim

Add shared element animations
parents 67f7e775 764dc88f
......@@ -13,6 +13,7 @@ public class Constants {
public static final String EVENT_JSON = "event_json";
public static final String EVENT_LIST_JSON = "event_list_json";
public static final String USER_ID = "user_id";
public static final String USER_JSON = "user_json";
public static final String USER_HOSTEL = "user_hostel";
public static final String SENT_TOKEN_TO_SERVER = "sentTokenToServer";
public static final String REGISTRATION_COMPLETE = "registrationComplete";
......@@ -28,6 +29,7 @@ public class Constants {
public static final String BODY_JSON = "body_json";
public static final String BODY_LIST_JSON = "body_list_json";
public static final String ROLE_LIST_JSON = "role_list_json";
public static final String NO_SHARED_ELEM = "no_shared_elem";
public static final String LOGIN_MESSAGE = "Please login to continue!";
......
package app.insti;
import android.support.transition.ChangeBounds;
import android.support.transition.ChangeImageTransform;
import android.support.transition.ChangeTransform;
import android.support.transition.TransitionSet;
public class DetailsTransition extends TransitionSet {
public DetailsTransition() {
setOrdering(ORDERING_TOGETHER);
addTransition(new ChangeBounds()).
addTransition(new ChangeTransform()).
addTransition(new ChangeImageTransform());
}
}
......@@ -6,9 +6,13 @@ import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.design.widget.NavigationView;
import android.support.transition.Fade;
import android.support.transition.Slide;
import android.support.transition.Transition;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;
......@@ -16,6 +20,10 @@ import com.google.gson.Gson;
import com.squareup.picasso.Callback;
import com.squareup.picasso.Picasso;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;
import app.insti.activity.MainActivity;
import app.insti.api.RetrofitInterface;
import app.insti.api.model.Body;
......@@ -24,6 +32,8 @@ import app.insti.api.model.Notification;
import app.insti.api.model.User;
import app.insti.fragment.BodyFragment;
import app.insti.fragment.EventFragment;
import app.insti.fragment.TransitionTargetChild;
import app.insti.fragment.TransitionTargetFragment;
import app.insti.fragment.UserFragment;
public final class Utils {
......@@ -76,29 +86,111 @@ public final class Utils {
ft.commit();
}
public static void openBodyFragment(Body body, FragmentActivity fragmentActivity) {
public static void updateSharedElementFragment(final Fragment fragment, final Fragment currentFragment, Map<View, String> sharedElements) {
FragmentTransaction ft = currentFragment.getActivity().getSupportFragmentManager().beginTransaction();
Transition transition = new DetailsTransition();
/* Set up transitions */
fragment.setSharedElementEnterTransition(transition);
fragment.setEnterTransition(new Slide());
currentFragment.setExitTransition(new Fade());
fragment.setSharedElementReturnTransition(transition);
/* Set transition for parent in case it is a child */
if (currentFragment instanceof TransitionTargetChild) {
((TransitionTargetChild) currentFragment).getParent().setExitTransition(new Fade());
}
transition.addListener(new Transition.TransitionListener() {
@Override
public void onTransitionStart(Transition transition) {
}
@Override
public void onTransitionEnd(Transition transition) {
if (fragment instanceof TransitionTargetFragment) {
((TransitionTargetFragment) fragment).transitionEnd();
}
if (currentFragment instanceof TransitionTargetFragment) {
((TransitionTargetFragment) currentFragment).transitionEnd();
}
}
@Override
public void onTransitionCancel(Transition transition) {}
@Override
public void onTransitionPause(Transition transition) {}
@Override
public void onTransitionResume(Transition transition) {}
});
/* Add all shared elements */
for (Map.Entry<View, String> entry : sharedElements.entrySet()) {
ft.addSharedElement(entry.getKey(), entry.getValue());
}
/* Update the fragment */
ft.replace(R.id.framelayout_for_fragment, fragment, fragment.getTag())
.addToBackStack(fragment.getTag())
.commit();
}
public static BodyFragment getBodyFragment(Body body) {
Bundle bundle = new Bundle();
bundle.putString(Constants.BODY_JSON, new Gson().toJson(body));
BodyFragment bodyFragment = new BodyFragment();
bodyFragment.setArguments(bundle);
updateFragment(bodyFragment, fragmentActivity);
return bodyFragment;
}
public static void openEventFragment(Event event, FragmentActivity fragmentActivity) {
public static void openBodyFragment(Body body, FragmentActivity fragmentActivity) {
updateFragment(getBodyFragment(body), fragmentActivity);
}
public static void openBodyFragment(Body body, Fragment currentFragment, View sharedAvatar) {
Map<View, String> sharedElements = new HashMap<>();
sharedElements.put(sharedAvatar, "sharedAvatar");
updateSharedElementFragment(
getBodyFragment(body), currentFragment, sharedElements
);
}
public static EventFragment getEventFragment(Event event, boolean sharedElements) {
String eventJson = new Gson().toJson(event);
Bundle bundle = new Bundle();
bundle.putString(Constants.EVENT_JSON, eventJson);
bundle.putBoolean(Constants.NO_SHARED_ELEM, !sharedElements);
EventFragment eventFragment = new EventFragment();
eventFragment.setArguments(bundle);
updateFragment(eventFragment, fragmentActivity);
return eventFragment;
}
public static void openEventFragment(Event event, FragmentActivity fragmentActivity) {
updateFragment(getEventFragment(event, false), fragmentActivity);
}
public static void openEventFragment(Event event, Fragment currentFragment, View sharedAvatar) {
Map<View, String> sharedElements = new HashMap<>();
sharedElements.put(sharedAvatar, "sharedAvatar");
updateSharedElementFragment(
getEventFragment(event, true), currentFragment, sharedElements
);
}
public static void openUserFragment(User user, FragmentActivity fragmentActivity) {
Bundle bundle = new Bundle();
bundle.putString(Constants.USER_ID, user.getUserID());
UserFragment userFragment = new UserFragment();
userFragment.setArguments(bundle);
updateFragment(userFragment, fragmentActivity);
updateFragment(UserFragment.newInstance(user.getUserID()), fragmentActivity);
}
public static void openUserFragment(User user, Fragment currentFragment, View sharedAvatar) {
Map<View, String> sharedElements = new HashMap<>();
sharedElements.put(sharedAvatar, "sharedAvatar");
updateSharedElementFragment(
UserFragment.newInstance(user), currentFragment, sharedElements
);
}
public static void setSessionId(String sessionId1) {
......
package app.insti.adapter;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import java.util.List;
import app.insti.R;
import app.insti.Utils;
import app.insti.api.model.Body;
......@@ -15,7 +16,7 @@ public class BodyAdapter extends CardAdapter<Body> {
super(bodyList, mFragment);
}
public void onClick(Body body, FragmentActivity fragmentActivity) {
Utils.openBodyFragment(body, fragmentActivity);
public void onClick(Body body, Fragment fragment, View view) {
Utils.openBodyFragment(body, fragment, view.findViewById(R.id.object_picture));
}
}
......@@ -25,7 +25,8 @@ public abstract class CardAdapter<T extends CardInterface> extends RecyclerView.
private List<T> tList;
private Fragment mFragment;
public abstract void onClick(T t, FragmentActivity fragmentActivity);
public void onClick(T t, FragmentActivity fragmentActivity) {};
public void onClick(T t, Fragment fragment, View view) {}
public String getBigImageUrl(T t) {
return null;
......@@ -53,6 +54,7 @@ public abstract class CardAdapter<T extends CardInterface> extends RecyclerView.
@Override
public void onClick(View view) {
CardAdapter.this.onClick(tList.get(postViewHolder.getAdapterPosition()), mFragment.getActivity());
CardAdapter.this.onClick(tList.get(postViewHolder.getAdapterPosition()), mFragment, view);
}
});
......@@ -65,9 +67,15 @@ public abstract class CardAdapter<T extends CardInterface> extends RecyclerView.
viewHolder.title.setText(t.getTitle());
viewHolder.subtitle.setText(t.getSubtitle());
// Set transition names
// FIXME: Replace getTitle() with getId() once that is merged
viewHolder.avatar.setTransitionName(Integer.toString(t.getTitle().hashCode()) + "_sharedAvatar");
if (getBigImageUrl(t) != null) {
// Show big image, hide avatar
viewHolder.bigPicture.setVisibility(View.VISIBLE);
// FIXME: Replace getTitle() with getId() once that is merged
viewHolder.bigPicture.setTransitionName(Integer.toString(t.getTitle().hashCode()) + "_sharedBigPicture");
viewHolder.avatar.setVisibility(View.GONE);
// Load big image with low resolution as avatar
......
......@@ -2,6 +2,7 @@ package app.insti.adapter;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import java.util.List;
......@@ -10,14 +11,20 @@ import app.insti.Utils;
import app.insti.api.model.Event;
public class FeedAdapter extends CardAdapter<Event> {
public FeedAdapter(List<Event> eventList, Fragment fragment) {
super(eventList, fragment);
}
@Override
public void onClick(Event event, FragmentActivity fragmentActivity) {
Utils.openEventFragment(event, fragmentActivity);
public void onClick(Event event, FragmentActivity fragmentActivity) {}
@Override
public void onClick(Event event, final Fragment fragment, View view) {
int picId = R.id.object_picture;
if (event.isEventBigImage()) {
picId = R.id.big_object_picture;
}
Utils.openEventFragment(event, fragment, view.findViewById(picId));
}
@Override
......
package app.insti.adapter;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import java.util.List;
......@@ -13,19 +13,18 @@ import app.insti.api.model.User;
import app.insti.interfaces.CardInterface;
public class GenericAdapter extends CardAdapter<CardInterface> {
public GenericAdapter(List<CardInterface> cardInterfaceList, Fragment fragment){
super(cardInterfaceList, fragment);
}
@Override
public void onClick(CardInterface cardInterface, FragmentActivity fragmentActivity) {
public void onClick(CardInterface cardInterface, Fragment fragment, View view) {
if (cardInterface instanceof Event) {
Utils.openEventFragment((Event) cardInterface, fragmentActivity);
Utils.openEventFragment((Event) cardInterface, fragment, view.findViewById(R.id.object_picture));
} else if (cardInterface instanceof Body) {
Utils.openBodyFragment((Body) cardInterface, fragmentActivity);
Utils.openBodyFragment((Body) cardInterface, fragment, view.findViewById(R.id.object_picture));
} else if (cardInterface instanceof User) {
Utils.openUserFragment((User) cardInterface, fragmentActivity);
Utils.openUserFragment((User) cardInterface, fragment, view.findViewById(R.id.object_picture));
}
}
......
package app.insti.adapter;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import java.util.List;
import app.insti.R;
import app.insti.Utils;
import app.insti.api.model.Role;
......@@ -16,7 +17,7 @@ public class RoleAdapter extends CardAdapter<Role> {
}
@Override
public void onClick(Role role, FragmentActivity fragmentActivity) {
Utils.openBodyFragment(role.getRoleBodyDetails(), fragmentActivity);
public void onClick(Role role, Fragment fragment, View view) {
Utils.openBodyFragment(role.getRoleBodyDetails(), fragment, view.findViewById(R.id.object_picture));
}
}
package app.insti.adapter;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import java.util.List;
......@@ -16,8 +16,8 @@ public class UserAdapter extends CardAdapter<User> {
}
@Override
public void onClick(User user, FragmentActivity fragmentActivity) {
Utils.openUserFragment(user, fragmentActivity);
public void onClick(User user, Fragment fragment, View view) {
Utils.openUserFragment(user, fragment, view.findViewById(R.id.object_picture));
}
@Override
......
......@@ -29,8 +29,8 @@ import android.widget.TextView;
import android.widget.Toast;
import com.google.gson.Gson;
import com.squareup.picasso.Picasso;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
......@@ -57,7 +57,7 @@ import ru.noties.markwon.Markwon;
* Use the {@link BodyFragment#newInstance} factory method to
* create an instance of this fragment.
*/
public class BodyFragment extends BackHandledFragment {
public class BodyFragment extends BackHandledFragment implements TransitionTargetFragment {
// TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
......@@ -83,6 +83,7 @@ public class BodyFragment extends BackHandledFragment {
private ImageView bodyPicture;
private Body body;
private boolean bodyDisplayed = false;
private boolean transitionEnded = false;
public BodyFragment() {
// Required empty public constructor
......@@ -122,6 +123,14 @@ public class BodyFragment extends BackHandledFragment {
}
}
@Override
public void transitionEnd() {
if (getActivity() == null || getView() == null) return;
bodyPicture = (ImageView) getView().findViewById(R.id.body_picture);
Utils.loadImageWithPlaceholder(bodyPicture, body.getBodyImageURL());
transitionEnded = true;
}
@Override
public void onStart() {
super.onStart();
......@@ -201,7 +210,14 @@ public class BodyFragment extends BackHandledFragment {
/* Set body information */
bodyName.setText(body.getBodyName());
bodySubtitle.setText(body.getBodyShortDescription());
Utils.loadImageWithPlaceholder(bodyPicture, body.getBodyImageURL());
/* Load only low res image if transition is not completed */
if (transitionEnded) {
Utils.loadImageWithPlaceholder(bodyPicture, body.getBodyImageURL());
} else {
Picasso.get().load(Utils.resizeImageUrl(body.getBodyImageURL())).into(bodyPicture);
}
bodyPicture.setOnClickListener(new View.OnClickListener() {
@Override
......
......@@ -26,9 +26,9 @@ import app.insti.api.model.Body;
* Use the {@link BodyRecyclerViewFragment#newInstance} factory method to
* create an instance of this fragment.
*/
public class BodyRecyclerViewFragment extends Fragment {
public class BodyRecyclerViewFragment extends Fragment implements TransitionTargetFragment, TransitionTargetChild {
private static final String TAG = "BodyRecyclerViewFragment";
public Fragment parentFragment = null;
private RecyclerView recyclerView;
private BodyAdapter bodyAdapter;
......@@ -39,6 +39,18 @@ public class BodyRecyclerViewFragment extends Fragment {
// Required empty public constructor
}
@Override
public void transitionEnd() {
if (parentFragment instanceof TransitionTargetFragment) {
((TransitionTargetFragment) parentFragment).transitionEnd();
}
}
@Override
public Fragment getParent() {
return parentFragment;
}
// TODO: Rename and change types and number of parameters
public static BodyRecyclerViewFragment newInstance(List<Body> bodyList) {
BodyRecyclerViewFragment fragment = new BodyRecyclerViewFragment();
......
......@@ -33,6 +33,7 @@ import android.widget.TextView;
import android.widget.Toast;
import com.google.gson.Gson;
import com.squareup.picasso.Picasso;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
......@@ -57,7 +58,7 @@ import ru.noties.markwon.Markwon;
/**
* A simple {@link Fragment} subclass.
*/
public class EventFragment extends BackHandledFragment {
public class EventFragment extends BackHandledFragment implements TransitionTargetFragment {
Event event;
Button goingButton;
Button interestedButton;
......@@ -86,6 +87,12 @@ public class EventFragment extends BackHandledFragment {
// Required empty public constructor
}
@Override
public void transitionEnd() {
if (getActivity() == null || getView() == null) return;
Utils.loadImageWithPlaceholder(eventPicture, event.getEventImageURL());
}
/**
* Get a spannable with a small count badge to set for an element text
*
......@@ -137,6 +144,10 @@ public class EventFragment extends BackHandledFragment {
Toolbar toolbar = getActivity().findViewById(R.id.toolbar);
toolbar.setTitle(event.getEventName());
if (bundle.getBoolean(Constants.NO_SHARED_ELEM, true)) {
this.transitionEnd();
}
}
private void inflateViews(final Event event) {
......@@ -152,7 +163,11 @@ public class EventFragment extends BackHandledFragment {
webEventButton = getActivity().findViewById(R.id.web_event_button);
shareEventButton = getActivity().findViewById(R.id.share_event_button);
Utils.loadImageWithPlaceholder(eventPicture, event.getEventImageURL());
if (event.isEventBigImage()) {
Picasso.get().load(event.getEventImageURL()).into(eventPicture);
} else {
Picasso.get().load(Utils.resizeImageUrl(event.getEventImageURL())).into(eventPicture);
}
eventTitle.setText(event.getEventName());
Markwon.setMarkdown(eventDescription, event.getEventDescription());
......
......@@ -25,9 +25,9 @@ import app.insti.api.model.Event;
* Use the {@link EventRecyclerViewFragment#newInstance} factory method to
* create an instance of this fragment.
*/
public class EventRecyclerViewFragment extends Fragment {
public class EventRecyclerViewFragment extends Fragment implements TransitionTargetFragment, TransitionTargetChild {
private static final String TAG = "EventRecyclerViewFragment";
public Fragment parentFragment = null;
private RecyclerView recyclerView;
private FeedAdapter feedAdapter;
......@@ -38,6 +38,18 @@ public class EventRecyclerViewFragment extends Fragment {
// Required empty public constructor
}
@Override
public void transitionEnd() {
if (parentFragment instanceof TransitionTargetFragment) {
((TransitionTargetFragment) parentFragment).transitionEnd();
}
}
@Override
public Fragment getParent() {
return parentFragment;
}
// TODO: Rename and change types and number of parameters
public static EventRecyclerViewFragment newInstance(List<Event> eventList) {
EventRecyclerViewFragment fragment = new EventRecyclerViewFragment();
......
......@@ -40,6 +40,9 @@ import retrofit2.Response;
*/
public class ExploreFragment extends Fragment {
private RecyclerView recyclerView;
LinearLayoutManager mLayoutManager;
private static List<Body> allBodies = new ArrayList<>();
private static List<Body> bodies = new ArrayList<>();
private static List<Event> events = new ArrayList<>();
......@@ -47,6 +50,9 @@ public class ExploreFragment extends Fragment {
private static List<CardInterface> cards = new ArrayList<>();
private static int index;
private static int top;
private String sessionId;
private GenericAdapter genericAdapter;
......@@ -69,8 +75,21 @@ public class ExploreFragment extends Fragment {
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
public void onPause()
{
super.onPause();
index = mLayoutManager.findFirstVisibleItemPosition();
View v = recyclerView.getChildAt(0);
top = (v == null) ? 0 : (v.getTop() - recyclerView.getPaddingTop());
}
@Override
public void onResume()
{
super.onResume();
if(index != -1) {
mLayoutManager.scrollToPositionWithOffset( index, top);
}
}
@Override
......@@ -199,9 +218,10 @@ public class ExploreFragment extends Fragment {
public void initRecyclerView() {
if (getActivity() == null || getView() == null) return;
RecyclerView bodiesRecyclerView = getView().findViewById(R.id.explore_recycler_view);
recyclerView = getView().findViewById(R.id.explore_recycler_view);
mLayoutManager = new LinearLayoutManager(getContext());
genericAdapter = new GenericAdapter(cards, this);
bodiesRecyclerView.setAdapter(genericAdapter);
bodiesRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
recyclerView.setAdapter(genericAdapter);
recyclerView.setLayoutManager(mLayoutManager);
}
}
\ No newline at end of file
......@@ -23,9 +23,9 @@ import app.insti.api.model.Role;
* Use the {@link RoleRecyclerViewFragment#newInstance} factory method to
* create an instance of this fragment.
*/
public class RoleRecyclerViewFragment extends Fragment {
public class RoleRecyclerViewFragment extends Fragment implements TransitionTargetFragment, TransitionTargetChild {
private static final String TAG = "RoleRecyclerViewFragment";
public Fragment parentFragment = null;
private RecyclerView recyclerView;
private RoleAdapter roleAdapter;
......@@ -36,6 +36,18 @@ public class RoleRecyclerViewFragment extends Fragment {
// Required empty public constructor
}
@Override
public void transitionEnd() {
if (parentFragment instanceof TransitionTargetFragment) {
((TransitionTargetFragment) parentFragment).transitionEnd();
}
}
@Override
public Fragment getParent() {
return parentFragment;
}
// TODO: Rename and change types and number of parameters
public static RoleRecyclerViewFragment newInstance(List<Role> roleList) {
RoleRecyclerViewFragment fragment = new RoleRecyclerViewFragment();
......
package app.insti.fragment;
import android.support.v4.app.Fragment;
public interface TransitionTargetChild {
Fragment getParent();
}
package app.insti.fragment;
public interface TransitionTargetFragment {
void transitionEnd();
}
......@@ -14,8 +14,6 @@ import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
......@@ -33,16 +31,14 @@ import app.insti.Constants;
import app.insti.R;
import app.insti.ShareURLMaker;
import app.insti.Utils;
import app.insti.adapter.RoleAdapter;
import app.insti.adapter.TabAdapter;
import app.insti.api.EmptyCallback;
import app.insti.api.RetrofitInterface;
import app.insti.api.model.Body;
import app.insti.api.model.Event;
import app.insti.api.model.Role;
import app.insti.api.model.User;
import app.insti.interfaces.ItemClickListener;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import static android.view.View.VISIBLE;
......@@ -50,7 +46,7 @@ import static android.view.View.VISIBLE;
/**
* A simple {@link Fragment} subclass.
*/
public class UserFragment extends BackHandledFragment {
public class UserFragment extends BackHandledFragment implements TransitionTargetFragment {
private User user;
// Hold a reference to the current animator,
......@@ -66,6 +62,7 @@ public class UserFragment extends BackHandledFragment {
private Rect startBounds;
private float startScaleFinal;
private ImageView userProfilePictureImageView;
private boolean showingMin = false;
public UserFragment() {
// Required empty public constructor
......@@ -79,6 +76,14 @@ public class UserFragment extends BackHandledFragment {
return fragment;
}
public static UserFragment newInstance(User minUser) {
UserFragment fragment = new UserFragment();
Bundle args = new Bundle();
args.putString(Constants.USER_JSON, Utils.gson.toJson(minUser));
fragment.setArguments(args);
return fragment;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
......@@ -86,6 +91,15 @@ public class UserFragment extends BackHandledFragment {
return inflater.inflate(R.layout.fragment_user, container, false);
}
@Override
public void transitionEnd() {
if (getActivity() == null || getView() == null) return;
if (showingMin) {
showingMin = false;
loadUser(user.getUserID());
}
}
@Override
public boolean onBackPressed() {
if (zoomMode) {
......@@ -96,31 +110,38 @@ public class UserFragment extends BackHandledFragment {
return false;
}
@Override
public void onStart() {
super.onStart();
Toolbar toolbar = getActivity().findViewById(R.id.toolbar);
toolbar.setTitle("Profile");
Bundle bundle = getArguments();
String userID = bundle.getString(Constants.USER_ID);
public void loadUser(String userID) {
RetrofitInterface retrofitInterface = Utils.getRetrofitInterface();
retrofitInterface.getUser(Utils.getSessionIDHeader(), userID).enqueue(new Callback<User>() {
retrofitInterface.getUser(Utils.getSessionIDHeader(), userID).enqueue(new EmptyCallback<User>() {
@Override
public void onResponse(Call<User> call, Response<User> response) {
if (response.isSuccessful()) {
user = response.body();
populateViews();
getActivity().findViewById(R.id.loadingPanel).setVisibility(View.GONE);
}
}
});
}
@Override
public void onFailure(Call<User> call, Throwable t) {
@Override
public void onStart() {
super.onStart();
}
});
Toolbar toolbar = getActivity().findViewById(R.id.toolbar);
toolbar.setTitle("Profile");
Bundle bundle = getArguments();
String userID = bundle.getString(Constants.USER_ID);
String userJson = bundle.getString(Constants.USER_JSON);
if (userID != null) {
loadUser(userID);
} else if (userJson != null) {
user = Utils.gson.fromJson(userJson, User.class);
showingMin = true;
populateViews();
}
}
private void populateViews() {
......@@ -131,12 +152,8 @@ public class UserFragment extends BackHandledFragment {
TextView userContactNumberTextView = getActivity().findViewById(R.id.user_contact_no_profile);
ImageButton userShareImageButton = getActivity().findViewById(R.id.share_user_button);
/* Show tabs */
getActivity().findViewById(R.id.tab_layout).setVisibility(VISIBLE);
Picasso.get()
.load(user.getUserProfilePictureUrl())
.resize(500, 0)
.placeholder(R.drawable.user_placeholder)
.into(userProfilePictureImageView);
......@@ -148,40 +165,52 @@ public class UserFragment extends BackHandledFragment {
});
mShortAnimationDuration = getResources().getInteger(android.R.integer.config_shortAnimTime);
final List<Role> roleList = user.getUserRoles();
final List<Body> bodyList = user.getUserFollowedBodies();
final List<Event> eventList = user.getUserGoingEvents();
List<Role> formerRoleList = user.getUserFormerRoles();
for (Role role : formerRoleList) {
role.setRoleName("Former " + role.getRoleName());
if (!showingMin) {
/* Show tabs */
getActivity().findViewById(R.id.tab_layout).setVisibility(VISIBLE);
/* Load lists */
final List<Role> roleList = user.getUserRoles();
final List<Body> bodyList = user.getUserFollowedBodies();
final List<Event> eventList = user.getUserGoingEvents();
List<Role> formerRoleList = user.getUserFormerRoles();
for (Role role : formerRoleList) {
role.setRoleName("Former " + role.getRoleName());
}
roleList.addAll(formerRoleList);
List<Event> eventInterestedList = user.getUserInterestedEvents();
eventList.removeAll(eventInterestedList);
eventList.addAll(eventInterestedList);
RoleRecyclerViewFragment frag1 = RoleRecyclerViewFragment.newInstance(roleList);
BodyRecyclerViewFragment frag2 = BodyRecyclerViewFragment.newInstance(bodyList);
EventRecyclerViewFragment frag3 = EventRecyclerViewFragment.newInstance(eventList);
frag1.parentFragment = this;
frag2.parentFragment = this;
frag3.parentFragment = this;
TabAdapter tabAdapter = new TabAdapter(getChildFragmentManager());
tabAdapter.addFragment(frag1, "Associations");
tabAdapter.addFragment(frag2, "Following");
tabAdapter.addFragment(frag3, "Events");
// Set up the ViewPager with the sections adapter.
ViewPager viewPager = (ViewPager) getActivity().findViewById(R.id.viewPager);
viewPager.setAdapter(tabAdapter);
viewPager.setOffscreenPageLimit(2);
TabLayout tabLayout = (TabLayout) getActivity().findViewById(R.id.tab_layout);
tabLayout.setupWithViewPager(viewPager);
}
roleList.addAll(formerRoleList);
List<Event> eventInterestedList = user.getUserInterestedEvents();
eventList.removeAll(eventInterestedList);
eventList.addAll(eventInterestedList);
RoleRecyclerViewFragment frag1 = RoleRecyclerViewFragment.newInstance(roleList);
BodyRecyclerViewFragment frag2 = BodyRecyclerViewFragment.newInstance(bodyList);
EventRecyclerViewFragment frag3 = EventRecyclerViewFragment.newInstance(eventList);
TabAdapter tabAdapter = new TabAdapter(getChildFragmentManager());
tabAdapter.addFragment(frag1, "Associations");
tabAdapter.addFragment(frag2, "Following");
tabAdapter.addFragment(frag3, "Events");
// Set up the ViewPager with the sections adapter.
ViewPager viewPager = (ViewPager) getActivity().findViewById(R.id.viewPager);
viewPager.setAdapter(tabAdapter);
viewPager.setOffscreenPageLimit(2);
TabLayout tabLayout = (TabLayout) getActivity().findViewById(R.id.tab_layout);
tabLayout.setupWithViewPager(viewPager);
userNameTextView.setText(user.getUserName());
userRollNumberTextView.setText(user.getUserRollNumber());
if (!user.getUserEmail().equals("N/A")) {
if (user.getUserEmail() != null && !user.getUserEmail().equals("N/A")) {
userEmailIDTextView.setText(user.getUserEmail());
} else {
userEmailIDTextView.setText(user.getUserRollNumber() + "@iitb.ac.in");
if (user.getUserRollNumber() != null)
userEmailIDTextView.setText(user.getUserRollNumber() + "@iitb.ac.in");
}
userContactNumberTextView.setText(user.getUserContactNumber());
userEmailIDTextView.setOnClickListener(new View.OnClickListener() {
@Override
......@@ -191,6 +220,7 @@ public class UserFragment extends BackHandledFragment {
});
if (user.getUserContactNumber() != null) {
userContactNumberTextView.setText(user.getUserContactNumber());
userContactNumberTextView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
......@@ -212,8 +242,6 @@ public class UserFragment extends BackHandledFragment {
}
});
userShareImageButton.setVisibility(VISIBLE);
getActivity().findViewById(R.id.loadingPanel).setVisibility(View.GONE);
}
private void call(String contactNumber) {
......
This diff is collapsed.
This diff is collapsed.
......@@ -2,7 +2,8 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="app.insti.fragment.NewsFragment">
tools:context="app.insti.fragment.NewsFragment"
android:background="?attr/themeColor">
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/news_swipe_refresh_layout"
......
......@@ -2,6 +2,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/themeColor"
tools:context="app.insti.fragment.PlacementBlogFragment">
<android.support.v4.widget.SwipeRefreshLayout
......
......@@ -2,6 +2,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/themeColor"
tools:context="app.insti.fragment.TrainingBlogFragment">
<android.support.v4.widget.SwipeRefreshLayout
......
......@@ -7,7 +7,8 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="app.insti.fragment.UserFragment">
tools:context="app.insti.fragment.UserFragment"
android:background="?attr/themeColor">
<RelativeLayout
android:layout_width="match_parent"
......@@ -18,7 +19,8 @@
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_margin="20dp"
android:layout_marginRight="15dp" />
android:layout_marginRight="15dp"
android:transitionName="sharedAvatar" />
<LinearLayout
android:layout_width="wrap_content"
......
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