Search in sources :

Example 41 with FileMeta

use of com.foobnix.dao2.FileMeta in project LibreraReader by foobnix.

the class ShareDialog method show.

public static void show(final Activity a, final File file, final Runnable onDeleteAction, final int page, final DocumentWrapperUI ui, final DocumentController dc) {
    if (!ExtUtils.isExteralSD(file.getPath()) && ExtUtils.isNotValidFile(file)) {
        Toast.makeText(a, R.string.file_not_found, Toast.LENGTH_LONG).show();
        return;
    }
    final boolean isPDF = BookType.PDF.is(file.getPath());
    // a instanceof MainTabs2 ? false :
    final boolean isLibrary = false;
    // true;
    final boolean isMainTabs = a instanceof MainTabs2;
    List<String> items = new ArrayList<String>();
    if (isLibrary) {
        items.add(a.getString(R.string.library));
    }
    if (dc != null) {
        if (a instanceof VerticalViewActivity || AppState.get().isMusicianMode) {
            items.add(AppState.get().nameHorizontalMode);
        }
        if (a instanceof HorizontalViewActivity || AppState.get().isMusicianMode) {
            items.add(AppState.get().nameVerticalMode);
        }
        if (AppState.get().isMusicianMode == false) {
            items.add(AppState.get().nameMusicianMode);
        }
    }
    if (isPDF) {
        items.add(a.getString(R.string.make_text_reflow));
    }
    items.add(a.getString(R.string.open_with));
    items.add(a.getString(R.string.send_file));
    items.add(a.getString(R.string.export_bookmarks));
    final boolean canDelete = ExtUtils.isExteralSD(file.getPath()) ? true : file.canWrite();
    final boolean isShowInfo = !ExtUtils.isExteralSD(file.getPath());
    if (isMainTabs) {
        if (canDelete) {
            items.add(a.getString(R.string.delete));
        }
        items.add(a.getString(R.string.remove_from_library));
    }
    if (!isMainTabs) {
        items.add(a.getString(R.string.send_snapshot_of_the_page) + " " + (Math.max(page, 0) + 1) + "");
    }
    items.add(a.getString(R.string.tags));
    if (isShowInfo) {
        items.add(a.getString(R.string.file_info));
    }
    final AlertDialog.Builder builder = new AlertDialog.Builder(a);
    // builder.setTitle(R.string.choose_)//
    builder.setItems(items.toArray(new String[items.size()]), new DialogInterface.OnClickListener() {

        @Override
        public void onClick(final DialogInterface dialog, final int which) {
            int i = 0;
            if (isLibrary && which == i++) {
                a.finish();
                MainTabs2.startActivity(a, UITab.getCurrentTabIndex(UITab.SearchFragment));
            }
            if (dc != null && (a instanceof HorizontalViewActivity || AppState.get().isMusicianMode) && which == i++) {
                dc.onCloseActivityFinal(new Runnable() {

                    @Override
                    public void run() {
                        if (AppState.get().isMusicianMode) {
                            AppState.get().isAlwaysOpenAsMagazine = true;
                        } else {
                            AppState.get().isAlwaysOpenAsMagazine = false;
                        }
                        AppState.get().isMusicianMode = false;
                        ExtUtils.showDocumentWithoutDialog(a, file, page + 1);
                    }
                });
            }
            if (dc != null && (a instanceof VerticalViewActivity || AppState.get().isMusicianMode) && which == i++) {
                if (dc != null) {
                    dc.onCloseActivityFinal(new Runnable() {

                        @Override
                        public void run() {
                            if (AppState.get().isMusicianMode) {
                                AppState.get().isAlwaysOpenAsMagazine = false;
                            } else {
                                AppState.get().isAlwaysOpenAsMagazine = true;
                            }
                            AppState.get().isMusicianMode = false;
                            ExtUtils.showDocumentWithoutDialog(a, file, page + 1);
                        }
                    });
                }
            }
            if (dc != null && AppState.get().isMusicianMode == false && which == i++) {
                dc.onCloseActivityFinal(new Runnable() {

                    @Override
                    public void run() {
                        AppState.get().isMusicianMode = true;
                        AppState.get().isAlwaysOpenAsMagazine = false;
                        ExtUtils.showDocumentWithoutDialog(a, file, page + 1);
                    }
                });
            }
            if (isPDF && which == i++) {
                ExtUtils.openPDFInTextReflow(a, file, page + 1, dc);
            }
            if (which == i++) {
                ExtUtils.openWith(a, file);
            } else if (which == i++) {
                ExtUtils.sendFileTo(a, file);
            } else if (which == i++) {
                ExtUtils.sendBookmarksTo(a, file);
            } else if (isMainTabs && canDelete && which == i++) {
                FileInformationDialog.dialogDelete(a, file, onDeleteAction);
            } else if (isMainTabs && which == i++) {
                FileMeta load = AppDB.get().load(file.getPath());
                if (load != null) {
                    load.setIsSearchBook(false);
                    AppDB.get().update(load);
                }
                EventBus.getDefault().post(new UpdateAllFragments());
            } else if (!isMainTabs && which == i++) {
                if (dc != null) {
                    ExtUtils.sharePage(a, file, page, dc.getPageUrl(page).toString());
                } else {
                    ExtUtils.sharePage(a, file, page, null);
                }
            } else if (which == i++) {
                Dialogs.showTagsDialog(a, file, null);
            } else if (isShowInfo && which == i++) {
                FileInformationDialog.showFileInfoDialog(a, file, onDeleteAction);
            }
        }
    });
    AlertDialog create = builder.create();
    create.setOnDismissListener(new OnDismissListener() {

        @Override
        public void onDismiss(DialogInterface dialog) {
            Keyboards.hideNavigation(a);
        }
    });
    create.show();
}
Also used : AlertDialog(android.app.AlertDialog) MainTabs2(com.foobnix.ui2.MainTabs2) VerticalViewActivity(org.ebookdroid.ui.viewer.VerticalViewActivity) DialogInterface(android.content.DialogInterface) UpdateAllFragments(com.foobnix.pdf.search.activity.msg.UpdateAllFragments) OnDismissListener(android.content.DialogInterface.OnDismissListener) ArrayList(java.util.ArrayList) HorizontalViewActivity(com.foobnix.pdf.search.activity.HorizontalViewActivity) FileMeta(com.foobnix.dao2.FileMeta)

