Search in sources :

Example 36 with FileMeta

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

the class ExtUtils method openPDFInTextReflowAsync.

public static File openPDFInTextReflowAsync(Activity a, final File file, Handler dialog) {
    try {
        File bookTempRoot = new File(AppState.get().downlodsPath, file.getName());
        if (!bookTempRoot.exists()) {
            bookTempRoot.mkdirs();
        } else {
            CacheZipUtils.removeFiles(bookTempRoot.listFiles());
        }
        String pwd = "";
        try {
            pwd = a.getIntent().getStringExtra(HorizontalModeController.EXTRA_PASSWORD);
            if (pwd == null) {
                pwd = "";
            }
        } catch (Exception e) {
            LOG.e(e);
        }
        CodecDocument doc = BookType.getCodecContextByPath(file.getPath()).openDocument(file.getPath(), pwd);
        List<OutlineLink> outline = doc.getOutline();
        final File fileReflowHtml = new File(bookTempRoot, "temp" + REFLOW_HTML);
        try {
            FileWriter fout = new FileWriter(fileReflowHtml);
            BufferedWriter out = new BufferedWriter(fout);
            out.write("<html>");
            out.write("<head><meta charset=\"utf-8\"/></head>");
            out.write("<body>");
            int pages = doc.getPageCount();
            int imgCount = 0;
            for (int i = 0; i < pages; i++) {
                LOG.d("Extract page", i);
                CodecPage pageCodec = doc.getPage(i);
                String html = pageCodec.getPageHTMLWithImages();
                out.write("<a id=\"" + i + "\"></a>");
                html = TxtUtils.replaceEndLine(html);
                int startImage = html.indexOf(IMAGE_BEGIN);
                while (startImage >= 0) {
                    if (!TempHolder.get().isConverting) {
                        CacheZipUtils.removeFiles(bookTempRoot.listFiles());
                        bookTempRoot.delete();
                        break;
                    }
                    imgCount++;
                    LOG.d("Extract image", imgCount);
                    int endImage = html.indexOf(IMAGE_END, startImage);
                    String mime = html.substring(startImage + IMAGE_BEGIN.length(), endImage);
                    String format;
                    if (mime.startsWith(IMAGE_JPEG_BASE64)) {
                        format = ".jpg";
                        mime = mime.replace(IMAGE_JPEG_BASE64, "");
                    } else if (mime.startsWith(IMAGE_PNG_BASE64)) {
                        format = ".png";
                        mime = mime.replace(IMAGE_PNG_BASE64, "");
                    } else {
                        format = ".none";
                    }
                    // FileOutputStream mimeOut = new FileOutputStream(new File(bookTempRoot, "mime"
                    // + imgCount + ".mime"));
                    // mimeOut.write(mime.getBytes());
                    // mimeOut.close();
                    byte[] decode = Base64.decode(mime, Base64.DEFAULT);
                    String imageName = imgCount + format;
                    LOG.d("Extract-mime", mime.substring(mime.length() - 10, mime.length()));
                    FileOutputStream imgStream = new FileOutputStream(new File(bookTempRoot, imageName));
                    imgStream.write(decode);
                    imgStream.close();
                    html = html.substring(0, startImage) + "<img src=\"" + imageName + "\"/>" + html.substring(endImage + IMAGE_END.length());
                    startImage = html.indexOf(IMAGE_BEGIN);
                    LOG.d("startImage", startImage);
                }
                // out.write(TextUtils.htmlEncode(html));
                // html = html.replace("< ", "&lt; ");
                // html = html.replace("> ", "&gt; ");
                // html = html.replace("&", "&amp;");
                out.write(html);
                pageCodec.recycle();
                LOG.d("Extract page end1", i);
                dialog.sendEmptyMessage(((i + 1) * 100) / pages);
                if (!TempHolder.get().isConverting) {
                    CacheZipUtils.removeFiles(bookTempRoot.listFiles());
                    bookTempRoot.delete();
                    break;
                }
            }
            doc.recycle();
            out.write("</body></html>");
            out.flush();
            out.close();
            fout.close();
        } catch (Exception e) {
            LOG.e(e);
            return null;
        }
        File epubOutpub = new File(AppState.get().downlodsPath, file.getName() + REFLOW_EPUB);
        if (epubOutpub.isFile()) {
            epubOutpub.delete();
        }
        FileMeta meta = AppDB.get().getOrCreate(file.getPath());
        Fb2Extractor.convertFolderToEpub(bookTempRoot, epubOutpub, meta.getAuthor(), meta.getTitle(), outline);
        CacheZipUtils.removeFiles(bookTempRoot.listFiles());
        bookTempRoot.delete();
        if (!TempHolder.get().isConverting) {
            epubOutpub.delete();
            LOG.d("Delete temp file", fileReflowHtml.getPath());
        }
        LOG.d("openPDFInTextReflow", fileReflowHtml.getPath());
        return epubOutpub;
    } catch (RuntimeException e) {
        LOG.e(e);
        return null;
    }
}
Also used : OutlineLink(org.ebookdroid.core.codec.OutlineLink) FileWriter(java.io.FileWriter) CodecPage(org.ebookdroid.core.codec.CodecPage) BufferedWriter(java.io.BufferedWriter) FileOutputStream(java.io.FileOutputStream) File(java.io.File) FileMeta(com.foobnix.dao2.FileMeta) CodecDocument(org.ebookdroid.core.codec.CodecDocument)

