diff options
author | Alex Ning <chineseperson5@gmail.com> | 2019-09-01 15:43:28 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2019-09-01 15:43:28 +0000 |
commit | 870b21717403fc5a9304183816d0c9cef9f73d4d (patch) | |
tree | 4bfcc5de29be8206445314c625752c868a1c5c5b /app/src | |
parent | c9c4b7fc58622743d452a4e0c4f0da6633096575 (diff) | |
download | infinity-for-reddit-870b21717403fc5a9304183816d0c9cef9f73d4d.tar infinity-for-reddit-870b21717403fc5a9304183816d0c9cef9f73d4d.tar.gz infinity-for-reddit-870b21717403fc5a9304183816d0c9cef9f73d4d.tar.bz2 infinity-for-reddit-870b21717403fc5a9304183816d0c9cef9f73d4d.tar.lz infinity-for-reddit-870b21717403fc5a9304183816d0c9cef9f73d4d.tar.xz infinity-for-reddit-870b21717403fc5a9304183816d0c9cef9f73d4d.tar.zst infinity-for-reddit-870b21717403fc5a9304183816d0c9cef9f73d4d.zip |
Fixed lazy mode in anonymous mode in MainActivity.
Diffstat (limited to 'app/src')
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java | 143 | ||||
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/PostViewModel.java | 14 |
2 files changed, 105 insertions, 52 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java index 05061989..abe26221 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java @@ -940,70 +940,123 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe } boolean startLazyMode() { - switch (viewPager.getCurrentItem()) { - case 0: - return ((FragmentCommunicator) frontPagePostFragment).startLazyMode(); - case 1: - return ((FragmentCommunicator) popularPostFragment).startLazyMode(); - case 2: - return ((FragmentCommunicator) allPostFragment).startLazyMode(); + if(mAccessToken == null) { + switch (viewPager.getCurrentItem()) { + case 0: + return ((FragmentCommunicator) popularPostFragment).startLazyMode(); + case 1: + return ((FragmentCommunicator) allPostFragment).startLazyMode(); + } + } else { + switch (viewPager.getCurrentItem()) { + case 0: + return ((FragmentCommunicator) frontPagePostFragment).startLazyMode(); + case 1: + return ((FragmentCommunicator) popularPostFragment).startLazyMode(); + case 2: + return ((FragmentCommunicator) allPostFragment).startLazyMode(); + } } return false; } void stopLazyMode() { - switch (getCurrentLazyModeFragmentPosition()) { - case 0: - ((FragmentCommunicator) frontPagePostFragment).stopLazyMode(); - break; - case 1: - ((FragmentCommunicator) popularPostFragment).stopLazyMode(); - break; - case 2: - ((FragmentCommunicator) allPostFragment).stopLazyMode(); - break; + if(mAccessToken == null) { + switch (getCurrentLazyModeFragmentPosition()) { + case 0: + ((FragmentCommunicator) popularPostFragment).stopLazyMode(); + break; + case 1: + ((FragmentCommunicator) allPostFragment).stopLazyMode(); + break; + } + } else { + switch (getCurrentLazyModeFragmentPosition()) { + case 0: + ((FragmentCommunicator) frontPagePostFragment).stopLazyMode(); + break; + case 1: + ((FragmentCommunicator) popularPostFragment).stopLazyMode(); + break; + case 2: + ((FragmentCommunicator) allPostFragment).stopLazyMode(); + break; + } } } void resumeLazyMode() { - switch (getCurrentLazyModeFragmentPosition()) { - case 0: - ((FragmentCommunicator) frontPagePostFragment).resumeLazyMode(false); - break; - case 1: - ((FragmentCommunicator) popularPostFragment).resumeLazyMode(false); - break; - case 2: - ((FragmentCommunicator) allPostFragment).resumeLazyMode(false); - break; + if(mAccessToken == null) { + switch (getCurrentLazyModeFragmentPosition()) { + case 0: + ((FragmentCommunicator) popularPostFragment).resumeLazyMode(false); + break; + case 1: + ((FragmentCommunicator) allPostFragment).resumeLazyMode(false); + break; + } + } else { + switch (getCurrentLazyModeFragmentPosition()) { + case 0: + ((FragmentCommunicator) frontPagePostFragment).resumeLazyMode(false); + break; + case 1: + ((FragmentCommunicator) popularPostFragment).resumeLazyMode(false); + break; + case 2: + ((FragmentCommunicator) allPostFragment).resumeLazyMode(false); + break; + } } } void pauseLazyMode() { - switch (getCurrentLazyModeFragmentPosition()) { - case 0: - ((FragmentCommunicator) frontPagePostFragment).pauseLazyMode(false); - break; - case 1: - ((FragmentCommunicator) popularPostFragment).pauseLazyMode(false); - break; - case 2: - ((FragmentCommunicator) allPostFragment).pauseLazyMode(false); + if(mAccessToken == null) { + switch (getCurrentLazyModeFragmentPosition()) { + case 0: + ((FragmentCommunicator) popularPostFragment).pauseLazyMode(false); + break; + case 1: + ((FragmentCommunicator) allPostFragment).pauseLazyMode(false); + } + } else { + switch (getCurrentLazyModeFragmentPosition()) { + case 0: + ((FragmentCommunicator) frontPagePostFragment).pauseLazyMode(false); + break; + case 1: + ((FragmentCommunicator) popularPostFragment).pauseLazyMode(false); + break; + case 2: + ((FragmentCommunicator) allPostFragment).pauseLazyMode(false); + } } } int getCurrentLazyModeFragmentPosition() { - if(!isInLazyMode) { - return -1; - } else if(frontPagePostFragment != null && ((FragmentCommunicator) frontPagePostFragment).isInLazyMode()) { - return 0; - } else if(popularPostFragment != null && ((FragmentCommunicator) popularPostFragment).isInLazyMode()) { - return 1; - } else if(allPostFragment != null && ((FragmentCommunicator) allPostFragment).isInLazyMode()) { - return 2; + if(mAccessToken == null) { + if(!isInLazyMode) { + return -1; + } else if(popularPostFragment != null && ((FragmentCommunicator) popularPostFragment).isInLazyMode()) { + return 0; + } else if(allPostFragment != null && ((FragmentCommunicator) allPostFragment).isInLazyMode()) { + return 1; + } else { + return -1; + } } else { - return -1; + if(!isInLazyMode) { + return -1; + } else if(frontPagePostFragment != null && ((FragmentCommunicator) frontPagePostFragment).isInLazyMode()) { + return 0; + } else if(popularPostFragment != null && ((FragmentCommunicator) popularPostFragment).isInLazyMode()) { + return 1; + } else if(allPostFragment != null && ((FragmentCommunicator) allPostFragment).isInLazyMode()) { + return 2; + } else { + return -1; + } } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostViewModel.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostViewModel.java index cae2bace..62e58547 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostViewModel.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostViewModel.java @@ -23,7 +23,7 @@ public class PostViewModel extends ViewModel { private LiveData<PagedList<Post>> posts; private MutableLiveData<Boolean> nsfwLiveData; private MutableLiveData<String> sortTypeLiveData; - private nsfwAndSortTypeLiveData NSFWAndSortTypeLiveData; + private PostViewModel.NSFWAndSortTypeLiveData NSFWAndSortTypeLiveData; public PostViewModel(Retrofit retrofit, String accessToken, Locale locale, int postType, String sortType, int filter, boolean nsfw) { @@ -42,7 +42,7 @@ public class PostViewModel extends ViewModel { sortTypeLiveData = new MutableLiveData<>(); sortTypeLiveData.postValue(sortType); - NSFWAndSortTypeLiveData = new nsfwAndSortTypeLiveData(nsfwLiveData, sortTypeLiveData); + NSFWAndSortTypeLiveData = new NSFWAndSortTypeLiveData(nsfwLiveData, sortTypeLiveData); PagedList.Config pagedListConfig = (new PagedList.Config.Builder()) @@ -73,7 +73,7 @@ public class PostViewModel extends ViewModel { sortTypeLiveData = new MutableLiveData<>(); sortTypeLiveData.postValue(sortType); - NSFWAndSortTypeLiveData = new nsfwAndSortTypeLiveData(nsfwLiveData, sortTypeLiveData); + NSFWAndSortTypeLiveData = new NSFWAndSortTypeLiveData(nsfwLiveData, sortTypeLiveData); PagedList.Config pagedListConfig = (new PagedList.Config.Builder()) @@ -104,7 +104,7 @@ public class PostViewModel extends ViewModel { sortTypeLiveData = new MutableLiveData<>(); sortTypeLiveData.postValue(sortType); - NSFWAndSortTypeLiveData = new nsfwAndSortTypeLiveData(nsfwLiveData, sortTypeLiveData); + NSFWAndSortTypeLiveData = new NSFWAndSortTypeLiveData(nsfwLiveData, sortTypeLiveData); PagedList.Config pagedListConfig = (new PagedList.Config.Builder()) @@ -135,7 +135,7 @@ public class PostViewModel extends ViewModel { sortTypeLiveData = new MutableLiveData<>(); sortTypeLiveData.postValue(sortType); - NSFWAndSortTypeLiveData = new nsfwAndSortTypeLiveData(nsfwLiveData, sortTypeLiveData); + NSFWAndSortTypeLiveData = new NSFWAndSortTypeLiveData(nsfwLiveData, sortTypeLiveData); PagedList.Config pagedListConfig = (new PagedList.Config.Builder()) @@ -261,8 +261,8 @@ public class PostViewModel extends ViewModel { } } - private static class nsfwAndSortTypeLiveData extends MediatorLiveData<Pair<Boolean, String>> { - public nsfwAndSortTypeLiveData(LiveData<Boolean> nsfw, LiveData<String> sortType) { + private static class NSFWAndSortTypeLiveData extends MediatorLiveData<Pair<Boolean, String>> { + public NSFWAndSortTypeLiveData(LiveData<Boolean> nsfw, LiveData<String> sortType) { addSource(nsfw, accessToken1 -> setValue(Pair.create(accessToken1, sortType.getValue()))); addSource(sortType, sortType1 -> setValue(Pair.create(nsfw.getValue(), sortType1))); } |