Firebase with viewpager - android

I am currently building an app using firebase.
I have an activity in which the background and UI are the same, but the page has only the contents that change inside according to the date.
It`s kind of some diary app.
I am worried about whether I need to ViewPager or not to use ViewPager, but if I have saved it somewhere and clicked on that date, I need to display the contents with setText(). I'm not sure about that how to do more optimization.
And when I scroll horizontally across the screen, I want to see the pages change with swipe-animation. Do I have to use viewPager? I mean I use one page but I want to give a fake animation effect as the page looks. If this helps optimally.
Anyway, So I'm looking for an example that uses viewPager with firebase recycler-view, but it's a bit hard to find. Is it better to use a fragment? with this?
Optimization has been troubling for weeks on issues.
I have a lot of questions, but I would like to hear good advice on these things.
I would appreciate it if you could explain it slowly and easily.
Thank you very much for reading.

Page has only the contents that change inside according to the date.It`s kind of some diary app. I am worried about whether I need to
ViewPager or not to use ViewPager?
Yes, Viewpager with FragmentStatePagerAdapter is a good choice here, as there may be many dates in your case with its own content.
Check out the below link, it explained very well how any why to use viewpager with tabLayout.
https://guides.codepath.com/android/google-play-style-tabs-using-tablayout
And when I scroll horizontally across the screen, I want to see the
pages change with swipe-animation. Do I have to use viewPager?
For animation between the page swipes, you can use pageTransformer.
Checkout this
https://developer.android.com/training/animation/screen-slide.html
and
https://medium.com/#BashaChris/the-android-viewpager-has-become-a-fairly-popular-component-among-android-apps-its-simple-6bca403b16d4

Related

Android. Compose how to implement page by page scroll

I am new in compose and I'm trying to implement own ViewPager. I was create HorizontalPager and PagerState. Inside Pager I create LazyRow, and everything looks good but I have some problem. I want to make it scroll only one item at a time. but it doesn't work like that. As far as I understand it is responsible flingBehavior.
But unfortunately I don't quite understand how it works. I found an example in the library com.google.accompanist:accompanist-pager, but it is very difficult for me to understand, in addition, an additional library is used there (chrisbanes.github.io/snapper), is it possible to implement this in a simpler way?
Please, help me how to implement page by page scroll.
UPD: In this page https://fvilarino.medium.com/creating-a-viewpager-in-jetpack-compose-332d6a9181a5 I was found a simpler example, but scrolling on one page also does not work here, tell me please in which direction I need to move in order to perform a page by page scroll within this

Alternative to FragmentStatePagerAdapter [duplicate]

I want to find a replacement to the FragmentStatePagerAdapter + PagerFragment as we all know the FragmentStatePagerAdapter is still broken up to this day. There have been a bunch of attempts on github and by myself to make something that mimics the functionality of the FragmentStatePagerAdapter, except all of them seem to have extremely complicated logic with bugs that seem impossible to debug, e.g. https://gist.github.com/ypresto/8c13cb88a0973d071a64.
The core functionality of my application needs to be able to display fragments/views dynamically, e.g. a photo carousel with interleaving ads as the user swipes from left to right and vice versa. And we can dynamically remove or add or manage stuff from/to the adapter.
I've been thinking of potentially making a horizontal recycler view with the view taking up the full screen, and having a bunch of listeners that make the view "center" as the user swipes so that it has a view pager feel to it. But I'm not 100% convinced that this is the best solution to solving this issue. I was wondering if anyone has ever come across issues with FragmentStatePagerAdapter, and has found a good solution to workaround.
Thanks for the help!

Alternatives to android.widget.Gallery (not the Gallery app)

Apology if this has been asked before, but I've tried googling the topic without any good result. Basically I'm trying to find a replacement for Gallery widget which Google has decided to deprecate. So far I have the following candidates:
ViewPager. Unfortunately (as far as I know), you can only display one View at a time. I know someone has posted a workaround for this here: https://gist.github.com/devunwired/8cbe094bb7a783e37ad1. But I'm having problem with this approach. On my phone, three images are shown (horizontally). The most left & the most right are static, while the middle one is scrollable (like what ViewPager should do). i.e. the most left & most right image doesnt scroll as I scroll the ViewPager. So I have to turn down this solution.
GridView. Seems good, but it seems like GridView is designed to be scrollable horizontally & vertically. I just want one row, and scroll horizontally. As far as I know, Gallery is not designed with this in mind.
HorizontalScrollView. Another one that Google has suggested in the Javadocs (apart from ViewPager). Seems like a good one to use, but... if i understand it correctly, using this approach all the contents are going to be instantiated up front. There is no lazy loading..
So I'm puzzled right here. Seems like the best solution is to either use ViewPager with only one View at a time (undesirable for what I want), or stick with Gallery.
What do people think??
Thanks in advance!
android.support.v4.view.ViewPager is the definitive answer.
You can display any number of pages (Views), it all depends on the PagerAdapter. It has a method .getPageWidth(position), which gets called for each page. If it returns 0.5, for example, the page will only be half the width of the ViewPager.
Don't stick with Gallery, as it has memory leak issues.

ListView or ScrollView?

At the moment, I am using a ScrollView with a LinearLayout inside it. I want to implement a snap function. Am I better off using a ListView? Is it even possible to implement a snap function with my current setup? I want to keep things simple.
By "snap function" I am assuming that you mean paging so the user can swipe from side to side similar to the Play Store or the ICS Dialer apps. While yes, you can implement this yourself with a ScrollView, or any number of other solutions, I don't think you should because you can use Android's ViewPager class.
ViewPager is a wonderful view that uses a collection of Fragments as pages in a single layout. This will give your user a very familiar and consistent interface, and will save you a lot of very difficult code.

Swipe Indication for user Android

Suppose I have a ListView displaying exactly 10 rows that is not intended to scroll.
When the user swipes, the next list of 10 rows would be displayed. The bottom of the ListView would say something like "page 2 of 3".
How can I indicate to users that they should swipe to get the next page?
A page indicator might be helpful like you said. I view-pager may be another option. In that case I would use: http://viewpagerindicator.com/
I think you are best off rolling your own solution using a ScrollView and/or a ViewPager
According to a GoogleIO presentation about ListViews, they are coded with many "behind-the-scenes" tricks in order to optimize performance.
When you start trying to modify how they work, then you end up with a complex widget that doesn't make use of its own complexity and optimizations.
Some type of vertical view pager could be good for what you see though.
Reference: http://www.youtube.com/watch?v=wDBM6wVEO70

Categories

Resources