Commit 99e7df5a authored by Nihal Singh's avatar Nihal Singh Committed by Varun Patil

Updated gitignore. EventFragment refactor UES

parent fed8e5aa
*.iml *.iml
.gradle .gradle
/local.properties /local.properties
/.idea/workspace.xml /.idea/workspace.xml
/.idea/libraries /.idea/libraries
/.idea/gradle.xml
/.idea/modules.xml
/.idea/caches
.DS_Store .DS_Store
/build /build
/captures /captures
.externalNativeBuild .externalNativeBuild
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
<option value="$PROJECT_DIR$/app" />
</set>
</option>
<option name="resolveModulePerSourceSet" value="false" />
</GradleProjectSettings>
</option>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/IITB-App.iml" filepath="$PROJECT_DIR$/IITB-App.iml" />
<module fileurl="file://$PROJECT_DIR$/IITBApp.iml" filepath="$PROJECT_DIR$/IITBApp.iml" />
<module fileurl="file://$PROJECT_DIR$/InstiApp.iml" filepath="$PROJECT_DIR$/InstiApp.iml" />
<module fileurl="file://$PROJECT_DIR$/InstiApp2.iml" filepath="$PROJECT_DIR$/InstiApp2.iml" />
<module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
</modules>
</component>
</project>
\ No newline at end of file
...@@ -11,15 +11,6 @@ import android.graphics.Point; ...@@ -11,15 +11,6 @@ import android.graphics.Point;
import android.graphics.Rect; import android.graphics.Rect;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import androidx.annotation.NonNull;
import com.google.android.material.appbar.AppBarLayout;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import androidx.fragment.app.Fragment;
import androidx.core.widget.NestedScrollView;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.appcompat.widget.Toolbar;
import android.text.Spannable; import android.text.Spannable;
import android.text.SpannableString; import android.text.SpannableString;
import android.text.Spanned; import android.text.Spanned;
...@@ -38,6 +29,8 @@ import android.widget.ImageView; ...@@ -38,6 +29,8 @@ import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.squareup.picasso.Picasso; import com.squareup.picasso.Picasso;
...@@ -46,6 +39,13 @@ import java.text.SimpleDateFormat; ...@@ -46,6 +39,13 @@ import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import androidx.annotation.NonNull;
import androidx.appcompat.widget.Toolbar;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.core.widget.NestedScrollView;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import app.insti.Constants; import app.insti.Constants;
import app.insti.R; import app.insti.R;
import app.insti.ShareURLMaker; import app.insti.ShareURLMaker;
...@@ -65,10 +65,10 @@ import ru.noties.markwon.Markwon; ...@@ -65,10 +65,10 @@ import ru.noties.markwon.Markwon;
* A simple {@link Fragment} subclass. * A simple {@link Fragment} subclass.
*/ */
public class EventFragment extends BackHandledFragment implements TransitionTargetFragment { public class EventFragment extends BackHandledFragment implements TransitionTargetFragment {
public String TAG = "EventFragment";
private Event event; private Event event;
private Button goingButton; private Button goingButton;
private Button interestedButton; private Button interestedButton;
public String TAG = "EventFragment";
private int appBarOffset = 0; private int appBarOffset = 0;
private boolean creatingView = false; private boolean creatingView = false;
...@@ -91,12 +91,6 @@ public class EventFragment extends BackHandledFragment implements TransitionTarg ...@@ -91,12 +91,6 @@ public class EventFragment extends BackHandledFragment implements TransitionTarg
// Required empty public constructor // 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 * Get a spannable with a small count badge to set for an element text
* *
...@@ -118,6 +112,12 @@ public class EventFragment extends BackHandledFragment implements TransitionTarg ...@@ -118,6 +112,12 @@ public class EventFragment extends BackHandledFragment implements TransitionTarg
return spannable; return spannable;
} }
@Override
public void transitionEnd() {
if (getActivity() == null || getView() == null) return;
Utils.loadImageWithPlaceholder(eventPicture, event.getEventImageURL());
}
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { Bundle savedInstanceState) {
...@@ -159,7 +159,9 @@ public class EventFragment extends BackHandledFragment implements TransitionTarg ...@@ -159,7 +159,9 @@ public class EventFragment extends BackHandledFragment implements TransitionTarg
setupAppBarLayout(); setupAppBarLayout();
} }
/** Initialize app bar layout */ /**
* Initialize app bar layout
*/
private void setupAppBarLayout() { private void setupAppBarLayout() {
// Set the behavior // Set the behavior
AppBarLayout mAppBarLayout = getView().findViewById(R.id.appBar); AppBarLayout mAppBarLayout = getView().findViewById(R.id.appBar);
...@@ -182,8 +184,10 @@ public class EventFragment extends BackHandledFragment implements TransitionTarg ...@@ -182,8 +184,10 @@ public class EventFragment extends BackHandledFragment implements TransitionTarg
}); });
} }
/** Set appbar to have an offset */ /**
private void setAppBarOffset(int offsetPx){ * Set appbar to have an offset
*/
private void setAppBarOffset(int offsetPx) {
AppBarLayout mAppBarLayout = getView().findViewById(R.id.appBar); AppBarLayout mAppBarLayout = getView().findViewById(R.id.appBar);
CoordinatorLayout mCoordinatorLayour = getView().findViewById(R.id.coordinator); CoordinatorLayout mCoordinatorLayour = getView().findViewById(R.id.coordinator);
CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) mAppBarLayout.getLayoutParams(); CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) mAppBarLayout.getLayoutParams();
...@@ -265,11 +269,11 @@ public class EventFragment extends BackHandledFragment implements TransitionTarg ...@@ -265,11 +269,11 @@ public class EventFragment extends BackHandledFragment implements TransitionTarg
eventDate.setText(TextUtils.concat(timing)); eventDate.setText(TextUtils.concat(timing));
} }
interestedButton.setOnClickListener(getUESOnClickListener(1)); interestedButton.setOnClickListener(getInterestedButtonOnClickListener());
goingButton.setOnClickListener(getUESOnClickListener(2)); goingButton.setOnClickListener(getGoingButtonOnClickListener());
setFollowButtons(event.getEventUserUes()); updateGoingInterestedButtonsAppearance(event.getEventUserUes());
if (!event.getEventVenues().isEmpty()) { if (!event.getEventVenues().isEmpty()) {
if (event.getEventVenues().get(0).getVenueLatitude() == 0) { if (event.getEventVenues().get(0).getVenueLatitude() == 0) {
...@@ -348,202 +352,237 @@ public class EventFragment extends BackHandledFragment implements TransitionTarg ...@@ -348,202 +352,237 @@ public class EventFragment extends BackHandledFragment implements TransitionTarg
}); });
} }
/** Setup button colors depending on status */ private void updateButtonColors(int status) {
private void setFollowButtons(int status) {
// Set colors
Utils.setupFollowButton(getContext(), interestedButton, status == Constants.STATUS_INTERESTED); Utils.setupFollowButton(getContext(), interestedButton, status == Constants.STATUS_INTERESTED);
Utils.setupFollowButton(getContext(), goingButton, status == Constants.STATUS_GOING); Utils.setupFollowButton(getContext(), goingButton, status == Constants.STATUS_GOING);
}
// Show badges private void updateButtonBadges() {
interestedButton.setText(getCountBadgeSpannable("INTERESTED", event.getEventInterestedCount())); interestedButton.setText(getCountBadgeSpannable("INTERESTED", event.getEventInterestedCount()));
goingButton.setText(getCountBadgeSpannable("GOING", event.getEventGoingCount())); goingButton.setText(getCountBadgeSpannable("GOING", event.getEventGoingCount()));
} }
private View.OnClickListener getUESOnClickListener(final int status) { private void updateGoingInterestedButtonsAppearance(int status) {
updateButtonColors(status);
updateButtonBadges();
}
private View.OnClickListener getGoingButtonOnClickListener() {
return new View.OnClickListener() { return new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View v) {
final int endStatus = event.getEventUserUes() == status ? 0 : status; int currentStatus = event.getEventUserUes();
final int finalStatus;
if (currentStatus == Constants.STATUS_GOING) {
event.setEventGoingCount(event.getEventGoingCount() - 1);
finalStatus = Constants.STATUS_NOT_GOING;
} else if (currentStatus == Constants.STATUS_INTERESTED) {
event.setEventInterestedCount(event.getEventInterestedCount() - 1);
event.setEventGoingCount(event.getEventGoingCount() + 1);
finalStatus = Constants.STATUS_GOING;
} else {
event.setEventGoingCount(event.getEventGoingCount() + 1);
finalStatus = Constants.STATUS_GOING;
}
RetrofitInterface retrofitInterface = Utils.getRetrofitInterface(); RetrofitInterface retrofitInterface = Utils.getRetrofitInterface();
retrofitInterface.updateUserEventStatus(Utils.getSessionIDHeader(), event.getEventID(), endStatus).enqueue(new Callback<Void>() { retrofitInterface.updateUserEventStatus(Utils.getSessionIDHeader(), event.getEventID(), finalStatus).enqueue(new Callback<Void>() {
@Override @Override
public void onResponse(Call<Void> call, Response<Void> response) { public void onResponse(Call<Void> call, Response<Void> response) {
if (response.isSuccessful()) { event.setEventUserUes(finalStatus);
/* TODO: Find a better way to change counts */ updateGoingInterestedButtonsAppearance(finalStatus);
if (endStatus == 0) {
if (event.getEventUserUes() == 1) {
event.setEventInterestedCount(event.getEventInterestedCount() - 1);
}
if (event.getEventUserUes() == 2) {
event.setEventGoingCount(event.getEventGoingCount() - 1);
}
} else if (endStatus == 1) {
if (event.getEventUserUes() != 1) {
event.setEventInterestedCount(event.getEventInterestedCount() + 1);
}
if (event.getEventUserUes() == 2) {
event.setEventGoingCount(event.getEventGoingCount() - 1);
}
} else if (endStatus == 2) {
if (event.getEventUserUes() != 2) {
event.setEventGoingCount(event.getEventGoingCount() + 1);
}
if (event.getEventUserUes() == 1) {
event.setEventInterestedCount(event.getEventInterestedCount() - 1);
}
}
event.setEventUserUes(endStatus);
setFollowButtons(endStatus);
// Update global memory cache // Update global memory cache
Utils.eventCache.updateCache(event); Utils.eventCache.updateCache(event);
}
} }
@Override @Override
public void onFailure(Call<Void> call, Throwable t) { public void onFailure(Call<Void> call, Throwable t) {
Toast.makeText(getContext(), "Network Error", Toast.LENGTH_LONG).show(); Toast.makeText(getContext(), "Network Error", Toast.LENGTH_LONG).show();
} }
}); });
} }
}; };
} }
private void zoomImageFromThumb(final ImageView thumbView) { private View.OnClickListener getInterestedButtonOnClickListener () {
// If there's an animation in progress, cancel it return new View.OnClickListener() {
// immediately and proceed with this one. @Override
if (mCurrentAnimator != null) { public void onClick(View v) {
mCurrentAnimator.cancel(); int currentStatus = event.getEventUserUes();
} final int finalStatus;
if (currentStatus == Constants.STATUS_INTERESTED) {
event.setEventInterestedCount(event.getEventInterestedCount() - 1);
finalStatus = Constants.STATUS_NOT_GOING;
} else if (currentStatus == Constants.STATUS_GOING) {
event.setEventInterestedCount(event.getEventInterestedCount() + 1);
event.setEventGoingCount(event.getEventGoingCount() - 1);
finalStatus = Constants.STATUS_INTERESTED;
} else {
event.setEventGoingCount(event.getEventInterestedCount() + 1);
finalStatus = Constants.STATUS_INTERESTED;
}
// Load the high-resolution "zoomed-in" image. RetrofitInterface retrofitInterface = Utils.getRetrofitInterface();
expandedImageView = (ImageView) getActivity().findViewById( retrofitInterface.updateUserEventStatus(Utils.getSessionIDHeader(), event.getEventID(), finalStatus).enqueue(new Callback<Void>() {
R.id.expanded_image_event); @Override
expandedImageView.setImageDrawable(thumbView.getDrawable()); public void onResponse(Call<Void> call, Response<Void> response) {
event.setEventUserUes(finalStatus);
// Calculate the starting and ending bounds for the zoomed-in image. updateGoingInterestedButtonsAppearance(finalStatus);
// This step involves lots of math. Yay, math.
startBounds = new Rect(); // Update global memory cache
final Rect finalBounds = new Rect(); Utils.eventCache.updateCache(event);
final Point globalOffset = new Point(); }
// The start bounds are the global visible rectangle of the thumbnail, @Override
// and the final bounds are the global visible rectangle of the container public void onFailure(Call<Void> call, Throwable t) {
// view. Also set the container view's offset as the origin for the Toast.makeText(getContext(), "Network Error", Toast.LENGTH_LONG).show();
// bounds, since that's the origin for the positioning animation }
// properties (X, Y).
thumbView.getGlobalVisibleRect(startBounds); });
getActivity().findViewById(R.id.container_event) }
.getGlobalVisibleRect(finalBounds, globalOffset); };
startBounds.offset(-globalOffset.x, -globalOffset.y);
finalBounds.offset(-globalOffset.x, -globalOffset.y);
// Adjust the start bounds to be the same aspect ratio as the final
// bounds using the "center crop" technique. This prevents undesirable
// stretching during the animation. Also calculate the start scaling
// factor (the end scaling factor is always 1.0).
float startScale;
if ((float) finalBounds.width() / finalBounds.height()
> (float) startBounds.width() / startBounds.height()) {
// Extend start bounds horizontally
startScale = (float) startBounds.height() / finalBounds.height();
float startWidth = startScale * finalBounds.width();
float deltaWidth = (startWidth - startBounds.width()) / 2;
startBounds.left -= deltaWidth;
startBounds.right += deltaWidth;
} else {
// Extend start bounds vertically
startScale = (float) startBounds.width() / finalBounds.width();
float startHeight = startScale * finalBounds.height();
float deltaHeight = (startHeight - startBounds.height()) / 2;
startBounds.top -= deltaHeight;
startBounds.bottom += deltaHeight;
} }
// Hide the thumbnail and show the zoomed-in view. When the animation
// begins, it will position the zoomed-in view in the place of the private void zoomImageFromThumb ( final ImageView thumbView){
// thumbnail. // If there's an animation in progress, cancel it
thumbView.setAlpha(0f); // immediately and proceed with this one.
expandedImageView.setVisibility(View.VISIBLE); if (mCurrentAnimator != null) {
mCurrentAnimator.cancel();
// Set the pivot point for SCALE_X and SCALE_Y transformations
// to the top-left corner of the zoomed-in view (the default
// is the center of the view).
expandedImageView.setPivotX(0f);
expandedImageView.setPivotY(0f);
// Construct and run the parallel animation of the four translation and
// scale properties (X, Y, SCALE_X, and SCALE_Y).
AnimatorSet set = new AnimatorSet();
set
.play(ObjectAnimator.ofFloat(expandedImageView, View.X,
startBounds.left, finalBounds.left))
.with(ObjectAnimator.ofFloat(expandedImageView, View.Y,
startBounds.top, finalBounds.top))
.with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_X,
startScale, 1f))
.with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_Y,
startScale, 1f));
set.setDuration(mShortAnimationDuration);
set.setInterpolator(new DecelerateInterpolator());
set.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
mCurrentAnimator = null;
expandedImageView.setBackgroundColor(Color.parseColor("#9E9E9E"));
} }
@Override // Load the high-resolution "zoomed-in" image.
public void onAnimationCancel(Animator animation) { expandedImageView = (ImageView) getActivity().findViewById(
mCurrentAnimator = null; R.id.expanded_image_event);
expandedImageView.setImageDrawable(thumbView.getDrawable());
// Calculate the starting and ending bounds for the zoomed-in image.
// This step involves lots of math. Yay, math.
startBounds = new Rect();
final Rect finalBounds = new Rect();
final Point globalOffset = new Point();
// The start bounds are the global visible rectangle of the thumbnail,
// and the final bounds are the global visible rectangle of the container
// view. Also set the container view's offset as the origin for the
// bounds, since that's the origin for the positioning animation
// properties (X, Y).
thumbView.getGlobalVisibleRect(startBounds);
getActivity().findViewById(R.id.container_event)
.getGlobalVisibleRect(finalBounds, globalOffset);
startBounds.offset(-globalOffset.x, -globalOffset.y);
finalBounds.offset(-globalOffset.x, -globalOffset.y);
// Adjust the start bounds to be the same aspect ratio as the final
// bounds using the "center crop" technique. This prevents undesirable
// stretching during the animation. Also calculate the start scaling
// factor (the end scaling factor is always 1.0).
float startScale;
if ((float) finalBounds.width() / finalBounds.height()
> (float) startBounds.width() / startBounds.height()) {
// Extend start bounds horizontally
startScale = (float) startBounds.height() / finalBounds.height();
float startWidth = startScale * finalBounds.width();
float deltaWidth = (startWidth - startBounds.width()) / 2;
startBounds.left -= deltaWidth;
startBounds.right += deltaWidth;
} else {
// Extend start bounds vertically
startScale = (float) startBounds.width() / finalBounds.width();
float startHeight = startScale * finalBounds.height();
float deltaHeight = (startHeight - startBounds.height()) / 2;
startBounds.top -= deltaHeight;
startBounds.bottom += deltaHeight;
} }
});
set.start();
mCurrentAnimator = set;
startScaleFinal = startScale; // Hide the thumbnail and show the zoomed-in view. When the animation
zoomMode = true; // begins, it will position the zoomed-in view in the place of the
} // thumbnail.
thumbView.setAlpha(0f);
expandedImageView.setVisibility(View.VISIBLE);
// Set the pivot point for SCALE_X and SCALE_Y transformations
// to the top-left corner of the zoomed-in view (the default
// is the center of the view).
expandedImageView.setPivotX(0f);
expandedImageView.setPivotY(0f);
// Construct and run the parallel animation of the four translation and
// scale properties (X, Y, SCALE_X, and SCALE_Y).
AnimatorSet set = new AnimatorSet();
set
.play(ObjectAnimator.ofFloat(expandedImageView, View.X,
startBounds.left, finalBounds.left))
.with(ObjectAnimator.ofFloat(expandedImageView, View.Y,
startBounds.top, finalBounds.top))
.with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_X,
startScale, 1f))
.with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_Y,
startScale, 1f));
set.setDuration(mShortAnimationDuration);
set.setInterpolator(new DecelerateInterpolator());
set.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
mCurrentAnimator = null;
expandedImageView.setBackgroundColor(Color.parseColor("#9E9E9E"));
}
private void zoomOut(final ImageView expandedImageView, Rect startBounds, float startScaleFinal, final View thumbView) { @Override
expandedImageView.setBackgroundColor(0x00000000); public void onAnimationCancel(Animator animation) {
if (mCurrentAnimator != null) { mCurrentAnimator = null;
mCurrentAnimator.cancel(); }
});
set.start();
mCurrentAnimator = set;
startScaleFinal = startScale;
zoomMode = true;
} }
// Animate the four positioning/sizing properties in parallel, private void zoomOut ( final ImageView expandedImageView, Rect startBounds,
// back to their original values. float startScaleFinal, final View thumbView){
AnimatorSet set = new AnimatorSet(); expandedImageView.setBackgroundColor(0x00000000);
set.play(ObjectAnimator if (mCurrentAnimator != null) {
.ofFloat(expandedImageView, View.X, startBounds.left)) mCurrentAnimator.cancel();
.with(ObjectAnimator
.ofFloat(expandedImageView,
View.Y, startBounds.top))
.with(ObjectAnimator
.ofFloat(expandedImageView,
View.SCALE_X, startScaleFinal))
.with(ObjectAnimator
.ofFloat(expandedImageView,
View.SCALE_Y, startScaleFinal));
set.setDuration(mShortAnimationDuration);
set.setInterpolator(new DecelerateInterpolator());
set.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
thumbView.setAlpha(1f);
expandedImageView.setVisibility(View.GONE);
mCurrentAnimator = null;
} }
@Override // Animate the four positioning/sizing properties in parallel,
public void onAnimationCancel(Animator animation) { // back to their original values.
thumbView.setAlpha(1f); AnimatorSet set = new AnimatorSet();
expandedImageView.setVisibility(View.GONE); set.play(ObjectAnimator
mCurrentAnimator = null; .ofFloat(expandedImageView, View.X, startBounds.left))
} .with(ObjectAnimator
}); .ofFloat(expandedImageView,
set.start(); View.Y, startBounds.top))
mCurrentAnimator = set; .with(ObjectAnimator
.ofFloat(expandedImageView,
View.SCALE_X, startScaleFinal))
.with(ObjectAnimator
.ofFloat(expandedImageView,
View.SCALE_Y, startScaleFinal));
set.setDuration(mShortAnimationDuration);
set.setInterpolator(new DecelerateInterpolator());
set.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
thumbView.setAlpha(1f);
expandedImageView.setVisibility(View.GONE);
mCurrentAnimator = null;
}
@Override
public void onAnimationCancel(Animator animation) {
thumbView.setAlpha(1f);
expandedImageView.setVisibility(View.GONE);
mCurrentAnimator = null;
}
});
set.start();
mCurrentAnimator = set;
}
} }
}
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