Search in sources :

Example 1 with Entry

use of com.foobnix.opds.Entry in project LibreraReader by foobnix.

the class OpdsFragment2 method getAllCatalogs.

public List<Entry> getAllCatalogs() {
    if (false) {
        String test = "https://books.fbreader.org/opds";
        return Arrays.asList(new Entry(test, test));
    }
    String[] list = AppState.get().myOPDSLinks.split(";");
    List<Entry> res = new ArrayList<Entry>();
    boolean hasStars = false;
    for (String line : list) {
        if (TxtUtils.isEmpty(line)) {
            continue;
        }
        if (line.contains("star_1.png")) {
            hasStars = true;
            continue;
        }
        String[] it = line.split(",");
        res.add(new Entry(it[0], it[1], it[2], it[3], true));
    }
    if (hasStars) {
        res.add(0, new Entry(SamlibOPDS.ROOT_FAVORITES, getString(R.string.favorites), getString(R.string.my_favorites_links), "assets://opds/star_1.png", true));
    }
    return res;
}
Also used : Entry(com.foobnix.opds.Entry) ArrayList(java.util.ArrayList)

Example 2 with Entry

use of com.foobnix.opds.Entry in project LibreraReader by foobnix.

the class OpdsFragment2 method populateDataInUI.

@Override
public void populateDataInUI(List<Entry> entries) {
    if (isNeedLoginPassword) {
        AddCatalogDialog.showDialogLogin(getActivity(), new Runnable() {

            @Override
            public void run() {
                populate();
            }
        });
        return;
    }
    if (entries == null || entries.isEmpty()) {
        if ("/".equals(url)) {
            return;
        }
        Urls.openWevView(getActivity(), url, new Runnable() {

            @Override
            public void run() {
                url = popStack();
            }
        });
        url = popStack();
        return;
    }
    searchAdapter.clearItems();
    searchAdapter.getItemsList().addAll(entries);
    recyclerView.setAdapter(searchAdapter);
    if (title != null) {
        titleView.setText("" + title.replaceAll("[\n\r\t ]+", " ").trim());
    }
    int isHomeVisible = url == "/" ? View.VISIBLE : View.GONE;
    onPlus.setVisibility(isHomeVisible);
    defaults.setVisibility(isHomeVisible);
    faq.setVisibility(isHomeVisible);
    onProxy.setVisibility(isHomeVisible);
    view1.setVisibility(isHomeVisible);
    starIcon.setVisibility(url == "/" ? View.GONE : View.VISIBLE);
    for (Entry cat : allCatalogs) {
        if (url.equals(cat.homeUrl)) {
            starIcon.setVisibility(View.GONE);
            break;
        }
    }
    if (AppState.get().myOPDSLinks.contains(url)) {
        starIcon.setImageResource(R.drawable.star_1);
    } else {
        starIcon.setImageResource(R.drawable.star_2);
    }
    TintUtil.setTintImageWithAlpha(starIcon, Color.WHITE);
}
Also used : Entry(com.foobnix.opds.Entry)

Example 3 with Entry

use of com.foobnix.opds.Entry in project LibreraReader by foobnix.

