diff options
Diffstat (limited to 'app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayStatusFragment.java')
-rw-r--r-- | app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayStatusFragment.java | 86 |
1 files changed, 69 insertions, 17 deletions
diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayStatusFragment.java b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayStatusFragment.java index 6967afc91..81327af0a 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayStatusFragment.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayStatusFragment.java @@ -47,7 +47,9 @@ import java.util.List; import es.dmoral.toasty.Toasty; import fr.gouv.etalab.mastodon.R; import fr.gouv.etalab.mastodon.activities.BaseMainActivity; +import fr.gouv.etalab.mastodon.activities.ListActivity; import fr.gouv.etalab.mastodon.activities.MainActivity; +import fr.gouv.etalab.mastodon.asynctasks.ManageListsAsyncTask; import fr.gouv.etalab.mastodon.asynctasks.RetrieveFeedsAfterBookmarkAsyncTask; import fr.gouv.etalab.mastodon.asynctasks.RetrieveFeedsAsyncTask; import fr.gouv.etalab.mastodon.asynctasks.RetrieveMissingFeedsAsyncTask; @@ -67,6 +69,7 @@ import fr.gouv.etalab.mastodon.drawers.PeertubeAdapter; import fr.gouv.etalab.mastodon.drawers.PixelfedListAdapter; import fr.gouv.etalab.mastodon.drawers.StatusListAdapter; import fr.gouv.etalab.mastodon.helper.Helper; +import fr.gouv.etalab.mastodon.interfaces.OnListActionInterface; import fr.gouv.etalab.mastodon.interfaces.OnRetrieveFeedsAfterBookmarkInterface; import fr.gouv.etalab.mastodon.interfaces.OnRetrieveFeedsInterface; import fr.gouv.etalab.mastodon.interfaces.OnRetrieveMissingFeedsInterface; @@ -84,7 +87,7 @@ import fr.gouv.etalab.mastodon.sqlite.TempMuteDAO; * Created by Thomas on 24/04/2017. * Fragment to display content related to status */ -public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsInterface, OnRetrieveMissingFeedsInterface, OnRetrieveFeedsAfterBookmarkInterface { +public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsInterface, OnRetrieveMissingFeedsInterface, OnRetrieveFeedsAfterBookmarkInterface, OnListActionInterface { private boolean flag_loading; @@ -126,6 +129,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn private BroadcastReceiver receive_action; private BroadcastReceiver receive_data; private Date lastReadTootDate, initialBookMarkDate, updatedBookMarkDate; + private int timelineId; public DisplayStatusFragment(){ } @@ -156,13 +160,17 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn remote_channel_name = bundle.getString("remote_channel_name", null); instanceType = bundle.getString("instanceType", "MASTODON"); ischannel = bundle.getBoolean("ischannel",false); + timelineId = bundle.getInt("timelineId"); + } + if( ischannel) type = RetrieveFeedsAsyncTask.Type.CHANNEL; SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); //instanceType should not be null only for Peertube accounts - if( !remoteInstance.equals("") && instanceType == null){ + + if( remoteInstance != null && !remoteInstance.equals("") && instanceType == null){ List<RemoteInstance> remoteInstanceObj = new InstancesDAO(context, db).getInstanceByName(remoteInstance); if( remoteInstanceObj != null && remoteInstanceObj.size() > 0) instanceType = remoteInstanceObj.get(0).getType(); @@ -196,7 +204,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn lastReadToot = sharedpreferences.getString(Helper.LAST_READ_TOOT_ID + userId + instance, null); lastReadTootDate = Helper.stringToDate(context, sharedpreferences.getString(Helper.LAST_READ_TOOT_DATE + userId + instance, null)); } - if( instanceType.equals("MASTODON") || instanceType.equals("MISSKEY") ){ + if( instanceType == null || instanceType.equals("MASTODON") || instanceType.equals("MISSKEY") ){ if( type == RetrieveFeedsAsyncTask.Type.TAG && tag != null) { BaseMainActivity.displayPeertube = null; List<TagTimeline> tagTimelines = new SearchDAO(context, db).getTimelineInfo(tag); @@ -318,7 +326,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn }); - if( !instanceType.equals("PEERTUBE")) + if( instanceType == null || !instanceType.equals("PEERTUBE")) swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { @@ -914,9 +922,9 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn ((MainActivity) context).updateHomeCounter(); else { if( type != RetrieveFeedsAsyncTask.Type.CONVERSATION) - ((MainActivity) context).updateTimeLine(type, inserted); + ((MainActivity) context).manageTab(type, inserted); else - ((MainActivity) context).updateTimeLine(type, insertedConversation); + ((MainActivity) context).manageTab(type, insertedConversation); } }catch (Exception ignored){} } @@ -989,24 +997,26 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn } } - private void manageAsyncTask(boolean pagination){ + private void manageAsyncTask(boolean pagination) { //Message for an account if (type == RetrieveFeedsAsyncTask.Type.USER || type == RetrieveFeedsAsyncTask.Type.CHANNEL) - asyncTask = new RetrieveFeedsAsyncTask(context, type, targetedId, max_id, showMediaOnly, showPinned, showReply,DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - //Tag timelines - else if (type == RetrieveFeedsAsyncTask.Type.TAG || type == RetrieveFeedsAsyncTask.Type.SEARCH) + asyncTask = new RetrieveFeedsAsyncTask(context, type, targetedId, max_id, showMediaOnly, showPinned, showReply, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + //Tag timelines + else if (type == RetrieveFeedsAsyncTask.Type.SEARCH) asyncTask = new RetrieveFeedsAsyncTask(context, type, tag, targetedId, max_id, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - else if( type == RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE) { + else if (type == RetrieveFeedsAsyncTask.Type.TAG ) + asyncTask = new RetrieveFeedsAsyncTask(context, type, timelineId, max_id, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + else if (type == RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE) { //Remote instances - if( search_peertube == null) { //Not a Peertube search - if( remote_channel_name == null) { //Not a channel + if (search_peertube == null) { //Not a Peertube search + if (remote_channel_name == null) { //Not a channel asyncTask = new RetrieveFeedsAsyncTask(context, type, remoteInstance, max_id, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } - else + } else asyncTask = new RetrieveFeedsAsyncTask(context, remoteInstance, remote_channel_name, null, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } - else + } else asyncTask = new RetrievePeertubeSearchAsyncTask(context, remoteInstance, search_peertube, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + }else if( type == RetrieveFeedsAsyncTask.Type.LIST){ + new ManageListsAsyncTask(context,targetedId, max_id ,null, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); }else { if( !pagination) { if (type == RetrieveFeedsAsyncTask.Type.HOME) { @@ -1027,4 +1037,46 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn } + @Override + public void onActionDone(ManageListsAsyncTask.action actionType, APIResponse apiResponse, int statusCode) { + final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); + mainLoader.setVisibility(View.GONE); + nextElementLoader.setVisibility(View.GONE); + //Discards 404 - error which can often happen due to toots which have been deleted + if (apiResponse.getError() != null) { + if ( !apiResponse.getError().getError().startsWith("404 -")) + Toasty.error(context, apiResponse.getError().getError(), Toast.LENGTH_LONG).show(); + swipeRefreshLayout.setRefreshing(false); + isSwipped = false; + flag_loading = false; + return; + } + if( actionType == ManageListsAsyncTask.action.GET_LIST_TIMELINE) { + + int previousPosition = this.statuses.size(); + List<Status> statuses = apiResponse.getStatuses(); + max_id = apiResponse.getMax_id(); + flag_loading = (max_id == null); + if (!isSwipped && firstLoad && (statuses == null || statuses.size() == 0)) + textviewNoAction.setVisibility(View.VISIBLE); + else + textviewNoAction.setVisibility(View.GONE); + + if (isSwipped) { + if (previousPosition > 0) { + for (int i = 0; i < previousPosition; i++) { + this.statuses.remove(0); + } + statusListAdapter.notifyItemRangeRemoved(0, previousPosition); + } + isSwipped = false; + } + if (statuses != null && statuses.size() > 0) { + this.statuses.addAll(statuses); + statusListAdapter.notifyItemRangeInserted(previousPosition, statuses.size()); + } + swipeRefreshLayout.setRefreshing(false); + firstLoad = false; + } + } } |