mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-11-10 20:57:25 +01:00
Directly adding subreddit to multireddit is available.
This commit is contained in:
parent
a809cb59c2
commit
54e0b2f332
@ -32,7 +32,14 @@
|
|||||||
android:theme="@style/AppTheme"
|
android:theme="@style/AppTheme"
|
||||||
android:usesCleartextTraffic="true"
|
android:usesCleartextTraffic="true"
|
||||||
tools:replace="android:label">
|
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
|
<activity
|
||||||
android:name=".activities.PostFilterUsageListingActivity"
|
android:name=".activities.PostFilterUsageListingActivity"
|
||||||
android:parentActivityName=".activities.SettingsActivity"
|
android:parentActivityName=".activities.SettingsActivity"
|
||||||
|
@ -22,6 +22,7 @@ import ml.docilealligator.infinityforreddit.activities.InboxActivity;
|
|||||||
import ml.docilealligator.infinityforreddit.activities.LinkResolverActivity;
|
import ml.docilealligator.infinityforreddit.activities.LinkResolverActivity;
|
||||||
import ml.docilealligator.infinityforreddit.activities.LoginActivity;
|
import ml.docilealligator.infinityforreddit.activities.LoginActivity;
|
||||||
import ml.docilealligator.infinityforreddit.activities.MainActivity;
|
import ml.docilealligator.infinityforreddit.activities.MainActivity;
|
||||||
|
import ml.docilealligator.infinityforreddit.activities.MultiredditSelectionActivity;
|
||||||
import ml.docilealligator.infinityforreddit.activities.PostFilterUsageListingActivity;
|
import ml.docilealligator.infinityforreddit.activities.PostFilterUsageListingActivity;
|
||||||
import ml.docilealligator.infinityforreddit.activities.PostFilterPreferenceActivity;
|
import ml.docilealligator.infinityforreddit.activities.PostFilterPreferenceActivity;
|
||||||
import ml.docilealligator.infinityforreddit.activities.PostImageActivity;
|
import ml.docilealligator.infinityforreddit.activities.PostImageActivity;
|
||||||
@ -239,4 +240,6 @@ public interface AppComponent {
|
|||||||
void inject(PostFilterUsageListingActivity postFilterUsageListingActivity);
|
void inject(PostFilterUsageListingActivity postFilterUsageListingActivity);
|
||||||
|
|
||||||
void inject(SearchUsersResultActivity searchUsersResultActivity);
|
void inject(SearchUsersResultActivity searchUsersResultActivity);
|
||||||
|
|
||||||
|
void inject(MultiredditSelectionActivity multiredditSelectionActivity);
|
||||||
}
|
}
|
||||||
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -70,6 +70,7 @@ import ml.docilealligator.infinityforreddit.R;
|
|||||||
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
||||||
import ml.docilealligator.infinityforreddit.SortType;
|
import ml.docilealligator.infinityforreddit.SortType;
|
||||||
import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback;
|
import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback;
|
||||||
|
import ml.docilealligator.infinityforreddit.asynctasks.AddSubredditOrUserToMultiReddit;
|
||||||
import ml.docilealligator.infinityforreddit.asynctasks.CheckIsSubscribedToSubredditAsyncTask;
|
import ml.docilealligator.infinityforreddit.asynctasks.CheckIsSubscribedToSubredditAsyncTask;
|
||||||
import ml.docilealligator.infinityforreddit.asynctasks.GetCurrentAccount;
|
import ml.docilealligator.infinityforreddit.asynctasks.GetCurrentAccount;
|
||||||
import ml.docilealligator.infinityforreddit.asynctasks.InsertSubredditDataAsyncTask;
|
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.PostFragment;
|
||||||
import ml.docilealligator.infinityforreddit.fragments.SidebarFragment;
|
import ml.docilealligator.infinityforreddit.fragments.SidebarFragment;
|
||||||
import ml.docilealligator.infinityforreddit.message.ReadMessage;
|
import ml.docilealligator.infinityforreddit.message.ReadMessage;
|
||||||
|
import ml.docilealligator.infinityforreddit.multireddit.MultiReddit;
|
||||||
import ml.docilealligator.infinityforreddit.post.Post;
|
import ml.docilealligator.infinityforreddit.post.Post;
|
||||||
import ml.docilealligator.infinityforreddit.post.PostDataSource;
|
import ml.docilealligator.infinityforreddit.post.PostDataSource;
|
||||||
import ml.docilealligator.infinityforreddit.readpost.InsertReadPost;
|
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 ACCOUNT_NAME_STATE = "ANS";
|
||||||
private static final String MESSAGE_FULLNAME_STATE = "MFS";
|
private static final String MESSAGE_FULLNAME_STATE = "MFS";
|
||||||
private static final String NEW_ACCOUNT_NAME_STATE = "NANS";
|
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)
|
@BindView(R.id.coordinator_layout_view_subreddit_detail_activity)
|
||||||
CoordinatorLayout coordinatorLayout;
|
CoordinatorLayout coordinatorLayout;
|
||||||
@ -902,19 +905,19 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
|
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
|
||||||
switch (item.getItemId()) {
|
int itemId = item.getItemId();
|
||||||
case android.R.id.home:
|
if (itemId == android.R.id.home) {
|
||||||
finish();
|
finish();
|
||||||
return true;
|
return true;
|
||||||
case R.id.action_sort_view_subreddit_detail_activity:
|
} else if (itemId == R.id.action_sort_view_subreddit_detail_activity) {
|
||||||
displaySortTypeBottomSheetFragment();
|
displaySortTypeBottomSheetFragment();
|
||||||
return true;
|
return true;
|
||||||
case R.id.action_search_view_subreddit_detail_activity:
|
} else if (itemId == R.id.action_search_view_subreddit_detail_activity) {
|
||||||
Intent intent = new Intent(this, SearchActivity.class);
|
Intent intent = new Intent(this, SearchActivity.class);
|
||||||
intent.putExtra(SearchActivity.EXTRA_SUBREDDIT_NAME, subredditName);
|
intent.putExtra(SearchActivity.EXTRA_SUBREDDIT_NAME, subredditName);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
return true;
|
return true;
|
||||||
case R.id.action_refresh_view_subreddit_detail_activity:
|
} else if (itemId == R.id.action_refresh_view_subreddit_detail_activity) {
|
||||||
if (mMenu != null) {
|
if (mMenu != null) {
|
||||||
mMenu.findItem(R.id.action_lazy_mode_view_subreddit_detail_activity).setTitle(R.string.action_start_lazy_mode);
|
mMenu.findItem(R.id.action_lazy_mode_view_subreddit_detail_activity).setTitle(R.string.action_start_lazy_mode);
|
||||||
}
|
}
|
||||||
@ -924,7 +927,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
|||||||
fetchSubredditData();
|
fetchSubredditData();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
case R.id.action_lazy_mode_view_subreddit_detail_activity:
|
} else if (itemId == R.id.action_lazy_mode_view_subreddit_detail_activity) {
|
||||||
if (sectionsPagerAdapter != null) {
|
if (sectionsPagerAdapter != null) {
|
||||||
MenuItem lazyModeItem = mMenu.findItem(R.id.action_lazy_mode_view_subreddit_detail_activity);
|
MenuItem lazyModeItem = mMenu.findItem(R.id.action_lazy_mode_view_subreddit_detail_activity);
|
||||||
if (isInLazyMode) {
|
if (isInLazyMode) {
|
||||||
@ -947,11 +950,11 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
case R.id.action_change_post_layout_view_subreddit_detail_activity:
|
} else if (itemId == R.id.action_change_post_layout_view_subreddit_detail_activity) {
|
||||||
PostLayoutBottomSheetFragment postLayoutBottomSheetFragment = new PostLayoutBottomSheetFragment();
|
PostLayoutBottomSheetFragment postLayoutBottomSheetFragment = new PostLayoutBottomSheetFragment();
|
||||||
postLayoutBottomSheetFragment.show(getSupportFragmentManager(), postLayoutBottomSheetFragment.getTag());
|
postLayoutBottomSheetFragment.show(getSupportFragmentManager(), postLayoutBottomSheetFragment.getTag());
|
||||||
return true;
|
return true;
|
||||||
case R.id.action_select_user_flair_view_subreddit_detail_activity:
|
} else if (itemId == R.id.action_select_user_flair_view_subreddit_detail_activity) {
|
||||||
if (mAccessToken == null) {
|
if (mAccessToken == null) {
|
||||||
Toast.makeText(this, R.string.login_first, Toast.LENGTH_SHORT).show();
|
Toast.makeText(this, R.string.login_first, Toast.LENGTH_SHORT).show();
|
||||||
return true;
|
return true;
|
||||||
@ -960,7 +963,14 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
|||||||
selectUserFlairIntent.putExtra(SelectUserFlairActivity.EXTRA_SUBREDDIT_NAME, subredditName);
|
selectUserFlairIntent.putExtra(SelectUserFlairActivity.EXTRA_SUBREDDIT_NAME, subredditName);
|
||||||
startActivity(selectUserFlairIntent);
|
startActivity(selectUserFlairIntent);
|
||||||
return true;
|
return true;
|
||||||
case R.id.action_share_view_subreddit_detail_activity:
|
} 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);
|
Intent shareIntent = new Intent(Intent.ACTION_SEND);
|
||||||
shareIntent.setType("text/plain");
|
shareIntent.setType("text/plain");
|
||||||
shareIntent.putExtra(Intent.EXTRA_TEXT, "https://www.reddit.com/r/" + subredditName);
|
shareIntent.putExtra(Intent.EXTRA_TEXT, "https://www.reddit.com/r/" + subredditName);
|
||||||
@ -974,6 +984,34 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
|||||||
return false;
|
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
|
@Override
|
||||||
protected void onSaveInstanceState(@NonNull Bundle outState) {
|
protected void onSaveInstanceState(@NonNull Bundle outState) {
|
||||||
super.onSaveInstanceState(outState);
|
super.onSaveInstanceState(outState);
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
package ml.docilealligator.infinityforreddit.adapters;
|
package ml.docilealligator.infinityforreddit.adapters;
|
||||||
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
@ -23,13 +21,11 @@ import butterknife.BindView;
|
|||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
|
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
|
||||||
import me.zhanghai.android.fastscroll.PopupTextProvider;
|
import me.zhanghai.android.fastscroll.PopupTextProvider;
|
||||||
import ml.docilealligator.infinityforreddit.activities.ViewMultiRedditDetailActivity;
|
|
||||||
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.R;
|
||||||
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
||||||
|
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
|
||||||
|
import ml.docilealligator.infinityforreddit.multireddit.FavoriteMultiReddit;
|
||||||
|
import ml.docilealligator.infinityforreddit.multireddit.MultiReddit;
|
||||||
import pl.droidsonroids.gif.GifImageView;
|
import pl.droidsonroids.gif.GifImageView;
|
||||||
import retrofit2.Retrofit;
|
import retrofit2.Retrofit;
|
||||||
|
|
||||||
@ -46,24 +42,29 @@ public class MultiRedditListingRecyclerViewAdapter extends RecyclerView.Adapter<
|
|||||||
private RequestManager mGlide;
|
private RequestManager mGlide;
|
||||||
|
|
||||||
private String mAccessToken;
|
private String mAccessToken;
|
||||||
private String mAccountName;
|
|
||||||
private List<MultiReddit> mMultiReddits;
|
private List<MultiReddit> mMultiReddits;
|
||||||
private List<MultiReddit> mFavoriteMultiReddits;
|
private List<MultiReddit> mFavoriteMultiReddits;
|
||||||
private int mPrimaryTextColor;
|
private int mPrimaryTextColor;
|
||||||
private int mSecondaryTextColor;
|
private int mSecondaryTextColor;
|
||||||
|
private OnItemClickListener mOnItemClickListener;
|
||||||
|
|
||||||
|
public interface OnItemClickListener {
|
||||||
|
void onClick(MultiReddit multiReddit);
|
||||||
|
void onLongClick(MultiReddit multiReddit);
|
||||||
|
}
|
||||||
|
|
||||||
public MultiRedditListingRecyclerViewAdapter(AppCompatActivity activity, Retrofit oauthRetrofit,
|
public MultiRedditListingRecyclerViewAdapter(AppCompatActivity activity, Retrofit oauthRetrofit,
|
||||||
RedditDataRoomDatabase redditDataRoomDatabase,
|
RedditDataRoomDatabase redditDataRoomDatabase,
|
||||||
CustomThemeWrapper customThemeWrapper,
|
CustomThemeWrapper customThemeWrapper,
|
||||||
String accessToken, String accountName) {
|
String accessToken, OnItemClickListener onItemClickListener) {
|
||||||
mActivity = activity;
|
mActivity = activity;
|
||||||
mGlide = Glide.with(activity);
|
mGlide = Glide.with(activity);
|
||||||
mOauthRetrofit = oauthRetrofit;
|
mOauthRetrofit = oauthRetrofit;
|
||||||
mRedditDataRoomDatabase = redditDataRoomDatabase;
|
mRedditDataRoomDatabase = redditDataRoomDatabase;
|
||||||
mAccessToken = accessToken;
|
mAccessToken = accessToken;
|
||||||
mAccountName = accountName;
|
|
||||||
mPrimaryTextColor = customThemeWrapper.getPrimaryTextColor();
|
mPrimaryTextColor = customThemeWrapper.getPrimaryTextColor();
|
||||||
mSecondaryTextColor = customThemeWrapper.getSecondaryTextColor();
|
mSecondaryTextColor = customThemeWrapper.getSecondaryTextColor();
|
||||||
|
mOnItemClickListener = onItemClickListener;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -176,13 +177,11 @@ public class MultiRedditListingRecyclerViewAdapter extends RecyclerView.Adapter<
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
holder.itemView.setOnClickListener(view -> {
|
holder.itemView.setOnClickListener(view -> {
|
||||||
Intent intent = new Intent(mActivity, ViewMultiRedditDetailActivity.class);
|
mOnItemClickListener.onClick(multiReddit);
|
||||||
intent.putExtra(ViewMultiRedditDetailActivity.EXTRA_MULTIREDDIT_DATA, multiReddit);
|
|
||||||
mActivity.startActivity(intent);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
holder.itemView.setOnLongClickListener(view -> {
|
holder.itemView.setOnLongClickListener(view -> {
|
||||||
showOptionsBottomSheetFragment(multiReddit);
|
mOnItemClickListener.onLongClick(multiReddit);
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -264,13 +263,11 @@ public class MultiRedditListingRecyclerViewAdapter extends RecyclerView.Adapter<
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
holder.itemView.setOnClickListener(view -> {
|
holder.itemView.setOnClickListener(view -> {
|
||||||
Intent intent = new Intent(mActivity, ViewMultiRedditDetailActivity.class);
|
mOnItemClickListener.onClick(multiReddit);
|
||||||
intent.putExtra(ViewMultiRedditDetailActivity.EXTRA_MULTIREDDIT_DATA, multiReddit);
|
|
||||||
mActivity.startActivity(intent);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
holder.itemView.setOnLongClickListener(view -> {
|
holder.itemView.setOnLongClickListener(view -> {
|
||||||
showOptionsBottomSheetFragment(multiReddit);
|
mOnItemClickListener.onLongClick(multiReddit);
|
||||||
return true;
|
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) {
|
public void setMultiReddits(List<MultiReddit> multiReddits) {
|
||||||
mMultiReddits = multiReddits;
|
mMultiReddits = multiReddits;
|
||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
|
@ -339,4 +339,11 @@ public interface RedditAPI {
|
|||||||
|
|
||||||
@POST("/api/read_all_messages")
|
@POST("/api/read_all_messages")
|
||||||
Call<String> readAllMessages(@HeaderMap Map<String, String> headers);
|
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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,7 @@
|
|||||||
package ml.docilealligator.infinityforreddit.fragments;
|
package ml.docilealligator.infinityforreddit.fragments;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
@ -13,6 +14,7 @@ import android.widget.LinearLayout;
|
|||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
import androidx.lifecycle.ViewModelProvider;
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
@ -28,15 +30,19 @@ import javax.inject.Named;
|
|||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
import me.zhanghai.android.fastscroll.FastScrollerBuilder;
|
import me.zhanghai.android.fastscroll.FastScrollerBuilder;
|
||||||
import ml.docilealligator.infinityforreddit.activities.BaseActivity;
|
|
||||||
import ml.docilealligator.infinityforreddit.activities.SubscribedThingListingActivity;
|
|
||||||
import ml.docilealligator.infinityforreddit.adapters.MultiRedditListingRecyclerViewAdapter;
|
|
||||||
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
|
|
||||||
import ml.docilealligator.infinityforreddit.FragmentCommunicator;
|
import ml.docilealligator.infinityforreddit.FragmentCommunicator;
|
||||||
import ml.docilealligator.infinityforreddit.Infinity;
|
import ml.docilealligator.infinityforreddit.Infinity;
|
||||||
import ml.docilealligator.infinityforreddit.multireddit.MultiRedditViewModel;
|
|
||||||
import ml.docilealligator.infinityforreddit.R;
|
import ml.docilealligator.infinityforreddit.R;
|
||||||
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
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.multireddit.MultiReddit;
|
||||||
|
import ml.docilealligator.infinityforreddit.multireddit.MultiRedditViewModel;
|
||||||
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
|
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
|
||||||
import retrofit2.Retrofit;
|
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_ACCOUNT_NAME = "EAN";
|
||||||
public static final String EXTRA_ACCESS_TOKEN = "EAT";
|
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)
|
@BindView(R.id.swipe_refresh_layout_multi_reddit_listing_fragment)
|
||||||
SwipeRefreshLayout mSwipeRefreshLayout;
|
SwipeRefreshLayout mSwipeRefreshLayout;
|
||||||
@ -67,7 +74,7 @@ public class MultiRedditListingFragment extends Fragment implements FragmentComm
|
|||||||
CustomThemeWrapper mCustomThemeWrapper;
|
CustomThemeWrapper mCustomThemeWrapper;
|
||||||
|
|
||||||
public MultiRedditViewModel mMultiRedditViewModel;
|
public MultiRedditViewModel mMultiRedditViewModel;
|
||||||
private SubscribedThingListingActivity mActivity;
|
private AppCompatActivity mActivity;
|
||||||
private RequestManager mGlide;
|
private RequestManager mGlide;
|
||||||
private LinearLayoutManager mLinearLayoutManager;
|
private LinearLayoutManager mLinearLayoutManager;
|
||||||
|
|
||||||
@ -86,7 +93,7 @@ public class MultiRedditListingFragment extends Fragment implements FragmentComm
|
|||||||
|
|
||||||
applyTheme();
|
applyTheme();
|
||||||
|
|
||||||
if ((mActivity instanceof BaseActivity && ((BaseActivity) mActivity).isImmersiveInterface())) {
|
if ((mActivity != null && ((BaseActivity) mActivity).isImmersiveInterface())) {
|
||||||
mRecyclerView.setPadding(0, 0, 0, ((BaseActivity) mActivity).getNavBarHeight());
|
mRecyclerView.setPadding(0, 0, 0, ((BaseActivity) mActivity).getNavBarHeight());
|
||||||
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
|
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
|
||||||
&& mSharedPreferences.getBoolean(SharedPreferencesUtils.IMMERSIVE_INTERFACE_KEY, true)) {
|
&& 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 accountName = getArguments().getString(EXTRA_ACCOUNT_NAME);
|
||||||
String accessToken = getArguments().getString(EXTRA_ACCESS_TOKEN);
|
String accessToken = getArguments().getString(EXTRA_ACCESS_TOKEN);
|
||||||
|
boolean isGettingMultiredditInfo = getArguments().getBoolean(EXTRA_IS_GETTING_MULTIREDDIT_INFO, false);
|
||||||
|
|
||||||
mGlide = Glide.with(this);
|
mGlide = Glide.with(this);
|
||||||
|
|
||||||
mLinearLayoutManager = new LinearLayoutManager(mActivity);
|
mLinearLayoutManager = new LinearLayoutManager(mActivity);
|
||||||
mRecyclerView.setLayoutManager(mLinearLayoutManager);
|
mRecyclerView.setLayoutManager(mLinearLayoutManager);
|
||||||
MultiRedditListingRecyclerViewAdapter adapter = new MultiRedditListingRecyclerViewAdapter(mActivity,
|
MultiRedditListingRecyclerViewAdapter adapter = new MultiRedditListingRecyclerViewAdapter(mActivity,
|
||||||
mOauthRetrofit, mRedditDataRoomDatabase, mCustomThemeWrapper, accessToken, accountName);
|
mOauthRetrofit, mRedditDataRoomDatabase, mCustomThemeWrapper, accessToken, new MultiRedditListingRecyclerViewAdapter.OnItemClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(MultiReddit multiReddit) {
|
||||||
|
if (mActivity instanceof MultiredditSelectionActivity) {
|
||||||
|
((MultiredditSelectionActivity) mActivity).getSelectedMultireddit(multiReddit);
|
||||||
|
} else {
|
||||||
|
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);
|
mRecyclerView.setAdapter(adapter);
|
||||||
|
if (mActivity instanceof SubscribedThingListingActivity) {
|
||||||
mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
|
mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
|
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
|
||||||
super.onScrolled(recyclerView, dx, dy);
|
super.onScrolled(recyclerView, dx, dy);
|
||||||
if (dy > 0) {
|
if (dy > 0) {
|
||||||
mActivity.fab.hide();
|
((SubscribedThingListingActivity) mActivity).fab.hide();
|
||||||
} else {
|
} else {
|
||||||
mActivity.fab.show();
|
((SubscribedThingListingActivity) mActivity).fab.show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
new FastScrollerBuilder(mRecyclerView).build();
|
new FastScrollerBuilder(mRecyclerView).build();
|
||||||
|
|
||||||
mMultiRedditViewModel = new ViewModelProvider(this,
|
mMultiRedditViewModel = new ViewModelProvider(this,
|
||||||
@ -149,6 +177,14 @@ public class MultiRedditListingFragment extends Fragment implements FragmentComm
|
|||||||
return rootView;
|
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() {
|
public void goBackToTop() {
|
||||||
if (mLinearLayoutManager != null) {
|
if (mLinearLayoutManager != null) {
|
||||||
mLinearLayoutManager.scrollToPositionWithOffset(0, 0);
|
mLinearLayoutManager.scrollToPositionWithOffset(0, 0);
|
||||||
@ -158,7 +194,7 @@ public class MultiRedditListingFragment extends Fragment implements FragmentComm
|
|||||||
@Override
|
@Override
|
||||||
public void onAttach(@NonNull Context context) {
|
public void onAttach(@NonNull Context context) {
|
||||||
super.onAttach(context);
|
super.onAttach(context);
|
||||||
mActivity = (SubscribedThingListingActivity) context;
|
mActivity = (AppCompatActivity) context;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
41
app/src/main/res/layout/activity_multireddit_selection.xml
Normal file
41
app/src/main/res/layout/activity_multireddit_selection.xml
Normal file
@ -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>
|
@ -41,8 +41,14 @@
|
|||||||
app:showAsAction="never" />
|
app:showAsAction="never" />
|
||||||
|
|
||||||
<item
|
<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: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"
|
android:title="@string/action_share"
|
||||||
app:showAsAction="never" />
|
app:showAsAction="never" />
|
||||||
</menu>
|
</menu>
|
||||||
|
@ -37,6 +37,8 @@
|
|||||||
<string name="customize_post_filter_activity_label">Customize Post Filter</string>
|
<string name="customize_post_filter_activity_label">Customize Post Filter</string>
|
||||||
<string name="filtered_posts_activity_subtitle">Filtered Posts</string>
|
<string name="filtered_posts_activity_subtitle">Filtered Posts</string>
|
||||||
<string name="post_filter_preference_activity_label">Post Filter</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_open">Open navigation drawer</string>
|
||||||
<string name="navigation_drawer_close">Close 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_give_award">Give Award</string>
|
||||||
<string name="action_save_to_database">Save to Database</string>
|
<string name="action_save_to_database">Save to Database</string>
|
||||||
<string name="action_read_all_messages">Read All Messages</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="parse_json_response_error">Error occurred when parsing the JSON response</string>
|
||||||
<string name="retrieve_token_error">Error Retrieving the token</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_success">Read all messages successfully</string>
|
||||||
<string name="read_all_messages_failed">Unable to read all messages</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>
|
</resources>
|
||||||
|
Loading…
Reference in New Issue
Block a user