Search in sources :

Example 11 with FileMeta

use of com.foobnix.dao2.FileMeta 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;
        }
    };
}
Also used : ResultResponse(com.foobnix.android.utils.ResultResponse) File(java.io.File) DocumentFile(android.support.v4.provider.DocumentFile) FileMeta(com.foobnix.dao2.FileMeta)

Example 12 with FileMeta

use of com.foobnix.dao2.FileMeta 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;
        }
    };
}
Also used : ResultResponse(com.foobnix.android.utils.ResultResponse) OpenDirMessage(com.foobnix.pdf.search.activity.msg.OpenDirMessage) Intent(android.content.Intent) File(java.io.File) DocumentFile(android.support.v4.provider.DocumentFile) FileMeta(com.foobnix.dao2.FileMeta)

Example 13 with FileMeta

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

the class FileMetaAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final RecyclerView.ViewHolder holderAll, final int position) {
    final FileMeta fileMeta = getItem(position);
    if (holderAll instanceof StarsTitleViewHolder) {
        final StarsTitleViewHolder holder = (StarsTitleViewHolder) holderAll;
        if (holder.clearAllFolders != null) {
            TxtUtils.underlineTextView(holder.clearAllFolders).setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    clearAllStarredFolders.run();
                }
            });
        }
        if (holder.clearAllBooks != null) {
            TxtUtils.underlineTextView(holder.clearAllBooks).setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    clearAllStarredBooks.run();
                }
            });
        }
        if (holder.onGridList != null) {
            PopupHelper.updateGridOrListIcon(holder.onGridList, AppState.get().starsMode);
            holder.onGridList.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    onGridOrList.onResultRecive(holder.onGridList);
                }
            });
        }
        TintUtil.setBackgroundFillColor(holder.parent, TintUtil.color);
    }
    if (holderAll instanceof FileMetaViewHolder) {
        final FileMetaViewHolder holder = (FileMetaViewHolder) holderAll;
        if (!AppState.get().isShowImages && adapterType == ADAPTER_COVERS) {
            adapterType = ADAPTER_GRID;
        }
        bindFileMetaView(holder, position);
        IMG.getCoverPageWithEffect(holder.image, fileMeta.getPath(), IMG.getImageSize(), new SimpleImageLoadingListener() {

            @Override
            public void onLoadingCancelled(String imageUri, View view) {
                super.onLoadingCancelled(imageUri, view);
            }

            @Override
            public void onLoadingStarted(String imageUri, View view) {
                super.onLoadingStarted(imageUri, view);
            }

            @Override
            public void onLoadingComplete(String arg0, View arg1, Bitmap arg2) {
                if (position <= items.size() - 1) {
                    FileMeta it = AppDB.get().load(fileMeta.getPath());
                    if (it != null) {
                        items.set(position, it);
                        bindFileMetaView(holder, position);
                    }
                }
            }
        });
        holder.imageParent.setVisibility(AppState.get().isShowImages ? View.VISIBLE : View.GONE);
    } else if (holderAll instanceof TagViewHolder) {
        final TagViewHolder holder = (TagViewHolder) holderAll;
        holder.title.setText(fileMeta.getPathTxt());
        TintUtil.setTintImageWithAlpha(holder.image);
        bindItemClickAndLongClickListeners(holder.parent, fileMeta);
    } else if (holderAll instanceof DirectoryViewHolder) {
        final DirectoryViewHolder holder = (DirectoryViewHolder) holderAll;
        holder.title.setText(fileMeta.getPathTxt());
        holder.path.setText(fileMeta.getPath());
        TintUtil.setTintImageWithAlpha(holder.image, holder.image.getContext() instanceof MainTabs2 ? TintUtil.getColorInDayNighth() : TintUtil.getColorInDayNighthBook());
        bindItemClickAndLongClickListeners(holder.parent, fileMeta);
        if (!AppState.get().isBorderAndShadow) {
            holder.parent.setBackgroundColor(Color.TRANSPARENT);
        }
        if (AppDB.get().isStarFolder(fileMeta.getPath())) {
            holder.starIcon.setImageResource(R.drawable.star_1);
        } else {
            holder.starIcon.setImageResource(R.drawable.star_2);
        }
        TintUtil.setTintImageWithAlpha(holder.starIcon, holder.starIcon.getContext() instanceof MainTabs2 ? TintUtil.getColorInDayNighth() : TintUtil.getColorInDayNighthBook());
        if (onStarClickListener != null) {
            holder.starIcon.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    onStarClickListener.onResultRecive(fileMeta, FileMetaAdapter.this);
                }
            });
        }
        holder.starIcon.setVisibility(ExtUtils.isExteralSD(fileMeta.getPath()) ? View.GONE : View.VISIBLE);
        if (adapterType == ADAPTER_GRID || adapterType == ADAPTER_COVERS) {
            // holder.image.setVisibility(View.GONE);
            holder.path.setVisibility(View.GONE);
        } else {
            // holder.image.setVisibility(View.VISIBLE);
            if (tempValue == TEMP_VALUE_FOLDER_PATH) {
                holder.path.setVisibility(View.VISIBLE);
            } else {
                holder.path.setVisibility(View.GONE);
            }
        }
    } else if (holderAll instanceof StarsLayoutViewHolder) {
        final StarsLayoutViewHolder holder = (StarsLayoutViewHolder) holderAll;
        final FileMetaAdapter adapter = new FileMetaAdapter();
        adapter.setOnItemClickListener(onItemClickListener);
        adapter.setOnItemLongClickListener(onItemLongClickListener);
        adapter.setOnMenuClickListener(onMenuClickListener);
        adapter.setOnStarClickListener(onStarClickListener);
        adapter.setOnAuthorClickListener(onAuthorClickListener);
        adapter.setOnSeriesClickListener(onSeriesClickListener);
        adapter.setAdapterType(FileMetaAdapter.ADAPTER_GRID);
        adapter.tempValue = TEMP_VALUE_STAR_GRID_ITEM;
        holder.recyclerView.setAdapter(adapter);
        adapter.getItemsList().clear();
        TintUtil.setBackgroundFillColor(holder.panelRecent, TintUtil.color);
        TintUtil.setBackgroundFillColor(holder.panelStars, TintUtil.color);
        List<FileMeta> allStars = AppDB.get().getStarsFiles();
        final String STARRED = holder.starredName.getContext().getString(R.string.starred).toUpperCase(Locale.US) + " (" + allStars.size() + ")";
        holder.recentName.setText(holder.starredName.getContext().getString(R.string.recent) + " (" + (getItemCount() - 1) + ")");
        holder.starredNameIcon.setImageResource(R.drawable.star_1);
        TintUtil.setTintImageNoAlpha(holder.starredNameIcon, Color.WHITE);
        TxtUtils.underlineTextView(holder.starredName);
        holder.starredName.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(final View v) {
                MyPopupMenu menu = new MyPopupMenu(v.getContext(), v);
                menu.getMenu().add(STARRED).setIcon(R.drawable.star_1).setOnMenuItemClickListener(new OnMenuItemClickListener() {

                    @Override
                    public boolean onMenuItemClick(MenuItem item) {
                        AppState.get().recentTag = "";
                        holder.starredNameIcon.setImageResource(R.drawable.star_1);
                        TintUtil.setTintImageNoAlpha(holder.starredNameIcon, Color.WHITE);
                        TxtUtils.underline(holder.starredName, STARRED);
                        adapter.getItemsList().clear();
                        List<FileMeta> allStars = AppDB.get().getStarsFiles();
                        adapter.getItemsList().addAll(allStars);
                        adapter.notifyDataSetChanged();
                        return false;
                    }
                });
                List<String> tags = AppDB.get().getAll(SEARCH_IN.TAGS);
                Collections.sort(tags);
                for (final String tag : tags) {
                    int count = AppDB.get().getAllWithTag(tag).size();
                    final String nameName = tag + " (" + count + ")";
                    menu.getMenu().add(nameName).setIcon(R.drawable.glyphicons_67_tags).setOnMenuItemClickListener(new OnMenuItemClickListener() {

                        @Override
                        public boolean onMenuItemClick(MenuItem item) {
                            AppState.get().recentTag = tag;
                            holder.starredNameIcon.setImageResource(R.drawable.glyphicons_67_tags);
                            TintUtil.setTintImageNoAlpha(holder.starredNameIcon, Color.WHITE);
                            TxtUtils.underline(holder.starredName, nameName);
                            adapter.getItemsList().clear();
                            List<FileMeta> allTags = AppDB.get().searchBy("@tags " + tag, SORT_BY.FILE_NAME, false);
                            adapter.getItemsList().addAll(allTags);
                            adapter.notifyDataSetChanged();
                            return false;
                        }
                    });
                }
                menu.show();
            }
        });
        if (TxtUtils.isEmpty(AppState.get().recentTag)) {
            holder.starredNameIcon.setImageResource(R.drawable.star_1);
            TintUtil.setTintImageNoAlpha(holder.starredNameIcon, Color.WHITE);
            TxtUtils.underline(holder.starredName, STARRED);
            adapter.getItemsList().clear();
            adapter.getItemsList().addAll(allStars);
            adapter.notifyDataSetChanged();
        } else {
            holder.starredNameIcon.setImageResource(R.drawable.glyphicons_67_tags);
            TintUtil.setTintImageNoAlpha(holder.starredNameIcon, Color.WHITE);
            adapter.getItemsList().clear();
            List<FileMeta> allTags = AppDB.get().searchBy("@tags " + AppState.get().recentTag, SORT_BY.FILE_NAME, false);
            adapter.getItemsList().addAll(allTags);
            adapter.notifyDataSetChanged();
            TxtUtils.underline(holder.starredName, AppState.get().recentTag + " (" + allTags.size() + ")");
        }
    } else if (holderAll instanceof AuthorViewHolder) {
        AuthorViewHolder aHolder = (AuthorViewHolder) holderAll;
        aHolder.onBindViewHolder(aHolder, fileMeta.getSequence());
        aHolder.parent.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                if (onSeriesClickListener != null) {
                    onSeriesClickListener.onResultRecive(fileMeta.getSequence());
                }
            }
        });
    }
}
Also used : MainTabs2(com.foobnix.ui2.MainTabs2) OnMenuItemClickListener(android.view.MenuItem.OnMenuItemClickListener) MyPopupMenu(com.foobnix.pdf.info.view.MyPopupMenu) MenuItem(android.view.MenuItem) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) SimpleImageLoadingListener(com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener) Bitmap(android.graphics.Bitmap) AuthorViewHolder(com.foobnix.ui2.adapter.AuthorsAdapter2.AuthorViewHolder) OnClickListener(android.view.View.OnClickListener) List(java.util.List) FileMeta(com.foobnix.dao2.FileMeta)

