Skip to content

Instantly share code, notes, and snippets.

Avatar
🇮🇳

Saurabh Pant aqua30

🇮🇳
View GitHub Profile
View MemberListViewHolder_after.java
class MemberListViewHolder(mContext: Context, itemView:View):RecyclerView.ViewHolder(itemView){
lateinit var userPreference: Preference<LoginResponse>
init{
super.itemView
ButterKnife.bind(this,itemView)
inject(context)
}
View UserListViewHolderEntryPoint.kt
@InstallIn(ActivityComponent::class)
@EntryPoint
interface UserListViewHolderEntryPoint {
var loginPref: Preference<LoginResponse>
}
View MemberListViewHolder_before.java
class MemberListViewHolder(itemView:View):RecyclerView.ViewHolder(itemView){
@Inject
lateinit var userPreference: Preference<LoginResponse>
init{
super.itemView
ButterKnife.bind(this,itemView)
SheroesApplication.getAppComponent(itemView.context).inject(this)
if(null!=userPreference&&userPreference.isSet&&null!=userPreference.get().userSummary){
mUserId=userPreference.get().userSummary.userId
View migration_build.gradle
defaultConfig {
// this will prevent the excetion for InstallIn check on injected modules for time being
javaCompileOptions.annotationProcessorOptions.arguments['dagger.hilt.disableModulesHaveInstallInCheck'] = 'true'
}
View SheroesAppComponent_1.java
@InstallIn(SingletonComponent.class)
@Module(
includes = {
SheroesAppModule.class, VMModule.class, UseCaseModule.class,
ApiModule.class, RepositoryModule.class, AnalyticModule.class
}
)
interface AppModuleComponent{}
@InstallIn(SingletonComponent.class)
View SheroesApplication.java
public class SheroesApplication extends Application {
SheroesAppComponent mSheroesAppComponent;
@Override
public void onCreate() {
super.onCreate();
mSheroesAppComponent = DaggerSheroesAppComponent.builder()
.sheroesAppModule(
new SheroesAppModule(this, this)
View SheroesAppComponent.java
@Singleton
@Component(
modules = {
SheroesAppModule.class, VMModule.class, UseCaseModule.class,
ApiModule.class, RepositoryModule.class, AnalyticModule.class
}
)
public interface SheroesAppComponent {
void inject(HomeActivity homeActivity);
View RetrofitHelper.kt
object RetrofitHelper {
/**
* as dependency injection is not used in this project for brevity,
* static object initialization is done for demo purpose.
*
* @param url: Base url for apis
* @return TestApis: Instance of the test api retrofit interface
**/
fun testApiInstance(url: String): TestApis {
View status_pages_status_based.kt
install(StatusPages) {
exception<Throwable> { ... }
status(
// any number of status codes can be mentioned
HttpStatusCode.InternalServerError,
HttpStatusCode.BadGateway,
) { call, statusCode ->
when(statusCode) {
View status_pages_exception_based.kt
install(StatusPages) {
exception<Throwable> { call, throwable ->
when(throwable) {
is ValidationException -> {
call.respond(
HttpStatusCode.BadRequest,
ExceptionResponse("${throwable.message}", HttpStatusCode.BadRequest.value)
)
}
is ParsingException -> {