Merge branch 'master' of github.com:nikiroo/fanfix
authorNiki Roo <niki@nikiroo.be>
Thu, 21 Dec 2017 06:44:56 +0000 (07:44 +0100)
committerNiki Roo <niki@nikiroo.be>
Thu, 21 Dec 2017 06:44:56 +0000 (07:44 +0100)
18 files changed:
configure.sh
res/layout/activity_main.xml
res/layout/activity_say_it.xml [deleted file]
res/layout/fragment_android_reader_book.xml
res/layout/fragment_android_reader_group.xml
res/mipmap-anydpi-v26/ic_launcher.xml [deleted file]
res/mipmap-anydpi-v26/ic_launcher_round.xml [deleted file]
src/AndroidManifest.xml
src/be/nikiroo/fanfix/DataLoader.java
src/be/nikiroo/fanfix/Instance.java
src/be/nikiroo/fanfix/VersionCheck.java
src/be/nikiroo/fanfix/bundles/StringIdBundle.java
src/be/nikiroo/fanfix/library/CacheLibrary.java
src/be/nikiroo/fanfix/reader/android/AndroidReaderActivity.java
src/be/nikiroo/fanfix/reader/android/AndroidReaderBook.java
src/be/nikiroo/fanfix/reader/android/AndroidReaderGroup.java
src/be/nikiroo/fanfix/reader/android/SayIt.java [deleted file]
src/be/nikiroo/fanfix/supported/BasicSupport.java

index 8952fef2d7ec607ded0d7c6b4a3af0a1931339fe..e054bf646ad3b7fbcafdbb333bf817217bb45bf0 100755 (executable)
@@ -4,9 +4,11 @@
 PREFIX=/usr/local
 PROGS="java javac jar make sed"
 
+IMG=be/nikiroo/utils/ui/ImageUtilsAwt
 CLI=be/nikiroo/fanfix/reader/cli/CliReader
 TUI=
 GUI=be/nikiroo/fanfix/reader/ui/GuiReader
+JIMG=
 JCLI=
 JTUI=
 JGUI=
@@ -76,7 +78,7 @@ else
 fi;
 
 echo "MAIN = be/nikiroo/fanfix/Main" > Makefile
-echo "MORE = $CLI $TUI $GUI" >> Makefile
+echo "MORE = $CLI $TUI $GUI $IMG" >> Makefile
 echo "TEST = be/nikiroo/fanfix/test/Test" >> Makefile
 echo "TEST_PARAMS = $cols $ok $ko" >> Makefile
 echo "NAME = fanfix" >> Makefile
index 6187f32de1c854ec8f9afe1b2651d3f5c7185fdc..e576892e8981cb6018d1ae5daf7d104004fc9ce5 100644 (file)
@@ -2,60 +2,37 @@
 <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:app="http://schemas.android.com/apk/res-auto"
     xmlns:tools="http://schemas.android.com/tools"
-    android:id="@+id/mainRoot"
+    android:id="@+id/Main"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     tools:context=".AndroidReaderActivity">
 
-    <EditText
-        android:id="@+id/editText"
-        android:layout_width="177dp"
-        android:layout_height="38dp"
-        android:layout_marginStart="8dp"
-        android:layout_marginTop="8dp"
-        android:ems="10"
-        android:inputType="textPersonName"
-        android:text="@string/enter_text"
-        app:layout_constraintStart_toStartOf="parent"
-        app:layout_constraintTop_toTopOf="parent" />
-
-    <Button
-        android:id="@+id/button"
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
-        android:layout_marginEnd="8dp"
-        android:layout_marginStart="8dp"
-        android:onClick="onClick"
-        android:text="Download if needed"
-        app:layout_constraintBottom_toBottomOf="@+id/editText"
-        app:layout_constraintEnd_toEndOf="parent"
-        app:layout_constraintHorizontal_bias="1.0"
-        app:layout_constraintStart_toEndOf="@+id/editText" />
-
     <Button
-        android:id="@+id/button2"
+        android:id="@+id/Main_btnAdd"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_marginEnd="8dp"
         android:layout_marginStart="8dp"
