Skip to content
This repository has been archived by the owner on Jul 23, 2020. It is now read-only.

Commit

Permalink
changes on readers
Browse files Browse the repository at this point in the history
  • Loading branch information
raulhaag committed Feb 28, 2018
1 parent 6147661 commit c5cf210
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,36 +50,28 @@ protected void calculateParticularScale(Page dimension) {

@Override
public void postLayout() {
absoluteScroll(getPagePosition(currentPage), yScroll);
absoluteScroll(getPagePosition(currentPage - 1), yScroll);
generateDrawPool();
if (readerListener != null) {
readerListener.onPageChanged(currentPage);
readerListener.onPageChanged(currentPage - 1);
}
}

@Override
public void seekPage(int index) {
int page = index - 1;
if (page < 0)
page = 0;
else if (index >= pages.size())
page = pages.size() - 1;
if (viewReady && pagesLoaded) {
absoluteScroll(getPagePosition(page), yScroll);
generateDrawPool();
}
currentPage = page;
currentPage = index;
if (readerListener != null) {
readerListener.onPageChanged(transformPage(currentPage));
readerListener.onPageChanged(currentPage);
}
}

public void reloadImage(int idx) {
int pageIdx;
if(idx == 0)
pageIdx = idx;
else
pageIdx = idx - 1;
int pageIdx = idx - 1;
if (pages != null && pageIdx < pages.size() && pageIdx >= 0) {
int cPage = currentPage;
if (pages.size() < cPage || cPage < 0)
Expand Down Expand Up @@ -158,7 +150,7 @@ public boolean onDoubleTapEvent(MotionEvent e) {
public void reset() {
xScroll = 0;
yScroll = 0;
currentPage = 0;
currentPage = 1;
pages = null;
pagesLoaded = false;
viewReady = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,12 @@ public void freePage(int idx) {

@Override
public int getCurrentPage() {
return currentPage + 1;
return currentPage;
}

public String getPath(int idx) {
Page p = getPage(idx);
int iIdx = idx - 1;
Page p = getPage(iIdx);
if (p != null) {
return p.getPath();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ public HorizontalPagedReader(Context context) {
public abstract void addOnPageChangeListener();

@Override
public int getCurrentPage() {
return mViewPager.getCurrentItem() + 1;
protected int getCurrentPosition() {
return mViewPager.getCurrentItem();
}

public void init() {
String infService = Context.LAYOUT_INFLATER_SERVICE;
LayoutInflater li = (LayoutInflater)getContext().getSystemService(infService);
li.inflate(R.layout.view_paged_reader, this, true);
mViewPager = (UnScrolledViewPager) findViewById(R.id.pager);
mViewPager = findViewById(R.id.pager);
addOnPageChangeListener();
mViewPager.setOnSwipeOutListener(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,15 @@ public boolean onSingleTapConfirmed(MotionEvent e) {
readerListener.onStartOver();
}
} else {
mViewPager.setCurrentItem(currentPage - 1);
mViewPager.setCurrentItem(getCurrentPosition() - 1);
}
} else if (e.getX() > getWidth() / 4 * 3) {
if (currentPage == paths.size() - 1) {
if (currentPage == paths.size()) {
if (readerListener != null) {
readerListener.onEndOver();
}
} else {
mViewPager.setCurrentItem(currentPage + 1);
mViewPager.setCurrentItem(getCurrentPosition() + 1);
}
} else {
readerListener.onMenuRequired();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.support.v4.view.PagerAdapter;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand All @@ -34,7 +33,7 @@ public abstract class PagedReader extends Reader implements TapListener {
private static ImageViewTouchBase.DisplayType mScreenFit;
protected PageAdapter mPageAdapter;
List<String> paths;
int currentPage = 0;
int currentPage = 1; //keep the value from 1..n for externally view
private InitialPosition iniPosition = InitialPosition.LEFT_UP;

public PagedReader(Context context) {
Expand All @@ -43,6 +42,8 @@ public PagedReader(Context context) {

public abstract void setPagerAdapter(PageAdapter mPageAdapter);

protected abstract int getCurrentPosition();

@Override
public void setScreenFit(ImageViewTouchBase.DisplayType displayType) {
mScreenFit = displayType;
Expand All @@ -68,51 +69,30 @@ public void freeMemory() {

@Override
public void freePage(int idx) {
if (idx == 0) {
if (mPageAdapter != null && mPageAdapter.pages[idx] != null) {
mPageAdapter.pages[idx].unloadImage();
}
} else {
if (mPageAdapter != null && mPageAdapter.pages[idx - 1] != null) {
mPageAdapter.pages[idx - 1].unloadImage();
}
int iIdx = idx - 1;
if (mPageAdapter != null && mPageAdapter.pages[iIdx] != null) {
mPageAdapter.pages[iIdx].unloadImage();
}
}

@Override
public String getPath(int idx) {
if (paths != null) {
if (idx == 0)
return paths.get(idx);
else if (idx < paths.size())
return paths.get(idx - 1);
return paths.get(idx - 1);
}
return "";
}

@Override
public void reset() {
setPagerAdapter(null);
currentPage = 0;
currentPage = 1;
}

@Override
public void reloadImage(int idx) {
//Log.d("PR", "idx: " + idx);
if (mPageAdapter != null) {
if (idx > mPageAdapter.pages.length) {
Log.e("PagedReader", "idx > mPageAdapter.pages.length !");
} else {
if (idx == 0) {
if (mPageAdapter.pages[idx] != null) {
mPageAdapter.pages[idx].setImage();
}
} else {
if (mPageAdapter.pages[idx - 1] != null) {
mPageAdapter.pages[idx - 1].setImage();
}
}
}
if (mPageAdapter != null && mPageAdapter.pages[idx - 1] != null) {
mPageAdapter.pages[idx - 1].setImage();
}
}

Expand All @@ -136,12 +116,10 @@ public class PageAdapter extends PagerAdapter {
}

public Page getCurrentPage() {
return pages[currentPage];
return pages[getCurrentPosition()];
}

public void setCurrentPage(int nCurrentPage) {
if (mDirection == Direction.L2R)
nCurrentPage = paths.size() - nCurrentPage;
currentPage = nCurrentPage;
for (int i = 0; i < pages.length; i++) {
if (pages[i] != null) {
Expand All @@ -155,11 +133,7 @@ public void setCurrentPage(int nCurrentPage) {
}

Page getPage(int idx) {
if (idx < 0)
idx = 0;
else if (idx >= pages.length)
idx = pages.length - 1;
return pages[idx];
return pages[idx - 1];
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ public void onPageScrolled(int position, float positionOffset, int positionOffse
if (readerListener != null) {
readerListener.onPageChanged(transformPage(position));
}
currentPage = position;
currentPage = position + 1;
if (mPageAdapter != null)
mPageAdapter.setCurrentPage(position);
}

@Override
public void onPageSelected(int position) {
currentPage = position;
currentPage = position + 1;
}

@Override
Expand All @@ -47,6 +47,11 @@ public boolean isLastPageVisible() {
return paths != null && !paths.isEmpty() && mViewPager.getCurrentItem() == (paths.size() - 1);
}

@Override
public int getCurrentPage() {
return getCurrentPosition() + 1;
}

@Override
public void goToPage(int aPage) {
int page = aPage - 1;
Expand All @@ -66,15 +71,15 @@ public boolean onSingleTapConfirmed(MotionEvent e) {
readerListener.onStartOver();
}
} else {
mViewPager.setCurrentItem(currentPage - 1);
mViewPager.setCurrentItem(getCurrentPosition() - 1);
}
} else if (e.getX() > getWidth() / 4 * 3) {
if (currentPage == paths.size() - 1) {
if (readerListener != null) {
readerListener.onEndOver();
}
} else {
mViewPager.setCurrentItem(currentPage + 1);
mViewPager.setCurrentItem(getCurrentPosition() + 1);
}
} else {
readerListener.onMenuRequired();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void goToPage(int aPage) {
int page = aPage - 1;
mViewPager.setCurrentItem(page);
if (readerListener != null) {
readerListener.onPageChanged(transformPage(page));
readerListener.onPageChanged(aPage);
}
currentPage = aPage;
}
Expand All @@ -49,7 +49,7 @@ public void init() {
String infService = Context.LAYOUT_INFLATER_SERVICE;
LayoutInflater li = (LayoutInflater) getContext().getSystemService(infService);
li.inflate(R.layout.view_paged_reader_vertical, this, true);
mViewPager = (UnScrolledViewPagerVertical) findViewById(R.id.pager);
mViewPager = findViewById(R.id.pager);
addOnPageChangeListener();
mViewPager.setOnSwipeOutListener(this);
}
Expand All @@ -61,14 +61,14 @@ public void onPageScrolled(int position, float positionOffset, int positionOffse
if (readerListener != null) {
readerListener.onPageChanged(transformPage(position));
}
currentPage = position;
currentPage = position + 1;
if(mPageAdapter != null)
mPageAdapter.setCurrentPage(position);
}

@Override
public void onPageSelected(int position) {
currentPage = position;
currentPage = position + 1;
}

@Override
Expand All @@ -83,23 +83,28 @@ public void setPagerAdapter(PageAdapter nPageAdapter) {
mViewPager.setAdapter(mPageAdapter);
}

@Override
protected int getCurrentPosition() {
return mViewPager.getCurrentItem();
}

public boolean onSingleTapConfirmed(MotionEvent e) {
if (readerListener != null)
if (e.getX() < getWidth() / 4) {
if (currentPage == 0) {
if (currentPage == 1) {
if (readerListener != null) {
readerListener.onStartOver();
}
} else {
mViewPager.setCurrentItem(currentPage - 1);
mViewPager.setCurrentItem(getCurrentPosition() - 1);
}
} else if (e.getX() > getWidth() / 4 * 3) {
if (currentPage == paths.size() - 1) {
if (currentPage == paths.size()) {
if (readerListener != null) {
readerListener.onEndOver();
}
} else {
mViewPager.setCurrentItem(currentPage + 1);
mViewPager.setCurrentItem(getCurrentPosition() + 1);
}
} else {
readerListener.onMenuRequired();
Expand Down
11 changes: 6 additions & 5 deletions app/src/main/res/layout/fragment_reader.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,26 +46,27 @@
android:orientation="horizontal">
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="4"
android:layout_weight="1"
android:background="@color/transparent"
android:ellipsize="end"
android:maxLines="1"
android:paddingLeft="4dp"
android:paddingRight="4dp"
android:text="Chapter title n"
android:text=""
android:textColor="@android:color/primary_text_dark" />

<TextView
android:id="@+id/pages"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@color/transparent"
android:gravity="right"
android:maxLines="1"
android:paddingLeft="4dp"
android:paddingRight="4dp"
android:text="Page 1/n"
android:text=""
android:textColor="@android:color/primary_text_dark" />
</LinearLayout>
</RelativeLayout>
Expand Down

0 comments on commit c5cf210

Please sign in to comment.