diff options
author | ByteHamster <info@bytehamster.com> | 2019-09-29 22:27:46 +0200 |
---|---|---|
committer | ByteHamster <info@bytehamster.com> | 2019-09-29 22:27:46 +0200 |
commit | 31c746684bbdb44c6b737a52bf5c8debf05625d6 (patch) | |
tree | e7d215178074847a4948a3dd97d2335551f720cf /app | |
parent | 0187786047175a4be1e4fa01c9fa7da8eca49ff3 (diff) | |
download | AntennaPod-31c746684bbdb44c6b737a52bf5c8debf05625d6.zip |
Added ViewModel to FeedInfoFragment for even smoother animation
Diffstat (limited to 'app')
-rw-r--r-- | app/src/main/java/de/danoeh/antennapod/fragment/FeedInfoFragment.java | 29 | ||||
-rw-r--r-- | app/src/main/java/de/danoeh/antennapod/fragment/FeedSettingsFragment.java | 4 | ||||
-rw-r--r-- | app/src/main/java/de/danoeh/antennapod/viewmodel/FeedLoaderViewModel.java (renamed from app/src/main/java/de/danoeh/antennapod/viewmodel/FeedSettingsViewModel.java) | 2 |
3 files changed, 14 insertions, 21 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/FeedInfoFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/FeedInfoFragment.java index c37d1e3eb..b47559124 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/FeedInfoFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/FeedInfoFragment.java @@ -1,5 +1,6 @@ package de.danoeh.antennapod.fragment; +import android.arch.lifecycle.ViewModelProviders; import android.content.ClipData; import android.content.Context; import android.content.Intent; @@ -26,6 +27,7 @@ import com.bumptech.glide.request.RequestOptions; import com.joanzapata.iconify.Iconify; import de.danoeh.antennapod.activity.MainActivity; +import de.danoeh.antennapod.viewmodel.FeedLoaderViewModel; import org.apache.commons.lang3.StringUtils; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; @@ -102,7 +104,6 @@ public class FeedInfoFragment extends Fragment { @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View root = inflater.inflate(R.layout.feedinfo, null); - long feedId = getArguments().getLong(EXTRA_FEED_ID, -1); setHasOptionsMenu(true); imgvCover = root.findViewById(R.id.imgvCover); @@ -123,27 +124,19 @@ public class FeedInfoFragment extends Fragment { txtvUrl = root.findViewById(R.id.txtvUrl); txtvUrl.setOnClickListener(copyUrlToClipboard); + postponeEnterTransition(); + return root; + } - disposable = Maybe.create((MaybeOnSubscribe<Feed>) emitter -> { - Feed feed = DBReader.getFeed(feedId); - if (feed != null) { - emitter.onSuccess(feed); - } else { - emitter.onComplete(); - } - }) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) + @Override + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { + long feedId = getArguments().getLong(EXTRA_FEED_ID); + ViewModelProviders.of(getActivity()).get(FeedLoaderViewModel.class).getFeed(feedId) .subscribe(result -> { feed = result; showFeed(); - }, error -> { - Log.d(TAG, Log.getStackTraceString(error)); - }, () -> { - Log.e(TAG, "Activity was started with invalid arguments"); - }); - - return root; + startPostponedEnterTransition(); + }).dispose(); } private void showFeed() { diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/FeedSettingsFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/FeedSettingsFragment.java index be3bf12af..dd45c9baa 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/FeedSettingsFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/FeedSettingsFragment.java @@ -17,7 +17,7 @@ import de.danoeh.antennapod.core.preferences.UserPreferences; import de.danoeh.antennapod.core.storage.DBWriter; import de.danoeh.antennapod.dialog.AuthenticationDialog; import de.danoeh.antennapod.dialog.EpisodeFilterDialog; -import de.danoeh.antennapod.viewmodel.FeedSettingsViewModel; +import de.danoeh.antennapod.viewmodel.FeedLoaderViewModel; public class FeedSettingsFragment extends PreferenceFragmentCompat { private static final CharSequence PREF_EPISODE_FILTER = "episodeFilter"; @@ -39,7 +39,7 @@ public class FeedSettingsFragment extends PreferenceFragmentCompat { postponeEnterTransition(); long feedId = getArguments().getLong(EXTRA_FEED_ID); - ViewModelProviders.of(getActivity()).get(FeedSettingsViewModel.class).getFeed(feedId) + ViewModelProviders.of(getActivity()).get(FeedLoaderViewModel.class).getFeed(feedId) .subscribe(result -> { feed = result; feedPreferences = feed.getPreferences(); diff --git a/app/src/main/java/de/danoeh/antennapod/viewmodel/FeedSettingsViewModel.java b/app/src/main/java/de/danoeh/antennapod/viewmodel/FeedLoaderViewModel.java index fe11a645c..bba14fe2d 100644 --- a/app/src/main/java/de/danoeh/antennapod/viewmodel/FeedSettingsViewModel.java +++ b/app/src/main/java/de/danoeh/antennapod/viewmodel/FeedLoaderViewModel.java @@ -5,7 +5,7 @@ import de.danoeh.antennapod.core.feed.Feed; import de.danoeh.antennapod.core.storage.DBReader; import io.reactivex.Maybe; -public class FeedSettingsViewModel extends ViewModel { +public class FeedLoaderViewModel extends ViewModel { private Feed feed; public Maybe<Feed> getFeed(long feedId) { |