Skip to content

Commit 4e3ceb3

Browse files
committed
Merge branch 'fix/fragment-gone' into 'master'
Prevent crash when trying to set Activity (sub)title from detached fragment See merge request fmasa/wfrp-master!112
2 parents 661c04a + e5643bc commit 4e3ceb3

File tree

1 file changed

+2
-10
lines changed

1 file changed

+2
-10
lines changed

app/src/main/java/cz/muni/fi/rpg/ui/common/BaseFragment.kt

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,14 @@ abstract class BaseFragment(@LayoutRes contentLayoutId: Int) : Fragment(contentL
99
* Set title of parent activity's action bar
1010
*/
1111
protected fun setTitle(title: String) {
12-
val activity = requireActivity()
13-
14-
if (activity is AppCompatActivity) {
15-
activity.supportActionBar?.title = title
16-
}
12+
activity?.let { (activity as AppCompatActivity).supportActionBar?.title = title }
1713
}
1814

1915
/**
2016
* Set subtitle of parent activity's action bar
2117
* Note: This is not really optimal way to do this, but I did not found another one
2218
*/
2319
protected fun setSubtitle(subtitle: String) {
24-
val activity = requireActivity()
25-
26-
if (activity is AppCompatActivity) {
27-
activity.supportActionBar?.subtitle = subtitle
28-
}
20+
activity?.let { (activity as AppCompatActivity).supportActionBar?.subtitle = subtitle }
2921
}
3022
}

0 commit comments

Comments
 (0)