Package uz space proverb data import androidx room. ColumnInfo
Download 53.03 Kb.
|
Zoonim naqil-maqallar sozligi code
package uz.space.proverb.data import androidx.room.ColumnInfo import androidx.room.Entity import androidx.room.PrimaryKey @Entity(tableName = "proverbs-table") data class Proverb( @PrimaryKey var id: Int, @ColumnInfo(name = "proverb") var proverb: String, @ColumnInfo(name = "favorit") var favorit: Int, @ColumnInfo(name = "all_text") var allText: String ) package uz.space.proverb.data import androidx.lifecycle.LiveData
@Dao
@Query("SELECT * FROM `proverbs-table`") fun getAllProverbs(): LiveData @Update
@Query("SELECT * FROM `proverbs-table` WHERE proverb LIKE :proverb")
package uz.space.proverb.data import android.content.Context
@Database(entities = [Proverb::class], version = 1) abstract class ProverbDatabase : RoomDatabase() { companion object { @Volatile private var INSTANCE: ProverbDatabase? = null fun getInstance(context: Context): ProverbDatabase { var tempInstance = INSTANCE if(tempInstance != null){ return tempInstance }else { synchronized(this) { return Room.databaseBuilder( context, ProverbDatabase::class.java, "proverb-database.db" ) .createFromAsset("proverb-database.db") .build() } } } } abstract fun dao(): ProverbDao } package uz.space.proverb.data import androidx.lifecycle.LiveData class ProverbRepository(private val proverbDao: ProverbDao) { val readAllData: LiveData suspend fun updateProverb(proverb: Proverb) = proverbDao.updateProverb(proverb) fun searchDatabase(proverb: String): LiveData } package uz.space.proverb.settings import android.content.Context import android.content.ContextWrapper import android.content.SharedPreferences import androidx.appcompat.app.AppCompatActivity class Settings() { companion object{
} fun setTextSize(key: String, textSize: Float, context: Context) { val preferences: SharedPreferences = context.getSharedPreferences(MY_SETTINGS, Context.MODE_PRIVATE) preferences.edit().putFloat(key, textSize).apply() } fun getTextSize(key: String, context: Context): Float { val preferences: SharedPreferences = context.getSharedPreferences(MY_SETTINGS, Context.MODE_PRIVATE) return if(key == TEXT_SIZE_TITLE){ preferences.getFloat(key, 18F) }else{ preferences.getFloat(key, 16F) } }
package uz.space.proverb.ui.favorit import android.util.TypedValue import android.view.LayoutInflater import android.view.ViewGroup import androidx.recyclerview.widget.RecyclerView import uz.space.proverb.R import uz.space.proverb.data.Proverb import uz.space.proverb.databinding.ItemFavoritListBinding import uz.space.proverb.settings.Settings class FavoritAdapter : RecyclerView.Adapter var models: List
Download 53.03 Kb. Do'stlaringiz bilan baham: |
ma'muriyatiga murojaat qiling