First pass at user-configurable NSFW Timeout.

This commit is contained in:
PhotonQyv 2017-08-07 00:53:33 +01:00
parent a648a26894
commit d3f79b94fe
6 changed files with 71 additions and 17 deletions

View File

@ -509,24 +509,27 @@ public class StatusListAdapter extends BaseAdapter implements OnPostActionInterf
/*
Added a Countdown Timer, so that Sensitive (NSFW)
images only get displayed for 5 seconds, giving
the user time to click on them to expand them, if
they want. Images are then hidden again.
images only get displayed for user set time,
giving the user time to click on them to expand them,
if they want. Images are then hidden again.
*/
final int timeout = 5;
final int timeout = sharedpreferences.getInt(Helper.SET_NSFW_TIMEOUT, 0);
new CountDownTimer((timeout * 1000), 1000){
if (timeout > 0) {
public void onTick(long millisUntilFinished) { }
new CountDownTimer((timeout * 1000), 1000) {
public void onFinish(){
public void onTick(long millisUntilFinished) {
}
status.setAttachmentShown(false);
holder.status_show_more.setVisibility(View.VISIBLE);
public void onFinish() {
status.setAttachmentShown(false);
holder.status_show_more.setVisibility(View.VISIBLE);
statusListAdapter.notifyDataSetChanged();
}
}.start();
statusListAdapter.notifyDataSetChanged();
}
}.start();
}
}
});

View File

@ -13,6 +13,7 @@ package fr.gouv.etalab.mastodon.fragments;
*
* You should have received a copy of the GNU General Public License along with Mastalab; if not,
* see <http://www.gnu.org/licenses>. */
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.content.ContentUris;
@ -28,13 +29,13 @@ import android.provider.DocumentsContract;
import android.provider.MediaStore;
import android.support.v4.app.Fragment;
import android.support.v7.widget.SwitchCompat;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.LinearLayout;
import android.widget.SeekBar;
import android.widget.TextView;
import fr.gouv.etalab.mastodon.activities.MainActivity;
@ -43,7 +44,6 @@ import mastodon.etalab.gouv.fr.mastodon.R;
import static android.app.Activity.RESULT_OK;
import static fr.gouv.etalab.mastodon.helper.Helper.CHANGE_THEME_INTENT;
import static fr.gouv.etalab.mastodon.helper.Helper.HOME_TIMELINE_INTENT;
import static fr.gouv.etalab.mastodon.helper.Helper.INTENT_ACTION;
@ -213,6 +213,33 @@ public class SettingsFragment extends Fragment {
}
});
// NSFW Timeout
SeekBar nsfwTimeoutSeekBar = (SeekBar) rootView.findViewById(R.id.set_nsfw_timeout);
final TextView set_nsfw_timeout_value = (TextView) rootView.findViewById(R.id.set_nsfw_timeout_value);
nsfwTimeoutSeekBar.setMax(30);
int nsfwTimeout = sharedpreferences.getInt(Helper.SET_NSFW_TIMEOUT, 5);
nsfwTimeoutSeekBar.setProgress(nsfwTimeout);
set_nsfw_timeout_value.setText(String.valueOf(nsfwTimeout));
nsfwTimeoutSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onStopTrackingTouch(SeekBar seekBar) {}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {}
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
set_nsfw_timeout_value.setText(String.valueOf(progress));
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putInt(Helper.SET_NSFW_TIMEOUT, progress);
editor.apply();
}
});
return rootView;
}

View File

@ -52,8 +52,6 @@ import android.text.Html;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.TextPaint;
import android.text.method.ArrowKeyMovementMethod;
import android.text.method.LinkMovementMethod;
import android.text.style.ClickableSpan;
import android.util.DisplayMetrics;
import android.util.Patterns;
@ -115,6 +113,7 @@ import fr.gouv.etalab.mastodon.activities.ShowAccountActivity;
import fr.gouv.etalab.mastodon.activities.TootActivity;
import fr.gouv.etalab.mastodon.activities.WebviewActivity;
import fr.gouv.etalab.mastodon.asynctasks.RemoveAccountAsyncTask;
import fr.gouv.etalab.mastodon.client.API;
import fr.gouv.etalab.mastodon.client.Entities.Account;
import fr.gouv.etalab.mastodon.client.Entities.Mention;
import fr.gouv.etalab.mastodon.client.Entities.Status;
@ -122,7 +121,6 @@ import fr.gouv.etalab.mastodon.client.PatchBaseImageDownloader;
import fr.gouv.etalab.mastodon.sqlite.AccountDAO;
import fr.gouv.etalab.mastodon.sqlite.Sqlite;
import mastodon.etalab.gouv.fr.mastodon.R;
import fr.gouv.etalab.mastodon.client.API;
import static android.app.Notification.DEFAULT_SOUND;
import static android.app.Notification.DEFAULT_VIBRATE;
@ -185,6 +183,7 @@ public class Helper {
public static final String SET_TIME_TO = "set_time_to";
public static final String SET_AUTO_STORE = "set_auto_store";
public static final String SET_POPUP_PUSH = "set_popup_push";
public static final String SET_NSFW_TIMEOUT = "set_nsfw_timeout";
public static final int ATTACHMENT_ALWAYS = 1;
public static final int ATTACHMENT_WIFI = 2;
public static final int ATTACHMENT_ASK = 3;

View File

@ -166,6 +166,29 @@
android:layout_height="wrap_content"
/>
</LinearLayout>
<!-- NSFW Timeout -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text="@string/set_nsfw_timeout"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_gravity="center_vertical"
android:layout_height="wrap_content">
<TextView
android:id="@+id/set_nsfw_timeout_value"
android:layout_gravity="center"
android:layout_width="50dp"
android:layout_height="wrap_content" />
<SeekBar
android:layout_gravity="center_vertical"
android:id="@+id/set_nsfw_timeout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</SeekBar>
</LinearLayout>
</LinearLayout>
</ScrollView>

View File

@ -279,6 +279,7 @@
<string name="set_wifi_only">Notifier en WIFI seulement</string>
<string name="set_notif_silent">Utiliser le vibreur</string>
<string name="set_night_mode">Mode nuit</string>
<string name="set_nsfw_timeout">NSFW view timeout (seconds, 0 means off)</string>
<string name="settings_title_profile">Modifier le profil</string>
<string name="set_profile_description">Présentation…</string>
<string name="set_save_changes">Enregistrer les modifications</string>

View File

@ -285,6 +285,7 @@
<string name="set_wifi_only">Notify in WIFI only</string>
<string name="set_notif_silent">Silent Notifications</string>
<string name="set_night_mode">Night mode</string>
<string name="set_nsfw_timeout">NSFW view timeout (seconds, 0 means off)</string>
<string name="settings_title_profile">Edit profile</string>
<string name="set_profile_description">Bio…</string>
<string name="set_save_changes">Save changes</string>