Example 37 with FileMeta

use of com.foobnix.dao2.FileMeta 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)

Example 38 with FileMeta

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

the class RecentBooksWidget method updateList.

private void updateList(final RemoteViews remoteViews) {
    List<FileMeta> recent = null;
    if (AppState.get().isStarsInWidget) {
        recent = AppDB.get().getStarsFiles();
    } else {
        recent = AppDB.get().getRecent();
    }
    String className = VerticalViewActivity.class.getName();
    if (AppState.get().isAlwaysOpenAsMagazine) {
        className = HorizontalViewActivity.class.getName();
    }
    remoteViews.removeAllViews(R.id.linearLayout);
    for (int i = 0; i < recent.size() && i < AppState.get().widgetItemsCount; i++) {
        FileMeta fileMeta = recent.get(i);
        RemoteViews v = new RemoteViews(context.getPackageName(), R.layout.widget_list_image);
        String url = IMG.toUrl(fileMeta.getPath(), ImageExtractor.COVER_PAGE_WITH_EFFECT, IMG.getImageSize());
        Bitmap image = ImageLoader.getInstance().loadImageSync(url, IMG.displayCacheMemoryDisc);
        v.setImageViewBitmap(R.id.imageView1, image);
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.fromFile(new File(fileMeta.getPath())));
        intent.setClassName(context, className);
        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
        v.setOnClickPendingIntent(R.id.imageView1, pendingIntent);
        remoteViews.addView(R.id.linearLayout, v);
    }
}
Also used : RemoteViews(android.widget.RemoteViews) Bitmap(android.graphics.Bitmap) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) HorizontalViewActivity(com.foobnix.pdf.search.activity.HorizontalViewActivity) PendingIntent(android.app.PendingIntent) File(java.io.File) FileMeta(com.foobnix.dao2.FileMeta) SuppressLint(android.annotation.SuppressLint)

Example 39 with FileMeta

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

the class BrowserAdapter method getView.

