Skip to content

Instantly share code, notes, and snippets.

⌨️
Coding

Andrew Lord lordcodes

⌨️
Coding
Block or report user

Report or block lordcodes

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@lordcodes
lordcodes / PlanningActivity.kt
Created Jan 30, 2019
Code for article "Using lazy in Kotlin to bind Android views"
View PlanningActivity.kt
class PlanningActivity : AppCompatActivity() {
private val planningText by bindView<TextView>(R.id.planning_text)
// or
private val planningText: TextView by bindView(R.id.planning_text)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_planning)
planningText.text = "Hello!"
@lordcodes
lordcodes / PlanningActivity.kt
Created Jan 30, 2019
Code for article "Using lazy in Kotlin to bind Android views"
View PlanningActivity.kt
fun <ViewT : View> Activity.bindView(@IdRes idRes: Int): Lazy<ViewT> {
return lazyUnsychronized {
findViewById<ViewT>(idRes)
}
}
@lordcodes
lordcodes / PlanningActivity.kt
Created Jan 30, 2019
Code for article "Using lazy in Kotlin to bind Android views"
View PlanningActivity.kt
// LazyExt.kt
fun <T> lazyUnsychronized(initializer: () -> T): Lazy<T> =
lazy(LazyThreadSafetyMode.NONE, initializer)
// PlanningActivity.kt
private val planningText by lazyUnsychronized {
findViewById<TextView>(R.id.planning_text)
}
@lordcodes
lordcodes / PlanningActivity.kt
Created Jan 30, 2019
Code for article "Using lazy in Kotlin to bind Android views"
View PlanningActivity.kt
private val planningText by lazy(LazyThreadSafetyMode.NONE) {
findViewById<TextView>(R.id.planning_text)
}
@lordcodes
lordcodes / PlanningActivity.kt
Created Jan 30, 2019
Code for article "Using lazy in Kotlin to bind Android views"
View PlanningActivity.kt
private val planningText by lazy {
findViewById<TextView>(R.id.planning_text)
}
@lordcodes
lordcodes / PlanningActivity.kt
Created Jan 30, 2019
Code for article "Using lazy in Kotlin to bind Android views"
View PlanningActivity.kt
import kotlinx.android.synthetic.main.activity_planning.*
class PlanningActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_planning)
planning_text.text = "Hello"
}
}
@lordcodes
lordcodes / PlanningActivity.java
Created Jan 30, 2019
Code for article "Using lazy in Kotlin to bind Android views"
View PlanningActivity.java
public class PlanningActivity extends AppCompatActivity {
@BindView(R.id.planning_text) TextView planningText;
@BindView(R.id.app_icon) ImageView appIcon;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_planning);
ButterKnife.bind(this);
@lordcodes
lordcodes / PlanningActivity.java
Created Jan 30, 2019
Code for article "Using lazy in Kotlin to bind Android views"
View PlanningActivity.java
public class PlanningActivity extends AppCompatActivity {
private TextView planningText;
private ImageView appIcon;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_planning);
// Before: Needed to cast
@lordcodes
lordcodes / config.yml
Created Jan 24, 2019
Code for article "Adding Continuous Integration to your Android project"
View config.yml
version: 2.0
jobs:
build:
working_directory: ~/workspace
docker:
- image: circleci/android:api-28
steps:
- checkout
@lordcodes
lordcodes / ci-setup.sh
Created Jan 22, 2019
Android Circle CI config involving workflows, caching and sharing the workspace between steps in workflow.
View ci-setup.sh
#!/usr/bin/env bash
# Accept licenses
${ANDROID_HOME}/tools/bin/sdkmanager --licenses
# Install dependencies
./gradlew androidDependencies || true
You can’t perform that action at this time.