use of com.foobnix.opds.Link in project LibreraReader by foobnix.
the class OpdsFragment2 method updateLinks.
public void updateLinks(String parentTitle, String homeUrl, List<Link> links) {
for (Link l : links) {
Hrefs.fixHref(l, homeUrl);
l.parentTitle = parentTitle;
File book = new File(AppState.get().downlodsPath, l.getDownloadName());
if (book.isFile()) {
l.filePath = book.getPath();
}
}
}
use of com.foobnix.opds.Link 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);
}
use of com.foobnix.opds.Link 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;
}
use of com.foobnix.opds.Link 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();
}
}
Aggregations