From cfa6a1108eb09c7b6baa4910418cd470fe713934 Mon Sep 17 00:00:00 2001 From: stom79 Date: Wed, 28 Nov 2018 11:24:59 +0100 Subject: [PATCH] Improve hide long toots --- .../mastodon/drawers/StatusListAdapter.java | 27 ++++++++++++----- .../mastodon/fragments/SettingsFragment.java | 21 +++++++++----- .../gouv/etalab/mastodon/helper/Helper.java | 2 +- .../res/layout-sw600dp/fragment_settings.xml | 29 ++++++++++++++++--- app/src/main/res/layout/drawer_status.xml | 7 +++-- .../main/res/layout/drawer_status_compact.xml | 6 ++-- .../main/res/layout/drawer_status_focused.xml | 7 +++-- app/src/main/res/layout/fragment_settings.xml | 29 ++++++++++++++++--- app/src/main/res/values/strings.xml | 3 ++ 9 files changed, 99 insertions(+), 32 deletions(-) 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 78f6e7af5..46550002a 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 @@ -717,23 +717,36 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct }); } holder.status_content.setText(status.getContentSpan(), TextView.BufferType.SPANNABLE); - boolean truncate_toots = sharedpreferences.getBoolean(Helper.SET_TRUNCATE_TOOTS, false); - if( truncate_toots) { + int truncate_toots_size = sharedpreferences.getInt(Helper.SET_TRUNCATE_TOOTS_SIZE, 0); + if( truncate_toots_size > 0) { + holder.status_content.setMaxLines(truncate_toots_size); if (status.getNumberLines() == -1) { - status.setNumberLines(holder.status_content.getLineCount()); + status.setNumberLines(-2); + holder.status_show_more_content.setVisibility(View.GONE); + holder.status_content.post(new Runnable() { + @Override + public void run() { + status.setNumberLines(holder.status_content.getLineCount()); + if( status.getNumberLines() > truncate_toots_size) { + notifyStatusChanged(status); + } + } + }); } - if (status.getNumberLines() > 10) { + else if (status.getNumberLines() > truncate_toots_size) { holder.status_show_more_content.setVisibility(View.VISIBLE); if (status.isExpanded()) { holder.status_content.setMaxLines(Integer.MAX_VALUE); - holder.status_show_more_content.setText(R.string.load_attachment_spoiler_less); + holder.status_show_more_content.setText(R.string.hide_toot_truncate); } else { - holder.status_content.setMaxLines(10); - holder.status_show_more_content.setText(R.string.load_attachment_spoiler); + holder.status_content.setMaxLines(truncate_toots_size); + holder.status_show_more_content.setText(R.string.display_toot_truncate); } } else { holder.status_show_more_content.setVisibility(View.GONE); } + }else{ + holder.status_show_more_content.setVisibility(View.GONE); } holder.status_show_more_content.setOnClickListener(new View.OnClickListener() { @Override 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 56a276df2..bfae89d3c 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 @@ -262,15 +262,22 @@ public class SettingsFragment extends Fragment { } }); - boolean truncate_toots = sharedpreferences.getBoolean(Helper.SET_TRUNCATE_TOOTS, false); - final CheckBox set_truncate_toots = rootView.findViewById(R.id.set_truncate_toots); - set_truncate_toots.setChecked(truncate_toots); - - set_truncate_toots.setOnClickListener(new View.OnClickListener() { + int truncate_toots_size = sharedpreferences.getInt(Helper.SET_TRUNCATE_TOOTS_SIZE, 0); + SeekBar set_truncate_size = rootView.findViewById(R.id.set_truncate_size); + set_truncate_size.setMax(20); + set_truncate_size.setProgress(truncate_toots_size); + TextView set_truncate_toots = rootView.findViewById(R.id.set_truncate_toots); + set_truncate_toots.setText(String.valueOf(truncate_toots_size)); + set_truncate_size.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override - public void onClick(View v) { + public void onStopTrackingTouch(SeekBar seekBar) {} + @Override + public void onStartTrackingTouch(SeekBar seekBar) {} + @Override + public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { + set_truncate_toots.setText(String.valueOf(progress)); SharedPreferences.Editor editor = sharedpreferences.edit(); - editor.putBoolean(Helper.SET_TRUNCATE_TOOTS, set_truncate_toots.isChecked()); + editor.putInt(Helper.SET_TRUNCATE_TOOTS_SIZE, progress); editor.apply(); } }); 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 cff09c323..209dcc756 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 @@ -338,7 +338,7 @@ public class Helper { public static final String SET_DISPLAY_GLOBAL = "set_display_global"; public static final String SET_AUTOMATICALLY_SPLIT_TOOTS = "set_automatically_split_toots"; public static final String SET_AUTOMATICALLY_SPLIT_TOOTS_SIZE = "set_automatically_split_toots_size"; - public static final String SET_TRUNCATE_TOOTS = "set_truncate_toots"; + public static final String SET_TRUNCATE_TOOTS_SIZE = "set_truncate_toots_size"; //End points public static final String EP_AUTHORIZE = "/oauth/authorize"; diff --git a/app/src/main/res/layout-sw600dp/fragment_settings.xml b/app/src/main/res/layout-sw600dp/fragment_settings.xml index 1f139f703..8329cf86f 100644 --- a/app/src/main/res/layout-sw600dp/fragment_settings.xml +++ b/app/src/main/res/layout-sw600dp/fragment_settings.xml @@ -187,11 +187,32 @@ android:layout_height="wrap_content" /> - + android:layout_height="wrap_content" + android:gravity="center_vertical" + android:text="@string/set_truncate_toot"/> + + + + +