the class EntryAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final RecyclerView.ViewHolder holderAll, final int position) {
    final Entry entry = getItem(position);
    final EntryViewHolder holder = (EntryViewHolder) holderAll;
    final Context context = holder.parent.getContext();
    if (TxtUtils.isNotEmpty(entry.title)) {
        String trim = entry.title.trim();
        if (TxtUtils.isNotEmpty(entry.year)) {
            trim += " (" + entry.year + ")";
        }
        holder.title.setText("" + trim);
        holder.title.setVisibility(View.VISIBLE);
    } else {
        holder.title.setVisibility(View.GONE);
    }
    String body = entry.content + entry.summary;
    if (TxtUtils.isNotEmpty(body)) {
        holder.content.setVisibility(View.VISIBLE);
        String text = TxtUtils.replaceLast(body, "\n", "");
        holder.content.setText(Html.fromHtml(text));
        if (body.length() >= 200) {
            holder.expand.setVisibility(View.VISIBLE);
            holder.expand.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    holder.expand.setVisibility(View.GONE);
                    holder.content.setMaxLines(100);
                }
            });
        } else {
            holder.expand.setVisibility(View.GONE);
        }
        if (AppState.get().isInkMode) {
        // holder.expand.setTextColor(Color.GRAY);
        }
    } else {
        holder.content.setVisibility(View.GONE);
        holder.expand.setVisibility(View.GONE);
    }
    if (entry.appState != null) {
        holder.remove.setVisibility(View.VISIBLE);
        holder.remove.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                onRemoveLinkClickListener.onResultRecive(entry);
            }
        });
        if (SamlibOPDS.isSamlibUrl(entry.homeUrl)) {
            holder.remove.setVisibility(View.GONE);
        }
    } else {
        holder.remove.setVisibility(View.GONE);
    }
    if (TxtUtils.isNotEmpty(entry.author)) {
        holder.author.setText(entry.author);
        holder.author.setVisibility(View.VISIBLE);
        if (TxtUtils.isNotEmpty(entry.authorUrl)) {
            holder.author.setTextColor(ContextCompat.getColor(context, R.color.tint_blue));
            if (AppState.get().isUiTextColor) {
                TintUtil.setUITextColor(holder.author, AppState.get().uiTextColor);
            }
            holder.author.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    onLinkClickListener.onResultRecive(new Link(entry.authorUrl));
                }
            });
        } else {
        }
        if (AppState.get().isInkMode) {
        // holder.author.setTextColor(Color.GRAY);
        }
    } else {
        holder.author.setVisibility(View.GONE);
    }
    if (TxtUtils.isNotEmpty(entry.category)) {
        holder.category.setText(entry.category);
        holder.category.setVisibility(View.VISIBLE);
    } else {
        holder.category.setVisibility(View.GONE);
    }
    holder.category.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
        }
    });
    holder.links.removeAllViews();
    holder.downloadLinks.removeAllViews();
    holder.image.setVisibility(View.GONE);
    String imgLink = "";
    for (final Link link : entry.links) {
        if (link.TYPE_LOGO.equals(link.type) || link.isThumbnail()) {
            holder.image.setVisibility(View.VISIBLE);
            ImageLoader.getInstance().displayImage(link.href, holder.image, IMG.displayOPDSOptions);
            if (AppState.get().isInkMode) {
            // TintUtil.grayScaleImageView(holder.image);
            }
        } else if (link.isSearchLink()) {
            LinearLayout l = new LinearLayout(context);
            l.setOrientation(LinearLayout.HORIZONTAL);
            l.setGravity(Gravity.CENTER_VERTICAL);
            final EditText search = new EditText(context);
            search.setTag(true);
            search.setSingleLine();
            search.setMinimumWidth(Dips.dpToPx(400));
            search.setHint(R.string.search);
            final ImageView button = new ImageView(context);
            button.setMinimumWidth(Dips.dpToPx(42));
            button.setImageResource(R.drawable.glyphicons_28_search);
            TintUtil.setTintImageWithAlpha(button);
            l.addView(search, new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, 1.0f));
            l.addView(button, new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 0.0f));
            button.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    if (TxtUtils.isNotEmpty(search.toString())) {
                        String encode = Urls.encode(search.getText().toString());
                        String replace = link.href.replace("{searchterms}", encode).replace("{searchTerms}", encode);
                        Link l = new Link(replace);
                        onLinkClickListener.onResultRecive(l);
                        Keyboards.close(search);
                    } else {
                        Toast.makeText(context, R.string.incorrect_value, Toast.LENGTH_SHORT).show();
                    }
                }
            });
            EditTextHelper.enableKeyboardSearch(search, new Runnable() {

                @Override
                public void run() {
                    button.performClick();
                }
            });
            holder.links.addView(l, new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
        } else if (link.isImageLink()) {
            if (TxtUtils.isNotEmpty(imgLink)) {
                if (link.rel.contains("thumbnail")) {
                    continue;
                }
            }
            if (!link.href.equals(imgLink) && AppState.get().opdsLargeCovers) {
                ScaledImageView img = new ScaledImageView(holder.parent.getContext());
                img.setPadding(PD, PD, PD, PD);
                ImageLoader.getInstance().displayImage(link.href, img, IMG.displayCacheMemoryDisc);
                if (AppState.get().isInkMode) {
                // TintUtil.grayScaleImageView(img);
                }
                holder.links.addView(img, new LinearLayout.LayoutParams(Dips.screenWidth() / 2, LayoutParams.WRAP_CONTENT));
                imgLink = link.href;
                img.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        FileInformationDialog.showImageHttpPath(context, link.href);
                    }
                });
            }
        } else if (link.type == null || link.type.equals(Link.APPLICATION_ATOM_XML) || (link.type.contains(";profile") && link.title == null)) {
            continue;
        } else if (link.isWebLink() && TxtUtils.isEmpty(link.title)) {
            continue;
        } else if (link.isDisabled()) {
            continue;
        } else {
            TextView t = new TextView(holder.parent.getContext());
            t.setPadding(PD, PD, PD, PD);
            t.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    onLinkClickListener.onResultRecive(link);
                }
            });
            t.setOnLongClickListener(new OnLongClickListener() {

                @Override
                public boolean onLongClick(View v) {
                    holder.parent.performLongClick();
                    return false;
                }
            });
            String downloadFormat = link.getDownloadDisplayFormat();
            if (downloadFormat != null) {
                t.setText(link.title != null ? link.title : downloadFormat.replace(".zip", ""));
                t.setGravity(Gravity.CENTER);
                t.setBackgroundResource(R.drawable.bg_border_blue_entry);
                t.setMinimumWidth(Dips.dpToPx(40));
                if (link.filePath != null) {
                    Drawable d = ContextCompat.getDrawable(context, R.drawable.glyphicons_2_book_open2);
                    TintUtil.setDrawableTint(d, t.getCurrentTextColor());
                    t.setCompoundDrawablePadding(Dips.dpToPx(6));
                    t.setCompoundDrawablesWithIntrinsicBounds(d, null, null, null);
                    t.setActivated(true);
                }
                android.widget.LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
                lp.setMargins(0, 0, Dips.dpToPx(4), 0);
                holder.downloadLinks.addView(t, lp);
            } else {
                t.setText(link.title != null ? link.title : link.type);
                t.setTextColor(context.getResources().getColor(R.color.tint_blue));
                if (AppState.get().isUiTextColor) {
                    TintUtil.setUITextColor(t, AppState.get().uiTextColor);
                }
                if (AppState.get().isInkMode) {
                // t.setTextColor(Color.GRAY);
                }
                holder.links.addView(t);
            }
        }
    }
    bindItemClickAndLongClickListeners(holder.parent, entry);
}
Also used : Context(android.content.Context) EditText(android.widget.EditText) LayoutParams(android.support.v7.widget.StaggeredGridLayoutManager.LayoutParams) ScaledImageView(com.foobnix.pdf.info.view.ScaledImageView) Drawable(android.graphics.drawable.Drawable) ScaledImageView(com.foobnix.pdf.info.view.ScaledImageView) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) Entry(com.foobnix.opds.Entry) OnLongClickListener(android.view.View.OnLongClickListener) OnClickListener(android.view.View.OnClickListener) TextView(android.widget.TextView) ScaledImageView(com.foobnix.pdf.info.view.ScaledImageView) ImageView(android.widget.ImageView) Link(com.foobnix.opds.Link) LinearLayout(android.widget.LinearLayout)

