Changing post layout in other activities is available. Show username in card layout posts.

This commit is contained in:
Alex Ning 2019-11-11 15:27:11 +08:00
parent a3ae945e39
commit d7928436fe
11 changed files with 151 additions and 17 deletions

View File

@ -31,6 +31,7 @@ import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask
import ml.docilealligator.infinityforreddit.Event.ChangeNSFWEvent;
import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent;
import ml.docilealligator.infinityforreddit.Fragment.PostFragment;
import ml.docilealligator.infinityforreddit.Fragment.PostLayoutBottomSheetFragment;
import ml.docilealligator.infinityforreddit.FragmentCommunicator;
import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.PostDataSource;
@ -40,7 +41,7 @@ import ml.docilealligator.infinityforreddit.SharedPreferencesUtils;
import ml.docilealligator.infinityforreddit.SortType;
import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback;
public class AccountPostsActivity extends BaseActivity implements SortTypeSelectionCallback {
public class AccountPostsActivity extends BaseActivity implements SortTypeSelectionCallback, PostLayoutBottomSheetFragment.PostLayoutSelectionCallback {
static final String EXTRA_USER_WHERE = "EUW";
@ -68,6 +69,7 @@ public class AccountPostsActivity extends BaseActivity implements SortTypeSelect
private Fragment mFragment;
private Menu mMenu;
private AppBarLayout.LayoutParams params;
private PostLayoutBottomSheetFragment postLayoutBottomSheetFragment;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -139,6 +141,8 @@ public class AccountPostsActivity extends BaseActivity implements SortTypeSelect
params = (AppBarLayout.LayoutParams) collapsingToolbarLayout.getLayoutParams();
postLayoutBottomSheetFragment = new PostLayoutBottomSheetFragment();
if (savedInstanceState != null) {
mNullAccessToken = savedInstanceState.getBoolean(NULL_ACCESS_TOKEN_STATE);
mAccessToken = savedInstanceState.getString(ACCESS_TOKEN_STATE);
@ -229,6 +233,9 @@ public class AccountPostsActivity extends BaseActivity implements SortTypeSelect
}
}
return true;
case R.id.action_change_post_layout_account_posts_activity:
postLayoutBottomSheetFragment.show(getSupportFragmentManager(), postLayoutBottomSheetFragment.getTag());
return true;
case android.R.id.home:
finish();
return true;
@ -275,4 +282,12 @@ public class AccountPostsActivity extends BaseActivity implements SortTypeSelect
public void onChangeNSFWEvent(ChangeNSFWEvent changeNSFWEvent) {
((FragmentCommunicator) mFragment).changeNSFW(changeNSFWEvent.nsfw);
}
@Override
public void postLayoutSelected(int postLayout) {
if (mFragment != null) {
mSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_USER_POST, postLayout).apply();
((FragmentCommunicator) mFragment).changePostLayout(postLayout);
}
}
}

View File