-        android:layout_marginTop="28dp"
-        android:onClick="buttonClick"
-        android:text="Add all sources"
+        android:layout_marginTop="8dp"
+        android:onClick="onAdd"
+        android:text="Add story"
         app:layout_constraintEnd_toEndOf="parent"
         app:layout_constraintHorizontal_bias="0.472"
         app:layout_constraintStart_toStartOf="parent"
-        app:layout_constraintTop_toBottomOf="@+id/editText" />
+        app:layout_constraintTop_toTopOf="parent" />
 
     <LinearLayout
-        android:id="@+id/dropZone"
-        android:layout_width="363dp"
-        android:layout_height="wrap_content"
+        android:id="@+id/Main_pnlStories"
+        android:layout_width="0dp"
+        android:layout_height="0dp"
+        android:layout_marginBottom="8dp"
         android:layout_marginEnd="8dp"
         android:layout_marginStart="8dp"
-        android:layout_marginTop="88dp"
+        android:layout_marginTop="8dp"
         android:orientation="vertical"
+        app:layout_constraintBottom_toBottomOf="parent"
         app:layout_constraintEnd_toEndOf="parent"
         app:layout_constraintStart_toStartOf="parent"
-        app:layout_constraintTop_toBottomOf="@+id/editText"></LinearLayout>
+        app:layout_constraintTop_toBottomOf="@+id/Main_btnAdd"></LinearLayout>
 
 </android.support.constraint.ConstraintLayout>
diff --git a/res/layout/activity_say_it.xml b/res/layout/activity_say_it.xml
deleted file mode 100644 (file)
index 527ae08..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:app="http://schemas.android.com/apk/res-auto"
-    xmlns:tools="http://schemas.android.com/tools"
-    android:layout_width="match_parent"
-    android:layout_height="match_parent"
-    tools:context="be.nikiroo.testy.be.nikiroo.fanfix.reader.android.SayIt">
-
-    <TextView
-        android:id="@+id/textView"
-        android:layout_width="285dp"
-        android:layout_height="250dp"
-        android:text="TextView"
-        tools:layout_editor_absoluteX="38dp"
-        tools:layout_editor_absoluteY="130dp" />
-</android.support.constraint.ConstraintLayout>
index a742c86b5bc188f5b3cd90801420b068f27bbb8d..3cd5423840d19495ff3b9125f29619b77feba0e2 100644 (file)
@@ -1,7 +1,7 @@
 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:app="http://schemas.android.com/apk/res-auto"
     xmlns:tools="http://schemas.android.com/tools"
-    android:id="@+id/coverWidget"
+    android:id="@+id/Book"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:clickable="true"
         android:layout_height="wrap_content">
 
         <TextView
-            android:id="@+id/title"
+            android:id="@+id/Book_lblTitle"
             android:layout_width="0dp"
             android:layout_height="wrap_content"
             android:layout_marginEnd="8dp"
             android:layout_marginStart="8dp"
             android:layout_marginTop="8dp"
-            android:text="TITLE"
-            app:layout_constraintEnd_toStartOf="@+id/cover"
+            android:textStyle="bold"
+            app:layout_constraintEnd_toStartOf="@+id/Book_imgCover"
             app:layout_constraintStart_toStartOf="parent"
-            app:layout_constraintTop_toTopOf="@+id/cover" />
+            app:layout_constraintTop_toTopOf="@+id/Book_imgCover" />
 
         <ImageView
-            android:id="@+id/cover"
+            android:id="@+id/Book_imgCover"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_marginBottom="8dp"
             app:layout_constraintBottom_toBottomOf="parent"
             app:layout_constraintEnd_toEndOf="parent"
             app:layout_constraintTop_toTopOf="parent" />
