Prepare API changes

This commit is contained in:
stom79 2018-12-15 12:21:03 +01:00
parent 1305329321
commit dd7695f1c1
4 changed files with 116 additions and 3 deletions

View File

@ -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<Void, Void, Void> {
apiResponse = api.getStatusbyId(targetedID);
break;
case TAG:
apiResponse = api.getPublicTimelineTag(tag, false, max_id);
List<TagTimeline> 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);

View File

@ -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());

View File

@ -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 <http://www.gnu.org/licenses>. */
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;
}
}

View File

@ -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<TagTimeline>
*/
public List<TagTimeline> 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<String>
*/
private List<TagTimeline> cursorToTagTimelineSearch(Cursor c){
//No element found
if (c.getCount() == 0)
return null;
List<TagTimeline> 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;
}
}