mirror of
https://github.com/JustinZeus/Wholphin.git
synced 2026-07-09 16:11:20 +02:00
Basics for user prefs, logging in, etc
This commit is contained in:
parent
763521aabf
commit
76d78246db
15 changed files with 613 additions and 35 deletions
|
|
@ -0,0 +1,53 @@
|
|||
package com.github.damontecres.dolphin.hilt
|
||||
|
||||
import android.content.Context
|
||||
import androidx.datastore.core.DataStore
|
||||
import androidx.datastore.core.DataStoreFactory
|
||||
import androidx.datastore.core.handlers.ReplaceFileCorruptionHandler
|
||||
import androidx.datastore.dataStoreFile
|
||||
import androidx.room.Room
|
||||
import com.github.damontecres.dolphin.data.DolphinDatabase
|
||||
import com.github.damontecres.dolphin.data.JellyfinServerDao
|
||||
import com.github.damontecres.dolphin.preferences.UserPreferences
|
||||
import com.github.damontecres.dolphin.preferences.UserPreferencesSerializer
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import dagger.hilt.InstallIn
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import dagger.hilt.components.SingletonComponent
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Module
|
||||
@InstallIn(SingletonComponent::class)
|
||||
object DatabaseModule {
|
||||
@Provides
|
||||
@Singleton
|
||||
fun database(
|
||||
@ApplicationContext context: Context,
|
||||
): DolphinDatabase =
|
||||
Room
|
||||
.databaseBuilder(
|
||||
context,
|
||||
DolphinDatabase::class.java,
|
||||
"dolphin",
|
||||
).build()
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun serverDao(db: DolphinDatabase): JellyfinServerDao = db.serverDao()
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun userPreferencesDataStore(
|
||||
@ApplicationContext context: Context,
|
||||
userPreferencesSerializer: UserPreferencesSerializer,
|
||||
): DataStore<UserPreferences> =
|
||||
DataStoreFactory.create(
|
||||
serializer = userPreferencesSerializer,
|
||||
produceFile = { context.dataStoreFile("user_preferences.pb") },
|
||||
corruptionHandler =
|
||||
ReplaceFileCorruptionHandler(
|
||||
produceNewData = { UserPreferences.getDefaultInstance() },
|
||||
),
|
||||
)
|
||||
}
|
||||
|
|
@ -0,0 +1,57 @@
|
|||
package com.github.damontecres.dolphin.hilt
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.provider.Settings
|
||||
import com.github.damontecres.dolphin.BuildConfig
|
||||
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 org.jellyfin.sdk.Jellyfin
|
||||
import org.jellyfin.sdk.api.okhttp.OkHttpFactory
|
||||
import org.jellyfin.sdk.createJellyfin
|
||||
import org.jellyfin.sdk.model.ClientInfo
|
||||
import org.jellyfin.sdk.model.DeviceInfo
|
||||
|
||||
@Module
|
||||
@InstallIn(SingletonComponent::class)
|
||||
object DolphinModule {
|
||||
@Provides
|
||||
fun okHttpClient() =
|
||||
OkHttpClient
|
||||
.Builder()
|
||||
.apply {
|
||||
// TODO user agent, timeouts, logging, etc
|
||||
}.build()
|
||||
|
||||
@Provides
|
||||
fun okHttpFactory(okHttpClient: OkHttpClient) = OkHttpFactory(okHttpClient)
|
||||
|
||||
@Provides
|
||||
fun jellyfin(
|
||||
okHttpFactory: OkHttpFactory,
|
||||
@ApplicationContext context: Context,
|
||||
): Jellyfin =
|
||||
createJellyfin {
|
||||
this.context = context
|
||||
clientInfo =
|
||||
ClientInfo(
|
||||
name = "Dolphin",
|
||||
version = BuildConfig.VERSION_NAME,
|
||||
)
|
||||
deviceInfo =
|
||||
DeviceInfo(
|
||||
id = @SuppressLint("HardwareIds") Settings.Secure.getString(context.contentResolver, Settings.Secure.ANDROID_ID),
|
||||
name = Settings.Global.getString(context.contentResolver, Settings.Global.DEVICE_NAME),
|
||||
)
|
||||
apiClientFactory = okHttpFactory
|
||||
socketConnectionFactory = okHttpFactory
|
||||
minimumServerVersion = Jellyfin.minimumVersion
|
||||
}
|
||||
|
||||
@Provides
|
||||
fun apiClient(jellyfin: Jellyfin) = jellyfin.createApi()
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue