package rasel.lunar.launcher.workers

import android.annotation.SuppressLint
import android.content.Context
import androidx.work.WorkerParameters
import rasel.lunar.launcher.model.getRssData
import rasel.lunar.launcher.home.adapters.RssFeedsParser
import rasel.lunar.launcher.utils.RssList

class NewsFeedsGetter : BaseGetter {
    var feddsUrls = arrayListOf<String>()
    constructor(context: Context, workerParams: WorkerParameters) : super(context, workerParams) {

    }

    @SuppressLint("RestrictedApi")
    override fun realWork(): Result {
        feddsUrls.clear()
        feddsUrls.addAll(RssList.newsFeeds)
        feddsUrls.addAll(RssList.getFeedUrls())

        for(url in feddsUrls) {
            for (it in RssFeedsParser.getFeeds(url)) {
                if (it.pubDate() >= limitDateTime) {
                    temp.add(it.getRssData())
                }
            }
        }


        return Result.success().apply {
            WorkersDb.insertBulkData(temp)
        }

//        temp.forEach { synchronized(rssSet){
//            rssSet.put(it.originPage(), it)
//        }  }.run {
//            rssSetTouchCount -= 1
//            Result.success() }
    }


}