Example 14 with FileMeta

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

the class FileMetaAdapter method bindFileMetaView.

private FileMeta bindFileMetaView(final FileMetaViewHolder holder, final int position) {
    if (position >= items.size()) {
        return new FileMeta();
    }
    final FileMeta fileMeta = getItem(position);
    if (fileMeta == null) {
        return new FileMeta();
    }
    holder.title.setText(fileMeta.getTitle());
    holder.author.setText(fileMeta.getAuthor());
    if (AppState.get().isUiTextColor) {
        TintUtil.setUITextColor(holder.author, AppState.get().uiTextColor);
        TintUtil.setUITextColor(holder.series, AppState.get().uiTextColor);
    }
    if (TxtUtils.isEmpty(fileMeta.getAuthor())) {
        if (adapterType == ADAPTER_GRID) {
            holder.author.setVisibility(View.INVISIBLE);
        } else {
            holder.author.setVisibility(View.GONE);
        }
    } else {
        holder.author.setVisibility(View.VISIBLE);
    }
    if (holder.series != null && onSeriesClickListener != null) {
        String sequence = fileMeta.getSequence();
        holder.series.setVisibility(TxtUtils.isNotEmpty(sequence) ? View.VISIBLE : View.GONE);
        holder.series.setText(sequence);
        holder.series.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                if (onSeriesClickListener != null) {
                    onSeriesClickListener.onResultRecive(fileMeta.getSequence());
                }
            }
        });
    }
    holder.author.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (onAuthorClickListener != null) {
                onAuthorClickListener.onResultRecive(fileMeta.getAuthor());
            }
        }
    });
    if (holder.tags != null) {
        if (TxtUtils.isNotEmpty(fileMeta.getTag())) {
            holder.tags.setVisibility(View.VISIBLE);
            holder.tags.removeAllViews();
            for (final String tag : StringDB.asList(fileMeta.getTag())) {
                TextView t = new TextView(holder.tags.getContext());
                t.setTextAppearance(holder.tags.getContext(), R.style.textLink);
                TxtUtils.bold(t);
                t.setText(tag + " ");
                t.setTextSize(12);
                t.setGravity(Gravity.CENTER_VERTICAL);
                TypedValue outValue = new TypedValue();
                holder.tags.getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
                t.setBackgroundResource(outValue.resourceId);
                if (AppState.get().isUiTextColor) {
                    TintUtil.setUITextColor(t, AppState.get().uiTextColor);
                }
                t.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        if (onTagClickListner != null) {
                            onTagClickListner.onResultRecive(tag);
                        }
                    }
                });
                t.setOnLongClickListener(new OnLongClickListener() {

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

                            @Override
                            public void run() {
                                notifyDataSetChanged();
                            }
                        });
                        return true;
                    }
                });
                holder.tags.addView(t);
            }
        } else {
            holder.tags.setVisibility(View.GONE);
        }
    }
    holder.path.setText(fileMeta.getPathTxt());
    holder.browserExt.setText(fileMeta.getChild() != null ? fileMeta.getChild() : fileMeta.getExt());
    if (fileMeta.getPages() != null && fileMeta.getPages() != 0) {
        holder.size.setText(fileMeta.getSizeTxt() + " (" + fileMeta.getPages() + ")");
    } else {
        holder.size.setText(fileMeta.getSizeTxt());
    }
    if (holder.date != null) {
        holder.date.setText(fileMeta.getDateTxt());
    }
    double recentProgress = fileMeta.getIsRecentProgress() == null ? 0 : fileMeta.getIsRecentProgress();
    if (holder.idProgressColor != null && recentProgress > 0) {
        holder.progresLayout.setVisibility(View.VISIBLE);
        holder.idPercentText.setVisibility(View.VISIBLE);
        holder.idProgressColor.setBackgroundColor(TintUtil.color);
        int width = adapterType == ADAPTER_LIST_COMPACT ? Dips.dpToPx(100) : Dips.dpToPx(200);
        holder.idProgressBg.getLayoutParams().width = width;
        holder.idProgressColor.getLayoutParams().width = (int) (width * recentProgress);
        holder.idProgressColor.setLayoutParams(holder.idProgressColor.getLayoutParams());
        holder.idPercentText.setText("" + Math.round(100f * recentProgress) + "%");
    } else if (holder.progresLayout != null) {
        holder.progresLayout.setVisibility(View.INVISIBLE);
        holder.idPercentText.setVisibility(View.INVISIBLE);
    }
    if (adapterType == ADAPTER_GRID && recentProgress > 0) {
        holder.idPercentText.setText("" + (int) (100 * recentProgress) + "%");
        if (AppState.get().coverBigSize < IMG.TWO_LINE_COVER_SIZE) {
            holder.browserExt.setVisibility(View.GONE);
        } else {
            holder.browserExt.setVisibility(View.VISIBLE);
        }
    } else if (adapterType == ADAPTER_GRID) {
        holder.idPercentText.setText("");
        holder.browserExt.setVisibility(View.VISIBLE);
    }
    if (fileMeta.getIsStar() == null || fileMeta.getIsStar() == false) {
        holder.star.setImageResource(R.drawable.star_2);
    } else {
        holder.star.setImageResource(R.drawable.star_1);
    }
    TintUtil.setTintImageWithAlpha(holder.star, holder.parent.getContext() instanceof MainTabs2 ? TintUtil.getColorInDayNighth() : TintUtil.getColorInDayNighthBook());
    if (onStarClickListener != null) {
        holder.star.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                onStarClickListener.onResultRecive(fileMeta, FileMetaAdapter.this);
            }
        });
        holder.star.setOnLongClickListener(new OnLongClickListener() {

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

                    @Override
                    public void run() {
                        notifyDataSetChanged();
                    }
                });
                return true;
            }
        });
    } else {
    }
    holder.star.setVisibility(ExtUtils.isExteralSD(fileMeta.getPath()) ? View.GONE : View.VISIBLE);
    if (holder.signIcon != null) {
        holder.signIcon.setOnClickListener(new OnClickListener() {

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

                    @Override
                    public void run() {
                        TintUtil.setTintImageWithAlpha(holder.signIcon, TxtUtils.isEmpty(fileMeta.getTag()) ? TintUtil.COLOR_TINT_GRAY : TintUtil.color);
                    }
                });
            }
        });
        TintUtil.setTintImageWithAlpha(holder.signIcon, TxtUtils.isEmpty(fileMeta.getTag()) ? TintUtil.COLOR_TINT_GRAY : TintUtil.color);
    }
    bindItemClickAndLongClickListeners(holder.parent, fileMeta);
    if (adapterType == ADAPTER_GRID || adapterType == ADAPTER_COVERS) {
        holder.path.setVisibility(View.GONE);
        holder.size.setVisibility(View.GONE);
        int sizeDP = AppState.get().coverBigSize;
        if (tempValue == TEMP_VALUE_STAR_GRID_ITEM) {
            sizeDP = Math.max(80, AppState.get().coverSmallSize);
        }
        IMG.updateImageSizeBig((View) holder.image.getParent().getParent(), sizeDP);
        LayoutParams lp = holder.image.getLayoutParams();
        lp.width = Dips.dpToPx(sizeDP);
        if (AppState.get().isCropBookCovers) {
            lp.height = (int) (lp.width * IMG.WIDTH_DK);
        } else {
            lp.width = LayoutParams.WRAP_CONTENT;
            lp.height = LayoutParams.WRAP_CONTENT;
        }
    } else {
        holder.path.setVisibility(View.VISIBLE);
        holder.size.setVisibility(View.VISIBLE);
        IMG.updateImageSizeSmall((View) holder.image.getParent().getParent());
        LayoutParams lp = holder.image.getLayoutParams();
        lp.width = Dips.dpToPx(AppState.get().coverSmallSize);
        if (AppState.get().isCropBookCovers) {
            lp.height = (int) (lp.width * IMG.WIDTH_DK);
        } else {
            lp.height = LayoutParams.WRAP_CONTENT;
        }
    }
    if (holder.date != null) {
        holder.date.setVisibility(View.VISIBLE);
        holder.size.setVisibility(View.VISIBLE);
        if (adapterType == ADAPTER_LIST_COMPACT) {
            holder.date.setVisibility(View.GONE);
            holder.size.setVisibility(View.GONE);
        }
    }
    if (AppState.get().isBorderAndShadow) {
        View parent = (View) holder.image.getParent();
        parent.setBackgroundColor(Color.TRANSPARENT);
        FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) parent.getLayoutParams();
        layoutParams.setMargins(0, 0, 0, 0);
    }
    if (AppState.get().isCropBookCovers) {
        holder.image.setScaleType(ScaleType.CENTER_CROP);
    } else {
        holder.image.setScaleType(ScaleType.FIT_CENTER);
    }
    if (holder.layoutBootom != null) {
        if (adapterType == ADAPTER_COVERS) {
            holder.layoutBootom.setVisibility(View.GONE);
            holder.infoLayout.setVisibility(View.GONE);
        } else {
            holder.layoutBootom.setVisibility(View.VISIBLE);
            holder.infoLayout.setVisibility(View.VISIBLE);
        }
    }
    holder.authorParent.setVisibility(View.VISIBLE);
    if (adapterType == ADAPTER_LIST || adapterType == ADAPTER_LIST_COMPACT) {
        if (AppState.get().coverSmallSize >= IMG.TWO_LINE_COVER_SIZE) {
            holder.title.setSingleLine(false);
            holder.title.setLines(2);
            holder.path.setVisibility(View.VISIBLE);
            holder.title.setTextSize(16);
        } else {
            holder.title.setSingleLine(false);
            holder.title.setLines(2);
            holder.title.setTextSize(14);
            holder.authorParent.setVisibility(View.GONE);
            holder.path.setVisibility(View.GONE);
            holder.infoLayout.setVisibility(View.VISIBLE);
            holder.title.setText(fileMeta.getPathTxt());
        }
    }
    TintUtil.setTintImageWithAlpha(holder.menu, holder.parent.getContext() instanceof MainTabs2 ? TintUtil.getColorInDayNighth() : TintUtil.getColorInDayNighthBook());
    if (holder.remove != null) {
        holder.remove.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                onDeleteClickListener.onResultRecive(fileMeta);
            }
        });
        if (onDeleteClickListener == null) {
            holder.remove.setVisibility(View.GONE);
        }
    }
    holder.menu.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (onMenuClickListener != null) {
                onMenuClickListener.onResultRecive(fileMeta);
            }
        }
    });
    holder.parent.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            onItemClickListener.onResultRecive(fileMeta);
        }
    });
    holder.parent.setOnLongClickListener(new OnLongClickListener() {

        @Override
        public boolean onLongClick(View v) {
            onItemLongClickListener.onResultRecive(fileMeta);
            return true;
        }
    });
    if (!AppState.get().isBorderAndShadow) {
        holder.parent.setBackgroundColor(Color.TRANSPARENT);
    }
    return fileMeta;
}
Also used : MainTabs2(com.foobnix.ui2.MainTabs2) LayoutParams(android.view.ViewGroup.LayoutParams) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) OnLongClickListener(android.view.View.OnLongClickListener) FrameLayout(android.widget.FrameLayout) OnClickListener(android.view.View.OnClickListener) TextView(android.widget.TextView) File(java.io.File) FileMeta(com.foobnix.dao2.FileMeta) TypedValue(android.util.TypedValue)

