Skip to content

Commit

Permalink
Use weak self
Browse files Browse the repository at this point in the history
  • Loading branch information
levinli303 committed Dec 29, 2022
1 parent 5eae423 commit f0660da
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions app/src/main/java/space/celestia/mobilecelestia/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -916,9 +916,9 @@ class MainActivity : AppCompatActivity(R.layout.activity_main),
}

private fun showToolbar() {
val ref = WeakReference(this)
val weakSelf = WeakReference(this)
hideOverlay(true) {
val drawerLayout = ref.get()?.drawerLayout ?: return@hideOverlay
val drawerLayout = weakSelf.get()?.drawerLayout ?: return@hideOverlay
drawerLayout.openDrawer(GravityCompat.END, true)
}
}
Expand Down Expand Up @@ -1922,8 +1922,9 @@ class MainActivity : AppCompatActivity(R.layout.activity_main),

// Utilities
private fun showBottomSheetFragment(fragment: Fragment) {
val weakSelf = WeakReference(this)
hideOverlay(true) {
showBottomSheetFragmentDirect(fragment)
weakSelf.get()?.showBottomSheetFragmentDirect(fragment)
}
}

Expand All @@ -1938,8 +1939,9 @@ class MainActivity : AppCompatActivity(R.layout.activity_main),
}

private fun showToolbarFragment(fragment: Fragment) {
val weakSelf = WeakReference(this)
hideOverlay(true) {
showToolbarFragmentDirect(fragment)
weakSelf.get()?.showToolbarFragmentDirect(fragment)
}
}

Expand Down

0 comments on commit f0660da

Please sign in to comment.