From 68b1c6a7f43db0b14d5b0bc34593706f3e4e06c6 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Tue, 5 Jan 2021 23:17:56 +0800 Subject: Adding users to a multireddit is now available. --- app/src/main/AndroidManifest.xml | 2 +- .../infinityforreddit/AppComponent.java | 4 +- .../activities/CreateMultiRedditActivity.java | 4 +- .../activities/EditMultiRedditActivity.java | 56 +++--- .../activities/SearchActivity.java | 38 ++-- .../activities/SearchUsersResultActivity.java | 10 +- .../activities/SelectedSubredditsActivity.java | 178 ------------------ .../SelectedSubredditsAndUsersActivity.java | 200 +++++++++++++++++++++ .../activities/SubredditSelectionActivity.java | 18 +- .../SelectedSubredditsRecyclerViewAdapter.java | 5 + ...ubredditsOrUsersOptionsBottomSheetFragment.java | 57 ++++++ .../res/layout/activity_create_multi_reddit.xml | 2 +- .../main/res/layout/activity_edit_multi_reddit.xml | 2 +- .../res/layout/activity_selected_subreddits.xml | 12 +- ...ct_subreddits_or_users_options_bottom_sheet.xml | 47 +++++ app/src/main/res/values-de/strings.xml | 2 +- app/src/main/res/values-es/strings.xml | 2 +- app/src/main/res/values-fr/strings.xml | 2 +- app/src/main/res/values-hi/strings.xml | 2 +- app/src/main/res/values-hr/strings.xml | 2 +- app/src/main/res/values-it/strings.xml | 2 +- app/src/main/res/values-ja/strings.xml | 2 +- app/src/main/res/values-pt-rBR/strings.xml | 2 +- app/src/main/res/values-tr-rTR/strings.xml | 2 +- app/src/main/res/values-zh-rCN/strings.xml | 2 +- app/src/main/res/values/strings.xml | 2 +- 26 files changed, 402 insertions(+), 255 deletions(-) delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/activities/SelectedSubredditsActivity.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/activities/SelectedSubredditsAndUsersActivity.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/SelectSubredditsOrUsersOptionsBottomSheetFragment.java create mode 100644 app/src/main/res/layout/fragment_select_subreddits_or_users_options_bottom_sheet.xml (limited to 'app/src/main') diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 4a938525..d513dd38 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -117,7 +117,7 @@ android:parentActivityName=".activities.MainActivity" android:theme="@style/AppTheme.Slidable" /> diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java index e8ad4767..9db681e3 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java @@ -36,7 +36,7 @@ import ml.docilealligator.infinityforreddit.activities.SearchResultActivity; import ml.docilealligator.infinityforreddit.activities.SearchSubredditsResultActivity; import ml.docilealligator.infinityforreddit.activities.SearchUsersResultActivity; import ml.docilealligator.infinityforreddit.activities.SelectUserFlairActivity; -import ml.docilealligator.infinityforreddit.activities.SelectedSubredditsActivity; +import ml.docilealligator.infinityforreddit.activities.SelectedSubredditsAndUsersActivity; import ml.docilealligator.infinityforreddit.activities.SendPrivateMessageActivity; import ml.docilealligator.infinityforreddit.activities.SettingsActivity; import ml.docilealligator.infinityforreddit.activities.SubmitCrosspostActivity; @@ -181,7 +181,7 @@ public interface AppComponent { void inject(EditMultiRedditActivity editMultiRedditActivity); - void inject(SelectedSubredditsActivity selectedSubredditsActivity); + void inject(SelectedSubredditsAndUsersActivity selectedSubredditsAndUsersActivity); void inject(ReportActivity reportActivity); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CreateMultiRedditActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CreateMultiRedditActivity.java index 3201fcbe..6077f232 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CreateMultiRedditActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CreateMultiRedditActivity.java @@ -144,8 +144,8 @@ public class CreateMultiRedditActivity extends BaseActivity { private void bindView() { selectSubredditTextView.setOnClickListener(view -> { - Intent intent = new Intent(CreateMultiRedditActivity.this, SelectedSubredditsActivity.class); - intent.putStringArrayListExtra(SelectedSubredditsActivity.EXTRA_SELECTED_SUBREDDITS, mSubreddits); + Intent intent = new Intent(CreateMultiRedditActivity.this, SelectedSubredditsAndUsersActivity.class); + intent.putStringArrayListExtra(SelectedSubredditsAndUsersActivity.EXTRA_SELECTED_SUBREDDITS, mSubreddits); startActivityForResult(intent, SUBREDDIT_SELECTION_REQUEST_CODE); }); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditMultiRedditActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditMultiRedditActivity.java index 65ef4faa..5ae37fb3 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditMultiRedditActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditMultiRedditActivity.java @@ -179,9 +179,9 @@ public class EditMultiRedditActivity extends BaseActivity { } selectSubredditTextView.setOnClickListener(view -> { - Intent intent = new Intent(EditMultiRedditActivity.this, SelectedSubredditsActivity.class); + Intent intent = new Intent(EditMultiRedditActivity.this, SelectedSubredditsAndUsersActivity.class); if (multiReddit.getSubreddits() != null) { - intent.putStringArrayListExtra(SelectedSubredditsActivity.EXTRA_SELECTED_SUBREDDITS, multiReddit.getSubreddits()); + intent.putStringArrayListExtra(SelectedSubredditsAndUsersActivity.EXTRA_SELECTED_SUBREDDITS, multiReddit.getSubreddits()); } startActivityForResult(intent, SUBREDDIT_SELECTION_REQUEST_CODE); }); @@ -196,34 +196,34 @@ public class EditMultiRedditActivity extends BaseActivity { @Override public boolean onOptionsItemSelected(@NonNull MenuItem item) { - switch (item.getItemId()) { - case android.R.id.home: - finish(); + int itemId = item.getItemId(); + if (itemId == android.R.id.home) { + finish(); + return true; + } else if (itemId == R.id.action_save_edit_multi_reddit_activity) { + if (mAccountName == null || mAccessToken == null) { + Snackbar.make(coordinatorLayout, R.string.something_went_wrong, Snackbar.LENGTH_SHORT).show(); return true; - case R.id.action_save_edit_multi_reddit_activity: - if (mAccountName == null || mAccessToken == null) { - Snackbar.make(coordinatorLayout, R.string.something_went_wrong, Snackbar.LENGTH_SHORT).show(); - return true; - } - if (nameEditText.getText() == null || nameEditText.getText().toString().equals("")) { - Snackbar.make(coordinatorLayout, R.string.no_multi_reddit_name, Snackbar.LENGTH_SHORT).show(); - return true; - } + } + if (nameEditText.getText() == null || nameEditText.getText().toString().equals("")) { + Snackbar.make(coordinatorLayout, R.string.no_multi_reddit_name, Snackbar.LENGTH_SHORT).show(); + return true; + } - String jsonModel = new MultiRedditJSONModel(nameEditText.getText().toString(), descriptionEditText.getText().toString(), - visibilitySwitch.isChecked(), multiReddit.getSubreddits()).createJSONModel(); - EditMultiReddit.editMultiReddit(mRetrofit, mAccessToken, multiReddit.getPath(), - jsonModel, new EditMultiReddit.EditMultiRedditListener() { - @Override - public void success() { - finish(); - } + String jsonModel = new MultiRedditJSONModel(nameEditText.getText().toString(), descriptionEditText.getText().toString(), + visibilitySwitch.isChecked(), multiReddit.getSubreddits()).createJSONModel(); + EditMultiReddit.editMultiReddit(mRetrofit, mAccessToken, multiReddit.getPath(), + jsonModel, new EditMultiReddit.EditMultiRedditListener() { + @Override + public void success() { + finish(); + } - @Override - public void failed() { - Snackbar.make(coordinatorLayout, R.string.edit_multi_reddit_failed, Snackbar.LENGTH_SHORT).show(); - } - }); + @Override + public void failed() { + Snackbar.make(coordinatorLayout, R.string.edit_multi_reddit_failed, Snackbar.LENGTH_SHORT).show(); + } + }); } return false; } @@ -234,7 +234,7 @@ public class EditMultiRedditActivity extends BaseActivity { if (requestCode == SUBREDDIT_SELECTION_REQUEST_CODE && resultCode == RESULT_OK) { if (data != null) { multiReddit.setSubreddits(data.getStringArrayListExtra( - SelectedSubredditsActivity.EXTRA_RETURN_SELECTED_SUBREDDITS)); + SelectedSubredditsAndUsersActivity.EXTRA_RETURN_SELECTED_SUBREDDITS)); } } } 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 f25b77aa..141d0ffd 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchActivity.java @@ -54,8 +54,11 @@ public class SearchActivity extends BaseActivity { static final String EXTRA_SUBREDDIT_NAME = "ESN"; static final String EXTRA_SUBREDDIT_IS_USER = "ESIU"; static final String EXTRA_SEARCH_ONLY_SUBREDDITS = "ESOS"; + static final String EXTRA_SEARCH_ONLY_USERS = "ESOU"; static final String EXTRA_RETURN_SUBREDDIT_NAME = "ERSN"; - static final String EXTRA_RETURN_SUBREDDIT_ICON_URL = "ERSIURL"; + static final String EXTRA_RETURN_SUBREDDIT_ICON_URL = "ERSIU"; + static final String EXTRA_RETURN_USER_NAME = "ERUN"; + static final String EXTRA_RETURN_USER_ICON_URL = "ERUIU"; private static final String NULL_ACCOUNT_NAME_STATE = "NANS"; private static final String ACCOUNT_NAME_STATE = "ANS"; @@ -64,6 +67,7 @@ public class SearchActivity extends BaseActivity { private static final int SUBREDDIT_SELECTION_REQUEST_CODE = 0; private static final int SUBREDDIT_SEARCH_REQUEST_CODE = 1; + private static final int USER_SEARCH_REQUEST_CODE = 2; @BindView(R.id.coordinator_layout_search_activity) CoordinatorLayout coordinatorLayout; @@ -100,6 +104,7 @@ public class SearchActivity extends BaseActivity { private String subredditName; private boolean subredditIsUser; private boolean searchOnlySubreddits; + private boolean searchOnlyUsers; private SearchActivityRecyclerViewAdapter adapter; RecentSearchQueryViewModel mRecentSearchQueryViewModel; @@ -126,6 +131,7 @@ public class SearchActivity extends BaseActivity { setSupportActionBar(toolbar); searchOnlySubreddits = getIntent().getBooleanExtra(EXTRA_SEARCH_ONLY_SUBREDDITS, false); + searchOnlyUsers = getIntent().getBooleanExtra(EXTRA_SEARCH_ONLY_USERS, false); simpleSearchView.setOnSearchViewListener(new SimpleSearchView.SearchViewListener() { @Override @@ -189,7 +195,7 @@ public class SearchActivity extends BaseActivity { getCurrentAccountAndInitializeViewPager(); } - if (searchOnlySubreddits) { + if (searchOnlySubreddits || searchOnlyUsers) { subredditNameRelativeLayout.setVisibility(View.GONE); } else { subredditNameRelativeLayout.setOnClickListener(view -> { @@ -260,6 +266,10 @@ public class SearchActivity extends BaseActivity { Intent intent = new Intent(SearchActivity.this, SearchSubredditsResultActivity.class); intent.putExtra(SearchSubredditsResultActivity.EXTRA_QUERY, query); startActivityForResult(intent, SUBREDDIT_SEARCH_REQUEST_CODE); + } else if (searchOnlyUsers) { + Intent intent = new Intent(this, SearchUsersResultActivity.class); + intent.putExtra(SearchUsersResultActivity.EXTRA_QUERY, query); + startActivityForResult(intent, USER_SEARCH_REQUEST_CODE); } else { Intent intent = new Intent(SearchActivity.this, SearchResultActivity.class); intent.putExtra(SearchResultActivity.EXTRA_QUERY, query); @@ -335,26 +345,32 @@ public class SearchActivity extends BaseActivity { return; } - if (requestCode == SUBREDDIT_SELECTION_REQUEST_CODE) { - if (resultCode == RESULT_OK) { - subredditName = data.getExtras().getString(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_NAME); - subredditIsUser = data.getExtras().getBoolean(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_IS_USER); + if (resultCode == RESULT_OK && data != null) { + if (requestCode == SUBREDDIT_SELECTION_REQUEST_CODE) { + subredditName = data.getStringExtra(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_NAME); + subredditIsUser = data.getBooleanExtra(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_IS_USER, false); if (subredditName == null) { subredditNameTextView.setText(R.string.all_subreddits); } else { subredditNameTextView.setText(subredditName); } - } - } else if (requestCode == SUBREDDIT_SEARCH_REQUEST_CODE) { - if (resultCode == RESULT_OK) { - String name = data.getExtras().getString(SearchSubredditsResultActivity.EXTRA_RETURN_SUBREDDIT_NAME); - String iconUrl = data.getExtras().getString(SearchSubredditsResultActivity.EXTRA_RETURN_SUBREDDIT_ICON_URL); + } else if (requestCode == SUBREDDIT_SEARCH_REQUEST_CODE) { + String name = data.getStringExtra(SearchSubredditsResultActivity.EXTRA_RETURN_SUBREDDIT_NAME); + String iconUrl = data.getStringExtra(SearchSubredditsResultActivity.EXTRA_RETURN_SUBREDDIT_ICON_URL); Intent returnIntent = new Intent(); returnIntent.putExtra(EXTRA_RETURN_SUBREDDIT_NAME, name); returnIntent.putExtra(EXTRA_RETURN_SUBREDDIT_ICON_URL, iconUrl); setResult(Activity.RESULT_OK, returnIntent); finish(); + } else if (requestCode == USER_SEARCH_REQUEST_CODE) { + String username = data.getStringExtra(SearchUsersResultActivity.EXTRA_RETURN_USER_NAME); + String iconUrl = data.getStringExtra(SearchUsersResultActivity.EXTRA_RETURN_USER_ICON_URL); + Intent returnIntent = new Intent(); + returnIntent.putExtra(EXTRA_RETURN_USER_NAME, username); + returnIntent.putExtra(EXTRA_RETURN_USER_ICON_URL, iconUrl); + setResult(Activity.RESULT_OK, returnIntent); + finish(); } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchUsersResultActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchUsersResultActivity.java index 23dc6fd4..a1aea4bd 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchUsersResultActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchUsersResultActivity.java @@ -49,11 +49,11 @@ public class SearchUsersResultActivity extends BaseActivity implements ActivityT private static final String ACCOUNT_NAME_STATE = "ANS"; private static final String FRAGMENT_OUT_STATE = "FOS"; - @BindView(R.id.coordinator_layout_search_subreddits_result_activity) + @BindView(R.id.coordinator_layout_search_users_result_activity) CoordinatorLayout coordinatorLayout; - @BindView(R.id.appbar_layout_search_subreddits_result_activity) + @BindView(R.id.appbar_layout_search_users_result_activity) AppBarLayout appBarLayout; - @BindView(R.id.toolbar_search_subreddits_result_activity) + @BindView(R.id.toolbar_search_users_result_activity) Toolbar toolbar; Fragment mFragment; @Inject @@ -122,7 +122,7 @@ public class SearchUsersResultActivity extends BaseActivity implements ActivityT getCurrentAccountAndInitializeFragment(query); } else { mFragment = getSupportFragmentManager().getFragment(savedInstanceState, FRAGMENT_OUT_STATE); - getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_search_subreddits_result_activity, mFragment).commit(); + getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_search_users_result_activity, mFragment).commit(); } } } @@ -159,7 +159,7 @@ public class SearchUsersResultActivity extends BaseActivity implements ActivityT bundle.putString(UserListingFragment.EXTRA_ACCESS_TOKEN, mAccessToken); bundle.putString(UserListingFragment.EXTRA_ACCOUNT_NAME, mAccountName); mFragment.setArguments(bundle); - getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_search_subreddits_result_activity, mFragment).commit(); + getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_search_users_result_activity, mFragment).commit(); }); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SelectedSubredditsActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SelectedSubredditsActivity.java deleted file mode 100644 index 3097538b..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SelectedSubredditsActivity.java +++ /dev/null @@ -1,178 +0,0 @@ -package ml.docilealligator.infinityforreddit.activities; - -import android.app.Activity; -import android.content.Intent; -import android.content.SharedPreferences; -import android.os.Bundle; -import android.view.Menu; -import android.view.MenuItem; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.appcompat.widget.Toolbar; -import androidx.coordinatorlayout.widget.CoordinatorLayout; -import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; - -import com.google.android.material.appbar.AppBarLayout; -import com.google.android.material.floatingactionbutton.FloatingActionButton; -import com.r0adkll.slidr.Slidr; - -import java.util.ArrayList; - -import javax.inject.Inject; -import javax.inject.Named; - -import butterknife.BindView; -import butterknife.ButterKnife; -import ml.docilealligator.infinityforreddit.ActivityToolbarInterface; -import ml.docilealligator.infinityforreddit.adapters.SelectedSubredditsRecyclerViewAdapter; -import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; -import ml.docilealligator.infinityforreddit.Infinity; -import ml.docilealligator.infinityforreddit.R; -import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; - -public class SelectedSubredditsActivity extends BaseActivity implements ActivityToolbarInterface { - - public static final String EXTRA_SELECTED_SUBREDDITS = "ESS"; - public static final String EXTRA_RETURN_SELECTED_SUBREDDITS = "ERSS"; - private static final int SUBREDDIT_SELECTION_REQUEST_CODE = 1; - private static final String SELECTED_SUBREDDITS_STATE = "SSS"; - - @BindView(R.id.coordinator_layout_selected_subreddits_activity) - CoordinatorLayout coordinatorLayout; - @BindView(R.id.appbar_layout_selected_subreddits_activity) - AppBarLayout appBarLayout; - @BindView(R.id.toolbar_selected_subreddits_activity) - Toolbar toolbar; - @BindView(R.id.recycler_view_selected_subreddits_activity) - RecyclerView recyclerView; - @BindView(R.id.fab_selected_subreddits_activity) - FloatingActionButton fab; - @Inject - @Named("default") - SharedPreferences mSharedPreferences; - @Inject - CustomThemeWrapper mCustomThemeWrapper; - private LinearLayoutManager linearLayoutManager; - private SelectedSubredditsRecyclerViewAdapter adapter; - private ArrayList subreddits; - - @Override - protected void onCreate(Bundle savedInstanceState) { - ((Infinity) getApplication()).getAppComponent().inject(this); - - setImmersiveModeNotApplicable(); - - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_selected_subreddits); - - ButterKnife.bind(this); - - applyCustomTheme(); - - if (mSharedPreferences.getBoolean(SharedPreferencesUtils.SWIPE_RIGHT_TO_GO_BACK, true)) { - Slidr.attach(this); - } - - setSupportActionBar(toolbar); - getSupportActionBar().setDisplayHomeAsUpEnabled(true); - setToolbarGoToTop(toolbar); - - if (savedInstanceState != null) { - subreddits = savedInstanceState.getStringArrayList(SELECTED_SUBREDDITS_STATE); - } else { - subreddits = getIntent().getStringArrayListExtra(EXTRA_SELECTED_SUBREDDITS); - } - - adapter = new SelectedSubredditsRecyclerViewAdapter(mCustomThemeWrapper, subreddits); - linearLayoutManager = new LinearLayoutManager(this); - recyclerView.setLayoutManager(linearLayoutManager); - recyclerView.setAdapter(adapter); - recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { - @Override - public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) { - super.onScrolled(recyclerView, dx, dy); - if (dy > 0) { - fab.hide(); - } else { - fab.show(); - } - } - }); - - fab.setOnClickListener(view -> { - Intent intent = new Intent(this, SubredditMultiselectionActivity.class); - startActivityForResult(intent, SUBREDDIT_SELECTION_REQUEST_CODE); - }); - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - getMenuInflater().inflate(R.menu.selected_subreddits_activity, menu); - applyMenuItemTheme(menu); - return true; - } - - @Override - public boolean onOptionsItemSelected(@NonNull MenuItem item) { - if (item.getItemId() == android.R.id.home) { - finish(); - return true; - } else if (item.getItemId() == R.id.action_save_selected_subreddits_activity) { - if (adapter != null) { - Intent returnIntent = new Intent(); - returnIntent.putExtra(EXTRA_RETURN_SELECTED_SUBREDDITS, adapter.getSubreddits()); - setResult(Activity.RESULT_OK, returnIntent); - } - finish(); - } - return false; - } - - @Override - protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { - super.onActivityResult(requestCode, resultCode, data); - if (requestCode == SUBREDDIT_SELECTION_REQUEST_CODE && resultCode == RESULT_OK) { - if (data != null) { - if (subreddits == null) { - subreddits = new ArrayList<>(); - } - subreddits = data.getStringArrayListExtra(SubredditMultiselectionActivity.EXTRA_RETURN_SELECTED_SUBREDDITS); - adapter.addSubreddits(subreddits); - } - } - } - - @Override - protected void onSaveInstanceState(@NonNull Bundle outState) { - super.onSaveInstanceState(outState); - if (adapter != null) { - outState.putStringArrayList(SELECTED_SUBREDDITS_STATE, adapter.getSubreddits()); - } - } - - @Override - protected SharedPreferences getDefaultSharedPreferences() { - return mSharedPreferences; - } - - @Override - protected CustomThemeWrapper getCustomThemeWrapper() { - return mCustomThemeWrapper; - } - - @Override - protected void applyCustomTheme() { - coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor()); - applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar); - applyFABTheme(fab); - } - - @Override - public void onLongPress() { - if (linearLayoutManager != null) { - linearLayoutManager.scrollToPositionWithOffset(0, 0); - } - } -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SelectedSubredditsAndUsersActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SelectedSubredditsAndUsersActivity.java new file mode 100644 index 00000000..cfc30dcf --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SelectedSubredditsAndUsersActivity.java @@ -0,0 +1,200 @@ +package ml.docilealligator.infinityforreddit.activities; + +import android.app.Activity; +import android.content.Intent; +import android.content.SharedPreferences; +import android.os.Bundle; +import android.view.Menu; +import android.view.MenuItem; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.appcompat.widget.Toolbar; +import androidx.coordinatorlayout.widget.CoordinatorLayout; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.google.android.material.appbar.AppBarLayout; +import com.google.android.material.floatingactionbutton.FloatingActionButton; +import com.r0adkll.slidr.Slidr; + +import java.util.ArrayList; + +import javax.inject.Inject; +import javax.inject.Named; + +import butterknife.BindView; +import butterknife.ButterKnife; +import ml.docilealligator.infinityforreddit.ActivityToolbarInterface; +import ml.docilealligator.infinityforreddit.adapters.SelectedSubredditsRecyclerViewAdapter; +import ml.docilealligator.infinityforreddit.bottomsheetfragments.SelectSubredditsOrUsersOptionsBottomSheetFragment; +import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; +import ml.docilealligator.infinityforreddit.Infinity; +import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; + +public class SelectedSubredditsAndUsersActivity extends BaseActivity implements ActivityToolbarInterface { + + public static final String EXTRA_SELECTED_SUBREDDITS = "ESS"; + public static final String EXTRA_RETURN_SELECTED_SUBREDDITS = "ERSS"; + private static final int SUBREDDIT_SELECTION_REQUEST_CODE = 1; + private static final int USER_SELECTION_REQUEST_CODE = 2; + private static final String SELECTED_SUBREDDITS_STATE = "SSS"; + + @BindView(R.id.coordinator_layout_selected_subreddits_and_users_activity) + CoordinatorLayout coordinatorLayout; + @BindView(R.id.appbar_layout_selected_subreddits_and_users_activity) + AppBarLayout appBarLayout; + @BindView(R.id.toolbar_selected_subreddits_and_users_activity) + Toolbar toolbar; + @BindView(R.id.recycler_view_selected_subreddits_and_users_activity) + RecyclerView recyclerView; + @BindView(R.id.fab_selected_subreddits_and_users_activity) + FloatingActionButton fab; + @Inject + @Named("default") + SharedPreferences mSharedPreferences; + @Inject + CustomThemeWrapper mCustomThemeWrapper; + private LinearLayoutManager linearLayoutManager; + private SelectedSubredditsRecyclerViewAdapter adapter; + private ArrayList subreddits; + + @Override + protected void onCreate(Bundle savedInstanceState) { + ((Infinity) getApplication()).getAppComponent().inject(this); + + setImmersiveModeNotApplicable(); + + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_selected_subreddits); + + ButterKnife.bind(this); + + applyCustomTheme(); + + if (mSharedPreferences.getBoolean(SharedPreferencesUtils.SWIPE_RIGHT_TO_GO_BACK, true)) { + Slidr.attach(this); + } + + setSupportActionBar(toolbar); + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + setToolbarGoToTop(toolbar); + + if (savedInstanceState != null) { + subreddits = savedInstanceState.getStringArrayList(SELECTED_SUBREDDITS_STATE); + } else { + subreddits = getIntent().getStringArrayListExtra(EXTRA_SELECTED_SUBREDDITS); + } + + adapter = new SelectedSubredditsRecyclerViewAdapter(mCustomThemeWrapper, subreddits); + linearLayoutManager = new LinearLayoutManager(this); + recyclerView.setLayoutManager(linearLayoutManager); + recyclerView.setAdapter(adapter); + recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { + @Override + public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) { + super.onScrolled(recyclerView, dx, dy); + if (dy > 0) { + fab.hide(); + } else { + fab.show(); + } + } + }); + + fab.setOnClickListener(view -> { + SelectSubredditsOrUsersOptionsBottomSheetFragment selectSubredditsOrUsersOptionsBottomSheetFragment = new SelectSubredditsOrUsersOptionsBottomSheetFragment(); + selectSubredditsOrUsersOptionsBottomSheetFragment.show(getSupportFragmentManager(), selectSubredditsOrUsersOptionsBottomSheetFragment.getTag()); + }); + } + + public void selectSubreddits() { + Intent intent = new Intent(this, SubredditMultiselectionActivity.class); + startActivityForResult(intent, SUBREDDIT_SELECTION_REQUEST_CODE); + } + + public void selectUsers() { + Intent intent = new Intent(this, SearchActivity.class); + intent.putExtra(SearchActivity.EXTRA_SEARCH_ONLY_USERS, true); + startActivityForResult(intent, USER_SELECTION_REQUEST_CODE); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.selected_subreddits_activity, menu); + applyMenuItemTheme(menu); + return true; + } + + @Override + public boolean onOptionsItemSelected(@NonNull MenuItem item) { + if (item.getItemId() == android.R.id.home) { + finish(); + return true; + } else if (item.getItemId() == R.id.action_save_selected_subreddits_activity) { + if (adapter != null) { + Intent returnIntent = new Intent(); + returnIntent.putExtra(EXTRA_RETURN_SELECTED_SUBREDDITS, adapter.getSubreddits()); + setResult(Activity.RESULT_OK, returnIntent); + } + finish(); + } + return false; + } + + @Override + protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { + super.onActivityResult(requestCode, resultCode, data); + if (resultCode == RESULT_OK) { + if (requestCode == SUBREDDIT_SELECTION_REQUEST_CODE) { + if (data != null) { + if (subreddits == null) { + subreddits = new ArrayList<>(); + } + subreddits = data.getStringArrayListExtra(SubredditMultiselectionActivity.EXTRA_RETURN_SELECTED_SUBREDDITS); + adapter.addSubreddits(subreddits); + } + } else if (requestCode == USER_SELECTION_REQUEST_CODE) { + if (data != null) { + if (subreddits == null) { + subreddits = new ArrayList<>(); + } + adapter.addUserInSubredditType("u_" + data.getStringExtra(SearchActivity.EXTRA_RETURN_USER_NAME)); + } + } + } + } + + @Override + protected void onSaveInstanceState(@NonNull Bundle outState) { + super.onSaveInstanceState(outState); + if (adapter != null) { + outState.putStringArrayList(SELECTED_SUBREDDITS_STATE, adapter.getSubreddits()); + } + } + + @Override + protected SharedPreferences getDefaultSharedPreferences() { + return mSharedPreferences; + } + + @Override + protected CustomThemeWrapper getCustomThemeWrapper() { + return mCustomThemeWrapper; + } + + @Override + protected void applyCustomTheme() { + coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor()); + applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar); + applyFABTheme(fab); + } + + @Override + public void onLongPress() { + if (linearLayoutManager != null) { + linearLayoutManager.scrollToPositionWithOffset(0, 0); + } + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubredditSelectionActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubredditSelectionActivity.java index 62061cf0..5f9efb2d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubredditSelectionActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubredditSelectionActivity.java @@ -234,15 +234,15 @@ public class SubredditSelectionActivity extends BaseActivity implements Activity @Override public boolean onOptionsItemSelected(@NonNull MenuItem item) { - switch (item.getItemId()) { - case android.R.id.home: - finish(); - return true; - case R.id.action_search_subreddit_selection_activity: - Intent intent = new Intent(this, SearchActivity.class); - intent.putExtra(SearchActivity.EXTRA_SEARCH_ONLY_SUBREDDITS, true); - startActivityForResult(intent, SUBREDDIT_SEARCH_REQUEST_CODE); - return true; + int itemId = item.getItemId(); + if (itemId == android.R.id.home) { + finish(); + return true; + } else if (itemId == R.id.action_search_subreddit_selection_activity) { + Intent intent = new Intent(this, SearchActivity.class); + intent.putExtra(SearchActivity.EXTRA_SEARCH_ONLY_SUBREDDITS, true); + startActivityForResult(intent, SUBREDDIT_SEARCH_REQUEST_CODE); + return true; } return false; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/SelectedSubredditsRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/SelectedSubredditsRecyclerViewAdapter.java index 61f4438d..e6bbe441 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/SelectedSubredditsRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/SelectedSubredditsRecyclerViewAdapter.java @@ -58,6 +58,11 @@ public class SelectedSubredditsRecyclerViewAdapter extends RecyclerView.Adapter< notifyItemRangeInserted(oldSize, newSubreddits.size()); } + public void addUserInSubredditType(String username) { + subreddits.add(username); + notifyItemInserted(subreddits.size()); + } + public ArrayList getSubreddits() { return subreddits; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/SelectSubredditsOrUsersOptionsBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/SelectSubredditsOrUsersOptionsBottomSheetFragment.java new file mode 100644 index 00000000..dd1b81ad --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/SelectSubredditsOrUsersOptionsBottomSheetFragment.java @@ -0,0 +1,57 @@ +package ml.docilealligator.infinityforreddit.bottomsheetfragments; + +import android.content.Context; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +import androidx.annotation.NonNull; + +import com.deishelon.roundedbottomsheet.RoundedBottomSheetDialogFragment; + +import butterknife.BindView; +import butterknife.ButterKnife; +import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.activities.SelectedSubredditsAndUsersActivity; + +public class SelectSubredditsOrUsersOptionsBottomSheetFragment extends RoundedBottomSheetDialogFragment { + + @BindView(R.id.select_subreddits_text_view_search_user_and_subreddit_sort_type_bottom_sheet_fragment) + TextView selectSubredditsTextView; + @BindView(R.id.select_users_text_view_search_user_and_subreddit_sort_type_bottom_sheet_fragment) + TextView selectUsersTextView; + private SelectedSubredditsAndUsersActivity activity; + + public SelectSubredditsOrUsersOptionsBottomSheetFragment() { + // Required empty public constructor + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + // Inflate the layout for this fragment + View rootView = inflater.inflate(R.layout.fragment_select_subreddits_or_users_options_bottom_sheet, container, false); + + ButterKnife.bind(this, rootView); + + selectSubredditsTextView.setOnClickListener(view -> { + activity.selectSubreddits(); + dismiss(); + }); + + selectUsersTextView.setOnClickListener(view -> { + activity.selectUsers(); + dismiss(); + }); + + return rootView; + } + + @Override + public void onAttach(@NonNull Context context) { + super.onAttach(context); + activity = (SelectedSubredditsAndUsersActivity) context; + } +} \ No newline at end of file diff --git a/app/src/main/res/layout/activity_create_multi_reddit.xml b/app/src/main/res/layout/activity_create_multi_reddit.xml index af7affcc..5b088546 100644 --- a/app/src/main/res/layout/activity_create_multi_reddit.xml +++ b/app/src/main/res/layout/activity_create_multi_reddit.xml @@ -109,7 +109,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="16dp" - android:text="@string/select_subreddits" + android:text="@string/select_subreddits_and_users" android:textSize="?attr/font_default" android:textColor="?attr/primaryTextColor" android:fontFamily="?attr/font_family" diff --git a/app/src/main/res/layout/activity_edit_multi_reddit.xml b/app/src/main/res/layout/activity_edit_multi_reddit.xml index 408b13c7..2e2442eb 100644 --- a/app/src/main/res/layout/activity_edit_multi_reddit.xml +++ b/app/src/main/res/layout/activity_edit_multi_reddit.xml @@ -115,7 +115,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="16dp" - android:text="@string/select_subreddits" + android:text="@string/select_subreddits_and_users" android:textSize="?attr/font_default" android:textColor="?attr/primaryTextColor" android:clickable="true" diff --git a/app/src/main/res/layout/activity_selected_subreddits.xml b/app/src/main/res/layout/activity_selected_subreddits.xml index eade8be2..9482cba4 100644 --- a/app/src/main/res/layout/activity_selected_subreddits.xml +++ b/app/src/main/res/layout/activity_selected_subreddits.xml @@ -4,11 +4,11 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" - android:id="@+id/coordinator_layout_selected_subreddits_activity" + android:id="@+id/coordinator_layout_selected_subreddits_and_users_activity" tools:context=".activities.AccountPostsActivity"> @@ -18,10 +18,10 @@ android:layout_height="match_parent" app:layout_scrollFlags="scroll|enterAlways" app:titleEnabled="false" - app:toolbarId="@+id/toolbar_selected_subreddits_activity"> + app:toolbarId="@+id/toolbar_selected_subreddits_and_users_activity"> + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index d4068354..84405d32 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -491,7 +491,7 @@ Funktioniert vielleicht nicht auf Android 11" "Name (Max. 50 Zeichen)" "Beschreibung" "Privat" - "Subreddits auswählen" + "Subreddits auswählen" "Wo ist der Name?" "Kann dieses Multireddit nicht erstellen" "Dieses Multireddit existiert bereits" diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 6419c67e..cf688202 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -502,7 +502,7 @@ https://play.google.com/store/apps/details?id=ml.docilealligator.infinityforredd "Nombre (Max. 50 Caracteres)" "Descripción" "Privado" - "Selecciona Subreddits" + "Selecciona Subreddits" "Introduce un nombre" "Ocurrió un error creando este multireddit" "Este multireddit ya existe" diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 24a5fbcf..3d16b411 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -531,7 +531,7 @@ https://play.google.com/store/apps/details?id=ml.docilealligator.infinityforredd "Nom ( Max. 50 caractères )" "Description" "Privé" - "Sélectionnez des Subreddits" + "Sélectionnez des Subreddits" "Où est le nom ?" "Impossible de créer ce multireddit" "Ce multireddit existe déjà" diff --git a/app/src/main/res/values-hi/strings.xml b/app/src/main/res/values-hi/strings.xml index 158888e1..44141878 100644 --- a/app/src/main/res/values-hi/strings.xml +++ b/app/src/main/res/values-hi/strings.xml @@ -522,7 +522,7 @@ https://play.google.com/store/apps/details?id=ml.docilealligator.infinityforredd "नाम (अधिकतम 50 वर्ण)" "विवरण " "गुप्त " - "सबरैडिट चुनें " + "सबरैडिट चुनें " "नाम कहाँ है? " "इस मल्टीरैडिट का निर्माण असफल " "यह मल्टीरैडिट पहले से उपलब्ध है " diff --git a/app/src/main/res/values-hr/strings.xml b/app/src/main/res/values-hr/strings.xml index 5ee49cff..d1455ae8 100644 --- a/app/src/main/res/values-hr/strings.xml +++ b/app/src/main/res/values-hr/strings.xml @@ -489,7 +489,7 @@ https://play.google.com/store/apps/details?id=ml.docilealligator.infinityforredd "Ime (max. 50 znakova)" "Opis" "Privatno" - "Odaberi podreddite" + "Odaberi podreddite" "Gdje je ime?" "Nije moguće stvoriti ovaj multireddit" "Ovaj multireddit već postoji" diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index d404728c..b2be9297 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -500,7 +500,7 @@ https://play.google.com/store/apps/details?id=ml.docilealligator.infinityforredd "Nome (massimo 50 caratteri)" "Descrizione" "Privato" - "Seleziona Subreddit" + "Seleziona Subreddit" "Dov'è il nome?" "Impossibile creare questo multireddit" "Il multireddit esiste già" diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml index 01c478b6..c2509673 100644 --- a/app/src/main/res/values-ja/strings.xml +++ b/app/src/main/res/values-ja/strings.xml @@ -523,7 +523,7 @@ https://play.google.com/store/apps/details?id=ml.docilealligator.infinityforredd "名前 (最大50文字)" "詳細" "プライベート" - "Subredditを選択" + "Subredditを選択" "名前が必要です。" "このカスタムフィードを作成できませんでした" "このカスタムフィードは既に存在しています" diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml index 81f4493a..24c70f5b 100644 --- a/app/src/main/res/values-pt-rBR/strings.xml +++ b/app/src/main/res/values-pt-rBR/strings.xml @@ -476,7 +476,7 @@ https://play.google.com/store/apps/details?id=ml.docilealligator.infinityforredd "Nome (Limite de 50 caracteres)" "Descrição" "Privado" - "Selecionar Subreddits" + "Selecionar Subreddits" "Onde está o nome?" "Não foi possível criar este multiReddit" "Este multiReddit já existe" diff --git a/app/src/main/res/values-tr-rTR/strings.xml b/app/src/main/res/values-tr-rTR/strings.xml index 37f7aff0..b8c14681 100644 --- a/app/src/main/res/values-tr-rTR/strings.xml +++ b/app/src/main/res/values-tr-rTR/strings.xml @@ -485,7 +485,7 @@ https://play.google.com/store/apps/details?id=ml.docilealligator.infinityforredd "Ad (Maks 50 Karakter)" "Açıklama" "Özel" - "Subredditleri Seç" + "Subredditleri Seç" "Ad nerede?" "Bu multireddit oluşturulamıyor" "Bu multireddit zaten var" diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index 1b2cedd4..9da3879e 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -491,7 +491,7 @@ https://play.google.com/store/apps/details?id=ml.docilealligator.infinityforredd "名称(最多50个字符)" "描述" "私人的" - "选择板块" + "选择板块" "名字在哪里?" "不能创建这个复合reddit" "这个复合reddit已经存在" diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d845d04c..640db5b0 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -608,7 +608,7 @@ Name (Max 50 Characters) Description Private - Select Subreddits + Select Subreddits and Users Where is the name? Cannot create this multireddit This multireddit already exists -- cgit v1.2.3