1
0
mirror of https://github.com/KokaKiwi/BarInsta synced 2024-11-18 04:37:30 +00:00

Add preference tp disable post open animation, extract some strings to xml, fix one locale string.

This commit is contained in:
Ammar Githam 2020-11-14 18:32:11 +09:00
parent 1fe6a0f3f1
commit 84467b60b5
12 changed files with 372 additions and 310 deletions

View File

@ -80,6 +80,7 @@ public class PostsLayoutPreferencesDialogFragment extends DialogFragment {
initAvatarsToggle(); initAvatarsToggle();
initCornersToggle(); initCornersToggle();
initGapToggle(); initGapToggle();
initAnimationDisableToggle();
} }
private void initLayoutToggle() { private void initLayoutToggle() {
@ -169,6 +170,11 @@ public class PostsLayoutPreferencesDialogFragment extends DialogFragment {
binding.showGapToggle.setOnCheckedChangeListener((buttonView, isChecked) -> preferencesBuilder.setHasGap(isChecked)); binding.showGapToggle.setOnCheckedChangeListener((buttonView, isChecked) -> preferencesBuilder.setHasGap(isChecked));
} }
private void initAnimationDisableToggle() {
binding.disableAnimationToggle.setChecked(preferencesBuilder.isAnimationDisabled());
binding.disableAnimationToggle.setOnCheckedChangeListener((buttonView, isChecked) -> preferencesBuilder.setAnimationDisabled(isChecked));
}
private int getSelectedLayoutId() { private int getSelectedLayoutId() {
switch (preferencesBuilder.getType()) { switch (preferencesBuilder.getType()) {
case STAGGERED_GRID: case STAGGERED_GRID:

View File

@ -94,6 +94,7 @@ public class HashTagFragment extends Fragment implements SwipeRefreshLayout.OnRe
private Set<FeedModel> selectedFeedModels; private Set<FeedModel> selectedFeedModels;
private FeedModel downloadFeedModel; private FeedModel downloadFeedModel;
private int downloadChildPosition = -1; private int downloadChildPosition = -1;
private PostsLayoutPreferences layoutPreferences = PostsLayoutPreferences.fromJson(settingsHelper.getString(Constants.PREF_HASHTAG_POSTS_LAYOUT));
private final OnBackPressedCallback onBackPressedCallback = new OnBackPressedCallback(false) { private final OnBackPressedCallback onBackPressedCallback = new OnBackPressedCallback(false) {
@Override @Override
@ -202,36 +203,23 @@ public class HashTagFragment extends Fragment implements SwipeRefreshLayout.OnRe
final View mainPostImage, final View mainPostImage,
final int position) { final int position) {
if (opening) return; if (opening) return;
else if (TextUtils.isEmpty(feedModel.getProfileModel().getUsername())) { if (TextUtils.isEmpty(feedModel.getProfileModel().getUsername())) {
opening = true; opening = true;
new PostFetcher(feedModel.getShortCode(), newFeedModel -> { new PostFetcher(feedModel.getShortCode(), newFeedModel -> openPostDialog(newFeedModel, profilePicView, mainPostImage, position))
final PostViewV2Fragment.Builder builder = PostViewV2Fragment .execute();
.builder(newFeedModel); return;
}
opening = true;
final PostViewV2Fragment.Builder builder = PostViewV2Fragment.builder(feedModel);
if (position >= 0) { if (position >= 0) {
builder.setPosition(position); builder.setPosition(position);
} }
final PostViewV2Fragment fragment = builder if (!layoutPreferences.isAnimationDisabled()) {
.setSharedProfilePicElement(profilePicView) builder.setSharedProfilePicElement(profilePicView)
.setSharedMainPostElement(mainPostImage) .setSharedMainPostElement(mainPostImage);
.build(); }
fragment.show(getChildFragmentManager(), "post_view"); builder.build().show(getChildFragmentManager(), "post_view");
opening = false; opening = false;
}).execute();
}
else {
opening = true;
final PostViewV2Fragment.Builder builder = PostViewV2Fragment
.builder(feedModel);
if (position >= 0) {
builder.setPosition(position);
}
final PostViewV2Fragment fragment = builder
.setSharedProfilePicElement(profilePicView)
.setSharedMainPostElement(mainPostImage)
.build();
fragment.show(getChildFragmentManager(), "post_view");
opening = false;
}
} }
}; };
private final FeedAdapterV2.SelectionModeCallback selectionModeCallback = new FeedAdapterV2.SelectionModeCallback() { private final FeedAdapterV2.SelectionModeCallback selectionModeCallback = new FeedAdapterV2.SelectionModeCallback() {
@ -376,7 +364,7 @@ public class HashTagFragment extends Fragment implements SwipeRefreshLayout.OnRe
binding.posts.setViewModelStoreOwner(this) binding.posts.setViewModelStoreOwner(this)
.setLifeCycleOwner(this) .setLifeCycleOwner(this)
.setPostFetchService(new HashtagPostFetchService(hashtagModel, isLoggedIn)) .setPostFetchService(new HashtagPostFetchService(hashtagModel, isLoggedIn))
.setLayoutPreferences(PostsLayoutPreferences.fromJson(settingsHelper.getString(Constants.PREF_HASHTAG_POSTS_LAYOUT))) .setLayoutPreferences(layoutPreferences)
.addFetchStatusChangeListener(fetching -> updateSwipeRefreshState()) .addFetchStatusChangeListener(fetching -> updateSwipeRefreshState())
.setFeedItemCallback(feedItemCallback) .setFeedItemCallback(feedItemCallback)
.setSelectionModeCallback(selectionModeCallback) .setSelectionModeCallback(selectionModeCallback)
@ -565,7 +553,10 @@ public class HashTagFragment extends Fragment implements SwipeRefreshLayout.OnRe
private void showPostsLayoutPreferences() { private void showPostsLayoutPreferences() {
final PostsLayoutPreferencesDialogFragment fragment = new PostsLayoutPreferencesDialogFragment( final PostsLayoutPreferencesDialogFragment fragment = new PostsLayoutPreferencesDialogFragment(
Constants.PREF_HASHTAG_POSTS_LAYOUT, Constants.PREF_HASHTAG_POSTS_LAYOUT,
preferences -> new Handler().postDelayed(() -> binding.posts.setLayoutPreferences(preferences), 200)); preferences -> {
layoutPreferences = preferences;
new Handler().postDelayed(() -> binding.posts.setLayoutPreferences(preferences), 200);
});
fragment.show(getChildFragmentManager(), "posts_layout_preferences"); fragment.show(getChildFragmentManager(), "posts_layout_preferences");
} }
} }

View File

@ -93,6 +93,8 @@ public class LocationFragment extends Fragment implements SwipeRefreshLayout.OnR
private Set<FeedModel> selectedFeedModels; private Set<FeedModel> selectedFeedModels;
private FeedModel downloadFeedModel; private FeedModel downloadFeedModel;
private int downloadChildPosition = -1; private int downloadChildPosition = -1;
private PostsLayoutPreferences layoutPreferences = PostsLayoutPreferences
.fromJson(settingsHelper.getString(Constants.PREF_LOCATION_POSTS_LAYOUT));
private final OnBackPressedCallback onBackPressedCallback = new OnBackPressedCallback(false) { private final OnBackPressedCallback onBackPressedCallback = new OnBackPressedCallback(false) {
@Override @Override
@ -200,36 +202,24 @@ public class LocationFragment extends Fragment implements SwipeRefreshLayout.OnR
final View mainPostImage, final View mainPostImage,
final int position) { final int position) {
if (opening) return; if (opening) return;
else if (TextUtils.isEmpty(feedModel.getProfileModel().getUsername())) { if (TextUtils.isEmpty(feedModel.getProfileModel().getUsername())) {
opening = true; opening = true;
new PostFetcher(feedModel.getShortCode(), newFeedModel -> { new PostFetcher(feedModel.getShortCode(), newFeedModel -> openPostDialog(newFeedModel, profilePicView, mainPostImage, position))
final PostViewV2Fragment.Builder builder = PostViewV2Fragment .execute();
.builder(newFeedModel); return;
if (position >= 0) {
builder.setPosition(position);
} }
final PostViewV2Fragment fragment = builder
.setSharedProfilePicElement(profilePicView)
.setSharedMainPostElement(mainPostImage)
.build();
fragment.show(getChildFragmentManager(), "post_view");
opening = false;
}).execute();
}
else {
opening = true; opening = true;
final PostViewV2Fragment.Builder builder = PostViewV2Fragment final PostViewV2Fragment.Builder builder = PostViewV2Fragment
.builder(feedModel); .builder(feedModel);
if (position >= 0) { if (position >= 0) {
builder.setPosition(position); builder.setPosition(position);
} }
final PostViewV2Fragment fragment = builder if (!layoutPreferences.isAnimationDisabled()) {
.setSharedProfilePicElement(profilePicView) builder.setSharedProfilePicElement(profilePicView)
.setSharedMainPostElement(mainPostImage) .setSharedMainPostElement(mainPostImage);
.build();
fragment.show(getChildFragmentManager(), "post_view");
opening = false;
} }
builder.build().show(getChildFragmentManager(), "post_view");
opening = false;
} }
}; };
private final FeedAdapterV2.SelectionModeCallback selectionModeCallback = new FeedAdapterV2.SelectionModeCallback() { private final FeedAdapterV2.SelectionModeCallback selectionModeCallback = new FeedAdapterV2.SelectionModeCallback() {
@ -359,7 +349,7 @@ public class LocationFragment extends Fragment implements SwipeRefreshLayout.OnR
binding.posts.setViewModelStoreOwner(this) binding.posts.setViewModelStoreOwner(this)
.setLifeCycleOwner(this) .setLifeCycleOwner(this)
.setPostFetchService(new LocationPostFetchService(locationModel, isLoggedIn)) .setPostFetchService(new LocationPostFetchService(locationModel, isLoggedIn))
.setLayoutPreferences(PostsLayoutPreferences.fromJson(settingsHelper.getString(Constants.PREF_LOCATION_POSTS_LAYOUT))) .setLayoutPreferences(layoutPreferences)
.addFetchStatusChangeListener(fetching -> updateSwipeRefreshState()) .addFetchStatusChangeListener(fetching -> updateSwipeRefreshState())
.setFeedItemCallback(feedItemCallback) .setFeedItemCallback(feedItemCallback)
.setSelectionModeCallback(selectionModeCallback) .setSelectionModeCallback(selectionModeCallback)
@ -542,7 +532,10 @@ public class LocationFragment extends Fragment implements SwipeRefreshLayout.OnR
private void showPostsLayoutPreferences() { private void showPostsLayoutPreferences() {
final PostsLayoutPreferencesDialogFragment fragment = new PostsLayoutPreferencesDialogFragment( final PostsLayoutPreferencesDialogFragment fragment = new PostsLayoutPreferencesDialogFragment(
Constants.PREF_LOCATION_POSTS_LAYOUT, Constants.PREF_LOCATION_POSTS_LAYOUT,
preferences -> new Handler().postDelayed(() -> binding.posts.setLayoutPreferences(preferences), 200)); preferences -> {
layoutPreferences = preferences;
new Handler().postDelayed(() -> binding.posts.setLayoutPreferences(preferences), 200);
});
fragment.show(getChildFragmentManager(), "posts_layout_preferences"); fragment.show(getChildFragmentManager(), "posts_layout_preferences");
} }
} }

View File

@ -62,6 +62,7 @@ public final class SavedViewerFragment extends Fragment implements SwipeRefreshL
private Set<FeedModel> selectedFeedModels; private Set<FeedModel> selectedFeedModels;
private FeedModel downloadFeedModel; private FeedModel downloadFeedModel;
private int downloadChildPosition = -1; private int downloadChildPosition = -1;
private PostsLayoutPreferences layoutPreferences = PostsLayoutPreferences.fromJson(settingsHelper.getString(getPostsLayoutPreferenceKey()));
private final OnBackPressedCallback onBackPressedCallback = new OnBackPressedCallback(false) { private final OnBackPressedCallback onBackPressedCallback = new OnBackPressedCallback(false) {
@Override @Override
@ -173,11 +174,11 @@ public final class SavedViewerFragment extends Fragment implements SwipeRefreshL
if (position >= 0) { if (position >= 0) {
builder.setPosition(position); builder.setPosition(position);
} }
final PostViewV2Fragment fragment = builder if (!layoutPreferences.isAnimationDisabled()) {
.setSharedProfilePicElement(profilePicView) builder.setSharedProfilePicElement(profilePicView)
.setSharedMainPostElement(mainPostImage) .setSharedMainPostElement(mainPostImage);
.build(); }
fragment.show(getChildFragmentManager(), "post_view"); builder.build().show(getChildFragmentManager(), "post_view");
} }
}; };
private final FeedAdapterV2.SelectionModeCallback selectionModeCallback = new FeedAdapterV2.SelectionModeCallback() { private final FeedAdapterV2.SelectionModeCallback selectionModeCallback = new FeedAdapterV2.SelectionModeCallback() {
@ -320,7 +321,7 @@ public final class SavedViewerFragment extends Fragment implements SwipeRefreshL
binding.posts.setViewModelStoreOwner(this) binding.posts.setViewModelStoreOwner(this)
.setLifeCycleOwner(this) .setLifeCycleOwner(this)
.setPostFetchService(new SavedPostFetchService(profileId, type)) .setPostFetchService(new SavedPostFetchService(profileId, type))
.setLayoutPreferences(PostsLayoutPreferences.fromJson(settingsHelper.getString(getPostsLayoutPreferenceKey()))) .setLayoutPreferences(layoutPreferences)
.addFetchStatusChangeListener(fetching -> updateSwipeRefreshState()) .addFetchStatusChangeListener(fetching -> updateSwipeRefreshState())
.setFeedItemCallback(feedItemCallback) .setFeedItemCallback(feedItemCallback)
.setSelectionModeCallback(selectionModeCallback) .setSelectionModeCallback(selectionModeCallback)
@ -394,7 +395,10 @@ public final class SavedViewerFragment extends Fragment implements SwipeRefreshL
private void showPostsLayoutPreferences() { private void showPostsLayoutPreferences() {
final PostsLayoutPreferencesDialogFragment fragment = new PostsLayoutPreferencesDialogFragment( final PostsLayoutPreferencesDialogFragment fragment = new PostsLayoutPreferencesDialogFragment(
getPostsLayoutPreferenceKey(), getPostsLayoutPreferenceKey(),
preferences -> new Handler().postDelayed(() -> binding.posts.setLayoutPreferences(preferences), 200)); preferences -> {
layoutPreferences = preferences;
new Handler().postDelayed(() -> binding.posts.setLayoutPreferences(preferences), 200);
});
fragment.show(getChildFragmentManager(), "posts_layout_preferences"); fragment.show(getChildFragmentManager(), "posts_layout_preferences");
} }
} }

