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 mozilla.components.feature.contextmenu.ContextMenuCandidate
|
2020-01-02 23:31:52 +01:00
|
|
|
import org.mozilla.fenix.components.FenixSnackbar
|
2019-05-31 17:16:08 +02:00
|
|
|
|
2020-07-08 04:46:25 +02:00
|
|
|
class FenixSnackbarDelegate(private val view: View) : ContextMenuCandidate.SnackbarDelegate {
|
|
|
|
|
2019-05-31 17:16:08 +02:00
|
|
|
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)?
|
|
|
|
) {
|
2019-07-15 17:24:59 +02:00
|
|
|
if (listener != null && action != 0) {
|
2020-04-02 21:30:13 +02:00
|
|
|
FenixSnackbar.make(
|
|
|
|
view = view,
|
|
|
|
duration = FenixSnackbar.LENGTH_SHORT,
|
2020-04-13 21:16:01 +02:00
|
|
|
isDisplayedWithBrowserToolbar = true
|
2020-04-02 21:30:13 +02:00
|
|
|
)
|
2020-01-02 23:31:52 +01:00
|
|
|
.setText(view.context.getString(text))
|
|
|
|
.setAction(view.context.getString(action)) { listener.invoke(view) }
|
|
|
|
.show()
|
2019-12-30 23:43:15 +01:00
|
|
|
} else {
|
2020-04-02 21:30:13 +02:00
|
|
|
FenixSnackbar.make(view,
|
|
|
|
duration = FenixSnackbar.LENGTH_SHORT,
|
2020-04-13 21:16:01 +02:00
|
|
|
isDisplayedWithBrowserToolbar = true
|
2020-04-02 21:30:13 +02:00
|
|
|
)
|
2020-01-02 23:31:52 +01:00
|
|
|
.setText(view.context.getString(text))
|
|
|
|
.show()
|
2019-05-31 17:16:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|