+
+        <TextView
+            android:id="@+id/Book_lblAuthor"
+            android:layout_width="0dp"
+            android:layout_height="wrap_content"
+            android:layout_marginEnd="8dp"
+            android:layout_marginTop="8dp"
+            android:textColor="@android:color/darker_gray"
+            app:layout_constraintEnd_toStartOf="@+id/Book_imgCover"
+            app:layout_constraintStart_toEndOf="@+id/Book_lblBy"
+            app:layout_constraintTop_toBottomOf="@+id/Book_lblTitle" />
+
+        <TextView
+            android:id="@+id/Book_lblBy"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_marginStart="8dp"
+            android:layout_marginTop="8dp"
+            android:text="By "
+            android:textColor="@android:color/darker_gray"
+            app:layout_constraintStart_toStartOf="parent"
+            app:layout_constraintTop_toBottomOf="@+id/Book_lblTitle" />
     </android.support.constraint.ConstraintLayout>
 </FrameLayout>
index 978a2f16961327a6894df4c1c18c4e36857952a2..7d3b272b64e722d6447188e9ec17b09a2163e887 100644 (file)
@@ -6,10 +6,9 @@
 
     <!-- TODO: Update blank fragment layout -->
 
-    <LinearLayout
-        android:id="@+id/AndroidReaderGroup_root"
+    <ListView
+        android:id="@+id/Group_root"
         android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:orientation="vertical"></LinearLayout>
+        android:layout_height="match_parent" />
 
 </FrameLayout>
diff --git a/res/mipmap-anydpi-v26/ic_launcher.xml b/res/mipmap-anydpi-v26/ic_launcher.xml
deleted file mode 100644 (file)
index bbd3e02..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
-    <background android:drawable="@drawable/ic_launcher_background"/>
-    <foreground android:drawable="@drawable/ic_launcher_foreground"/>
-</adaptive-icon>
\ No newline at end of file
diff --git a/res/mipmap-anydpi-v26/ic_launcher_round.xml b/res/mipmap-anydpi-v26/ic_launcher_round.xml
deleted file mode 100644 (file)
index bbd3e02..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
-    <background android:drawable="@drawable/ic_launcher_background"/>
-    <foreground android:drawable="@drawable/ic_launcher_foreground"/>
-</adaptive-icon>
\ No newline at end of file
index 931bcb589d59d4d461b7dfa5b1c8cec02650b3a4..7e919baa53f6531f04fc8214512fe33c31ce61ea 100644 (file)
@@ -19,6 +19,5 @@
                 <category android:name="android.intent.category.LAUNCHER" />
             </intent-filter>
         </activity>
-        <activity android:name="be.nikiroo.fanfix.reader.android.SayIt" />
     </application>
 </manifest>
