2019-07-10 17:19:07 +02:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
package org.mozilla.fenix.library
|
|
|
|
|
2019-07-26 04:55:51 +02:00
|
|
|
import android.content.Context
|
2019-07-10 17:19:07 +02:00
|
|
|
import android.view.ViewGroup
|
|
|
|
import androidx.appcompat.widget.Toolbar
|
|
|
|
import androidx.core.content.ContextCompat
|
2019-09-12 22:56:39 +02:00
|
|
|
import androidx.recyclerview.widget.RecyclerView
|
2019-08-01 17:58:41 +02:00
|
|
|
import kotlinx.android.extensions.LayoutContainer
|
2019-07-10 17:19:07 +02:00
|
|
|
import org.mozilla.fenix.R
|
|
|
|
import org.mozilla.fenix.ext.asActivity
|
2019-10-11 08:02:22 +02:00
|
|
|
import org.mozilla.fenix.ext.getColorFromAttr
|
2019-10-26 06:41:48 +02:00
|
|
|
import org.mozilla.fenix.ext.setToolbarColors
|
2019-07-10 17:19:07 +02:00
|
|
|
|
2019-07-26 04:55:51 +02:00
|
|
|
open class LibraryPageView(
|
2019-08-01 17:58:41 +02:00
|
|
|
override val containerView: ViewGroup
|
|
|
|
) : LayoutContainer {
|
|
|
|
protected val context: Context inline get() = containerView.context
|
2019-07-26 04:55:51 +02:00
|
|
|
protected val activity = context.asActivity()
|
2019-07-10 17:19:07 +02:00
|
|
|
|
2019-09-12 22:56:39 +02:00
|
|
|
protected fun setUiForNormalMode(
|
|
|
|
title: String?,
|
|
|
|
libraryItemsList: RecyclerView
|
|
|
|
) {
|
2019-10-26 06:41:48 +02:00
|
|
|
updateToolbar(
|
|
|
|
title = title,
|
|
|
|
foregroundColor = context.getColorFromAttr(R.attr.primaryText),
|
|
|
|
backgroundColor = context.getColorFromAttr(R.attr.foundation)
|
2019-08-01 17:58:41 +02:00
|
|
|
)
|
2019-11-27 09:40:38 +01:00
|
|
|
libraryItemsList.adapter?.notifyDataSetChanged()
|
2019-08-01 17:58:41 +02:00
|
|
|
}
|
|
|
|
|
2019-09-12 22:56:39 +02:00
|
|
|
protected fun setUiForSelectingMode(
|
|
|
|
title: String?,
|
|
|
|
libraryItemsList: RecyclerView
|
|
|
|
) {
|
2019-10-26 06:41:48 +02:00
|
|
|
updateToolbar(
|
|
|
|
title = title,
|
|
|
|
foregroundColor = ContextCompat.getColor(context, R.color.white_color),
|
|
|
|
backgroundColor = context.getColorFromAttr(R.attr.accentHighContrast)
|
2019-08-01 17:58:41 +02:00
|
|
|
)
|
2019-11-27 09:40:38 +01:00
|
|
|
libraryItemsList.adapter?.notifyDataSetChanged()
|
2019-08-01 17:58:41 +02:00
|
|
|
}
|
|
|
|
|
2019-10-26 06:41:48 +02:00
|
|
|
private fun updateToolbar(title: String?, foregroundColor: Int, backgroundColor: Int) {
|
|
|
|
activity?.title = title
|
2019-07-10 17:19:07 +02:00
|
|
|
val toolbar = activity?.findViewById<Toolbar>(R.id.navigationToolbar)
|
2019-10-26 06:41:48 +02:00
|
|
|
toolbar?.setToolbarColors(foregroundColor, backgroundColor)
|
2019-07-10 17:19:07 +02:00
|
|
|
}
|
|
|
|
}
|