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 TextView errorMessage; | |
… | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
errorMessage = (TextView) findViewById(R.id.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
private lateinit var errorMessage: TextView | |
… | |
override fun onCreate(savedInstanceState: Bundle?) { | |
… | |
errorMessage = findViewById(R.id.error_message) as TextView | |
} |
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.getViewById(@IdRes id: Int): T { | |
return findViewById(id) as T | |
} |
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 lateinit var errorMessage: TextView | |
… | |
override fun onCreate(savedInstanceState: Bundle?) { | |
… | |
errorMessage = getViewById(R.id.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
private val errorMessage: TextView by lazy { getViewById(R.id.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
class ViewFinderDelegate<T : View> : ReadOnlyProperty<Activity, T> { | |
private object EMPTY | |
private val id: Int | |
private var view: Any? = Empty | |
constructor(@IdRes id: Int) { | |
this.id = id | |
} | |
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 ViewFinderDelegate(R.id.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 <T : View> Activity.view(IdRes id: Int): ReadOnlyProperty<Activity, T> | |
= ViewFinderDelegate(id) |
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
interface ContextProvdier { | |
fun provideContext(): Context | |
} | |
class OwnActivity : AppCompatActivity(), ContextProvider { | |
fun provideContext() = this | |
} | |
class OwnFragment : Fragment(), ContextProvider { | |
fun provideContext() = context |
OlderNewer