mirror of
https://github.com/NiciDieNase/chaosflix
synced 2025-02-17 05:28:24 +00:00
WIP
This commit is contained in:
parent
8a0795081a
commit
63de712349
5 changed files with 30 additions and 30 deletions
|
@ -9,6 +9,7 @@ import android.content.Context
|
|||
import android.content.Intent
|
||||
import android.preference.PreferenceManager
|
||||
import android.util.Log
|
||||
import android.widget.Toast
|
||||
import androidx.core.app.NotificationCompat
|
||||
import de.nicidienase.chaosflix.common.ChaosflixPreferenceManager
|
||||
import de.nicidienase.chaosflix.common.mediadata.entities.recording.persistence.Event
|
||||
|
@ -30,17 +31,14 @@ class ChaosRecommendationsService : IntentService("ChaosRecommendationService")
|
|||
|
||||
val mediaRepository = ViewModelFactory.getInstance(this).mediaRepository
|
||||
val preferenceManager = ChaosflixPreferenceManager(PreferenceManager.getDefaultSharedPreferences(applicationContext))
|
||||
|
||||
if(preferenceManager.recommendationsGenerated){
|
||||
Log.d(TAG, "already generated, returning")
|
||||
return
|
||||
}
|
||||
|
||||
// if(preferenceManager.recommendationsGenerated){
|
||||
// Log.d(TAG, "already generated, returning")
|
||||
// Toast.makeText(this, "already generated, returning", Toast.LENGTH_SHORT).show()
|
||||
// return
|
||||
// }
|
||||
ioScope.launch {
|
||||
val recommendations = mediaRepository.getRecommendations()
|
||||
|
||||
var count = 0
|
||||
|
||||
try {
|
||||
val builder = RecommendationBuilder()
|
||||
.setContext(applicationContext)
|
||||
|
@ -67,7 +65,8 @@ class ChaosRecommendationsService : IntentService("ChaosRecommendationService")
|
|||
} catch (e: IOException) {
|
||||
Log.e(TAG, "Unable to update recommendation", e)
|
||||
}
|
||||
preferenceManager.recommendationsGenerated = true
|
||||
Toast.makeText(this@ChaosRecommendationsService, "done generating recommendations", Toast.LENGTH_SHORT).show()
|
||||
preferenceManager.recommendationsGenerated = false
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -78,20 +77,16 @@ class ChaosRecommendationsService : IntentService("ChaosRecommendationService")
|
|||
val builder = TaskStackBuilder.create(this)
|
||||
.addParentStack(ConferencesActivity::class.java)
|
||||
.addNextIntent(detailsIntent)
|
||||
|
||||
detailsIntent.setAction(event.guid)
|
||||
|
||||
detailsIntent.action = event.guid
|
||||
return builder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val TAG = ChaosRecommendationsService::class.java.simpleName
|
||||
|
||||
private const val MAX_RECOMMENDATIONS = 5
|
||||
}
|
||||
|
||||
class RecommendationBuilder {
|
||||
|
||||
private var id: Int = 0
|
||||
private var icon: Int = 0
|
||||
private lateinit var intent: PendingIntent
|
||||
|
@ -132,6 +127,16 @@ class ChaosRecommendationsService : IntentService("ChaosRecommendationService")
|
|||
return this
|
||||
}
|
||||
|
||||
fun setSmallIcon(icon: Int): RecommendationBuilder {
|
||||
this.icon = icon
|
||||
return this
|
||||
}
|
||||
|
||||
fun setId(id: Int): RecommendationBuilder {
|
||||
this.id = id
|
||||
return this
|
||||
}
|
||||
|
||||
@Throws(IOException::class)
|
||||
fun build(): Notification {
|
||||
return NotificationCompat.BigPictureStyle(
|
||||
|
@ -147,16 +152,5 @@ class ChaosRecommendationsService : IntentService("ChaosRecommendationService")
|
|||
.setContentIntent(intent)
|
||||
).build()
|
||||
}
|
||||
|
||||
fun setSmallIcon(icon: Int): RecommendationBuilder {
|
||||
this.icon = icon
|
||||
return this
|
||||
}
|
||||
|
||||
fun setId(id: Int): RecommendationBuilder {
|
||||
this.id = id
|
||||
return this
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -1,6 +1,8 @@
|
|||
package de.nicidienase.chaosflix.leanback
|
||||
|
||||
import android.content.Intent
|
||||
import android.util.Log
|
||||
import android.widget.Toast
|
||||
import androidx.core.app.ActivityOptionsCompat
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.leanback.widget.ImageCardView
|
||||
|
@ -57,6 +59,10 @@ class ItemViewClickedListener(private val fragment: Fragment, private val stream
|
|||
SelectableContentItem.UpdateStreams -> {
|
||||
streamUpdater?.invoke()
|
||||
}
|
||||
SelectableContentItem.AddRecommendations -> {
|
||||
activity.startService(Intent(activity, ChaosRecommendationsService::class.java))
|
||||
Toast.makeText(activity, "creating Recommendations", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,5 +6,6 @@ enum class SelectableContentItem(val title: String, @DrawableRes val icon: Int,
|
|||
Settings("Settings", R.drawable.ic_settings),
|
||||
About("About", R.drawable.ic_info),
|
||||
LeakCanary("Leak Canary", R.drawable.ic_warning),
|
||||
AddRecommendations("Recommendations", R.drawable.ic_refresh),
|
||||
UpdateStreams("Update Streams", R.drawable.ic_refresh)
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package de.nicidienase.chaosflix.leanback.conferences
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
|
@ -9,7 +8,6 @@ import de.nicidienase.chaosflix.common.ChaosflixPreferenceManager
|
|||
import de.nicidienase.chaosflix.common.viewmodel.BrowseViewModel
|
||||
import de.nicidienase.chaosflix.common.viewmodel.ViewModelFactory
|
||||
import de.nicidienase.chaosflix.leanback.ChannelManager
|
||||
import de.nicidienase.chaosflix.leanback.ChaosRecommendationsService
|
||||
import de.nicidienase.chaosflix.leanback.R
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
|
@ -32,12 +30,12 @@ class ConferencesActivity : androidx.fragment.app.FragmentActivity() {
|
|||
ChannelManager.setupChannels(this@ConferencesActivity, viewmodel, prefs)
|
||||
}
|
||||
} else {
|
||||
setupRecommendationsRow()
|
||||
setupRecommendations()
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupRecommendationsRow() {
|
||||
startService(Intent(this, ChaosRecommendationsService::class.java))
|
||||
private fun setupRecommendations() {
|
||||
// startService(Intent(this, ChaosRecommendationsService::class.java))
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -95,6 +95,7 @@ class ConferencesBrowseFragment : BrowseSupportFragment() {
|
|||
listRowAdapter.add(SelectableContentItem.Settings)
|
||||
// listRowAdapter.add(SelectableContentItem.About)
|
||||
if (BuildConfig.DEBUG) {
|
||||
listRowAdapter.add(SelectableContentItem.AddRecommendations)
|
||||
listRowAdapter.add(SelectableContentItem.LeakCanary)
|
||||
}
|
||||
settingsRow = ListRow(HeaderItem("Chaosflix"), listRowAdapter)
|
||||
|
|
Loading…
Add table
Reference in a new issue