-
-
Notifications
You must be signed in to change notification settings - Fork 444
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: The Activity now notifies when the drawer status has changed (#…
…4560) * The Activity now notifies when the drawer status has changed * Drawer status changes: now with multiple listeners
- Loading branch information
Showing
4 changed files
with
94 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
...openfoodfacts/github/scrachx/openfood/features/shared/NavigationWithDrawerBaseFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package openfoodfacts.github.scrachx.openfood.features.shared | ||
|
||
import android.content.Context | ||
|
||
/** | ||
* A custom [NavigationBaseFragment] that can be notified of navigation drawer events. | ||
* The host (= Activity) must contain a Navigation Drawer and implements [NavigationDrawerHost] | ||
*/ | ||
abstract class NavigationWithDrawerBaseFragment : NavigationBaseFragment(), OnNavigationDrawerStatusChanged { | ||
|
||
override fun onAttach(context: Context) { | ||
super.onAttach(context) | ||
|
||
if (context is NavigationDrawerHost) { | ||
context.addOnDrawerStatusChanged(this) | ||
} | ||
} | ||
|
||
override fun onDetach() { | ||
if (requireContext() is NavigationDrawerHost) { | ||
(context as NavigationDrawerHost).removeOnDrawerStatusChanged(this) | ||
} | ||
|
||
super.onDetach() | ||
} | ||
|
||
override fun onDrawerOpened() { | ||
// No implementation by default | ||
} | ||
|
||
override fun onDrawerClosed() { | ||
// No implementation by default | ||
} | ||
} | ||
|
||
/** | ||
* Interface to implement for an Activity with a NavigationDrawer | ||
*/ | ||
interface NavigationDrawerHost { | ||
fun addOnDrawerStatusChanged(onDrawerStatusChanged: OnNavigationDrawerStatusChanged) | ||
fun removeOnDrawerStatusChanged(onDrawerStatusChanged: OnNavigationDrawerStatusChanged) | ||
} | ||
|
||
/** | ||
* Interface to notify when the status of a NavigationDrawer has changed (opened/closed) | ||
*/ | ||
interface OnNavigationDrawerStatusChanged { | ||
fun onDrawerOpened() | ||
fun onDrawerClosed() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters