2019-05-31 17:16:08 +02:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
2019-07-12 20:38:15 +02:00
|
|
|
* 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/. */
|
2019-05-31 17:16:08 +02:00
|
|
|
|
|
|
|
package org.mozilla.fenix.browser
|
|
|
|
|
|
|
|
import android.view.View
|
2019-07-15 17:24:59 +02:00
|
|
|
import androidx.annotation.StringRes
|
2019-05-31 17:16:08 +02:00
|
|
|
import com.google.android.material.snackbar.Snackbar
|
|
|
|
import mozilla.components.feature.contextmenu.ContextMenuCandidate
|
|
|
|
import org.mozilla.fenix.components.FenixSnackbar
|
|
|
|
|
|
|
|
class FenixSnackbarDelegate(val view: View, private val anchorView: View?) :
|
|
|
|
ContextMenuCandidate.SnackbarDelegate {
|
|
|
|
override fun show(
|
|
|
|
snackBarParentView: View,
|
2019-07-15 17:24:59 +02:00
|
|
|
@StringRes text: Int,
|
2019-05-31 17:16:08 +02:00
|
|
|
duration: Int,
|
2019-07-15 17:24:59 +02:00
|
|
|
@StringRes action: Int,
|
2019-05-31 17:16:08 +02:00
|
|
|
listener: ((v: View) -> Unit)?
|
|
|
|
) {
|
|
|
|
val snackbar = FenixSnackbar.make(view, Snackbar.LENGTH_LONG).setText(view.context.getString(text))
|
2019-07-15 17:24:59 +02:00
|
|
|
if (listener != null && action != 0) {
|
|
|
|
snackbar.setAction(view.context.getString(action)) {
|
2019-05-31 17:16:08 +02:00
|
|
|
listener.invoke(view)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
snackbar.anchorView = anchorView
|
|
|
|
snackbar.show()
|
|
|
|
}
|
|
|
|
}
|