From dd7695f1c1f679bb28d3f6ac395af1995adf2227 Mon Sep 17 00:00:00 2001 From: stom79 Date: Sat, 15 Dec 2018 12:21:03 +0100 Subject: [PATCH] Prepare API changes --- .../asynctasks/RetrieveFeedsAsyncTask.java | 15 +++++- .../fr/gouv/etalab/mastodon/client/API.java | 12 ++++- .../mastodon/client/Entities/TagTimeline.java | 53 +++++++++++++++++++ .../etalab/mastodon/sqlite/SearchDAO.java | 39 ++++++++++++++ 4 files changed, 116 insertions(+), 3 deletions(-) create mode 100644 app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/TagTimeline.java 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 a21c29b81..3539b7992 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 @@ -25,10 +25,12 @@ import fr.gouv.etalab.mastodon.client.API; import fr.gouv.etalab.mastodon.client.APIResponse; import fr.gouv.etalab.mastodon.client.Entities.Peertube; import fr.gouv.etalab.mastodon.client.Entities.RemoteInstance; +import fr.gouv.etalab.mastodon.client.Entities.TagTimeline; import fr.gouv.etalab.mastodon.helper.FilterToots; 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.SearchDAO; import fr.gouv.etalab.mastodon.sqlite.Sqlite; import fr.gouv.etalab.mastodon.sqlite.StatusCacheDAO; @@ -189,7 +191,18 @@ public class RetrieveFeedsAsyncTask extends AsyncTask { apiResponse = api.getStatusbyId(targetedID); break; case TAG: - apiResponse = api.getPublicTimelineTag(tag, false, max_id); + List tagTimelines = new SearchDAO(contextReference.get(), db).getTimelineInfo(tag); + if( tagTimelines != null && tagTimelines.size() > 0){ + TagTimeline tagTimeline = tagTimelines.get(0); + boolean isArt = tagTimeline.isART(); + if( isArt) + apiResponse = api.getCustomArtTimeline(false, tag, max_id); + else + apiResponse = api.getPublicTimelineTag(tag, false, max_id); + }else{ + apiResponse = api.getPublicTimelineTag(tag, false, max_id); + } + break; case ART: apiResponse = api.getArtTimeline(false, max_id); 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 04631c858..62c145566 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 @@ -1086,7 +1086,13 @@ public class API { + public APIResponse getCustomArtTimeline(boolean local, String tag, String max_id){ + return getArtTimeline(local, tag, max_id); + } + public APIResponse getArtTimeline(boolean local, String max_id){ + return getArtTimeline(local, null, max_id); + } /** * Retrieves art timeline * @param local boolean only local timeline @@ -1094,8 +1100,10 @@ public class API { * @return APIResponse */ @SuppressWarnings("SameParameterValue") - public APIResponse getArtTimeline(boolean local, String max_id){ - APIResponse apiResponse = getPublicTimelineTag("mastoart", local, true, max_id, null, tootPerPage); + private APIResponse getArtTimeline(boolean local, String tag, String max_id){ + if( tag == null) + tag = "mastoart"; + APIResponse apiResponse = getPublicTimelineTag(tag, local, true, max_id, null, tootPerPage); APIResponse apiResponseReply = new APIResponse(); if( apiResponse != null){ apiResponseReply.setMax_id(apiResponse.getMax_id()); diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/TagTimeline.java b/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/TagTimeline.java new file mode 100644 index 000000000..65fc956fe --- /dev/null +++ b/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/TagTimeline.java @@ -0,0 +1,53 @@ +/* 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 . */ +package fr.gouv.etalab.mastodon.client.Entities; + +/** + * Created by Thomas on 15/12/2018. + * Manage Tags timeline settings + */ + +public class TagTimeline { + + private String name; + private boolean isART; + private boolean isNSFW; + + + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public boolean isART() { + return isART; + } + + public void setART(boolean ART) { + isART = ART; + } + + public boolean isNSFW() { + return isNSFW; + } + + public void setNSFW(boolean NSFW) { + isNSFW = NSFW; + } +} diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/sqlite/SearchDAO.java b/app/src/main/java/fr/gouv/etalab/mastodon/sqlite/SearchDAO.java index f0c20f9a1..0bf333b5a 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/sqlite/SearchDAO.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/sqlite/SearchDAO.java @@ -23,6 +23,8 @@ import android.database.sqlite.SQLiteDatabase; import java.util.ArrayList; import java.util.Date; import java.util.List; + +import fr.gouv.etalab.mastodon.client.Entities.TagTimeline; import fr.gouv.etalab.mastodon.helper.Helper; @@ -136,4 +138,41 @@ public class SearchDAO { //Search list is returned return searches; } + + + /** + * Returns TagTimeline information by its keyword in db + * @return info List + */ + public List getTimelineInfo(String keyword){ + try { + Cursor c = db.query(Sqlite.TABLE_SEARCH, null, Sqlite.COL_KEYWORDS + " = \"" + keyword + "\" AND " + Sqlite.COL_USER_ID + " = \"" + userId+ "\"", null, null, null, null, null); + return cursorToTagTimelineSearch(c); + } catch (Exception e) { + return null; + } + } + + /*** + * Method to hydrate stored search from database + * @param c Cursor + * @return List + */ + private List cursorToTagTimelineSearch(Cursor c){ + //No element found + if (c.getCount() == 0) + return null; + List searches = new ArrayList<>(); + while (c.moveToNext() ) { + TagTimeline tagTimeline = new TagTimeline(); + tagTimeline.setName(c.getString(c.getColumnIndex(Sqlite.COL_KEYWORDS))); + tagTimeline.setART(c.getInt(c.getColumnIndex(Sqlite.COL_IS_ART))==1); + tagTimeline.setNSFW(c.getInt(c.getColumnIndex(Sqlite.COL_IS_NSFW))==1); + searches.add(tagTimeline); + } + //Close the cursor + c.close(); + //Search list is returned + return searches; + } }