Skip to content

Instantly share code, notes, and snippets.

Avatar
👓
Doing Android stuff

Mitch Tabian mitchtabian

👓
Doing Android stuff
View GitHub Profile
View ListAdapterTemplate.kt
#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME}#end
import androidx.recyclerview.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.AsyncListDiffer
import androidx.recyclerview.widget.DiffUtil
#parse("File Header.java")
@mitchtabian
mitchtabian / ComplexMethod_INVALID.kt
Last active Aug 2, 2020
Basics #6: Hilt Modules, Binds and Provides
View ComplexMethod_INVALID.kt
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.fragment.app.Fragment
import com.google.gson.Gson
import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
import dagger.hilt.android.AndroidEntryPoint
import dagger.hilt.android.components.ApplicationComponent
import javax.inject.Inject
View Dependencies.kt
val google_maps = "17.0.0"
val google_maps_ktx = "2.1.1"
val google_maps_utils = "2.0.3"
val google_maps_utils_ktx = "1.7.0"
val google_maps = "com.google.android.gms:play-services-maps:${Versions.google_maps}"
val google_maps_ktx = "com.google.maps.android:maps-ktx:${Versions.google_maps_ktx}"
val google_maps_utils = "com.google.maps.android:android-maps-utils:${Versions.google_maps_utils}"
val google_maps_utils_ktx = "com.google.maps.android:maps-utils-ktx:${Versions.google_maps_utils_ktx}"
View MainActivity.java
private boolean checkMapServices(){
if(isServicesOK()){
if(isMapsEnabled()){
return true;
}
}
return false;
}
private void buildAlertMessageNoGps() {
View AndroidManifest.xml
<!-- **NOTE** This must be in /debug/ -->
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.codingwithmitch.daggerhiltplayground">
<application>
<activity
android:name="com.codingwithmitch.daggerhiltplayground.HiltTestActivity"
android:exported="false" />
</application>
View HiltExt.kt
import android.content.ComponentName
import android.content.Intent
import android.os.Bundle
import androidx.annotation.StyleRes
import androidx.core.util.Preconditions
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentFactory
import androidx.fragment.app.testing.FragmentScenario.EmptyFragmentActivity
import androidx.test.core.app.ActivityScenario
import androidx.test.core.app.ApplicationProvider
View activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
>
@mitchtabian
mitchtabian / MainActivity.kt
Last active Jul 6, 2020
Basics #2: Field injecting a class with no dependencies. You own that class.
View MainActivity.kt
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject
@AndroidEntryPoint
class MainActivity : AppCompatActivity() {
@Inject
lateinit var someClass: SomeClass
@mitchtabian
mitchtabian / MyApplication.kt
Last active Jul 6, 2020
Basics #1: Preparing to use Hilt
View MyApplication.kt
import android.app.Application
import dagger.hilt.android.HiltAndroidApp
@HiltAndroidApp
class MyApplication : Application(){
override fun onCreate() {
super.onCreate()
}
}
@mitchtabian
mitchtabian / MainActivity.kt
Created Jul 3, 2020
Basics #7: Multiple Bindings of the same type
View MainActivity.kt
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.AndroidEntryPoint
import dagger.hilt.android.components.ApplicationComponent
import javax.inject.Inject
import javax.inject.Qualifier
import javax.inject.Singleton
You can’t perform that action at this time.