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 OwnFragment : Fragment() { | |
val errorMessage by string(R.string.error_message) | |
} |
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
fun View.string(@StringRes id: Int): ReadOnlyProperty<View, String> | |
= StringDelegate(contextProvider, id) | |
fun Activity.string(@StringRes id: Int): ReadOnlyProperty<Activity, String> | |
= StringDelegate(contextProvider, id) | |
fun Fragment.string(@StringRes id: Int): ReadOnlyProperty<Fragment, String> | |
= StringDelegate(contextProvider, id) | |
private class StringDelegate : ReadOnlyProperty<Any, Stirng> |
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 StringDelegate : ReadOnlyPropery<Any, String> { | |
private val stringRes: Int | |
private val contextProvider: () -> Context | |
private var string: String? = null | |
constructor(contextProvider: () -> Context, @StringRes stringRes: Int) { | |
this.contextProvider = contextProvider | |
this.stringRes = stringRes | |
} |
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
val View.contextProvider: () -> Context | |
get() = this::getContext | |
val Activity.contextProvider: () -> Context | |
get() = { this } | |
val Fragment.contextProvider: () -> Context | |
get() = this::getContext | |
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 OwnFragment : Fragment(), ContextProvider { | |
val errorMessage by string(R.string.error_message) | |
overrider fun provideContext() = context | |
} |
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
fun ContextProvider.string(@StringRes stringRes: Int): ReadOnlyProperty<ContextProvider, Stirng> | |
= StringDelegate(stringRes) |
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 StringDelegate : ReadOnlyPropery<ContextProvider, String> { | |
private val stringRes: Int | |
private var string: String? = null | |
constructor(@StringRes stringRes: Int) { | |
this.stringRes = stringRes | |
} | |
override fun getValue(ref: ContextProvider, property: KProperty<*>): String { |
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
interface ContextProvdier { | |
fun provideContext(): Context | |
} | |
class OwnActivity : AppCompatActivity(), ContextProvider { | |
fun provideContext() = this | |
} | |
class OwnFragment : Fragment(), ContextProvider { | |
fun provideContext() = context |
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
private val errorMessage: TextView by view(R.id.errorMessage) |
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
fun <T : View> Activity.view(IdRes id: Int): ReadOnlyProperty<Activity, T> | |
= ViewFinderDelegate(id) |
NewerOlder