Skip to content
This repository has been archived by the owner on Jan 15, 2024. It is now read-only.

Commit

Permalink
AppDetails Screenshot resizing and animation (#153)
Browse files Browse the repository at this point in the history
* Resize screenshot viewpager based on screenshot size
* Moved ScreenshotViewPager to details package
* Added screenshot animations
* Removed log and reverted auto formatting

Closes #141
  • Loading branch information
aadamsdev authored and d4rken committed Sep 30, 2017
1 parent c5294d1 commit 011e88c
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
import android.support.design.widget.CollapsingToolbarLayout;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.Toolbar;
import android.text.Html;
import android.text.method.LinkMovementMethod;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
Expand Down Expand Up @@ -67,10 +67,10 @@ public class AppDetailsFragment extends BasePresenterFragment<AppDetailsContract
@BindView(R.id.title_secondary) TextView secondaryTitle;
@BindView(R.id.tag_container) FlowLayout tagContainer;

@BindView(R.id.screenshot_pager) ViewPager screenshotPager;
@BindView(R.id.screenshot_pager) ScreenshotViewPager screenshotPager;
@BindView(R.id.description) TextView description;

private static final String REDDIT_MSG_URL_HEADER="https://www.reddit.com/message/compose/?to=/r/Android&subject=**RAS Flag Report**&message=";
private static final String REDDIT_MSG_URL_HEADER = "https://www.reddit.com/message/compose/?to=/r/Android&subject=**RAS Flag Report**&message=";

private List<String> contactItems = new ArrayList<>();
private List<String> downloadItems = new ArrayList<>();
Expand Down Expand Up @@ -121,7 +121,7 @@ public void onClick(DialogInterface dialogInterface, int i) {
if (flagMessage.getText().toString().isEmpty()) {
Toast.makeText(getContext(), getContext().getResources().getString(R.string.no_message), Toast.LENGTH_LONG).show();
} else {
openInChrome(REDDIT_MSG_URL_HEADER + "*****" + collapsingToolbar.getTitle() +" REPORT" + "*****" + "%0A" +(flagMessage.getText().toString().trim()));
openInChrome(REDDIT_MSG_URL_HEADER + "*****" + collapsingToolbar.getTitle() + " REPORT" + "*****" + "%0A" + (flagMessage.getText().toString().trim()));
}
}
})
Expand Down Expand Up @@ -329,7 +329,9 @@ public void displayIcon(@Nullable AppInfo appInfo) {

@Override
public void onScreenshotClicked(String url) {
new ScreenshotDialog(getContext(), screenshotUrls, screenshotUrls.indexOf(url)).show();
ScreenshotDialog dialog = new ScreenshotDialog(getContext(), screenshotUrls, screenshotUrls.indexOf(url));
dialog.getWindow().getAttributes().windowAnimations = R.style.ScreenshotDialogTheme;
dialog.show();
}

private void fadeHeaderItems(float scrollRange, int verticalOffset) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package subreddit.android.appstore.screens.details;

import android.content.Context;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.View;
import android.widget.ImageView;

import subreddit.android.appstore.R;
import subreddit.android.appstore.screens.details.ScreenshotsAdapter;

/**
* Created by andrewadams on 2017-09-29.
*/

public class ScreenshotViewPager extends ViewPager {
private ScreenshotsAdapter screenshotsAdapter;

public ScreenshotViewPager(Context context) {
super(context);
}

public ScreenshotViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
}

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
if (screenshotsAdapter != null) {
View currentView = screenshotsAdapter.getCurrentView();
if (currentView != null) {
ImageView imageView = (ImageView) currentView.findViewById(R.id.gallery_image);
Drawable drawable = imageView.getDrawable();
if (drawable != null) {
Rect drawableBounds = drawable.getBounds();
int height = drawableBounds.height();
int width = drawableBounds.width();
if (height > width) {
int newHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 200, getResources().getDisplayMetrics());
heightMeasureSpec = MeasureSpec.makeMeasureSpec(newHeight, MeasureSpec.EXACTLY);
} else if (height < width) {
int newHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 75, getResources().getDisplayMetrics());
heightMeasureSpec = MeasureSpec.makeMeasureSpec(newHeight, MeasureSpec.EXACTLY);
}
}
}
}
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}

@Override
public void setAdapter(PagerAdapter adapter) {
screenshotsAdapter = (ScreenshotsAdapter) adapter;
super.setAdapter(adapter);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand All @@ -23,6 +24,7 @@ public class ScreenshotsAdapter extends PagerAdapter {
private LayoutInflater layoutInflater;
List<String> urls = new ArrayList<>();
ScreenshotClickedListener l;
private View currentView;

public ScreenshotsAdapter(Context context, int imagesPerPage) {
this.imagesPerPage = imagesPerPage;
Expand Down Expand Up @@ -79,6 +81,16 @@ public void setScreenshotClickedListener(ScreenshotClickedListener l) {
this.l = l;
}

@Override
public void setPrimaryItem(ViewGroup container, int position, Object object) {
currentView = (View) object;
super.setPrimaryItem(container, position, object);
}

public View getCurrentView() {
return currentView;
}

interface ScreenshotClickedListener {
void onScreenshotClicked(String url);
}
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/anim/slide_in_left.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="500"
android:fromXDelta="100%p"
android:toXDelta="0" />
5 changes: 5 additions & 0 deletions app/src/main/res/anim/slide_out_left.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="500"
android:fromXDelta="0"
android:toXDelta="-100%p" />
2 changes: 1 addition & 1 deletion app/src/main/res/layout/fragment_appdetails_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
android:layout_height="wrap_content"
android:orientation="vertical">

<android.support.v4.view.ViewPager
<subreddit.android.appstore.screens.details.ScreenshotViewPager
android:id="@+id/screenshot_pager"
android:layout_width="match_parent"
android:layout_height="200dp"/>
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,10 @@
<item name="android:minHeight">56dp</item>
</style>

<style name="ScreenshotDialogTheme">
<item name="android:windowEnterAnimation">@anim/slide_in_left</item>
<item name="android:windowExitAnimation">@anim/slide_out_left</item>
</style>

</resources>

0 comments on commit 011e88c

Please sign in to comment.