- public void onClick(View view) {
- new AsyncTask<Void, Void, String>() {
- @Override
- protected void onPreExecute() {
- EditText editText = findViewById(R.id.editText);
- editText.setText("Downloading...");
- }
-
- @Override
- protected String doInBackground(Void... voids) {
- try {
- URL[] urls = new URL[] {
- new URL("https://e621.net/pool/show/13124"),
- new URL("https://e621.net/pool/show/13121"), };
-
- for (int i = 0; i < urls.length; i++) {
- if (reader.getLibrary().getList().size() <= i) {
- reader.getLibrary().imprt(urls[i], null);
- }
- }
-
- String message = "";
- for (MetaData meta : reader.getLibrary().getList()) {
- message += meta.getTitle() + "\n";
+ public void onAdd(View view) {
+ final View root = findViewById(R.id.Main);
+
+ ask(this,
+ "Import new story",
+ "Enter the story URL (the program will then download it -- the interface will not be usable until it is downloaded",
+ "Download", new AnswerListener() {
+ @Override
+ public void onAnswer(final String answer) {
+ root.setEnabled(false);
+ new Thread(new Runnable() {
+ @Override
+ public void run() {
+ try {
+ URL url = new URL(answer);
+ reader.getLibrary().imprt(url, null);
+ } catch (Throwable e) {
+ // TODO: show error message correctly
+ String mess = "";
+ for (String tab = ""; e != null
+ && e != e.getCause(); e = e
+ .getCause()) {
+ mess += tab + "["
+ + e.getClass().getSimpleName()
+ + "] " + e.getMessage() + "\n";
+ tab += "\t";
+ }
+
+ final String messf = mess;
+ AndroidReaderActivity.this
+ .runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ ask(AndroidReaderActivity.this,
+ "Error",
+ "Cannot import URL: \n"
+ + messf,
+ "OK", null);
+ }
+ });
+
+ }
+
+ AndroidReaderActivity.this
+ .runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ refresh();
+ root.setEnabled(true);
+ }
+ });
+ }
+ }).start();