@ -30,6 +30,7 @@ import ml.docilealligator.infinityforreddit.AppBarStateChangeListener;
import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask;
import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent;
import ml.docilealligator.infinityforreddit.Fragment.PostFragment;
import ml.docilealligator.infinityforreddit.Fragment.PostLayoutBottomSheetFragment;
import ml.docilealligator.infinityforreddit.Fragment.SearchPostSortTypeBottomSheetFragment;
import ml.docilealligator.infinityforreddit.Fragment.SortTimeBottomSheetFragment;
import ml.docilealligator.infinityforreddit.Fragment.SortTypeBottomSheetFragment;
@ -44,7 +45,8 @@ import ml.docilealligator.infinityforreddit.SharedPreferencesUtils;
import ml.docilealligator.infinityforreddit.SortType;
import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback;
public class FilteredThingActivity extends BaseActivity implements SortTypeSelectionCallback {
public class FilteredThingActivity extends BaseActivity implements SortTypeSelectionCallback,
PostLayoutBottomSheetFragment.PostLayoutSelectionCallback {
public static final String EXTRA_NAME = "ESN";
public static final String EXTRA_QUERY = "EQ";
@ -82,6 +84,7 @@ public class FilteredThingActivity extends BaseActivity implements SortTypeSelec
private UserThingSortTypeBottomSheetFragment userThingSortTypeBottomSheetFragment;
private SearchPostSortTypeBottomSheetFragment searchPostSortTypeBottomSheetFragment;
private SortTimeBottomSheetFragment sortTimeBottomSheetFragment;
private PostLayoutBottomSheetFragment postLayoutBottomSheetFragment;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -169,6 +172,8 @@ public class FilteredThingActivity extends BaseActivity implements SortTypeSelec
} else {
getCurrentAccountAndBindView(filter);
}
postLayoutBottomSheetFragment = new PostLayoutBottomSheetFragment();
}
@Override
@ -344,6 +349,9 @@ public class FilteredThingActivity extends BaseActivity implements SortTypeSelec
}
}
return true;
case R.id.action_change_post_layout_filtered_post_activity:
postLayoutBottomSheetFragment.show(getSupportFragmentManager(), postLayoutBottomSheetFragment.getTag());
return true;
}
return false;
}
@ -368,6 +376,26 @@ public class FilteredThingActivity extends BaseActivity implements SortTypeSelec
((PostFragment) mFragment).changeSortType(sortType);
}
@Override
public void postLayoutSelected(int postLayout) {
if (mFragment != null) {
switch (postType) {
case PostDataSource.TYPE_FRONT_PAGE:
mSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_FRONT_PAGE_POST, postLayout).apply();
break;
case PostDataSource.TYPE_SUBREDDIT:
mSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_SUBREDDIT_POST, postLayout).apply();
break;
case PostDataSource.TYPE_USER:
mSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_USER_POST, postLayout).apply();
break;
case PostDataSource.TYPE_SEARCH:
mSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_SEARCH_POST, postLayout).apply();
}
((FragmentCommunicator) mFragment).changePostLayout(postLayout);
}
}
@Override
public void sortTypeSelected(String sortType) {
Bundle bundle = new Bundle();

View File

@ -35,6 +35,7 @@ import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask
import ml.docilealligator.infinityforreddit.Event.ChangeNSFWEvent;
import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent;
import ml.docilealligator.infinityforreddit.Fragment.PostFragment;
import ml.docilealligator.infinityforreddit.Fragment.PostLayoutBottomSheetFragment;
import ml.docilealligator.infinityforreddit.Fragment.SearchPostSortTypeBottomSheetFragment;
import ml.docilealligator.infinityforreddit.Fragment.SearchUserAndSubredditSortTypeBottomSheetFragment;
import ml.docilealligator.infinityforreddit.Fragment.SortTimeBottomSheetFragment;
@ -49,7 +50,8 @@ import ml.docilealligator.infinityforreddit.SharedPreferencesUtils;
import ml.docilealligator.infinityforreddit.SortType;
import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback;
public class SearchResultActivity extends BaseActivity implements SortTypeSelectionCallback {
public class SearchResultActivity extends BaseActivity implements SortTypeSelectionCallback,
PostLayoutBottomSheetFragment.PostLayoutSelectionCallback {
static final String EXTRA_QUERY = "QK";
static final String EXTRA_SUBREDDIT_NAME = "ESN";
@ -77,6 +79,7 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
private SearchPostSortTypeBottomSheetFragment searchPostSortTypeBottomSheetFragment;
private SortTimeBottomSheetFragment sortTimeBottomSheetFragment;
private SearchUserAndSubredditSortTypeBottomSheetFragment searchUserAndSubredditSortTypeBottomSheetFragment;
private PostLayoutBottomSheetFragment postLayoutBottomSheetFragment;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -153,6 +156,8 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
searchUserAndSubredditSortTypeBottomSheetFragment = new SearchUserAndSubredditSortTypeBottomSheetFragment();
postLayoutBottomSheetFragment = new PostLayoutBottomSheetFragment();
// Get the intent, verify the action and get the query
Intent intent = getIntent();
String query = intent.getStringExtra(EXTRA_QUERY);
@ -226,6 +231,9 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
case R.id.action_refresh_search_result_activity:
sectionsPagerAdapter.refresh();
return true;
case R.id.action_change_post_layout_search_result_activity:
postLayoutBottomSheetFragment.show(getSupportFragmentManager(), postLayoutBottomSheetFragment.getTag());
return true;
}
return super.onOptionsItemSelected(item);
}
@ -262,6 +270,11 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
sectionsPagerAdapter.changeSortType(sortType, fragmentPosition);
}
@Override
public void postLayoutSelected(int postLayout) {
sectionsPagerAdapter.changePostLayout(postLayout);
}
@Subscribe
public void onAccountSwitchEvent(SwitchAccountEvent event) {
finish();
@ -395,5 +408,12 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
postFragment.changeNSFW(nsfw);
}
}
void changePostLayout(int postLayout) {
if (postFragment != null) {
mSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_SEARCH_POST, postLayout).apply();
((FragmentCommunicator) postFragment).changePostLayout(postLayout);
}
}
}
}

View File

