I have implement GO TO page feature in this App. It help user to jump directly on entered page number.
I have got most of success, and in most of cases i can jump successfully at given page number.
I have implement this feature in search which is already present and comments old code as given below in Edited Files>ReadingFragment.java>performSearch(String query)
Issues
(1). In some cases page number jump to diffrent pages, like if i enterd 110 then it will redirect to 109.
(2). when i want to jump at chapter starting page number then page number is changed but chapter containt does not changes. like if chapter start with page no. 49, I am on Page no. 99, when i enter 49 then page number is been change to 49 but containt is of page no. 99.
`// get index from page number
public int getIndexFromPage(int pageNumber) {
int total = 0;
int totalIndex = 0;
for (List<Integer> pagesPerSection : pageOffsets) {
total += pagesPerSection.size();
totalIndex = totalIndex + 1;
if (total - 1 >= pageNumber) {
return totalIndex - 1;
}
}
return 0;
}
// get total pages before given index
public int getUptoPage(int position) {
int total = 0, max = 0;
for (List pagesPerSection : pageOffsets) {
max = max + 1;
if (position == max - 1) {
return total;
}
total += pagesPerSection.size();
}
return 0;
}
// get current index pageOffSets
public int getPageOffSets(int position) {
int max = 0;
for (List pagesPerSection : pageOffsets) {
max = max + 1;
if (position == max - 1) {
return pagesPerSection.size();
}
}
return 0;
}
// jump to particular index forward
public boolean navigateFrontSpine(int indexSpine) {
int index = Integer.parseInt(query);
if (index > bookView.getTotalNumberOfPages()) {
Toast.makeText(context, "Please enter number between 0 to " + bookView.getTotalNumberOfPages(), Toast.LENGTH_SHORT).show();
} else {
bookView.gotoPageNumber(index);
}
// final ProgressDialog searchProgress = new ProgressDialog(context);
// searchProgress.setOwnerActivity(getActivity());
// searchProgress.setCancelable(true);
// searchProgress.setMax(100);
// searchProgress.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
//
//
// final int[] counter = {0}; //Yes, this is essentially a pointer to an int :P
//
// final SearchTextTask task = new SearchTextTask(bookView.getBook());
//
// task.setOnPreExecute(() -> {
//
// searchProgress.setMessage(getString(R.string.search_wait));
// searchProgress.show();
//
// // Hide on-screen keyboard if it is showing
// InputMethodManager imm = (InputMethodManager) context.getSystemService(Activity.INPUT_METHOD_SERVICE);
// imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);
//
// });
//
// task.setOnProgressUpdate((values) -> {
//
// if (isAdded()) {
//
// LOG.debug("Found match at index=" + values[0].getIndex()
// + ", offset=" + values[0].getStart() + " with context "
// + values[0].getDisplay());
// SearchResult res = values[0];
//
// if (res.getDisplay() != null) {
// counter[0] = counter[0] + 1;
// String update = String.format(
// getString(R.string.search_hits), counter[0]);
// searchProgress.setMessage(update);
// }
//
// searchProgress.setProgress(bookView.getPercentageFor(res.getIndex(), res.getStart()));
// }
// });
//
// task.setOnCancelled((result) -> {
// if (isAdded()) {
// Toast.makeText(context, R.string.search_cancelled,
// Toast.LENGTH_LONG).show();
// }
// });
//
// task.setOnPostExecute((result) -> {
// searchProgress.dismiss();
//
// if (!task.isCancelled() && isAdded()) {
//
// List resultList = result.getOrElse(new ArrayList<>());
//
// if (resultList.size() > 0) {
// searchResults = resultList;
// showSearchResultDialog(resultList);
// } else {
// Toast.makeText(context,
// R.string.search_no_matches, Toast.LENGTH_LONG)
// .show();
// }
// }
// });
//
// searchProgress.setOnCancelListener(dialog -> task.cancel(true));
// executeTask(task, query);
Description
I have implement GO TO page feature in this App. It help user to jump directly on entered page number. I have got most of success, and in most of cases i can jump successfully at given page number.
I have implement this feature in search which is already present and comments old code as given below in Edited Files>ReadingFragment.java>performSearch(String query)
Issues
(1). In some cases page number jump to diffrent pages, like if i enterd 110 then it will redirect to 109. (2). when i want to jump at chapter starting page number then page number is changed but chapter containt does not changes. like if chapter start with page no. 49, I am on Page no. 99, when i enter 49 then page number is been change to 49 but containt is of page no. 99.
Edited Files
public void gotoPage(int pageNumber);
`public void gotoPageNumber(int pageNum) {
}`
`@Override public void gotoPage(int pageNumber) {
}`
`// get index from page number public int getIndexFromPage(int pageNumber) { int total = 0; int totalIndex = 0;
}
// get total pages before given index public int getUptoPage(int position) { int total = 0, max = 0; for (List pagesPerSection : pageOffsets) {
max = max + 1;
}
// get current index pageOffSets public int getPageOffSets(int position) { int max = 0; for (List pagesPerSection : pageOffsets) {
max = max + 1;
}
// jump to particular index forward public boolean navigateFrontSpine(int indexSpine) {
}
// jump to particular index backward public boolean navigateBackSpine(int indexSpine) {
}`
`public void performSearch(String query) {
// final ProgressDialog searchProgress = new ProgressDialog(context); // searchProgress.setOwnerActivity(getActivity()); // searchProgress.setCancelable(true); // searchProgress.setMax(100); // searchProgress.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); // // // final int[] counter = {0}; //Yes, this is essentially a pointer to an int :P // // final SearchTextTask task = new SearchTextTask(bookView.getBook()); // // task.setOnPreExecute(() -> { // // searchProgress.setMessage(getString(R.string.search_wait)); // searchProgress.show(); // // // Hide on-screen keyboard if it is showing // InputMethodManager imm = (InputMethodManager) context.getSystemService(Activity.INPUT_METHOD_SERVICE); // imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0); // // }); // // task.setOnProgressUpdate((values) -> { // // if (isAdded()) { // // LOG.debug("Found match at index=" + values[0].getIndex() // + ", offset=" + values[0].getStart() + " with context " // + values[0].getDisplay()); // SearchResult res = values[0]; // // if (res.getDisplay() != null) { // counter[0] = counter[0] + 1; // String update = String.format( // getString(R.string.search_hits), counter[0]); // searchProgress.setMessage(update); // } // // searchProgress.setProgress(bookView.getPercentageFor(res.getIndex(), res.getStart())); // } // }); // // task.setOnCancelled((result) -> { // if (isAdded()) { // Toast.makeText(context, R.string.search_cancelled, // Toast.LENGTH_LONG).show(); // } // }); // // task.setOnPostExecute((result) -> { // searchProgress.dismiss(); // // if (!task.isCancelled() && isAdded()) { // // List resultList = result.getOrElse(new ArrayList<>());
//
// if (resultList.size() > 0) {
// searchResults = resultList;
// showSearchResultDialog(resultList);
// } else {
// Toast.makeText(context,
// R.string.search_no_matches, Toast.LENGTH_LONG)
// .show();
// }
// }
// });
//
// searchProgress.setOnCancelListener(dialog -> task.cancel(true));
// executeTask(task, query);
}`
Thanks.