Finish adding SuicidePreventionActivity.

This commit is contained in:
Alex Ning 2021-03-07 16:10:09 +08:00
parent 31f4739a17
commit 7ceb83d408
3 changed files with 37 additions and 23 deletions

View File

@ -58,6 +58,7 @@ public class SearchActivity extends BaseActivity {
static final String EXTRA_RETURN_USER_NAME = "ERUN"; static final String EXTRA_RETURN_USER_NAME = "ERUN";
static final String EXTRA_RETURN_USER_ICON_URL = "ERUIU"; static final String EXTRA_RETURN_USER_ICON_URL = "ERUIU";
static final String EXTRA_IS_MULTI_SELECTION = "EIMS"; static final String EXTRA_IS_MULTI_SELECTION = "EIMS";
static final int SUICIDE_PREVENTION_ACTIVITY_REQUEST_CODE = 101;
private static final String SUBREDDIT_NAME_STATE = "SNS"; private static final String SUBREDDIT_NAME_STATE = "SNS";
private static final String SUBREDDIT_IS_USER_STATE = "SIUS"; private static final String SUBREDDIT_IS_USER_STATE = "SIUS";
@ -251,31 +252,36 @@ public class SearchActivity extends BaseActivity {
private void search(String query) { private void search(String query) {
if (query.equalsIgnoreCase("suicide") && mSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_SUICIDE_PREVENTION_ACTIVITY, true)) { if (query.equalsIgnoreCase("suicide") && mSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_SUICIDE_PREVENTION_ACTIVITY, true)) {
Intent intent = new Intent(this, SuicidePreventionActivity.class); Intent intent = new Intent(this, SuicidePreventionActivity.class);
startActivity(intent); intent.putExtra(SuicidePreventionActivity.EXTRA_QUERY, query);
startActivityForResult(intent, SUICIDE_PREVENTION_ACTIVITY_REQUEST_CODE);
} else { } else {
if (searchOnlySubreddits) { openSearchResult(query);
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); private void openSearchResult(String query) {
} else if (searchOnlyUsers) { if (searchOnlySubreddits) {
Intent intent = new Intent(this, SearchUsersResultActivity.class); Intent intent = new Intent(SearchActivity.this, SearchSubredditsResultActivity.class);
intent.putExtra(SearchUsersResultActivity.EXTRA_QUERY, query); intent.putExtra(SearchSubredditsResultActivity.EXTRA_QUERY, query);
intent.putExtra(SearchUsersResultActivity.EXTRA_IS_MULTI_SELECTION, getIntent().getBooleanExtra(EXTRA_IS_MULTI_SELECTION, false)); intent.putExtra(SearchSubredditsResultActivity.EXTRA_IS_MULTI_SELECTION, getIntent().getBooleanExtra(EXTRA_IS_MULTI_SELECTION, false));
startActivityForResult(intent, USER_SEARCH_REQUEST_CODE); startActivityForResult(intent, SUBREDDIT_SEARCH_REQUEST_CODE);
} else { } else if (searchOnlyUsers) {
Intent intent = new Intent(SearchActivity.this, SearchResultActivity.class); Intent intent = new Intent(this, SearchUsersResultActivity.class);
intent.putExtra(SearchResultActivity.EXTRA_QUERY, query); intent.putExtra(SearchUsersResultActivity.EXTRA_QUERY, query);
if (subredditName != null) { intent.putExtra(SearchUsersResultActivity.EXTRA_IS_MULTI_SELECTION, getIntent().getBooleanExtra(EXTRA_IS_MULTI_SELECTION, false));
if (subredditIsUser) { startActivityForResult(intent, USER_SEARCH_REQUEST_CODE);
intent.putExtra(SearchResultActivity.EXTRA_SUBREDDIT_NAME, "u_" + subredditName); } else {
} else { Intent intent = new Intent(SearchActivity.this, SearchResultActivity.class);
intent.putExtra(SearchResultActivity.EXTRA_SUBREDDIT_NAME, subredditName); 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();
} }
} }
@ -373,6 +379,8 @@ public class SearchActivity extends BaseActivity {
} }
setResult(Activity.RESULT_OK, returnIntent); setResult(Activity.RESULT_OK, returnIntent);
finish(); finish();
} else if (requestCode == SUICIDE_PREVENTION_ACTIVITY_REQUEST_CODE) {
openSearchResult(data.getStringExtra(SuicidePreventionActivity.EXTRA_RETURN_QUERY));
} }
} }

View File

@ -1,5 +1,6 @@
package ml.docilealligator.infinityforreddit.activities; package ml.docilealligator.infinityforreddit.activities;
import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.res.ColorStateList; import android.content.res.ColorStateList;
import android.os.Bundle; import android.os.Bundle;
@ -21,6 +22,8 @@ import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
public class SuicidePreventionActivity extends BaseActivity { public class SuicidePreventionActivity extends BaseActivity {
static final String EXTRA_QUERY = "EQ";
static final String EXTRA_RETURN_QUERY = "ERQ";
@BindView(R.id.linear_layout_suicide_prevention_activity) @BindView(R.id.linear_layout_suicide_prevention_activity)
LinearLayout linearLayout; LinearLayout linearLayout;
@BindView(R.id.quote_text_view_suicide_prevention_activity) @BindView(R.id.quote_text_view_suicide_prevention_activity)
@ -57,6 +60,9 @@ public class SuicidePreventionActivity extends BaseActivity {
if (doNotShowThisAgainCheckBox.isChecked()) { if (doNotShowThisAgainCheckBox.isChecked()) {
mSharedPreferences.edit().putBoolean(SharedPreferencesUtils.SHOW_SUICIDE_PREVENTION_ACTIVITY, false).apply(); mSharedPreferences.edit().putBoolean(SharedPreferencesUtils.SHOW_SUICIDE_PREVENTION_ACTIVITY, false).apply();
} }
Intent returnIntent = new Intent();
returnIntent.putExtra(EXTRA_RETURN_QUERY, getIntent().getStringExtra(EXTRA_QUERY));
setResult(RESULT_OK, returnIntent);
finish(); finish();
}); });
} }

View File

@ -1049,7 +1049,7 @@
<string name="restore_settings_failed_cannot_get_file">Cannot access the file</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="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="do_not_show_this_again">Don\'t show this again</string>
<string name="continue_suicide_prevention_activity">Continue</string> <string name="continue_suicide_prevention_activity">Continue</string>
</resources> </resources>