Some fixes

This commit is contained in:
stom79 2018-12-16 18:03:39 +01:00
parent c49768fd98
commit 716b55d430
4 changed files with 46 additions and 18 deletions

View File

@ -15,6 +15,7 @@
package fr.gouv.etalab.mastodon.asynctasks;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.os.AsyncTask;
import java.lang.ref.WeakReference;
@ -26,7 +27,10 @@ import fr.gouv.etalab.mastodon.client.API;
import fr.gouv.etalab.mastodon.client.APIResponse;
import fr.gouv.etalab.mastodon.client.Entities.Account;
import fr.gouv.etalab.mastodon.client.Entities.Conversation;
import fr.gouv.etalab.mastodon.client.Entities.TagTimeline;
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveMissingFeedsInterface;
import fr.gouv.etalab.mastodon.sqlite.SearchDAO;
import fr.gouv.etalab.mastodon.sqlite.Sqlite;
/**
@ -78,6 +82,21 @@ public class RetrieveMissingFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
apiResponse = api.getPublicTimelineSinceId(false, since_id);
else if (type == RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE)
apiResponse = api.getInstanceTimelineSinceId(remoteInstance, since_id);
else if (type == RetrieveFeedsAsyncTask.Type.TAG) {
SQLiteDatabase db = Sqlite.getInstance(contextReference.get(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
List<TagTimeline> tagTimelines = new SearchDAO(contextReference.get(), db).getTimelineInfo(remoteInstance);
if( tagTimelines != null && tagTimelines.size() > 0){
TagTimeline tagTimeline = tagTimelines.get(0);
boolean isArt = tagTimeline.isART();
if( isArt)
apiResponse = api.getCustomArtTimelineSinceId(false, remoteInstance, since_id);
else
apiResponse = api.getPublicTimelineTagSinceId(remoteInstance, false, since_id);
}else{
apiResponse = api.getPublicTimelineTag(remoteInstance, false, since_id);
}
}else if (type == RetrieveFeedsAsyncTask.Type.ART)
apiResponse = api.getArtTimelineSinceId( false, since_id);
if (apiResponse != null) {
if( type != RetrieveFeedsAsyncTask.Type.CONVERSATION)
tempStatus = apiResponse.getStatuses();

View File

@ -1087,11 +1087,19 @@ public class API {
public APIResponse getCustomArtTimeline(boolean local, String tag, String max_id){
return getArtTimeline(local, tag, max_id);
return getArtTimeline(local, tag, max_id, null);
}
public APIResponse getArtTimeline(boolean local, String max_id){
return getArtTimeline(local, null, max_id);
return getArtTimeline(local, null, max_id, null);
}
public APIResponse getCustomArtTimelineSinceId(boolean local, String tag, String since_id){
return getArtTimeline(local, tag, null, since_id);
}
public APIResponse getArtTimelineSinceId(boolean local, String since_id){
return getArtTimeline(local, null, null, since_id);
}
/**
* Retrieves art timeline
@ -1099,10 +1107,10 @@ public class API {
* @param max_id String id max
* @return APIResponse
*/
private APIResponse getArtTimeline(boolean local, String tag, String max_id){
private APIResponse getArtTimeline(boolean local, String tag, String max_id, String since_id){
if( tag == null)
tag = "mastoart";
APIResponse apiResponse = getPublicTimelineTag(tag, local, true, max_id, null, tootPerPage);
APIResponse apiResponse = getPublicTimelineTag(tag, local, true, max_id, since_id, tootPerPage);
APIResponse apiResponseReply = new APIResponse();
if( apiResponse != null){
apiResponseReply.setMax_id(apiResponse.getMax_id());
@ -1137,6 +1145,18 @@ public class API {
public APIResponse getPublicTimelineTag(String tag, boolean local, String max_id){
return getPublicTimelineTag(tag, local, false, max_id, null, tootPerPage);
}
/**
* Retrieves public tag timeline *synchronously*
* @param tag String
* @param local boolean only local timeline
* @param since_id String since id
* @return APIResponse
*/
@SuppressWarnings("SameParameterValue")
public APIResponse getPublicTimelineTagSinceId(String tag, boolean local, String since_id){
return getPublicTimelineTag(tag, local, false, null, since_id, tootPerPage);
}
/**
* Retrieves public tag timeline *synchronously*
* @param tag String

View File

@ -625,8 +625,10 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
* @param sinceId String
*/
public void retrieveMissingToots(String sinceId){
if (type == RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE)
if (type == RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE )
asyncTask = new RetrieveMissingFeedsAsyncTask(context, remoteInstance, sinceId, type, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
else if(type == RetrieveFeedsAsyncTask.Type.TAG)
asyncTask = new RetrieveMissingFeedsAsyncTask(context, tag, sinceId, type, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
else
asyncTask = new RetrieveMissingFeedsAsyncTask(context, sinceId, type, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
@ -744,9 +746,6 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
int position = 0;
insertedConversation = statuses.size();
if( this.statuses != null) {
long initialConversationId = -1;
if( this.statuses.size() > 0 )
initialConversationId = Long.parseLong(this.statuses.get(0).getConversationId());
for (Iterator<Status> it = this.statuses.iterator(); it.hasNext(); ) {
Status status = it.next();
for (Status status1 : statuses) {

View File

@ -2983,16 +2983,6 @@ public class Helper {
}
}
public static String getDefaultLocale(){
String locale = Locale.getDefault().getCountry();
if( locale.startsWith("zh")){
if( Locale.getDefault().getLanguage().equals("TW") || Locale.getDefault().getLanguage().equals("CN"))
locale = Locale.getDefault().getCountry() + "-" + Locale.getDefault().getLanguage();
else
locale = Locale.getDefault().getCountry() + "-TW";
}
return locale;
}
public static int languageSpinnerPosition(Context context){
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE);