Skip to content
Permalink
Browse files

Remove unnecessary prefixes for ids to clean up ViewBinding code

  • Loading branch information
ianhanniballake committed Feb 6, 2020
1 parent 9d56d24 commit ab8786003dece813608b74eba07eaa9a73d57fcd
Showing with 264 additions and 266 deletions.
  1. +4 −4 legacy-standalone/src/main/java/com/google/android/apps/muzei/legacy/SourceSettingsActivity.kt
  2. +2 −2 legacy-standalone/src/main/res/layout/legacy_choose_source_item.xml
  3. +14 −14 main/src/main/java/com/google/android/apps/muzei/ArtDetailFragment.kt
  4. +15 −15 main/src/main/java/com/google/android/apps/muzei/AutoAdvanceFragment.kt
  5. +24 −24 main/src/main/java/com/google/android/apps/muzei/ChooseProviderFragment.kt
  6. +4 −4 main/src/main/java/com/google/android/apps/muzei/IntroFragment.kt
  7. +7 −7 main/src/main/java/com/google/android/apps/muzei/TutorialFragment.kt
  8. +7 −7 main/src/main/java/com/google/android/apps/muzei/browse/BrowseProviderFragment.kt
  9. +11 −11 main/src/main/java/com/google/android/apps/muzei/legacy/LegacySourceInfoFragment.kt
  10. +4 −4 main/src/main/java/com/google/android/apps/muzei/settings/AboutActivity.kt
  11. +12 −12 main/src/main/java/com/google/android/apps/muzei/settings/EffectsScreenFragment.kt
  12. +19 −19 main/src/main/java/com/google/android/apps/muzei/settings/GesturesFragment.kt
  13. +1 −1 main/src/main/res/layout-land/intro_fragment.xml
  14. +2 −2 main/src/main/res/layout-sw600dp/about_activity.xml
  15. +1 −1 main/src/main/res/layout-sw600dp/effects_screen_fragment.xml
  16. +2 −2 main/src/main/res/layout-w540dp/legacy_source_info_fragment.xml
  17. +2 −2 main/src/main/res/layout/about_activity.xml
  18. +1 −1 main/src/main/res/layout/about_include_content.xml
  19. +3 −3 main/src/main/res/layout/art_detail_fragment.xml
  20. +11 −11 main/src/main/res/layout/auto_advance_fragment.xml
  21. +3 −3 main/src/main/res/layout/browse_provider_fragment.xml
  22. +1 −1 main/src/main/res/layout/browse_provider_item.xml
  23. +2 −2 main/src/main/res/layout/choose_provider_fragment.xml
  24. +25 −25 main/src/main/res/layout/choose_provider_item.xml
  25. +1 −1 main/src/main/res/layout/effects_fragment.xml
  26. +1 −1 main/src/main/res/layout/effects_screen_fragment.xml
  27. +20 −20 main/src/main/res/layout/effects_screen_fragment_include_content.xml
  28. +25 −26 main/src/main/res/layout/gestures_fragment.xml
  29. +1 −2 main/src/main/res/layout/intro_fragment.xml
  30. +3 −3 main/src/main/res/layout/legacy_source_info_fragment.xml
  31. +15 −15 main/src/main/res/layout/legacy_source_info_item.xml
  32. +6 −6 main/src/main/res/layout/tutorial_content.xml
  33. +1 −1 main/src/main/res/menu/legacy_source_info_fragment.xml
  34. +3 −3 source-gallery/src/main/java/com/google/android/apps/muzei/gallery/GallerySettingsActivity.kt
  35. +3 −3 source-gallery/src/main/res/layout/gallery_activity.xml
  36. +3 −3 wearable/src/main/java/com/google/android/apps/muzei/ChooseProviderActivity.kt
  37. +3 −3 wearable/src/main/java/com/google/android/apps/muzei/MuzeiActivity.kt
  38. +1 −1 wearable/src/main/res/layout/choose_provider_activity.xml
  39. +1 −1 wearable/src/main/res/layout/muzei_activity.xml
