diff --git a/CHANGELOG.md b/CHANGELOG.md index db18171..50dca8d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,14 +9,15 @@ * Ask permission when entering the general preferences. * fix #230: page not loading because of '$' signs. * fix #232: user profiles in private messages. +* fix #233: on the topic list, keep the filter (Favorites, Read...) when rotating the screen ## v1.0.1 ### Fixed -* #2 : reply window opened multiple times -* #8 : event received too late in activity lifecycle -* #9 : nullpointer exception in user manager +* #2: reply window opened multiple times +* #8: event received too late in activity lifecycle +* #9: nullpointer exception in user manager ## v1.0.0 diff --git a/app/src/main/java/com/ayuget/redface/data/api/model/TopicFilter.java b/app/src/main/java/com/ayuget/redface/data/api/model/TopicFilter.java index 6d8adcd..528307e 100644 --- a/app/src/main/java/com/ayuget/redface/data/api/model/TopicFilter.java +++ b/app/src/main/java/com/ayuget/redface/data/api/model/TopicFilter.java @@ -18,6 +18,8 @@ import android.content.Context; +import androidx.annotation.NonNull; + import com.ayuget.redface.R; public enum TopicFilter { @@ -26,6 +28,7 @@ public enum TopicFilter { PARTICIPATED, READ; + @NonNull public String resolve(Context context) { if (this == NONE) { return context.getResources().getString(R.string.action_topics_filter_all); diff --git a/app/src/main/java/com/ayuget/redface/ui/fragment/TopicListFragment.java b/app/src/main/java/com/ayuget/redface/ui/fragment/TopicListFragment.java index 7b51bad..3a96007 100644 --- a/app/src/main/java/com/ayuget/redface/ui/fragment/TopicListFragment.java +++ b/app/src/main/java/com/ayuget/redface/ui/fragment/TopicListFragment.java @@ -69,6 +69,7 @@ @FragmentWithArgs public class TopicListFragment extends ToggleToolbarFragment implements TopicsAdapter.OnTopicClickedListener { private static final String ARG_LAST_LOADED_PAGE = "last_loaded_page"; + private static final String ARG_TOPIC_FILTER = "topic_filter"; /** * Interface definition for a callback to be invoked when a topic in this fragment has @@ -133,6 +134,13 @@ public TopicListFragment() { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + // Restore the list of topics when the fragment is recreated by the framework + if (savedInstanceState != null) { + lastLoadedPage = savedInstanceState.getInt(ARG_LAST_LOADED_PAGE, 0); + topicFilter = (TopicFilter) savedInstanceState.get(ARG_TOPIC_FILTER); + savedInstanceState.clear(); + } + if (topicFilter == null) { topicFilter = TopicFilter.NONE; } @@ -188,17 +196,6 @@ private void refreshTopicList() { loadTopics(); } - @Override - public void onActivityCreated(@Nullable Bundle savedInstanceState) { - super.onActivityCreated(savedInstanceState); - - // Restore the list of topics when the fragment is recreated by the framework - if (savedInstanceState != null) { - lastLoadedPage = savedInstanceState.getInt(ARG_LAST_LOADED_PAGE, 0); - savedInstanceState.clear(); - } - } - @Override public void onResume() { super.onResume(); @@ -209,7 +206,7 @@ public void onResume() { refreshTopicList(); }); - if (displayedTopics == null || displayedTopics.size() == 0 || settings.refreshTopicList()) { + if (displayedTopics == null || displayedTopics.isEmpty() || settings.refreshTopicList()) { displayedTopics = new ArrayList<>(); loadTopics(); } else { @@ -299,6 +296,7 @@ public void onCreateOptionsMenu(Toolbar toolbar) { public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); outState.putInt(ARG_LAST_LOADED_PAGE, lastLoadedPage); + outState.putSerializable(ARG_TOPIC_FILTER, topicFilter); } @Override @@ -379,7 +377,7 @@ public void onNext(List loadedTopics) { public void onError(Throwable throwable) { Timber.e(throwable, "Error loading first page for category '%s', subcategory '%s'", category.name(), subcategory); - if (displayedTopics.size() == 0) { + if (displayedTopics.isEmpty()) { dataPresenter.showErrorView(); } else { SnackbarHelper.make(TopicListFragment.this, R.string.error_loading_topics).show();