feat(search): show suicide help dialog (#767)
* feat(search): show suicide help dialog * change wording, add helpline url, change behavior --------- Co-authored-by: sk <sk22@mailbox.org>
This commit is contained in:
@@ -60,6 +60,7 @@ public class GlobalUserPreferences{
|
|||||||
public static boolean showNavigationLabels;
|
public static boolean showNavigationLabels;
|
||||||
public static boolean displayPronounsInTimelines, displayPronounsInThreads, displayPronounsInUserListings;
|
public static boolean displayPronounsInTimelines, displayPronounsInThreads, displayPronounsInUserListings;
|
||||||
public static boolean overlayMedia;
|
public static boolean overlayMedia;
|
||||||
|
public static boolean showSuicideHelp;
|
||||||
|
|
||||||
private static SharedPreferences getPrefs(){
|
private static SharedPreferences getPrefs(){
|
||||||
return MastodonApp.context.getSharedPreferences("global", Context.MODE_PRIVATE);
|
return MastodonApp.context.getSharedPreferences("global", Context.MODE_PRIVATE);
|
||||||
@@ -119,6 +120,7 @@ public class GlobalUserPreferences{
|
|||||||
displayPronounsInThreads=prefs.getBoolean("displayPronounsInThreads", true);
|
displayPronounsInThreads=prefs.getBoolean("displayPronounsInThreads", true);
|
||||||
displayPronounsInUserListings=prefs.getBoolean("displayPronounsInUserListings", true);
|
displayPronounsInUserListings=prefs.getBoolean("displayPronounsInUserListings", true);
|
||||||
overlayMedia=prefs.getBoolean("overlayMedia", false);
|
overlayMedia=prefs.getBoolean("overlayMedia", false);
|
||||||
|
showSuicideHelp=prefs.getBoolean("showSuicideHelp", true);
|
||||||
|
|
||||||
if (prefs.contains("prefixRepliesWithRe")) {
|
if (prefs.contains("prefixRepliesWithRe")) {
|
||||||
prefixReplies = prefs.getBoolean("prefixRepliesWithRe", false)
|
prefixReplies = prefs.getBoolean("prefixRepliesWithRe", false)
|
||||||
@@ -177,6 +179,7 @@ public class GlobalUserPreferences{
|
|||||||
.putBoolean("displayPronounsInThreads", displayPronounsInThreads)
|
.putBoolean("displayPronounsInThreads", displayPronounsInThreads)
|
||||||
.putBoolean("displayPronounsInUserListings", displayPronounsInUserListings)
|
.putBoolean("displayPronounsInUserListings", displayPronounsInUserListings)
|
||||||
.putBoolean("overlayMedia", overlayMedia)
|
.putBoolean("overlayMedia", overlayMedia)
|
||||||
|
.putBoolean("showSuicideHelp", showSuicideHelp)
|
||||||
.apply();
|
.apply();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import android.graphics.Outline;
|
|||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.graphics.drawable.LayerDrawable;
|
import android.graphics.drawable.LayerDrawable;
|
||||||
import android.net.Uri;
|
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
@@ -26,7 +25,7 @@ import android.widget.TextView;
|
|||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
import android.widget.Toolbar;
|
import android.widget.Toolbar;
|
||||||
|
|
||||||
import org.joinmastodon.android.MainActivity;
|
import org.joinmastodon.android.GlobalUserPreferences;
|
||||||
import org.joinmastodon.android.R;
|
import org.joinmastodon.android.R;
|
||||||
import org.joinmastodon.android.api.requests.search.GetSearchResults;
|
import org.joinmastodon.android.api.requests.search.GetSearchResults;
|
||||||
import org.joinmastodon.android.api.session.AccountSessionManager;
|
import org.joinmastodon.android.api.session.AccountSessionManager;
|
||||||
@@ -38,19 +37,16 @@ import org.joinmastodon.android.model.SearchResults;
|
|||||||
import org.joinmastodon.android.model.viewmodel.ListItem;
|
import org.joinmastodon.android.model.viewmodel.ListItem;
|
||||||
import org.joinmastodon.android.model.viewmodel.SearchResultViewModel;
|
import org.joinmastodon.android.model.viewmodel.SearchResultViewModel;
|
||||||
import org.joinmastodon.android.ui.DividerItemDecoration;
|
import org.joinmastodon.android.ui.DividerItemDecoration;
|
||||||
|
import org.joinmastodon.android.ui.M3AlertDialogBuilder;
|
||||||
import org.joinmastodon.android.ui.SearchViewHelper;
|
import org.joinmastodon.android.ui.SearchViewHelper;
|
||||||
import org.joinmastodon.android.ui.adapters.GenericListItemsAdapter;
|
import org.joinmastodon.android.ui.adapters.GenericListItemsAdapter;
|
||||||
import org.joinmastodon.android.ui.utils.HideableSingleViewRecyclerAdapter;
|
import org.joinmastodon.android.ui.utils.HideableSingleViewRecyclerAdapter;
|
||||||
import org.joinmastodon.android.ui.utils.UiUtils;
|
import org.joinmastodon.android.ui.utils.UiUtils;
|
||||||
import org.joinmastodon.android.ui.viewholders.AccountViewHolder;
|
import org.joinmastodon.android.ui.viewholders.AccountViewHolder;
|
||||||
import org.joinmastodon.android.ui.viewholders.SimpleListItemViewHolder;
|
import org.joinmastodon.android.ui.viewholders.SimpleListItemViewHolder;
|
||||||
import org.parceler.Parcels;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
|
||||||
import java.util.function.BiConsumer;
|
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
@@ -381,16 +377,54 @@ public class SearchQueryFragment extends MastodonRecyclerFragment<SearchResultVi
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void openHashtag(SearchResult res){
|
private void openHashtag(SearchResult res){
|
||||||
|
wrapSuicideDialog(()->{
|
||||||
UiUtils.openHashtagTimeline(getActivity(), accountID, res.hashtag.name, res.hashtag.following);
|
UiUtils.openHashtagTimeline(getActivity(), accountID, res.hashtag.name, res.hashtag.following);
|
||||||
AccountSessionManager.getInstance().getAccount(accountID).getCacheController().putRecentSearch(res);
|
AccountSessionManager.getInstance().getAccount(accountID).getCacheController().putRecentSearch(res);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isInRecentMode(){
|
private boolean isInRecentMode(){
|
||||||
return TextUtils.isEmpty(currentQuery);
|
return TextUtils.isEmpty(currentQuery);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void wrapSuicideDialog(Runnable r){
|
||||||
|
if(!GlobalUserPreferences.showSuicideHelp){
|
||||||
|
r.run();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String[] terms=getContext().getString(R.string.sk_suicide_search_terms).toLowerCase().split(",");
|
||||||
|
String query=currentQuery.trim().toLowerCase();
|
||||||
|
boolean termMatches=false;
|
||||||
|
for(String term : terms){
|
||||||
|
if(query.contains(term)){
|
||||||
|
termMatches=true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!termMatches){
|
||||||
|
r.run();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String url=getContext().getString(R.string.sk_suicide_helplines_url);
|
||||||
|
new M3AlertDialogBuilder(getActivity())
|
||||||
|
.setTitle(R.string.sk_search_suicide_title)
|
||||||
|
.setMessage(R.string.sk_search_suicide_message)
|
||||||
|
.setNegativeButton(R.string.sk_do_not_show_again, (dialog, which)->{
|
||||||
|
GlobalUserPreferences.showSuicideHelp = false;
|
||||||
|
GlobalUserPreferences.save();
|
||||||
|
r.run();
|
||||||
|
})
|
||||||
|
.setNeutralButton(R.string.sk_search_suicide_hotlines, (dialog, which)->UiUtils.launchWebBrowser(getContext(), url))
|
||||||
|
.setPositiveButton(R.string.ok, (dialog, which)->r.run())
|
||||||
|
.setOnDismissListener((dialog)->{})
|
||||||
|
.show();
|
||||||
|
}
|
||||||
|
|
||||||
private void onSearchViewEnter(){
|
private void onSearchViewEnter(){
|
||||||
deliverResult(currentQuery, null);
|
wrapSuicideDialog(()->deliverResult(currentQuery, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onOpenURLClick(){
|
private void onOpenURLClick(){
|
||||||
@@ -398,10 +432,12 @@ public class SearchQueryFragment extends MastodonRecyclerFragment<SearchResultVi
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void onGoToHashtagClick(){
|
private void onGoToHashtagClick(){
|
||||||
|
wrapSuicideDialog(()->{
|
||||||
String q=searchViewHelper.getQuery();
|
String q=searchViewHelper.getQuery();
|
||||||
if(q.startsWith("#"))
|
if(q.startsWith("#"))
|
||||||
q=q.substring(1);
|
q=q.substring(1);
|
||||||
UiUtils.openHashtagTimeline(getActivity(), accountID, q, null);
|
UiUtils.openHashtagTimeline(getActivity(), accountID, q, null);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onGoToAccountClick(){
|
private void onGoToAccountClick(){
|
||||||
@@ -422,11 +458,11 @@ public class SearchQueryFragment extends MastodonRecyclerFragment<SearchResultVi
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void onGoToStatusSearchClick(){
|
private void onGoToStatusSearchClick(){
|
||||||
deliverResult(searchViewHelper.getQuery(), SearchResult.Type.STATUS);
|
wrapSuicideDialog(()->deliverResult(searchViewHelper.getQuery(), SearchResult.Type.STATUS));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onGoToAccountSearchClick(){
|
private void onGoToAccountSearchClick(){
|
||||||
deliverResult(searchViewHelper.getQuery(), SearchResult.Type.ACCOUNT);
|
wrapSuicideDialog(()->deliverResult(searchViewHelper.getQuery(), SearchResult.Type.ACCOUNT));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onClearRecentClick(){
|
private void onClearRecentClick(){
|
||||||
|
|||||||
@@ -374,6 +374,12 @@
|
|||||||
<string name="sk_duration_days_3">3 days</string>
|
<string name="sk_duration_days_3">3 days</string>
|
||||||
<string name="sk_duration_days_7">7 days</string>
|
<string name="sk_duration_days_7">7 days</string>
|
||||||
<string name="sk_notification_mention">You were mentioned by %s</string>
|
<string name="sk_notification_mention">You were mentioned by %s</string>
|
||||||
|
<string name="sk_suicide_search_terms">Suicide</string>
|
||||||
|
<string name="sk_search_suicide_title">In case you’re in distress…</string>
|
||||||
|
<string name="sk_search_suicide_message">If you’re looking for a sign not to commit suicide, this is it. Please consider reaching out to a local suicide hotline if you’re in distress.</string>
|
||||||
|
<string name="sk_search_suicide_hotlines">Find a helpline</string>
|
||||||
|
<string name="sk_do_not_show_again">Don’t show again</string>
|
||||||
|
<string name="sk_suicide_helplines_url">https://findahelpline.com</string>
|
||||||
<plurals name="sk_posts_count_label">
|
<plurals name="sk_posts_count_label">
|
||||||
<item quantity="one">post</item>
|
<item quantity="one">post</item>
|
||||||
<item quantity="other">posts</item>
|
<item quantity="other">posts</item>
|
||||||
|
|||||||
Reference in New Issue
Block a user