Show a suicide prevention quote when searching suicide.

This commit is contained in:
Alex Ning 2021-03-07 00:05:09 +08:00
parent a03cdfe814
commit 31f4739a17
12 changed files with 207 additions and 31 deletions

View File

@ -32,11 +32,16 @@
android:theme="@style/AppTheme"
android:usesCleartextTraffic="true"
tools:replace="android:label">
<activity android:name=".activities.MultiredditSelectionActivity"
<activity android:name=".activities.SuicidePreventionActivity"
android:parentActivityName=".activities.MainActivity"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".activities.MultiredditSelectionActivity"
android:label="@string/multireddit_selection_activity_label"
android:parentActivityName=".activities.MainActivity"
android:theme="@style/AppTheme.NoActionBar"/>
<activity android:name=".activities.SearchUsersResultActivity"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".activities.SearchUsersResultActivity"
android:label="@string/search_users_result_activity_label"
android:parentActivityName=".activities.MainActivity"
android:theme="@style/AppTheme.NoActionBar" />

View File

@ -43,6 +43,7 @@ import ml.docilealligator.infinityforreddit.activities.SubmitCrosspostActivity;
import ml.docilealligator.infinityforreddit.activities.SubredditMultiselectionActivity;
import ml.docilealligator.infinityforreddit.activities.SubredditSelectionActivity;
import ml.docilealligator.infinityforreddit.activities.SubscribedThingListingActivity;
import ml.docilealligator.infinityforreddit.activities.SuicidePreventionActivity;
import ml.docilealligator.infinityforreddit.activities.ViewImageOrGifActivity;
import ml.docilealligator.infinityforreddit.activities.ViewImgurMediaActivity;
import ml.docilealligator.infinityforreddit.activities.ViewMultiRedditDetailActivity;
@ -251,4 +252,6 @@ public interface AppComponent {
void inject(ViewRedditGalleryImageOrGifFragment viewRedditGalleryImageOrGifFragment);
void inject(ViewPostDetailFragment viewPostDetailFragment);
void inject(SuicidePreventionActivity suicidePreventionActivity);
}

View File

