summaryrefslogtreecommitdiffstats
path: root/app/src/main/java/fr/gouv/etalab
diff options
context:
space:
mode:
authorstom79 <tschneider.ac@gmail.com>2018-12-15 17:13:06 +0100
committerstom79 <tschneider.ac@gmail.com>2018-12-15 17:13:06 +0100
commitcf1dc7518c4988ab54b78ef3d78741e53cc2de5f (patch)
treea43d0a81ac7255dd28c2d8d788a759539ff20641 /app/src/main/java/fr/gouv/etalab
parentdd7695f1c1f679bb28d3f6ac395af1995adf2227 (diff)
Change frontend
Diffstat (limited to 'app/src/main/java/fr/gouv/etalab')
-rw-r--r--app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseMainActivity.java262
-rw-r--r--app/src/main/java/fr/gouv/etalab/mastodon/drawers/StatusListAdapter.java23
-rw-r--r--app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayStatusFragment.java28
-rw-r--r--app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java13
-rw-r--r--app/src/main/java/fr/gouv/etalab/mastodon/sqlite/SearchDAO.java17
5 files changed, 221 insertions, 122 deletions
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<Integer> stackBack = new Stack<>();
public static List<Filters> 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,39 +829,30 @@ public abstract class BaseMainActivity extends BaseActivity
}
});
- if( tabStrip.getChildCount() > 2 && !display_direct)
- tabStrip.getChildAt(2).setOnLongClickListener(new View.OnLongClickListener() {
+ countPage = 2;
+ if( sharedpreferences.getBoolean(Helper.SET_DISPLAY_DIRECT, true))
+ countPage++;
+ if( sharedpreferences.getBoolean(Helper.SET_DISPLAY_LOCAL, true))
+ countPage++;
+ if( sharedpreferences.getBoolean(Helper.SET_DISPLAY_GLOBAL, true))
+ countPage++;
+ 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);
}
});
- else if ( tabStrip.getChildCount() > 3 && display_direct)
- tabStrip.getChildAt(3).setOnLongClickListener(new View.OnLongClickListener() {
+ if( tabPosition.containsKey("local"))
+ tabStrip.getChildAt(tabPosition.get("local")).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++;
- if( sharedpreferences.getBoolean(Helper.SET_DISPLAY_LOCAL, true))
- countPage++;
- if( sharedpreferences.getBoolean(Helper.SET_DISPLAY_GLOBAL, true))
- countPage++;
- if( sharedpreferences.getBoolean(Helper.SET_DISPLAY_ART, true))
- countPage++;
viewPager.setOffscreenPageLimit(countPage);
main_app_container = findViewById(R.id.main_app_container);
@@ -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<String, DisplayStatusFragment> 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<TagTimeline> 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<String> 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<Status> 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<Status> 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<Status> 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<TagTimeline> 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<Status> 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<String> 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 -------
/***