Example 15 with FileMeta

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

the class BooksService method onHandleIntent.

@Override
protected void onHandleIntent(Intent intent) {
    if (intent == null) {
        return;
    }
    try {
        LOG.d(TAG, "BooksService", "Action", intent.getAction());
        if (ACTION_REMOVE_DELETED.equals(intent.getAction())) {
            List<FileMeta> list = AppDB.get().getAll();
            for (FileMeta meta : list) {
                File bookFile = new File(meta.getPath());
                if (!bookFile.exists()) {
                    AppDB.get().delete(meta);
                    LOG.d(TAG, "Delete meta", meta.getPath());
                }
            }
            sendFinishMessage();
            LOG.d("BooksService , searchDate", AppState.get().searchDate);
            if (AppState.get().searchDate != 0) {
                List<FileMeta> localMeta = new LinkedList<FileMeta>();
                for (final String path : AppState.get().searchPaths.split(",")) {
                    if (path != null && path.trim().length() > 0) {
                        final File root = new File(path);
                        if (root.isDirectory()) {
                            LOG.d(TAG, "Searcin in " + root.getPath());
                            SearchCore.search(localMeta, root, ExtUtils.seachExts);
                        }
                    }
                }
                for (FileMeta meta : localMeta) {
                    File file = new File(meta.getPath());
                    if (file.lastModified() >= AppState.get().searchDate) {
                        if (AppDB.get().getDao().hasKey(meta)) {
                            LOG.d(TAG, "Skip book", file.getPath());
                            continue;
                        }
                        FileMetaCore.get().upadteBasicMeta(meta, file);
                        EbookMeta ebookMeta = FileMetaCore.get().getEbookMeta(meta.getPath(), CacheDir.ZipService, true);
                        FileMetaCore.get().udpateFullMeta(meta, ebookMeta);
                        meta.setIsSearchBook(true);
                        AppDB.get().updateOrSave(meta);
                        LOG.d(TAG, "BooksService", "insert", meta.getPath());
                    }
                }
                AppState.get().searchDate = System.currentTimeMillis();
                sendFinishMessage();
            }
        } else if (ACTION_SEARCH_ALL.equals(intent.getAction())) {
            LOG.d(ACTION_SEARCH_ALL);
            IMG.clearDiscCache();
            IMG.clearMemoryCache();
            ImageExtractor.clearErrors();
            List<FileMeta> allWithTag = AppDB.get().getAllWithTag();
            LOG.d(TAG, "allWithTag", allWithTag.size());
            List<Uri> recent = AppSharedPreferences.get().getRecent();
            List<FileMeta> starsAndRecent = AppDB.get().deleteAllSafe();
            long time = Integer.MAX_VALUE;
            for (Uri uri : recent) {
                FileMeta item = new FileMeta(uri.getPath());
                item.setIsRecent(true);
                item.setIsStarTime(time--);
                starsAndRecent.add(item);
            }
            for (FileMeta m : starsAndRecent) {
                if (m.getCusType() != null && FileMetaAdapter.DISPLAY_TYPE_DIRECTORY == m.getCusType()) {
                    m.setIsSearchBook(false);
                } else {
                    m.setIsSearchBook(true);
                }
            }
            AppSharedPreferences.get().cleanRecent();
            itemsMeta.clear();
            handler.post(timer);
            for (final String path : AppState.get().searchPaths.split(",")) {
                if (path != null && path.trim().length() > 0) {
                    final File root = new File(path);
                    if (root.isDirectory()) {
                        LOG.d("Searcin in " + root.getPath());
                        SearchCore.search(itemsMeta, root, ExtUtils.seachExts);
                    }
                }
            }
            AppState.get().searchDate = System.currentTimeMillis();
            for (FileMeta meta : itemsMeta) {
                meta.setIsSearchBook(true);
            }
            itemsMeta.addAll(starsAndRecent);
            AppDB.get().saveAll(itemsMeta);
            handler.removeCallbacks(timer);
            sendFinishMessage();
            handler.post(timer2);
            for (FileMeta meta : itemsMeta) {
                File file = new File(meta.getPath());
                FileMetaCore.get().upadteBasicMeta(meta, file);
            }
            AppDB.get().updateAll(itemsMeta);
            for (FileMeta meta : itemsMeta) {
                EbookMeta ebookMeta = FileMetaCore.get().getEbookMeta(meta.getPath(), CacheDir.ZipService, true);
                LOG.d("BooksService getAuthor", meta.getPath(), ebookMeta.getAuthor());
                FileMetaCore.get().udpateFullMeta(meta, ebookMeta);
            }
            AppDB.get().updateAll(itemsMeta);
            AppDB.get().updateAll(allWithTag);
            itemsMeta.clear();
            handler.removeCallbacks(timer2);
            sendFinishMessage();
            CacheDir.ZipService.removeCacheContent();
        }
    } finally {
    }
}
Also used : EbookMeta(com.foobnix.ext.EbookMeta) List(java.util.List) LinkedList(java.util.LinkedList) File(java.io.File) Uri(android.net.Uri) FileMeta(com.foobnix.dao2.FileMeta) LinkedList(java.util.LinkedList)

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