use of com.foobnix.opds.Entry in project LibreraReader by foobnix.
the class AddCatalogDialog method showDialog.
public static void showDialog(final Activity a, final Runnable onRefresh, final Entry e, final boolean validate) {
AlertDialog.Builder builder = new AlertDialog.Builder(a);
View dialog = LayoutInflater.from(a).inflate(R.layout.dialog_add_catalog, null, false);
final EditText url = (EditText) dialog.findViewById(R.id.url);
url.setText("http://");
url.setSelection(url.getText().length());
url.setEnabled(validate);
final EditText name = (EditText) dialog.findViewById(R.id.name);
final EditText description = (EditText) dialog.findViewById(R.id.description);
final ProgressBar progressBar = (ProgressBar) dialog.findViewById(R.id.progressBar);
TintUtil.setDrawableTint(progressBar.getIndeterminateDrawable().getCurrent(), TintUtil.color);
final ImageView image = (ImageView) dialog.findViewById(R.id.image);
final CheckBox addAsWEb = (CheckBox) dialog.findViewById(R.id.addAsWEb);
addAsWEb.setVisibility(View.GONE);
final String editAppState = e != null ? e.appState : null;
if (editAppState != null) {
String[] line = e.appState.replace(";", "").split(",");
url.setText(line[0]);
name.setText(line[1]);
description.setText(line[2]);
ImageLoader.getInstance().displayImage(line[3], image, IMG.displayCacheMemoryDisc);
if (e.logo != null) {
image.setTag(e.logo);
}
}
progressBar.setVisibility(View.GONE);
image.setVisibility(View.GONE);
builder.setView(dialog);
builder.setTitle(R.string.add_catalog);
builder.setPositiveButton(R.string.add, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
}
});
builder.setNegativeButton(R.string.close, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
Keyboards.close(a);
}
});
final AlertDialog infoDialog = builder.create();
infoDialog.setOnDismissListener(new OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
Keyboards.close(a);
}
});
infoDialog.show();
url.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
infoDialog.getButton(AlertDialog.BUTTON_POSITIVE).setText(R.string.add);
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
}
});
infoDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() {
AsyncTask asyncTask;
@Override
public void onClick(View v) {
final String feedUrl = url.getText().toString();
if (infoDialog.getButton(AlertDialog.BUTTON_POSITIVE).getText().equals(a.getString(R.string.ok)) || addAsWEb.isChecked() || !validate) {
Entry entry = new Entry();
entry.setAppState(feedUrl, name.getText().toString(), description.getText().toString(), image.getTag().toString());
if (editAppState != null) {
AppState.get().myOPDSLinks = AppState.get().myOPDSLinks.replace(editAppState, "");
}
AppState.get().myOPDSLinks = entry.appState + AppState.get().myOPDSLinks;
onRefresh.run();
infoDialog.dismiss();
AppState.get().save(a);
return;
}
if (AsyncTasks.isRunning(asyncTask)) {
AsyncTasks.toastPleaseWait(a);
return;
}
asyncTask = new AsyncTask() {
@Override
protected Object doInBackground(Object... params) {
return OPDS.getFeed(feedUrl);
}
@Override
protected void onPreExecute() {
progressBar.setVisibility(View.VISIBLE);
image.setVisibility(View.GONE);
}
@Override
protected void onPostExecute(Object result) {
try {
progressBar.setVisibility(View.GONE);
if (result == null || ((Feed) result).entries.isEmpty()) {
if (result != null && ((Feed) result).isNeedLoginPassword) {
AddCatalogDialog.showDialogLogin(a, new Runnable() {
@Override
public void run() {
}
});
} else {
Toast.makeText(a, a.getString(R.string.incorrect_value) + " OPDS " + feedUrl, Toast.LENGTH_LONG).show();
infoDialog.getButton(AlertDialog.BUTTON_POSITIVE).setText(R.string.add);
addAsWEb.setVisibility(View.VISIBLE);
name.setText(feedUrl);
image.setTag("assets://opds/web.png");
}
return;
}
Feed feed = (Feed) result;
name.setText(TxtUtils.nullToEmpty(feed.title));
if (TxtUtils.isNotEmpty(feed.subtitle)) {
description.setText(TxtUtils.nullToEmpty(feed.subtitle));
}
if (feed.icon != null) {
image.setVisibility(View.VISIBLE);
feed.icon = Hrefs.fixHref(feed.icon, feedUrl);
image.setTag(feed.icon);
ImageLoader.getInstance().displayImage(feed.icon, image, IMG.displayCacheMemoryDisc);
} else {
image.setTag("assets://opds/web.png");
}
infoDialog.getButton(AlertDialog.BUTTON_POSITIVE).setText(R.string.ok);
} catch (Exception e) {
LOG.e(e);
}
}
}.execute();
}
});
}
Aggregations