[Android] Save name in network favorites

Geoffrey Métais git at videolan.org
Thu Mar 12 16:13:06 CET 2015


vlc-ports/android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Mar 12 16:12:42 2015 +0100| [7f26c696235f00795633c423a57081a066888659] | committer: Geoffrey Métais

Save name in network favorites

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

 .../src/org/videolan/vlc/MediaDatabase.java        |   32 ++++++++++++++------
 .../videolan/vlc/gui/network/NetworkFragment.java  |   14 ++++-----
 .../org/videolan/vlc/gui/tv/MainTvActivity.java    |    6 ++--
 .../vlc/gui/tv/MediaItemDetailsFragment.java       |    3 +-
 4 files changed, 34 insertions(+), 21 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/MediaDatabase.java b/vlc-android/src/org/videolan/vlc/MediaDatabase.java
index 5cfa8f4..62a774e 100644
--- a/vlc-android/src/org/videolan/vlc/MediaDatabase.java
+++ b/vlc-android/src/org/videolan/vlc/MediaDatabase.java
@@ -50,7 +50,7 @@ public class MediaDatabase {
 
     private SQLiteDatabase mDb;
     private static final String DB_NAME = "vlc_database";
-    private static final int DB_VERSION = 17;
+    private static final int DB_VERSION = 18;
     private static final int CHUNK_SIZE = 50;
 
     private static final String DIR_TABLE_NAME = "directories_table";
@@ -96,6 +96,7 @@ public class MediaDatabase {
 
     private static final String NETWORK_FAV_TABLE_NAME = "fav_table";
     private static final String NETWORK_FAV_URI = "uri";
+    private static final String NETWORK_FAV_TITLE = "title";
 
     public enum mediaColumn {
         MEDIA_TABLE_NAME, MEDIA_PATH, MEDIA_TIME, MEDIA_LENGTH,
@@ -253,7 +254,9 @@ public class MediaDatabase {
         private void createNetworkFavTableQuery(SQLiteDatabase db) {
             String createMrlTableQuery = "CREATE TABLE IF NOT EXISTS " +
                     NETWORK_FAV_TABLE_NAME + " (" +
-                    MRL_URI + " TEXT PRIMARY KEY NOT NULL);";
+                    NETWORK_FAV_URI + " TEXT PRIMARY KEY NOT NULL, " +
+                    NETWORK_FAV_TITLE + " TEXT NOT NULL" +
+                    ");";
             db.execSQL(createMrlTableQuery);
         }
 
@@ -313,9 +316,14 @@ public class MediaDatabase {
                 case 13:
                     createNetworkFavTableQuery(db);
                     break;
-                    case 17:
-                        dropMRLTableQuery(db);
-                        createMRLTableQuery(db);
+                case 17:
+                    dropMRLTableQuery(db);
+                    createMRLTableQuery(db);
+                    break;
+                case 18:
+                    dropNetworkFavTableQuery(db);
+                    createNetworkFavTableQuery(db);
+                    break;
                 default:
                     break;
                 }
@@ -1003,9 +1011,10 @@ public class MediaDatabase {
     }
 
 
-    public synchronized void addNetworkFavItem(String mrl) {
+    public synchronized void addNetworkFavItem(String mrl, String title) {
         ContentValues values = new ContentValues();
         values.put(NETWORK_FAV_URI, Uri.encode(mrl));
+        values.put(NETWORK_FAV_TITLE, Uri.encode(title));
         mDb.replace(NETWORK_FAV_TABLE_NAME, null, values);
     }
 
@@ -1020,15 +1029,18 @@ public class MediaDatabase {
         return exists;
     }
 
-    public synchronized ArrayList<String> getAllNetworkFav() {
-        ArrayList<String> favs = new ArrayList<String>();
+    public synchronized ArrayList<MediaWrapper> getAllNetworkFav() {
+        ArrayList<MediaWrapper> favs = new ArrayList<MediaWrapper>();
 
+        MediaWrapper mw;
         Cursor cursor = mDb.query(NETWORK_FAV_TABLE_NAME,
-                new String[] { NETWORK_FAV_URI },
+                new String[] { NETWORK_FAV_URI , NETWORK_FAV_TITLE},
                 null, null, null, null, null);
 
         while (cursor.moveToNext()) {
-            favs.add(Uri.decode(cursor.getString(0)));
+            mw = new MediaWrapper(Uri.decode(cursor.getString(0)));
+            mw.setTitle(Uri.decode(cursor.getString(1)));
+            favs.add(mw);
         }
         cursor.close();
 
diff --git a/vlc-android/src/org/videolan/vlc/gui/network/NetworkFragment.java b/vlc-android/src/org/videolan/vlc/gui/network/NetworkFragment.java
index 23892f3..3f9cd16 100644
--- a/vlc-android/src/org/videolan/vlc/gui/network/NetworkFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/network/NetworkFragment.java
@@ -247,11 +247,11 @@ public class NetworkFragment extends BrowserFragment implements IRefreshable, Me
     public void refresh() {
         mAdapter.clear();
         if (mRoot){
-            ArrayList<String> favs = MediaDatabase.getInstance().getAllNetworkFav();
+            ArrayList<MediaWrapper> favs = MediaDatabase.getInstance().getAllNetworkFav();
             if (!favs.isEmpty()) {
                 mFavorites = favs.size();
-                for (String fav : favs) {
-                    mAdapter.addItem(new MediaWrapper(fav), false, true);
+                for (MediaWrapper fav : favs) {
+                    mAdapter.addItem(fav, false, true);
                     mAdapter.notifyDataSetChanged();
                 }
                 mAdapter.addItem("Network favorites", false, true);
@@ -265,7 +265,7 @@ public class NetworkFragment extends BrowserFragment implements IRefreshable, Me
     }
 
     private void updateFavorites(){
-        ArrayList<String> favs = MediaDatabase.getInstance().getAllNetworkFav();
+        ArrayList<MediaWrapper> favs = MediaDatabase.getInstance().getAllNetworkFav();
         int newSize = favs.size(), totalSize = mAdapter.getItemCount();
 
         if (newSize == 0 && mFavorites == 0)
@@ -278,8 +278,8 @@ public class NetworkFragment extends BrowserFragment implements IRefreshable, Me
         else {
             if (mFavorites == 0)
                 mAdapter.addItem("Network favorites", false, false); //add header if needed
-            for (String fav : favs)
-                mAdapter.addItem(new MediaWrapper(fav), false, false); //add new favorites
+            for (MediaWrapper fav : favs)
+                mAdapter.addItem(fav, false, false); //add new favorites
         }
         mFavorites = newSize; //update count
     }
@@ -289,7 +289,7 @@ public class NetworkFragment extends BrowserFragment implements IRefreshable, Me
         if (db.networkFavExists(mMrl))
             db.deleteNetworkFav(mMrl);
         else
-            db.addNetworkFavItem(mMrl);
+            db.addNetworkFavItem(mMrl, mCurrentMedia.getTitle());
         getActivity().supportInvalidateOptionsMenu();
     }
 
diff --git a/vlc-android/tv/src/org/videolan/vlc/gui/tv/MainTvActivity.java b/vlc-android/tv/src/org/videolan/vlc/gui/tv/MainTvActivity.java
index a4a6393..2bff457 100644
--- a/vlc-android/tv/src/org/videolan/vlc/gui/tv/MainTvActivity.java
+++ b/vlc-android/tv/src/org/videolan/vlc/gui/tv/MainTvActivity.java
@@ -320,10 +320,10 @@ public class MainTvActivity extends Activity implements IVideoBrowser, OnItemVie
 
             mNetworkAdapter = new ArrayObjectAdapter(new CardPresenter(mContext));
             mNetworkAdapter.add(new CardPresenter.SimpleCard(0, getString(R.string.network_browsing), R.drawable.ic_menu_network_big));
-            ArrayList<String> favs = MediaDatabase.getInstance().getAllNetworkFav();
+            ArrayList<MediaWrapper> favs = MediaDatabase.getInstance().getAllNetworkFav();
             if (!favs.isEmpty()) {
-                for (String fav : favs) {
-                    mNetworkAdapter.add(new MediaWrapper(fav));
+                for (MediaWrapper fav : favs) {
+                    mNetworkAdapter.add(fav);
                 }
             }
             header = new HeaderItem(HEADER_NETWORK, getString(R.string.network_browsing), null);
diff --git a/vlc-android/tv/src/org/videolan/vlc/gui/tv/MediaItemDetailsFragment.java b/vlc-android/tv/src/org/videolan/vlc/gui/tv/MediaItemDetailsFragment.java
index e49e5c1..c8cf459 100644
--- a/vlc-android/tv/src/org/videolan/vlc/gui/tv/MediaItemDetailsFragment.java
+++ b/vlc-android/tv/src/org/videolan/vlc/gui/tv/MediaItemDetailsFragment.java
@@ -81,6 +81,7 @@ public class MediaItemDetailsFragment extends DetailsFragment implements AudioSe
         mMedia = extras.getParcelable("item");
         ClassPresenterSelector selector = new ClassPresenterSelector();
         final MediaWrapper media = new MediaWrapper(mMedia.getLocation());
+        media.setTitle(mMedia.getTitle());
         // Attach your media item details presenter to the row presenter:
         DetailsOverviewRowPresenter rowPresenter =
                 new DetailsOverviewRowPresenter(new DetailsDescriptionPresenter());
@@ -102,7 +103,7 @@ public class MediaItemDetailsFragment extends DetailsFragment implements AudioSe
                         startActivity(intent);
                         break;
                     case ID_FAVORITE_ADD:
-                        mDb.addNetworkFavItem(mMedia.getLocation());
+                        mDb.addNetworkFavItem(mMedia.getLocation(), mMedia.getTitle());
                         Toast.makeText(getActivity(), "Saved to favorites", Toast.LENGTH_SHORT).show();
                         break;
                     case ID_FAVORITE_DELETE:



More information about the Android mailing list