Created
August 8, 2022 09:00
-
-
Save ravisorathiya/f8309560e51d2cd8729b8146286f7f9d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import android.app.Application | |
import android.content.Context | |
import androidx.room.Room | |
import com.google.gson.Gson | |
import com.google.gson.GsonBuilder | |
import com.huawei.hms.mlsdk.MLAnalyzerFactory | |
import com.huawei.hms.mlsdk.imgseg.MLImageSegmentationAnalyzer | |
import com.huawei.hms.mlsdk.imgseg.MLImageSegmentationScene | |
import com.huawei.hms.mlsdk.imgseg.MLImageSegmentationSetting | |
import com.wondersoftware.mastapp.MastApplication | |
import com.wondersoftware.mastapp.business.datasource.cache.AppDatabase | |
import com.wondersoftware.mastapp.business.datasource.data_store.AppDataStore | |
import com.wondersoftware.mastapp.business.datasource.data_store.AppDataStoreManager | |
import com.wondersoftware.mastapp.utills.BASE_URL | |
import com.wondersoftware.mastapp.utills.DATABASE_NAME | |
import dagger.Module | |
import dagger.Provides | |
import dagger.hilt.InstallIn | |
import dagger.hilt.android.qualifiers.ApplicationContext | |
import dagger.hilt.components.SingletonComponent | |
import okhttp3.OkHttpClient | |
import retrofit2.Retrofit | |
import retrofit2.converter.gson.GsonConverterFactory | |
import java.util.concurrent.TimeUnit | |
import javax.inject.Singleton | |
@Module | |
@InstallIn(SingletonComponent::class) | |
object AppModule { | |
@Provides | |
fun provideApplication(@ApplicationContext context: Context): MastApplication = | |
context as MastApplication | |
@Singleton | |
@Provides | |
fun provideGsonBuilder(): Gson { | |
return GsonBuilder() | |
.create() | |
} | |
@Provides | |
@Singleton | |
fun provideHttpClient(): OkHttpClient { | |
return OkHttpClient.Builder() | |
.readTimeout(15, TimeUnit.SECONDS) | |
.connectTimeout(15, TimeUnit.SECONDS) | |
.build() | |
} | |
@Provides | |
@Singleton | |
fun provideRetrofit(okHttpClient: OkHttpClient): Retrofit = | |
Retrofit.Builder() | |
.baseUrl(BASE_URL) | |
.client(okHttpClient) | |
.addConverterFactory(GsonConverterFactory.create()) | |
.build() | |
@Singleton | |
@Provides | |
fun provideAppDb(app: Application): AppDatabase { | |
return Room | |
.databaseBuilder(app, AppDatabase::class.java, DATABASE_NAME) | |
.fallbackToDestructiveMigration() | |
.build() | |
} | |
@Provides | |
@Singleton | |
fun provideDataStore(mastApplication: MastApplication): AppDataStore = | |
AppDataStoreManager(mastApplication) | |
@Provides | |
@Singleton | |
fun provideImageAnalyzer(): MLImageSegmentationAnalyzer { | |
val analyzerSetting = MLImageSegmentationSetting.Factory() | |
.setExact(true) | |
.setAnalyzerType(MLImageSegmentationSetting.BODY_SEG) | |
.setScene(MLImageSegmentationScene.FOREGROUND_ONLY) | |
.create() | |
val analyzer: MLImageSegmentationAnalyzer by lazy { | |
MLAnalyzerFactory.getInstance().getImageSegmentationAnalyzer(analyzerSetting) | |
} | |
return analyzer | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment