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);
|
||||
collapsingToolbarLayout.setLayoutParams(params);
|
||||
} else {
|
||||
((FragmentCommunicator) mFragment).startLazyMode();
|
||||
isInLazyMode = true;
|
||||
lazyModeItem.setTitle(R.string.action_stop_lazy_mode);
|
||||
params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_NO_SCROLL);
|
||||
collapsingToolbarLayout.setLayoutParams(params);
|
||||
if(((FragmentCommunicator) mFragment).startLazyMode()) {
|
||||
isInLazyMode = true;
|
||||
lazyModeItem.setTitle(R.string.action_stop_lazy_mode);
|
||||
params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_NO_SCROLL);
|
||||
collapsingToolbarLayout.setLayoutParams(params);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
case android.R.id.home:
|
||||
|
@ -3,7 +3,9 @@ package ml.docilealligator.infinityforreddit;
|
||||
interface FragmentCommunicator {
|
||||
void refresh();
|
||||
default void changeNSFW(boolean nsfw) {};
|
||||
default void startLazyMode() {}
|
||||
default boolean startLazyMode() {
|
||||
return false;
|
||||
}
|
||||
default void stopLazyMode() {}
|
||||
default void resumeLazyMode(boolean resumeNow) {}
|
||||
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);
|
||||
collapsingToolbarLayout.setLayoutParams(params);
|
||||
} else {
|
||||
sectionsPagerAdapter.startLazyMode();
|
||||
isInLazyMode = true;
|
||||
lazyModeItem.setTitle(R.string.action_stop_lazy_mode);
|
||||
params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_NO_SCROLL);
|
||||
collapsingToolbarLayout.setLayoutParams(params);
|
||||
if(sectionsPagerAdapter.startLazyMode()) {
|
||||
isInLazyMode = true;
|
||||
lazyModeItem.setTitle(R.string.action_stop_lazy_mode);
|
||||
params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_NO_SCROLL);
|
||||
collapsingToolbarLayout.setLayoutParams(params);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -935,17 +936,17 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe
|
||||
return fragment;
|
||||
}
|
||||
|
||||
void startLazyMode() {
|
||||
boolean startLazyMode() {
|
||||
switch (viewPager.getCurrentItem()) {
|
||||
case 0:
|
||||
((FragmentCommunicator) frontPagePostFragment).startLazyMode();
|
||||
break;
|
||||
return ((FragmentCommunicator) frontPagePostFragment).startLazyMode();
|
||||
case 1:
|
||||
((FragmentCommunicator) popularPostFragment).startLazyMode();
|
||||
break;
|
||||
return ((FragmentCommunicator) popularPostFragment).startLazyMode();
|
||||
case 2:
|
||||
((FragmentCommunicator) allPostFragment).startLazyMode();
|
||||
return ((FragmentCommunicator) allPostFragment).startLazyMode();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void stopLazyMode() {
|
||||
|
@ -75,6 +75,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
||||
|
||||
private boolean isInLazyMode = false;
|
||||
private boolean isLazyModePaused = false;
|
||||
private boolean hasPost = false;
|
||||
|
||||
private PostRecyclerViewAdapter mAdapter;
|
||||
private RecyclerView.SmoothScroller smoothScroller;
|
||||
@ -367,16 +368,19 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
||||
});
|
||||
|
||||
mPostViewModel.hasPost().observe(this, hasPost -> {
|
||||
this.hasPost = hasPost;
|
||||
if(hasPost) {
|
||||
mFetchPostInfoLinearLayout.setVisibility(View.GONE);
|
||||
} else {
|
||||
if(isInLazyMode) {
|
||||
stopLazyMode();
|
||||
}
|
||||
|
||||
showErrorView(R.string.no_posts);
|
||||
}
|
||||
});
|
||||
|
||||
mPostViewModel.getPaginationNetworkState().observe(this, networkState -> {
|
||||
mAdapter.setNetworkState(networkState);
|
||||
});
|
||||
mPostViewModel.getPaginationNetworkState().observe(this, networkState -> mAdapter.setNetworkState(networkState));
|
||||
|
||||
return rootView;
|
||||
}
|
||||
@ -399,6 +403,9 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
||||
|
||||
@Override
|
||||
public void refresh() {
|
||||
if(isInLazyMode) {
|
||||
stopLazyMode();
|
||||
}
|
||||
mPostViewModel.refresh();
|
||||
}
|
||||
|
||||
@ -417,7 +424,12 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
||||
}
|
||||
|
||||
@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;
|
||||
isLazyModePaused = false;
|
||||
|
||||
@ -426,6 +438,8 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
||||
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
Toast.makeText(activity, getString(R.string.lazy_mode_start, lazyModeInterval),
|
||||
Toast.LENGTH_SHORT).show();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -493,11 +493,14 @@ public class ViewSubredditDetailActivity extends AppCompatActivity implements So
|
||||
collapsingToolbarLayout.setLayoutParams(params);
|
||||
} else {
|
||||
isInLazyMode = true;
|
||||
((FragmentCommunicator) mFragment).startLazyMode();
|
||||
lazyModeItem.setTitle(R.string.action_stop_lazy_mode);
|
||||
appBarLayout.setExpanded(false);
|
||||
params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL | AppBarLayout.LayoutParams.SCROLL_FLAG_EXIT_UNTIL_COLLAPSED);
|
||||
collapsingToolbarLayout.setLayoutParams(params);
|
||||
if(((FragmentCommunicator) mFragment).startLazyMode()) {
|
||||
lazyModeItem.setTitle(R.string.action_stop_lazy_mode);
|
||||
appBarLayout.setExpanded(false);
|
||||
params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL | AppBarLayout.LayoutParams.SCROLL_FLAG_EXIT_UNTIL_COLLAPSED);
|
||||
collapsingToolbarLayout.setLayoutParams(params);
|
||||
} else {
|
||||
isInLazyMode = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
@ -546,11 +546,14 @@ public class ViewUserDetailActivity extends AppCompatActivity implements UserThi
|
||||
collapsingToolbarLayout.setLayoutParams(params);
|
||||
} else {
|
||||
isInLazyMode = true;
|
||||
sectionsPagerAdapter.startLazyMode();
|
||||
lazyModeItem.setTitle(R.string.action_stop_lazy_mode);
|
||||
appBarLayout.setExpanded(false);
|
||||
params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL | AppBarLayout.LayoutParams.SCROLL_FLAG_EXIT_UNTIL_COLLAPSED);
|
||||
collapsingToolbarLayout.setLayoutParams(params);
|
||||
if(sectionsPagerAdapter.startLazyMode()) {
|
||||
lazyModeItem.setTitle(R.string.action_stop_lazy_mode);
|
||||
appBarLayout.setExpanded(false);
|
||||
params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL | AppBarLayout.LayoutParams.SCROLL_FLAG_EXIT_UNTIL_COLLAPSED);
|
||||
collapsingToolbarLayout.setLayoutParams(params);
|
||||
} else {
|
||||
isInLazyMode = false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -708,10 +711,11 @@ public class ViewUserDetailActivity extends AppCompatActivity implements UserThi
|
||||
}
|
||||
}
|
||||
|
||||
void startLazyMode() {
|
||||
boolean startLazyMode() {
|
||||
if(postFragment != null) {
|
||||
((FragmentCommunicator) postFragment).startLazyMode();
|
||||
return ((FragmentCommunicator) postFragment).startLazyMode();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void stopLazyMode() {
|
||||
|
@ -102,6 +102,7 @@
|
||||
<string name="app_label">Infinity</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_stop">Lazy Mode stopped</string>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user