Commit b3188013 authored by Nicolas Pomepuy's avatar Nicolas Pomepuy

Improve UI

parent e336daac
......@@ -224,7 +224,8 @@ class MainActivity : AppCompatActivity(), PermissionHelper.OnVLCPermissionResult
link, "", "", "", "", null
)
PodcastApp.database.podcastDao().insert(podcastEntry)
UpdateManager.updatePodcast(this, podcastEntry)
val poscast = PodcastApp.database.podcastsWithEpisodeDao().loadPodcastWithEpisodes(link)
UpdateManager.updatePodcast(this, poscast)
handler.obtainMessage(PODCAST_ADD_SUCCESS).sendToTarget()
......
......@@ -17,6 +17,10 @@ class PodcastService : VLCExtensionService() {
return
}
if (stringId == "") {
browseSubscriptions()
return
}
PodcastApp.appExecutors.diskIO().execute {
val dateFormat = android.text.format.DateFormat.getDateFormat(applicationContext)
val episodes = PodcastApp.database.episodeDao().getAllByPodcast(stringId).sortedByDescending { it.createdAt }
......@@ -36,17 +40,22 @@ class PodcastService : VLCExtensionService() {
mServiceHandler.post { updateList(podcast.title, casts, false, false) }
mServiceHandler.post { updateList(podcast.title, stringId, casts, false, false) }
}
}
override fun refresh() {
override fun refresh(parent:String) {
if (BuildConfig.DEBUG) Log.d(TAG, "Refresh")
PodcastApp.appExecutors.networkIO().execute {
UpdateManager.updateAll(this)
// mServiceHandler.post { updateList(null, null, false, false) }
val podcastWithEpisodes = PodcastApp.database.podcastsWithEpisodeDao().findPodcastWithEpisodes(parent)
if (podcastWithEpisodes != null) {
UpdateManager.updatePodcast(this, podcastWithEpisodes)
}
browse(parent)
}
}
......@@ -55,7 +64,7 @@ class PodcastService : VLCExtensionService() {
val episode = PodcastApp.database.episodeDao().get(id)
if (episode != null) {
episode.progress = progress
PodcastApp.database.episodeDao().insert(episode)
PodcastApp.database.episodeDao().insertOrUpdate(episode)
}
......@@ -65,10 +74,11 @@ class PodcastService : VLCExtensionService() {
val episode = PodcastApp.database.episodeDao().get(id)
if (episode != null) {
episode.isRead = read
PodcastApp.database.episodeDao().insert(episode)
PodcastApp.database.episodeDao().insertOrUpdate(episode)
}
}
public override fun onInitialize() {
browseSubscriptions()
}
......@@ -90,7 +100,7 @@ class PodcastService : VLCExtensionService() {
}
mServiceHandler.post { updateList("podcasts", items, true, false) }
mServiceHandler.post { updateList("podcasts", "", items, true, false) }
}
}
......@@ -7,7 +7,7 @@ import org.videolan.podcast.core.room.entities.EpisodeEntity
@Dao
interface EpisodeDao {
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insert(episodeEntity: EpisodeEntity)
fun insertOrUpdate(episodeEntity: EpisodeEntity)
@Delete
fun delete(episodeEntity: EpisodeEntity)
......
......@@ -11,4 +11,13 @@ interface PodcastsWithEpisodesDao {
@Query("SELECT * FROM podcast WHERE updated_at IS NOT NULL")
fun loadPodcastsLive(): LiveData<List<PodcastWithEpisodes>>
@Query("SELECT * FROM podcast")
fun loadAllPodcastsWithEpisodes(): List<PodcastWithEpisodes>
@Query("SELECT * from podcast where link=:link")
fun loadPodcastWithEpisodes(link:String): PodcastWithEpisodes
@Query("SELECT * from podcast where link=:link")
fun findPodcastWithEpisodes(link:String): PodcastWithEpisodes?
}
\ No newline at end of file
......@@ -15,18 +15,18 @@ data class EpisodeEntity(
@ColumnInfo(name = "podcast_id", index = true)
var podcastId: String,
@ColumnInfo(name = "created_at")
var createdAt: Date?,
var createdAt: Date? = null,
@ColumnInfo(name = "title")
var title: String?,
var title: String? = null,
@ColumnInfo(name = "description")
var description: String?,
var description: String? = null,
@ColumnInfo(name = "image")
var image: String?,
var image: String? = null,
@ColumnInfo(name = "is_audio")
var isAudio: Boolean,
var isAudio: Boolean = true,
@ColumnInfo(name = "progress")
var progress: Float,
var progress: Float = 0f,
@ColumnInfo(name = "is_read")
var isRead: Boolean
var isRead: Boolean = false
)
\ No newline at end of file
......@@ -11,7 +11,7 @@ import com.rometools.rome.io.XmlReader
import org.videolan.podcast.BuildConfig
import org.videolan.podcast.PodcastApp
import org.videolan.podcast.core.room.entities.EpisodeEntity
import org.videolan.podcast.core.room.entities.PodcastEntity
import org.videolan.podcast.core.room.entities.PodcastWithEpisodes
import org.videolan.podcast.storage.Util
import org.videolan.vlc.extensions.api.VLCExtensionItem
import java.io.InputStream
......@@ -23,7 +23,7 @@ object UpdateManager {
fun updateAll(context: Context) {
val podcasts = PodcastApp.database.podcastDao().listAll()
val podcasts = PodcastApp.database.podcastsWithEpisodeDao().loadAllPodcastsWithEpisodes()
for (podcast in podcasts) {
updatePodcast(context, podcast)
}
......@@ -31,12 +31,12 @@ object UpdateManager {
}
fun updatePodcast(context: Context, podcast: PodcastEntity) {
fun updatePodcast(context: Context, podcast: PodcastWithEpisodes) {
var inputStream: InputStream? = null
try {
inputStream = URL(podcast.link).openConnection().getInputStream()
inputStream = URL(podcast.podcast.link).openConnection().getInputStream()
val input = SyndFeedInput()
val feed = input.build(XmlReader(inputStream))
......@@ -71,11 +71,11 @@ object UpdateManager {
}
}
podcast.image = image
podcast.author = author
podcast.title = feed.title
podcast.description = feed.description
PodcastApp.database.podcastDao().insert(podcast)
podcast.podcast.image = image
podcast.podcast.author = author
podcast.podcast.title = feed.title
podcast.podcast.description = feed.description
PodcastApp.database.podcastDao().insert(podcast.podcast)
......@@ -114,18 +114,28 @@ object UpdateManager {
}
}
if (image == null && podcast.image != null) {
image = podcast.image
if (image == null && podcast.podcast.image != null) {
image = podcast.podcast.image
}
val episodeEntity = EpisodeEntity(link, podcast.link, item.publishedDate
?: Date(), item.title, item.description.value, image, type == VLCExtensionItem.TYPE_AUDIO, 0F, false)
PodcastApp.database.episodeDao().insert(episodeEntity)
val episodeEntity = podcast.episodes.filter { it.link == link }.singleOrNull() ?: EpisodeEntity(link, podcast.podcast.link)
episodeEntity.createdAt = item.publishedDate
episodeEntity.title = item.title
episodeEntity.description = item.description.value
episodeEntity.image = image
episodeEntity.isAudio = type == VLCExtensionItem.TYPE_AUDIO
PodcastApp.database.episodeDao().insertOrUpdate(episodeEntity)
}
podcast.updatedAt = Date()
PodcastApp.database.podcastDao().update(podcast)
podcast.podcast.updatedAt = Date()
PodcastApp.database.podcastDao().update(podcast.podcast)
} catch (e: Exception) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment