[Android] Chapter : Fix name issues and add time

Alexandre Perraud git at videolan.org
Wed Sep 9 16:42:31 CEST 2015


vlc-ports/android | branch: master | Alexandre Perraud <4leyx4ndre at gmail.com> | Wed Sep  9 16:41:35 2015 +0200| [d6231a8710175c5359d523a2865978640e243926] | committer: Alexandre Perraud

Chapter : Fix name issues and add time

> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=d6231a8710175c5359d523a2865978640e243926
---

 .../res/layout/dialog_select_chapter_item.xml      |   33 ++++++++++++++----
 .../videolan/vlc/gui/dialogs/AdvOptionsDialog.java |    6 +++-
 .../vlc/gui/dialogs/SelectChapterDialog.java       |   35 ++++++++++++++------
 3 files changed, 56 insertions(+), 18 deletions(-)

diff --git a/vlc-android/res/layout/dialog_select_chapter_item.xml b/vlc-android/res/layout/dialog_select_chapter_item.xml
index 7e91192..d831b92 100644
--- a/vlc-android/res/layout/dialog_select_chapter_item.xml
+++ b/vlc-android/res/layout/dialog_select_chapter_item.xml
@@ -1,8 +1,27 @@
 <?xml version="1.0" encoding="utf-8"?>
-<TextView xmlns:android="http://schemas.android.com/apk/res/android"
-    android:layout_width="match_parent"
-    android:layout_height="wrap_content"
-    android:ellipsize="marquee"
-    android:padding="@dimen/half_default_margin"
-    android:background="@drawable/background_chapter_item"
-    android:singleLine="true" />
\ No newline at end of file
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="wrap_content"
+    android:layout_height="wrap_content">
+
+    <TextView
+        android:id="@+id/chapter_name"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_alignParentLeft="true"
+        android:layout_toLeftOf="@+id/chapter_time"
+        android:background="@drawable/background_chapter_item"
+        android:ellipsize="marquee"
+        android:padding="@dimen/half_default_margin"
+        android:singleLine="true"
+        android:text="Chapter_name" />
+
+    <TextView
+        android:id="@+id/chapter_time"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_alignParentRight="true"
+        android:background="@drawable/background_chapter_item"
+        android:padding="@dimen/half_default_margin"
+        android:text="00:00" />
+
+</RelativeLayout>
\ No newline at end of file
diff --git a/vlc-android/src/org/videolan/vlc/gui/dialogs/AdvOptionsDialog.java b/vlc-android/src/org/videolan/vlc/gui/dialogs/AdvOptionsDialog.java
index b485705..3d3bbe5 100644
--- a/vlc-android/src/org/videolan/vlc/gui/dialogs/AdvOptionsDialog.java
+++ b/vlc-android/src/org/videolan/vlc/gui/dialogs/AdvOptionsDialog.java
@@ -364,7 +364,11 @@ public class AdvOptionsDialog extends DialogFragment implements View.OnClickList
             final int chaptersCount = chapters != null ? chapters.length : 0;
 
             if (chaptersCount > 1) {
-                mChaptersTitle.setText(chapters[mService.getChapterIdx()].name);
+                int index = mService.getChapterIdx();
+                if (chapters[index].name == null || chapters[index].name.equals(""))
+                    mChaptersTitle.setText(getResources().getString(R.string.chapter) + " " + index);
+                else
+                    mChaptersTitle.setText(chapters[index].name);
             } else
                 mChaptersTitle.setVisibility(View.GONE);
 
diff --git a/vlc-android/src/org/videolan/vlc/gui/dialogs/SelectChapterDialog.java b/vlc-android/src/org/videolan/vlc/gui/dialogs/SelectChapterDialog.java
index 04390e8..a4c18aa 100644
--- a/vlc-android/src/org/videolan/vlc/gui/dialogs/SelectChapterDialog.java
+++ b/vlc-android/src/org/videolan/vlc/gui/dialogs/SelectChapterDialog.java
@@ -29,8 +29,8 @@ import android.view.ViewGroup;
 import android.view.Window;
 import android.view.WindowManager;
 import android.widget.AdapterView;
-import android.widget.ArrayAdapter;
 import android.widget.ListView;
+import android.widget.SimpleAdapter;
 
 import org.videolan.libvlc.MediaPlayer;
 import org.videolan.vlc.PlaybackService;
@@ -39,6 +39,10 @@ import org.videolan.vlc.gui.PlaybackServiceFragment;
 import org.videolan.vlc.util.Strings;
 import org.videolan.vlc.util.Util;
 
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
+
 public class SelectChapterDialog extends DialogFragment implements PlaybackService.Client.Callback {
 
     public final static String TAG = "VLC/SelectChapterDialog";
@@ -86,18 +90,23 @@ public class SelectChapterDialog extends DialogFragment implements PlaybackServi
         if (chaptersCount <= 1) {
             return;
         }
-        ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), R.layout.dialog_select_chapter_item);
-        for (int i = 0; i < chaptersCount; ++i) {
+
+        ArrayList<Map<String, String>> chapterList = new ArrayList<Map<String, String>>();
+
+        for (int i = 0; i < chaptersCount; i++) {
             String name;
-            if (chapters[i].name == null || chapters[i].name.equals("")) {
-                StringBuilder sb = new StringBuilder(getResources().getString(R.string.chapter) + " ").append(i);
-                if (chapters[i].timeOffset >= 0)
-                    sb.append(" - ").append(Strings.millisToString(chapters[i].timeOffset));
-                name = sb.toString();
-            } else
+            if (chapters[i].name == null || chapters[i].name.equals(""))
+                name = getResources().getString(R.string.chapter) + " " + i;
+            else
                 name = chapters[i].name;
-            adapter.insert(name, i);
+            chapterList.add(putData(name, Strings.millisToString(chapters[i].timeOffset)));
         }
+
+        String[] from = { "name", "time" };
+        int[] to = { R.id.chapter_name, R.id.chapter_time };
+        SimpleAdapter adapter = new SimpleAdapter(getActivity(), chapterList,
+                R.layout.dialog_select_chapter_item, from, to);
+
         mChapterList.setAdapter(adapter);
         mChapterList.setSelection(mService.getChapterIdx());
         mChapterList.setItemChecked(mService.getChapterIdx(), true);
@@ -133,4 +142,10 @@ public class SelectChapterDialog extends DialogFragment implements PlaybackServi
         mService = null;
     }
 
+    private HashMap<String, String> putData(String name, String time) {
+        HashMap<String, String> item = new HashMap<String, String>();
+        item.put("name", name);
+        item.put("time", time);
+        return item;
+    }
 }



More information about the Android mailing list