mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-15 18:12:54 +00:00
[fenix] Simplify ItsNotBrokenSnack() and make resilient
Co-authored by: Emily Kager <ekager@mozilla.com>
This commit is contained in:
parent
fa92b472ea
commit
b702f77c8a
@ -309,7 +309,7 @@ class BrowserFragment : Fragment(), BackHandler {
|
||||
}
|
||||
ToolbarMenu.Item.Help -> {
|
||||
// TODO Help #1016
|
||||
ItsNotBrokenSnack(context!!).showSnackbar(activity = activity!!, issueNumber = "1016")
|
||||
ItsNotBrokenSnack(context!!).showSnackbar(issueNumber = "1016")
|
||||
}
|
||||
ToolbarMenu.Item.NewTab -> {
|
||||
val directions = BrowserFragmentDirections
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
package org.mozilla.fenix.ext
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.ActivityNotFoundException
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
@ -11,7 +12,9 @@ import android.content.Intent.ACTION_SEND
|
||||
import android.content.Intent.EXTRA_SUBJECT
|
||||
import android.content.Intent.EXTRA_TEXT
|
||||
import android.content.Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
import android.view.ContextThemeWrapper
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.fragment.app.FragmentActivity
|
||||
import mozilla.components.support.base.log.Log
|
||||
import mozilla.components.support.base.log.Log.Priority.WARN
|
||||
import org.mozilla.fenix.FenixApplication
|
||||
@ -30,6 +33,12 @@ val Context.application: FenixApplication
|
||||
val Context.components: Components
|
||||
get() = application.components
|
||||
|
||||
fun Context.asActivity() = (this as? ContextThemeWrapper)?.baseContext as? Activity
|
||||
?: this as? Activity
|
||||
|
||||
fun Context.asFragmentActivity() = (this as? ContextThemeWrapper)?.baseContext as? FragmentActivity
|
||||
?: this as? FragmentActivity
|
||||
|
||||
fun Context.getPreferenceKey(@StringRes resourceId: Int): String =
|
||||
resources.getString(resourceId)
|
||||
|
||||
|
@ -252,7 +252,7 @@ class HomeFragment : Fragment(), CoroutineScope {
|
||||
is SessionsAction.MenuTapped ->
|
||||
openSessionMenu(SessionBottomSheetFragment.SessionType.Archived(it.archivedSession))
|
||||
is SessionsAction.ShareTapped ->
|
||||
ItsNotBrokenSnack(context!!).showSnackbar(activity = activity!!, issueNumber = "244")
|
||||
ItsNotBrokenSnack(context!!).showSnackbar(issueNumber = "244")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ class SessionBottomSheetFragment : BottomSheetDialogFragment(), LayoutContainer
|
||||
}
|
||||
|
||||
view.send_and_share_session_button.setOnClickListener {
|
||||
ItsNotBrokenSnack(context!!).showSnackbar(activity = activity!!, issueNumber = "244")
|
||||
ItsNotBrokenSnack(context!!).showSnackbar(issueNumber = "244")
|
||||
}
|
||||
|
||||
view.delete_session_button.setOnClickListener {
|
||||
|
@ -48,19 +48,19 @@ class LibraryFragment : Fragment() {
|
||||
)
|
||||
)
|
||||
libraryDownloads.setOnClickListener {
|
||||
ItsNotBrokenSnack(context!!).showSnackbar(activity = activity!!, issueNumber = "348")
|
||||
ItsNotBrokenSnack(context!!).showSnackbar(issueNumber = "348")
|
||||
}
|
||||
libraryScreenshots.setOnClickListener {
|
||||
ItsNotBrokenSnack(context!!).showSnackbar(activity = activity!!, issueNumber = "89")
|
||||
ItsNotBrokenSnack(context!!).showSnackbar(issueNumber = "89")
|
||||
}
|
||||
libraryFavorites.setOnClickListener {
|
||||
ItsNotBrokenSnack(context!!).showSnackbar(activity = activity!!, issueNumber = "90")
|
||||
ItsNotBrokenSnack(context!!).showSnackbar(issueNumber = "90")
|
||||
}
|
||||
libraryReadingList.setOnClickListener {
|
||||
ItsNotBrokenSnack(context!!).showSnackbar(activity = activity!!, issueNumber = "913")
|
||||
ItsNotBrokenSnack(context!!).showSnackbar(issueNumber = "913")
|
||||
}
|
||||
librarySessions.setOnClickListener {
|
||||
ItsNotBrokenSnack(context!!).showSnackbar(activity = activity!!, issueNumber = "637")
|
||||
ItsNotBrokenSnack(context!!).showSnackbar(issueNumber = "637")
|
||||
}
|
||||
}
|
||||
|
||||
@ -76,7 +76,7 @@ class LibraryFragment : Fragment() {
|
||||
}
|
||||
R.id.librarySearch -> {
|
||||
// TODO Library Search
|
||||
ItsNotBrokenSnack(context!!).showSnackbar(activity = activity!!, issueNumber = "1118")
|
||||
ItsNotBrokenSnack(context!!).showSnackbar(issueNumber = "1118")
|
||||
true
|
||||
}
|
||||
else -> super.onOptionsItemSelected(item)
|
||||
|
@ -119,7 +119,7 @@ class HistoryFragment : Fragment(), CoroutineScope, BackHandler {
|
||||
}
|
||||
R.id.librarySearch -> {
|
||||
// TODO Library Search #1118
|
||||
ItsNotBrokenSnack(context!!).showSnackbar(activity = activity!!, issueNumber = "1118")
|
||||
ItsNotBrokenSnack(context!!).showSnackbar(issueNumber = "1118")
|
||||
true
|
||||
}
|
||||
else -> super.onOptionsItemSelected(item)
|
||||
|
@ -52,7 +52,7 @@ class SearchFragment : Fragment() {
|
||||
} ?: ""
|
||||
|
||||
view.search_scan_button.setOnClickListener {
|
||||
ItsNotBrokenSnack(context!!).showSnackbar(activity = activity!!, issueNumber = "113")
|
||||
ItsNotBrokenSnack(context!!).showSnackbar(issueNumber = "113")
|
||||
}
|
||||
|
||||
toolbarComponent = ToolbarComponent(
|
||||
|
@ -40,6 +40,7 @@ import org.mozilla.fenix.R.string.pref_key_feedback
|
||||
import org.mozilla.fenix.R.string.pref_key_help
|
||||
import org.mozilla.fenix.R.string.pref_key_make_default_browser
|
||||
import org.mozilla.fenix.R.string.pref_key_rate
|
||||
import org.mozilla.fenix.R.string.pref_key_remote_debugging
|
||||
import org.mozilla.fenix.R.string.pref_key_site_permissions
|
||||
import org.mozilla.fenix.R.string.pref_key_accessibility
|
||||
import org.mozilla.fenix.R.string.pref_key_language
|
||||
@ -99,7 +100,7 @@ class SettingsFragment : PreferenceFragmentCompat(), CoroutineScope, AccountObse
|
||||
}
|
||||
resources.getString(pref_key_language) -> {
|
||||
// TODO #220
|
||||
ItsNotBrokenSnack(context!!).showSnackbar(activity = activity!!, issueNumber = "220")
|
||||
ItsNotBrokenSnack(context!!).showSnackbar(issueNumber = "220")
|
||||
}
|
||||
resources.getString(pref_key_data_choices) -> {
|
||||
navigateToDataChoices()
|
||||
|
@ -4,25 +4,25 @@
|
||||
|
||||
package org.mozilla.fenix.utils
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.view.View
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
import org.mozilla.fenix.ext.asActivity
|
||||
import org.mozilla.fenix.ext.components
|
||||
|
||||
class ItsNotBrokenSnack(val context: Context) {
|
||||
fun getSnackbar(issueNumber: String, view: View): Snackbar {
|
||||
val snackbar = Snackbar.make(view, message.replace("%", issueNumber), Snackbar.LENGTH_SHORT)
|
||||
snackbar.setAction("Add Tab to Issue", {
|
||||
context.components.useCases.tabsUseCases.addTab
|
||||
.invoke(issues + issueNumber)
|
||||
})
|
||||
return snackbar
|
||||
}
|
||||
|
||||
fun showSnackbar(issueNumber: String, activity: Activity) {
|
||||
val rootView = activity.window.decorView.findViewById<View>(android.R.id.content)
|
||||
getSnackbar(issueNumber, rootView).show()
|
||||
fun showSnackbar(issueNumber: String) {
|
||||
val rootView = context.asActivity()?.window?.decorView?.findViewById<View>(android.R.id.content)
|
||||
rootView?.let {
|
||||
Snackbar.make(rootView, message.replace("%", issueNumber), Snackbar.LENGTH_SHORT).apply {
|
||||
setAction("Add Tab to Issue") {
|
||||
context.components.useCases.tabsUseCases.addTab
|
||||
.invoke(issues + issueNumber)
|
||||
}
|
||||
show()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
Loading…
Reference in New Issue
Block a user