@ -6,18 +6,16 @@ import android.os.Bundle;
import android.widget.RelativeLayout;
import android.widget.Toast;
import com.airbnb.lottie.LottieAnimationView;
import javax.inject.Inject;
import javax.inject.Named;
import butterknife.BindView;
import butterknife.ButterKnife;
import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.bottomsheetfragments.RandomBottomSheetFragment;
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.post.FetchPost;
import ml.docilealligator.infinityforreddit.R;
import retrofit2.Retrofit;
public class FetchRandomSubredditOrPostActivity extends BaseActivity {
@ -26,8 +24,6 @@ public class FetchRandomSubredditOrPostActivity extends BaseActivity {
@BindView(R.id.relative_layout_fetch_random_subreddit_or_post_activity)
RelativeLayout relativeLayout;
@BindView(R.id.lottie_animation_view_fetch_random_subreddit_or_post_activity)
LottieAnimationView lottieAnimationView;
@Inject
@Named("no_oauth")
Retrofit mRetrofit;

View File

@ -249,28 +249,33 @@ public class SearchActivity extends BaseActivity {
}
private void search(String query) {
if (searchOnlySubreddits) {
Intent intent = new Intent(SearchActivity.this, SearchSubredditsResultActivity.class);
intent.putExtra(SearchSubredditsResultActivity.EXTRA_QUERY, query);
intent.putExtra(SearchSubredditsResultActivity.EXTRA_IS_MULTI_SELECTION, getIntent().getBooleanExtra(EXTRA_IS_MULTI_SELECTION, false));
startActivityForResult(intent, SUBREDDIT_SEARCH_REQUEST_CODE);
} else if (searchOnlyUsers) {
Intent intent = new Intent(this, SearchUsersResultActivity.class);
intent.putExtra(SearchUsersResultActivity.EXTRA_QUERY, query);
intent.putExtra(SearchUsersResultActivity.EXTRA_IS_MULTI_SELECTION, getIntent().getBooleanExtra(EXTRA_IS_MULTI_SELECTION, false));
startActivityForResult(intent, USER_SEARCH_REQUEST_CODE);
} else {
Intent intent = new Intent(SearchActivity.this, SearchResultActivity.class);
intent.putExtra(SearchResultActivity.EXTRA_QUERY, query);
if (subredditName != null) {
if (subredditIsUser) {
intent.putExtra(SearchResultActivity.EXTRA_SUBREDDIT_NAME, "u_" + subredditName);
} else {
intent.putExtra(SearchResultActivity.EXTRA_SUBREDDIT_NAME, subredditName);
}
}
if (query.equalsIgnoreCase("suicide") && mSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_SUICIDE_PREVENTION_ACTIVITY, true)) {
Intent intent = new Intent(this, SuicidePreventionActivity.class);
startActivity(intent);
finish();
} else {
if (searchOnlySubreddits) {
Intent intent = new Intent(SearchActivity.this, SearchSubredditsResultActivity.class);
intent.putExtra(SearchSubredditsResultActivity.EXTRA_QUERY, query);
intent.putExtra(SearchSubredditsResultActivity.EXTRA_IS_MULTI_SELECTION, getIntent().getBooleanExtra(EXTRA_IS_MULTI_SELECTION, false));
startActivityForResult(intent, SUBREDDIT_SEARCH_REQUEST_CODE);
} else if (searchOnlyUsers) {
Intent intent = new Intent(this, SearchUsersResultActivity.class);
intent.putExtra(SearchUsersResultActivity.EXTRA_QUERY, query);
intent.putExtra(SearchUsersResultActivity.EXTRA_IS_MULTI_SELECTION, getIntent().getBooleanExtra(EXTRA_IS_MULTI_SELECTION, false));
startActivityForResult(intent, USER_SEARCH_REQUEST_CODE);
} else {
Intent intent = new Intent(SearchActivity.this, SearchResultActivity.class);
intent.putExtra(SearchResultActivity.EXTRA_QUERY, query);
if (subredditName != null) {
if (subredditIsUser) {
intent.putExtra(SearchResultActivity.EXTRA_SUBREDDIT_NAME, "u_" + subredditName);
} else {
intent.putExtra(SearchResultActivity.EXTRA_SUBREDDIT_NAME, subredditName);
}
}
startActivity(intent);
finish();
}
}
}

View File

@ -0,0 +1,82 @@
package ml.docilealligator.infinityforreddit.activities;
import android.content.SharedPreferences;
import android.content.res.ColorStateList;
import android.os.Bundle;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.google.android.material.button.MaterialButton;
import com.google.android.material.checkbox.MaterialCheckBox;
import javax.inject.Inject;
import javax.inject.Named;
import butterknife.BindView;
import butterknife.ButterKnife;
import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
public class SuicidePreventionActivity extends BaseActivity {
@BindView(R.id.linear_layout_suicide_prevention_activity)
LinearLayout linearLayout;
@BindView(R.id.quote_text_view_suicide_prevention_activity)
TextView quoteTextView;
@BindView(R.id.linear_layout_check_box_wrapper_suicide_prevention_activity)
LinearLayout checkBoxWrapperlinearLayout;
@BindView(R.id.do_not_show_this_again_check_box)
MaterialCheckBox doNotShowThisAgainCheckBox;
@BindView(R.id.do_not_show_this_again_text_view)
TextView doNotShowThisAgainTextView;
@BindView(R.id.continue_button_suicide_prevention_activity)
MaterialButton continueButton;
@Inject
@Named("default")
SharedPreferences mSharedPreferences;
@Inject
CustomThemeWrapper mCustomThemeWrapper;
@Override
protected void onCreate(Bundle savedInstanceState) {
((Infinity) getApplicationContext()).getAppComponent().inject(this);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_suicide_prevention);
ButterKnife.bind(this);
applyCustomTheme();
checkBoxWrapperlinearLayout.setOnClickListener(view -> {
doNotShowThisAgainCheckBox.performClick();
});
continueButton.setOnClickListener(view -> {
if (doNotShowThisAgainCheckBox.isChecked()) {
mSharedPreferences.edit().putBoolean(SharedPreferencesUtils.SHOW_SUICIDE_PREVENTION_ACTIVITY, false).apply();
}
finish();
});
}
@Override
protected SharedPreferences getDefaultSharedPreferences() {
return mSharedPreferences;
}
@Override
protected CustomThemeWrapper getCustomThemeWrapper() {
return mCustomThemeWrapper;
}
@Override
protected void applyCustomTheme() {
linearLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor());
quoteTextView.setTextColor(mCustomThemeWrapper.getPrimaryTextColor());
doNotShowThisAgainTextView.setTextColor(mCustomThemeWrapper.getPrimaryTextColor());
continueButton.setBackgroundTintList(ColorStateList.valueOf(mCustomThemeWrapper.getColorPrimaryLightTheme()));
continueButton.setTextColor(mCustomThemeWrapper.getButtonTextColor());
}
}

View File

