mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-11-10 20:57:25 +01:00
Fix updating flair in ViewPostDetailFragment.
This commit is contained in:
parent
288f1777d9
commit
b2aff0c047
@ -44,14 +44,12 @@ import javax.inject.Named;
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import ml.docilealligator.infinityforreddit.ActivityToolbarInterface;
|
||||
import ml.docilealligator.infinityforreddit.Flair;
|
||||
import ml.docilealligator.infinityforreddit.Infinity;
|
||||
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.SwitchAccount;
|
||||
import ml.docilealligator.infinityforreddit.bottomsheetfragments.FlairBottomSheetFragment;
|
||||
import ml.docilealligator.infinityforreddit.comment.Comment;
|
||||
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
|
||||
import ml.docilealligator.infinityforreddit.events.NeedForPostListFromPostFragmentEvent;
|
||||
@ -62,8 +60,7 @@ import ml.docilealligator.infinityforreddit.fragments.ViewPostDetailFragment;
|
||||
import ml.docilealligator.infinityforreddit.post.Post;
|
||||
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
|
||||
|
||||
public class ViewPostDetailActivity extends BaseActivity implements FlairBottomSheetFragment.FlairSelectionCallback,
|
||||
SortTypeSelectionCallback, ActivityToolbarInterface {
|
||||
public class ViewPostDetailActivity extends BaseActivity implements SortTypeSelectionCallback, ActivityToolbarInterface {
|
||||
|
||||
public static final String EXTRA_POST_DATA = "EPD";
|
||||
public static final String EXTRA_POST_ID = "EPI";
|
||||
@ -386,14 +383,6 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS
|
||||
return super.onKeyDown(keyCode, event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flairSelected(Flair flair) {
|
||||
ViewPostDetailFragment fragment = sectionsPagerAdapter.getCurrentFragment();
|
||||
if (fragment != null) {
|
||||
fragment.changeFlair(flair);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sortTypeSelected(SortType sortType) {
|
||||
ViewPostDetailFragment fragment = sectionsPagerAdapter.getCurrentFragment();
|
||||
|
@ -17,6 +17,8 @@ import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.inject.Inject;
|
||||
@ -30,6 +32,7 @@ import ml.docilealligator.infinityforreddit.FetchFlairs;
|
||||
import ml.docilealligator.infinityforreddit.Flair;
|
||||
import ml.docilealligator.infinityforreddit.Infinity;
|
||||
import ml.docilealligator.infinityforreddit.R;
|
||||
import ml.docilealligator.infinityforreddit.events.FlairSelectedEvent;
|
||||
import retrofit2.Retrofit;
|
||||
|
||||
|
||||
@ -40,6 +43,7 @@ public class FlairBottomSheetFragment extends BottomSheetDialogFragment {
|
||||
|
||||
public static final String EXTRA_ACCESS_TOKEN = "EAT";
|
||||
public static final String EXTRA_SUBREDDIT_NAME = "ESN";
|
||||
public static final String EXTRA_VIEW_POST_DETAIL_FRAGMENT_ID = "EPFI";
|
||||
@BindView(R.id.progress_bar_flair_bottom_sheet_fragment)
|
||||
ProgressBar progressBar;
|
||||
@BindView(R.id.error_text_view_flair_bottom_sheet_fragment)
|
||||
@ -72,8 +76,14 @@ public class FlairBottomSheetFragment extends BottomSheetDialogFragment {
|
||||
|
||||
((Infinity) mActivity.getApplication()).getAppComponent().inject(this);
|
||||
|
||||
long viewPostFragmentId = getArguments().getLong(EXTRA_VIEW_POST_DETAIL_FRAGMENT_ID, -1);
|
||||
mAdapter = new FlairBottomSheetRecyclerViewAdapter(mActivity, mCustomThemeWrapper, flair -> {
|
||||
((FlairSelectionCallback) mActivity).flairSelected(flair);
|
||||
if (viewPostFragmentId <= 0) {
|
||||
//PostXXXActivity
|
||||
((FlairSelectionCallback) mActivity).flairSelected(flair);
|
||||
} else {
|
||||
EventBus.getDefault().post(new FlairSelectedEvent(viewPostFragmentId, flair));
|
||||
}
|
||||
dismiss();
|
||||
});
|
||||
|
||||
|
@ -0,0 +1,13 @@
|
||||
package ml.docilealligator.infinityforreddit.events;
|
||||
|
||||
import ml.docilealligator.infinityforreddit.Flair;
|
||||
|
||||
public class FlairSelectedEvent {
|
||||
public long viewPostDetailFragmentId;
|
||||
public Flair flair;
|
||||
|
||||
public FlairSelectedEvent(long viewPostDetailFragmentId, Flair flair) {
|
||||
this.viewPostDetailFragmentId = viewPostDetailFragmentId;
|
||||
this.flair = flair;
|
||||
}
|
||||
}
|
@ -88,6 +88,7 @@ import ml.docilealligator.infinityforreddit.customviews.CustomToroContainer;
|
||||
import ml.docilealligator.infinityforreddit.events.ChangeNSFWBlurEvent;
|
||||
import ml.docilealligator.infinityforreddit.events.ChangeNetworkStatusEvent;
|
||||
import ml.docilealligator.infinityforreddit.events.ChangeSpoilerBlurEvent;
|
||||
import ml.docilealligator.infinityforreddit.events.FlairSelectedEvent;
|
||||
import ml.docilealligator.infinityforreddit.events.PostUpdateEventToDetailActivity;
|
||||
import ml.docilealligator.infinityforreddit.events.PostUpdateEventToPostList;
|
||||
import ml.docilealligator.infinityforreddit.message.ReadMessage;
|
||||
@ -191,6 +192,8 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
|
||||
String sortType;
|
||||
@State
|
||||
boolean mRespectSubredditRecommendedSortType;
|
||||
@State
|
||||
long viewPostDetailFragmentId;
|
||||
private ViewPostDetailActivity activity;
|
||||
private RequestManager mGlide;
|
||||
private Locale mLocale;
|
||||
@ -262,6 +265,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
|
||||
mExpandChildren = !mSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_TOP_LEVEL_COMMENTS_FIRST, false);
|
||||
if (savedInstanceState == null) {
|
||||
mRespectSubredditRecommendedSortType = mSharedPreferences.getBoolean(SharedPreferencesUtils.RESPECT_SUBREDDIT_RECOMMENDED_COMMENT_SORT_TYPE, false);
|
||||
viewPostDetailFragmentId = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
mGlide = Glide.with(this);
|
||||
@ -915,6 +919,7 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(FlairBottomSheetFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
||||
bundle.putString(FlairBottomSheetFragment.EXTRA_SUBREDDIT_NAME, mPost.getSubredditName());
|
||||
bundle.putLong(FlairBottomSheetFragment.EXTRA_VIEW_POST_DETAIL_FRAGMENT_ID, viewPostDetailFragmentId);
|
||||
flairBottomSheetFragment.setArguments(bundle);
|
||||
flairBottomSheetFragment.show(activity.getSupportFragmentManager(), flairBottomSheetFragment.getTag());
|
||||
return true;
|
||||
@ -1724,6 +1729,13 @@ public class ViewPostDetailFragment extends Fragment implements FragmentCommunic
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onFlairSelectedEvent(FlairSelectedEvent event) {
|
||||
if (event.viewPostDetailFragmentId == viewPostDetailFragmentId) {
|
||||
changeFlair(event.flair);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(@NonNull Context context) {
|
||||
super.onAttach(context);
|
||||
|
Loading…
Reference in New Issue
Block a user