View File

@ -75,6 +75,7 @@ public class TopicPostsFragment extends Fragment implements SwipeRefreshLayout.O
private Set<FeedModel> selectedFeedModels; private Set<FeedModel> selectedFeedModels;
private FeedModel downloadFeedModel; private FeedModel downloadFeedModel;
private int downloadChildPosition = -1; private int downloadChildPosition = -1;
private PostsLayoutPreferences layoutPreferences = PostsLayoutPreferences.fromJson(settingsHelper.getString(Constants.PREF_TOPIC_POSTS_LAYOUT));
private final OnBackPressedCallback onBackPressedCallback = new OnBackPressedCallback(false) { private final OnBackPressedCallback onBackPressedCallback = new OnBackPressedCallback(false) {
@Override @Override
@ -186,11 +187,11 @@ public class TopicPostsFragment extends Fragment implements SwipeRefreshLayout.O
if (position >= 0) { if (position >= 0) {
builder.setPosition(position); builder.setPosition(position);
} }
final PostViewV2Fragment fragment = builder if (!layoutPreferences.isAnimationDisabled()) {
.setSharedProfilePicElement(profilePicView) builder.setSharedProfilePicElement(profilePicView)
.setSharedMainPostElement(mainPostImage) .setSharedMainPostElement(mainPostImage);
.build(); }
fragment.show(getChildFragmentManager(), "post_view"); builder.build().show(getChildFragmentManager(), "post_view");
} }
}; };
private final FeedAdapterV2.SelectionModeCallback selectionModeCallback = new FeedAdapterV2.SelectionModeCallback() { private final FeedAdapterV2.SelectionModeCallback selectionModeCallback = new FeedAdapterV2.SelectionModeCallback() {
@ -400,7 +401,7 @@ public class TopicPostsFragment extends Fragment implements SwipeRefreshLayout.O
binding.posts.setViewModelStoreOwner(this) binding.posts.setViewModelStoreOwner(this)
.setLifeCycleOwner(this) .setLifeCycleOwner(this)
.setPostFetchService(new DiscoverPostFetchService(topicalExploreRequest)) .setPostFetchService(new DiscoverPostFetchService(topicalExploreRequest))
.setLayoutPreferences(PostsLayoutPreferences.fromJson(settingsHelper.getString(Constants.PREF_TOPIC_POSTS_LAYOUT))) .setLayoutPreferences(layoutPreferences)
.addFetchStatusChangeListener(fetching -> updateSwipeRefreshState()) .addFetchStatusChangeListener(fetching -> updateSwipeRefreshState())
.setFeedItemCallback(feedItemCallback) .setFeedItemCallback(feedItemCallback)
.setSelectionModeCallback(selectionModeCallback) .setSelectionModeCallback(selectionModeCallback)
@ -422,7 +423,10 @@ public class TopicPostsFragment extends Fragment implements SwipeRefreshLayout.O
private void showPostsLayoutPreferences() { private void showPostsLayoutPreferences() {
final PostsLayoutPreferencesDialogFragment fragment = new PostsLayoutPreferencesDialogFragment( final PostsLayoutPreferencesDialogFragment fragment = new PostsLayoutPreferencesDialogFragment(
Constants.PREF_TOPIC_POSTS_LAYOUT, Constants.PREF_TOPIC_POSTS_LAYOUT,
preferences -> new Handler().postDelayed(() -> binding.posts.setLayoutPreferences(preferences), 200)); preferences -> {
layoutPreferences = preferences;
new Handler().postDelayed(() -> binding.posts.setLayoutPreferences(preferences), 200);
});
fragment.show(getChildFragmentManager(), "posts_layout_preferences"); fragment.show(getChildFragmentManager(), "posts_layout_preferences");
} }
} }

View File

@ -72,6 +72,7 @@ public class FeedFragment extends Fragment implements SwipeRefreshLayout.OnRefre
private Set<FeedModel> selectedFeedModels; private Set<FeedModel> selectedFeedModels;
private FeedModel downloadFeedModel; private FeedModel downloadFeedModel;
private int downloadChildPosition = -1; private int downloadChildPosition = -1;
private PostsLayoutPreferences layoutPreferences = PostsLayoutPreferences.fromJson(settingsHelper.getString(Constants.PREF_POSTS_LAYOUT));
private final FeedAdapterV2.FeedItemCallback feedItemCallback = new FeedAdapterV2.FeedItemCallback() { private final FeedAdapterV2.FeedItemCallback feedItemCallback = new FeedAdapterV2.FeedItemCallback() {
@Override @Override
@ -153,11 +154,11 @@ public class FeedFragment extends Fragment implements SwipeRefreshLayout.OnRefre
if (position >= 0) { if (position >= 0) {
builder.setPosition(position); builder.setPosition(position);
} }
final PostViewV2Fragment fragment = builder if (!layoutPreferences.isAnimationDisabled()) {
.setSharedProfilePicElement(profilePicView) builder.setSharedProfilePicElement(profilePicView)
.setSharedMainPostElement(mainPostImage) .setSharedMainPostElement(mainPostImage);
.build(); }
fragment.show(getChildFragmentManager(), "post_view"); builder.build().show(getChildFragmentManager(), "post_view");
} }
}; };
private final OnBackPressedCallback onBackPressedCallback = new OnBackPressedCallback(false) { private final OnBackPressedCallback onBackPressedCallback = new OnBackPressedCallback(false) {
@ -324,7 +325,7 @@ public class FeedFragment extends Fragment implements SwipeRefreshLayout.OnRefre
binding.feedRecyclerView.setViewModelStoreOwner(this) binding.feedRecyclerView.setViewModelStoreOwner(this)
.setLifeCycleOwner(this) .setLifeCycleOwner(this)
.setPostFetchService(new FeedPostFetchService()) .setPostFetchService(new FeedPostFetchService())
.setLayoutPreferences(PostsLayoutPreferences.fromJson(settingsHelper.getString(Constants.PREF_POSTS_LAYOUT))) .setLayoutPreferences(layoutPreferences)
.addFetchStatusChangeListener(fetching -> updateSwipeRefreshState()) .addFetchStatusChangeListener(fetching -> updateSwipeRefreshState())
.setFeedItemCallback(feedItemCallback) .setFeedItemCallback(feedItemCallback)
.setSelectionModeCallback(selectionModeCallback) .setSelectionModeCallback(selectionModeCallback)
@ -377,7 +378,10 @@ public class FeedFragment extends Fragment implements SwipeRefreshLayout.OnRefre
private void showPostsLayoutPreferences() { private void showPostsLayoutPreferences() {
final PostsLayoutPreferencesDialogFragment fragment = new PostsLayoutPreferencesDialogFragment( final PostsLayoutPreferencesDialogFragment fragment = new PostsLayoutPreferencesDialogFragment(
Constants.PREF_POSTS_LAYOUT, Constants.PREF_POSTS_LAYOUT,
preferences -> new Handler().postDelayed(() -> binding.feedRecyclerView.setLayoutPreferences(preferences), 200)); preferences -> {
layoutPreferences = preferences;
new Handler().postDelayed(() -> binding.feedRecyclerView.setLayoutPreferences(preferences), 200);
});
fragment.show(getChildFragmentManager(), "posts_layout_preferences"); fragment.show(getChildFragmentManager(), "posts_layout_preferences");
} }

View File

@ -117,6 +117,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
private Set<FeedModel> selectedFeedModels; private Set<FeedModel> selectedFeedModels;
private FeedModel downloadFeedModel; private FeedModel downloadFeedModel;
private int downloadChildPosition = -1; private int downloadChildPosition = -1;
private PostsLayoutPreferences layoutPreferences = PostsLayoutPreferences.fromJson(settingsHelper.getString(Constants.PREF_PROFILE_POSTS_LAYOUT));
private final Runnable usernameSettingRunnable = () -> { private final Runnable usernameSettingRunnable = () -> {
final ActionBar actionBar = fragmentActivity.getSupportActionBar(); final ActionBar actionBar = fragmentActivity.getSupportActionBar();
@ -238,11 +239,11 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
if (position >= 0) { if (position >= 0) {
builder.setPosition(position); builder.setPosition(position);
} }
final PostViewV2Fragment fragment = builder if (!layoutPreferences.isAnimationDisabled()) {
.setSharedProfilePicElement(profilePicView) builder.setSharedProfilePicElement(profilePicView)
.setSharedMainPostElement(mainPostImage) .setSharedMainPostElement(mainPostImage);
.build(); }
fragment.show(getChildFragmentManager(), "post_view"); builder.build().show(getChildFragmentManager(), "post_view");
} }
}; };
private final FeedAdapterV2.SelectionModeCallback selectionModeCallback = new FeedAdapterV2.SelectionModeCallback() { private final FeedAdapterV2.SelectionModeCallback selectionModeCallback = new FeedAdapterV2.SelectionModeCallback() {
@ -876,7 +877,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
binding.postsRecyclerView.setViewModelStoreOwner(this) binding.postsRecyclerView.setViewModelStoreOwner(this)
.setLifeCycleOwner(this) .setLifeCycleOwner(this)
.setPostFetchService(new ProfilePostFetchService(profileModel)) .setPostFetchService(new ProfilePostFetchService(profileModel))
.setLayoutPreferences(PostsLayoutPreferences.fromJson(settingsHelper.getString(Constants.PREF_PROFILE_POSTS_LAYOUT))) .setLayoutPreferences(layoutPreferences)
.addFetchStatusChangeListener(fetching -> updateSwipeRefreshState()) .addFetchStatusChangeListener(fetching -> updateSwipeRefreshState())
.setFeedItemCallback(feedItemCallback) .setFeedItemCallback(feedItemCallback)
.setSelectionModeCallback(selectionModeCallback) .setSelectionModeCallback(selectionModeCallback)
@ -922,7 +923,10 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
private void showPostsLayoutPreferences() { private void showPostsLayoutPreferences() {
final PostsLayoutPreferencesDialogFragment fragment = new PostsLayoutPreferencesDialogFragment( final PostsLayoutPreferencesDialogFragment fragment = new PostsLayoutPreferencesDialogFragment(
Constants.PREF_PROFILE_POSTS_LAYOUT, Constants.PREF_PROFILE_POSTS_LAYOUT,
preferences -> new Handler().postDelayed(() -> binding.postsRecyclerView.setLayoutPreferences(preferences), 200)); preferences -> {
layoutPreferences = preferences;
new Handler().postDelayed(() -> binding.postsRecyclerView.setLayoutPreferences(preferences), 200);
});
fragment.show(getChildFragmentManager(), "posts_layout_preferences"); fragment.show(getChildFragmentManager(), "posts_layout_preferences");
} }
} }

