diff options
Diffstat (limited to 'app/src/main/java/fr/gouv/etalab/mastodon/fragments')
4 files changed, 106 insertions, 104 deletions
diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayFiltersFragment.java b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayFiltersFragment.java index db7bd0318..1982d5530 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayFiltersFragment.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayFiltersFragment.java @@ -18,6 +18,7 @@ import android.annotation.SuppressLint; import android.content.Context; import android.content.DialogInterface; import android.content.SharedPreferences; +import android.database.sqlite.SQLiteDatabase; import android.os.AsyncTask; import android.os.Bundle; import android.support.annotation.NonNull; @@ -48,9 +49,14 @@ import fr.gouv.etalab.mastodon.activities.MainActivity; import fr.gouv.etalab.mastodon.asynctasks.ManageFiltersAsyncTask; import fr.gouv.etalab.mastodon.client.APIResponse; import fr.gouv.etalab.mastodon.client.Entities.Filters; +import fr.gouv.etalab.mastodon.client.Entities.ManageTimelines; import fr.gouv.etalab.mastodon.drawers.FilterAdapter; import fr.gouv.etalab.mastodon.helper.Helper; import fr.gouv.etalab.mastodon.interfaces.OnFilterActionInterface; +import fr.gouv.etalab.mastodon.sqlite.Sqlite; +import fr.gouv.etalab.mastodon.sqlite.TimelinesDAO; + +import static fr.gouv.etalab.mastodon.sqlite.Sqlite.DB_NAME; /** @@ -256,7 +262,16 @@ public class DisplayFiltersFragment extends Fragment implements OnFilterActionIn } } MainActivity.filters = apiResponse.getFilters(); - ((MainActivity)context).refreshFilters(); + SQLiteDatabase db = Sqlite.getInstance(context, DB_NAME, null, Sqlite.DB_VERSION).open(); + List<ManageTimelines> timelines = new TimelinesDAO(context, db).getDisplayedTimelines(); + for(ManageTimelines tl: timelines) { + if( tl.getType() == ManageTimelines.Type.HOME || tl.getType() == ManageTimelines.Type.LOCAL || tl.getType() == ManageTimelines.Type.PUBLIC) { + DisplayStatusFragment homeFragment = (DisplayStatusFragment) ((MainActivity) context).getSupportFragmentManager().getFragments().get(tl.getPosition()); + if (homeFragment != null) + homeFragment.refreshFilter(); + } + } + } } 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; + } + } } diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/SettingsFragment.java b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/SettingsFragment.java index 76f19867a..e05362110 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/SettingsFragment.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/SettingsFragment.java @@ -674,6 +674,19 @@ public class SettingsFragment extends Fragment { } }); + boolean new_badge = sharedpreferences.getBoolean(Helper.SET_DISPLAY_NEW_BADGE, true); + final CheckBox set_new_badge = rootView.findViewById(R.id.set_display_new_badge); + set_new_badge.setChecked(new_badge); + + set_new_badge.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + SharedPreferences.Editor editor = sharedpreferences.edit(); + editor.putBoolean(Helper.SET_DISPLAY_NEW_BADGE, set_new_badge.isChecked()); + editor.apply(); + } + }); + boolean fit_preview = sharedpreferences.getBoolean(Helper.SET_FULL_PREVIEW, false); final CheckBox set_fit_preview = rootView.findViewById(R.id.set_fit_preview); set_fit_preview.setChecked(fit_preview); @@ -798,86 +811,6 @@ public class SettingsFragment extends Fragment { } }); - - boolean display_direct = sharedpreferences.getBoolean(Helper.SET_DISPLAY_DIRECT, true); - final CheckBox set_display_direct = rootView.findViewById(R.id.set_display_direct); - set_display_direct.setChecked(display_direct); - - set_display_direct.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - SharedPreferences.Editor editor = sharedpreferences.edit(); - editor.putBoolean(Helper.SET_DISPLAY_DIRECT, set_display_direct.isChecked()); - editor.apply(); - if( getActivity() != null) - getActivity().recreate(); - Intent intent = new Intent(context, MainActivity.class); - if(getActivity() != null) - getActivity().finish(); - startActivity(intent); - } - }); - - boolean display_local = sharedpreferences.getBoolean(Helper.SET_DISPLAY_LOCAL, true); - final CheckBox set_display_local = rootView.findViewById(R.id.set_display_local); - set_display_local.setChecked(display_local); - - set_display_local.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - SharedPreferences.Editor editor = sharedpreferences.edit(); - editor.putBoolean(Helper.SET_DISPLAY_LOCAL, set_display_local.isChecked()); - editor.apply(); - if( getActivity() != null) - getActivity().recreate(); - Intent intent = new Intent(context, MainActivity.class); - if(getActivity() != null) - getActivity().finish(); - startActivity(intent); - } - }); - - boolean display_global = sharedpreferences.getBoolean(Helper.SET_DISPLAY_GLOBAL, true); - final CheckBox set_display_global = rootView.findViewById(R.id.set_display_global); - set_display_global.setChecked(display_global); - - set_display_global.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - SharedPreferences.Editor editor = sharedpreferences.edit(); - editor.putBoolean(Helper.SET_DISPLAY_GLOBAL, set_display_global.isChecked()); - editor.apply(); - if( getActivity() != null) - getActivity().recreate(); - Intent intent = new Intent(context, MainActivity.class); - intent.putExtra(INTENT_ACTION, BACK_TO_SETTINGS); - if(getActivity() != null) - getActivity().finish(); - startActivity(intent); - } - }); - - - boolean display_art = sharedpreferences.getBoolean(Helper.SET_DISPLAY_ART, true); - final CheckBox set_display_art = rootView.findViewById(R.id.set_display_art); - set_display_art.setChecked(display_art); - - set_display_art.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - SharedPreferences.Editor editor = sharedpreferences.edit(); - editor.putBoolean(Helper.SET_DISPLAY_ART, set_display_art.isChecked()); - editor.apply(); - if( getActivity() != null) - getActivity().recreate(); - Intent intent = new Intent(context, MainActivity.class); - intent.putExtra(INTENT_ACTION, BACK_TO_SETTINGS); - if(getActivity() != null) - getActivity().finish(); - startActivity(intent); - } - }); - boolean disableGif = sharedpreferences.getBoolean(Helper.SET_DISABLE_GIF, false); final CheckBox set_disable_gif = rootView.findViewById(R.id.set_disable_gif); set_disable_gif.setChecked(disableGif); @@ -1067,11 +1000,7 @@ public class SettingsFragment extends Fragment { editor.apply(); break; } - if (getActivity() != null) - getActivity().recreate(); - Intent intent = new Intent(context, MainActivity.class); - intent.putExtra(INTENT_ACTION, BACK_TO_SETTINGS); - startActivity(intent); + ((MainActivity) context).recreate(); } count1++; } diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/TabLayoutNotificationsFragment.java b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/TabLayoutNotificationsFragment.java index e1d0f2f63..d52e54dae 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/TabLayoutNotificationsFragment.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/TabLayoutNotificationsFragment.java @@ -25,6 +25,7 @@ import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentStatePagerAdapter; import android.support.v4.content.ContextCompat; +import android.support.v4.view.ViewPager; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -176,6 +177,10 @@ public class TabLayoutNotificationsFragment extends Fragment { return inflatedView; } + public ViewPager getViewPager(){ + return viewPager; + } + @Override public void onAttach(Context context) { super.onAttach(context); @@ -249,7 +254,8 @@ public class TabLayoutNotificationsFragment extends Fragment { } public void refreshAll(){ - + if( viewPager == null) + return; FragmentStatePagerAdapter a = (FragmentStatePagerAdapter) viewPager.getAdapter(); if( a != null) { DisplayNotificationsFragment notifAll = (DisplayNotificationsFragment) a.instantiateItem(viewPager, 0); |