Search in sources :

Example 6 with CodecDocument

use of org.ebookdroid.core.codec.CodecDocument in project LibreraReader by foobnix.

the class FileInformationDialog method showFileInfoDialog.

public static void showFileInfoDialog(final Activity a, final File file, final Runnable onDeleteAction) {
    AlertDialog.Builder builder = new AlertDialog.Builder(a);
    final FileMeta fileMeta = AppDB.get().getOrCreate(file.getPath());
    final View dialog = LayoutInflater.from(a).inflate(R.layout.dialog_file_info, null, false);
    TextView title = (TextView) dialog.findViewById(R.id.title);
    final TextView bookmarks = (TextView) dialog.findViewById(R.id.bookmarks);
    title.setText(TxtUtils.getFileMetaBookName(fileMeta));
    ((TextView) dialog.findViewById(R.id.path)).setText(file.getPath());
    ((TextView) dialog.findViewById(R.id.date)).setText(fileMeta.getDateTxt());
    ((TextView) dialog.findViewById(R.id.info)).setText(fileMeta.getExt());
    if (fileMeta.getPages() != null && fileMeta.getPages() != 0) {
        ((TextView) dialog.findViewById(R.id.size)).setText(fileMeta.getSizeTxt() + " (" + fileMeta.getPages() + ")");
    } else {
        ((TextView) dialog.findViewById(R.id.size)).setText(fileMeta.getSizeTxt());
    }
    ((TextView) dialog.findViewById(R.id.mimeType)).setText("" + ExtUtils.getMimeType(file));
    final TextView hypenLang = (TextView) dialog.findViewById(R.id.hypenLang);
    hypenLang.setText(DialogTranslateFromTo.getLanuageByCode(fileMeta.getLang()));
    if (fileMeta.getLang() == null) {
        ((View) hypenLang.getParent()).setVisibility(View.GONE);
    }
    List<AppBookmark> objects = AppSharedPreferences.get().getBookmarksByBook(file);
    StringBuilder lines = new StringBuilder();
    String fast = a.getString(R.string.fast_bookmark);
    if (TxtUtils.isListNotEmpty(objects)) {
        for (AppBookmark b : objects) {
            if (!fast.equals(b.getText())) {
                lines.append(b.getPage() + ": " + b.getText());
                lines.append("\n");
            }
        }
    }
    bookmarks.setText(TxtUtils.replaceLast(lines.toString(), "\n", ""));
    bookmarks.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            AlertDialogs.showOkDialog(a, bookmarks.getText().toString(), null);
        }
    });
    final TextView infoView = (TextView) dialog.findViewById(R.id.metaInfo);
    String bookOverview = FileMetaCore.getBookOverview(file.getPath());
    infoView.setText(TxtUtils.nullToEmpty(bookOverview));
    infoView.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            AlertDialogs.showOkDialog(a, infoView.getText().toString(), null);
        }
    });
    String sequence = fileMeta.getSequence();
    if (TxtUtils.isNotEmpty(sequence)) {
        String replace = sequence.replaceAll(",$", "").replace(",", " / ");
        ((TextView) dialog.findViewById(R.id.metaSeries)).setText(replace);
    } else {
        ((TextView) dialog.findViewById(R.id.metaSeries)).setVisibility(View.GONE);
        ((TextView) dialog.findViewById(R.id.metaSeriesID)).setVisibility(View.GONE);
    }
    String genre = fileMeta.getGenre();
    if (TxtUtils.isNotEmpty(genre)) {
        genre = TxtUtils.firstUppercase(genre.replaceAll(",$", "").replace(",", ", "));
        ((TextView) dialog.findViewById(R.id.metaGenre)).setText(genre);
    } else {
        ((TextView) dialog.findViewById(R.id.metaGenre)).setVisibility(View.GONE);
        ((TextView) dialog.findViewById(R.id.metaGenreID)).setVisibility(View.GONE);
    }
    final Runnable tagsRunnable = new Runnable() {

        @Override
        public void run() {
            String tag = fileMeta.getTag();
            if (TxtUtils.isNotEmpty(tag)) {
                String replace = tag.replace("#", " ");
                replace = TxtUtils.replaceLast(replace, ",", "").trim();
                ((TextView) dialog.findViewById(R.id.tagsList)).setText(replace);
                ((TextView) dialog.findViewById(R.id.tagsID)).setVisibility(View.VISIBLE);
                ((TextView) dialog.findViewById(R.id.tagsList)).setVisibility(View.VISIBLE);
            } else {
                ((TextView) dialog.findViewById(R.id.tagsID)).setVisibility(View.GONE);
                ((TextView) dialog.findViewById(R.id.tagsList)).setVisibility(View.GONE);
            }
        }
    };
    tagsRunnable.run();
    TxtUtils.underlineTextView((TextView) dialog.findViewById(R.id.addTags)).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Dialogs.showTagsDialog(v.getContext(), new File(fileMeta.getPath()), new Runnable() {

                @Override
                public void run() {
                    tagsRunnable.run();
                    EventBus.getDefault().post(new NotifyAllFragments());
                }
            });
        }
    });
    TextView metaPDF = (TextView) dialog.findViewById(R.id.metaPDF);
    metaPDF.setVisibility(View.GONE);
    if (BookType.PDF.is(file.getPath())) {
        CodecDocument doc = ImageExtractor.singleCodecContext(file.getPath(), "", 0, 0);
        if (doc != null) {
            metaPDF.setVisibility(View.VISIBLE);
            StringBuilder meta = new StringBuilder();
            List<String> list = Arrays.asList(// 
            "info:Title", // 
            "info:Author", // 
            "info:Subject", // 
            "info:Keywords");
            for (String id : list) {
                String metaValue = doc.getMeta(id);
                if (TxtUtils.isNotEmpty(metaValue)) {
                    id = id.replace("info:Title", a.getString(R.string.title));
                    id = id.replace("info:Author", a.getString(R.string.author));
                    id = id.replace("info:Subject", a.getString(R.string.subject));
                    id = id.replace("info:Keywords", a.getString(R.string.keywords));
                    meta.append("<b>" + id).append(": " + "</b>").append(metaValue).append("<br>");
                }
            }
            doc.recycle();
            String text = TxtUtils.replaceLast(meta.toString(), "<br>", "");
            metaPDF.setText(Html.fromHtml(text));
        }
    }
    TextView convertFile = (TextView) dialog.findViewById(R.id.convertFile);
    convertFile.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            ShareDialog.showsItemsDialog(a, file.getPath(), AppState.CONVERTERS.get("EPUB"));
        }
    });
    convertFile.setText(TxtUtils.underline(a.getString(R.string.convert_to) + " EPUB"));
    convertFile.setVisibility(ExtUtils.isImageOrEpub(file) ? View.GONE : View.VISIBLE);
    convertFile.setVisibility(View.GONE);
    TxtUtils.underlineTextView((TextView) dialog.findViewById(R.id.openWith)).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (infoDialog != null) {
                infoDialog.dismiss();
                infoDialog = null;
            }
            ExtUtils.openWith(a, file);
        }
    });
    TxtUtils.underlineTextView((TextView) dialog.findViewById(R.id.sendFile)).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (infoDialog != null) {
                infoDialog.dismiss();
                infoDialog = null;
            }
            ExtUtils.sendFileTo(a, file);
        }
    });
    TextView delete = TxtUtils.underlineTextView((TextView) dialog.findViewById(R.id.delete));
    if (onDeleteAction == null) {
        delete.setVisibility(View.GONE);
    }
    delete.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (infoDialog != null) {
                infoDialog.dismiss();
                infoDialog = null;
            }
            dialogDelete(a, file, onDeleteAction);
        }
    });
    View openFile = dialog.findViewById(R.id.openFile);
    openFile.setVisibility(ExtUtils.isNotSupportedFile(file) ? View.GONE : View.VISIBLE);
    openFile.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (infoDialog != null) {
                infoDialog.dismiss();
                infoDialog = null;
            }
            ExtUtils.showDocument(a, file);
        }
    });
    final ImageView coverImage = (ImageView) dialog.findViewById(R.id.image);
    coverImage.setMaxWidth(Dips.screenWidth() / 3);
    // coverImage.getLayoutParams().width = Dips.screenWidth() / 3;
    IMG.getCoverPage(coverImage, file.getPath(), IMG.getImageSize());
    coverImage.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            showImage(a, file.getPath());
        }
    });
    // IMG.updateImageSizeBig(coverImage);
    final ImageView starIcon = ((ImageView) dialog.findViewById(R.id.starIcon));
    starIcon.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            DefaultListeners.getOnStarClick(a).onResultRecive(fileMeta, null);
            if (fileMeta.getIsStar() == null || fileMeta.getIsStar() == false) {
                starIcon.setImageResource(R.drawable.star_2);
            } else {
                starIcon.setImageResource(R.drawable.star_1);
            }
            TintUtil.setTintImageWithAlpha(starIcon, Color.WHITE);
        }
    });
    if (fileMeta.getIsStar() == null || fileMeta.getIsStar() == false) {
        starIcon.setImageResource(R.drawable.star_2);
    } else {
        starIcon.setImageResource(R.drawable.star_1);
    }
    TintUtil.setTintImageWithAlpha(starIcon, Color.WHITE);
    TintUtil.setBackgroundFillColor(openFile, TintUtil.color);
    // builder.setTitle(R.string.file_info);
    builder.setView(dialog);
    builder.setNegativeButton(R.string.close, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int id) {
        }
    });
    infoDialog = builder.create();
    infoDialog.setOnDismissListener(new OnDismissListener() {

        @Override
        public void onDismiss(DialogInterface dialog) {
            Keyboards.hideNavigation(a);
        }
    });
    infoDialog.show();
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) OnDismissListener(android.content.DialogInterface.OnDismissListener) ScaledImageView(com.foobnix.pdf.info.view.ScaledImageView) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) NotifyAllFragments(com.foobnix.pdf.search.activity.msg.NotifyAllFragments) AppBookmark(com.foobnix.pdf.info.wrapper.AppBookmark) OnClickListener(android.view.View.OnClickListener) TextView(android.widget.TextView) ScaledImageView(com.foobnix.pdf.info.view.ScaledImageView) ImageView(android.widget.ImageView) File(java.io.File) FileMeta(com.foobnix.dao2.FileMeta) CodecDocument(org.ebookdroid.core.codec.CodecDocument)

Aggregations

CodecDocument (org.ebookdroid.core.codec.CodecDocument)6 CodecPage (org.ebookdroid.core.codec.CodecPage)4 File (java.io.File)3 FileMeta (com.foobnix.dao2.FileMeta)2 TargetApi (android.annotation.TargetApi)1 AlertDialog (android.app.AlertDialog)1 DialogInterface (android.content.DialogInterface)1 OnDismissListener (android.content.DialogInterface.OnDismissListener)1 Bitmap (android.graphics.Bitmap)1 Matrix (android.graphics.Matrix)1 Rect (android.graphics.Rect)1 RectF (android.graphics.RectF)1 OnUtteranceCompletedListener (android.speech.tts.TextToSpeech.OnUtteranceCompletedListener)1 UtteranceProgressListener (android.speech.tts.UtteranceProgressListener)1 View (android.view.View)1 OnClickListener (android.view.View.OnClickListener)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 ScaledImageView (com.foobnix.pdf.info.view.ScaledImageView)1 AppBookmark (com.foobnix.pdf.info.wrapper.AppBookmark)1