From be917d6b2466550afe3ecf757d43aaadbdbcf2ca Mon Sep 17 00:00:00 2001 From: stom79 Date: Sun, 21 Oct 2018 18:43:57 +0200 Subject: [PATCH] Favorites for peertube --- .../mastodon/activities/BaseMainActivity.java | 9 +- .../mastodon/activities/PeertubeActivity.java | 35 ++++- .../asynctasks/RetrieveFeedsAsyncTask.java | 8 + .../fr/gouv/etalab/mastodon/client/API.java | 5 +- .../mastodon/client/Entities/Peertube.java | 12 +- .../DisplayFavoritesPeertubeFragment.java | 148 ++++++++++++++++++ .../mastodon/sqlite/PeertubeFavoritesDAO.java | 146 +++++++++++++++++ .../gouv/etalab/mastodon/sqlite/Sqlite.java | 20 ++- .../drawable-anydpi/ic_bookmark_peertube.xml | 9 ++ .../ic_bookmark_peertube_border.xml | 9 ++ .../ic_favorite_peertube_full.png | Bin 0 -> 292 bytes .../ic_favorite_peertube_full.png | Bin 0 -> 246 bytes .../ic_favorite_peertube_full.png | Bin 0 -> 218 bytes .../ic_favorite_peertube_full.png | Bin 0 -> 398 bytes .../ic_favorite_peertube_full.png | Bin 0 -> 549 bytes .../ic_favorite_peertube_full.png | Bin 0 -> 717 bytes app/src/main/res/layout/activity_peertube.xml | 14 ++ .../layout/fragment_peertube_favourites.xml | 61 ++++++++ .../main/res/menu/activity_main_drawer.xml | 4 + app/src/main/res/values/strings.xml | 4 + 20 files changed, 478 insertions(+), 6 deletions(-) create mode 100644 app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayFavoritesPeertubeFragment.java create mode 100644 app/src/main/java/fr/gouv/etalab/mastodon/sqlite/PeertubeFavoritesDAO.java create mode 100644 app/src/main/res/drawable-anydpi/ic_bookmark_peertube.xml create mode 100644 app/src/main/res/drawable-anydpi/ic_bookmark_peertube_border.xml create mode 100644 app/src/main/res/drawable-hdpi/ic_favorite_peertube_full.png create mode 100644 app/src/main/res/drawable-ldpi/ic_favorite_peertube_full.png create mode 100644 app/src/main/res/drawable-mdpi/ic_favorite_peertube_full.png create mode 100644 app/src/main/res/drawable-xhdpi/ic_favorite_peertube_full.png create mode 100644 app/src/main/res/drawable-xxhdpi/ic_favorite_peertube_full.png create mode 100644 app/src/main/res/drawable-xxxhdpi/ic_favorite_peertube_full.png create mode 100644 app/src/main/res/layout/fragment_peertube_favourites.xml diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseMainActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseMainActivity.java index 41e1ba6d7..10dd2b17d 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseMainActivity.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseMainActivity.java @@ -106,6 +106,7 @@ import fr.gouv.etalab.mastodon.client.HttpsConnection; import fr.gouv.etalab.mastodon.fragments.DisplayAccountsFragment; import fr.gouv.etalab.mastodon.fragments.DisplayBookmarksFragment; import fr.gouv.etalab.mastodon.fragments.DisplayDraftsFragment; +import fr.gouv.etalab.mastodon.fragments.DisplayFavoritesPeertubeFragment; import fr.gouv.etalab.mastodon.fragments.DisplayFiltersFragment; import fr.gouv.etalab.mastodon.fragments.DisplayFollowRequestSentFragment; import fr.gouv.etalab.mastodon.fragments.DisplayHowToFragment; @@ -1830,7 +1831,7 @@ public abstract class BaseMainActivity extends BaseActivity toolbarTitle.setVisibility(View.VISIBLE); delete_instance.setVisibility(View.GONE); appBar.setExpanded(true); - if (id != R.id.nav_drafts && id != R.id.nav_bookmarks ) { + if (id != R.id.nav_drafts && id != R.id.nav_bookmarks && id != R.id.nav_peertube ) { delete_all.hide(); }else{ delete_all.show(); @@ -1901,6 +1902,12 @@ public abstract class BaseMainActivity extends BaseActivity fragmentManager.beginTransaction() .replace(R.id.main_app_container, displayBookmarksFragment, fragmentTag).commit(); toot.hide(); + }else if (id == R.id.nav_peertube) { + DisplayFavoritesPeertubeFragment displayFavoritesPeertubeFragment = new DisplayFavoritesPeertubeFragment(); + fragmentTag = "BOOKMARKS_PEERTUBE"; + fragmentManager.beginTransaction() + .replace(R.id.main_app_container, displayFavoritesPeertubeFragment, fragmentTag).commit(); + toot.hide(); }else if( id == R.id.nav_follow_request){ toot.hide(); DisplayFollowRequestSentFragment followRequestSentFragment = new DisplayFollowRequestSentFragment(); diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/PeertubeActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/PeertubeActivity.java index 5f3f01cbe..8c6da2d7c 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/PeertubeActivity.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/PeertubeActivity.java @@ -21,6 +21,8 @@ import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; import android.content.pm.PackageManager; +import android.database.sqlite.SQLiteDatabase; +import android.graphics.drawable.Drawable; import android.media.MediaPlayer; import android.net.Uri; import android.os.AsyncTask; @@ -66,6 +68,8 @@ import fr.gouv.etalab.mastodon.drawers.StatusListAdapter; import fr.gouv.etalab.mastodon.helper.FullScreenMediaController; import fr.gouv.etalab.mastodon.helper.Helper; import fr.gouv.etalab.mastodon.interfaces.OnRetrievePeertubeInterface; +import fr.gouv.etalab.mastodon.sqlite.PeertubeFavoritesDAO; +import fr.gouv.etalab.mastodon.sqlite.Sqlite; import static fr.gouv.etalab.mastodon.helper.Helper.EXTERNAL_STORAGE_REQUEST_CODE; import static fr.gouv.etalab.mastodon.helper.Helper.manageDownloads; @@ -82,7 +86,7 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube private FullScreenMediaController.fullscreen fullscreen; private VideoView videoView; private RelativeLayout loader; - private TextView peertube_view_count, peertube_like_count, peertube_dislike_count, peertube_share, peertube_download, peertube_description, peertube_title; + private TextView peertube_view_count, peertube_bookmark, peertube_like_count, peertube_dislike_count, peertube_share, peertube_download, peertube_description, peertube_title; private ScrollView peertube_information_container; private MediaPlayer mediaPlayer; private FullScreenMediaController fullScreenMediaController; @@ -112,6 +116,7 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube setContentView(R.layout.activity_peertube); loader = findViewById(R.id.loader); peertube_view_count = findViewById(R.id.peertube_view_count); + peertube_bookmark = findViewById(R.id.peertube_bookmark); peertube_like_count = findViewById(R.id.peertube_like_count); peertube_dislike_count = findViewById(R.id.peertube_dislike_count); peertube_share = findViewById(R.id.peertube_share); @@ -283,6 +288,34 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube } } }); + SQLiteDatabase db = Sqlite.getInstance(PeertubeActivity.this, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); + List peertubes = new PeertubeFavoritesDAO(PeertubeActivity.this, db).getSinglePeertube(peertube); + + Drawable img; + + if( peertubes == null || peertubes.size() == 0) + img = ContextCompat.getDrawable(PeertubeActivity.this, R.drawable.ic_bookmark_peertube_border); + else + img = ContextCompat.getDrawable(PeertubeActivity.this, R.drawable.ic_bookmark_peertube); + peertube_bookmark.setCompoundDrawablesWithIntrinsicBounds(null, img, null, null); + + peertube_bookmark.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + List peertubes = new PeertubeFavoritesDAO(PeertubeActivity.this, db).getSinglePeertube(peertube); + if( peertubes == null || peertubes.size() == 0){ + new PeertubeFavoritesDAO(PeertubeActivity.this, db).insert(peertube); + Toast.makeText(PeertubeActivity.this,R.string.bookmark_add_peertube, Toast.LENGTH_SHORT).show(); + }else{ + new PeertubeFavoritesDAO(PeertubeActivity.this, db).remove(peertube); + Toast.makeText(PeertubeActivity.this,R.string.bookmark_remove_peertube, Toast.LENGTH_SHORT).show(); + } + if( peertubes != null && peertubes.size() > 0) //Was initially in cache + peertube_bookmark.setCompoundDrawablesWithIntrinsicBounds( null, ContextCompat.getDrawable(PeertubeActivity.this, R.drawable.ic_bookmark_peertube_border), null ,null); + else + peertube_bookmark.setCompoundDrawablesWithIntrinsicBounds( null, ContextCompat.getDrawable(PeertubeActivity.this, R.drawable.ic_bookmark_peertube), null ,null); + } + }); peertube_share.setOnClickListener(new View.OnClickListener() { @Override diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveFeedsAsyncTask.java b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveFeedsAsyncTask.java index 4c8ff65e0..71bb8a75c 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveFeedsAsyncTask.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveFeedsAsyncTask.java @@ -30,6 +30,7 @@ import fr.gouv.etalab.mastodon.helper.FilterToots; import fr.gouv.etalab.mastodon.helper.Helper; import fr.gouv.etalab.mastodon.interfaces.OnRetrieveFeedsInterface; import fr.gouv.etalab.mastodon.sqlite.InstancesDAO; +import fr.gouv.etalab.mastodon.sqlite.PeertubeFavoritesDAO; import fr.gouv.etalab.mastodon.sqlite.Sqlite; import fr.gouv.etalab.mastodon.sqlite.StatusCacheDAO; @@ -68,6 +69,7 @@ public class RetrieveFeedsAsyncTask extends AsyncTask { CONTEXT, TAG, CACHE_BOOKMARKS, + CACHE_BOOKMARKS_PEERTUBE, CACHE_STATUS, REMOTE_INSTANCE } @@ -179,6 +181,12 @@ public class RetrieveFeedsAsyncTask extends AsyncTask { List statuses = new StatusCacheDAO(contextReference.get(), db).getAllStatus(StatusCacheDAO.BOOKMARK_CACHE); apiResponse.setStatuses(statuses); break; + case CACHE_BOOKMARKS_PEERTUBE: + apiResponse = new APIResponse(); + db = Sqlite.getInstance(contextReference.get(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); + List peertubes = new PeertubeFavoritesDAO(contextReference.get(), db).getAllPeertube(); + apiResponse.setPeertubes(peertubes); + break; case CACHE_STATUS: apiResponse = new APIResponse(); db = Sqlite.getInstance(contextReference.get(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/client/API.java b/app/src/main/java/fr/gouv/etalab/mastodon/client/API.java index 45fcff057..cea593711 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/client/API.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/client/API.java @@ -616,7 +616,6 @@ public class API { try { HttpsConnection httpsConnection = new HttpsConnection(context); String response = httpsConnection.get("https://"+instance+"/api/v1/videos", 60, params, null); - Helper.largeLog(response); JSONArray jsonArray = new JSONObject(response).getJSONArray("data"); peertubes = parsePeertube(instance, jsonArray); } catch (HttpsConnection.HttpsConnectionException e) { @@ -2386,10 +2385,11 @@ public class API { * @param resobj JSONObject * @return Peertube */ - private static Peertube parsePeertube(Context context, String instance, JSONObject resobj){ + public static Peertube parsePeertube(Context context, String instance, JSONObject resobj){ Peertube peertube = new Peertube(); try { peertube.setId(resobj.get("id").toString()); + peertube.setCache(resobj); peertube.setUuid(resobj.get("uuid").toString()); peertube.setName(resobj.get("name").toString()); peertube.setDescription(resobj.get("description").toString()); @@ -2425,6 +2425,7 @@ public class API { peertube.setId(resobj.get("id").toString()); peertube.setUuid(resobj.get("uuid").toString()); peertube.setName(resobj.get("name").toString()); + peertube.setCache(resobj); peertube.setInstance(instance); peertube.setHost(resobj.getJSONObject("account").get("host").toString()); peertube.setDescription(resobj.get("description").toString()); diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Peertube.java b/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Peertube.java index 0febba666..80ae76581 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Peertube.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Peertube.java @@ -14,6 +14,8 @@ * see . */ package fr.gouv.etalab.mastodon.client.Entities; +import org.json.JSONObject; + import java.util.Date; import java.util.List; @@ -40,7 +42,7 @@ public class Peertube { private Account account; private List resolution; private boolean commentsEnabled; - + private JSONObject cache; public Peertube() { } @@ -207,4 +209,12 @@ public class Peertube { public void setCommentsEnabled(boolean commentsEnabled) { this.commentsEnabled = commentsEnabled; } + + public JSONObject getCache() { + return cache; + } + + public void setCache(JSONObject cache) { + this.cache = cache; + } } diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayFavoritesPeertubeFragment.java b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayFavoritesPeertubeFragment.java new file mode 100644 index 000000000..fa127db17 --- /dev/null +++ b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayFavoritesPeertubeFragment.java @@ -0,0 +1,148 @@ +package fr.gouv.etalab.mastodon.fragments; +/* Copyright 2017 Thomas Schneider + * + * This file is a part of Mastalab + * + * This program is free software; you can redistribute it and/or modify it under the terms of the + * GNU General Public License as published by the Free Software Foundation; either version 3 of the + * License, or (at your option) any later version. + * + * Mastalab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even + * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General + * Public License for more details. + * + * You should have received a copy of the GNU General Public License along with Mastalab; if not, + * see . */ + +import android.content.Context; +import android.content.DialogInterface; +import android.database.sqlite.SQLiteDatabase; +import android.os.AsyncTask; +import android.os.Bundle; +import android.support.annotation.NonNull; +import android.support.design.widget.FloatingActionButton; +import android.support.v4.app.Fragment; +import android.support.v7.app.AlertDialog; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.RelativeLayout; + +import java.util.ArrayList; +import java.util.List; + +import fr.gouv.etalab.mastodon.R; +import fr.gouv.etalab.mastodon.activities.MainActivity; +import fr.gouv.etalab.mastodon.asynctasks.RetrieveFeedsAsyncTask; +import fr.gouv.etalab.mastodon.client.APIResponse; +import fr.gouv.etalab.mastodon.client.Entities.Peertube; +import fr.gouv.etalab.mastodon.drawers.PeertubeAdapter; +import fr.gouv.etalab.mastodon.interfaces.OnRetrieveFeedsInterface; +import fr.gouv.etalab.mastodon.sqlite.PeertubeFavoritesDAO; +import fr.gouv.etalab.mastodon.sqlite.Sqlite; +import fr.gouv.etalab.mastodon.sqlite.StatusCacheDAO; + + +/** + * Created by Thomas on 21/10/2018. + * Fragment to display bookmarks for Peertube + */ +public class DisplayFavoritesPeertubeFragment extends Fragment implements OnRetrieveFeedsInterface { + + + private Context context; + private List peertubes; + private PeertubeAdapter peertubeAdapter; + private RelativeLayout textviewNoAction; + private RelativeLayout mainLoader; + private RecyclerView lv_status; + + @Override + public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + + View rootView = inflater.inflate(R.layout.fragment_peertube_favourites, container, false); + context = getContext(); + + lv_status = rootView.findViewById(R.id.lv_status); + + mainLoader = rootView.findViewById(R.id.loader); + textviewNoAction = rootView.findViewById(R.id.no_action); + mainLoader.setVisibility(View.VISIBLE); + return rootView; + } + + + @Override + public void onCreate(Bundle saveInstance) + { + super.onCreate(saveInstance); + } + + + @Override + public void onAttach(Context context) { + super.onAttach(context); + this.context = context; + } + + @Override + public void onResume() { + super.onResume(); + new RetrieveFeedsAsyncTask(context, RetrieveFeedsAsyncTask.Type.CACHE_BOOKMARKS_PEERTUBE, null, DisplayFavoritesPeertubeFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + } + + @Override + public void onRetrieveFeeds(APIResponse apiResponse) { + + final SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); + mainLoader.setVisibility(View.GONE); + FloatingActionButton delete_all = null; + try { + delete_all = ((MainActivity) context).findViewById(R.id.delete_all); + }catch (Exception ignored){} + peertubes = apiResponse.getPeertubes(); + if( peertubes != null && peertubes.size() > 0) { + LinearLayoutManager mLayoutManager = new LinearLayoutManager(context); + peertubeAdapter = new PeertubeAdapter(context, peertubes.get(0).getInstance(), this.peertubes); + lv_status.setAdapter(peertubeAdapter); + lv_status.setLayoutManager(mLayoutManager); + textviewNoAction.setVisibility(View.GONE); + lv_status.setVisibility(View.VISIBLE); + }else { + textviewNoAction.setVisibility(View.VISIBLE); + lv_status.setVisibility(View.GONE); + } + + if( delete_all != null) + delete_all.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + AlertDialog.Builder builder = new AlertDialog.Builder(context); + builder.setTitle(R.string.delete_all); + builder.setIcon(android.R.drawable.ic_dialog_alert) + .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialogConfirm, int which) { + new PeertubeFavoritesDAO(context, db).removeAll(); + peertubes = new ArrayList<>(); + peertubes.clear(); + peertubeAdapter = new PeertubeAdapter(context,null, peertubes); + lv_status.setAdapter(peertubeAdapter); + peertubeAdapter.notifyDataSetChanged(); + textviewNoAction.setVisibility(View.VISIBLE); + dialogConfirm.dismiss(); + } + }) + .setNegativeButton(R.string.no, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialogConfirm, int which) { + dialogConfirm.dismiss(); + } + }) + .show(); + } + }); + } +} diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/sqlite/PeertubeFavoritesDAO.java b/app/src/main/java/fr/gouv/etalab/mastodon/sqlite/PeertubeFavoritesDAO.java new file mode 100644 index 000000000..aed3ac684 --- /dev/null +++ b/app/src/main/java/fr/gouv/etalab/mastodon/sqlite/PeertubeFavoritesDAO.java @@ -0,0 +1,146 @@ +package fr.gouv.etalab.mastodon.sqlite; +/* Copyright 2018 Thomas Schneider + * + * This file is a part of Mastalab + * + * This program is free software; you can redistribute it and/or modify it under the terms of the + * GNU General Public License as published by the Free Software Foundation; either version 3 of the + * License, or (at your option) any later version. + * + * Mastalab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even + * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General + * Public License for more details. + * + * You should have received a copy of the GNU General Public License along with Mastalab; if not, + * see . */ + +import android.content.ContentValues; +import android.content.Context; +import android.content.SharedPreferences; +import android.database.Cursor; +import android.database.sqlite.SQLiteDatabase; + +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +import fr.gouv.etalab.mastodon.client.API; +import fr.gouv.etalab.mastodon.client.Entities.Peertube; +import fr.gouv.etalab.mastodon.helper.Helper; + + +/** + * Created by Thomas on 21/10/2018. + * Manage Peertube favorites + */ +public class PeertubeFavoritesDAO { + + private SQLiteDatabase db; + public Context context; + + public PeertubeFavoritesDAO(Context context, SQLiteDatabase db) { + //Creation of the DB with tables + this.context = context; + this.db = db; + } + + + //------- INSERTIONS ------- + /** + * Insert a status in database + * @param peertube Peertube + * @return boolean + */ + public long insert(Peertube peertube) { + ContentValues values = new ContentValues(); + values.put(Sqlite.COL_UUID, peertube.getUuid()); + values.put(Sqlite.COL_INSTANCE, peertube.getInstance()); + values.put(Sqlite.COL_DATE, Helper.dateToString(new Date())); + values.put(Sqlite.COL_CACHE, peertube.getCache().toString()); + //Inserts cached peertube + long last_id; + try{ + last_id = db.insert(Sqlite.TABLE_PEERTUBE_FAVOURITES, null, values); + }catch (Exception e) { + last_id = -1; + } + return last_id; + } + //------- REMOVE ------- + + /*** + * Remove stored status + * @return int + */ + public int remove(Peertube peertube){ + return db.delete(Sqlite.TABLE_PEERTUBE_FAVOURITES, Sqlite.COL_UUID + " = \""+ peertube.getUuid() +"\" AND " + Sqlite.COL_INSTANCE + " = \"" + peertube.getInstance() + "\"", null); + } + + /*** + * Remove stored status + * @return int + */ + public int removeAll(){ + return db.delete(Sqlite.TABLE_PEERTUBE_FAVOURITES, null, null); + } + + + + //------- GETTERS ------- + + /** + * Returns all cached Peertube + * @return stored peertube List + */ + public List getAllPeertube(){ + SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); + try { + Cursor c = db.query(Sqlite.TABLE_PEERTUBE_FAVOURITES, null, null, null, null, null, Sqlite.COL_DATE+ " DESC"); + return cursorToListPeertube(c); + } catch (Exception e) { + return null; + } + } + + /** + * Returns a cached Peertube + * @return stored peertube List + */ + public List getSinglePeertube(Peertube peertube){ + SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); + try { + Cursor c = db.query(Sqlite.TABLE_PEERTUBE_FAVOURITES, null, Sqlite.COL_UUID + " = \""+ peertube.getUuid() +"\" AND " + Sqlite.COL_INSTANCE + " = \"" + peertube.getInstance() + "\"", null, null, null, Sqlite.COL_DATE+ " DESC"); + return cursorToListPeertube(c); + } catch (Exception e) { + return null; + } + } + + /*** + * Method to hydrate cached statuses from database + * @param c Cursor + * @return List + */ + private List cursorToListPeertube(Cursor c){ + //No element found + if (c.getCount() == 0) + return null; + List peertubes = new ArrayList<>(); + while (c.moveToNext() ) { + //Restore cached status + try { + Peertube peertube = API.parsePeertube(context, c.getString(c.getColumnIndex(Sqlite.COL_INSTANCE)), new JSONObject(c.getString(c.getColumnIndex(Sqlite.COL_CACHE)))); + peertubes.add(peertube); + } catch (JSONException e) { + e.printStackTrace(); + } + } + //Close the cursor + c.close(); + //Peertubes list is returned + return peertubes; + } +} diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/sqlite/Sqlite.java b/app/src/main/java/fr/gouv/etalab/mastodon/sqlite/Sqlite.java index 970c4c32f..19e79fdee 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/sqlite/Sqlite.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/sqlite/Sqlite.java @@ -26,7 +26,7 @@ import android.database.sqlite.SQLiteOpenHelper; public class Sqlite extends SQLiteOpenHelper { - public static final int DB_VERSION = 14; + public static final int DB_VERSION = 15; public static final String DB_NAME = "mastodon_etalab_db"; public static SQLiteDatabase db; private static Sqlite sInstance; @@ -52,6 +52,9 @@ public class Sqlite extends SQLiteOpenHelper { //Table for instance names static final String TABLE_INSTANCES = "INSTANCES"; + //Table for peertube favorites + static final String TABLE_PEERTUBE_FAVOURITES = "PEERTUBE_FAVOURITES"; + static final String COL_USER_ID = "USER_ID"; static final String COL_USERNAME = "USERNAME"; static final String COL_ACCT = "ACCT"; @@ -166,6 +169,18 @@ public class Sqlite extends SQLiteOpenHelper { + COL_INSTANCE + " TEXT NOT NULL, " + COL_USER_ID + " TEXT NOT NULL, " + COL_INSTANCE_TYPE + " TEXT, " + COL_DATE_CREATION + " TEXT NOT NULL)"; + static final String COL_UUID = "UUID"; + static final String COL_CACHE = "CACHE"; + static final String COL_DATE = "DATE"; + + private final String CREATE_TABLE_PEERTUBE_FAVOURITES = "CREATE TABLE " + + TABLE_PEERTUBE_FAVOURITES + "(" + + COL_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + + COL_UUID + " TEXT NOT NULL, " + + COL_INSTANCE + " TEXT NOT NULL, " + + COL_CACHE + " TEXT NOT NULL, " + + COL_DATE + " TEXT NOT NULL)"; + public Sqlite(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) { super(context, name, factory, version); } @@ -189,6 +204,7 @@ public class Sqlite extends SQLiteOpenHelper { db.execSQL(CREATE_TABLE_STATUSES_CACHE); db.execSQL(CREATE_UNIQUE_CACHE_INDEX); db.execSQL(CREATE_TABLE_INSTANCES); + db.execSQL(CREATE_TABLE_PEERTUBE_FAVOURITES); } @Override @@ -228,6 +244,8 @@ public class Sqlite extends SQLiteOpenHelper { db.execSQL("ALTER TABLE " + TABLE_USER_ACCOUNT + " ADD COLUMN "+ COL_EMOJIS + " TEXT"); case 13: db.execSQL("ALTER TABLE " + TABLE_INSTANCES + " ADD COLUMN "+ COL_INSTANCE_TYPE + " TEXT"); + case 14: + db.execSQL(CREATE_TABLE_PEERTUBE_FAVOURITES); default: break; } diff --git a/app/src/main/res/drawable-anydpi/ic_bookmark_peertube.xml b/app/src/main/res/drawable-anydpi/ic_bookmark_peertube.xml new file mode 100644 index 000000000..b8c26706c --- /dev/null +++ b/app/src/main/res/drawable-anydpi/ic_bookmark_peertube.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable-anydpi/ic_bookmark_peertube_border.xml b/app/src/main/res/drawable-anydpi/ic_bookmark_peertube_border.xml new file mode 100644 index 000000000..1348ada67 --- /dev/null +++ b/app/src/main/res/drawable-anydpi/ic_bookmark_peertube_border.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable-hdpi/ic_favorite_peertube_full.png b/app/src/main/res/drawable-hdpi/ic_favorite_peertube_full.png new file mode 100644 index 0000000000000000000000000000000000000000..e996c6b2ce3fba097347ca56eafc5e7c83e20d31 GIT binary patch literal 292 zcmV+<0o(qGP)|8RJN!4@cH&u|M#>^_i> z2HY5aBPjsE-$0xHpo#rra7Na|%kUCS0WSEAfg7PMgGfyvn2ON0k_2tb5!&{WplvTg z+d2}otwCt3BtcslLYpGPUm`XAVUS0Tg84*hn~fUXqC~~qa|U7bbmEMWCNLf7fGt&~ z6VR4~D-Ylc(PDg=r;2c}V+Vy;H02PJU6W8^@ee}`vH3iJ;RjUHHwJG~3J5!f4?s=t q8LUYyS#%jrG3by}Bry(_vJn7cusjZ6*&{Ci000040e2api9jk2?Fgf5(bdkMig?70A2whkbn-LPqbc&GVBhO`=g@?Up14k+QX{d<2LvL>G1RG>_Ex-OvCVoN>Vx6YMlM>uc?MpR&XiPr2i!(XN^P!k$*c z0S{+G9@F1zf0kS!EeWOC=iA#E;Zzbb{jqzK4a|`g1QPX|-)|8X1Z|*`_g+;6XNdLT wvF4%rxmDF8PI1&2{0g|iHu`84{X&1&3x)Vb(mx=t8UO$Q07*qoM6N<$f)iA19{>OV literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-mdpi/ic_favorite_peertube_full.png b/app/src/main/res/drawable-mdpi/ic_favorite_peertube_full.png new file mode 100644 index 0000000000000000000000000000000000000000..a37c2f29242198319ae4a2a23cef0f0c9065be74 GIT binary patch literal 218 zcmeAS@N?(olHy`uVBq!ia0vp^LLkh+0wn(&ce?|m7J9lkhE&{2PFP@eA$`WV4bu}X zof(*w1=x(&Fnn5O{6bN?GwH|S5As~$Mr#^3*BiGSp5kFp)6Bj2@Oqvk0oRunQyUVr zTmp6DTulXBFII@UI*5EUt~s>w2{W_&nU|~FVdQ&MBb@077O>sQ>@~ literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-xhdpi/ic_favorite_peertube_full.png b/app/src/main/res/drawable-xhdpi/ic_favorite_peertube_full.png new file mode 100644 index 0000000000000000000000000000000000000000..c433b2f8cf8445f28825a7124ef51da0063b3bb0 GIT binary patch literal 398 zcmV;90df9`P)jARTi{!%sTiAQ#bdYf6n#1s#u}Lx&V3#S zSAk|3nm1zHnvwXhMc8az@ON zcSOed&}OQnRMWPh4XvxEKgo#}lM@r_lOD>EnUYv80T~usCJJ-UVA!fn@f6B9-aVvB zI)rk>5{wv|2VdrnQJq^d!nKkqGo*W#2DtPv7xbH4xGv5l=9Es;W7$Tw#$;)Yb9a+u szL|{p6*CF8*!;P-F=I7+1N^mo0dyNNp&QNZ{iB7OYBNbky3IYB_-vCMjAD(FuPMyZn>wqlK(&}_e@-Pxe&R~ z%Dlg1GRCvnj+67gJHsuAQRY*_zB`>0-KaN^Pj1s9#J866faPR%}ZY~r3g_)U5ca@ zp8BZ5dX<8KpZ&$j4`;_zP=_R?sgPA7plO*qlG0SF1JR67?`YGKhzBz|p!&52a97%} z(RA{@hvxC5tZB_CcP6E2Dmzb=(zxo^VuVH|9KwepDvAMG4YWt1ul-iVZkmO+og`Z+ z)B`EFl+{f7mKZ98MizD6f-?c?G}%KL$c%$OmDj}bXGIydIaGk$?2J`}%>-(Ll&mZ$ n4=Y$kZnpmX9CR&6dqRSv6O53yzbYo=XB5+%a3W63xhOv;a`L=PQJeeTz4zUZA>RMMtlt0d|JkpvY( z5}g=B1`Ehz1v5zF7EU4V>)M6W=)yB($&n{#hBDm1NtA?x*^hS2;&;LLgquhdbX5}Y zXND__Hp(g`2bVF&NV^eB=zzP;RZ8oy9N_wfiZTbSzZp1s(Zn_TRJ*TS|6(Ts5 znB+|C#UkqdxEg51_+4)p8(wgA-U=l4;ujjxM89IL36%4_JAHzQy;wm`!qvm`E?tsH zEFTwww`+rN2{urt6`<>EpfM{zBW$3I6`(0L z(1I19c{b3h6`)l%(7Y9(?`)u~6`%|oC~XC3lnvBv1?V;#sNM?DSvJrEsHK<2zQpmVYVD?MFEhx`Q1!9C?Tcg2TQ zTNS6nOC`=z>W)LorHW1!&Jgyfn8TLhxe}c59rMT#+N%I5?O%wAsw`xiJxc4WSS|*o zaR$_F)>iGt6Dgd>$Wh#5SBsRN20ht-y;-oR?zP za=PTA=kH~ciy~1BcPL^gA~~kc00000NkvXXu0mjfG}% + + + + + + + + + + + + + + diff --git a/app/src/main/res/menu/activity_main_drawer.xml b/app/src/main/res/menu/activity_main_drawer.xml index eb138aa40..494d67d58 100644 --- a/app/src/main/res/menu/activity_main_drawer.xml +++ b/app/src/main/res/menu/activity_main_drawer.xml @@ -31,6 +31,10 @@ android:id="@+id/nav_bookmarks" android:icon="@drawable/ic_bookmark" android:title="@string/bookmarks" /> + Add an instance Comments are not enabled on this video! Pick up a resolution + Peertube favourites + The video has been added to bookmarks! + The video has been removed from bookmarks! + There is no Peertube videos in your favourites! Never