Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplified some code #693

Merged
merged 2 commits into from Sep 23, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -128,12 +128,14 @@ class EffectsFragment : Fragment(R.layout.effects_fragment) {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
binding = EffectsFragmentBinding.bind(view)
if (requireActivity().isPreviewMode) {
binding.toolbar.setNavigationIcon(R.drawable.ic_ab_done)
binding.toolbar.navigationContentDescription = getString(R.string.done)
binding.toolbar.setNavigationOnClickListener {
requireActivity().run {
setResult(Activity.RESULT_OK)
finish()
with(binding.toolbar) {
setNavigationIcon(R.drawable.ic_ab_done)
navigationContentDescription = getString(R.string.done)
setNavigationOnClickListener {
requireActivity().run {
setResult(Activity.RESULT_OK)
finish()
}
}
}
}
Expand Down Expand Up @@ -189,15 +191,18 @@ class EffectsFragment : Fragment(R.layout.effects_fragment) {
effectsLinked: Boolean = Prefs.getSharedPreferences(requireContext())
.getBoolean(Prefs.PREF_LINK_EFFECTS, false)
) {
val menuItem = binding.toolbar.menu.findItem(R.id.action_link_effects)
menuItem.setIcon(if (effectsLinked)
R.drawable.ic_action_link_effects
else
R.drawable.ic_action_link_effects_off)
menuItem.title = if (effectsLinked)
getString(R.string.action_link_effects)
else
getString(R.string.action_link_effects_off)
binding.toolbar.menu.findItem(R.id.action_link_effects).apply {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use with(binding.toolbar.menu.findItem(R.id.action_link_effects))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

title = when (effectsLinked) {
true -> {
setIcon(R.drawable.ic_action_link_effects)
getString(R.string.action_link_effects)
}
false -> {
setIcon(R.drawable.ic_action_link_effects_off)
getString(R.string.action_link_effects_off)
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switch this back to the previous setup:

  1. when (boolean) can always be more succinctly written as an if statement
  2. Don't setIcon as a side effect of setting the title. Keep this as two separate statements. Yes, the two if statements are intentional.

}
}

override fun onStop() {
Expand Down