use of com.foobnix.ui2.adapter.EntryAdapter 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;
}
Aggregations