aboutsummaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2021-01-05 08:00:45 +0000
committerAlex Ning <chineseperson5@gmail.com>2021-01-05 08:00:45 +0000
commit54e0b2f3327e8858a3f4640eeda5f3d8ec223890 (patch)
tree2afec1d80078b0e0b0e716a273bbf5ad59bf88b1 /app/src/main
parenta809cb59c27a01e2bbd155809780f187ae52d355 (diff)
downloadinfinity-for-reddit-54e0b2f3327e8858a3f4640eeda5f3d8ec223890.tar
infinity-for-reddit-54e0b2f3327e8858a3f4640eeda5f3d8ec223890.tar.gz
infinity-for-reddit-54e0b2f3327e8858a3f4640eeda5f3d8ec223890.tar.bz2
infinity-for-reddit-54e0b2f3327e8858a3f4640eeda5f3d8ec223890.tar.lz
infinity-for-reddit-54e0b2f3327e8858a3f4640eeda5f3d8ec223890.tar.xz
infinity-for-reddit-54e0b2f3327e8858a3f4640eeda5f3d8ec223890.tar.zst
infinity-for-reddit-54e0b2f3327e8858a3f4640eeda5f3d8ec223890.zip
Directly adding subreddit to multireddit is available.
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/AndroidManifest.xml9
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java3
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/MultiredditSelectionActivity.java250
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java162
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/adapters/MultiRedditListingRecyclerViewAdapter.java39
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/apis/RedditAPI.java7
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/AddSubredditOrUserToMultiReddit.java43
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/fragments/MultiRedditListingFragment.java66
-rw-r--r--app/src/main/res/layout/activity_multireddit_selection.xml41
-rw-r--r--app/src/main/res/menu/view_subreddit_detail_activity.xml8
-rw-r--r--app/src/main/res/values/strings.xml6
11 files changed, 530 insertions, 104 deletions
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 4cd7c035..4a938525 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -32,7 +32,14 @@
android:theme="@style/AppTheme"
android:usesCleartextTraffic="true"
tools:replace="android:label">
- <activity android:name=".activities.SearchUsersResultActivity"></activity>
+ <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:label="@string/search_users_result_activity_label"
+ android:parentActivityName=".activities.MainActivity"
+ android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".activities.PostFilterUsageListingActivity"
android:parentActivityName=".activities.SettingsActivity"
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java
index d2797aad..e8ad4767 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java
@@ -22,6 +22,7 @@ import ml.docilealligator.infinityforreddit.activities.InboxActivity;
import ml.docilealligator.infinityforreddit.activities.LinkResolverActivity;
import ml.docilealligator.infinityforreddit.activities.LoginActivity;
import ml.docilealligator.infinityforreddit.activities.MainActivity;
+import ml.docilealligator.infinityforreddit.activities.MultiredditSelectionActivity;
import ml.docilealligator.infinityforreddit.activities.PostFilterUsageListingActivity;
import ml.docilealligator.infinityforreddit.activities.PostFilterPreferenceActivity;
import ml.docilealligator.infinityforreddit.activities.PostImageActivity;
@@ -239,4 +240,6 @@ public interface AppComponent {
void inject(PostFilterUsageListingActivity postFilterUsageListingActivity);
void inject(SearchUsersResultActivity searchUsersResultActivity);
+
+ void inject(MultiredditSelectionActivity multiredditSelectionActivity);
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MultiredditSelectionActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MultiredditSelectionActivity.java
new file mode 100644
index 00000000..adc68363
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MultiredditSelectionActivity.java
@@ -0,0 +1,250 @@
+package ml.docilealligator.infinityforreddit.activities;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.os.Build;
+import android.os.Bundle;
+import android.os.Handler;
+import android.view.MenuItem;
+import android.view.View;
+import android.view.Window;
+import android.view.WindowManager;
+import android.widget.Toast;
+
+import androidx.annotation.NonNull;
+import androidx.appcompat.widget.Toolbar;
+import androidx.coordinatorlayout.widget.CoordinatorLayout;
+import androidx.fragment.app.Fragment;
+
+import com.google.android.material.appbar.AppBarLayout;
+import com.r0adkll.slidr.Slidr;
+
+import org.greenrobot.eventbus.EventBus;
+import org.greenrobot.eventbus.Subscribe;
+
+import java.util.ArrayList;
+import java.util.concurrent.Executor;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+
+import butterknife.BindView;
+import butterknife.ButterKnife;
+import ml.docilealligator.infinityforreddit.ActivityToolbarInterface;
+import ml.docilealligator.infinityforreddit.Infinity;
+import ml.docilealligator.infinityforreddit.R;
+import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
+import ml.docilealligator.infinityforreddit.asynctasks.GetCurrentAccount;
+import ml.docilealligator.infinityforreddit.asynctasks.InsertMultiRedditAsyncTask;
+import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
+import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent;
+import ml.docilealligator.infinityforreddit.fragments.MultiRedditListingFragment;
+import ml.docilealligator.infinityforreddit.multireddit.FetchMyMultiReddits;
+import ml.docilealligator.infinityforreddit.multireddit.MultiReddit;
+import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
+import retrofit2.Retrofit;
+
+public class MultiredditSelectionActivity extends BaseActivity implements ActivityToolbarInterface {
+
+ static final String EXTRA_RETURN_MULTIREDDIT = "ERM";
+
+ private static final String INSERT_SUBSCRIBED_MULTIREDDIT_STATE = "ISSS";
+ private static final String NULL_ACCESS_TOKEN_STATE = "NATS";
+ private static final String ACCESS_TOKEN_STATE = "ATS";
+ private static final String ACCOUNT_NAME_STATE = "ANS";
+ private static final String FRAGMENT_OUT_STATE = "FOS";
+
+ @BindView(R.id.coordinator_layout_multireddit_selection_activity)
+ CoordinatorLayout coordinatorLayout;
+ @BindView(R.id.appbar_layout_multireddit_selection_activity)
+ AppBarLayout appBarLayout;
+ @BindView(R.id.toolbar_multireddit_selection_activity)
+ Toolbar toolbar;
+ @Inject
+ @Named("oauth")
+ Retrofit mOauthRetrofit;
+ @Inject
+ RedditDataRoomDatabase mRedditDataRoomDatabase;
+ @Inject
+ @Named("default")
+ SharedPreferences mSharedPreferences;
+ @Inject
+ CustomThemeWrapper mCustomThemeWrapper;
+ @Inject
+ Executor mExecutor;
+ private boolean mNullAccessToken = false;
+ private String mAccessToken;
+ private String mAccountName;
+ private boolean mInsertSuccess = false;
+ private Fragment mFragment;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ ((Infinity) getApplication()).getAppComponent().inject(this);
+
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_multireddit_selection);
+
+ ButterKnife.bind(this);
+
+ EventBus.getDefault().register(this);
+
+ applyCustomTheme();
+
+ if (mSharedPreferences.getBoolean(SharedPreferencesUtils.SWIPE_RIGHT_TO_GO_BACK, true)) {
+ Slidr.attach(this);
+ }
+
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
+ Window window = getWindow();
+
+ if (isChangeStatusBarIconColor()) {
+ addOnOffsetChangedListener(appBarLayout);
+ }
+
+ if (isImmersiveInterface()) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
+ coordinatorLayout.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
+ View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
+ View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
+ } else {
+ window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
+ }
+ adjustToolbar(toolbar);
+ }
+ }
+
+ setSupportActionBar(toolbar);
+ getSupportActionBar().setDisplayHomeAsUpEnabled(true);
+
+ if (savedInstanceState == null) {
+ getCurrentAccountAndBindView();
+ } else {
+ mInsertSuccess = savedInstanceState.getBoolean(INSERT_SUBSCRIBED_MULTIREDDIT_STATE);
+ mNullAccessToken = savedInstanceState.getBoolean(NULL_ACCESS_TOKEN_STATE);
+ mAccessToken = savedInstanceState.getString(ACCESS_TOKEN_STATE);
+ mAccountName = savedInstanceState.getString(ACCOUNT_NAME_STATE);
+
+ if (!mNullAccessToken && mAccountName == null) {
+ getCurrentAccountAndBindView();
+ } else {
+ mFragment = getSupportFragmentManager().getFragment(savedInstanceState, FRAGMENT_OUT_STATE);
+ getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_multireddit_selection_activity, mFragment).commit();
+ bindView(false);
+ }
+ }
+ }
+
+ @Override
+ protected SharedPreferences getDefaultSharedPreferences() {
+ return mSharedPreferences;
+ }
+
+ @Override
+ protected CustomThemeWrapper getCustomThemeWrapper() {
+ return mCustomThemeWrapper;
+ }
+
+ @Override
+ protected void applyCustomTheme() {
+ coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor());
+ applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar);
+ }
+
+ private void getCurrentAccountAndBindView() {
+ GetCurrentAccount.getCurrentAccount(mExecutor, new Handler(), mRedditDataRoomDatabase, account -> {
+ if (account == null) {
+ mNullAccessToken = true;
+ } else {
+ mAccessToken = account.getAccessToken();
+ mAccountName = account.getUsername();
+ }
+ bindView(true);
+ });
+ }
+
+ private void bindView(boolean initializeFragment) {
+ if (isFinishing() || isDestroyed()) {
+ return;
+ }
+
+ loadMultiReddits();
+
+ if (initializeFragment) {
+ mFragment = new MultiRedditListingFragment();
+ Bundle bundle = new Bundle();
+ bundle.putString(MultiRedditListingFragment.EXTRA_ACCOUNT_NAME, mAccountName);
+ bundle.putString(MultiRedditListingFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
+ bundle.putBoolean(MultiRedditListingFragment.EXTRA_IS_GETTING_MULTIREDDIT_INFO, true);
+ mFragment.setArguments(bundle);
+ getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_multireddit_selection_activity, mFragment).commit();
+ }
+ }
+
+ private void loadMultiReddits() {
+ if (!mInsertSuccess) {
+ FetchMyMultiReddits.fetchMyMultiReddits(mOauthRetrofit, mAccessToken, new FetchMyMultiReddits.FetchMyMultiRedditsListener() {
+ @Override
+ public void success(ArrayList<MultiReddit> multiReddits) {
+ new InsertMultiRedditAsyncTask(mRedditDataRoomDatabase, multiReddits, mAccountName, () -> {
+ mInsertSuccess = true;
+ ((MultiRedditListingFragment) mFragment).stopRefreshProgressbar();
+ }).execute();
+ }
+
+ @Override
+ public void failed() {
+ mInsertSuccess = false;
+ ((MultiRedditListingFragment) mFragment).stopRefreshProgressbar();
+ Toast.makeText(MultiredditSelectionActivity.this, R.string.error_loading_multi_reddit_list, Toast.LENGTH_SHORT).show();
+ }
+ });
+ }
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(@NonNull MenuItem item) {
+ if (item.getItemId() == android.R.id.home) {
+ finish();
+ return true;
+ }
+
+ return false;
+ }
+
+ public void getSelectedMultireddit(MultiReddit multiReddit) {
+ Intent returnIntent = new Intent();
+ returnIntent.putExtra(EXTRA_RETURN_MULTIREDDIT, multiReddit);
+ setResult(Activity.RESULT_OK, returnIntent);
+ finish();
+ }
+
+ @Override
+ protected void onSaveInstanceState(@NonNull Bundle outState) {
+ super.onSaveInstanceState(outState);
+ getSupportFragmentManager().putFragment(outState, FRAGMENT_OUT_STATE, mFragment);
+ outState.putBoolean(INSERT_SUBSCRIBED_MULTIREDDIT_STATE, mInsertSuccess);
+ outState.putBoolean(NULL_ACCESS_TOKEN_STATE, mNullAccessToken);
+ outState.putString(ACCESS_TOKEN_STATE, mAccessToken);
+ outState.putString(ACCOUNT_NAME_STATE, mAccountName);
+ }
+
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+ EventBus.getDefault().unregister(this);
+ }
+
+ @Subscribe
+ public void onAccountSwitchEvent(SwitchAccountEvent event) {
+ finish();
+ }
+
+ @Override
+ public void onLongPress() {
+ if (mFragment != null) {
+ ((MultiRedditListingFragment) mFragment).goBackToTop();
+ }
+ }
+} \ No newline at end of file
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java
index fce50705..aa4732fa 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java
@@ -70,6 +70,7 @@ import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.SortType;
import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback;
+import ml.docilealligator.infinityforreddit.asynctasks.AddSubredditOrUserToMultiReddit;
import ml.docilealligator.infinityforreddit.asynctasks.CheckIsSubscribedToSubredditAsyncTask;
import ml.docilealligator.infinityforreddit.asynctasks.GetCurrentAccount;
import ml.docilealligator.infinityforreddit.asynctasks.InsertSubredditDataAsyncTask;
@@ -87,6 +88,7 @@ import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent;
import ml.docilealligator.infinityforreddit.fragments.PostFragment;
import ml.docilealligator.infinityforreddit.fragments.SidebarFragment;
import ml.docilealligator.infinityforreddit.message.ReadMessage;
+import ml.docilealligator.infinityforreddit.multireddit.MultiReddit;
import ml.docilealligator.infinityforreddit.post.Post;
import ml.docilealligator.infinityforreddit.post.PostDataSource;
import ml.docilealligator.infinityforreddit.readpost.InsertReadPost;
@@ -117,6 +119,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
private static final String ACCOUNT_NAME_STATE = "ANS";
private static final String MESSAGE_FULLNAME_STATE = "MFS";
private static final String NEW_ACCOUNT_NAME_STATE = "NANS";
+ private static final int ADD_TO_MULTIREDDIT_REQUEST_CODE = 1;
@BindView(R.id.coordinator_layout_view_subreddit_detail_activity)
CoordinatorLayout coordinatorLayout;
@@ -902,79 +905,114 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
- switch (item.getItemId()) {
- case android.R.id.home:
- finish();
- return true;
- case R.id.action_sort_view_subreddit_detail_activity:
- displaySortTypeBottomSheetFragment();
- return true;
- case R.id.action_search_view_subreddit_detail_activity:
- Intent intent = new Intent(this, SearchActivity.class);
- intent.putExtra(SearchActivity.EXTRA_SUBREDDIT_NAME, subredditName);
- startActivity(intent);
- return true;
- case R.id.action_refresh_view_subreddit_detail_activity:
- if (mMenu != null) {
- mMenu.findItem(R.id.action_lazy_mode_view_subreddit_detail_activity).setTitle(R.string.action_start_lazy_mode);
- }
- if (sectionsPagerAdapter != null) {
- sectionsPagerAdapter.refresh();
- mFetchSubredditInfoSuccess = false;
- fetchSubredditData();
- }
- return true;
- case R.id.action_lazy_mode_view_subreddit_detail_activity:
- if (sectionsPagerAdapter != null) {
- MenuItem lazyModeItem = mMenu.findItem(R.id.action_lazy_mode_view_subreddit_detail_activity);
- if (isInLazyMode) {
- isInLazyMode = false;
- sectionsPagerAdapter.stopLazyMode();
- lazyModeItem.setTitle(R.string.action_start_lazy_mode);
- params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL | AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS |
- AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS_COLLAPSED);
+ int itemId = item.getItemId();
+ if (itemId == android.R.id.home) {
+ finish();
+ return true;
+ } else if (itemId == R.id.action_sort_view_subreddit_detail_activity) {
+ displaySortTypeBottomSheetFragment();
+ return true;
+ } else if (itemId == R.id.action_search_view_subreddit_detail_activity) {
+ Intent intent = new Intent(this, SearchActivity.class);
+ intent.putExtra(SearchActivity.EXTRA_SUBREDDIT_NAME, subredditName);
+ startActivity(intent);
+ return true;
+ } else if (itemId == R.id.action_refresh_view_subreddit_detail_activity) {
+ if (mMenu != null) {
+ mMenu.findItem(R.id.action_lazy_mode_view_subreddit_detail_activity).setTitle(R.string.action_start_lazy_mode);
+ }
+ if (sectionsPagerAdapter != null) {
+ sectionsPagerAdapter.refresh();
+ mFetchSubredditInfoSuccess = false;
+ fetchSubredditData();
+ }
+ return true;
+ } else if (itemId == R.id.action_lazy_mode_view_subreddit_detail_activity) {
+ if (sectionsPagerAdapter != null) {
+ MenuItem lazyModeItem = mMenu.findItem(R.id.action_lazy_mode_view_subreddit_detail_activity);
+ if (isInLazyMode) {
+ isInLazyMode = false;
+ sectionsPagerAdapter.stopLazyMode();
+ lazyModeItem.setTitle(R.string.action_start_lazy_mode);
+ params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL | AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS |
+ AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS_COLLAPSED);
+ collapsingToolbarLayout.setLayoutParams(params);
+ } else {
+ isInLazyMode = true;
+ if (sectionsPagerAdapter.startLazyMode()) {
+ lazyModeItem.setTitle(R.string.action_stop_lazy_mode);
+ appBarLayout.setExpanded(false);
+ params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL | AppBarLayout.LayoutParams.SCROLL_FLAG_EXIT_UNTIL_COLLAPSED);
collapsingToolbarLayout.setLayoutParams(params);
} else {
- isInLazyMode = true;
- if (sectionsPagerAdapter.startLazyMode()) {
- lazyModeItem.setTitle(R.string.action_stop_lazy_mode);
- appBarLayout.setExpanded(false);
- params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL | AppBarLayout.LayoutParams.SCROLL_FLAG_EXIT_UNTIL_COLLAPSED);
- collapsingToolbarLayout.setLayoutParams(params);
- } else {
- isInLazyMode = false;
- }
+ isInLazyMode = false;
}
}
+ }
+ return true;
+ } else if (itemId == R.id.action_change_post_layout_view_subreddit_detail_activity) {
+ PostLayoutBottomSheetFragment postLayoutBottomSheetFragment = new PostLayoutBottomSheetFragment();
+ postLayoutBottomSheetFragment.show(getSupportFragmentManager(), postLayoutBottomSheetFragment.getTag());
+ return true;
+ } else if (itemId == R.id.action_select_user_flair_view_subreddit_detail_activity) {
+ if (mAccessToken == null) {
+ Toast.makeText(this, R.string.login_first, Toast.LENGTH_SHORT).show();
return true;
- case R.id.action_change_post_layout_view_subreddit_detail_activity:
- PostLayoutBottomSheetFragment postLayoutBottomSheetFragment = new PostLayoutBottomSheetFragment();
- postLayoutBottomSheetFragment.show(getSupportFragmentManager(), postLayoutBottomSheetFragment.getTag());
- return true;
- case R.id.action_select_user_flair_view_subreddit_detail_activity:
- if (mAccessToken == null) {
- Toast.makeText(this, R.string.login_first, Toast.LENGTH_SHORT).show();
- return true;
- }
- Intent selectUserFlairIntent = new Intent(this, SelectUserFlairActivity.class);
- selectUserFlairIntent.putExtra(SelectUserFlairActivity.EXTRA_SUBREDDIT_NAME, subredditName);
- startActivity(selectUserFlairIntent);
- return true;
- case R.id.action_share_view_subreddit_detail_activity:
- Intent shareIntent = new Intent(Intent.ACTION_SEND);
- shareIntent.setType("text/plain");
- shareIntent.putExtra(Intent.EXTRA_TEXT, "https://www.reddit.com/r/" + subredditName);
- if (shareIntent.resolveActivity(getPackageManager()) != null) {
- startActivity(Intent.createChooser(shareIntent, getString(R.string.share)));
- } else {
- Toast.makeText(this, R.string.no_app, Toast.LENGTH_SHORT).show();
- }
+ }
+ Intent selectUserFlairIntent = new Intent(this, SelectUserFlairActivity.class);
+ selectUserFlairIntent.putExtra(SelectUserFlairActivity.EXTRA_SUBREDDIT_NAME, subredditName);
+ startActivity(selectUserFlairIntent);
+ return true;
+ } else if (itemId == R.id.action_add_to_multireddit_view_subreddit_detail_activity) {
+ if (mAccessToken == null) {
+ Toast.makeText(this, R.string.login_first, Toast.LENGTH_SHORT).show();
return true;
+ }
+ Intent intent = new Intent(this, MultiredditSelectionActivity.class);
+ startActivityForResult(intent, ADD_TO_MULTIREDDIT_REQUEST_CODE);
+ } else if (itemId == R.id.action_share_view_subreddit_detail_activity) {
+ Intent shareIntent = new Intent(Intent.ACTION_SEND);
+ shareIntent.setType("text/plain");
+ shareIntent.putExtra(Intent.EXTRA_TEXT, "https://www.reddit.com/r/" + subredditName);
+ if (shareIntent.resolveActivity(getPackageManager()) != null) {
+ startActivity(Intent.createChooser(shareIntent, getString(R.string.share)));
+ } else {
+ Toast.makeText(this, R.string.no_app, Toast.LENGTH_SHORT).show();
+ }
+ return true;
}
return false;
}
@Override
+ protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
+ super.onActivityResult(requestCode, resultCode, data);
+ if (requestCode == ADD_TO_MULTIREDDIT_REQUEST_CODE && resultCode == RESULT_OK) {
+ if (data != null) {
+ MultiReddit multiReddit = data.getParcelableExtra(MultiredditSelectionActivity.EXTRA_RETURN_MULTIREDDIT);
+ if (multiReddit != null) {
+ AddSubredditOrUserToMultiReddit.addSubredditOrUserToMultiReddit(mOauthRetrofit,
+ mAccessToken, multiReddit.getPath(), subredditName,
+ new AddSubredditOrUserToMultiReddit.AddSubredditOrUserToMultiRedditListener() {
+ @Override
+ public void success() {
+ Toast.makeText(ViewSubredditDetailActivity.this,
+ getString(R.string.add_subreddit_or_user_to_multireddit_success, subredditName, multiReddit.getDisplayName()), Toast.LENGTH_LONG).show();
+ }
+
+ @Override
+ public void failed(int code) {
+ Toast.makeText(ViewSubredditDetailActivity.this,
+ getString(R.string.add_subreddit_or_user_to_multireddit_failed, subredditName, multiReddit.getDisplayName()), Toast.LENGTH_LONG).show();
+ }
+ });
+ }
+
+ }
+ }
+ }
+
+ @Override
protected void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
outState.putBoolean(FETCH_SUBREDDIT_INFO_STATE, mFetchSubredditInfoSuccess);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/MultiRedditListingRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/MultiRedditListingRecyclerViewAdapter.java
index 7dd20529..5d2d3ef1 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/MultiRedditListingRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/MultiRedditListingRecyclerViewAdapter.java
@@ -1,7 +1,5 @@
package ml.docilealligator.infinityforreddit.adapters;
-import android.content.Intent;
-import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -23,13 +21,11 @@ import butterknife.BindView;
import butterknife.ButterKnife;
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
import me.zhanghai.android.fastscroll.PopupTextProvider;
-import ml.docilealligator.infinityforreddit.activities.ViewMultiRedditDetailActivity;
+import ml.docilealligator.infinityforreddit.R;
+import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
-import ml.docilealligator.infinityforreddit.bottomsheetfragments.MultiRedditOptionsBottomSheetFragment;
import ml.docilealligator.infinityforreddit.multireddit.FavoriteMultiReddit;
import ml.docilealligator.infinityforreddit.multireddit.MultiReddit;
-import ml.docilealligator.infinityforreddit.R;
-import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import pl.droidsonroids.gif.GifImageView;
import retrofit2.Retrofit;
@@ -46,24 +42,29 @@ public class MultiRedditListingRecyclerViewAdapter extends RecyclerView.Adapter<
private RequestManager mGlide;
private String mAccessToken;
- private String mAccountName;
private List<MultiReddit> mMultiReddits;
private List<MultiReddit> mFavoriteMultiReddits;
private int mPrimaryTextColor;
private int mSecondaryTextColor;
+ private OnItemClickListener mOnItemClickListener;
+
+ public interface OnItemClickListener {
+ void onClick(MultiReddit multiReddit);
+ void onLongClick(MultiReddit multiReddit);
+ }
public MultiRedditListingRecyclerViewAdapter(AppCompatActivity activity, Retrofit oauthRetrofit,
RedditDataRoomDatabase redditDataRoomDatabase,
CustomThemeWrapper customThemeWrapper,
- String accessToken, String accountName) {
+ String accessToken, OnItemClickListener onItemClickListener) {
mActivity = activity;
mGlide = Glide.with(activity);
mOauthRetrofit = oauthRetrofit;
mRedditDataRoomDatabase = redditDataRoomDatabase;
mAccessToken = accessToken;
- mAccountName = accountName;
mPrimaryTextColor = customThemeWrapper.getPrimaryTextColor();
mSecondaryTextColor = customThemeWrapper.getSecondaryTextColor();
+ mOnItemClickListener = onItemClickListener;
}
@Override
@@ -176,13 +177,11 @@ public class MultiRedditListingRecyclerViewAdapter extends RecyclerView.Adapter<
}
});
holder.itemView.setOnClickListener(view -> {
- Intent intent = new Intent(mActivity, ViewMultiRedditDetailActivity.class);
- intent.putExtra(ViewMultiRedditDetailActivity.EXTRA_MULTIREDDIT_DATA, multiReddit);
- mActivity.startActivity(intent);
+ mOnItemClickListener.onClick(multiReddit);
});
holder.itemView.setOnLongClickListener(view -> {
- showOptionsBottomSheetFragment(multiReddit);
+ mOnItemClickListener.onLongClick(multiReddit);
return true;
});
@@ -264,13 +263,11 @@ public class MultiRedditListingRecyclerViewAdapter extends RecyclerView.Adapter<
}
});
holder.itemView.setOnClickListener(view -> {
- Intent intent = new Intent(mActivity, ViewMultiRedditDetailActivity.class);
- intent.putExtra(ViewMultiRedditDetailActivity.EXTRA_MULTIREDDIT_DATA, multiReddit);
- mActivity.startActivity(intent);
+ mOnItemClickListener.onClick(multiReddit);
});
holder.itemView.setOnLongClickListener(view -> {
- showOptionsBottomSheetFragment(multiReddit);
+ mOnItemClickListener.onLongClick(multiReddit);
return true;
});
@@ -311,14 +308,6 @@ public class MultiRedditListingRecyclerViewAdapter extends RecyclerView.Adapter<
}
}
- private void showOptionsBottomSheetFragment(MultiReddit multiReddit) {
- MultiRedditOptionsBottomSheetFragment fragment = new MultiRedditOptionsBottomSheetFragment();
- Bundle bundle = new Bundle();
- bundle.putParcelable(MultiRedditOptionsBottomSheetFragment.EXTRA_MULTI_REDDIT, multiReddit);
- fragment.setArguments(bundle);
- fragment.show(mActivity.getSupportFragmentManager(), fragment.getTag());
- }
-
public void setMultiReddits(List<MultiReddit> multiReddits) {
mMultiReddits = multiReddits;
notifyDataSetChanged();
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/apis/RedditAPI.java b/app/src/main/java/ml/docilealligator/infinityforreddit/apis/RedditAPI.java
index 516d6e36..1799ff57 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/apis/RedditAPI.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/apis/RedditAPI.java
@@ -339,4 +339,11 @@ public interface RedditAPI {
@POST("/api/read_all_messages")
Call<String> readAllMessages(@HeaderMap Map<String, String> headers);
+
+
+ @FormUrlEncoded
+ @PUT("/api/multi{multipath}r/{subredditName}")
+ Call<String> addSubredditToMultiReddit(@HeaderMap Map<String, String> headers, @FieldMap Map<String, String> params,
+ @Path(value = "multipath", encoded = true) String multipath, @Path("subredditName") String subredditName);
+
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/AddSubredditOrUserToMultiReddit.java b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/AddSubredditOrUserToMultiReddit.java
new file mode 100644
index 00000000..d69e5f88
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/asynctasks/AddSubredditOrUserToMultiReddit.java
@@ -0,0 +1,43 @@
+package ml.docilealligator.infinityforreddit.asynctasks;
+
+import androidx.annotation.NonNull;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import ml.docilealligator.infinityforreddit.apis.RedditAPI;
+import ml.docilealligator.infinityforreddit.utils.APIUtils;
+import retrofit2.Call;
+import retrofit2.Callback;
+import retrofit2.Response;
+import retrofit2.Retrofit;
+
+public class AddSubredditOrUserToMultiReddit {
+ public interface AddSubredditOrUserToMultiRedditListener {
+ void success();
+ void failed(int code);
+ }
+
+ public static void addSubredditOrUserToMultiReddit(Retrofit oauthRetrofit, String accessToken, String multipath,
+ String subredditName,
+ AddSubredditOrUserToMultiRedditListener addSubredditOrUserToMultiRedditListener) {
+ Map<String, String> params = new HashMap<>();
+ params.put(APIUtils.MODEL_KEY, "{\"name\":\"" + subredditName + "\"}");
+ oauthRetrofit.create(RedditAPI.class).addSubredditToMultiReddit(APIUtils.getOAuthHeader(accessToken), params, multipath, subredditName)
+ .enqueue(new Callback<String>() {
+ @Override
+ public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
+ if (response.isSuccessful()) {
+ addSubredditOrUserToMultiRedditListener.success();
+ } else {
+ addSubredditOrUserToMultiRedditListener.failed(response.code());
+ }
+ }
+
+ @Override
+ public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
+ addSubredditOrUserToMultiRedditListener.failed(-1);
+ }
+ });
+ }
+}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/MultiRedditListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/MultiRedditListingFragment.java
index b9ae3f7b..28f9a0bf 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/MultiRedditListingFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/MultiRedditListingFragment.java
@@ -1,6 +1,7 @@
package ml.docilealligator.infinityforreddit.fragments;
import android.content.Context;
+import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.os.Build;
@@ -13,6 +14,7 @@ import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.annotation.NonNull;
+import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager;
@@ -28,15 +30,19 @@ import javax.inject.Named;
import butterknife.BindView;
import butterknife.ButterKnife;
import me.zhanghai.android.fastscroll.FastScrollerBuilder;
+import ml.docilealligator.infinityforreddit.FragmentCommunicator;
+import ml.docilealligator.infinityforreddit.Infinity;
+import ml.docilealligator.infinityforreddit.R;
+import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.activities.BaseActivity;
+import ml.docilealligator.infinityforreddit.activities.MultiredditSelectionActivity;
import ml.docilealligator.infinityforreddit.activities.SubscribedThingListingActivity;
+import ml.docilealligator.infinityforreddit.activities.ViewMultiRedditDetailActivity;
import ml.docilealligator.infinityforreddit.adapters.MultiRedditListingRecyclerViewAdapter;
+import ml.docilealligator.infinityforreddit.bottomsheetfragments.MultiRedditOptionsBottomSheetFragment;
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
-import ml.docilealligator.infinityforreddit.FragmentCommunicator;
-import ml.docilealligator.infinityforreddit.Infinity;
+import ml.docilealligator.infinityforreddit.multireddit.MultiReddit;
import ml.docilealligator.infinityforreddit.multireddit.MultiRedditViewModel;
-import ml.docilealligator.infinityforreddit.R;
-import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
import retrofit2.Retrofit;
@@ -44,6 +50,7 @@ public class MultiRedditListingFragment extends Fragment implements FragmentComm
public static final String EXTRA_ACCOUNT_NAME = "EAN";
public static final String EXTRA_ACCESS_TOKEN = "EAT";
+ public static final String EXTRA_IS_GETTING_MULTIREDDIT_INFO = "EIGMI";
@BindView(R.id.swipe_refresh_layout_multi_reddit_listing_fragment)
SwipeRefreshLayout mSwipeRefreshLayout;
@@ -67,7 +74,7 @@ public class MultiRedditListingFragment extends Fragment implements FragmentComm
CustomThemeWrapper mCustomThemeWrapper;
public MultiRedditViewModel mMultiRedditViewModel;
- private SubscribedThingListingActivity mActivity;
+ private AppCompatActivity mActivity;
private RequestManager mGlide;
private LinearLayoutManager mLinearLayoutManager;
@@ -86,7 +93,7 @@ public class MultiRedditListingFragment extends Fragment implements FragmentComm
applyTheme();
- if ((mActivity instanceof BaseActivity && ((BaseActivity) mActivity).isImmersiveInterface())) {
+ if ((mActivity != null && ((BaseActivity) mActivity).isImmersiveInterface())) {
mRecyclerView.setPadding(0, 0, 0, ((BaseActivity) mActivity).getNavBarHeight());
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
&& mSharedPreferences.getBoolean(SharedPreferencesUtils.IMMERSIVE_INTERFACE_KEY, true)) {
@@ -99,25 +106,46 @@ public class MultiRedditListingFragment extends Fragment implements FragmentComm
String accountName = getArguments().getString(EXTRA_ACCOUNT_NAME);
String accessToken = getArguments().getString(EXTRA_ACCESS_TOKEN);
+ boolean isGettingMultiredditInfo = getArguments().getBoolean(EXTRA_IS_GETTING_MULTIREDDIT_INFO, false);
mGlide = Glide.with(this);
mLinearLayoutManager = new LinearLayoutManager(mActivity);
mRecyclerView.setLayoutManager(mLinearLayoutManager);
MultiRedditListingRecyclerViewAdapter adapter = new MultiRedditListingRecyclerViewAdapter(mActivity,
- mOauthRetrofit, mRedditDataRoomDatabase, mCustomThemeWrapper, accessToken, accountName);
- mRecyclerView.setAdapter(adapter);
- mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
+ mOauthRetrofit, mRedditDataRoomDatabase, mCustomThemeWrapper, accessToken, new MultiRedditListingRecyclerViewAdapter.OnItemClickListener() {
@Override
- public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
- super.onScrolled(recyclerView, dx, dy);
- if (dy > 0) {
- mActivity.fab.hide();
+ public void onClick(MultiReddit multiReddit) {
+ if (mActivity instanceof MultiredditSelectionActivity) {
+ ((MultiredditSelectionActivity) mActivity).getSelectedMultireddit(multiReddit);
} else {
- mActivity.fab.show();
+ Intent intent = new Intent(mActivity, ViewMultiRedditDetailActivity.class);
+ intent.putExtra(ViewMultiRedditDetailActivity.EXTRA_MULTIREDDIT_DATA, multiReddit);
+ mActivity.startActivity(intent);
+ }
+ }
+
+ @Override
+ public void onLongClick(MultiReddit multiReddit) {
+ if (!isGettingMultiredditInfo) {
+ showOptionsBottomSheetFragment(multiReddit);
}
}
});
+ mRecyclerView.setAdapter(adapter);
+ if (mActivity instanceof SubscribedThingListingActivity) {
+ mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
+ @Override
+ public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
+ super.onScrolled(recyclerView, dx, dy);
+ if (dy > 0) {
+ ((SubscribedThingListingActivity) mActivity).fab.hide();
+ } else {
+ ((SubscribedThingListingActivity) mActivity).fab.show();
+ }
+ }
+ });
+ }
new FastScrollerBuilder(mRecyclerView).build();
mMultiRedditViewModel = new ViewModelProvider(this,
@@ -149,6 +177,14 @@ public class MultiRedditListingFragment extends Fragment implements FragmentComm
return rootView;
}
+ private void showOptionsBottomSheetFragment(MultiReddit multiReddit) {
+ MultiRedditOptionsBottomSheetFragment fragment = new MultiRedditOptionsBottomSheetFragment();
+ Bundle bundle = new Bundle();
+ bundle.putParcelable(MultiRedditOptionsBottomSheetFragment.EXTRA_MULTI_REDDIT, multiReddit);
+ fragment.setArguments(bundle);
+ fragment.show(mActivity.getSupportFragmentManager(), fragment.getTag());
+ }
+
public void goBackToTop() {
if (mLinearLayoutManager != null) {
mLinearLayoutManager.scrollToPositionWithOffset(0, 0);
@@ -158,7 +194,7 @@ public class MultiRedditListingFragment extends Fragment implements FragmentComm
@Override
public void onAttach(@NonNull Context context) {
super.onAttach(context);
- mActivity = (SubscribedThingListingActivity) context;
+ mActivity = (AppCompatActivity) context;
}
@Override
diff --git a/app/src/main/res/layout/activity_multireddit_selection.xml b/app/src/main/res/layout/activity_multireddit_selection.xml
new file mode 100644
index 00000000..4c114742
--- /dev/null
+++ b/app/src/main/res/layout/activity_multireddit_selection.xml
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<androidx.coordinatorlayout.widget.CoordinatorLayout 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:id="@+id/coordinator_layout_multireddit_selection_activity"
+ tools:application=".MultiredditSelectionActivity">
+
+ <com.google.android.material.appbar.AppBarLayout
+ android:id="@+id/appbar_layout_multireddit_selection_activity"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:theme="@style/AppTheme.AppBarOverlay">
+
+ <com.google.android.material.appbar.CollapsingToolbarLayout
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ app:layout_scrollFlags="scroll|enterAlways"
+ app:titleEnabled="false"
+ app:toolbarId="@+id/toolbar_multireddit_selection_activity">
+
+ <androidx.appcompat.widget.Toolbar
+ android:id="@+id/toolbar_multireddit_selection_activity"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:minHeight="?attr/actionBarSize"
+ app:popupTheme="@style/AppTheme.PopupOverlay"
+ app:navigationIcon="?attr/homeAsUpIndicator" />
+
+ </com.google.android.material.appbar.CollapsingToolbarLayout>
+
+ </com.google.android.material.appbar.AppBarLayout>
+
+ <FrameLayout
+ android:id="@+id/frame_layout_multireddit_selection_activity"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ app:layout_behavior="@string/appbar_scrolling_view_behavior" />
+
+</androidx.coordinatorlayout.widget.CoordinatorLayout> \ No newline at end of file
diff --git a/app/src/main/res/menu/view_subreddit_detail_activity.xml b/app/src/main/res/menu/view_subreddit_detail_activity.xml
index f9a8cffc..1144d8e7 100644
--- a/app/src/main/res/menu/view_subreddit_detail_activity.xml
+++ b/app/src/main/res/menu/view_subreddit_detail_activity.xml
@@ -41,8 +41,14 @@
app:showAsAction="never" />
<item
- android:id="@+id/action_share_view_subreddit_detail_activity"
+ android:id="@+id/action_add_to_multireddit_view_subreddit_detail_activity"
android:orderInCategory="7"
+ android:title="@string/action_add_to_multireddit"
+ app:showAsAction="never" />
+
+ <item
+ android:id="@+id/action_share_view_subreddit_detail_activity"
+ android:orderInCategory="8"
android:title="@string/action_share"
app:showAsAction="never" />
</menu>
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 9658a65a..d845d04c 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -37,6 +37,8 @@
<string name="customize_post_filter_activity_label">Customize Post Filter</string>
<string name="filtered_posts_activity_subtitle">Filtered Posts</string>
<string name="post_filter_preference_activity_label">Post Filter</string>
+ <string name="search_users_result_activity_label">Users</string>
+ <string name="multireddit_selection_activity_label">Select a Multireddit</string>
<string name="navigation_drawer_open">Open navigation drawer</string>
<string name="navigation_drawer_close">Close navigation drawer</string>
@@ -76,6 +78,7 @@
<string name="action_give_award">Give Award</string>
<string name="action_save_to_database">Save to Database</string>
<string name="action_read_all_messages">Read All Messages</string>
+ <string name="action_add_to_multireddit">Add to Multireddit</string>
<string name="parse_json_response_error">Error occurred when parsing the JSON response</string>
<string name="retrieve_token_error">Error Retrieving the token</string>
@@ -998,4 +1001,7 @@
<string name="read_all_messages_success">Read all messages successfully</string>
<string name="read_all_messages_failed">Unable to read all messages</string>
+ <string name="add_subreddit_or_user_to_multireddit_success">%1$s is added to multireddit %2$s</string>
+ <string name="add_subreddit_or_user_to_multireddit_failed">Unable to add %1$s to multireddit %2$s</string>
+
</resources>