@Override
public View getView(int i, View convertView, ViewGroup viewGroup) {
    View browserItem = convertView = null;
    if (convertView != null && ((Boolean) convertView.getTag()) != AppState.get().isBrowseGrid) {
        convertView = null;
    }
    if (convertView == null) {
        if (AppState.get().isBrowseGrid) {
            browserItem = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.browse_item_grid, viewGroup, false);
        } else {
            browserItem = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.browse_item_list, viewGroup, false);
        }
        browserItem.setTag(AppState.get().isBrowseGrid);
    }
    final ImageView imageView = (ImageView) browserItem.findViewById(R.id.browserItemIcon);
    final ImageView starIcon = (ImageView) browserItem.findViewById(R.id.starIcon);
    final FileMeta file = files.get(i);
    final TextView title1 = (TextView) browserItem.findViewById(R.id.title1);
    final TextView title2 = (TextView) browserItem.findViewById(R.id.title2);
    title1.setText(file.getPathTxt());
    View progresLayout = browserItem.findViewById(R.id.progresLayout);
    if (progresLayout != null) {
        progresLayout.setVisibility(View.GONE);
    }
    View delete = browserItem.findViewById(R.id.delete);
    if (delete != null) {
        delete.setVisibility(View.GONE);
    }
    final TextView extFile = (TextView) browserItem.findViewById(R.id.browserExt);
    final ImageView itemMenu = (ImageView) browserItem.findViewById(R.id.itemMenu);
    TintUtil.setTintImageWithAlpha(itemMenu);
    final View infoLayout = browserItem.findViewById(R.id.infoLayout);
    final TextView textPath = (TextView) browserItem.findViewById(R.id.browserPath);
    imageView.setColorFilter(null);
    if (file.getPath().equals(currentDirectory.getParent())) {
        imageView.setImageResource(R.drawable.glyphicons_217_circle_arrow_left);
        TintUtil.setTintImageWithAlpha(imageView);
        imageView.setBackgroundColor(Color.TRANSPARENT);
        title1.setText(file.getPath());
        title1.setSingleLine();
        infoLayout.setVisibility(View.GONE);
        itemMenu.setVisibility(View.GONE);
        extFile.setVisibility(View.GONE);
        title2.setVisibility(View.GONE);
        textPath.setVisibility(View.GONE);
        imageView.setScaleType(ScaleType.CENTER_INSIDE);
        starIcon.setVisibility(View.GONE);
        imageView.getLayoutParams().width = AppState.get().isBrowseGrid ? Dips.dpToPx(AppState.get().coverBigSize) : Dips.dpToPx(35);
        imageView.getLayoutParams().height = AppState.get().isBrowseGrid ? Dips.dpToPx((int) (AppState.get().coverBigSize * 1.5)) : Dips.dpToPx(35);
        imageView.setLayoutParams(imageView.getLayoutParams());
    } else if (new File(file.getPath()).isDirectory()) {
        imageView.getLayoutParams().width = AppState.get().isBrowseGrid ? Dips.dpToPx(AppState.get().coverBigSize) : Dips.dpToPx(35);
        imageView.getLayoutParams().height = AppState.get().isBrowseGrid ? Dips.dpToPx((int) (AppState.get().coverBigSize * 1.5)) : Dips.dpToPx(35);
        imageView.setLayoutParams(imageView.getLayoutParams());
        title1.setSingleLine();
        imageView.setImageResource(R.drawable.glyphicons_441_folder_closed);
        TintUtil.setTintImageWithAlpha(imageView);
        imageView.setBackgroundColor(Color.TRANSPARENT);
        infoLayout.setVisibility(View.GONE);
        itemMenu.setVisibility(View.GONE);
        extFile.setVisibility(View.GONE);
        title2.setVisibility(View.GONE);
        textPath.setVisibility(View.GONE);
        imageView.setScaleType(ScaleType.CENTER_INSIDE);
        starIcon.setVisibility(View.GONE);
    } else {
        imageView.setBackgroundColor(Color.TRANSPARENT);
        if (AppState.get().isBrowseGrid) {
            IMG.updateImageSizeBig(imageView);
            IMG.updateImageSizeBig((View) imageView.getParent());
        } else {
            IMG.updateImageSizeSmall(imageView);
            IMG.updateImageSizeSmall((View) imageView.getParent());
        }
        if (AppState.get().isCropBookCovers) {
            imageView.setScaleType(ScaleType.CENTER_CROP);
        } else {
            imageView.setScaleType(ScaleType.FIT_CENTER);
        }
        starIcon.setVisibility(View.VISIBLE);
        if (AppState.get().isBrowseGrid) {
            title2.setVisibility(View.GONE);
            textPath.setVisibility(View.GONE);
        } else {
            title2.setVisibility(View.VISIBLE);
            textPath.setVisibility(View.VISIBLE);
        }
        FileMeta info = null;
        if (info != null) {
            title1.setText("" + info.getTitle());
            title2.setText("" + info.getAuthor());
        }
        if (!AppState.get().isBrowseGrid && AppState.get().coverSmallSize >= IMG.TWO_LINE_COVER_SIZE) {
            title1.setSingleLine(false);
            title1.setLines(2);
        } else {
            title1.setSingleLine(true);
            title1.setLines(1);
        }
        IMG.getCoverPageWithEffect(imageView, file.getPath(), IMG.getImageSize(), new ImageLoadingListener() {

            @Override
            public void onLoadingStarted(String arg0, View arg1) {
            // TODO Auto-generated method stub
            }

            @Override
            public void onLoadingFailed(String arg0, View arg1, FailReason arg2) {
            // TODO Auto-generated method stub
            }

            @Override
            public void onLoadingComplete(String arg0, View arg1, Bitmap arg2) {
                // MetaCache.get().getByPath(file.getPath());
                FileMeta info = null;
                if (info != null) {
                    title1.setText("" + info.getTitle());
                    title2.setText("" + info.getAuthor());
                    textPath.setText(info.getPathTxt());
                    extFile.setText(info.getExt());
                    StarsWrapper.addStars(starIcon, info);
                }
            }

            @Override
            public void onLoadingCancelled(String arg0, View arg1) {
            // TODO Auto-generated method stub
            }
        });
        textPath.setText(file.getPathTxt());
        infoLayout.setVisibility(View.VISIBLE);
        itemMenu.setVisibility(View.VISIBLE);
        extFile.setVisibility(View.VISIBLE);
        final TextView textSize = (TextView) browserItem.findViewById(R.id.browserSize);
        final TextView textDate = (TextView) browserItem.findViewById(R.id.browseDate);
        View menuIcon = browserItem.findViewById(R.id.itemMenu);
        menuIcon.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                if (onMenuPressed != null) {
                // onMenuPressed.onResult(file.getFile());
                }
            }
        });
        extFile.setText(file.getExt());
        textSize.setText(file.getSizeTxt());
        textDate.setText(file.getDateTxt());
    }
    return browserItem;
}
Also used : Bitmap(android.graphics.Bitmap) ImageLoadingListener(com.nostra13.universalimageloader.core.listener.ImageLoadingListener) OnClickListener(android.view.View.OnClickListener) TextView(android.widget.TextView) ImageView(android.widget.ImageView) FailReason(com.nostra13.universalimageloader.core.assist.FailReason) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) File(java.io.File) FileMeta(com.foobnix.dao2.FileMeta)

