add clean Cache

This commit is contained in:
Felix Bürkle 2018-11-24 21:28:39 +01:00
parent a6fa29d7a1
commit 616ca6ea50
12 changed files with 90 additions and 24 deletions

View file

@ -23,6 +23,9 @@ abstract class ConferenceDao : BaseDao<PersistentConference>() {
@Query("SELECT * FROM conference WHERE conferenceGroupId = :id ORDER BY acronym DESC") @Query("SELECT * FROM conference WHERE conferenceGroupId = :id ORDER BY acronym DESC")
abstract fun findConferenceByGroup(id: Long): LiveData<List<PersistentConference>> abstract fun findConferenceByGroup(id: Long): LiveData<List<PersistentConference>>
@Query("DELETE FROM conference")
abstract fun delete()
override fun updateOrInsertInternal(item: PersistentConference) { override fun updateOrInsertInternal(item: PersistentConference) {
if (item.id != 0L) { if (item.id != 0L) {
update(item) update(item)

View file

@ -15,6 +15,9 @@ abstract class ConferenceGroupDao : BaseDao<ConferenceGroup>() {
@Query("DELETE FROM conference_group WHERE id NOT IN (SELECT conference.conferenceGroupId FROM conference)") @Query("DELETE FROM conference_group WHERE id NOT IN (SELECT conference.conferenceGroupId FROM conference)")
abstract fun deleteEmptyGroups() abstract fun deleteEmptyGroups()
@Query("DElETE FROM conference_group")
abstract fun delete()
override fun updateOrInsertInternal(item: ConferenceGroup) { override fun updateOrInsertInternal(item: ConferenceGroup) {
if (item.id != 0L) { if (item.id != 0L) {
update(item) update(item)

View file

@ -48,6 +48,9 @@ abstract class EventDao: BaseDao<PersistentEvent>() {
@Query("SELECT * FROM event WHERE frontendLink = :url ") @Query("SELECT * FROM event WHERE frontendLink = :url ")
abstract fun findEventsByFrontendurl(url: String):LiveData<PersistentEvent?> abstract fun findEventsByFrontendurl(url: String):LiveData<PersistentEvent?>
@Query("DElETE FROM event")
abstract fun delete()
override fun updateOrInsertInternal(item: PersistentEvent) { override fun updateOrInsertInternal(item: PersistentEvent) {
if (item.id != 0L) { if (item.id != 0L) {
update(item) update(item)

View file

@ -25,6 +25,9 @@ abstract class RecordingDao: BaseDao<PersistentRecording>() {
@Query("DELETE FROM recording WHERE eventId = :eventId") @Query("DELETE FROM recording WHERE eventId = :eventId")
abstract fun deleteRecordingsForEvent(eventId: Long) abstract fun deleteRecordingsForEvent(eventId: Long)
@Query("DElETE FROM recording")
abstract fun delete()
override fun updateOrInsertInternal(item: PersistentRecording) { override fun updateOrInsertInternal(item: PersistentRecording) {
if (item.id != 0L) { if (item.id != 0L) {
update(item) update(item)

View file

@ -15,6 +15,9 @@ abstract class RelatedEventDao : BaseDao<PersistentRelatedEvent>() {
@Query("SELECT * FROM related WHERE parentEventId = :parentId AND relatedEventGuid = :related") @Query("SELECT * FROM related WHERE parentEventId = :parentId AND relatedEventGuid = :related")
abstract fun findSpecificRelatedEventSync(parentId: Long, related: String): PersistentRelatedEvent? abstract fun findSpecificRelatedEventSync(parentId: Long, related: String): PersistentRelatedEvent?
@Query("DElETE FROM related")
abstract fun delete()
override fun updateOrInsertInternal(item: PersistentRelatedEvent) { override fun updateOrInsertInternal(item: PersistentRelatedEvent) {
if (item.id != 0L) { if (item.id != 0L) {
update(item) update(item)

View file

@ -133,6 +133,17 @@ class Downloader(private val recordingApi: RecordingService,
} }
} }
fun deleteNonUserData(){
with(database){
conferenceGroupDao().delete()
conferenceDao().delete()
eventDao().delete()
recordingDao().delete()
relatedEventDao().delete()
}
}
private fun saveConferences(conferencesWrapper: ConferencesWrapper): List<PersistentConference> { private fun saveConferences(conferencesWrapper: ConferencesWrapper): List<PersistentConference> {
return conferencesWrapper.conferencesMap.map { entry -> return conferencesWrapper.conferencesMap.map { entry ->
val conferenceGroup: ConferenceGroup = getOrCreateConferenceGroup(entry.key) val conferenceGroup: ConferenceGroup = getOrCreateConferenceGroup(entry.key)

View file

@ -21,13 +21,13 @@ class DetailsViewModel(
val database: ChaosflixDatabase, val database: ChaosflixDatabase,
recordingApi: RecordingService, recordingApi: RecordingService,
val offlineItemManager: OfflineItemManager, val offlineItemManager: OfflineItemManager,
val preferencesManager: PreferencesManager val preferencesManager: PreferencesManager,
val downloader: Downloader
) : ViewModel() { ) : ViewModel() {
val state: SingleLiveEvent<LiveEvent<DetailsViewModelState,Bundle,String>> val state: SingleLiveEvent<LiveEvent<DetailsViewModelState,Bundle,String>>
= SingleLiveEvent() = SingleLiveEvent()
val downloader = Downloader(recordingApi, database)
var writeExternalStorageAllowed: Boolean = false var writeExternalStorageAllowed: Boolean = false
private val handler = ThreadHandler() private val handler = ThreadHandler()

View file

@ -0,0 +1,13 @@
package de.nicidienase.chaosflix.common.viewmodel
import android.arch.lifecycle.ViewModel
import de.nicidienase.chaosflix.common.mediadata.sync.Downloader
import de.nicidienase.chaosflix.common.util.ThreadHandler
class PreferencesViewModel(val downloader: Downloader) : ViewModel() {
fun cleanNonUserData() {
ThreadHandler().runOnBackgroundThread {
downloader.deleteNonUserData()
}
}
}

View file

@ -8,6 +8,7 @@ import de.nicidienase.chaosflix.common.DatabaseFactory
import de.nicidienase.chaosflix.common.OfflineItemManager import de.nicidienase.chaosflix.common.OfflineItemManager
import de.nicidienase.chaosflix.common.PreferencesManager import de.nicidienase.chaosflix.common.PreferencesManager
import de.nicidienase.chaosflix.common.mediadata.network.ApiFactory import de.nicidienase.chaosflix.common.mediadata.network.ApiFactory
import de.nicidienase.chaosflix.common.mediadata.sync.Downloader
class ViewModelFactory(context: Context) : ViewModelProvider.Factory { class ViewModelFactory(context: Context) : ViewModelProvider.Factory {
@ -20,18 +21,18 @@ class ViewModelFactory(context: Context) : ViewModelProvider.Factory {
PreferencesManager(PreferenceManager.getDefaultSharedPreferences(context.applicationContext)) PreferencesManager(PreferenceManager.getDefaultSharedPreferences(context.applicationContext))
val offlineItemManager = val offlineItemManager =
OfflineItemManager(context.applicationContext, database.offlineEventDao(),preferencesManager) OfflineItemManager(context.applicationContext, database.offlineEventDao(),preferencesManager)
val downloader by lazy { Downloader(recordingApi, database) }
@Suppress("UNCHECKED_CAST") @Suppress("UNCHECKED_CAST")
override fun <T : ViewModel?> create(modelClass: Class<T>): T { override fun <T : ViewModel?> create(modelClass: Class<T>): T {
if (modelClass.isAssignableFrom(BrowseViewModel::class.java)) { if (modelClass.isAssignableFrom(BrowseViewModel::class.java)) {
return BrowseViewModel(offlineItemManager, database, recordingApi, streamingApi, preferencesManager) as T return BrowseViewModel(offlineItemManager, database, recordingApi, streamingApi, preferencesManager) as T
} else if (modelClass.isAssignableFrom(PlayerViewModel::class.java)) { } else if (modelClass.isAssignableFrom(PlayerViewModel::class.java)) {
return PlayerViewModel(database) as T return PlayerViewModel(database) as T
} else if (modelClass.isAssignableFrom(DetailsViewModel::class.java)) { } else if (modelClass.isAssignableFrom(DetailsViewModel::class.java)) {
return DetailsViewModel(database, recordingApi, offlineItemManager, preferencesManager) as T return DetailsViewModel(database, recordingApi, offlineItemManager, preferencesManager, downloader) as T
} else if (modelClass.isAssignableFrom(PreferencesViewModel::class.java)){
return PreferencesViewModel(downloader) as T
} else { } else {
throw UnsupportedOperationException("The requested ViewModel is currently unsupported. " + throw UnsupportedOperationException("The requested ViewModel is currently unsupported. " +
"Please make sure to implement are correct creation of it. " + "Please make sure to implement are correct creation of it. " +

View file

@ -37,4 +37,9 @@
<string name="watchlist_preferences_key">watchlist</string> <string name="watchlist_preferences_key">watchlist</string>
<string name="watchlist_dialog_needed">new-watchlist</string> <string name="watchlist_dialog_needed">new-watchlist</string>
<string name="return_to_homescreen">Return to Homescreen</string> <string name="return_to_homescreen">Return to Homescreen</string>
<string name="clean_cache">Clean Cache</string>
<string name="download_folder">Download folder</string>
<string name="pref_autoselect_recording">Don\'t show selection dialog, just use HD-mp4</string>
<string name="pref_autoselect_stream">Don\'t show selection dialog, just use DASH</string>
<string name="pref_mobile_downloads">Enable downloads over mobile or payed networks</string>
</resources> </resources>

View file

@ -5,24 +5,28 @@
android:key="allow_metered_networks" android:key="allow_metered_networks"
android:defaultValue="false" android:defaultValue="false"
android:title="Allow downloads over metered networks" android:title="Allow downloads over metered networks"
android:summary="Enable downloads over mobile or payed networks"/> android:summary="@string/pref_mobile_downloads"/>
<CheckBoxPreference <CheckBoxPreference
android:key="auto_select_stream" android:key="auto_select_stream"
android:defaultValue="false" android:defaultValue="false"
android:title="Automatically chose stream" android:title="Automatically chose stream"
android:summary="Don't show selection dialog, just use DASH"/> android:summary="@string/pref_autoselect_stream"/>
<CheckBoxPreference <CheckBoxPreference
android:key="auto_select_recording" android:key="auto_select_recording"
android:defaultValue="false" android:defaultValue="false"
android:title="Automatically chose recording" android:title="Automatically chose recording"
android:summary="Don't show selection dialog, just use HD-mp4"/> android:summary="@string/pref_autoselect_recording"/>
<Preference <Preference
android:id="@+id/download_folder" android:id="@+id/download_folder"
android:key="download_folder" android:key="download_folder"
android:title="Download folder" android:title="@string/download_folder"/>
android:focusable="false" />
<Preference
android:id="@+id/deleteData"
android:key="delete_data"
android:title="@string/clean_cache"/>
</PreferenceScreen> </PreferenceScreen>

View file

@ -1,11 +1,14 @@
package de.nicidienase.chaosflix.touch.settings package de.nicidienase.chaosflix.touch.settings
import android.arch.lifecycle.ViewModelProviders
import android.content.Context
import android.content.Intent import android.content.Intent
import android.os.Bundle import android.os.Bundle
import android.preference.PreferenceManager import android.preference.PreferenceManager
import android.support.v7.preference.PreferenceFragmentCompat import android.support.v7.preference.PreferenceFragmentCompat
import de.nicidienase.chaosflix.R import de.nicidienase.chaosflix.R
import de.nicidienase.chaosflix.touch.ChaosflixApplication import de.nicidienase.chaosflix.common.viewmodel.PreferencesViewModel
import de.nicidienase.chaosflix.common.viewmodel.ViewModelFactory
import net.rdrei.android.dirchooser.DirectoryChooserActivity import net.rdrei.android.dirchooser.DirectoryChooserActivity
import net.rdrei.android.dirchooser.DirectoryChooserConfig import net.rdrei.android.dirchooser.DirectoryChooserConfig
@ -13,6 +16,15 @@ import net.rdrei.android.dirchooser.DirectoryChooserConfig
class SettingsFragment : PreferenceFragmentCompat() { class SettingsFragment : PreferenceFragmentCompat() {
private val REQUEST_DIRECTORY: Int = 0 private val REQUEST_DIRECTORY: Int = 0
private lateinit var viewModel: PreferencesViewModel
override fun onAttach(context: Context?) {
super.onAttach(context)
context?.let {context ->
viewModel = ViewModelProviders.of(this, ViewModelFactory(context)).get(PreferencesViewModel::class.java)
}
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data) super.onActivityResult(requestCode, resultCode, data)
@ -38,9 +50,10 @@ class SettingsFragment : PreferenceFragmentCompat() {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
setPreferencesFromResource(R.xml.preferences,rootKey) setPreferencesFromResource(R.xml.preferences,rootKey)
updateSummary() updateSummary()
val pref = this.findPreference("download_folder") val downloadFolderPref = this.findPreference("download_folder")
val cleanCachePref = this.findPreference("delete_data")
pref.setOnPreferenceClickListener({ downloadFolderPref?.setOnPreferenceClickListener {
val chooserIntent = Intent(context, DirectoryChooserActivity::class.java) val chooserIntent = Intent(context, DirectoryChooserActivity::class.java)
val config = DirectoryChooserConfig.builder() val config = DirectoryChooserConfig.builder()
@ -53,8 +66,12 @@ class SettingsFragment : PreferenceFragmentCompat() {
startActivityForResult(chooserIntent, REQUEST_DIRECTORY) startActivityForResult(chooserIntent, REQUEST_DIRECTORY)
return@setOnPreferenceClickListener true return@setOnPreferenceClickListener true
}
}) cleanCachePref?.setOnPreferenceClickListener {
viewModel.cleanNonUserData()
return@setOnPreferenceClickListener true
}
} }
companion object { companion object {