View File

@ -12,6 +12,7 @@ public final class PostsLayoutPreferences {
private final ProfilePicSize profilePicSize; private final ProfilePicSize profilePicSize;
private final boolean hasRoundedCorners; private final boolean hasRoundedCorners;
private final boolean hasGap; private final boolean hasGap;
private final boolean animationDisabled;
public static class Builder { public static class Builder {
private PostsLayoutType type = PostsLayoutType.GRID; private PostsLayoutType type = PostsLayoutType.GRID;
@ -21,6 +22,7 @@ public final class PostsLayoutPreferences {
private ProfilePicSize profilePicSize = ProfilePicSize.SMALL; private ProfilePicSize profilePicSize = ProfilePicSize.SMALL;
private boolean hasRoundedCorners = true; private boolean hasRoundedCorners = true;
private boolean hasGap = true; private boolean hasGap = true;
private boolean animationDisabled = false;
public Builder setType(final PostsLayoutType type) { public Builder setType(final PostsLayoutType type) {
this.type = type; this.type = type;
@ -57,6 +59,11 @@ public final class PostsLayoutPreferences {
return this; return this;
} }
public Builder setAnimationDisabled(final boolean animationDisabled) {
this.animationDisabled = animationDisabled;
return this;
}
// Breaking builder pattern and adding getters to avoid too many object creations in PostsLayoutPreferencesDialogFragment // Breaking builder pattern and adding getters to avoid too many object creations in PostsLayoutPreferencesDialogFragment
public PostsLayoutType getType() { public PostsLayoutType getType() {
return type; return type;
@ -86,6 +93,10 @@ public final class PostsLayoutPreferences {
return hasGap; return hasGap;
} }
public boolean isAnimationDisabled() {
return animationDisabled;
}
public Builder mergeFrom(final PostsLayoutPreferences preferences) { public Builder mergeFrom(final PostsLayoutPreferences preferences) {
if (preferences == null) { if (preferences == null) {
return this; return this;
@ -97,11 +108,13 @@ public final class PostsLayoutPreferences {
setProfilePicSize(preferences.getProfilePicSize()); setProfilePicSize(preferences.getProfilePicSize());
setHasRoundedCorners(preferences.getHasRoundedCorners()); setHasRoundedCorners(preferences.getHasRoundedCorners());
setHasGap(preferences.getHasGap()); setHasGap(preferences.getHasGap());
setAnimationDisabled(preferences.isAnimationDisabled());
return this; return this;
} }
public PostsLayoutPreferences build() { public PostsLayoutPreferences build() {
return new PostsLayoutPreferences(type, colCount, isAvatarVisible, isNameVisible, profilePicSize, hasRoundedCorners, hasGap); return new PostsLayoutPreferences(type, colCount, isAvatarVisible, isNameVisible, profilePicSize, hasRoundedCorners, hasGap,
animationDisabled);
} }
} }
@ -115,7 +128,8 @@ public final class PostsLayoutPreferences {
final boolean isNameVisible, final boolean isNameVisible,
final ProfilePicSize profilePicSize, final ProfilePicSize profilePicSize,
final boolean hasRoundedCorners, final boolean hasRoundedCorners,
final boolean hasGap) { final boolean hasGap,
final boolean animationDisabled) {
this.type = type; this.type = type;
this.colCount = colCount; this.colCount = colCount;
@ -124,6 +138,7 @@ public final class PostsLayoutPreferences {
this.profilePicSize = profilePicSize; this.profilePicSize = profilePicSize;
this.hasRoundedCorners = hasRoundedCorners; this.hasRoundedCorners = hasRoundedCorners;
this.hasGap = hasGap; this.hasGap = hasGap;
this.animationDisabled = animationDisabled;
} }
public PostsLayoutType getType() { public PostsLayoutType getType() {
@ -163,6 +178,10 @@ public final class PostsLayoutPreferences {
return new Gson().fromJson(json, PostsLayoutPreferences.class); return new Gson().fromJson(json, PostsLayoutPreferences.class);
} }
public boolean isAnimationDisabled() {
return animationDisabled;
}
@Override @Override
public boolean equals(final Object o) { public boolean equals(final Object o) {
if (this == o) return true; if (this == o) return true;
@ -172,12 +191,13 @@ public final class PostsLayoutPreferences {
isAvatarVisible == that.isAvatarVisible && isAvatarVisible == that.isAvatarVisible &&
isNameVisible == that.isNameVisible && isNameVisible == that.isNameVisible &&
type == that.type && type == that.type &&
profilePicSize == that.profilePicSize; profilePicSize == that.profilePicSize &&
animationDisabled == that.animationDisabled;
} }
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(type, colCount, isAvatarVisible, isNameVisible, profilePicSize); return Objects.hash(type, colCount, isAvatarVisible, isNameVisible, profilePicSize, animationDisabled);
} }
@Override @Override
@ -190,6 +210,7 @@ public final class PostsLayoutPreferences {
", profilePicSize=" + profilePicSize + ", profilePicSize=" + profilePicSize +
", hasRoundedCorners=" + hasRoundedCorners + ", hasRoundedCorners=" + hasRoundedCorners +
", hasGap=" + hasGap + ", hasGap=" + hasGap +
", animationDisabled=" + animationDisabled +
'}'; '}';
} }

View File

@ -1,7 +1,11 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/root" android:id="@+id/root"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -13,13 +17,13 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical" android:orientation="vertical"
app:layout_constraintGuide_percent="0.3" /> app:layout_constraintGuide_percent="0.4" />
<androidx.appcompat.widget.AppCompatTextView <androidx.appcompat.widget.AppCompatTextView
android:id="@+id/label_layout" android:id="@+id/label_layout"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="Layout style" android:text="@string/layout_style"
app:layout_constraintBottom_toBottomOf="@id/layout_toggle" app:layout_constraintBottom_toBottomOf="@id/layout_toggle"
app:layout_constraintEnd_toStartOf="@id/guideline" app:layout_constraintEnd_toStartOf="@id/guideline"
app:layout_constraintTop_toTopOf="@id/layout_toggle" /> app:layout_constraintTop_toTopOf="@id/layout_toggle" />
@ -65,7 +69,7 @@
android:id="@+id/label_col_count" android:id="@+id/label_col_count"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="Column count" android:text="@string/column_count"
app:layout_constraintBottom_toBottomOf="@id/col_count_toggle" app:layout_constraintBottom_toBottomOf="@id/col_count_toggle"
app:layout_constraintEnd_toStartOf="@id/guideline" app:layout_constraintEnd_toStartOf="@id/guideline"
app:layout_constraintTop_toTopOf="@id/col_count_toggle" /> app:layout_constraintTop_toTopOf="@id/col_count_toggle" />
@ -88,21 +92,21 @@
style="@style/Widget.App.Button.OutlinedButton.IconOnly" style="@style/Widget.App.Button.OutlinedButton.IconOnly"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="2" /> android:text="@string/two" />
<Button <Button
android:id="@+id/col_count_three" android:id="@+id/col_count_three"
style="@style/Widget.App.Button.OutlinedButton.IconOnly" style="@style/Widget.App.Button.OutlinedButton.IconOnly"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="3" /> android:text="@string/three" />
</com.google.android.material.button.MaterialButtonToggleGroup> </com.google.android.material.button.MaterialButtonToggleGroup>
<androidx.appcompat.widget.AppCompatTextView <androidx.appcompat.widget.AppCompatTextView
android:id="@+id/label_show_names_toggle" android:id="@+id/label_show_names_toggle"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="Show names" android:text="@string/show_names"
app:layout_constraintBottom_toBottomOf="@id/show_names_toggle" app:layout_constraintBottom_toBottomOf="@id/show_names_toggle"
app:layout_constraintEnd_toStartOf="@id/guideline" app:layout_constraintEnd_toStartOf="@id/guideline"
app:layout_constraintTop_toTopOf="@id/show_names_toggle" /> app:layout_constraintTop_toTopOf="@id/show_names_toggle" />
@ -123,7 +127,7 @@
android:id="@+id/label_show_avatar_toggle" android:id="@+id/label_show_avatar_toggle"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="Show avatars" android:text="@string/show_avatars"
app:layout_constraintBottom_toBottomOf="@id/show_avatar_toggle" app:layout_constraintBottom_toBottomOf="@id/show_avatar_toggle"
app:layout_constraintEnd_toStartOf="@id/guideline" app:layout_constraintEnd_toStartOf="@id/guideline"
app:layout_constraintTop_toTopOf="@id/show_avatar_toggle" /> app:layout_constraintTop_toTopOf="@id/show_avatar_toggle" />
@ -144,7 +148,7 @@
android:id="@+id/label_avatar_size" android:id="@+id/label_avatar_size"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="Avatar size" android:text="@string/avatar_size"
app:layout_constraintBottom_toBottomOf="@id/avatar_size_toggle" app:layout_constraintBottom_toBottomOf="@id/avatar_size_toggle"
app:layout_constraintEnd_toStartOf="@id/guideline" app:layout_constraintEnd_toStartOf="@id/guideline"
app:layout_constraintTop_toTopOf="@id/avatar_size_toggle" /> app:layout_constraintTop_toTopOf="@id/avatar_size_toggle" />
@ -188,7 +192,7 @@
android:id="@+id/label_corners" android:id="@+id/label_corners"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="Corners" android:text="@string/corners"
app:layout_constraintBottom_toBottomOf="@id/corners_toggle" app:layout_constraintBottom_toBottomOf="@id/corners_toggle"
app:layout_constraintEnd_toStartOf="@id/guideline" app:layout_constraintEnd_toStartOf="@id/guideline"
app:layout_constraintTop_toTopOf="@id/corners_toggle" /> app:layout_constraintTop_toTopOf="@id/corners_toggle" />
@ -225,7 +229,7 @@
android:id="@+id/label_gap" android:id="@+id/label_gap"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="Show grid gap" android:text="@string/show_grid_gap"
app:layout_constraintBottom_toBottomOf="@id/show_gap_toggle" app:layout_constraintBottom_toBottomOf="@id/show_gap_toggle"
app:layout_constraintEnd_toStartOf="@id/guideline" app:layout_constraintEnd_toStartOf="@id/guideline"
app:layout_constraintTop_toTopOf="@id/show_gap_toggle" /> app:layout_constraintTop_toTopOf="@id/show_gap_toggle" />
@ -235,13 +239,33 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:checked="true" android:checked="true"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toTopOf="@id/disable_animation_toggle"
app:layout_constraintStart_toEndOf="@id/guideline" app:layout_constraintStart_toEndOf="@id/guideline"
app:layout_constraintTop_toBottomOf="@id/corners_toggle" app:layout_constraintTop_toBottomOf="@id/corners_toggle"
app:showText="false" app:showText="false"
app:switchPadding="0dp" app:switchPadding="0dp"
app:thumbTextPadding="0dp" /> app:thumbTextPadding="0dp" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/label_disable_animation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/disable_animation"
app:layout_constraintBottom_toBottomOf="@id/disable_animation_toggle"
app:layout_constraintEnd_toStartOf="@id/guideline"
app:layout_constraintTop_toTopOf="@id/disable_animation_toggle" />
<com.google.android.material.switchmaterial.SwitchMaterial
android:id="@+id/disable_animation_toggle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="false"
app:layout_constraintStart_toEndOf="@id/guideline"
app:layout_constraintTop_toBottomOf="@id/show_gap_toggle"
app:showText="false"
app:switchPadding="0dp"
app:thumbTextPadding="0dp" />
<androidx.constraintlayout.widget.Group <androidx.constraintlayout.widget.Group
android:id="@+id/staggered_or_grid_options" android:id="@+id/staggered_or_grid_options"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -250,3 +274,4 @@
app:constraint_referenced_ids="label_col_count,col_count_toggle,label_show_avatar_toggle,show_avatar_toggle,label_show_names_toggle,show_names_toggle" app:constraint_referenced_ids="label_col_count,col_count_toggle,label_show_avatar_toggle,show_avatar_toggle,label_show_names_toggle,show_names_toggle"
tools:visibility="visible" /> tools:visibility="visible" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>

View File

@ -249,7 +249,7 @@
<string name="profile">個人檔案</string> <string name="profile">個人檔案</string>
<string name="more">更多</string> <string name="more">更多</string>
<string name="title_dm">訊息</string> <string name="title_dm">訊息</string>
<string name="number_selected">已選 %s</string> <string name="number_selected">已選 %d</string>
<string name="relogin">重新登入</string> <string name="relogin">重新登入</string>
<string name="relogin_summary">如果遇到任何問題,請刷新您的 Cookie</string> <string name="relogin_summary">如果遇到任何問題,請刷新您的 Cookie</string>
<string name="logout_success">已成功登出!</string> <string name="logout_success">已成功登出!</string>

View File

@ -320,6 +320,16 @@
<string name="layout">Layout</string> <string name="layout">Layout</string>
<string name="opening_post">Opening post...</string> <string name="opening_post">Opening post...</string>
<string name="share">Share</string> <string name="share">Share</string>
<string name="layout_style">Layout style</string>
<string name="column_count">Column count</string>
<string name="two">2</string>
<string name="three">3</string>
<string name="show_names">Show names</string>
<string name="show_avatars">Show avatars</string>
<string name="avatar_size">Avatar size</string>
<string name="corners">Corners</string>
<string name="show_grid_gap">Show grid gap</string>
<string name="disable_animation">Disable animation</string>
<plurals name="likes_count"> <plurals name="likes_count">
<item quantity="one">%d like</item> <item quantity="one">%d like</item>
<item quantity="other">%d likes</item> <item quantity="other">%d likes</item>

View File

@ -5,7 +5,7 @@ buildscript {
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:4.1.0' classpath 'com.android.tools.build:gradle:4.1.1'
def nav_version = "2.3.0" def nav_version = "2.3.0"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version" classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version"
} }