Example 40 with FileMeta

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

the class Dialogs method showTagsDialog.

public static void showTagsDialog(final Context a, File file, final Runnable refresh) {
    final FileMeta fileMeta = AppDB.get().getOrCreate(file.getPath());
    LOG.d("showTagsDialog book tags", fileMeta.getTag());
    final AlertDialog.Builder builder = new AlertDialog.Builder(a);
    // builder.setTitle(R.string.tag);
    View inflate = LayoutInflater.from(a).inflate(R.layout.dialog_tags, null, false);
    final ListView list = (ListView) inflate.findViewById(R.id.listView1);
    final TextView add = (TextView) inflate.findViewById(R.id.addTag);
    TxtUtils.underline(add, "+ " + a.getString(R.string.add_tag));
    final List<String> tags = StringDB.asList(AppState.get().bookTags);
    List<String> fileTags = StringDB.asList(fileMeta.getTag());
    for (String fileTag : fileTags) {
        if (!StringDB.contains(AppState.get().bookTags, fileTag)) {
            tags.add(fileTag);
        }
    }
    Collections.sort(tags);
    Iterator<String> iterator = tags.iterator();
    while (iterator.hasNext()) {
        if (TxtUtils.isEmpty(iterator.next().trim())) {
            iterator.remove();
        }
    }
    final Set<Integer> checked = new HashSet<>();
    final BaseItemLayoutAdapter<String> adapter = new BaseItemLayoutAdapter<String>(a, R.layout.tag_item, tags) {

        @Override
        public void populateView(View layout, final int position, final String tagName) {
            CheckBox text = (CheckBox) layout.findViewById(R.id.tagName);
            text.setText(tagName);
            text.setOnCheckedChangeListener(new OnCheckedChangeListener() {

                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    if (isChecked) {
                        checked.add(position);
                    } else {
                        checked.remove(position);
                    }
                }
            });
            text.setChecked(StringDB.contains(fileMeta.getTag(), tagName));
            layout.findViewById(R.id.deleteTag).setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    AlertDialogs.showOkDialog((Activity) a, a.getString(R.string.do_you_want_to_delete_this_tag_from_all_books_), new Runnable() {

                        @Override
                        public void run() {
                            checked.clear();
                            AppState.get().bookTags = StringDB.delete(AppState.get().bookTags, tagName);
                            tags.clear();
                            tags.addAll(StringDB.asList(AppState.get().bookTags));
                            notifyDataSetChanged();
                            List<FileMeta> allWithTag = AppDB.get().getAllWithTag(tagName);
                            for (FileMeta meta : allWithTag) {
                                meta.setTag(StringDB.delete(meta.getTag(), tagName));
                            }
                            AppDB.get().updateAll(allWithTag);
                            if (refresh != null) {
                                refresh.run();
                            }
                        }
                    });
                }
            });
        }
    };
    add.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            addTagsDialog(a, new Runnable() {

                @Override
                public void run() {
                    tags.clear();
                    tags.addAll(StringDB.asList(AppState.get().bookTags));
                    adapter.notifyDataSetChanged();
                }
            });
        }
    });
    list.setAdapter(adapter);
    builder.setView(inflate);
    builder.setNegativeButton(R.string.close, new AlertDialog.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
        }
    });
    builder.setPositiveButton(R.string.apply, new AlertDialog.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            String res = "";
            for (int i : checked) {
                res = StringDB.add(res, tags.get(i));
            }
            LOG.d("showTagsDialog", res);
            fileMeta.setTag(res);
            AppDB.get().update(fileMeta);
            if (refresh != null) {
                refresh.run();
            }
            TempHolder.listHash++;
        }
    });
    AlertDialog create = builder.create();
    create.setOnDismissListener(new OnDismissListener() {

        @Override
        public void onDismiss(DialogInterface dialog) {
            Keyboards.close((Activity) a);
            Keyboards.hideNavigation((Activity) a);
        }
    });
    create.show();
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) Activity(android.app.Activity) ListView(android.widget.ListView) TextView(android.widget.TextView) HashSet(java.util.HashSet) OnCheckedChangeListener(android.widget.CompoundButton.OnCheckedChangeListener) OnDismissListener(android.content.DialogInterface.OnDismissListener) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) ListView(android.widget.ListView) CheckBox(android.widget.CheckBox) OnClickListener(android.view.View.OnClickListener) BaseItemLayoutAdapter(com.foobnix.android.utils.BaseItemLayoutAdapter) FileMeta(com.foobnix.dao2.FileMeta) CompoundButton(android.widget.CompoundButton)

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