Package uz space proverb data import androidx room. ColumnInfo


Download 53.03 Kb.
bet1/10
Sana22.02.2023
Hajmi53.03 Kb.
#1219993
  1   2   3   4   5   6   7   8   9   10
Bog'liq
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
import androidx.room.Dao
import androidx.room.Query
import androidx.room.Update

@Dao
interface ProverbDao {


@Query("SELECT * FROM `proverbs-table`")
fun getAllProverbs(): LiveData>

@Update
suspend fun updateProverb(proverb: Proverb)

@Query("SELECT * FROM `proverbs-table` WHERE proverb LIKE :proverb")
fun searchData(proverb: String): LiveData>
}

package uz.space.proverb.data

import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase

@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> = proverbDao.getAllProverbs()

suspend fun updateProverb(proverb: Proverb) = proverbDao.updateProverb(proverb)

fun searchDatabase(proverb: String): LiveData>{
return proverbDao.searchData(proverb)
}

}

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{
private const val MY_SETTINGS = "MySettings"
const val TEXT_SIZE_TITLE = "title"
const val TEXT_SIZE_DESCRIPTON = "description"
const val DEFAULT_TEXT_SIZE_TITLE = 18F
const val DEFAULT_TEXT_SIZE_DESCRIPTION = 16F

}

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
= listOf()
set(value) {


Download 53.03 Kb.

Do'stlaringiz bilan baham:
  1   2   3   4   5   6   7   8   9   10




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling