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 FragmentAutoClearedValueBinding<T : ViewBinding>( | |
val binder: (View) -> T | |
) : ReadOnlyProperty<Fragment, T>, | |
DefaultLifecycleObserver { | |
private var value: T? = null | |
override fun onDestroy(owner: LifecycleOwner) { | |
value = null // Clear reference. | |
} |
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 MainActivity : AppCompatActivity() { | |
private val binding by viewBinding(ActivityMainBinding::inflate) | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(binding.root) | |
} | |
} |
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
<?xml version="1.0" encoding="utf-8"?> | |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content"> | |
<include | |
android:id="@+id/mergeLayout" | |
layout="@layout/layout_merge" /> | |
</LinearLayout> |
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
<merge xmlns:android="http://schemas.android.com/apk/res/android"> | |
<TextView | |
android:id="@+id/titleLbl" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" /> | |
</merge> |
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
<?xml version="1.0" encoding="utf-8"?> | |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content"> | |
<include layout="@layout/layout_merge" /> | |
</LinearLayout> |
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 MainActivity : AppCompatActivity() { | |
private lateinit var binding: ActivityMainBinding | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
binding = ActivityMainBinding.inflate(layoutInflater) | |
setContentView(binding.root) | |
} |
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
// In your buildSrc folder | |
sealed class BuildType(val secret: String) { | |
object DebugBuildType : BuildType(secret = "sword") | |
object ReleaseBuildType : BuildType(secret = "shield") | |
} |
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
// Our custom task inside buildSrc folder | |
open class PingUrlTask : DefaultTask() { | |
@Input | |
lateinit var url: String | |
@TaskAction | |
fun updateTranslations() { | |
println("Begin task") |
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
// For flavors usage | |
fun BaseFlavor.buildConfigBoolean(name: String, value: Boolean) = | |
buildConfigField("Boolean", name, value.toString()) | |
fun BaseFlavor.buildConfigString(name: String, value: String) = | |
buildConfigField("String", name, "\"$value\"") | |
// For build types usage | |
fun BuildType.buildConfigString(name: String, value: String) = | |
buildConfigField("String", name, "\"$value\"") |
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 PluginDependenciesSpec.androidApp(): PluginDependencySpec = | |
id("com.android.application") | |
fun PluginDependenciesSpec.androidLibrary(): PluginDependencySpec = | |
id("com.android.library") | |
fun PluginDependenciesSpec.kotlinAndroid(): PluginDependencySpec = | |
kotlin("android") | |
fun PluginDependenciesSpec.kotlinAndroidExt(): PluginDependencySpec = |
NewerOlder