Commit 2bbec9de authored by Varun Patil's avatar Varun Patil

Add SharedElement avatar

parent 21c7f971
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());
}
}
...@@ -4,9 +4,13 @@ import android.content.Context; ...@@ -4,9 +4,13 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
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.Fragment;
import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction; import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.Toast; import android.widget.Toast;
...@@ -14,6 +18,9 @@ import com.google.gson.Gson; ...@@ -14,6 +18,9 @@ import com.google.gson.Gson;
import com.squareup.picasso.Callback; import com.squareup.picasso.Callback;
import com.squareup.picasso.Picasso; import com.squareup.picasso.Picasso;
import java.util.HashMap;
import java.util.Map;
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.Body; import app.insti.api.model.Body;
...@@ -21,6 +28,7 @@ import app.insti.api.model.Event; ...@@ -21,6 +28,7 @@ import app.insti.api.model.Event;
import app.insti.api.model.User; import app.insti.api.model.User;
import app.insti.fragment.BodyFragment; import app.insti.fragment.BodyFragment;
import app.insti.fragment.EventFragment; import app.insti.fragment.EventFragment;
import app.insti.fragment.TransitionTargetFragment;
import app.insti.fragment.UserFragment; import app.insti.fragment.UserFragment;
public final class Utils { public final class Utils {
...@@ -71,29 +79,108 @@ public final class Utils { ...@@ -71,29 +79,108 @@ public final class Utils {
ft.commit(); ft.commit();
} }
public static void openBodyFragment(Body body, FragmentActivity fragmentActivity) { public static void updateSharedElementFragment(final TransitionTargetFragment ttFragment, Fragment currentFragment, Map<View, String> sharedElements) {
Fragment fragment = (Fragment) ttFragment;
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(new DetailsTransition());
transition.addListener(new Transition.TransitionListener() {
@Override
public void onTransitionStart(Transition transition) {
}
@Override
public void onTransitionEnd(Transition transition) {
ttFragment.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 bundle = new Bundle();
bundle.putString(Constants.BODY_JSON, new Gson().toJson(body)); bundle.putString(Constants.BODY_JSON, new Gson().toJson(body));
BodyFragment bodyFragment = new BodyFragment(); BodyFragment bodyFragment = new BodyFragment();
bodyFragment.setArguments(bundle); 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) {
String eventJson = new Gson().toJson(event); String eventJson = new Gson().toJson(event);
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putString(Constants.EVENT_JSON, eventJson); bundle.putString(Constants.EVENT_JSON, eventJson);
EventFragment eventFragment = new EventFragment(); EventFragment eventFragment = new EventFragment();
eventFragment.setArguments(bundle); eventFragment.setArguments(bundle);
updateFragment(eventFragment, fragmentActivity); return eventFragment;
} }
public static void openUserFragment(User user, FragmentActivity fragmentActivity) { public static void openEventFragment(Event event, FragmentActivity fragmentActivity) {
updateFragment(getEventFragment(event), fragmentActivity);
}
public static void openEventFragment(Event event, Fragment currentFragment, View sharedAvatar) {
Map<View, String> sharedElements = new HashMap<>();
sharedElements.put(sharedAvatar, "sharedAvatar");
updateSharedElementFragment(
getEventFragment(event), currentFragment, sharedElements
);
}
public static UserFragment getUserFragment(User user) {
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putString(Constants.USER_ID, user.getUserID()); bundle.putString(Constants.USER_ID, user.getUserID());
UserFragment userFragment = new UserFragment(); UserFragment userFragment = new UserFragment();
userFragment.setArguments(bundle); userFragment.setArguments(bundle);
updateFragment(userFragment, fragmentActivity); return userFragment;
}
public static void openUserFragment(User user, FragmentActivity fragmentActivity) {
updateFragment(getUserFragment(user), fragmentActivity);
}
public static void openUserFragment(User user, Fragment currentFragment, View sharedAvatar) {
Map<View, String> sharedElements = new HashMap<>();
sharedElements.put(sharedAvatar, "sharedAvatar");
updateSharedElementFragment(
getUserFragment(user), currentFragment, sharedElements
);
} }
public static void setSessionId(String sessionId1) { public static void setSessionId(String sessionId1) {
......
package app.insti.adapter; package app.insti.adapter;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity; import android.view.View;
import java.util.List; import java.util.List;
import app.insti.R;
import app.insti.Utils; import app.insti.Utils;
import app.insti.api.model.Body; import app.insti.api.model.Body;
...@@ -15,7 +16,7 @@ public class BodyAdapter extends CardAdapter<Body> { ...@@ -15,7 +16,7 @@ public class BodyAdapter extends CardAdapter<Body> {
super(bodyList, mFragment); super(bodyList, mFragment);
} }
public void onClick(Body body, FragmentActivity fragmentActivity) { public void onClick(Body body, Fragment fragment, View view) {
Utils.openBodyFragment(body, fragmentActivity); Utils.openBodyFragment(body, fragment, view.findViewById(R.id.object_picture));
} }
} }
...@@ -25,7 +25,8 @@ public abstract class CardAdapter<T extends CardInterface> extends RecyclerView. ...@@ -25,7 +25,8 @@ public abstract class CardAdapter<T extends CardInterface> extends RecyclerView.
private List<T> tList; private List<T> tList;
private Fragment mFragment; 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) { public String getBigImageUrl(T t) {
return null; return null;
...@@ -52,6 +53,7 @@ public abstract class CardAdapter<T extends CardInterface> extends RecyclerView. ...@@ -52,6 +53,7 @@ public abstract class CardAdapter<T extends CardInterface> extends RecyclerView.
@Override @Override
public void onClick(View view) { public void onClick(View view) {
CardAdapter.this.onClick(tList.get(postViewHolder.getAdapterPosition()), mFragment.getActivity()); CardAdapter.this.onClick(tList.get(postViewHolder.getAdapterPosition()), mFragment.getActivity());
CardAdapter.this.onClick(tList.get(postViewHolder.getAdapterPosition()), mFragment, view);
} }
}); });
...@@ -64,9 +66,13 @@ public abstract class CardAdapter<T extends CardInterface> extends RecyclerView. ...@@ -64,9 +66,13 @@ public abstract class CardAdapter<T extends CardInterface> extends RecyclerView.
viewHolder.title.setText(t.getTitle()); viewHolder.title.setText(t.getTitle());
viewHolder.subtitle.setText(t.getSubtitle()); viewHolder.subtitle.setText(t.getSubtitle());
// Set transition names
viewHolder.avatar.setTransitionName(Integer.toString(t.getTitle().hashCode()) + "_sharedAvatar");
if (getBigImageUrl(t) != null) { if (getBigImageUrl(t) != null) {
// Show big image, hide avatar // Show big image, hide avatar
viewHolder.bigPicture.setVisibility(View.VISIBLE); viewHolder.bigPicture.setVisibility(View.VISIBLE);
viewHolder.bigPicture.setTransitionName(Integer.toString(t.getTitle().hashCode()) + "_sharedBigPicture");
viewHolder.avatar.setVisibility(View.GONE); viewHolder.avatar.setVisibility(View.GONE);
// Load big image with low resolution as avatar // Load big image with low resolution as avatar
......
...@@ -2,6 +2,7 @@ package app.insti.adapter; ...@@ -2,6 +2,7 @@ package app.insti.adapter;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentActivity;
import android.view.View;
import java.util.List; import java.util.List;
...@@ -10,14 +11,20 @@ import app.insti.Utils; ...@@ -10,14 +11,20 @@ import app.insti.Utils;
import app.insti.api.model.Event; import app.insti.api.model.Event;
public class FeedAdapter extends CardAdapter<Event> { public class FeedAdapter extends CardAdapter<Event> {
public FeedAdapter(List<Event> eventList, Fragment fragment) { public FeedAdapter(List<Event> eventList, Fragment fragment) {
super(eventList, fragment); super(eventList, fragment);
} }
@Override @Override
public void onClick(Event event, FragmentActivity fragmentActivity) { public void onClick(Event event, FragmentActivity fragmentActivity) {}
Utils.openEventFragment(event, 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 @Override
......
package app.insti.adapter; package app.insti.adapter;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity; import android.view.View;
import java.util.List; import java.util.List;
...@@ -13,19 +13,18 @@ import app.insti.api.model.User; ...@@ -13,19 +13,18 @@ import app.insti.api.model.User;
import app.insti.interfaces.CardInterface; import app.insti.interfaces.CardInterface;
public class GenericAdapter extends CardAdapter<CardInterface> { public class GenericAdapter extends CardAdapter<CardInterface> {
public GenericAdapter(List<CardInterface> cardInterfaceList, Fragment fragment){ public GenericAdapter(List<CardInterface> cardInterfaceList, Fragment fragment){
super(cardInterfaceList, fragment); super(cardInterfaceList, fragment);
} }
@Override @Override
public void onClick(CardInterface cardInterface, FragmentActivity fragmentActivity) { public void onClick(CardInterface cardInterface, Fragment fragment, View view) {
if (cardInterface instanceof Event) { 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) { } 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) { } 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; package app.insti.adapter;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity; import android.view.View;
import java.util.List; import java.util.List;
import app.insti.R;
import app.insti.Utils; import app.insti.Utils;
import app.insti.api.model.Role; import app.insti.api.model.Role;
...@@ -16,7 +17,7 @@ public class RoleAdapter extends CardAdapter<Role> { ...@@ -16,7 +17,7 @@ public class RoleAdapter extends CardAdapter<Role> {
} }
@Override @Override
public void onClick(Role role, FragmentActivity fragmentActivity) { public void onClick(Role role, Fragment fragment, View view) {
Utils.openBodyFragment(role.getRoleBodyDetails(), fragmentActivity); Utils.openBodyFragment(role.getRoleBodyDetails(), fragment, view.findViewById(R.id.object_picture));
} }
} }
package app.insti.adapter; package app.insti.adapter;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity; import android.view.View;
import java.util.List; import java.util.List;
...@@ -16,8 +16,8 @@ public class UserAdapter extends CardAdapter<User> { ...@@ -16,8 +16,8 @@ public class UserAdapter extends CardAdapter<User> {
} }
@Override @Override
public void onClick(User user, FragmentActivity fragmentActivity) { public void onClick(User user, Fragment fragment, View view) {
Utils.openUserFragment(user, fragmentActivity); Utils.openUserFragment(user, fragment, view.findViewById(R.id.object_picture));
} }
@Override @Override
......
...@@ -29,8 +29,8 @@ import android.widget.TextView; ...@@ -29,8 +29,8 @@ import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.squareup.picasso.Picasso;
import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
...@@ -57,7 +57,7 @@ import ru.noties.markwon.Markwon; ...@@ -57,7 +57,7 @@ import ru.noties.markwon.Markwon;
* Use the {@link BodyFragment#newInstance} factory method to * Use the {@link BodyFragment#newInstance} factory method to
* create an instance of this fragment. * 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 // TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
...@@ -83,6 +83,7 @@ public class BodyFragment extends BackHandledFragment { ...@@ -83,6 +83,7 @@ public class BodyFragment extends BackHandledFragment {
private ImageView bodyPicture; private ImageView bodyPicture;
private Body body; private Body body;
private boolean bodyDisplayed = false; private boolean bodyDisplayed = false;
private boolean transitionEnded = false;
public BodyFragment() { public BodyFragment() {
// Required empty public constructor // Required empty public constructor
...@@ -122,6 +123,13 @@ public class BodyFragment extends BackHandledFragment { ...@@ -122,6 +123,13 @@ public class BodyFragment extends BackHandledFragment {
} }
} }
@Override
public void transitionEnd() {
bodyPicture = (ImageView) getActivity().findViewById(R.id.body_picture);
Utils.loadImageWithPlaceholder(bodyPicture, body.getBodyImageURL());
transitionEnded = true;
}
@Override @Override
public void onStart() { public void onStart() {
super.onStart(); super.onStart();
...@@ -201,7 +209,14 @@ public class BodyFragment extends BackHandledFragment { ...@@ -201,7 +209,14 @@ public class BodyFragment extends BackHandledFragment {
/* Set body information */ /* Set body information */
bodyName.setText(body.getBodyName()); bodyName.setText(body.getBodyName());
bodySubtitle.setText(body.getBodyShortDescription()); bodySubtitle.setText(body.getBodyShortDescription());
/* Load only low res image if transition is not completed */
if (transitionEnded) {
Utils.loadImageWithPlaceholder(bodyPicture, body.getBodyImageURL()); Utils.loadImageWithPlaceholder(bodyPicture, body.getBodyImageURL());
} else {
Picasso.get().load(Utils.resizeImageUrl(body.getBodyImageURL())).into(bodyPicture);
}
bodyPicture.setOnClickListener(new View.OnClickListener() { bodyPicture.setOnClickListener(new View.OnClickListener() {
@Override @Override
......
...@@ -33,6 +33,7 @@ import android.widget.TextView; ...@@ -33,6 +33,7 @@ import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.squareup.picasso.Picasso;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
...@@ -57,7 +58,7 @@ import ru.noties.markwon.Markwon; ...@@ -57,7 +58,7 @@ import ru.noties.markwon.Markwon;
/** /**
* A simple {@link Fragment} subclass. * A simple {@link Fragment} subclass.
*/ */
public class EventFragment extends BackHandledFragment { public class EventFragment extends BackHandledFragment implements TransitionTargetFragment {
Event event; Event event;
Button goingButton; Button goingButton;
Button interestedButton; Button interestedButton;
...@@ -86,6 +87,11 @@ public class EventFragment extends BackHandledFragment { ...@@ -86,6 +87,11 @@ public class EventFragment extends BackHandledFragment {
// Required empty public constructor // Required empty public constructor
} }
@Override
public void transitionEnd() {
Utils.loadImageWithPlaceholder(eventPicture, event.getEventImageURL());
}
/** /**
* Get a spannable with a small count badge to set for an element text * Get a spannable with a small count badge to set for an element text
* *
...@@ -152,7 +158,11 @@ public class EventFragment extends BackHandledFragment { ...@@ -152,7 +158,11 @@ public class EventFragment extends BackHandledFragment {
webEventButton = getActivity().findViewById(R.id.web_event_button); webEventButton = getActivity().findViewById(R.id.web_event_button);
shareEventButton = getActivity().findViewById(R.id.share_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()); eventTitle.setText(event.getEventName());
Markwon.setMarkdown(eventDescription, event.getEventDescription()); Markwon.setMarkdown(eventDescription, event.getEventDescription());
......
package app.insti.fragment;
public interface TransitionTargetFragment {
void transitionEnd();
}
...@@ -14,8 +14,6 @@ import android.os.Bundle; ...@@ -14,8 +14,6 @@ import android.os.Bundle;
import android.support.design.widget.TabLayout; import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager; 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.support.v7.widget.Toolbar;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
...@@ -33,14 +31,12 @@ import app.insti.Constants; ...@@ -33,14 +31,12 @@ import app.insti.Constants;
import app.insti.R; import app.insti.R;
import app.insti.ShareURLMaker; import app.insti.ShareURLMaker;
import app.insti.Utils; import app.insti.Utils;
import app.insti.adapter.RoleAdapter;
import app.insti.adapter.TabAdapter; import app.insti.adapter.TabAdapter;
import app.insti.api.RetrofitInterface; import app.insti.api.RetrofitInterface;
import app.insti.api.model.Body; import app.insti.api.model.Body;
import app.insti.api.model.Event; import app.insti.api.model.Event;
import app.insti.api.model.Role; import app.insti.api.model.Role;
import app.insti.api.model.User; import app.insti.api.model.User;
import app.insti.interfaces.ItemClickListener;
import retrofit2.Call; import retrofit2.Call;
import retrofit2.Callback; import retrofit2.Callback;
import retrofit2.Response; import retrofit2.Response;
...@@ -50,7 +46,7 @@ import static android.view.View.VISIBLE; ...@@ -50,7 +46,7 @@ import static android.view.View.VISIBLE;
/** /**
* A simple {@link Fragment} subclass. * A simple {@link Fragment} subclass.
*/ */
public class UserFragment extends BackHandledFragment { public class UserFragment extends BackHandledFragment implements TransitionTargetFragment {
private User user; private User user;
// Hold a reference to the current animator, // Hold a reference to the current animator,
...@@ -86,6 +82,9 @@ public class UserFragment extends BackHandledFragment { ...@@ -86,6 +82,9 @@ public class UserFragment extends BackHandledFragment {
return inflater.inflate(R.layout.fragment_user, container, false); return inflater.inflate(R.layout.fragment_user, container, false);
} }
@Override
public void transitionEnd() {}
@Override @Override
public boolean onBackPressed() { public boolean onBackPressed() {
if (zoomMode) { if (zoomMode) {
......
...@@ -35,7 +35,8 @@ ...@@ -35,7 +35,8 @@
android:layout_height="0dp" android:layout_height="0dp"
android:layout_weight="1" android:layout_weight="1"
android:adjustViewBounds="true" android:adjustViewBounds="true"
android:scaleType="fitCenter" /> android:scaleType="fitCenter"
android:transitionName="sharedAvatar" />
<android.support.v7.widget.CardView <android.support.v7.widget.CardView
android:layout_width="match_parent" android:layout_width="match_parent"
......
...@@ -31,7 +31,8 @@ ...@@ -31,7 +31,8 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="300dp" android:layout_height="300dp"
android:adjustViewBounds="true" android:adjustViewBounds="true"
android:scaleType="centerCrop" /> android:scaleType="centerCrop"
android:transitionName="sharedAvatar" />
<android.support.v7.widget.CardView <android.support.v7.widget.CardView
android:layout_width="match_parent" android:layout_width="match_parent"
......
...@@ -18,7 +18,8 @@ ...@@ -18,7 +18,8 @@
android:layout_width="100dp" android:layout_width="100dp"
android:layout_height="100dp" android:layout_height="100dp"
android:layout_margin="20dp" android:layout_margin="20dp"
android:layout_marginRight="15dp" /> android:layout_marginRight="15dp"
android:transitionName="sharedAvatar" />
<LinearLayout <LinearLayout
android:layout_width="wrap_content" 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