Commit 11af8196 authored by Christophe Henry's avatar Christophe Henry

Solves #15: Implement Jetpack's NavigationUI and get rid of the router

Incidentaly solves #20 as expected
parent fcd87dcd
...@@ -3,6 +3,7 @@ apply plugin: "kotlin-android" ...@@ -3,6 +3,7 @@ apply plugin: "kotlin-android"
apply plugin: "kotlin-android-extensions" apply plugin: "kotlin-android-extensions"
apply plugin: "kotlinx-serialization" apply plugin: "kotlinx-serialization"
apply plugin: "kotlin-kapt" apply plugin: "kotlin-kapt"
apply plugin: "androidx.navigation.safeargs.kotlin"
android { android {
compileSdkVersion 28 compileSdkVersion 28
...@@ -24,8 +25,6 @@ android { ...@@ -24,8 +25,6 @@ android {
enabled = true enabled = true
} }
com.android.build.gradle.internal.api.ApplicationVariantImpl
applicationVariants.all { variant -> applicationVariants.all { variant ->
if (variant.name.contains("elease")) { if (variant.name.contains("elease")) {
variant.mergeAssetsProvider.get().doLast { variant.mergeAssetsProvider.get().doLast {
...@@ -33,6 +32,10 @@ android { ...@@ -33,6 +32,10 @@ android {
} }
} }
} }
androidExtensions {
experimental = true
}
} }
dependencies { dependencies {
...@@ -43,14 +46,14 @@ dependencies { ...@@ -43,14 +46,14 @@ dependencies {
def test_runnner_version = "1.1.1" def test_runnner_version = "1.1.1"
def promise_version = "3.3.0" def promise_version = "3.3.0"
def android_support_version = "28.0.0" def android_support_version = "28.0.0"
def android_navigation = "1.0.0-rc02"
implementation 'androidx.legacy:legacy-support-v4:1.0.0-beta01'
implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0-beta01'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.0.0'
configurations { configurations {
all*.exclude group: 'com.google.guava', module: 'listenablefuture' all*.exclude group: 'com.google.guava', module: 'listenablefuture'
} }
implementation "androidx.legacy:legacy-support-v4:1.0.0"
implementation fileTree(dir: "libs", include: ["*.jar"]) implementation fileTree(dir: "libs", include: ["*.jar"])
// Kotlin stuff // Kotlin stuff
...@@ -62,7 +65,7 @@ dependencies { ...@@ -62,7 +65,7 @@ dependencies {
implementation "com.android.support:preference-v7:$android_support_version" implementation "com.android.support:preference-v7:$android_support_version"
implementation "com.android.support:support-core-utils:$android_support_version" implementation "com.android.support:support-core-utils:$android_support_version"
implementation "com.android.support:support-fragment:$android_support_version" implementation "com.android.support:support-fragment:$android_support_version"
implementation "com.android.support:support-compat:28.0.0" implementation "com.android.support:support-compat:$android_support_version"
// AndroidX layout // AndroidX layout
implementation "androidx.appcompat:appcompat:1.0.0-beta01" implementation "androidx.appcompat:appcompat:1.0.0-beta01"
...@@ -72,9 +75,10 @@ dependencies { ...@@ -72,9 +75,10 @@ dependencies {
implementation "androidx.recyclerview:recyclerview:1.0.0" implementation "androidx.recyclerview:recyclerview:1.0.0"
// ViewModel and LiveData // ViewModel and LiveData
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.0.0'
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version" implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version"
annotationProcessor "androidx.lifecycle:lifecycle-compiler:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-reactivestreams-ktx:$lifecycle_version" implementation "androidx.lifecycle:lifecycle-reactivestreams-ktx:$lifecycle_version"
annotationProcessor "androidx.lifecycle:lifecycle-compiler:$lifecycle_version"
testImplementation "androidx.arch.core:core-testing:$lifecycle_version" testImplementation "androidx.arch.core:core-testing:$lifecycle_version"
// Room // Room
...@@ -92,8 +96,13 @@ dependencies { ...@@ -92,8 +96,13 @@ dependencies {
implementation "nl.komponents.kovenant:kovenant:$promise_version" implementation "nl.komponents.kovenant:kovenant:$promise_version"
implementation "nl.komponents.kovenant:kovenant-android:$promise_version" implementation "nl.komponents.kovenant:kovenant-android:$promise_version"
// Navigation
implementation "android.arch.navigation:navigation-fragment-ktx:$android_navigation"
implementation "android.arch.navigation:navigation-ui-ktx:$android_navigation"
// Utils // Utils
implementation "org.apache.commons:commons-text:1.4" implementation "org.apache.commons:commons-text:1.4"
implementation "joda-time:joda-time:2.10.1"
// Tests // Tests
testImplementation "junit:junit:4.12" testImplementation "junit:junit:4.12"
......
...@@ -34,6 +34,8 @@ class RefresherService: Service() { ...@@ -34,6 +34,8 @@ class RefresherService: Service() {
this.startForeground(NotificationHelper.ONGOING_REFRESH_NOTIFICATION, refreshNotification) this.startForeground(NotificationHelper.ONGOING_REFRESH_NOTIFICATION, refreshNotification)
Store.ensureToken()
val promise = Store.getSubscriptions() val promise = Store.getSubscriptions()
.bind {Store.getUnreadCount()} .bind {Store.getUnreadCount()}
.bind {all(Store.subscriptions.keys.map {Store.getStreamContents(it)}, cancelOthersOnError = false)} .bind {all(Store.subscriptions.keys.map {Store.getStreamContents(it)}, cancelOthersOnError = false)}
......
package fr.chenry.android.freshrss.activities package fr.chenry.android.freshrss.activities
import android.os.Bundle import android.os.Bundle
import android.view.MenuItem
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment import androidx.navigation.NavController
import androidx.navigation.Navigation
import androidx.navigation.ui.AppBarConfiguration
import androidx.navigation.ui.setupActionBarWithNavController
import fr.chenry.android.freshrss.* import fr.chenry.android.freshrss.*
import fr.chenry.android.freshrss.components.waiting.WaitingFragment
import fr.chenry.android.freshrss.store.*
import fr.chenry.android.freshrss.utils.* import fr.chenry.android.freshrss.utils.*
import nl.komponents.kovenant.deferred import nl.komponents.kovenant.deferred
import nl.komponents.kovenant.resolve import nl.komponents.kovenant.resolve
import nl.komponents.kovenant.ui.failUi import nl.komponents.kovenant.ui.failUi
import nl.komponents.kovenant.ui.successUi import nl.komponents.kovenant.ui.successUi
class MainActivity: AppCompatActivity() { class MainActivity: AppCompatActivity() {
private val deferred = deferred<Unit, Exception>() private val deferred = deferred<Unit, Exception>()
private val navigation: NavController by lazy {
Navigation.findNavController(this, R.id.main_activity_host_fragment)
}
private val appBarConfiguration by lazy {AppBarConfiguration(navigation.graph)}
init { init {
FreshRSSApplication.application.refresherService.whenNotNull { FreshRSSApplication.application.refresherService.whenNotNull {
...@@ -27,54 +32,13 @@ class MainActivity: AppCompatActivity() { ...@@ -27,54 +32,13 @@ class MainActivity: AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main) setContentView(R.layout.activity_main)
setupActionBarWithNavController(navigation, appBarConfiguration)
Router.observe(::onRouteChanged)
setupActionBar()
} }
override fun onStart() { override fun onStart() {
super.onStart() super.onStart()
deferred.promise failUi {this.e(it)} deferred.promise failUi {this.e(it)}
Router.navigate(RouteName.SUBSCRIPTIONS, pushHistory = false)
} }
override fun onOptionsItemSelected(item: MenuItem?): Boolean { override fun onSupportNavigateUp() = navigation.navigateUp() || super.onSupportNavigateUp()
if(item == null) return super.onOptionsItemSelected(item)
return when(item.itemId) {
android.R.id.home -> onBackPressed().let {true}
else -> super.onOptionsItemSelected(item)
}
}
override fun onBackPressed() {
if(supportFragmentManager.backStackEntryCount > 0)
supportFragmentManager.popBackStackImmediate()
}
private fun onRouteChanged(to: Router.Route) {
val bundle = if(to.parameters.isEmpty()) Bundle.EMPTY else Bundle(to.parameters.entries.size).apply {
to.parameters.entries.forEach {(k, v) -> this.putString(k, v)}
}
val fragmentTransaction = supportFragmentManager
?.beginTransaction()
?.replace(
R.id.fragment_container,
Fragment.instantiate(this, to.fragment.qualifiedName, bundle)
)
if(to.pushHistory)
fragmentTransaction?.addToBackStack(null)
fragmentTransaction?.commit()
}
private fun setupActionBar() {
supportFragmentManager.addOnBackStackChangedListener {
if(supportFragmentManager.backStackEntryCount > 0) supportActionBar?.setDisplayHomeAsUpEnabled(true)
else supportActionBar?.setDisplayHomeAsUpEnabled(false)
}
supportFragmentManager?.beginTransaction()?.add(R.id.fragment_container, WaitingFragment())?.commit()
}
} }
...@@ -27,17 +27,12 @@ class RecyclerViewAdapter(private val fragment: SubscriptionArticlesFragment): ...@@ -27,17 +27,12 @@ class RecyclerViewAdapter(private val fragment: SubscriptionArticlesFragment):
override fun onBindViewHolder(holder: ViewHolder, position: Int) { override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val article = articles[position] val article = articles[position]
holder.bind(article) holder.bind(article)
holder.binding.root.setOnClickListener{ holder.binding.root.setOnClickListener{fragment.navigateToArticle(article.id)}
Router.navigate(RouteName.SUBSCRIPTION_CONTENT_DETAIL,
mapOf("streamId" to fragment.streamId, "articleId" to article.id))
}
} }
override fun getItemCount(): Int = articles.size override fun getItemCount(): Int = articles.size
inner class ViewHolder(val binding: FragmentSubscriptionArticleBinding): inner class ViewHolder(val binding: FragmentSubscriptionArticleBinding): RecyclerView.ViewHolder(binding.root) {
RecyclerView.ViewHolder(binding.root) {
fun bind(article: Article) { fun bind(article: Article) {
binding.setVariable(BR.article, article) binding.setVariable(BR.article, article)
binding.executePendingBindings() binding.executePendingBindings()
......
...@@ -15,6 +15,7 @@ import fr.chenry.android.freshrss.R ...@@ -15,6 +15,7 @@ import fr.chenry.android.freshrss.R
import fr.chenry.android.freshrss.store.database.FreshRSSDabatabase import fr.chenry.android.freshrss.store.database.FreshRSSDabatabase
import fr.chenry.android.freshrss.store.Store import fr.chenry.android.freshrss.store.Store
import fr.chenry.android.freshrss.store.database.models.* import fr.chenry.android.freshrss.store.database.models.*
import fr.chenry.android.freshrss.store.database.models.ReadStatus.UNREAD
import fr.chenry.android.freshrss.store.databindingsupport.viewmodels.SubscriptionArticlesVM import fr.chenry.android.freshrss.store.databindingsupport.viewmodels.SubscriptionArticlesVM
import fr.chenry.android.freshrss.store.databindingsupport.viewmodels.SubscriptionArticlesVMF import fr.chenry.android.freshrss.store.databindingsupport.viewmodels.SubscriptionArticlesVMF
import fr.chenry.android.freshrss.utils.capitalizeFull import fr.chenry.android.freshrss.utils.capitalizeFull
...@@ -72,7 +73,7 @@ class SubscriptionArticlesDetailFragment: Fragment() { ...@@ -72,7 +73,7 @@ class SubscriptionArticlesDetailFragment: Fragment() {
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
setReadStatus(ReadStatus.READ) if(article.readStatus == UNREAD) setReadStatus(ReadStatus.READ)
} }
override fun onDestroyView() { override fun onDestroyView() {
...@@ -137,17 +138,6 @@ class SubscriptionArticlesDetailFragment: Fragment() { ...@@ -137,17 +138,6 @@ class SubscriptionArticlesDetailFragment: Fragment() {
return false return false
} }
val readText = when(readStatus) {
ReadStatus.READ -> this.getString(R.string.read)
ReadStatus.UNREAD -> this.getString(R.string.unread)
}.let {this.getString(R.string.mark_read_status_authorization, it)}
if(!FreshRSSDabatabase.instance.account.canPostRequests) {
val toastText = this.getString(R.string.cannot_make_post_requests, readText)
Toast.makeText(context, toastText, LENGTH_LONG).show()
return false
}
isFetching.value = true isFetching.value = true
Store.postReadStatus(article, readStatus) Store.postReadStatus(article, readStatus)
...@@ -162,6 +152,12 @@ class SubscriptionArticlesDetailFragment: Fragment() { ...@@ -162,6 +152,12 @@ class SubscriptionArticlesDetailFragment: Fragment() {
} }
.failUi {e -> .failUi {e ->
this.e(e) this.e(e)
val readText = when(readStatus) {
ReadStatus.READ -> this.getString(R.string.read)
ReadStatus.UNREAD -> this.getString(R.string.unread)
}.let {this.getString(R.string.mark_read_status_authorization, it)}
val toastText = context?.getString(R.string.unable_to, readText) val toastText = context?.getString(R.string.unable_to, readText)
Toast.makeText(context, toastText, LENGTH_SHORT).show() Toast.makeText(context, toastText, LENGTH_SHORT).show()
} alwaysUi {isFetching.value = false} } alwaysUi {isFetching.value = false}
......
...@@ -3,46 +3,63 @@ package fr.chenry.android.freshrss.components.subscriptionarticles ...@@ -3,46 +3,63 @@ package fr.chenry.android.freshrss.components.subscriptionarticles
import android.os.Bundle import android.os.Bundle
import android.view.* import android.view.*
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.lifecycle.* import androidx.lifecycle.LiveData
import androidx.lifecycle.Observer
import androidx.navigation.findNavController
import androidx.navigation.fragment.navArgs
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import fr.chenry.android.freshrss.R import fr.chenry.android.freshrss.R
import fr.chenry.android.freshrss.store.api.models.StreamId
import fr.chenry.android.freshrss.store.database.FreshRSSDabatabase import fr.chenry.android.freshrss.store.database.FreshRSSDabatabase
import fr.chenry.android.freshrss.store.database.models.Articles import fr.chenry.android.freshrss.store.database.models.Articles
import fr.chenry.android.freshrss.store.databindingsupport.viewmodels.* import fr.chenry.android.freshrss.store.database.models.ReadStatus
import fr.chenry.android.freshrss.store.database.models.ReadStatus.READ
import fr.chenry.android.freshrss.store.database.models.ReadStatus.UNREAD
import kotlinx.android.synthetic.main.fragment_subscription_articles.*
sealed class SubscriptionArticlesFragment: Fragment() { open class SubscriptionArticlesFragment: Fragment(), Observer<Articles> {
lateinit var streamId: String
private set
private lateinit var model: LiveData<Articles>
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { private val streamId: String by lazy {args.id}
streamId = arguments?.getString("id")!! private val readStatus: ReadStatus by lazy {args.readStatus}
model = getModel(streamId) private val args: SubscriptionArticlesFragmentArgs by navArgs()
private val model: LiveData<Articles> by lazy {
return inflater.inflate(R.layout.fragment_subscription_articles, container, false) when(readStatus) {
.let { READ -> FreshRSSDabatabase.instance.getArticleByStreamId(streamId)
it as RecyclerView UNREAD -> FreshRSSDabatabase.instance.getArticleByStreamIdAndUnread(streamId)
it.layoutManager = LinearLayoutManager(context) }
it.adapter = RecyclerViewAdapter(this).let {adapter -> }
model.observe(this, Observer {articles -> private val adapter by lazy {
adapter.articles = articles RecyclerViewAdapter(this).apply {
adapter.notifyDataSetChanged() model.observe(this@SubscriptionArticlesFragment, this@SubscriptionArticlesFragment)
}) }
adapter
}
it
}
} }
abstract fun getModel(streamId: StreamId): LiveData<Articles> override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
} val view = inflater.inflate(R.layout.fragment_subscription_articles, container, false)
class SubscriptionAllArticlesFragment: SubscriptionArticlesFragment() { model.observe(this, this)
override fun getModel(streamId: StreamId) = FreshRSSDabatabase.instance.getArticleByStreamId(streamId)
} view.findViewById<RecyclerView>(R.id.fragment_subscription_article_recycler).apply {
layoutManager = LinearLayoutManager(context)
adapter = this@SubscriptionArticlesFragment.adapter
}
class SubscriptionUnreadArticlesFragment: SubscriptionArticlesFragment() { return view
override fun getModel(streamId: StreamId) = FreshRSSDabatabase.instance.getArticleByStreamIdAndUnread(streamId) }
override fun onChanged(articles: Articles?) {
(articles ?: listOf()).let {
fragment_subscription_article_waiting.visibility = if(it.isNotEmpty()) View.GONE else View.VISIBLE
fragment_subscription_article_recycler.visibility = if(it.isEmpty()) View.GONE else View.VISIBLE
adapter.articles = it
adapter.notifyDataSetChanged()
}
}
fun navigateToArticle(articleId: String) {
val direction =
SubscriptionArticlesFragmentDirections
.actionSubscriptionArticlesFragmentToSubscriptionArticlesDetailFragment(articleId)
view?.findNavController()?.navigate(direction)
}
} }
...@@ -2,9 +2,13 @@ package fr.chenry.android.freshrss.components.subscriptions ...@@ -2,9 +2,13 @@ package fr.chenry.android.freshrss.components.subscriptions
import androidx.lifecycle.LiveData import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import androidx.navigation.findNavController
import fr.chenry.android.freshrss.MainNavDirections
import fr.chenry.android.freshrss.R
import fr.chenry.android.freshrss.store.* import fr.chenry.android.freshrss.store.*
import fr.chenry.android.freshrss.store.api.models.Subscription import fr.chenry.android.freshrss.store.api.models.Subscription
import fr.chenry.android.freshrss.store.api.models.Subscriptions import fr.chenry.android.freshrss.store.api.models.Subscriptions
import fr.chenry.android.freshrss.store.database.models.ReadStatus.READ
class AllSubscriptionsFragment: SubscriptionsFragment() { class AllSubscriptionsFragment: SubscriptionsFragment() {
override val liveData: LiveData<Subscriptions> = MutableLiveData<Subscriptions>().apply { override val liveData: LiveData<Subscriptions> = MutableLiveData<Subscriptions>().apply {
...@@ -13,6 +17,7 @@ class AllSubscriptionsFragment: SubscriptionsFragment() { ...@@ -13,6 +17,7 @@ class AllSubscriptionsFragment: SubscriptionsFragment() {
} }
override fun onClick(subscription: Subscription) { override fun onClick(subscription: Subscription) {
Router.navigate(RouteName.SUBSCRIPTION_ARTICLES_ALL, mapOf("id" to subscription.id)) val direction = MainNavDirections.actionGlobalSubscriptionArticlesFragment(subscription.id, READ)
view?.findNavController()?.navigate(direction)
} }
} }
package fr.chenry.android.freshrss.components.subscriptions package fr.chenry.android.freshrss.components.subscriptions
import androidx.lifecycle.* import androidx.lifecycle.MutableLiveData
import fr.chenry.android.freshrss.store.RouteName import androidx.navigation.findNavController
import fr.chenry.android.freshrss.store.Router import fr.chenry.android.freshrss.MainNavDirections
import fr.chenry.android.freshrss.store.api.models.Subscription import fr.chenry.android.freshrss.store.api.models.Subscription
import fr.chenry.android.freshrss.store.api.models.Subscriptions import fr.chenry.android.freshrss.store.api.models.Subscriptions
import fr.chenry.android.freshrss.store.database.models.ReadStatus.UNREAD
class FavoritesSubscriptionsFragment: SubscriptionsFragment() { class FavoritesSubscriptionsFragment: SubscriptionsFragment() {
override val liveData = MutableLiveData<Subscriptions>().apply {this.value = listOf()} override val liveData = MutableLiveData<Subscriptions>().apply {this.value = listOf()}
override fun onClick(subscription: Subscription) { override fun onClick(subscription: Subscription) {
Router.navigate(RouteName.SUBSCRIPTION_ARTICLES_UNREAD, mapOf("id" to subscription.id)) val direction = MainNavDirections.actionGlobalSubscriptionArticlesFragment(subscription.id, UNREAD)
view?.findNavController()?.navigate(direction)
} }
} }
...@@ -4,6 +4,7 @@ import android.os.Bundle ...@@ -4,6 +4,7 @@ import android.os.Bundle
import android.view.* import android.view.*
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.lifecycle.LiveData import androidx.lifecycle.LiveData
import androidx.lifecycle.Observer
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import fr.chenry.android.freshrss.FreshRSSApplication import fr.chenry.android.freshrss.FreshRSSApplication
...@@ -11,9 +12,9 @@ import fr.chenry.android.freshrss.R ...@@ -11,9 +12,9 @@ import fr.chenry.android.freshrss.R
import fr.chenry.android.freshrss.store.Store import fr.chenry.android.freshrss.store.Store
import fr.chenry.android.freshrss.store.api.models.Subscription import fr.chenry.android.freshrss.store.api.models.Subscription
import fr.chenry.android.freshrss.store.api.models.Subscriptions import fr.chenry.android.freshrss.store.api.models.Subscriptions
import fr.chenry.android.freshrss.utils.getOrDefault
import fr.chenry.android.freshrss.utils.whenNotNull import fr.chenry.android.freshrss.utils.whenNotNull
import kotlinx.android.synthetic.main.fragment_main_subscription.* import kotlinx.android.synthetic.main.fragment_main_subscription.*
import kotlinx.android.synthetic.main.fragment_subscriptions.*
import kotlin.reflect.KClass import kotlin.reflect.KClass
class MainSubscriptionFragment: Fragment() { class MainSubscriptionFragment: Fragment() {
...@@ -75,23 +76,31 @@ class MainSubscriptionFragment: Fragment() { ...@@ -75,23 +76,31 @@ class MainSubscriptionFragment: Fragment() {
} }
} }
abstract class SubscriptionsFragment: Fragment() { abstract class SubscriptionsFragment: Fragment(), Observer<Subscriptions> {
abstract val liveData: LiveData<Subscriptions> abstract val liveData: LiveData<Subscriptions>
val subscriptions: Subscriptions get() = liveData.value ?: listOf() val subscriptions: Subscriptions get() = liveData.value ?: listOf()
private val adapter by lazy {RecyclerViewAdapter(this)}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val view = inflater.inflate(R.layout.fragment_subscriptions, container, false) val view = inflater.inflate(R.layout.fragment_subscriptions, container, false)
liveData.observe(this, this)
view.findViewById<RecyclerView>(R.id.subscriptions_list).let { view.findViewById<RecyclerView>(R.id.subscriptions_list).let {
it.layoutManager = LinearLayoutManager(context, RecyclerView.VERTICAL, false) it.layoutManager = LinearLayoutManager(context, RecyclerView.VERTICAL, false)
it.adapter = RecyclerViewAdapter(this).apply { it.adapter = this.adapter
liveData.observeForever {this.notifyDataSetChanged()}
}
} }
return view return view
} }
override fun onChanged(subscriptions: Subscriptions?) {
(subscriptions ?: listOf()).let {
subscriptions_list.visibility = if(it.isEmpty()) View.GONE else View.VISIBLE
fragment_subscriptions_waiting.visibility = if(it.isNotEmpty()) View.GONE else View.VISIBLE
adapter.notifyDataSetChanged()
}
}
abstract fun onClick(subscription: Subscription) abstract fun onClick(subscription: Subscription)
} }
\ No newline at end of file