Last active
August 30, 2018 17:08
-
-
Save Atternatt/33ddd8bf84eeafb7a324a34d8a9c340d to your computer and use it in GitHub Desktop.
Bundle Delegate
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
class UsageFragment : Fragment() { | |
private val numberWhatever by Argument("ARG_PROPERTY", 0) | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
//same behaviour tham BundleParam but withArguments in fragments | |
print("$numberWhatever!") | |
} | |
} |
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
class UsageActivity : Activity() { | |
private val numberWhatever by BundleParam("EXTRA_PROPERTY", 0) | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
//here we will get the property from the activity intent thanks to delegating it | |
print("$numberWhatever!") | |
} | |
} |
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
@Singleton | |
class UsagePrefs(context: Context) { | |
//we can observe changes of properties to update others | |
var userName: String by PrefParam(context = context, default = "") { lastUpdate = today.time} | |
private var lastUpdate: Long by PrefParam(context = context, default = 0L) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment