diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseMainActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseMainActivity.java index d690f11ca..6e5f9e7ba 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseMainActivity.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseMainActivity.java @@ -42,6 +42,7 @@ import android.support.v4.app.ActivityCompat; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentStatePagerAdapter; +import android.support.v4.app.FragmentTransaction; import android.support.v4.content.ContextCompat; import android.support.v4.content.LocalBroadcastManager; import android.support.v4.view.GravityCompat; @@ -109,6 +110,7 @@ import fr.gouv.etalab.mastodon.client.Entities.Notification; import fr.gouv.etalab.mastodon.client.Entities.RemoteInstance; import fr.gouv.etalab.mastodon.client.Entities.Results; import fr.gouv.etalab.mastodon.client.Entities.Status; +import fr.gouv.etalab.mastodon.client.Entities.TagTimeline; import fr.gouv.etalab.mastodon.client.Entities.Version; import fr.gouv.etalab.mastodon.client.HttpsConnection; import fr.gouv.etalab.mastodon.fragments.DisplayAccountsFragment; @@ -181,7 +183,7 @@ public abstract class BaseMainActivity extends BaseActivity private RelativeLayout main_app_container; private Stack stackBack = new Stack<>(); public static List filters = new ArrayList<>(); - private DisplayStatusFragment homeFragment, federatedFragment, localFragment, artFragment; + private DisplayStatusFragment homeFragment, federatedFragment, localFragment; private DisplayNotificationsFragment notificationsFragment; private static final int ERROR_DIALOG_REQUEST_CODE = 97; private static BroadcastReceiver receive_data, receive_federated_data, receive_local_data; @@ -827,30 +829,6 @@ public abstract class BaseMainActivity extends BaseActivity } }); - if( tabStrip.getChildCount() > 2 && !display_direct) - tabStrip.getChildAt(2).setOnLongClickListener(new View.OnLongClickListener() { - @Override - public boolean onLongClick(View v) { - return manageFilters(tabStrip, sharedpreferences); - } - }); - else if ( tabStrip.getChildCount() > 3 && display_direct) - tabStrip.getChildAt(3).setOnLongClickListener(new View.OnLongClickListener() { - @Override - public boolean onLongClick(View v) { - return manageFilters(tabStrip, sharedpreferences); - } - }); - if( tabStrip.getChildCount() == 5) - tabStrip.getChildAt(4).setOnLongClickListener(new View.OnLongClickListener() { - @Override - public boolean onLongClick(View v) { - return manageFilters(tabStrip, sharedpreferences); - } - }); - - - countPage = 2; if( sharedpreferences.getBoolean(Helper.SET_DISPLAY_DIRECT, true)) countPage++; @@ -861,6 +839,21 @@ public abstract class BaseMainActivity extends BaseActivity if( sharedpreferences.getBoolean(Helper.SET_DISPLAY_ART, true)) countPage++; + if( tabPosition.containsKey("global")) + tabStrip.getChildAt(tabPosition.get("global")).setOnLongClickListener(new View.OnLongClickListener() { + @Override + public boolean onLongClick(View v) { + return manageFilters(tabStrip, sharedpreferences); + } + }); + if( tabPosition.containsKey("local")) + tabStrip.getChildAt(tabPosition.get("local")).setOnLongClickListener(new View.OnLongClickListener() { + @Override + public boolean onLongClick(View v) { + return manageFilters(tabStrip, sharedpreferences); + } + }); + viewPager.setOffscreenPageLimit(countPage); main_app_container = findViewById(R.id.main_app_container); adapter = new PagerAdapter @@ -997,10 +990,10 @@ public abstract class BaseMainActivity extends BaseActivity break; case 5: if( countPage == 6) { - displayStatusFragment = ((DisplayStatusFragment) fragment); - displayStatusFragment.scrollToTop(); updateTimeLine(RetrieveFeedsAsyncTask.Type.ART, 0); } + displayStatusFragment = ((DisplayStatusFragment) fragment); + displayStatusFragment.scrollToTop(); break; case 1: DisplayNotificationsFragment displayNotificationsFragment = ((DisplayNotificationsFragment) fragment); @@ -1580,12 +1573,9 @@ public abstract class BaseMainActivity extends BaseActivity if(homeFragment != null && homeFragment.getUserVisibleHint()) popup = new PopupMenu(BaseMainActivity.this, tabStrip.getChildAt(0)); else if(localFragment != null && localFragment.getUserVisibleHint()) - popup = new PopupMenu(BaseMainActivity.this, tabStrip.getChildAt(2)); + popup = new PopupMenu(BaseMainActivity.this, tabStrip.getChildAt(tabPosition.get("local"))); else if(federatedFragment != null && federatedFragment.getUserVisibleHint()){ - if( !display_local && display_global) - popup = new PopupMenu(BaseMainActivity.this, tabStrip.getChildAt(2)); - else - popup = new PopupMenu(BaseMainActivity.this, tabStrip.getChildAt(3)); + popup = new PopupMenu(BaseMainActivity.this, tabStrip.getChildAt(tabPosition.get("global"))); } if( popup == null) return true; @@ -2338,7 +2328,7 @@ public abstract class BaseMainActivity extends BaseActivity } } - + public static HashMap tagFragment = new HashMap<>(); /** * Page Adapter for settings */ @@ -2383,10 +2373,12 @@ public abstract class BaseMainActivity extends BaseActivity return notificationsFragment; }else { statusFragment = new DisplayStatusFragment(); - bundle.putSerializable("type", Helper.timelineType(getApplicationContext(), position)); - if( Helper.timelineType(getApplicationContext(), position) == RetrieveFeedsAsyncTask.Type.TAG){ - if( tabLayout.getTabAt(position) != null && tabLayout.getTabAt(position).getText() != null) + bundle.putSerializable("type", Helper.timelineType(getApplicationContext(), position, countPage)); + if( Helper.timelineType(getApplicationContext(), position, countPage) == RetrieveFeedsAsyncTask.Type.TAG){ + if( tabLayout.getTabAt(position) != null && tabLayout.getTabAt(position).getText() != null) { bundle.putString("tag", tabLayout.getTabAt(position).getText().toString()); + tagFragment.put(tabLayout.getTabAt(position).getText().toString(), statusFragment); + } } statusFragment.setArguments(bundle); return statusFragment; @@ -2398,41 +2390,23 @@ public abstract class BaseMainActivity extends BaseActivity public Object instantiateItem(@NonNull ViewGroup container, int position) { Fragment createdFragment = (Fragment) super.instantiateItem(container, position); // save the appropriate reference depending on position - switch (position) { - case 0: - homeFragment = (DisplayStatusFragment) createdFragment; - break; - case 1: - notificationsFragment = (DisplayNotificationsFragment) createdFragment; - break; - case 2: - if( !display_direct && display_local) - localFragment = (DisplayStatusFragment) createdFragment; - else if ( !display_direct && display_global) - federatedFragment = (DisplayStatusFragment) createdFragment; - else - artFragment = (DisplayStatusFragment) createdFragment; - case 3: - if( display_direct && display_local) - localFragment = (DisplayStatusFragment) createdFragment; - else if( !display_direct && display_local && display_global) - federatedFragment = (DisplayStatusFragment) createdFragment; - else if( display_direct && display_global) - federatedFragment = (DisplayStatusFragment) createdFragment; - else - artFragment = (DisplayStatusFragment) createdFragment; - break; - case 4: - if( display_direct && display_local && display_global) - federatedFragment = (DisplayStatusFragment) createdFragment; - else - artFragment = (DisplayStatusFragment) createdFragment; - break; - case 5: - if( display_direct && display_local && display_global && display_art) - artFragment = (DisplayStatusFragment) createdFragment; - break; - } + if( position == 0){ + homeFragment = (DisplayStatusFragment) createdFragment; + }else if( position == 1){ + notificationsFragment = (DisplayNotificationsFragment) createdFragment; + }else if( position ==2 && countPage > 2){ + if( !display_direct && display_local) + localFragment = (DisplayStatusFragment) createdFragment; + else if (!display_local) + federatedFragment = (DisplayStatusFragment) createdFragment; + }else if (position == 3 && countPage > 3){ + if( display_local) + localFragment = (DisplayStatusFragment) createdFragment; + else if (display_global) + federatedFragment = (DisplayStatusFragment) createdFragment; + }else if( position == 4 && countPage > 4) + if( display_global) + federatedFragment = (DisplayStatusFragment) createdFragment; return createdFragment; } @@ -2445,59 +2419,125 @@ public abstract class BaseMainActivity extends BaseActivity private void attacheDelete(int position){ LinearLayout tabStrip = (LinearLayout) tabLayout.getChildAt(0); - String title = tabLayout.getTabAt(position).getText().toString().trim(); - SQLiteDatabase db = Sqlite.getInstance(BaseMainActivity.this, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); tabStrip.getChildAt(position).setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { - AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(BaseMainActivity.this, style); - dialogBuilder.setPositiveButton(R.string.validate, new DialogInterface.OnClickListener() { + String tag = tabLayout.getTabAt(position).getText().toString().trim(); + SQLiteDatabase db = Sqlite.getInstance(BaseMainActivity.this, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); + PopupMenu popup = new PopupMenu(BaseMainActivity.this, tabStrip.getChildAt(position)); + popup.getMenuInflater() + .inflate(R.menu.option_tag_timeline, popup.getMenu()); + Menu menu = popup.getMenu(); + final MenuItem itemMediaOnly = menu.findItem(R.id.action_show_media_only); + final MenuItem itemShowNSFW = menu.findItem(R.id.action_show_nsfw); + List tagTimelines = new SearchDAO(BaseMainActivity.this, db).getTimelineInfo(tag); + boolean mediaOnly = false; + boolean showNSFW = false; + if( tagTimelines != null && tagTimelines.size() > 0 ) { + mediaOnly = tagTimelines.get(0).isART(); + showNSFW = tagTimelines.get(0).isNSFW(); + } + itemMediaOnly.setChecked(mediaOnly); + itemShowNSFW.setChecked(showNSFW); + popup.setOnDismissListener(new PopupMenu.OnDismissListener() { @Override - public void onClick(DialogInterface dialog, int id) { - new SearchDAO(BaseMainActivity.this, db).remove(title); - String tag; - if( position > 0 && tabLayout.getTabAt(position - 1).getText() != null) { - tag = tabLayout.getTabAt(position - 1).getText().toString(); - }else if( tabLayout.getTabCount() > 1 && tabLayout.getTabAt(1).getText() != null) { - tag = tabLayout.getTabAt(1).getText().toString(); - }else //Last element - tag = ""; - Helper.removeTab(tabLayout, adapter, position); - adapter = new BaseMainActivity.PagerAdapter - (getSupportFragmentManager(), tabLayout.getTabCount()); - viewPager.setAdapter(adapter); - for(int i = 0; i < tabLayout.getTabCount() ; i++ ){ - if( tabLayout.getTabAt(i).getText() != null && tabLayout.getTabAt(i).getText().equals(tag.trim())){ - tabLayout.getTabAt(i).select(); - break; + public void onDismiss(PopupMenu menu) { + FragmentTransaction fragTransaction = getSupportFragmentManager().beginTransaction(); + fragTransaction.detach(tagFragment.get(tag)); + fragTransaction.attach(tagFragment.get(tag)); + fragTransaction.commit(); + } + }); + boolean finalMediaOnly = mediaOnly; + boolean finalShowNSFW = showNSFW; + popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { + public boolean onMenuItemClick(MenuItem item) { + item.setShowAsAction(MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW); + item.setActionView(new View(getApplicationContext())); + item.setOnActionExpandListener(new MenuItem.OnActionExpandListener() { + @Override + public boolean onMenuItemActionExpand(MenuItem item) { + return false; } + @Override + public boolean onMenuItemActionCollapse(MenuItem item) { + return false; + } + }); + switch (item.getItemId()) { + case R.id.action_show_media_only: + TagTimeline tagTimeline = new TagTimeline(); + tagTimeline.setName(tag.trim()); + tagTimeline.setART(!finalMediaOnly); + tagTimeline.setNSFW(finalShowNSFW); + itemMediaOnly.setChecked(!finalMediaOnly); + new SearchDAO(BaseMainActivity.this, db).updateSearch(tagTimeline); + break; + case R.id.action_show_nsfw: + tagTimeline = new TagTimeline(); + tagTimeline.setName(tag.trim()); + tagTimeline.setART(finalMediaOnly); + tagTimeline.setNSFW(!finalShowNSFW); + itemShowNSFW.setChecked(!finalShowNSFW); + new SearchDAO(BaseMainActivity.this, db).updateSearch(tagTimeline); + break; + case R.id.action_delete: + AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(BaseMainActivity.this, style); + dialogBuilder.setPositiveButton(R.string.validate, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int id) { + new SearchDAO(BaseMainActivity.this, db).remove(tag); + String tag; + if( position > 0 && tabLayout.getTabAt(position - 1).getText() != null) { + tag = tabLayout.getTabAt(position - 1).getText().toString(); + }else if( tabLayout.getTabCount() > 1 && tabLayout.getTabAt(1).getText() != null) { + tag = tabLayout.getTabAt(1).getText().toString(); + }else //Last element + tag = ""; + Helper.removeTab(tabLayout, adapter, position); + adapter = new BaseMainActivity.PagerAdapter + (getSupportFragmentManager(), tabLayout.getTabCount()); + viewPager.setAdapter(adapter); + for(int i = 0; i < tabLayout.getTabCount() ; i++ ){ + if( tabLayout.getTabAt(i).getText() != null && tabLayout.getTabAt(i).getText().equals(tag.trim())){ + tabLayout.getTabAt(i).select(); + break; + } + + } + } + }); + dialogBuilder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int id) { + dialog.dismiss(); + } + }); + dialogBuilder.setMessage(getString(R.string.delete) + ": " + tag); + AlertDialog alertDialog = dialogBuilder.create(); + alertDialog.setOnDismissListener(new DialogInterface.OnDismissListener() { + @Override + public void onDismiss(DialogInterface dialogInterface) { + //Hide keyboard + InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); + assert imm != null; + imm.hideSoftInputFromWindow(viewPager.getWindowToken(), 0); + } + }); + if( alertDialog.getWindow() != null ) + alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE); + alertDialog.show(); + return false; } + return false; } }); - dialogBuilder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int id) { - dialog.dismiss(); - } - }); - dialogBuilder.setMessage(getString(R.string.delete) + ": " + title); - AlertDialog alertDialog = dialogBuilder.create(); - alertDialog.setOnDismissListener(new DialogInterface.OnDismissListener() { - @Override - public void onDismiss(DialogInterface dialogInterface) { - //Hide keyboard - InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); - assert imm != null; - imm.hideSoftInputFromWindow(viewPager.getWindowToken(), 0); - } - }); - if( alertDialog.getWindow() != null ) - alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE); - alertDialog.show(); + popup.show(); return false; } }); + } public void updateHomeCounter(){ diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/StatusListAdapter.java b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/StatusListAdapter.java index 8989616af..02077c162 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/StatusListAdapter.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/StatusListAdapter.java @@ -105,6 +105,7 @@ import fr.gouv.etalab.mastodon.client.Entities.Card; import fr.gouv.etalab.mastodon.client.Entities.Emojis; import fr.gouv.etalab.mastodon.client.Entities.Error; import fr.gouv.etalab.mastodon.client.Entities.Status; +import fr.gouv.etalab.mastodon.client.Entities.TagTimeline; import fr.gouv.etalab.mastodon.fragments.DisplayStatusFragment; import fr.gouv.etalab.mastodon.helper.CrossActions; import fr.gouv.etalab.mastodon.helper.CustomTextView; @@ -152,6 +153,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct private List timedMute; private boolean redraft; private Status toot; + private TagTimeline tagTimeline; public StatusListAdapter(Context context, RetrieveFeedsAsyncTask.Type type, String targetedId, boolean isOnWifi, int behaviorWithAttachments, int translator, List statuses){ super(); @@ -167,6 +169,21 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct redraft = false; } + public StatusListAdapter(Context context, TagTimeline tagTimeline, String targetedId, boolean isOnWifi, int behaviorWithAttachments, int translator, List statuses){ + super(); + this.context = context; + this.statuses = statuses; + this.isOnWifi = isOnWifi; + this.behaviorWithAttachments = behaviorWithAttachments; + layoutInflater = LayoutInflater.from(this.context); + statusListAdapter = this; + this.type = RetrieveFeedsAsyncTask.Type.TAG; + this.targetedId = targetedId; + this.translator = translator; + redraft = false; + this.tagTimeline = tagTimeline; + } + public StatusListAdapter(Context context, int position, String targetedId, boolean isOnWifi, int behaviorWithAttachments, int translator, List statuses){ this.context = context; this.statuses = statuses; @@ -221,7 +238,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct @Override public void onViewAttachedToWindow(@NonNull RecyclerView.ViewHolder holder) { super.onViewAttachedToWindow(holder); - if( type != RetrieveFeedsAsyncTask.Type.ART && (holder.getItemViewType() == DISPLAYED_STATUS || holder.getItemViewType() == COMPACT_STATUS)) { + if( type != RetrieveFeedsAsyncTask.Type.ART && (tagTimeline == null || !tagTimeline.isART()) && (holder.getItemViewType() == DISPLAYED_STATUS || holder.getItemViewType() == COMPACT_STATUS)) { final ViewHolder viewHolder = (ViewHolder) holder; // Bug workaround for losing text selection ability, see: // https://code.google.com/p/android/issues/detail?id=208169 @@ -426,7 +443,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct @NonNull @Override public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { - if( type == RetrieveFeedsAsyncTask.Type.ART) + if( type == RetrieveFeedsAsyncTask.Type.ART || (tagTimeline != null && tagTimeline.isART())) return new ViewHolderArt(layoutInflater.inflate(R.layout.drawer_art, parent, false)); else if( viewType == DISPLAYED_STATUS) return new ViewHolder(layoutInflater.inflate(R.layout.drawer_status, parent, false)); @@ -445,7 +462,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct public void onBindViewHolder(@NonNull final RecyclerView.ViewHolder viewHolder, int i) { final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); final String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null); - if( type == RetrieveFeedsAsyncTask.Type.ART) { + if( type == RetrieveFeedsAsyncTask.Type.ART || (tagTimeline != null && tagTimeline.isART())) { final ViewHolderArt holder = (ViewHolderArt) viewHolder; final Status status = statuses.get(viewHolder.getAdapterPosition()); 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 aeb041c2a..863b58997 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 @@ -52,6 +52,7 @@ import fr.gouv.etalab.mastodon.client.Entities.Conversation; import fr.gouv.etalab.mastodon.client.Entities.Peertube; import fr.gouv.etalab.mastodon.client.Entities.RemoteInstance; import fr.gouv.etalab.mastodon.client.Entities.Status; +import fr.gouv.etalab.mastodon.client.Entities.TagTimeline; import fr.gouv.etalab.mastodon.drawers.PeertubeAdapter; import fr.gouv.etalab.mastodon.drawers.StatusListAdapter; import fr.gouv.etalab.mastodon.helper.Helper; @@ -61,6 +62,7 @@ import fr.gouv.etalab.mastodon.services.StreamingFederatedTimelineService; import fr.gouv.etalab.mastodon.services.StreamingLocalTimelineService; import fr.gouv.etalab.mastodon.sqlite.AccountDAO; import fr.gouv.etalab.mastodon.sqlite.InstancesDAO; +import fr.gouv.etalab.mastodon.sqlite.SearchDAO; import fr.gouv.etalab.mastodon.sqlite.Sqlite; import fr.gouv.etalab.mastodon.sqlite.TempMuteDAO; @@ -100,6 +102,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn private String search_peertube, remote_channel_name; private String initialBookMark; private boolean fetchMoreButtonDisplayed; + private TagTimeline tagTimeline; public DisplayStatusFragment(){ } @@ -117,6 +120,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn fetchMoreButtonDisplayed = false; showPinned = false; showReply = false; + tagTimeline = null; if (bundle != null) { type = (RetrieveFeedsAsyncTask.Type) bundle.get("type"); targetedId = bundle.getString("targetedId", null); @@ -156,7 +160,15 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn Account account = new AccountDAO(context, db).getAccountByID(userId); mutedAccount = new TempMuteDAO(context, db).getAllTimeMuted(account); - if( search_peertube == null && (instanceType == null || instanceType.equals("MASTODON"))) { + if( type == RetrieveFeedsAsyncTask.Type.TAG && tag != null) { + BaseMainActivity.displayPeertube = null; + List tagTimelines = new SearchDAO(context, db).getTimelineInfo(tag); + if( tagTimelines != null && tagTimelines.size() > 0) { + tagTimeline = tagTimelines.get(0); + statusListAdapter = new StatusListAdapter(context, tagTimeline, targetedId, isOnWifi, behaviorWithAttachments, positionSpinnerTrans, this.statuses); + lv_status.setAdapter(statusListAdapter); + } + }else if( search_peertube == null && (instanceType == null || instanceType.equals("MASTODON"))) { BaseMainActivity.displayPeertube = null; statusListAdapter = new StatusListAdapter(context, type, targetedId, isOnWifi, behaviorWithAttachments, positionSpinnerTrans, this.statuses); lv_status.setAdapter(statusListAdapter); @@ -474,8 +486,18 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn } }else { - this.statuses.addAll(statuses); - statusListAdapter.notifyItemRangeInserted(previousPosition, statuses.size()); + if( tagTimeline == null || !tagTimeline.isART() || (tagTimeline.isART() && tagTimeline.isNSFW())) { + this.statuses.addAll(statuses); + statusListAdapter.notifyItemRangeInserted(previousPosition, statuses.size()); + }else { //If it's an Art timeline not allowing NSFW + ArrayList safeStatuses = new ArrayList<>(); + for(Status status: statuses){ + if( !status.isSensitive()) + safeStatuses.add(status); + } + this.statuses.addAll(safeStatuses); + statusListAdapter.notifyItemRangeInserted(previousPosition, safeStatuses.size()); + } } if( type == RetrieveFeedsAsyncTask.Type.HOME ) { //Update the id of the last toot retrieved diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java b/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java index 200da9ea0..2f312cdfa 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java @@ -2574,6 +2574,7 @@ public class Helper { } + public static void refreshSearchTag(Context context, TabLayout tableLayout, BaseMainActivity.PagerAdapter pagerAdapter){ SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open(); List searches = new SearchDAO(context, db).getAllSearch(); @@ -2618,6 +2619,8 @@ public class Helper { } + + public static void removeSearchTag(String keyword, TabLayout tableLayout, BaseMainActivity.PagerAdapter pagerAdapter){ int selection = -1; @@ -3036,7 +3039,7 @@ public class Helper { } } - public static RetrieveFeedsAsyncTask.Type timelineType(Context context, int position){ + public static RetrieveFeedsAsyncTask.Type timelineType(Context context, int position, int pageCount){ SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE); boolean display_direct = sharedpreferences.getBoolean(Helper.SET_DISPLAY_DIRECT, true); boolean display_local = sharedpreferences.getBoolean(Helper.SET_DISPLAY_LOCAL, true); @@ -3044,7 +3047,7 @@ public class Helper { boolean display_art = sharedpreferences.getBoolean(Helper.SET_DISPLAY_ART, true); if (position == 0) { return RetrieveFeedsAsyncTask.Type.HOME; - }else if(position == 2) { + }else if(position == 2 && pageCount > 2) { if( display_direct) { String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null); String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, Helper.getLiveInstance(context)); @@ -3071,19 +3074,19 @@ public class Helper { return RetrieveFeedsAsyncTask.Type.PUBLIC; if( display_art) return RetrieveFeedsAsyncTask.Type.ART; - }else if( position == 3){ + }else if( position == 3 && pageCount > 3){ if( display_direct && display_local) return RetrieveFeedsAsyncTask.Type.LOCAL; if( display_global) return RetrieveFeedsAsyncTask.Type.PUBLIC; if( display_art) return RetrieveFeedsAsyncTask.Type.ART; - }else if (position == 4){ + }else if (position == 4 && pageCount > 4){ if( display_direct && display_local && display_global) return RetrieveFeedsAsyncTask.Type.PUBLIC; if( display_art) return RetrieveFeedsAsyncTask.Type.ART; - }else if (position == 5){ + }else if (position == 5 && pageCount > 5){ if( display_direct && display_local && display_global && display_art) return RetrieveFeedsAsyncTask.Type.ART; } 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 0bf333b5a..15dae6751 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 @@ -66,6 +66,23 @@ public class SearchDAO { } + //------- UPDATES ------- + + /** + * update tag timeline info in database + * @param tagTimeline TagTimeline + */ + public void updateSearch(TagTimeline tagTimeline) { + ContentValues values = new ContentValues(); + values.put(Sqlite.COL_IS_ART, tagTimeline.isART()?1:0); + values.put(Sqlite.COL_IS_NSFW, tagTimeline.isNSFW()?1:0); + //Inserts search + try{ + db.update(Sqlite.TABLE_SEARCH, values, Sqlite.COL_USER_ID + " = ? AND " + Sqlite.COL_KEYWORDS + " = ?", new String[]{userId, tagTimeline.getName()}); + }catch (Exception ignored) {} + } + + //------- REMOVE ------- /*** diff --git a/app/src/main/res/menu/option_tag_timeline.xml b/app/src/main/res/menu/option_tag_timeline.xml new file mode 100644 index 000000000..ef878cab6 --- /dev/null +++ b/app/src/main/res/menu/option_tag_timeline.xml @@ -0,0 +1,22 @@ + + + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d3dbf11ef..43d2e3e50 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -760,6 +760,8 @@ Српски Українська Русский + Media only + Show NSFW \ No newline at end of file