@ -507,7 +507,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
intent.putExtra(SearchActivity.EXTRA_SUBREDDIT_IS_USER, false);
intent.putExtra(SearchActivity.EXTRA_SEARCH_ONLY_SUBREDDITS, false);
startActivity(intent);
break;
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);
@ -517,7 +517,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
mFetchSubredditInfoSuccess = false;
fetchSubredditData();
}
break;
return true;
case R.id.action_lazy_mode_view_subreddit_detail_activity:
MenuItem lazyModeItem = mMenu.findItem(R.id.action_lazy_mode_view_subreddit_detail_activity);
if (isInLazyMode) {
@ -538,9 +538,10 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
isInLazyMode = false;
}
}
break;
return true;
case R.id.action_change_post_layout_view_subreddit_detail_activity:
postLayoutBottomSheetFragment.show(getSupportFragmentManager(), postLayoutBottomSheetFragment.getTag());
return true;
}
return false;
}

View File

@ -55,6 +55,7 @@ import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent;
import ml.docilealligator.infinityforreddit.FetchUserData;
import ml.docilealligator.infinityforreddit.Fragment.CommentsListingFragment;
import ml.docilealligator.infinityforreddit.Fragment.PostFragment;
import ml.docilealligator.infinityforreddit.Fragment.PostLayoutBottomSheetFragment;
import ml.docilealligator.infinityforreddit.Fragment.SortTimeBottomSheetFragment;
import ml.docilealligator.infinityforreddit.Fragment.UserThingSortTypeBottomSheetFragment;
import ml.docilealligator.infinityforreddit.FragmentCommunicator;
@ -74,7 +75,8 @@ import ml.docilealligator.infinityforreddit.UserFollowing;
import pl.droidsonroids.gif.GifImageView;
import retrofit2.Retrofit;
public class ViewUserDetailActivity extends BaseActivity implements SortTypeSelectionCallback {
public class ViewUserDetailActivity extends BaseActivity implements SortTypeSelectionCallback,
PostLayoutBottomSheetFragment.PostLayoutSelectionCallback {
public static final String EXTRA_USER_NAME_KEY = "EUNK";
public static final String EXTRA_MESSAGE_FULLNAME = "ENF";
@ -126,6 +128,7 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
private AppBarLayout.LayoutParams params;
private UserThingSortTypeBottomSheetFragment userThingSortTypeBottomSheetFragment;
private SortTimeBottomSheetFragment sortTimeBottomSheetFragment;
private PostLayoutBottomSheetFragment postLayoutBottomSheetFragment;
private boolean mNullAccessToken = false;
private String mAccessToken;
private String mAccountName;
@ -390,6 +393,7 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
userThingSortTypeBottomSheetFragment = new UserThingSortTypeBottomSheetFragment();
sortTimeBottomSheetFragment = new SortTimeBottomSheetFragment();
postLayoutBottomSheetFragment = new PostLayoutBottomSheetFragment();
}
@Override
@ -579,6 +583,9 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
}
}
return true;
case R.id.action_change_post_layout_view_user_detail_activity:
postLayoutBottomSheetFragment.show(getSupportFragmentManager(), postLayoutBottomSheetFragment.getTag());
return true;
}
return false;
}
@ -627,6 +634,11 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
sortTimeBottomSheetFragment.show(getSupportFragmentManager(), sortTimeBottomSheetFragment.getTag());
}
@Override
public void postLayoutSelected(int postLayout) {
sectionsPagerAdapter.changePostLayout(postLayout);
}
@Subscribe
public void onAccountSwitchEvent(SwitchAccountEvent event) {
if (!getClass().getName().equals(event.excludeActivityClassName)) {
@ -793,5 +805,12 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
postFragment.changeNSFW(nsfw);
}
}
void changePostLayout(int postLayout) {
if (postFragment != null) {
mSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_USER_POST, postLayout).apply();
((FragmentCommunicator) postFragment).changePostLayout(postLayout);
}
}
}
}

View File

