-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
migration to kotlin-inject partial 3
- Loading branch information
1 parent
0e51805
commit bf3406d
Showing
20 changed files
with
409 additions
and
218 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package org.yrovas.linklater | ||
|
||
import android.content.Context | ||
import android.util.Log | ||
import androidx.datastore.core.DataStore | ||
import androidx.datastore.preferences.core.Preferences | ||
import androidx.datastore.preferences.preferencesDataStore | ||
import io.ktor.client.HttpClient | ||
import io.ktor.client.engine.android.Android | ||
import io.ktor.client.plugins.DefaultRequest | ||
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation | ||
import io.ktor.client.plugins.logging.LogLevel | ||
import io.ktor.client.plugins.logging.Logger | ||
import io.ktor.client.plugins.logging.Logging | ||
import io.ktor.client.request.header | ||
import io.ktor.http.ContentType | ||
import io.ktor.http.HttpHeaders | ||
import io.ktor.serialization.kotlinx.json.json | ||
import kotlinx.serialization.json.Json | ||
import me.tatarka.inject.annotations.Component | ||
import me.tatarka.inject.annotations.Provides | ||
import me.tatarka.inject.annotations.Scope | ||
import org.yrovas.linklater.data.local.PrefDataStore | ||
import org.yrovas.linklater.data.local.PrefStore | ||
import org.yrovas.linklater.data.remote.BookmarkAPI | ||
import org.yrovas.linklater.data.remote.LinkDingAPI | ||
import org.yrovas.linklater.ui.activity.DestinationHost | ||
|
||
val Context.dataStore: DataStore<Preferences> by preferencesDataStore(name = "preferences") | ||
|
||
@Scope | ||
annotation class AppScope | ||
|
||
@Component | ||
@AppScope | ||
abstract class AppComponent( | ||
@get:Provides val context: Context, | ||
) { | ||
abstract val destinationHost: DestinationHost | ||
abstract val prefStore: PrefDataStore | ||
|
||
private val store: DataStore<Preferences> | ||
get() = context.dataStore | ||
|
||
@Provides | ||
fun providePrefStore(): PrefDataStore = PrefStore(store) | ||
|
||
@Provides | ||
fun provideHttpClient(): HttpClient = HttpClient(Android) { | ||
install(Logging) { | ||
logger = object : Logger { | ||
override fun log(message: String) { | ||
Log.i("Ktor =>", message) | ||
} | ||
} | ||
level = LogLevel.ALL | ||
} | ||
install(ContentNegotiation) { | ||
json(Json { | ||
prettyPrint = true | ||
isLenient = true | ||
ignoreUnknownKeys = true | ||
}) | ||
} | ||
install(DefaultRequest) { | ||
header(HttpHeaders.ContentType, ContentType.Application.Json) | ||
} | ||
} | ||
|
||
abstract val linkDingAPI: LinkDingAPI | ||
val bookmarkAPI: BookmarkAPI | ||
@Provides get() = linkDingAPI | ||
} |
4 changes: 1 addition & 3 deletions
4
app/src/main/java/org/yrovas/linklater/data/local/PrefDataStore.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
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
8 changes: 5 additions & 3 deletions
8
app/src/main/java/org/yrovas/linklater/data/remote/BookmarkAPI.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
7 changes: 5 additions & 2 deletions
7
app/src/main/java/org/yrovas/linklater/data/remote/EmptyBookmarkAPI.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
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
Oops, something went wrong.