formatting

This commit is contained in:
Felix 2020-04-12 19:30:15 +02:00
parent 4c49e8f8a8
commit 2077e1ed54
12 changed files with 42 additions and 47 deletions

View file

@ -21,20 +21,20 @@ class ChaosflixPreferenceManager(private val sharedPref: SharedPreferences) {
var recommendationsGenerated: Boolean by BooleanPreferencesDelegate(RECOMMENDATIONS_GENERATED, false) var recommendationsGenerated: Boolean by BooleanPreferencesDelegate(RECOMMENDATIONS_GENERATED, false)
private inner class BooleanPreferencesDelegate(key: String, default: Boolean) : private inner class BooleanPreferencesDelegate(key: String, default: Boolean) :
PreferencesDelegate<Boolean>(key,default, SharedPreferences::getBoolean, SharedPreferences.Editor::putBoolean) PreferencesDelegate<Boolean>(key, default, SharedPreferences::getBoolean, SharedPreferences.Editor::putBoolean)
private inner class StringPreferenceDelegate(key: String, default: String): private inner class StringPreferenceDelegate(key: String, default: String) :
PreferencesDelegate<String>(key,default, SharedPreferences::getString, SharedPreferences.Editor::putString) PreferencesDelegate<String>(key, default, SharedPreferences::getString, SharedPreferences.Editor::putString)
private inner class LongPreferenceDelegate(key: String, default: Long): private inner class LongPreferenceDelegate(key: String, default: Long) :
PreferencesDelegate<Long>(key,default, SharedPreferences::getLong, SharedPreferences.Editor::putLong) PreferencesDelegate<Long>(key, default, SharedPreferences::getLong, SharedPreferences.Editor::putLong)
abstract inner class PreferencesDelegate<T>( abstract inner class PreferencesDelegate<T>(
private val key: String, private val key: String,
private val default: T, private val default: T,
private val getter: SharedPreferences.(String, T) -> T?, private val getter: SharedPreferences.(String, T) -> T?,
private val setter: SharedPreferences.Editor.(String, T) -> SharedPreferences.Editor private val setter: SharedPreferences.Editor.(String, T) -> SharedPreferences.Editor
) : ReadWriteProperty<ChaosflixPreferenceManager, T> { ) : ReadWriteProperty<ChaosflixPreferenceManager, T> {
override fun getValue(thisRef: ChaosflixPreferenceManager, property: KProperty<*>): T { override fun getValue(thisRef: ChaosflixPreferenceManager, property: KProperty<*>): T {
return sharedPref.getter(key, default) ?: default return sharedPref.getter(key, default) ?: default

View file

@ -22,13 +22,13 @@ import de.nicidienase.chaosflix.common.userdata.entities.download.OfflineEvent
import de.nicidienase.chaosflix.common.userdata.entities.download.OfflineEventDao import de.nicidienase.chaosflix.common.userdata.entities.download.OfflineEventDao
import de.nicidienase.chaosflix.common.util.LiveEvent import de.nicidienase.chaosflix.common.util.LiveEvent
import de.nicidienase.chaosflix.common.viewmodel.DetailsViewModel import de.nicidienase.chaosflix.common.viewmodel.DetailsViewModel
import java.io.File
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.SupervisorJob import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import java.io.File
class OfflineItemManager( class OfflineItemManager(
context: Context, context: Context,
@ -198,7 +198,7 @@ class OfflineItemManager(
private fun getMovieDir(): String { private fun getMovieDir(): String {
val dir = preferencesManager.downloadFolder val dir = preferencesManager.downloadFolder
return if(dir.isNullOrBlank()){ return if (dir.isNullOrBlank()) {
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES).path Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES).path
} else { } else {
dir dir

View file

@ -22,13 +22,13 @@ import de.nicidienase.chaosflix.common.userdata.entities.watchlist.WatchlistItem
import de.nicidienase.chaosflix.common.util.ConferenceUtil import de.nicidienase.chaosflix.common.util.ConferenceUtil
import de.nicidienase.chaosflix.common.util.LiveEvent import de.nicidienase.chaosflix.common.util.LiveEvent
import de.nicidienase.chaosflix.common.util.SingleLiveEvent import de.nicidienase.chaosflix.common.util.SingleLiveEvent
import java.io.IOException
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import retrofit2.Response import retrofit2.Response
import java.io.IOException
class MediaRepository( class MediaRepository(
private val recordingApi: RecordingService, private val recordingApi: RecordingService,

View file

@ -5,14 +5,14 @@ import android.util.Log
import com.google.gson.Gson import com.google.gson.Gson
import de.nicidienase.chaosflix.BuildConfig import de.nicidienase.chaosflix.BuildConfig
import de.nicidienase.chaosflix.common.SingletonHolder2 import de.nicidienase.chaosflix.common.SingletonHolder2
import java.io.File
import java.net.SocketTimeoutException
import java.util.concurrent.TimeUnit
import okhttp3.Cache import okhttp3.Cache
import okhttp3.Interceptor import okhttp3.Interceptor
import okhttp3.OkHttpClient import okhttp3.OkHttpClient
import retrofit2.Retrofit import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory import retrofit2.converter.gson.GsonConverterFactory
import java.io.File
import java.net.SocketTimeoutException
import java.util.concurrent.TimeUnit
class ApiFactory private constructor(apiUrl: String, cache: File? = null) { class ApiFactory private constructor(apiUrl: String, cache: File? = null) {

View file

@ -9,8 +9,8 @@ import androidx.paging.LivePagedListBuilder
import androidx.paging.PagedList import androidx.paging.PagedList
import de.nicidienase.chaosflix.R import de.nicidienase.chaosflix.R
import de.nicidienase.chaosflix.common.ChaosflixDatabase import de.nicidienase.chaosflix.common.ChaosflixDatabase
import de.nicidienase.chaosflix.common.OfflineItemManager
import de.nicidienase.chaosflix.common.ChaosflixPreferenceManager import de.nicidienase.chaosflix.common.ChaosflixPreferenceManager
import de.nicidienase.chaosflix.common.OfflineItemManager
import de.nicidienase.chaosflix.common.ResourcesFacade import de.nicidienase.chaosflix.common.ResourcesFacade
import de.nicidienase.chaosflix.common.mediadata.MediaRepository import de.nicidienase.chaosflix.common.mediadata.MediaRepository
import de.nicidienase.chaosflix.common.mediadata.SearchResultDataSourceFactory import de.nicidienase.chaosflix.common.mediadata.SearchResultDataSourceFactory
@ -26,12 +26,12 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
class BrowseViewModel( class BrowseViewModel(
val offlineItemManager: OfflineItemManager, val offlineItemManager: OfflineItemManager,
private val mediaRepository: MediaRepository, private val mediaRepository: MediaRepository,
private val database: ChaosflixDatabase, private val database: ChaosflixDatabase,
private val streamingRepository: StreamingRepository, private val streamingRepository: StreamingRepository,
private val preferencesManager: ChaosflixPreferenceManager, private val preferencesManager: ChaosflixPreferenceManager,
private val resources: ResourcesFacade private val resources: ResourcesFacade
) : ViewModel() { ) : ViewModel() {
val state: SingleLiveEvent<LiveEvent<State, Event, String>> = SingleLiveEvent() val state: SingleLiveEvent<LiveEvent<State, Event, String>> = SingleLiveEvent()

View file

@ -8,25 +8,25 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.liveData import androidx.lifecycle.liveData
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
import de.nicidienase.chaosflix.common.ChaosflixDatabase import de.nicidienase.chaosflix.common.ChaosflixDatabase
import de.nicidienase.chaosflix.common.ChaosflixPreferenceManager
import de.nicidienase.chaosflix.common.ChaosflixUtil import de.nicidienase.chaosflix.common.ChaosflixUtil
import de.nicidienase.chaosflix.common.OfflineItemManager import de.nicidienase.chaosflix.common.OfflineItemManager
import de.nicidienase.chaosflix.common.ChaosflixPreferenceManager
import de.nicidienase.chaosflix.common.mediadata.MediaRepository import de.nicidienase.chaosflix.common.mediadata.MediaRepository
import de.nicidienase.chaosflix.common.mediadata.entities.recording.persistence.Event import de.nicidienase.chaosflix.common.mediadata.entities.recording.persistence.Event
import de.nicidienase.chaosflix.common.mediadata.entities.recording.persistence.Recording import de.nicidienase.chaosflix.common.mediadata.entities.recording.persistence.Recording
import de.nicidienase.chaosflix.common.userdata.entities.watchlist.WatchlistItem import de.nicidienase.chaosflix.common.userdata.entities.watchlist.WatchlistItem
import de.nicidienase.chaosflix.common.util.LiveEvent import de.nicidienase.chaosflix.common.util.LiveEvent
import de.nicidienase.chaosflix.common.util.SingleLiveEvent import de.nicidienase.chaosflix.common.util.SingleLiveEvent
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import java.io.File import java.io.File
import java.util.ArrayList import java.util.ArrayList
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
class DetailsViewModel( class DetailsViewModel(
private val database: ChaosflixDatabase, private val database: ChaosflixDatabase,
private val offlineItemManager: OfflineItemManager, private val offlineItemManager: OfflineItemManager,
private val preferencesManager: ChaosflixPreferenceManager, private val preferencesManager: ChaosflixPreferenceManager,
private val mediaRepository: MediaRepository private val mediaRepository: MediaRepository
) : ViewModel() { ) : ViewModel() {
private var eventId: Long = 0 private var eventId: Long = 0

View file

@ -7,8 +7,8 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.ViewModelProvider
import de.nicidienase.chaosflix.R import de.nicidienase.chaosflix.R
import de.nicidienase.chaosflix.common.ChaosflixDatabase import de.nicidienase.chaosflix.common.ChaosflixDatabase
import de.nicidienase.chaosflix.common.OfflineItemManager
import de.nicidienase.chaosflix.common.ChaosflixPreferenceManager import de.nicidienase.chaosflix.common.ChaosflixPreferenceManager
import de.nicidienase.chaosflix.common.OfflineItemManager
import de.nicidienase.chaosflix.common.ResourcesFacade import de.nicidienase.chaosflix.common.ResourcesFacade
import de.nicidienase.chaosflix.common.SingletonHolder import de.nicidienase.chaosflix.common.SingletonHolder
import de.nicidienase.chaosflix.common.mediadata.MediaRepository import de.nicidienase.chaosflix.common.mediadata.MediaRepository

View file

@ -18,7 +18,6 @@ object ChannelManager {
enum class Channels { enum class Channels {
PROMOTED, PROMOTED,
} }
suspend fun setupChannels(context: Context, viewmodel: BrowseViewModel, prefs: ChaosflixPreferenceManager) { suspend fun setupChannels(context: Context, viewmodel: BrowseViewModel, prefs: ChaosflixPreferenceManager) {
@ -59,9 +58,9 @@ object ChannelManager {
val programUri = context.contentResolver.insert(TvContractCompat.PreviewPrograms.CONTENT_URI, toContentValues) val programUri = context.contentResolver.insert(TvContractCompat.PreviewPrograms.CONTENT_URI, toContentValues)
ContentUris.parseId(programUri) ContentUris.parseId(programUri)
} }
Log.d(TAG,"Added $programmIds") Log.d(TAG, "Added $programmIds")
} }
} }
private val TAG = ChannelManager::class.java.simpleName private val TAG = ChannelManager::class.java.simpleName
} }

View file

@ -51,21 +51,21 @@ class ChaosRecommendationsService : IntentService("ChaosRecommendationService")
.asBitmap() .asBitmap()
.load(event.thumbUrl) .load(event.thumbUrl)
.submit(cardWidth, cardHeight) // Only use for synchronous .get() .submit(cardWidth, cardHeight) // Only use for synchronous .get()
.get(); .get()
val id = event.id.toInt() val id = event.id.toInt()
val contentRecommendation = builder.setIdTag("Event-$id") val contentRecommendation = builder.setIdTag("Event-$id")
.setTitle(event.title) .setTitle(event.title)
.setText(event.subtitle) .setText(event.subtitle)
.setContentImage(bitmap) .setContentImage(bitmap)
.setContentIntentData(ContentRecommendation.INTENT_TYPE_ACTIVITY,buildPendingIntent(event),0,null) .setContentIntentData(ContentRecommendation.INTENT_TYPE_ACTIVITY, buildPendingIntent(event), 0, null)
.build() .build()
val notification = contentRecommendation.getNotificationObject(applicationContext) val notification = contentRecommendation.getNotificationObject(applicationContext)
notificationManager?.notify(id, notification) notificationManager?.notify(id, notification)
Log.d(TAG, "Added notification for ${event.title}") Log.d(TAG, "Added notification for ${event.title}")
if(++ count >= MAX_RECOMMENDATIONS){ if (++ count >= MAX_RECOMMENDATIONS) {
break break
} }
} }
@ -93,5 +93,4 @@ class ChaosRecommendationsService : IntentService("ChaosRecommendationService")
private val TAG = ChaosRecommendationsService::class.java.simpleName private val TAG = ChaosRecommendationsService::class.java.simpleName
private const val MAX_RECOMMENDATIONS = 6 private const val MAX_RECOMMENDATIONS = 6
} }
}
}

View file

@ -24,8 +24,8 @@ class ConferencesActivity : androidx.fragment.app.FragmentActivity() {
val prefs = ChaosflixPreferenceManager(PreferenceManager.getDefaultSharedPreferences(applicationContext)) val prefs = ChaosflixPreferenceManager(PreferenceManager.getDefaultSharedPreferences(applicationContext))
val viewmodel = ViewModelProvider( val viewmodel = ViewModelProvider(
this,ViewModelFactory.getInstance(this)).get(BrowseViewModel::class.java) this, ViewModelFactory.getInstance(this)).get(BrowseViewModel::class.java)
if(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
lifecycleScope.launch { lifecycleScope.launch {
ChannelManager.setupChannels(this@ConferencesActivity, viewmodel, prefs) ChannelManager.setupChannels(this@ConferencesActivity, viewmodel, prefs)
} }
@ -38,7 +38,6 @@ class ConferencesActivity : androidx.fragment.app.FragmentActivity() {
// startService(Intent(this, ChaosRecommendationsService::class.java)) // startService(Intent(this, ChaosRecommendationsService::class.java))
} }
companion object { companion object {
private val TAG = ConferencesActivity::class.java.simpleName private val TAG = ConferencesActivity::class.java.simpleName
} }

View file

@ -23,7 +23,7 @@ class DetailsActivity : androidx.fragment.app.FragmentActivity() {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(R.layout.activity_event_details) setContentView(R.layout.activity_event_details)
lifecycleScope.launch { lifecycleScope.launch {
val fragment = if(intent.action == Intent.ACTION_VIEW) { val fragment = if (intent.action == Intent.ACTION_VIEW) {
val guid = intent.data.lastPathSegment val guid = intent.data.lastPathSegment
EventDetailsFragment().apply { EventDetailsFragment().apply {
arguments = bundleOf(EventDetailsFragment.ARG_EVENT_GUID to guid) arguments = bundleOf(EventDetailsFragment.ARG_EVENT_GUID to guid)

View file

@ -98,7 +98,6 @@ class EventDetailsFragment : DetailsSupportFragment() {
detailsViewModel = ViewModelProvider(this, viewModelFactory).get(DetailsViewModel::class.java) detailsViewModel = ViewModelProvider(this, viewModelFactory).get(DetailsViewModel::class.java)
playerViewModel = ViewModelProvider(this, viewModelFactory).get(PlayerViewModel::class.java) playerViewModel = ViewModelProvider(this, viewModelFactory).get(PlayerViewModel::class.java)
val detailsPresenter = FullWidthDetailsOverviewRowPresenter( val detailsPresenter = FullWidthDetailsOverviewRowPresenter(
EventDetailsDescriptionPresenter(requireContext())) EventDetailsDescriptionPresenter(requireContext()))
@ -122,7 +121,7 @@ class EventDetailsFragment : DetailsSupportFragment() {
playerViewModel.setEvent(guid) playerViewModel.setEvent(guid)
val eventLiveData = detailsViewModel.setEventByGuid(guid) val eventLiveData = detailsViewModel.setEventByGuid(guid)
eventLiveData.observe(viewLifecycleOwner, Observer { event -> eventLiveData.observe(viewLifecycleOwner, Observer { event ->
if(event != null){ if (event != null) {
title = event.title title = event.title
initializeBackgroundWithImage(event.posterUrl) initializeBackgroundWithImage(event.posterUrl)
@ -139,7 +138,6 @@ class EventDetailsFragment : DetailsSupportFragment() {
onItemViewClickedListener = ItemViewClickedListener(this@EventDetailsFragment) onItemViewClickedListener = ItemViewClickedListener(this@EventDetailsFragment)
startEntranceTransition() startEntranceTransition()
setupObserver(detailsViewModel) setupObserver(detailsViewModel)
} }
@ -169,7 +167,7 @@ class EventDetailsFragment : DetailsSupportFragment() {
detailsOverview.actionsAdapter = actionAdapter detailsOverview.actionsAdapter = actionAdapter
event.thumbUrl.let { setThumb(it, detailsOverview) } event.thumbUrl.let { setThumb(it, detailsOverview) }
liveData.observe(viewLifecycleOwner, Observer { liveData.observe(viewLifecycleOwner, Observer {
if(it != null){ if (it != null) {
detailsOverview.item = it detailsOverview.item = it
} }
}) })