@ -36,6 +36,7 @@ public class CreditsPreferenceFragment extends PreferenceFragmentCompat {
Preference materialIconsPreference = findPreference(SharedPreferencesUtils.MATERIAL_ICONS_KEY);
Preference nationalFlagsPreference = findPreference(SharedPreferencesUtils.NATIONAL_FLAGS);
Preference ufoAndCowPreference = findPreference(SharedPreferencesUtils.UFO_CAPTURING_ANIMATION);
Preference loveAnimationPreference = findPreference(SharedPreferencesUtils.LOVE_ANIMATION);
if (iconForegroundPreference != null) {
iconForegroundPreference.setOnPreferenceClickListener(preference -> {
@ -126,6 +127,15 @@ public class CreditsPreferenceFragment extends PreferenceFragmentCompat {
return true;
});
}
if (loveAnimationPreference != null) {
loveAnimationPreference.setOnPreferenceClickListener(preference -> {
Intent intent = new Intent(activity, LinkResolverActivity.class);
intent.setData(Uri.parse("https://lottiefiles.com/52103-love"));
startActivity(intent);
return true;
});
}
}
@Override

View File

@ -171,6 +171,8 @@ public class SharedPreferencesUtils {
public static final String HIDE_THE_NUMBER_OF_COMMENTS = "hide_the_number_of_comments";
public static final String BACKUP_SETTINGS = "backup_settings";
public static final String RESTORE_SETTINGS = "restore_settings";
public static final String SHOW_SUICIDE_PREVENTION_ACTIVITY = "show_suicide_prevention_activity";
public static final String LOVE_ANIMATION = "love_animation";
public static final String DEFAULT_PREFERENCES_FILE = "ml.docilealligator.infinityforreddit_preferences";
public static final String MAIN_PAGE_TABS_SHARED_PREFERENCES_FILE = "ml.docilealligator.infinityforreddit.main_page_tabs";

View File

@ -8,7 +8,6 @@
tools:context=".activities.FetchRandomSubredditOrPostActivity">
<com.airbnb.lottie.LottieAnimationView
android:id="@+id/lottie_animation_view_fetch_random_subreddit_or_post_activity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"

View File

@ -0,0 +1,63 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/linear_layout_suicide_prevention_activity"
tools:context=".activities.SuicidePreventionActivity">
<com.airbnb.lottie.LottieAnimationView
android:id="@+id/lottie_animation_view"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_gravity="center_horizontal"
app:lottie_autoPlay="true"
app:lottie_loop="true"
app:lottie_rawRes="@raw/love" />
<TextView
android:id="@+id/quote_text_view_suicide_prevention_activity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="16dp"
android:text="@string/suicide_prevention_quote"
android:fontFamily="?attr/font_family"
android:textSize="?attr/font_20" />
<LinearLayout
android:id="@+id/linear_layout_check_box_wrapper_suicide_prevention_activity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp">
<com.google.android.material.checkbox.MaterialCheckBox
android:id="@+id/do_not_show_this_again_check_box"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/do_not_show_this_again_text_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/do_not_show_this_again"
android:layout_gravity="center_vertical"
android:fontFamily="?attr/font_family"
android:textSize="?attr/font_default" />
<com.google.android.material.button.MaterialButton
android:id="@+id/continue_button_suicide_prevention_activity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:text="@string/continue_suicide_prevention_activity" />
</LinearLayout>
</LinearLayout>

File diff suppressed because one or more lines are too long

View File

@ -543,6 +543,7 @@
<string name="settings_show_avatar_on_the_right_in_the_navigation_drawer">Show Avatar on the Left in the Navigation Drawer</string>
<string name="settings_backup_settings_title">Backup Settings</string>
<string name="settings_restore_settings_title">Restore Settings</string>
<string name="settings_credits_love_animation_title">Love Animation</string>
<string name="no_link_available">Cannot get the link</string>
@ -1047,4 +1048,8 @@
<string name="restore_settings_failed_file_corrupted">Cannot restore settings. The file may be corrupted.</string>
<string name="restore_settings_failed_cannot_get_file">Cannot access the file</string>
<string name="suicide_prevention_quote">If you are looking for a sign not to kill yourself, this is it.\u2764</string>
<string name="do_not_show_this_again">Do not show this again</string>
<string name="continue_suicide_prevention_activity">Continue</string>
</resources>

View File

@ -51,4 +51,9 @@
app:title="@string/settings_credits_ufo_capturing_animation_title"
android:summary="https://lottiefiles.com/33858-ufo-capturing-animation" />
<Preference
app:key="love_animation"
app:title="@string/settings_credits_love_animation_title"
android:summary="https://lottiefiles.com/52103-love" />
</PreferenceScreen>