@ -181,6 +181,17 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
}
});
((PostViewHolder) holder).subredditTextView.setText(subredditNamePrefixed);
((PostViewHolder) holder).userTextView.setText(authorPrefixed);
((PostViewHolder) holder).userTextView.setOnClickListener(view -> {
if (canStartActivity) {
canStartActivity = false;
Intent intent = new Intent(mContext, ViewUserDetailActivity.class);
intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, post.getAuthor());
mContext.startActivity(intent);
}
});
if (mDisplaySubredditName) {
if (authorPrefixed.equals(subredditNamePrefixed)) {
if (post.getAuthorIconUrl() == null) {
@ -249,10 +260,9 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
}
}
((PostViewHolder) holder).nameTextView.setTextColor(mContext.getResources().getColor(R.color.colorAccent));
((PostViewHolder) holder).nameTextView.setText(subredditNamePrefixed);
((PostViewHolder) holder).subredditTextView.setTextColor(mContext.getResources().getColor(R.color.colorAccent));
((PostViewHolder) holder).nameTextView.setOnClickListener(view -> {
((PostViewHolder) holder).subredditTextView.setOnClickListener(view -> {
if (canStartActivity) {
canStartActivity = false;
if (post.getSubredditNamePrefixed().startsWith("u/")) {
@ -270,7 +280,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
});
((PostViewHolder) holder).iconGifImageView.setOnClickListener(view ->
((PostViewHolder) holder).nameTextView.performClick());
((PostViewHolder) holder).subredditTextView.performClick());
} else {
if (post.getAuthorIconUrl() == null) {
String authorName = post.getAuthor().equals("[deleted]") ? post.getSubredditNamePrefixed().substring(2) : post.getAuthor();
@ -305,10 +315,9 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
.into(((PostViewHolder) holder).iconGifImageView);
}
((PostViewHolder) holder).nameTextView.setTextColor(mContext.getResources().getColor(R.color.colorPrimaryDarkDayNightTheme));
((PostViewHolder) holder).nameTextView.setText(authorPrefixed);
((PostViewHolder) holder).subredditTextView.setTextColor(mContext.getResources().getColor(R.color.colorPrimaryDarkDayNightTheme));
((PostViewHolder) holder).nameTextView.setOnClickListener(view -> {
((PostViewHolder) holder).subredditTextView.setOnClickListener(view -> {
if (canStartActivity) {
canStartActivity = false;
Intent intent = new Intent(mContext, ViewUserDetailActivity.class);
@ -318,7 +327,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
});
((PostViewHolder) holder).iconGifImageView.setOnClickListener(view ->
((PostViewHolder) holder).nameTextView.performClick());
((PostViewHolder) holder).subredditTextView.performClick());
}
((PostViewHolder) holder).postTimeTextView.setText(postTime);
@ -1392,7 +1401,9 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
@BindView(R.id.icon_gif_image_view_item_post)
AspectRatioGifImageView iconGifImageView;
@BindView(R.id.name_text_view_item_post)
TextView nameTextView;
TextView subredditTextView;
@BindView(R.id.user_text_view_item_post)
TextView userTextView;
@BindView(R.id.stickied_post_image_view_item_post)
ImageView stickiedPostImageView;
@BindView(R.id.post_time_text_view_best_item_post)

View File

@ -38,11 +38,27 @@
android:layout_marginEnd="8dp"
android:textColor="#E91E63"
android:textSize="?attr/font_default"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintBottom_toTopOf="@id/user_text_view_item_post"
app:layout_constraintStart_toEndOf="@id/icon_gif_image_view_item_post"
app:layout_constraintEnd_toStartOf="@id/stickied_post_image_view_item_post"
app:layout_constraintTop_toTopOf="parent"/>
<TextView
android:id="@+id/user_text_view_item_post"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="8dp"
android:textColor="@color/colorPrimaryDarkDayNightTheme"
android:textSize="?attr/font_default"
android:maxLines="2"
android:ellipsize="end"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@+id/icon_gif_image_view_item_post"
app:layout_constraintEnd_toStartOf="@id/stickied_post_image_view_item_post"
app:layout_constraintTop_toBottomOf="@+id/name_text_view_item_post"
app:layout_constraintHorizontal_bias="0" />
<ImageView
android:id="@+id/stickied_post_image_view_item_post"
android:layout_width="24dp"

View File

@ -13,4 +13,10 @@
android:orderInCategory="2"
android:title="@string/action_start_lazy_mode"
app:showAsAction="never" />
<item
android:id="@+id/action_change_post_layout_account_posts_activity"
android:orderInCategory="3"
android:title="@string/action_change_post_layout"
app:showAsAction="never" />
</menu>

View File

@ -20,4 +20,10 @@
android:orderInCategory="3"
android:title="@string/action_start_lazy_mode"
app:showAsAction="never" />
<item
android:id="@+id/action_change_post_layout_filtered_post_activity"
android:orderInCategory="4"
android:title="@string/action_change_post_layout"
app:showAsAction="never" />
</menu>

View File

@ -20,4 +20,10 @@
android:orderInCategory="3"
android:title="@string/action_refresh"
app:showAsAction="never" />
<item
android:id="@+id/action_change_post_layout_search_result_activity"
android:orderInCategory="4"
android:title="@string/action_change_post_layout"
app:showAsAction="never" />
</menu>

View File

@ -26,4 +26,10 @@
android:orderInCategory="4"
android:title="@string/action_start_lazy_mode"
app:showAsAction="never" />
<item
android:id="@+id/action_change_post_layout_view_user_detail_activity"
android:orderInCategory="5"
android:title="@string/action_change_post_layout"
app:showAsAction="never" />
</menu>