Example 42 with FileMeta

use of com.foobnix.dao2.FileMeta in project LibreraReader by foobnix.

the class SearchCore method getFilesAndDirs.

public static List<FileMeta> getFilesAndDirs(String path, boolean filterEmpty) {
    File file = new File(path);
    if (!file.isDirectory()) {
        return Collections.emptyList();
    }
    ArrayList<FileMeta> files = new ArrayList<FileMeta>();
    File[] listFiles = null;
    if (AppState.get().isDisplayAllFilesInFolder) {
        listFiles = file.listFiles();
    } else {
        listFiles = file.listFiles(SUPPORTED_EXT_AND_DIRS_FILTER);
    }
    if (listFiles == null || listFiles.length == 0) {
        return Collections.emptyList();
    }
    List<File> res = new ArrayList<File>(Arrays.asList(listFiles));
    for (File it : res) {
        if (it.getName().startsWith(".")) {
            continue;
        }
        if (!AppState.get().isDisplayAllFilesInFolder && filterEmpty && !isDirderctoryWithBook(it, 0)) {
            continue;
        }
        FileMeta meta = new FileMeta(it.getPath());
        if (it.isDirectory()) {
            FileMetaCore.get().upadteBasicMeta(meta, it);
            meta.setCusType(FileMetaAdapter.DISPLAY_TYPE_DIRECTORY);
        } else {
            FileMeta load = AppDB.get().load(it.getPath());
            if (load == null) {
                FileMetaCore.get().upadteBasicMeta(meta, it);
            } else {
                meta = load;
            }
        }
        files.add(meta);
    }
    return files;
}
Also used : ArrayList(java.util.ArrayList) File(java.io.File) FileMeta(com.foobnix.dao2.FileMeta)

Aggregations

FileMeta (com.foobnix.dao2.FileMeta)42 File (java.io.File)26 View (android.view.View)10 OnClickListener (android.view.View.OnClickListener)10 ImageView (android.widget.ImageView)10 TextView (android.widget.TextView)10 Intent (android.content.Intent)8 Bitmap (android.graphics.Bitmap)8 ArrayList (java.util.ArrayList)6 TargetApi (android.annotation.TargetApi)4 AlertDialog (android.app.AlertDialog)4 DialogInterface (android.content.DialogInterface)4 DocumentFile (android.support.v4.provider.DocumentFile)4 RecyclerView (android.support.v7.widget.RecyclerView)4 HorizontalViewActivity (com.foobnix.pdf.search.activity.HorizontalViewActivity)4 MainTabs2 (com.foobnix.ui2.MainTabs2)4 SuppressLint (android.annotation.SuppressLint)3 PendingIntent (android.app.PendingIntent)3 OnDismissListener (android.content.DialogInterface.OnDismissListener)3 Uri (android.net.Uri)3