Example 4 with Entry

use of com.foobnix.opds.Entry in project LibreraReader by foobnix.

the class OpdsFragment2 method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_opds2, container, false);
    recyclerView = (FastScrollRecyclerView) view.findViewById(R.id.recyclerView);
    titleView = (TextView) view.findViewById(R.id.titleView);
    onPlus = (ImageView) view.findViewById(R.id.onPlus);
    onProxy = (ImageView) view.findViewById(R.id.onProxy);
    starIcon = (ImageView) view.findViewById(R.id.starIcon);
    pathContainer = view.findViewById(R.id.pathContainer);
    view1 = view.findViewById(R.id.view1);
    view2 = view.findViewById(R.id.view2);
    progressBar = (ProgressBar) view.findViewById(R.id.progressBar);
    progressBar.setVisibility(View.GONE);
    TintUtil.setDrawableTint(progressBar.getIndeterminateDrawable().getCurrent(), Color.WHITE);
    onPlus.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            AddCatalogDialog.showDialog(getActivity(), new Runnable() {

                @Override
                public void run() {
                    populate();
                }
            }, null, true);
        }
    });
    searchAdapter = new EntryAdapter();
    defaults = (TextView) view.findViewById(R.id.defaults);
    faq = (TextView) view.findViewById(R.id.faq);
    defaults.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            AlertDialogs.showOkDialog(getActivity(), getActivity().getString(R.string.restore_defaults_full), new Runnable() {

                @Override
                public void run() {
                    AppState.get().myOPDSLinks = AppState.OPDS_DEFAULT;
                    url = "/";
                    populate();
                }
            });
        }
    });
    faq.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Urls.open(getActivity(), "https://wiki.mobileread.com/wiki/OPDS");
        }
    });
    onGridList();
    searchAdapter.setOnItemClickListener(new ResultResponse<Entry>() {

        @Override
        public boolean onResultRecive(Entry result) {
            for (Link link : result.links) {
                if (link.isOpdsLink()) {
                    onClickLink(link);
                    break;
                }
            }
            return false;
        }
    });
    searchAdapter.setOnRemoveLinkClickListener(new ResultResponse<Entry>() {

        @Override
        public boolean onResultRecive(final Entry result) {
            AlertDialogs.showDialog(getActivity(), getActivity().getString(R.string.do_you_want_to_delete_), getString(R.string.delete), new Runnable() {

                @Override
                public void run() {
                    AppState.get().myOPDSLinks = AppState.get().myOPDSLinks.replace(result.appState, "");
                    url = "/";
                    populate();
                }
            });
            return false;
        }
    });
    searchAdapter.setOnLinkClickListener(new ResultResponse<Link>() {

        @Override
        public boolean onResultRecive(Link link) {
            onClickLink(link);
            return false;
        }
    });
    searchAdapter.setOnItemLongClickListener(new ResultResponse<Entry>() {

        @Override
        public boolean onResultRecive(Entry result) {
            if (url.equals("/")) {
                AddCatalogDialog.showDialog(getActivity(), new Runnable() {

                    @Override
                    public void run() {
                        populate();
                    }
                }, result, SamlibOPDS.isSamlibUrl(result.homeUrl) ? false : true);
            }
            return false;
        }
    });
    starIcon.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            final Entry entry = new Entry();
            String url2 = url;
            if (url2.contains("?")) {
                url2 = url2.substring(0, url2.indexOf("?"));
            }
            entry.setAppState(url, title, url2, "assets://opds/star_1.png");
            if (!AppState.get().myOPDSLinks.contains(url)) {
                AddCatalogDialog.showDialog(getActivity(), new Runnable() {

                    @Override
                    public void run() {
                        starIcon.setImageResource(R.drawable.star_1);
                        TintUtil.setTintImageWithAlpha(starIcon, Color.WHITE);
                    }
                }, entry, false);
            } else {
                AppState.get().myOPDSLinks = AppState.get().myOPDSLinks.replace(entry.appState, "");
                starIcon.setImageResource(R.drawable.star_2);
                TintUtil.setTintImageWithAlpha(starIcon, Color.WHITE);
            // AlertDialogs.showOkDialog(getActivity(),
            // getActivity().getString(R.string.do_you_want_to_delete_), new Runnable() {
            // 
            // @Override
            // public void run() {
            // 
            // // url = "/";
            // }
            // });
            }
        }
    });
    view.findViewById(R.id.onBack).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            onBackAction();
        }
    });
    view.findViewById(R.id.onHome).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            stack.clear();
            url = getHome();
            LOG.d("URLAction", "ADD", url);
            urlRoot = "";
            populate();
        }
    });
    view.findViewById(R.id.onHome).setOnLongClickListener(new OnLongClickListener() {

        @Override
        public boolean onLongClick(View v) {
            AlertDialogs.showOkDialog(getActivity(), getActivity().getString(R.string.restore_defaults_full), new Runnable() {

                @Override
                public void run() {
                    AppState.get().myOPDSLinks = AppState.OPDS_DEFAULT;
                    populate();
                }
            });
            return true;
        }
    });
    onProxy.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            final AlertDialog.Builder builder = new AlertDialog.Builder(v.getContext());
            View view = LayoutInflater.from(v.getContext()).inflate(R.layout.dialog_proxy_server, null, false);
            final CheckBox proxyEnable = (CheckBox) view.findViewById(R.id.proxyEnable);
            final CheckBox opdsLargeCovers = (CheckBox) view.findViewById(R.id.opdsLargeCovers);
            final EditText proxyServer = (EditText) view.findViewById(R.id.proxyServer);
            final EditText proxyPort = (EditText) view.findViewById(R.id.proxyPort);
            final EditText proxyUser = (EditText) view.findViewById(R.id.proxyUser);
            final EditText proxyPassword = (EditText) view.findViewById(R.id.proxyPassword);
            final TextView proxyType = (TextView) view.findViewById(R.id.proxyType);
            TintUtil.setBackgroundFillColor(view.findViewById(R.id.section1), TintUtil.color);
            TintUtil.setBackgroundFillColor(view.findViewById(R.id.section2), TintUtil.color);
            proxyEnable.setChecked(AppState.get().proxyEnable);
            proxyServer.setText(AppState.get().proxyServer);
            proxyPort.setText(AppState.get().proxyPort == 0 ? "" : "" + AppState.get().proxyPort);
            proxyUser.setText(AppState.get().proxyUser);
            proxyPassword.setText(AppState.get().proxyPassword);
            proxyEnable.setOnCheckedChangeListener(new OnCheckedChangeListener() {

                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    if (isChecked) {
                        if (TxtUtils.isEmpty(proxyServer.getText().toString())) {
                            proxyServer.requestFocus();
                            proxyEnable.setChecked(false);
                            Toast.makeText(getContext(), R.string.incorrect_value, Toast.LENGTH_SHORT).show();
                        } else if ("0".equals(proxyPort.getText().toString()) || TxtUtils.isEmpty(proxyPort.getText().toString())) {
                            proxyPort.requestFocus();
                            proxyEnable.setChecked(false);
                            Toast.makeText(getContext(), R.string.incorrect_value, Toast.LENGTH_SHORT).show();
                        }
                    }
                }
            });
            TxtUtils.underline(proxyType, AppState.get().proxyType);
            proxyType.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    PopupMenu menu = new PopupMenu(v.getContext(), v);
                    menu.getMenu().add(AppState.PROXY_HTTP).setOnMenuItemClickListener(new OnMenuItemClickListener() {

                        @Override
                        public boolean onMenuItemClick(MenuItem item) {
                            AppState.get().proxyType = AppState.PROXY_HTTP;
                            TxtUtils.underline(proxyType, AppState.get().proxyType);
                            return false;
                        }
                    });
                    menu.getMenu().add(AppState.PROXY_SOCKS).setOnMenuItemClickListener(new OnMenuItemClickListener() {

                        @Override
                        public boolean onMenuItemClick(MenuItem item) {
                            AppState.get().proxyType = AppState.PROXY_SOCKS;
                            TxtUtils.underline(proxyType, AppState.get().proxyType);
                            return false;
                        }
                    });
                    menu.show();
                }
            });
            builder.setPositiveButton(R.string.apply, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    AppState.get().proxyEnable = proxyEnable.isChecked();
                    AppState.get().proxyServer = proxyServer.getText().toString();
                    try {
                        AppState.get().proxyPort = Integer.parseInt(proxyPort.getText().toString());
                    } catch (Exception e) {
                        AppState.get().proxyPort = 0;
                    }
                    AppState.get().proxyUser = proxyUser.getText().toString().trim();
                    AppState.get().proxyPassword = proxyPassword.getText().toString().trim();
                    OPDS.buildProxy();
                    AppState.get().save(getActivity());
                    Keyboards.close(proxyServer);
                }
            });
            builder.setNeutralButton(R.string.cancel, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                }
            });
            opdsLargeCovers.setChecked(AppState.get().opdsLargeCovers);
            opdsLargeCovers.setOnCheckedChangeListener(new OnCheckedChangeListener() {

                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    AppState.get().opdsLargeCovers = isChecked;
                }
            });
            final TextView downlodsPath = (TextView) view.findViewById(R.id.downlodsPath);
            TxtUtils.underline(downlodsPath, TxtUtils.lastTwoPath(AppState.get().downlodsPath));
            downlodsPath.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(final View v) {
                    ChooserDialogFragment.chooseFolder(getActivity(), AppState.get().downlodsPath).setOnSelectListener(new ResultResponse2<String, Dialog>() {

                        @Override
                        public boolean onResultRecive(String nPath, Dialog dialog) {
                            AppState.get().downlodsPath = nPath;
                            TxtUtils.underline(downlodsPath, TxtUtils.lastTwoPath(AppState.get().downlodsPath));
                            dialog.dismiss();
                            return false;
                        }
                    });
                }
            });
            builder.setView(view);
            builder.show();
        }
    });
    OPDS.buildProxy();
    populate();
    onTintChanged();
    return view;
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) OnMenuItemClickListener(android.view.MenuItem.OnMenuItemClickListener) Entry(com.foobnix.opds.Entry) AlertDialog(android.app.AlertDialog) Dialog(android.app.Dialog) AddCatalogDialog(com.foobnix.pdf.info.widget.AddCatalogDialog) OnLongClickListener(android.view.View.OnLongClickListener) TextView(android.widget.TextView) EditText(android.widget.EditText) OnCheckedChangeListener(android.widget.CompoundButton.OnCheckedChangeListener) EntryAdapter(com.foobnix.ui2.adapter.EntryAdapter) MenuItem(android.view.MenuItem) FastScrollRecyclerView(com.foobnix.ui2.fast.FastScrollRecyclerView) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) RecyclerView(android.support.v7.widget.RecyclerView) CheckBox(android.widget.CheckBox) OnClickListener(android.view.View.OnClickListener) Link(com.foobnix.opds.Link) CompoundButton(android.widget.CompoundButton) PopupMenu(android.widget.PopupMenu)

