0

I would like to run this the same way as I do it's Swift counterpart. In the Swift version I'm loading the json into a parser that loads the list in id (highest to lowest) and displays the thumbnail image and title (provided by the json) and when clicked it shows the video of the attached ID.

I'm currently seeing nothing similar to the SwiftUI (list view in particular) setup, if you can provide any resources or examples to as such I would appreciate it.

Here is one of the SwiftUI files

import SwiftUI
import Combine

struct VideoList: View {
@Environment(\.presentationMode) private var presentationMode
@ObservedObject private(set) var viewModel: ViewModel
@State private var isRefreshing = false

var btnBack : some View { Button(action: {
    self.presentationMode.wrappedValue.dismiss()
    }) {
        HStack {
        Image("Home") // set image here
            .aspectRatio(contentMode: .fit)
            .foregroundColor(.white)
        }
    }
}

var body: some View {
    NavigationView {
        List(viewModel.videos.sorted { $0.id > $1.id}, id: \.id) { video in
            NavigationLink(
            destination: VideoDetails(viewModel: VideoDetails.ViewModel(video: video))) {
                VideoRow(video: video)
                
            }
        }
        .onPullToRefresh(isRefreshing: $isRefreshing, perform: {
            self.viewModel.fetchVideos()
        })
        .onReceive(viewModel.$videos, perform: { _ in
            self.isRefreshing = false
        })
    }
    .onAppear(perform: viewModel.fetchVideos)
    .navigationViewStyle(StackNavigationViewStyle())
    .navigationBarBackButtonHidden(true)
            .navigationBarItems(leading: btnBack)

}
}

Here is a clip from the json it is loading

{
"videos": [
    {
        "id": 97,
        "name": "name",
        "thumbnail": "https://videodelivery.net//thumbnails/thumbnail.jpg",
        "description": "October 11th, 2020",
        "video_link": "https://videodelivery.net//manifest/video.m3u8"
    },
    {
        "id": 96,
        "name": "name",
        "thumbnail": "https://videodelivery.net//thumbnails/thumbnail.jpg",
        "description": "October 11th, 2020",
        "video_link": "https://videodelivery.net//manifest/video.m3u8"
    },

1 Answers1

0

https://riptutorial.com/android/example/29241/try-offline-disk-cache-first--then-go-online-and-fetch-the-image

This is a fine example of caching thumbnails , follow this , only change would be :You write picasso.load in your adapter's getView method.Just set the imageview sing Picasso.Now, you can pass the video url when list view when tapped by using an intent inside onItemCLickListener and then in the destination activity, you can have a medi player where you can use that url to just set it on the medi player and play the video.

This solution will work for lists as well.

Also since picasso use memory caching by default, we have to use OKHTTP disk Cache as well because othewise Picaso would just check thumbnails in memory cache and would fail.

Rishabh Ritweek
  • 491
  • 3
  • 9
  • the problem isn't really in fetching images. it's fetching images putting them in an updating list structure, and then making them clickable to play the relevant content that I'm struggling with. If it isn't obvious I don't do much with android thus the confusion of where to start. – RealTechyGod Oct 23 '20 at 21:42
  • why wouldn't it updated if you have implemented caching perfectly..nd how r u trynna play the video.. if u have a remote url u can simply pass that remote url via intent and set it on MediaPlayer in say another activity.. can you explain more if you mean anything different by updated list?? – Rishabh Ritweek Oct 23 '20 at 21:45
  • but it needs to be in a list. again the main problem is I'm unsure of what is the best and least resource heavy way to load a list from json display the image and name provided but on click play the relevant content in the default player much like iOS does. @RishabhRitweek Update: every week there will be a new video so the json will be updated so users can see the new content – RealTechyGod Oct 23 '20 at 21:49
  • one sec, i saw that u already have a url for thumbnail ..so updating my answer..this shuld work – Rishabh Ritweek Oct 23 '20 at 21:51
  • the updated answer is not exactly the problem I'm having. Loading images and name from json into a list is simple (however I'm open to whatever way is needed to fulfill the second part) the second part though is how to get such items when clicked on to load the video file in the native player (like iOS) "video_link": "https://videodelivery.net//manifest/video.m3u8" – RealTechyGod Oct 26 '20 at 18:24