use of com.foobnix.android.utils.ResultResponse in project LibreraReader by foobnix.
the class DefaultListeners method getOnMenuClick.
public static ResultResponse<FileMeta> getOnMenuClick(final Activity a, final FileMetaAdapter searchAdapter) {
return new ResultResponse<FileMeta>() {
@Override
public boolean onResultRecive(final FileMeta result) {
final File file = new File(result.getPath());
Runnable onDeleteAction = new Runnable() {
@Override
public void run() {
deleteFile(a, searchAdapter, result);
}
};
if (ExtUtils.isExteralSD(result.getPath())) {
ShareDialog.show(a, file, onDeleteAction, -1, null, null);
} else {
if (ExtUtils.doifFileExists(a, file)) {
if (ExtUtils.isNotSupportedFile(file)) {
ShareDialog.showArchive(a, file, onDeleteAction);
} else {
ShareDialog.show(a, file, onDeleteAction, -1, null, null);
}
}
}
return false;
}
};
}
use of com.foobnix.android.utils.ResultResponse in project LibreraReader by foobnix.
the class DefaultListeners method getOnItemLongClickListener.
public static ResultResponse<FileMeta> getOnItemLongClickListener(final Activity a, final FileMetaAdapter searchAdapter) {
return new ResultResponse<FileMeta>() {
@Override
public boolean onResultRecive(final FileMeta result) {
if (ExtUtils.isExteralSD(result.getPath())) {
return false;
}
if (isTagCicked(a, result)) {
return true;
}
File item = new File(result.getPath());
if (item.isDirectory()) {
Intent intent = //
new Intent(UIFragment.INTENT_TINT_CHANGE).putExtra(MainTabs2.EXTRA_PAGE_NUMBER, //
UITab.getCurrentTabIndex(UITab.BrowseFragment));
LocalBroadcastManager.getInstance(a).sendBroadcast(intent);
EventBus.getDefault().post(new OpenDirMessage(result.getPath()));
return true;
}
Runnable onDeleteAction = new Runnable() {
@Override
public void run() {
deleteFile(a, searchAdapter, result);
}
};
if (ExtUtils.doifFileExists(a, item)) {
FileInformationDialog.showFileInfoDialog(a, item, onDeleteAction);
}
return true;
}
};
}
use of com.foobnix.android.utils.ResultResponse in project LibreraReader by foobnix.
the class DefaultListeners method getOnSeriesClickListener.
public static ResultResponse<String> getOnSeriesClickListener(final Activity a) {
return new ResultResponse<String>() {
@Override
public boolean onResultRecive(String result) {
result = AppDB.SEARCH_IN.SERIES.getDotPrefix() + " " + result;
Intent intent = //
new Intent(UIFragment.INTENT_TINT_CHANGE).putExtra(MainTabs2.EXTRA_SEACH_TEXT, //
result).putExtra(MainTabs2.EXTRA_PAGE_NUMBER, //
UITab.getCurrentTabIndex(UITab.SearchFragment));
LocalBroadcastManager.getInstance(a).sendBroadcast(intent);
return false;
}
};
}
use of com.foobnix.android.utils.ResultResponse in project LibreraReader by foobnix.
the class VerticalModeController method onCloseActivityAdnShowInterstial.
@Override
public void onCloseActivityAdnShowInterstial() {
handler.removeCallbacksAndMessages(null);
if (ctr == null || ctr.getDecodeService() == null) {
return;
}
if (ctr.getDecodeService().hasAnnotationChanges()) {
final StringBuilder path = new StringBuilder(getCurrentBook().getAbsolutePath());
final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle(R.string.save_changes);
builder.setMessage(getCurrentBook().getAbsolutePath());
builder.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
if (!path.toString().equals(getCurrentBook().getAbsolutePath())) {
LOG.d("Save TO new file", path.toString());
File newBook = new File(path.toString());
newBook.delete();
try {
copy(getCurrentBook(), newBook);
} catch (IOException e) {
Toast.makeText(activity, e.getMessage(), Toast.LENGTH_SHORT).show();
}
}
final ProgressDialog progress = ProgressDialog.show(getActivity(), null, getActivity().getString(R.string.saving_));
progress.setCancelable(false);
progress.show();
ctr.getDecodeService().saveAnnotations(path.toString(), new Runnable() {
@Override
public void run() {
LOG.d("saveAnnotations return 1");
progress.dismiss();
LOG.d("saveAnnotations return 2");
ctr.closeActivity(null);
}
});
}
});
builder.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
ctr.closeActivity(null);
}
});
builder.setNeutralButton(R.string.rename, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
PrefDialogs.selectFileDialog(activity, Arrays.asList(".pdf"), getCurrentBook(), new ResultResponse<String>() {
@Override
public boolean onResultRecive(String result) {
path.setLength(0);
path.append(result);
builder.setMessage(result);
builder.show();
return false;
}
});
}
});
builder.show();
} else {
ctr.closeActivity(null);
}
}
use of com.foobnix.android.utils.ResultResponse in project LibreraReader by foobnix.
the class DragingDialogs method showContent.
public static DragingPopup showContent(final FrameLayout anchor, final DocumentController controller) {
final OnItemClickListener onClickContent = new OnItemClickListener() {
@Override
public void onItemClick(final AdapterView<?> parent, final View view, final int position, final long id) {
final OutlineLinkWrapper link = (OutlineLinkWrapper) parent.getItemAtPosition(position);
if (link.targetPage != -1) {
int pageCount = controller.getPageCount();
if (link.targetPage < 1 || link.targetPage > pageCount) {
Toast.makeText(anchor.getContext(), "no", Toast.LENGTH_SHORT).show();
} else {
controller.onGoToPage(link.targetPage);
// ((ListView) parent).requestFocusFromTouch();
// ((ListView) parent).setSelection(position);
}
return;
}
}
};
DragingPopup dragingPopup = new DragingPopup(anchor.getContext().getString(R.string.content_of_book), anchor, 300, 400) {
@Override
public View getContentView(LayoutInflater inflater) {
View view = inflater.inflate(R.layout.dialog_recent_books, null, false);
LinearLayout attachemnts = (LinearLayout) view.findViewById(R.id.mediaAttachments);
List<String> mediaAttachments = controller.getMediaAttachments();
if (mediaAttachments != null && !mediaAttachments.isEmpty()) {
view.findViewById(R.id.mediaAttachmentsScroll).setVisibility(View.VISIBLE);
for (final String fname : mediaAttachments) {
String[] split = fname.split(",");
final String nameFull = split[0];
String name = nameFull;
if (name.contains("/")) {
name = name.substring(name.lastIndexOf("/") + 1);
}
long size = Long.parseLong(split[1]);
TextView t = new TextView(anchor.getContext());
t.setText(TxtUtils.underline(name + " (" + ExtUtils.readableFileSize(size) + ")"));
t.setPadding(Dips.dpToPx(2), Dips.dpToPx(2), Dips.dpToPx(2), Dips.dpToPx(2));
t.setBackgroundResource(R.drawable.bg_clickable);
attachemnts.addView(t);
t.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
new AsyncTask<Void, Void, File>() {
ProgressDialog dialog;
@Override
protected void onPreExecute() {
dialog = ProgressDialog.show(controller.getActivity(), "", controller.getString(R.string.msg_loading));
}
@Override
protected File doInBackground(Void... params) {
return EpubExtractor.extractAttachment(controller.getCurrentBook(), nameFull);
}
@Override
protected void onPostExecute(File aPath) {
try {
dialog.dismiss();
if (aPath != null && aPath.isFile()) {
LOG.d("Try to open path", aPath);
ExtUtils.openWith(anchor.getContext(), aPath);
} else {
Toast.makeText(controller.getActivity(), R.string.msg_unexpected_error, Toast.LENGTH_LONG).show();
}
} catch (Exception e) {
LOG.e(e);
}
}
}.execute();
}
});
}
} else {
view.findViewById(R.id.mediaAttachmentsScroll).setVisibility(View.GONE);
}
final ListView contentList = (ListView) view.findViewById(R.id.contentList);
contentList.setSelector(android.R.color.transparent);
contentList.setVerticalScrollBarEnabled(false);
final Runnable showOutline = new Runnable() {
@Override
public void run() {
controller.getOutline(new ResultResponse<List<OutlineLinkWrapper>>() {
@Override
public boolean onResultRecive(final List<OutlineLinkWrapper> outline) {
contentList.post(new Runnable() {
@Override
public void run() {
if (outline != null && outline.size() > 0) {
contentList.clearChoices();
OutlineLinkWrapper currentByPageNumber = OutlineHelper.getCurrentByPageNumber(outline, controller.getCurentPageFirst1());
final OutlineAdapter adapter = new OutlineAdapter(controller.getActivity(), outline, currentByPageNumber, controller.getPageCount());
contentList.setAdapter(adapter);
contentList.setOnItemClickListener(onClickContent);
contentList.setSelection(adapter.getItemPosition(currentByPageNumber) - 3);
}
}
});
return false;
}
}, true);
}
};
contentList.postDelayed(showOutline, 50);
if (false && BookType.FB2.is(controller.getCurrentBook().getPath())) {
setTitlePopupIcon(AppState.get().outlineMode == AppState.OUTLINE_ONLY_HEADERS ? R.drawable.glyphicons_114_justify : R.drawable.glyphicons_114_justify_sub);
titlePopupMenu = new MyPopupMenu(controller.getActivity(), null);
List<Integer> names = Arrays.asList(R.string.headings_only, R.string.heading_and_subheadings);
final List<Integer> icons = Arrays.asList(R.drawable.glyphicons_114_justify, R.drawable.glyphicons_114_justify_sub);
final List<Integer> actions = Arrays.asList(AppState.OUTLINE_ONLY_HEADERS, AppState.OUTLINE_HEADERS_AND_SUBHEADERES);
for (int i = 0; i < names.size(); i++) {
final int index = i;
titlePopupMenu.getMenu().add(names.get(i)).setIcon(icons.get(i)).setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
AppState.get().outlineMode = actions.get(index);
setTitlePopupIcon(icons.get(index));
showOutline.run();
return false;
}
});
}
}
return view;
}
}.show("showContent", false, true);
return dragingPopup;
}
Aggregations