nit: refactor data.local package structure

This commit is contained in:
Han Yin 2025-04-19 21:20:11 -07:00
parent 7ed79319e5
commit 7540c2a8b9
9 changed files with 32 additions and 23 deletions

View File

@ -4,6 +4,10 @@ import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import com.example.llama.revamp.data.local.dao.ModelDao
import com.example.llama.revamp.data.local.dao.SystemPromptDao
import com.example.llama.revamp.data.local.entity.ModelEntity
import com.example.llama.revamp.data.local.entity.SystemPromptEntity
import javax.inject.Singleton
/**

View File

@ -0,0 +1,17 @@
package com.example.llama.revamp.data.local.converter
import androidx.room.TypeConverter
import com.example.llama.revamp.util.GgufMetadata
import kotlinx.serialization.json.Json
class GgufMetadataConverters {
private val json = Json { encodeDefaults = false; ignoreUnknownKeys = true }
@TypeConverter
fun toJson(value: GgufMetadata?): String? =
value?.let { json.encodeToString(GgufMetadata.serializer(), it) }
@TypeConverter
fun fromJson(value: String?): GgufMetadata? =
value?.let { json.decodeFromString(GgufMetadata.serializer(), it) }
}

View File

@ -1,10 +1,11 @@
package com.example.llama.revamp.data.local
package com.example.llama.revamp.data.local.dao
import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import com.example.llama.revamp.data.local.entity.ModelEntity
import kotlinx.coroutines.flow.Flow
@Dao

View File

@ -1,10 +1,11 @@
package com.example.llama.revamp.data.local
package com.example.llama.revamp.data.local.dao
import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import com.example.llama.revamp.data.local.entity.SystemPromptEntity
import kotlinx.coroutines.flow.Flow
/**

View File

@ -1,11 +1,11 @@
package com.example.llama.revamp.data.local
package com.example.llama.revamp.data.local.entity
import androidx.room.Entity
import androidx.room.PrimaryKey
import androidx.room.TypeConverters
import com.example.llama.revamp.data.local.converter.GgufMetadataConverters
import com.example.llama.revamp.data.model.ModelInfo
import com.example.llama.revamp.util.GgufMetadata
import com.example.llama.revamp.util.GgufMetadataConverters
@Entity(tableName = "models")

View File

@ -1,4 +1,4 @@
package com.example.llama.revamp.data.local
package com.example.llama.revamp.data.local.entity
import androidx.room.Entity
import androidx.room.PrimaryKey

View File

@ -4,8 +4,8 @@ import android.content.Context
import android.net.Uri
import android.os.StatFs
import android.util.Log
import com.example.llama.revamp.data.local.ModelDao
import com.example.llama.revamp.data.local.ModelEntity
import com.example.llama.revamp.data.local.dao.ModelDao
import com.example.llama.revamp.data.local.entity.ModelEntity
import com.example.llama.revamp.data.model.ModelInfo
import com.example.llama.revamp.data.repository.ModelRepository.ImportProgressTracker
import com.example.llama.revamp.util.GgufMetadataReader

View File

@ -1,7 +1,7 @@
package com.example.llama.revamp.data.repository
import com.example.llama.revamp.data.local.SystemPromptDao
import com.example.llama.revamp.data.local.SystemPromptEntity
import com.example.llama.revamp.data.local.dao.SystemPromptDao
import com.example.llama.revamp.data.local.entity.SystemPromptEntity
import com.example.llama.revamp.data.model.SystemPrompt
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.first

View File

@ -1,8 +1,6 @@
package com.example.llama.revamp.util
import androidx.room.TypeConverter
import kotlinx.serialization.Serializable
import kotlinx.serialization.json.Json
import java.io.IOException
@ -189,18 +187,6 @@ data class GgufMetadata(
)
}
class GgufMetadataConverters {
private val json = Json { encodeDefaults = false; ignoreUnknownKeys = true }
@TypeConverter
fun toJson(value: GgufMetadata?): String? =
value?.let { json.encodeToString(GgufMetadata.serializer(), it) }
@TypeConverter
fun fromJson(value: String?): GgufMetadata? =
value?.let { json.decodeFromString(GgufMetadata.serializer(), it) }
}
/**
* Numerical codes used by `general.file_type` (see llama.cpp repo's `constants.py`).
* The `label` matches what llamacli prints.