Skip to content

Instantly share code, notes, and snippets.

Avatar

Paulo Pereira pauloaapereira

View GitHub Profile
@pauloaapereira
pauloaapereira / example1.kt
Created Jul 23, 2021
Declarative UI Brief Analysis
View example1.kt
Column(
modifier = Modifier.fillMaxSize(),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center
) {
Text(
text = "Text1",
color = Color.Black,
fontSize = 21.sp
)
@pauloaapereira
pauloaapereira / example1.xml
Created Jul 23, 2021
Declarative UI Brief Analysis
View example1.xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
@pauloaapereira
pauloaapereira / declarative_2.kt
Created May 22, 2021
Declarative UI Analysis
View declarative_2.kt
val listOfNumbers = listOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
val listOfEvenNumbers = listOfNumbers.filter { number -> number % 2 == 0 }
println(listOfEvenNumbers)
@pauloaapereira
pauloaapereira / declarative_1.kt
Created May 22, 2021
Declarative UI Analysis
View declarative_1.kt
val listOfNumbers = listOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
val listOfEvenNumbers = mutableListOf<Int>()
for (number in listOfNumbers) {
if (number % 2 == 0) {
listOfEvenNumbers.add(number)
}
}
println(listOfEvenNumbers)
@pauloaapereira
pauloaapereira / solid_6.kt
Created May 16, 2021
Android SOLID Error Handling
View solid_6.kt
class ErrorFragment : Fragment() {
private var _binding: FragmentErrorBinding? = null
private val binding get() = _binding!!
companion object {
private const val ERROR_KEY = "errorKey"
fun newError(error: ErrorView): ErrorFragment {
return ErrorFragment().apply {
@pauloaapereira
pauloaapereira / solid_5.kt
Created May 16, 2021
Android SOLID Error Handling
View solid_5.kt
@Parcelize
class ServerError : ErrorView {
override fun setupView(binding: FragmentErrorBinding) {
binding.apply {
errorTitle.setText(R.string.key_error)
errorDescription.setText(R.string.key_server_error)
errorImage.setImageResource(R.drawable.ic_server)
}
}
@pauloaapereira
pauloaapereira / solid_4.kt
Last active May 16, 2021
Android SOLID Error Handling
View solid_4.kt
@Parcelize
class InternetError(private val showWarning: Boolean) : ErrorViewWithWarning {
@IgnoredOnParcel
override var warning: Snackbar? = null
override fun setupView(binding: FragmentErrorBinding) {
binding.apply {
errorTitle.setText(R.string.key_error)
errorDescription.setText(R.string.key_internet_error)
@pauloaapereira
pauloaapereira / solid_3.kt
Created May 16, 2021
Android SOLID Error Handling
View solid_3.kt
@Parcelize
class NotFoundError : ErrorView {
override fun setupView(binding: FragmentErrorBinding) {
binding.apply {
errorTitle.setText(R.string.key_error)
errorDescription.setText(R.string.key_not_found_error)
errorImage.setImageResource(R.drawable.ic_not_found)
}
}
}
@pauloaapereira
pauloaapereira / solid_2.kt
Created May 16, 2021
Android SOLID Error Handling
View solid_2.kt
interface ErrorViewWithWarning : ErrorView {
var warning: Snackbar?
fun showWarning(root: View)
fun dismissWarning()
}
@pauloaapereira
pauloaapereira / solid_1.kt
Created May 16, 2021
Android SOLID Error Handling
View solid_1.kt
interface ErrorView : Parcelable {
fun setupView(binding: FragmentErrorBinding)
}