How to properly implement a feed (similar to Facebook / Instagram) in Android?

I am very new to Android. I am trying to create a social application that contains a lot of images and some metadata. It has a screen similar to a Facebook feed. I want to make this screen as smooth and standard as possible.

Here are the libraries that I use: OkHttp, Picasso, Retrofit, Gson.

Now I am collecting all json at a time, since I ran dummy values ​​in the backend, and the answer is quite small. But in the future, it will have previous and next fields to limit the json response.

Some of the questions I have right now are:

  • I am using Picasso with OkHttp. Are cache images on disk either or only in memory?

  • What are the best methods for caching a feed? Since most of the content is images, should I just let Picasso handle caching, or should I cache some elements myself? I heard about the DiskLruCache library from JakeWharton, but have not tried it. Should I go with him?

  • How to save the contents of the feed (for example, 3 or 4) in any direction of scrolling in the cache, so that the scrolling looks smooth and that the images do not load after appearing in the view.

  • How to automatically process the json response using the previous and next fields when the user scrolls through all the content that was selected this time. Basically I want to run queries based on the amount of content scrollable based on cursors.

  • Suppose there is a button and the user clicks it, should I change the number of likes in the user interface and side by sending a POST request to update the counter, or should I send a request and wait for the counter to be updated from the server before it is updated in the user interface?

I already went through the Instamaterial source code and found out some amazing things. But this does not demonstrate the integration of the entire base.

I just want to know if there are any other open source applications that I can study or study with. If you know any tutorials that will help too. I just want the app to look as smooth as possible, and you want to learn some best practices.

+7
performance android caching retrofit picasso
source share
3 answers
  • This will cache both the disk and the memory. If you set Picasso mode to debug mode, an indicator will appear that describes where the image was downloaded (memory / disk / network)

  • If you do not mind that Picasso controls how long things are cached, etc., then it should be good for him to handle caching. I'm also sure Picasso uses DiskLruCache

  • If your main problem is with images, they will all be cached and should not be downloaded after they do it once (until they are updated). You can also register a callback with Picasso to change the logic around showing or hiding placeholders.

  • I think what you are looking for is a scroll listener on your list (I assume you are using a list view). When it passes a certain position (5/6), start loading the next 10. If you use recyclerview, you can do this using the onScrollStateChanged function in the scroll listener and use LinearLayoutManager to call findLastVisibleItemPosition

  • It doesn't matter which approach you go with. If you think it will take a long time to update the server counter (which it should not), then it is probably best to update it locally first.

+6
source share

1. I would suggest you check out the Image Management Library on Facebook , which is Fresco , which is pretty awesome and mature compared to other image upload libraries.

2.Fresco processes all image caching from 3 architecture levels ( BITMAP_MEMORY_CACHE , ENCODED_MEMORY_CACHE and DISK_CACHE ). It also reduces OOM problems (out of memory). When the image in the view exits the screen, it automatically processes the bitmap image, therefore, freeing up memory.

3. For this, you implement Pagination, yes, of course, you may have to send the previous position or index of the position of the record so that you can get the points it needs.

4.To provide the user with a smooth experience in your application, you must increase the counter and at the same time send a request for sending to your server.

You can also check this Facebook tutorial as a channel .

+3
source share

I would prefer some approaches to some of your questions:

To handle JSON :

You can use the Retrofit library, so adding and removing files on the server side will be easily handled on the side of your Android client. Just deleting or adding a variable in the Java class will be enough!

To cash images :

I suggest you use Fresco , facebook library, it will facilitate your work. as it can handle rounded corner transforms, load progress bars, circular images, and many other features. Thus, not only handle cash and discs for you, but also works better with different image formats.

(I used picasso in my last project, some photos and some URIs didn’t work well, I tried Picasso, Glide and Universal Image Loader, on the same image and the same link ... ONLY Fresco can work fine for me)

This is not quite the answer to your questions, but I wanted to share my experience with those libraries that can help you.

+3
source share

All Articles