@@ -291,7 +291,7 @@ class SourceSettingsActivity : AppCompatActivity() {
val view = super.getView(position, convertView, parent)
val sourceView = getItem(position) ?: return view
return LegacyChooseSourceItemBinding.bind(view).run {
legacyTitle.text = sourceView.toCharSequence()
title.text = sourceView.toCharSequence()
root.alpha = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O &&
sourceView.source.targetSdkVersion >= Build.VERSION_CODES.O) {
ALPHA_DISABLED
@@ -301,14 +301,14 @@ class SourceSettingsActivity : AppCompatActivity() {
if (sourceView.source.selected) {
selectedSourceImage.colorFilter = PorterDuffColorFilter(sourceView.source.color,
PorterDuff.Mode.SRC_ATOP)
legacyTitle.setCompoundDrawablesRelativeWithIntrinsicBounds(
title.setCompoundDrawablesRelativeWithIntrinsicBounds(
selectedSourceImage,null, null, null)

} else {
legacyTitle.setCompoundDrawablesRelativeWithIntrinsicBounds(
title.setCompoundDrawablesRelativeWithIntrinsicBounds(
sourceView.icon,null, null, null)
}
legacySettings.apply {
settings.apply {
val show = sourceView.source.selected &&
sourceView.source.settingsActivity != null
val wasVisible = isVisible
@@ -26,7 +26,7 @@
tools:ignore="UseCompoundDrawables">

<TextView
android:id="@+id/legacy_title"
android:id="@+id/title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
@@ -40,7 +40,7 @@
android:textColor="?attr/colorOnSurface"/>

<ImageView
android:id="@+id/legacy_settings"
android:id="@+id/settings"
android:layout_width="24dp"
android:layout_height="24dp"
android:background="?selectableItemBackgroundBorderless"
@@ -150,7 +150,7 @@ class ArtDetailFragment : Fragment(R.layout.art_detail_fragment), (Boolean) -> U
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
binding = ArtDetailFragmentBinding.bind(view)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
binding.artDetailScrim.background = makeCubicGradientScrimDrawable(Gravity.TOP, 0x44)
binding.scrim.background = makeCubicGradientScrimDrawable(Gravity.TOP, 0x44)
}

val scrimColor = resources.getInteger(R.integer.scrim_channel_color)
@@ -165,9 +165,9 @@ class ArtDetailFragment : Fragment(R.layout.art_detail_fragment), (Boolean) -> U
binding.title.typeface = ResourcesCompat.getFont(requireContext(), R.font.alegreya_sans_black)
binding.byline.typeface = ResourcesCompat.getFont(requireContext(), R.font.alegreya_sans_medium)

binding.overflowMenuView.overflowIcon = ContextCompat.getDrawable(requireContext(),
binding.overflowMenu.overflowIcon = ContextCompat.getDrawable(requireContext(),
R.drawable.ic_overflow)
binding.overflowMenuView.setOnMenuItemClickListener { menuItem ->
binding.overflowMenu.setOnMenuItemClickListener { menuItem ->
val context = context ?: return@setOnMenuItemClickListener false
val id = overflowSourceActionMap.get(menuItem.itemId)
if (id > 0) {
@@ -213,13 +213,13 @@ class ArtDetailFragment : Fragment(R.layout.art_detail_fragment), (Boolean) -> U
}
}

binding.nextButton.setOnClickListener {
binding.nextArtwork.setOnClickListener {
FirebaseAnalytics.getInstance(requireContext()).logEvent("next_artwork", bundleOf(
FirebaseAnalytics.Param.CONTENT_TYPE to "art_detail"))
ProviderManager.getInstance(requireContext()).nextArtwork()
showFakeLoading()
}
TooltipCompat.setTooltipText(binding.nextButton, binding.nextButton.contentDescription)
TooltipCompat.setTooltipText(binding.nextArtwork, binding.nextArtwork.contentDescription)

backgroundImageViewState = savedInstanceState?.getSerializable(
KEY_IMAGE_VIEW_STATE) as ImageViewState?
@@ -302,7 +302,7 @@ class ArtDetailFragment : Fragment(R.layout.art_detail_fragment), (Boolean) -> U

currentProviderLiveData.observe(viewLifecycleOwner) { provider ->
val supportsNextArtwork = provider?.supportsNextArtwork == true
binding.nextButton.isVisible = supportsNextArtwork
binding.nextArtwork.isVisible = supportsNextArtwork
}

currentArtworkLiveData.observe(viewLifecycleOwner) { currentArtwork ->
@@ -352,14 +352,14 @@ class ArtDetailFragment : Fragment(R.layout.art_detail_fragment), (Boolean) -> U
} ?: return@launch
val activity = activity ?: return@launch
overflowSourceActionMap.clear()
binding.overflowMenuView.menu.clear()
binding.overflowMenu.menu.clear()
activity.menuInflater.inflate(R.menu.muzei_overflow,
binding.overflowMenuView.menu)
binding.overflowMenuView.menu.findItem(R.id.action_always_dark)?.isChecked =
binding.overflowMenu.menu)
binding.overflowMenu.menu.findItem(R.id.action_always_dark)?.isChecked =
MuzeiApplication.getAlwaysDark(activity)
commands.take(SOURCE_ACTION_IDS.size).forEachIndexed { i, action ->
overflowSourceActionMap.put(SOURCE_ACTION_IDS[i], action.id)
val menuItem = binding.overflowMenuView.menu.add(0, SOURCE_ACTION_IDS[i],
val menuItem = binding.overflowMenu.menu.add(0, SOURCE_ACTION_IDS[i],
0, action.title)
if (action.id == LegacySourceServiceProtocol.LEGACY_COMMAND_ID_NEXT_ARTWORK &&
currentProviderLiveData.value?.authority == LEGACY_AUTHORITY) {
@@ -411,13 +411,13 @@ class ArtDetailFragment : Fragment(R.layout.art_detail_fragment), (Boolean) -> U
}

private fun animateChromeVisibility(visible: Boolean) {
binding.artDetailScrim.visibility = View.VISIBLE
binding.artDetailScrim.animate()
binding.scrim.visibility = View.VISIBLE
binding.scrim.animate()
.alpha(if (visible) 1f else 0f)
.setDuration(200)
.withEndAction {
if (!visible) {
binding.artDetailScrim.visibility = View.GONE
binding.scrim.visibility = View.GONE
}
}

@@ -457,7 +457,7 @@ class ArtDetailFragment : Fragment(R.layout.art_detail_fragment), (Boolean) -> U

override fun onStop() {
super.onStop()
binding.overflowMenuView.hideOverflowMenu()
binding.overflowMenu.hideOverflowMenu()
ArtDetailOpenLiveData.value = false
}

@@ -45,14 +45,14 @@ class AutoAdvanceFragment : Fragment(R.layout.auto_advance_fragment) {

init {
INTERVAL_RADIO_BUTTON_IDS_BY_TIME.apply {
put(60 * 15, R.id.auto_advance_interval_15m)
put(60 * 30, R.id.auto_advance_interval_30m)
put(60 * 60, R.id.auto_advance_interval_1h)
put(60 * 60 * 3, R.id.auto_advance_interval_3h)
put(60 * 60 * 6, R.id.auto_advance_interval_6h)
put(60 * 60 * 24, R.id.auto_advance_interval_24h)
put(60 * 60 * 72, R.id.auto_advance_interval_72h)
put(0, R.id.auto_advance_interval_never)
put(60 * 15, R.id.interval_15m)
put(60 * 30, R.id.interval_30m)
put(60 * 60, R.id.interval_1h)
put(60 * 60 * 3, R.id.interval_3h)
put(60 * 60 * 6, R.id.interval_6h)
put(60 * 60 * 24, R.id.interval_24h)
put(60 * 60 * 72, R.id.interval_72h)
put(0, R.id.interval_never)
}
for (i in 0 until INTERVAL_RADIO_BUTTON_IDS_BY_TIME.size()) {
INTERVAL_TIME_BY_RADIO_BUTTON_ID.put(INTERVAL_RADIO_BUTTON_IDS_BY_TIME.valueAt(i),
@@ -65,8 +65,8 @@ class AutoAdvanceFragment : Fragment(R.layout.auto_advance_fragment) {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
val binding = AutoAdvanceFragmentBinding.bind(view)
val providerManager = ProviderManager.getInstance(requireContext())
binding.autoAdvanceWifi.isChecked = providerManager.loadOnWifi
binding.autoAdvanceWifi.setOnCheckedChangeListener { _, isChecked ->
binding.useWifi.isChecked = providerManager.loadOnWifi
binding.useWifi.setOnCheckedChangeListener { _, isChecked ->
FirebaseAnalytics.getInstance(requireContext()).logEvent(
"auto_advance_load_on_wifi", bundleOf(
FirebaseAnalytics.Param.VALUE to isChecked.toString()))
@@ -75,20 +75,20 @@ class AutoAdvanceFragment : Fragment(R.layout.auto_advance_fragment) {

val currentInterval = providerManager.loadFrequencySeconds

binding.autoAdvanceInterval.check(INTERVAL_RADIO_BUTTON_IDS_BY_TIME[currentInterval.toInt()])
binding.autoAdvanceInterval.setOnCheckedChangeListener { _, id ->
binding.intervalGroup.check(INTERVAL_RADIO_BUTTON_IDS_BY_TIME[currentInterval.toInt()])
binding.intervalGroup.setOnCheckedChangeListener { _, id ->
FirebaseAnalytics.getInstance(requireContext()).logEvent(
"auto_advance_load_frequency", bundleOf(
FirebaseAnalytics.Param.VALUE to INTERVAL_TIME_BY_RADIO_BUTTON_ID[id]))
providerManager.loadFrequencySeconds = INTERVAL_TIME_BY_RADIO_BUTTON_ID[id]
}

val text = binding.autoAdvanceTasker.text.toSpannable()
val text = binding.tasker.text.toSpannable()
val taskerIndex = text.indexOf("Tasker")
text[taskerIndex, taskerIndex + 6] = UnderlineSpan()
binding.autoAdvanceTasker.text = text
binding.tasker.text = text
val context = requireContext()
binding.autoAdvanceTasker.setOnClickListener {
binding.tasker.setOnClickListener {
try {
val pm = context.packageManager
context.startActivity(
@@ -95,12 +95,12 @@ class ChooseProviderFragment : Fragment(R.layout.choose_provider_fragment) {
binding.toolbar.setOnMenuItemClickListener { item ->
when (item.itemId) {
R.id.auto_advance_settings -> {
if (binding.chooseProviderDrawer.isDrawerOpen(GravityCompat.END)) {
binding.chooseProviderDrawer.closeDrawer(GravityCompat.END)
if (binding.drawer.isDrawerOpen(GravityCompat.END)) {
binding.drawer.closeDrawer(GravityCompat.END)
} else {
FirebaseAnalytics.getInstance(context).logEvent(
"auto_advance_open", null)
binding.chooseProviderDrawer.openDrawer(GravityCompat.END)
binding.drawer.openDrawer(GravityCompat.END)
}
true
}
@@ -123,23 +123,23 @@ class ChooseProviderFragment : Fragment(R.layout.choose_provider_fragment) {
}
}

binding.chooseProviderDrawer.setStatusBarBackgroundColor(Color.TRANSPARENT)
binding.chooseProviderDrawer.setScrimColor(Color.argb(68, 0, 0, 0))
binding.drawer.setStatusBarBackgroundColor(Color.TRANSPARENT)
binding.drawer.setScrimColor(Color.argb(68, 0, 0, 0))
currentProviderLiveData.observe(viewLifecycleOwner) { provider ->
val legacySelected = provider?.authority == LEGACY_AUTHORITY
binding.toolbar.menu.findItem(R.id.auto_advance_settings).isVisible = !legacySelected
binding.toolbar.menu.findItem(R.id.auto_advance_disabled).isVisible = legacySelected
if (legacySelected) {
binding.chooseProviderDrawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED,
binding.drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED,
GravityCompat.END)
} else {
binding.chooseProviderDrawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED,
binding.drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED,
GravityCompat.END)
}
}

val spacing = resources.getDimensionPixelSize(R.dimen.provider_padding)
binding.providerList.addItemDecoration(object : RecyclerView.ItemDecoration() {
binding.list.addItemDecoration(object : RecyclerView.ItemDecoration() {
override fun getItemOffsets(
outRect: Rect,
view: View,
@@ -150,7 +150,7 @@ class ChooseProviderFragment : Fragment(R.layout.choose_provider_fragment) {
}
})
val adapter = ProviderListAdapter()
binding.providerList.adapter = adapter
binding.list.adapter = adapter
viewModel.providers.observe(viewLifecycleOwner) {
adapter.submitList(it)
}
@@ -168,7 +168,7 @@ class ChooseProviderFragment : Fragment(R.layout.choose_provider_fragment) {
override fun onDismissed(transientBottomBar: Snackbar?, event: Int) {
if (isAdded && event != DISMISS_EVENT_CONSECUTIVE) {
// Reset the padding now that the SnackBar is dismissed
binding.providerList.updatePadding(bottom = resources.getDimensionPixelSize(
binding.list.updatePadding(bottom = resources.getDimensionPixelSize(
R.dimen.provider_padding))
}
}
@@ -179,7 +179,7 @@ class ChooseProviderFragment : Fragment(R.layout.choose_provider_fragment) {
show()
// Increase the padding when the SnackBar is shown to avoid
// overlapping the last element
binding.providerList.updatePadding(bottom = resources.getDimensionPixelSize(
binding.list.updatePadding(bottom = resources.getDimensionPixelSize(
R.dimen.provider_padding_with_snackbar))
}
} else {
@@ -325,14 +325,14 @@ class ChooseProviderFragment : Fragment(R.layout.choose_provider_fragment) {
setImage(providerInfo)

setSelected(providerInfo)
binding.providerSettings.setOnClickListener {
binding.settings.setOnClickListener {
FirebaseAnalytics.getInstance(requireContext()).logEvent(
"provider_settings_open", bundleOf(
FirebaseAnalytics.Param.ITEM_ID to authority,
FirebaseAnalytics.Param.ITEM_NAME to title))
launchProviderSettings(this)
}
binding.providerBrowse.setOnClickListener {
binding.browse.setOnClickListener {
FirebaseAnalytics.getInstance(requireContext()).logEvent(
"provider_browse_open", bundleOf(
FirebaseAnalytics.Param.ITEM_ID to authority,
@@ -344,33 +344,33 @@ class ChooseProviderFragment : Fragment(R.layout.choose_provider_fragment) {
}

fun setHeader(providerInfo: ProviderInfo) = providerInfo.run {
binding.providerIcon.setImageDrawable(icon)
binding.providerTitle.text = title
binding.icon.setImageDrawable(icon)
binding.title.text = title
}

fun setDescription(providerInfo: ProviderInfo) = providerInfo.run {
binding.providerDescription.text = description
binding.providerDescription.isGone = description.isNullOrEmpty()
binding.description.text = description
binding.description.isGone = description.isNullOrEmpty()
}

fun setImage(providerInfo: ProviderInfo) = providerInfo.run {
binding.providerArtwork.isVisible = currentArtworkUri != null
binding.artwork.isVisible = currentArtworkUri != null
if (currentArtworkUri != null) {
binding.providerArtwork.load(currentArtworkUri) {
binding.artwork.load(currentArtworkUri) {
lifecycle(viewLifecycleOwner)
listener(
onError = { _, _ -> binding.providerArtwork.isVisible = false },
onSuccess = { _, _ -> binding.providerArtwork.isVisible = true }
onError = { _, _ -> binding.artwork.isVisible = false },
onSuccess = { _, _ -> binding.artwork.isVisible = true }
)
}
}
}

fun setSelected(providerInfo: ProviderInfo) = providerInfo.run {
isSelected = selected
binding.providerSelected.isInvisible = !selected
binding.providerSettings.isVisible = selected && settingsActivity != null
binding.providerBrowse.isVisible = selected
binding.selected.isInvisible = !selected
binding.settings.isVisible = selected && settingsActivity != null
binding.browse.isVisible = selected
}
}

@@ -48,7 +48,7 @@ class IntroFragment : Fragment(R.layout.intro_fragment) {

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
binding = IntroFragmentBinding.bind(view)
binding.activateMuzeiButton.setOnClickListener {
binding.activateMuzei.setOnClickListener {
FirebaseAnalytics.getInstance(requireContext()).logEvent("activate", null)
try {
startActivity(Intent(WallpaperManager.ACTION_CHANGE_LIVE_WALLPAPER)
@@ -75,11 +75,11 @@ class IntroFragment : Fragment(R.layout.intro_fragment) {
add(R.id.animated_logo_fragment, logoFragment)
}

binding.activateMuzeiButton.alpha = 0f
binding.activateMuzei.alpha = 0f
logoFragment.onFillStarted = {
binding.activateMuzeiButton.animate().alpha(1f).setDuration(500)
binding.activateMuzei.animate().alpha(1f).setDuration(500)
}
binding.activateMuzeiButton.postDelayed({
binding.activateMuzei.postDelayed({
if (logoFragment.isAdded) {
logoFragment.start()
}

0 comments on commit ab87860

Please sign in to comment.
You can’t perform that action at this time.