mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-12-25 02:18:23 +01:00
Don't start lazy mode if there is no posts. Stop lazy mode when refreshing.
This commit is contained in:
parent
864eb21269
commit
2a356aa12e
@ -240,11 +240,12 @@ public class AccountPostsActivity extends AppCompatActivity implements UserThing
|
|||||||
params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL | AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS);
|
params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL | AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS);
|
||||||
collapsingToolbarLayout.setLayoutParams(params);
|
collapsingToolbarLayout.setLayoutParams(params);
|
||||||
} else {
|
} else {
|
||||||
((FragmentCommunicator) mFragment).startLazyMode();
|
if(((FragmentCommunicator) mFragment).startLazyMode()) {
|
||||||
isInLazyMode = true;
|
isInLazyMode = true;
|
||||||
lazyModeItem.setTitle(R.string.action_stop_lazy_mode);
|
lazyModeItem.setTitle(R.string.action_stop_lazy_mode);
|
||||||
params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_NO_SCROLL);
|
params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_NO_SCROLL);
|
||||||
collapsingToolbarLayout.setLayoutParams(params);
|
collapsingToolbarLayout.setLayoutParams(params);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
case android.R.id.home:
|
case android.R.id.home:
|
||||||
|
@ -3,7 +3,9 @@ package ml.docilealligator.infinityforreddit;
|
|||||||
interface FragmentCommunicator {
|
interface FragmentCommunicator {
|
||||||
void refresh();
|
void refresh();
|
||||||
default void changeNSFW(boolean nsfw) {};
|
default void changeNSFW(boolean nsfw) {};
|
||||||
default void startLazyMode() {}
|
default boolean startLazyMode() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
default void stopLazyMode() {}
|
default void stopLazyMode() {}
|
||||||
default void resumeLazyMode(boolean resumeNow) {}
|
default void resumeLazyMode(boolean resumeNow) {}
|
||||||
default void pauseLazyMode(boolean startTimer) {}
|
default void pauseLazyMode(boolean startTimer) {}
|
||||||
|
@ -719,11 +719,12 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe
|
|||||||
params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL | AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS);
|
params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL | AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS);
|
||||||
collapsingToolbarLayout.setLayoutParams(params);
|
collapsingToolbarLayout.setLayoutParams(params);
|
||||||
} else {
|
} else {
|
||||||
sectionsPagerAdapter.startLazyMode();
|
if(sectionsPagerAdapter.startLazyMode()) {
|
||||||
isInLazyMode = true;
|
isInLazyMode = true;
|
||||||
lazyModeItem.setTitle(R.string.action_stop_lazy_mode);
|
lazyModeItem.setTitle(R.string.action_stop_lazy_mode);
|
||||||
params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_NO_SCROLL);
|
params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_NO_SCROLL);
|
||||||
collapsingToolbarLayout.setLayoutParams(params);
|
collapsingToolbarLayout.setLayoutParams(params);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -935,17 +936,17 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe
|
|||||||
return fragment;
|
return fragment;
|
||||||
}
|
}
|
||||||
|
|
||||||
void startLazyMode() {
|
boolean startLazyMode() {
|
||||||
switch (viewPager.getCurrentItem()) {
|
switch (viewPager.getCurrentItem()) {
|
||||||
case 0:
|
case 0:
|
||||||
((FragmentCommunicator) frontPagePostFragment).startLazyMode();
|
return ((FragmentCommunicator) frontPagePostFragment).startLazyMode();
|
||||||
break;
|
|
||||||
case 1:
|
case 1:
|
||||||
((FragmentCommunicator) popularPostFragment).startLazyMode();
|
return ((FragmentCommunicator) popularPostFragment).startLazyMode();
|
||||||
break;
|
|
||||||
case 2:
|
case 2:
|
||||||
((FragmentCommunicator) allPostFragment).startLazyMode();
|
return ((FragmentCommunicator) allPostFragment).startLazyMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void stopLazyMode() {
|
void stopLazyMode() {
|
||||||
|
@ -75,6 +75,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
|
|
||||||
private boolean isInLazyMode = false;
|
private boolean isInLazyMode = false;
|
||||||
private boolean isLazyModePaused = false;
|
private boolean isLazyModePaused = false;
|
||||||
|
private boolean hasPost = false;
|
||||||
|
|
||||||
private PostRecyclerViewAdapter mAdapter;
|
private PostRecyclerViewAdapter mAdapter;
|
||||||
private RecyclerView.SmoothScroller smoothScroller;
|
private RecyclerView.SmoothScroller smoothScroller;
|
||||||
@ -367,16 +368,19 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
});
|
});
|
||||||
|
|
||||||
mPostViewModel.hasPost().observe(this, hasPost -> {
|
mPostViewModel.hasPost().observe(this, hasPost -> {
|
||||||
|
this.hasPost = hasPost;
|
||||||
if(hasPost) {
|
if(hasPost) {
|
||||||
mFetchPostInfoLinearLayout.setVisibility(View.GONE);
|
mFetchPostInfoLinearLayout.setVisibility(View.GONE);
|
||||||
} else {
|
} else {
|
||||||
|
if(isInLazyMode) {
|
||||||
|
stopLazyMode();
|
||||||
|
}
|
||||||
|
|
||||||
showErrorView(R.string.no_posts);
|
showErrorView(R.string.no_posts);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
mPostViewModel.getPaginationNetworkState().observe(this, networkState -> {
|
mPostViewModel.getPaginationNetworkState().observe(this, networkState -> mAdapter.setNetworkState(networkState));
|
||||||
mAdapter.setNetworkState(networkState);
|
|
||||||
});
|
|
||||||
|
|
||||||
return rootView;
|
return rootView;
|
||||||
}
|
}
|
||||||
@ -399,6 +403,9 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void refresh() {
|
public void refresh() {
|
||||||
|
if(isInLazyMode) {
|
||||||
|
stopLazyMode();
|
||||||
|
}
|
||||||
mPostViewModel.refresh();
|
mPostViewModel.refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -417,7 +424,12 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void startLazyMode() {
|
public boolean startLazyMode() {
|
||||||
|
if(!hasPost) {
|
||||||
|
Toast.makeText(activity, R.string.no_posts_no_lazy_mode, Toast.LENGTH_SHORT).show();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
isInLazyMode = true;
|
isInLazyMode = true;
|
||||||
isLazyModePaused = false;
|
isLazyModePaused = false;
|
||||||
|
|
||||||
@ -426,6 +438,8 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||||
Toast.makeText(activity, getString(R.string.lazy_mode_start, lazyModeInterval),
|
Toast.makeText(activity, getString(R.string.lazy_mode_start, lazyModeInterval),
|
||||||
Toast.LENGTH_SHORT).show();
|
Toast.LENGTH_SHORT).show();
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -493,11 +493,14 @@ public class ViewSubredditDetailActivity extends AppCompatActivity implements So
|
|||||||
collapsingToolbarLayout.setLayoutParams(params);
|
collapsingToolbarLayout.setLayoutParams(params);
|
||||||
} else {
|
} else {
|
||||||
isInLazyMode = true;
|
isInLazyMode = true;
|
||||||
((FragmentCommunicator) mFragment).startLazyMode();
|
if(((FragmentCommunicator) mFragment).startLazyMode()) {
|
||||||
lazyModeItem.setTitle(R.string.action_stop_lazy_mode);
|
lazyModeItem.setTitle(R.string.action_stop_lazy_mode);
|
||||||
appBarLayout.setExpanded(false);
|
appBarLayout.setExpanded(false);
|
||||||
params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL | AppBarLayout.LayoutParams.SCROLL_FLAG_EXIT_UNTIL_COLLAPSED);
|
params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL | AppBarLayout.LayoutParams.SCROLL_FLAG_EXIT_UNTIL_COLLAPSED);
|
||||||
collapsingToolbarLayout.setLayoutParams(params);
|
collapsingToolbarLayout.setLayoutParams(params);
|
||||||
|
} else {
|
||||||
|
isInLazyMode = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -546,11 +546,14 @@ public class ViewUserDetailActivity extends AppCompatActivity implements UserThi
|
|||||||
collapsingToolbarLayout.setLayoutParams(params);
|
collapsingToolbarLayout.setLayoutParams(params);
|
||||||
} else {
|
} else {
|
||||||
isInLazyMode = true;
|
isInLazyMode = true;
|
||||||
sectionsPagerAdapter.startLazyMode();
|
if(sectionsPagerAdapter.startLazyMode()) {
|
||||||
lazyModeItem.setTitle(R.string.action_stop_lazy_mode);
|
lazyModeItem.setTitle(R.string.action_stop_lazy_mode);
|
||||||
appBarLayout.setExpanded(false);
|
appBarLayout.setExpanded(false);
|
||||||
params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL | AppBarLayout.LayoutParams.SCROLL_FLAG_EXIT_UNTIL_COLLAPSED);
|
params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL | AppBarLayout.LayoutParams.SCROLL_FLAG_EXIT_UNTIL_COLLAPSED);
|
||||||
collapsingToolbarLayout.setLayoutParams(params);
|
collapsingToolbarLayout.setLayoutParams(params);
|
||||||
|
} else {
|
||||||
|
isInLazyMode = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -708,10 +711,11 @@ public class ViewUserDetailActivity extends AppCompatActivity implements UserThi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void startLazyMode() {
|
boolean startLazyMode() {
|
||||||
if(postFragment != null) {
|
if(postFragment != null) {
|
||||||
((FragmentCommunicator) postFragment).startLazyMode();
|
return ((FragmentCommunicator) postFragment).startLazyMode();
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void stopLazyMode() {
|
void stopLazyMode() {
|
||||||
|
@ -102,6 +102,7 @@
|
|||||||
<string name="app_label">Infinity</string>
|
<string name="app_label">Infinity</string>
|
||||||
<string name="search_hint">Search anything</string>
|
<string name="search_hint">Search anything</string>
|
||||||
|
|
||||||
|
<string name="no_posts_no_lazy_mode">No posts available</string>
|
||||||
<string name="lazy_mode_start">Lazy Mode starts in %1$.1fs</string>
|
<string name="lazy_mode_start">Lazy Mode starts in %1$.1fs</string>
|
||||||
<string name="lazy_mode_stop">Lazy Mode stopped</string>
|
<string name="lazy_mode_stop">Lazy Mode stopped</string>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user