Skip to content

Instantly share code, notes, and snippets.

View DaChelimo's full-sized avatar

Andrew Chelimo DaChelimo

  • Octagon Technologies
  • Nairobi, Kenya
  • 18:24 (UTC +03:00)
  • Instagram the_chelimo
View GitHub Profile
@DaChelimo
DaChelimo / system_utils.kt
Created July 15, 2021 15:36
A list of utility functions relating with the Android System UI
private fun setupEdgeToEdgeUI() {
WindowCompat.setDecorFitsSystemWindows(window, false)
ViewCompat.setOnApplyWindowInsetsListener(binding.overlayView) { v, insets ->
insets.getInsets(WindowInsetsCompat.Type.systemBars()).let { v.setPadding(it.left, it.top, it.right, it.bottom) }
WindowInsetsCompat.CONSUMED
}
}
@DaChelimo
DaChelimo / AndroidManiifest.xml
Last active April 29, 2021 07:42
Setting up API Keys
<application>
...
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="${facebook_app_id}" />
<activity
android:name="com.facebook.FacebookActivity"
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="@string/app_name" />
@DaChelimo
DaChelimo / exceptions.kt
Last active April 20, 2021 19:27
Codewars Throw without throwing
import java.util.*
import java.io.*
import java.nio.channels.FileChannel.MapMode
fun arrayIndexOutOfBound() {
val a = arrayOf<Int>()[-2]
}
fun negativeArraySize() {
val n = Array(-10, {0})
@DaChelimo
DaChelimo / AppConfig.kt
Last active April 21, 2021 06:23
Kotlin DSL Setup
//app level config constants
object AppConfig {
const val compileSdk = 30
const val minSdk = 21
const val targetSdk = 30
const val versionCode = 1
const val versionName = "1.0.0"
const val buildToolsVersion = "29.0.3"
const val androidTestInstrumentation = "androidx.test.runner.AndroidJUnitRunner"
@DaChelimo
DaChelimo / AndroidManifest.xml
Created April 2, 2021 08:29
How to create splash screen
<activity
android:name=".SplashActivity"
android:theme="@style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
@DaChelimo
DaChelimo / GradleDeps.txt
Last active March 23, 2021 10:35
List of libraries I commonly use (Testing, Networking, Coroutines and Glide libraries)
// Moshi
implementation "com.squareup.moshi:moshi:1.11.0"
implementation "com.squareup.moshi:moshi-kotlin:1.11.0"
kapt("com.squareup.moshi:moshi-kotlin-codegen:1.11.0")
// Retrofit
implementation "com.squareup.retrofit2:retrofit:2.9.0"
implementation "com.squareup.retrofit2:converter-moshi:2.6.0"
// Coroutines
@DaChelimo
DaChelimo / EspressoExt.kt
Created March 22, 2021 09:13
Extensions for Espresso Testing Library
fun setTextInTextView(value: String?): ViewAction {
return object : ViewAction {
override fun getConstraints(): Matcher<View> {
return allOf(isDisplayed(), isAssignableFrom(TextView::class.java))
}
override fun perform(uiController: UiController?, view: View) {
(view as TextView).text = value
}
@DaChelimo
DaChelimo / ViewModelFactoryExt.kt
Created December 3, 2020 08:14
A kotlin extension function that eliminates the need of writing ViewModelFactory
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
/**
* An extension function that removes the need to write ViewModelFactory by creating a factory based on ViewModel arguments
*
* Example:
* private val viewModel: DailyForecastViewModel by DailyForecastViewModel(requireContext()).createViewModel(this)
@DaChelimo
DaChelimo / sdf_patterns.html
Last active November 11, 2020 10:33
Patterns for SimpleDateFormat for Java & Kotlin
### SimpleDateFormat Patterns
*Year*
// yyyy or YYYY - Year
*Month*
MM - Month of the year (eg. 11)
MMM - Month of the year (eg. Nov)
@DaChelimo
DaChelimo / list-of-all-countries.kt
Created October 22, 2020 11:52
A kotlin list containing all the countries in the world.
val listOfAllCountries = arrayListOf("United States", "Canada", "Afghanistan", "Albania", "Algeria", "American Samoa", "Andorra", "Angola", "Anguilla", "Antarctica", "Antigua and/or Barbuda", "Argentina", "Armenia", "Aruba", "Australia", "Austria", "Azerbaijan", "Bahamas", "Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium", "Belize", "Benin", "Bermuda", "Bhutan", "Bolivia", "Bosnia and Herzegovina", "Botswana", "Bouvet Island", "Brazil", "British Indian Ocean Territory", "Brunei Darussalam", "Bulgaria", "Burkina Faso", "Burundi", "Cambodia", "Cameroon", "Cape Verde", "Cayman Islands", "Central African Republic", "Chad", "Chile", "China", "Christmas Island", "Cocos (Keeling) Islands", "Colombia", "Comoros", "Congo", "Cook Islands", "Costa Rica", "Croatia (Hrvatska)", "Cuba", "Cyprus", "Czech Republic", "Denmark", "Djibouti", "Dominica", "Dominican Republic", "East Timor", "Ecudaor", "Egypt", "El Salvador", "Equatorial Guinea", "Eritrea", "Estonia", "Ethiopia", "Falkland Islands (Malvinas)", "Faroe Islan