diff options
Diffstat (limited to '')
6 files changed, 123 insertions, 25 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java index 9e7ac3aa..78e661ee 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java @@ -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); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FetchRandomSubredditOrPostActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FetchRandomSubredditOrPostActivity.java index ab1722f2..d73e195c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FetchRandomSubredditOrPostActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FetchRandomSubredditOrPostActivity.java @@ -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; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchActivity.java index 6cb3b1e4..34351fc9 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchActivity.java @@ -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); + if (query.equalsIgnoreCase("suicide") && mSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_SUICIDE_PREVENTION_ACTIVITY, true)) { + Intent intent = new Intent(this, SuicidePreventionActivity.class); + startActivity(intent); } 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 (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(); } - startActivity(intent); - finish(); } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SuicidePreventionActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SuicidePreventionActivity.java new file mode 100644 index 00000000..998053b5 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SuicidePreventionActivity.java @@ -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()); + } +}
\ No newline at end of file diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/CreditsPreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/CreditsPreferenceFragment.java index 5c62f438..0ad8ad65 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/CreditsPreferenceFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/CreditsPreferenceFragment.java @@ -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 diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java index d1942a34..6d219e31 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java @@ -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"; |