\ No newline at end of file
index 4a42218c5f21058bd2fffe5384ea9585df2a2306..e2af0709bb316e06ac78634d6b3aa877082ccc33 100644 (file)
@@ -145,7 +145,7 @@ public class DataLoader {
                                                downloadCache.save(in, originalUrl);
                                                // ..But we want a resetable stream
                                                in.close();
-                                               in = downloadCache.load(originalUrl, false, stable);
+                                               in = downloadCache.load(originalUrl, true, stable);
                                        } else {
                                                InputStream resetIn = IOUtils.forceResetableStream(in);
                                                if (resetIn != in) {
index c265861aefb3f2b8c3e7e324c216ded7cad1682d..ed22f6217b13fd57bb28953f188c59f98f2321a4 100644 (file)
@@ -47,7 +47,7 @@ public class Instance {
                }
 
                // Most of the rest is dependent upon this:
-               createConfigs(configDir, true);
+               createConfigs(configDir, false);
 
                // update tracer:
                boolean debug = Instance.getConfig()
@@ -336,7 +336,7 @@ public class Instance {
         * @param configDir
         *            the directory where to find the configuration files
         * @param refresh
-        *            TRUE to refresh the configuration files from the default
+        *            TRUE to reset the configuration files from the default
         *            included ones
         */
        private static void createConfigs(String configDir, boolean refresh) {
@@ -390,7 +390,7 @@ public class Instance {
                if (remoteLib == null || remoteLib.trim().isEmpty()) {
                        String libDir = System.getProperty("fanfix.libdir");
                        if (libDir == null || libDir.isEmpty()) {
-                               config.getString(Config.LIBRARY_DIR);
+                               libDir = config.getString(Config.LIBRARY_DIR);
                        }
                        try {
                                lib = new LocalLibrary(getFile(libDir));
index 62ee814071b734b1fadff3f90d5b5b746b6dae1e..00450623cb3dea5603c77ae076eac2c9c8b7f0e9 100644 (file)
@@ -8,6 +8,7 @@ import java.net.URL;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
+import java.util.Locale;
 import java.util.Map;
 
 import be.nikiroo.utils.Version;
@@ -19,7 +20,7 @@ import be.nikiroo.utils.Version;
  * @author niki
  */
 public class VersionCheck {
-       private static final String url = "https://github.com/nikiroo/fanfix/raw/master/changelog.md";
+       private static final String base = "https://github.com/nikiroo/fanfix/raw/master/changelog${LANG}.md";
 
        private Version current;
        private List<Version> newer;
@@ -108,7 +109,27 @@ public class VersionCheck {
 
                if (Instance.isVersionCheckNeeded()) {
                        try {
-                               InputStream in = Instance.getCache().openNoCache(new URL(url));
+                               // Prepare the URLs according to the user's language
+                               Locale lang = Instance.getTrans().getLanguage();
+                               String fr = lang.getLanguage();
+                               String BE = lang.getCountry().replace(".UTF8", "");
+                               String urlFrBE = base.replace("${LANG}", "-" + fr + "_" + BE);
+                               String urlFr = base.replace("${LANG}", "-" + fr);
+                               String urlDefault = base.replace("${LANG}", "");
+
+                               InputStream in = null;
+                               for (String url : new String[] { urlFrBE, urlFr, urlDefault }) {
+                                       try {
+                                               in = Instance.getCache().openNoCache(new URL(url));
+                                               break;
+                                       } catch (IOException e) {
+                                       }
+                               }
+
+                               if (in == null) {
+                                       throw new IOException("No changelog found");
+                               }
+
                                BufferedReader reader = new BufferedReader(
                                                new InputStreamReader(in, "UTF-8"));
                                try {
@@ -140,8 +161,10 @@ public class VersionCheck {
                                        reader.close();
                                }
                        } catch (IOException e) {
-                               Instance.getTraceHandler().error(new IOException(
-                                               "Cannot download latest changelist on github.com", e));
+                               Instance.getTraceHandler()
+                                               .error(new IOException(
+                                                               "Cannot download latest changelist on github.com",
+                                                               e));
                        }
                }
 
index e94c05b448eb3ba3231035f9999ec4dbb22d40b7..24a9252d17a3fefafb2f430d69ad0d50e61e412a 100644 (file)
@@ -2,6 +2,7 @@ package be.nikiroo.fanfix.bundles;
 
 import java.io.File;
 import java.io.IOException;
+import java.util.Locale;
 
 import be.nikiroo.utils.resources.TransBundle;
 
@@ -11,6 +12,8 @@ import be.nikiroo.utils.resources.TransBundle;
  * @author niki
  */
 public class StringIdBundle extends TransBundle<StringId> {
+       private String lang;
+
        /**
         * Create a translation service for the given language (will fall back to
         * the default one i not found).
@@ -20,6 +23,19 @@ public class StringIdBundle extends TransBundle<StringId> {
         */
        public StringIdBundle(String lang) {
                super(StringId.class, Target.resources, lang);
+               this.lang = lang;
+       }
+
+       /**
+        * Return the currently used language as a String.
+        * 
+        * @return the language
+        * 
+        * @deprecated use the call from {@link TransBundle} when available
+        */
+       public Locale getLanguage() {
+               return getLocaleFor(lang);
+
        }
 
        /**
@@ -37,4 +53,39 @@ public class StringIdBundle extends TransBundle<StringId> {
                new StringIdBundle(null).updateFile(path);
                System.out.println("Path updated: " + path);
        }
+
+       /**
+        * Return the {@link Locale} representing the given language.
+        * 
+        * @param language
+        *            the language to initialise, in the form "en-GB" or "fr" for
+        *            instance
+        * 
+        * @return the corresponding {@link Locale} or the default {@link Locale} if
+        *         it is not known
+        * 
+        * @deprecated Use the call from {@link TransBundle} when available.
+        */
+       static private Locale getLocaleFor(String language) {
+               Locale locale;
+
+               if (language == null) {
+                       locale = Locale.getDefault();
+               } else {
+                       language = language.replaceAll("_", "-");
+                       String lang = language;
+                       String country = null;
+                       if (language.contains("-")) {
+                               lang = language.split("-")[0];
+                               country = language.split("-")[1];
+                       }
+
+                       if (country != null)
+                               locale = new Locale(lang, country);
+                       else
+                               locale = new Locale(lang);
+               }
+
+               return locale;
+       }
 }
index 26204156b4d587cb7353851de1a8ea8af7e12b84..ee22e3439cc6d38001b6c36885106641fba0112a 100644 (file)
@@ -124,20 +124,13 @@ public class CacheLibrary extends BasicLibrary {
 
        @Override
        protected void invalidateInfo(String luid) {
-               List<MetaData> metas = this.metas;
-
                if (luid == null) {
-                       this.metas = null;
+                       metas = null;
                } else if (metas != null) {
                        MetaData meta = lib.getInfo(luid);
                        for (int i = 0; i < metas.size(); i++) {
                                if (metas.get(i).getLuid().equals(luid)) {
-                                       if (meta != null) {
-                                               metas.set(i, meta);
-                                               meta = null;
-                                       } else {
-                                               metas.remove(i--);
-                                       }
+                                       metas.remove(i--);
                                }
                        }
 
@@ -179,13 +172,9 @@ public class CacheLibrary extends BasicLibrary {
                }
                lib.delete(luid);
 
-               List<MetaData> metas = this.metas;
-               if (metas != null) {
-                       for (int i = 0; i < metas.size(); i++) {
-                               if (metas.get(i).getLuid().equals(luid)) {
-                                       metas.set(i, lib.getInfo(luid));
-                               }
-                       }
+               MetaData meta = getInfo(luid);
+               if (meta != null) {
+                       metas.remove(meta);
                }
        }
 
@@ -263,6 +252,8 @@ public class CacheLibrary extends BasicLibrary {
                Story story = lib.imprt(url, pgImprt);
                cacheLib.save(story, story.getMeta().getLuid(), pgCache);
 
+               invalidateInfo(story.getMeta().getLuid());
+
                pg.done();
                return story;
        }
index b4d33d7bdd079a7d6fae1654f69fb5b124cd252b..290b5baee76f54b2b0a7d42266714199dbca318f 100644 (file)
@@ -1,11 +1,13 @@
 package be.nikiroo.fanfix.reader.android;
 
 import android.app.Activity;
+import android.app.AlertDialog;
 import android.app.FragmentTransaction;
-import android.content.Intent;
-import android.os.AsyncTask;
+import android.content.Context;
+import android.content.DialogInterface;
 import android.os.Bundle;
 import android.os.Environment;
+import android.text.InputType;
 import android.view.View;
 import android.widget.EditText;
 
@@ -25,70 +27,88 @@ public class AndroidReaderActivity extends Activity implements
 
        @Override
        protected void onCreate(Bundle savedInstanceState) {
-               config();
+               reader = config();
                super.onCreate(savedInstanceState);
                setContentView(R.layout.activity_main);
        }
 
-       int i = 1;
+       @Override
+       protected void onStart() {
+               super.onStart();
+               refresh();
+       }
 
-       public void buttonClick(View view) {
-               AndroidReaderGroup group = null;
-               if (group == null) {
-                       group = new AndroidReaderGroup();
-               }
+       private void refresh() {
+               AndroidReaderGroup group = new AndroidReaderGroup();
 
                FragmentTransaction trans = getFragmentManager().beginTransaction();
-               trans.replace(R.id.dropZone, group);
+               trans.replace(R.id.Main_pnlStories, group);
                trans.commit();
                getFragmentManager().executePendingTransactions();
 
-               group.fill(reader, null);
+               group.fill(reader.getLibrary().getList(), reader);
        }
 
-       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();
                                        }
+                               });
 
-                                       return message;
-                               } catch (Exception e) {
-                                       return e.getClass() + ": " + e.getMessage();
-                               }
-                       }
-
-                       @Override
-                       protected void onPostExecute(String message) {
-                               EditText editText = findViewById(R.id.editText);
-                               editText.setText("testy");
-
-                               Intent intent = new Intent(AndroidReaderActivity.this,
-                                               SayIt.class);
-                               intent.putExtra(SayIt.MESSAGE, message);
-                               startActivity(intent);
-                       }
-               }.execute();
+               /*
+                * Intent intent = new Intent(AndroidReaderActivity.this, SayIt.class);
+                * intent.putExtra(SayIt.MESSAGE, message); startActivity(intent);
+                */
        }
 
        @Override
@@ -101,9 +121,9 @@ public class AndroidReaderActivity extends Activity implements
                }
        }
 
-       private void config() {
+       private Reader config() {
                if (reader != null) {
-                       return;
+                       return reader;
                }
 
                String internal = getExternalFilesDir(null).toString();
@@ -130,6 +150,42 @@ public class AndroidReaderActivity extends Activity implements
                Instance.setTraceHandler(new TraceHandler(true, true, 2));
 
                BasicReader.setDefaultReaderType(Reader.ReaderType.ANDROID);
-               reader = BasicReader.getReader();
+               return BasicReader.getReader();
+       }
+
+       public static void ask(Context context, String title, String message,
+                       String okMessage, final AnswerListener listener) {
+               final EditText input = new EditText(context);
+               input.setFocusable(true);
+               input.setInputType(InputType.TYPE_CLASS_TEXT);
+
+               AlertDialog.Builder alert = new AlertDialog.Builder(context);
+               alert.setTitle(title);
+               alert.setMessage(message);
+               alert.setCancelable(true);
+               alert.setView(input);
+
+               if (listener != null) {
+                       alert.setPositiveButton(okMessage,
+                                       new DialogInterface.OnClickListener() {
+                                               @Override
+                                               public void onClick(DialogInterface dialog, int which) {
+                                                       listener.onAnswer(input.getText().toString());
+                                               }
+                                       });
+
+                       alert.setOnCancelListener(new DialogInterface.OnCancelListener() {
+                               @Override
+                               public void onCancel(DialogInterface dialog) {
+                                       listener.onAnswer(null);
+                               }
+                       });
+               }
+
+               alert.show();
+       }
+
+       private interface AnswerListener {
+               public void onAnswer(String answer);
        }
 }
\ No newline at end of file
index 5d3f65daf1a1859530466bad54bc04a56f06e6a8..700a566938627d06ce8d66e723a6c97c1b56d036 100644 (file)
@@ -14,16 +14,13 @@ import android.widget.TextView;
 
 import java.io.IOException;
 
-import be.nikiroo.fanfix.Instance;
 import be.nikiroo.fanfix.data.MetaData;
 import be.nikiroo.fanfix.reader.Reader;
 import be.nikiroo.utils.Image;
 import be.nikiroo.utils.android.ImageUtilsAndroid;
 
 public class AndroidReaderBook extends Fragment {
-       private Reader reader;
        private OnFragmentInteractionListener listener;
-       private MetaData meta;
 
        /**
         * This interface must be implemented by activities that contain this
@@ -63,56 +60,63 @@ public class AndroidReaderBook extends Fragment {
                listener = null;
        }
 
-       public void fill(final Reader reader, final String luid) {
-               View view = getView();
-               if (view == null) {
-                       return;
-               }
-
-               final ImageView cover = view.findViewById(R.id.cover);
-               final TextView title = view.findViewById(R.id.title);
-               final FrameLayout frame = view.findViewById(R.id.coverWidget);
+       public void fill(final MetaData meta, final Reader reader) {
+               ViewHolder viewHolder = new ViewHolder(getView());
 
-               new AsyncTask<Void, Void, MetaData>() {
+               viewHolder.title.setText(meta.getTitle());
+               viewHolder.author.setText(meta.getAuthor());
+               viewHolder.frame.setClickable(true);
+               viewHolder.frame.setFocusable(true);
+               viewHolder.frame.setOnClickListener(new View.OnClickListener() {
                        @Override
-                       protected MetaData doInBackground(Void[] objects) {
-                               return Instance.getLibrary().getInfo(luid);
+                       public void onClick(View v) {
+                               OnFragmentInteractionListener llistener = listener;
+                               if (llistener != null) {
+                                       llistener.onFragmentInteraction(meta);
+                               }
                        }
+               });
 
+               new AsyncTask<MetaData, Void, Image>() {
                        @Override
-                       protected void onPostExecute(MetaData meta) {
-                               AndroidReaderBook.this.meta = meta;
-
-                               if (meta != null) {
-                                       title.setText(meta.getTitle());
-                                       try {
-                                               Image coverImage = reader.getLibrary().getCover(
-                                                               meta.getLuid());
-                                               if (coverImage != null) {
-                                                       Bitmap coverBitmap = ImageUtilsAndroid
-                                                                       .fromImage(coverImage);
-                                                       coverBitmap = Bitmap.createScaledBitmap(
-                                                                       coverBitmap, 128, 128, true);
-                                                       cover.setImageBitmap(coverBitmap);
-                                               }
-                                       } catch (IOException e) {
-                                               e.printStackTrace();
-                                       }
+                       protected Image doInBackground(MetaData[] metas) {
+                               if (metas[0].getCover() != null) {
+                                       return metas[0].getCover();
                                }
 
-                               frame.setClickable(true);
-                               frame.setFocusable(true);
-                               frame.setOnClickListener(new View.OnClickListener() {
-                                       @Override
-                                       public void onClick(View v) {
-                                               OnFragmentInteractionListener llistener = listener;
-                                               if (llistener != null) {
-                                                       llistener
-                                                                       .onFragmentInteraction(AndroidReaderBook.this.meta);
-                                               }
+                               return reader.getLibrary().getCover(metas[0].getLuid());
+                       }
+
+                       @Override
+                       protected void onPostExecute(Image coverImage) {
+                               ViewHolder viewHolder = new ViewHolder(getView());
+
+                               try {
+                                       if (coverImage != null) {
+                                               Bitmap coverBitmap = ImageUtilsAndroid
+                                                               .fromImage(coverImage);
+                                               coverBitmap = Bitmap.createScaledBitmap(coverBitmap,
+                                                               128, 128, true);
+                                               viewHolder.cover.setImageBitmap(coverBitmap);
                                        }
-                               });
+                               } catch (IOException e) {
+                                       e.printStackTrace();
+                               }
                        }
-               }.execute();
+               }.execute(meta);
+       }
+
+       private class ViewHolder {
+               public FrameLayout frame;
+               public TextView title;
+               public TextView author;
+               public ImageView cover;
+
+               public ViewHolder(View book) {
+                       frame = book.findViewById(R.id.Book);
+                       title = book.findViewById(R.id.Book_lblTitle);
+                       author = book.findViewById(R.id.Book_lblAuthor);
+                       cover = book.findViewById(R.id.Book_imgCover);
+               }
        }
 }
index d998a8cf9c40b947226f0995d489052a957fc137..2d4819942a7d7b83c67fe645bb149b1015049004 100644 (file)
@@ -3,13 +3,17 @@ package be.nikiroo.fanfix.reader.android;
 import android.app.Fragment;
 import android.app.FragmentTransaction;
 import android.content.Context;
-import android.os.AsyncTask;
 import android.os.Bundle;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
+import android.widget.BaseAdapter;
+import android.widget.ListView;
 
+import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 import be.nikiroo.fanfix.data.MetaData;
 import be.nikiroo.fanfix.reader.Reader;
@@ -21,6 +25,7 @@ import be.nikiroo.fanfix.reader.Reader;
  */
 public class AndroidReaderGroup extends Fragment {
        private OnFragmentInteractionListener listener;
+       private Map<View, AndroidReaderBook> books = new HashMap<View, AndroidReaderBook>();
 
        public interface OnFragmentInteractionListener {
                void onFragmentInteraction(MetaData meta);
@@ -33,7 +38,6 @@ public class AndroidReaderGroup extends Fragment {
        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                        Bundle savedInstanceState) {
-               // Inflate the layout for this fragment
                return inflater.inflate(R.layout.fragment_android_reader_group,
                                container, false);
        }
@@ -52,31 +56,46 @@ public class AndroidReaderGroup extends Fragment {
                listener = null;
        }
 
-       public void fill(final Reader reader, final String source) {
-               new AsyncTask<Void, Void, List<MetaData>>() {
+       public void fill(final List<MetaData> metas, final Reader reader) {
+               final List<MetaData> datas = new ArrayList<MetaData>(metas);
+
+               ListView list = getView().findViewById(R.id.Group_root);
+               list.setAdapter(new BaseAdapter() {
+                       @Override
+                       public int getCount() {
+                               return datas.size();
+                       }
+
                        @Override
-                       protected List<MetaData> doInBackground(Void... voids) {
-                               return reader.getLibrary().getListBySource(source);
+                       public long getItemId(int position) {
+                               return -1; // TODO: what is a "row id" in this context?
                        }
 
                        @Override
-                       protected void onPostExecute(List<MetaData> metas) {
-                               for (MetaData meta : metas) {
-                                       String tag = "Book_" + meta.getLuid();
-                                       tag = null; // TODO: how does it work?
-                                       AndroidReaderBook book = null;// (AndroidReaderBook)
-                                                                                                       // getFragmentManager().findFragmentByTag(tag);
-                                       if (book == null) {
-                                               book = new AndroidReaderBook();
-                                               FragmentTransaction trans = getFragmentManager()
-                                                               .beginTransaction();
-                                               trans.add(R.id.AndroidReaderGroup_root, book, tag);
-                                               trans.commit();
-                                               getFragmentManager().executePendingTransactions();
-                                       }
-                                       book.fill(reader, meta.getLuid());
+                       public Object getItem(int position) {
+                               return datas.get(position);
+                       }
+
+                       @Override
+                       public View getView(int position, View convertView, ViewGroup parent) {
+                               AndroidReaderBook book = books.get(convertView);
+                               if (book == null) {
+                                       book = new AndroidReaderBook();
+
+                                       FragmentTransaction trans = getFragmentManager()
+                                                       .beginTransaction();
+                                       trans.add(book, null);
+                                       trans.commit();
+                                       getFragmentManager().executePendingTransactions();
+
+                                       books.put(book.getView(), book);
                                }
+
+                               MetaData meta = (MetaData) getItem(position);
+                               book.fill(meta, reader);
+
+                               return book.getView();
                        }
-               }.execute();
+               });
        }
 }
diff --git a/src/be/nikiroo/fanfix/reader/android/SayIt.java b/src/be/nikiroo/fanfix/reader/android/SayIt.java
deleted file mode 100644 (file)
index 1346506..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-package be.nikiroo.fanfix.reader.android;
-
-import android.app.Activity;
-import android.content.Intent;
-import android.os.Bundle;
-import android.widget.TextView;
-
-
-public class SayIt extends Activity {
-    public static final String MESSAGE = "be.nikiroo.testy.message";
-
-    @Override
-    protected void onCreate(Bundle savedInstanceState) {
-        super.onCreate(savedInstanceState);
-        setContentView(R.layout.activity_say_it);
-
-        // Get the Intent that started this activity and extract the string
-        Intent intent = getIntent();
-        String message = intent.getStringExtra(SayIt.MESSAGE);
-
-        // Capture the layout's TextView and set the string as its text
-        TextView textView = findViewById(R.id.textView);
-        textView.setText(message);
-    }
-}
index f16cdc7b6453ac00753bb479850ab7eb2edcafc5..0c127aa21a17d59631f6d3200e31ea08a582f077 100644 (file)
@@ -466,7 +466,7 @@ public abstract class BasicSupport {
                                        if (chap.getValue() != null) {
                                                setCurrentReferer(chap.getValue());
                                                chapIn = Instance.getCache().open(chap.getValue(),
-                                                               this, true);
+                                                               this, false);
                                        }
                                        pgChaps.setProgress(i * 100);
                                        try {