Example 5 with Entry

use of com.foobnix.opds.Entry in project LibreraReader by foobnix.

the class OpdsFragment2 method prepareDataInBackground.

@Override
public List<Entry> prepareDataInBackground() {
    try {
        LOG.d("OPDS URL", url);
        if ("/".equals(url)) {
            title = getString(R.string.catalogs);
            return allCatalogs = getAllCatalogs();
        }
        if (SamlibOPDS.isSamlibUrl(url)) {
            Pair<List<Entry>, String> pair = SamlibOPDS.getSamlibResult(url);
            List<Entry> samlibResult = pair.first;
            title = pair.second.replace(SamlibOPDS.ROOT_FAVORITES, getString(R.string.favorites)).replace(SamlibOPDS.ROOT_AWARDS, getString(R.string.awards));
            return samlibResult;
        }
        Feed feed = OPDS.getFeed(url);
        if (feed == null) {
            return Collections.emptyList();
        }
        isNeedLoginPassword = feed.isNeedLoginPassword;
        LOG.d("Load: >>>", feed.title, url);
        feed.updateLinksForUI();
        updateLinks(feed.title, urlRoot, feed.links);
        for (Link link : feed.links) {
            if ("next".equals(link.rel)) {
                feed.entries.add(new Entry("Next", link));
                break;
            }
        }
        for (Entry e : feed.entries) {
            updateLinks(e.getTitle(), urlRoot, e.links);
            if (e.authorUrl != null) {
                e.authorUrl = Hrefs.fixHref(e.authorUrl, urlRoot);
            }
        }
        title = TxtUtils.nullToEmpty(feed.title).replace("\n", "").replace("\r", "").trim();
        return feed.entries;
    } catch (Exception e) {
        LOG.e(e);
        return Collections.emptyList();
    }
}
Also used : Entry(com.foobnix.opds.Entry) List(java.util.List) ArrayList(java.util.ArrayList) Link(com.foobnix.opds.Link) Feed(com.foobnix.opds.Feed)

Aggregations

Entry (com.foobnix.opds.Entry)6 View (android.view.View)3 OnClickListener (android.view.View.OnClickListener)3 EditText (android.widget.EditText)3 ImageView (android.widget.ImageView)3 Link (com.foobnix.opds.Link)3 AlertDialog (android.app.AlertDialog)2 DialogInterface (android.content.DialogInterface)2 RecyclerView (android.support.v7.widget.RecyclerView)2 OnLongClickListener (android.view.View.OnLongClickListener)2 CheckBox (android.widget.CheckBox)2 TextView (android.widget.TextView)2 Feed (com.foobnix.opds.Feed)2 ArrayList (java.util.ArrayList)2 Dialog (android.app.Dialog)1 Context (android.content.Context)1 OnDismissListener (android.content.DialogInterface.OnDismissListener)1 Drawable (android.graphics.drawable.Drawable)1 AsyncTask (android.os.AsyncTask)1 LayoutParams (android.support.v7.widget.StaggeredGridLayoutManager.LayoutParams)1