-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from YuanLiou/feature/hilt
Feature/hilt
- Loading branch information
Showing
45 changed files
with
529 additions
and
416 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
4 changes: 2 additions & 2 deletions
4
app/src/main/java/tw/com/louis383/coffeefinder/BaseFragment.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
package tw.com.louis383.coffeefinder | ||
|
||
import androidx.fragment.app.Fragment | ||
import tw.com.louis383.coffeefinder.model.entity.Shop | ||
import tw.com.louis383.coffeefinder.model.domain.model.CoffeeShop | ||
|
||
/** | ||
* Created by louis383 on 2017/2/26. | ||
*/ | ||
abstract class BaseFragment : Fragment() { | ||
abstract fun prepareCoffeeShops(coffeeShops: List<Shop>) | ||
abstract fun prepareCoffeeShops(coffeeShops: List<CoffeeShop>) | ||
} |
This file contains 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
This file contains 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
6 changes: 0 additions & 6 deletions
6
app/src/main/java/tw/com/louis383/coffeefinder/di/ApplicationContext.kt
This file was deleted.
Oops, something went wrong.
22 changes: 0 additions & 22 deletions
22
app/src/main/java/tw/com/louis383/coffeefinder/di/components/AppComponent.kt
This file was deleted.
Oops, something went wrong.
51 changes: 10 additions & 41 deletions
51
app/src/main/java/tw/com/louis383/coffeefinder/di/module/AppModule.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,25 @@ | ||
package tw.com.louis383.coffeefinder.di.module | ||
|
||
import android.app.Application | ||
import android.content.Context | ||
import android.content.SharedPreferences | ||
import dagger.Module | ||
import dagger.Provides | ||
import tw.com.louis383.coffeefinder.di.ApplicationContext | ||
import tw.com.louis383.coffeefinder.model.* | ||
import javax.inject.Singleton | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.android.qualifiers.ApplicationContext | ||
import dagger.hilt.components.SingletonComponent | ||
|
||
/** | ||
* Created by louis383 on 2017/2/22. | ||
*/ | ||
@InstallIn(SingletonComponent::class) | ||
@Module | ||
class AppModule(private val application: Application) { | ||
object AppModule { | ||
|
||
@ApplicationContext | ||
@Provides | ||
fun provideApplicationContext(): Context { | ||
return application | ||
} | ||
|
||
@Provides | ||
@Singleton | ||
fun provideCoffeeAPI(): CoffeeTripAPI { | ||
return CoffeeTripAPI() | ||
} | ||
|
||
@Provides | ||
@Singleton | ||
fun provideCoffeeShopListManager(coffeeTripAPI: CoffeeTripAPI): CoffeeShopListManager { | ||
return CoffeeShopListManager(coffeeTripAPI) | ||
} | ||
|
||
@Provides | ||
@Singleton | ||
fun providePreferenceManager( | ||
@ApplicationContext context: Context | ||
): PreferenceManager { | ||
return PreferenceManager(context) | ||
} | ||
|
||
@Provides | ||
fun provideConnectivityChecker( | ||
@ApplicationContext context: Context | ||
): ConnectivityChecker { | ||
return ConnectivityChecker(context) | ||
} | ||
|
||
@Provides | ||
fun providePermissionChecker( | ||
fun provideDefaultPreference( | ||
@ApplicationContext context: Context | ||
): PermissionChecker { | ||
return PermissionChecker(context) | ||
): SharedPreferences { | ||
val preferenceName = "coffeeTrip_preference" | ||
return context.getSharedPreferences(preferenceName, Context.MODE_PRIVATE) | ||
} | ||
} |
This file contains 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
88 changes: 88 additions & 0 deletions
88
app/src/main/java/tw/com/louis383/coffeefinder/di/module/NetworkModule.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package tw.com.louis383.coffeefinder.di.module | ||
|
||
import android.content.Context | ||
import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory | ||
import dagger.Lazy | ||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.android.qualifiers.ApplicationContext | ||
import dagger.hilt.components.SingletonComponent | ||
import kotlinx.serialization.ExperimentalSerializationApi | ||
import kotlinx.serialization.json.Json | ||
import okhttp3.MediaType | ||
import okhttp3.OkHttpClient | ||
import okhttp3.logging.HttpLoggingInterceptor | ||
import retrofit2.Retrofit | ||
import tw.com.louis383.coffeefinder.BuildConfig | ||
import tw.com.louis383.coffeefinder.model.ConnectivityChecker | ||
import tw.com.louis383.coffeefinder.model.data.api.CoffeeTripService | ||
import java.util.concurrent.TimeUnit | ||
import javax.inject.Qualifier | ||
|
||
|
||
@Retention(AnnotationRetention.BINARY) | ||
@Qualifier | ||
private annotation class InternalNetworkApi | ||
|
||
@InstallIn(SingletonComponent::class) | ||
@Module | ||
object NetworkModule { | ||
|
||
@Provides | ||
fun provideConnectivityChecker( | ||
@ApplicationContext context: Context | ||
): ConnectivityChecker { | ||
return ConnectivityChecker(context) | ||
} | ||
|
||
@Provides | ||
@InternalNetworkApi | ||
fun provideLogInterceptor(): HttpLoggingInterceptor { | ||
return HttpLoggingInterceptor().also { | ||
if (BuildConfig.DEBUG) { | ||
it.level = HttpLoggingInterceptor.Level.HEADERS | ||
it.level = HttpLoggingInterceptor.Level.BODY | ||
} else { | ||
it.level = HttpLoggingInterceptor.Level.NONE | ||
} | ||
} | ||
} | ||
|
||
@Provides | ||
@InternalNetworkApi | ||
fun provideHttpClient( | ||
@InternalNetworkApi logInterceptor: HttpLoggingInterceptor | ||
): OkHttpClient { | ||
return OkHttpClient.Builder() | ||
.addInterceptor(logInterceptor) | ||
.connectTimeout(60, TimeUnit.SECONDS) | ||
.readTimeout(60, TimeUnit.SECONDS) | ||
.retryOnConnectionFailure(true) | ||
.build() | ||
} | ||
|
||
@OptIn(ExperimentalSerializationApi::class) | ||
@Provides | ||
@InternalNetworkApi | ||
fun provideRetrofit( | ||
@InternalNetworkApi httpClient: Lazy<OkHttpClient> | ||
): Retrofit { | ||
val HOST = BuildConfig.HOST | ||
val contentType = MediaType.parse("application/json")!! | ||
return Retrofit.Builder() | ||
.baseUrl(HOST) | ||
.addConverterFactory(Json.asConverterFactory(contentType)) | ||
.callFactory { | ||
httpClient.get().newCall(it) | ||
} | ||
.build() | ||
} | ||
|
||
@Provides | ||
fun provideCoffeeTripApi( | ||
@InternalNetworkApi retrofit: Retrofit | ||
): CoffeeTripService { | ||
return retrofit.create(CoffeeTripService::class.java) | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
app/src/main/java/tw/com/louis383/coffeefinder/di/module/RepositoryModule.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package tw.com.louis383.coffeefinder.di.module | ||
|
||
import dagger.Binds | ||
import dagger.Module | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
import tw.com.louis383.coffeefinder.model.domain.repository.CoffeeShopRepository | ||
import tw.com.louis383.coffeefinder.model.domain.repository.CoffeeShopRepositoryImpl | ||
|
||
@InstallIn(SingletonComponent::class) | ||
@Module | ||
abstract class RepositoryModule { | ||
|
||
@Binds | ||
abstract fun bindCoffeeShopRepository( | ||
coffeeShopRepositoryImpl: CoffeeShopRepositoryImpl | ||
): CoffeeShopRepository | ||
} |
4 changes: 2 additions & 2 deletions
4
app/src/main/java/tw/com/louis383/coffeefinder/list/CoffeeShopListView.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
package tw.com.louis383.coffeefinder.list | ||
|
||
import tw.com.louis383.coffeefinder.BaseView | ||
import tw.com.louis383.coffeefinder.model.entity.Shop | ||
import tw.com.louis383.coffeefinder.model.domain.model.CoffeeShop | ||
|
||
interface CoffeeShopListView : BaseView { | ||
fun setLoadingProgressBarVisibility(visible: Boolean) | ||
fun setRecyclerViewVisibility(visible: Boolean) | ||
fun setNoCoffeeShopPictureVisibility(visible: Boolean) | ||
fun showNoCoffeeShopMessage() | ||
fun setItems(items: List<Shop>) | ||
fun setItems(items: List<CoffeeShop>) | ||
} |
Oops, something went wrong.