<repo_name>Marrvvelll/Ayaziy<file_sep>/app/src/main/java/com/example/ayaziy/SongsFragment.kt
package com.example.ayaziy
import android.os.Bundle
import android.view.View
import android.widget.Adapter
import androidx.fragment.app.Fragment
import com.example.ayaziy.data.QosiqlarDatabase
import com.example.ayaziy.data.dao.QosiqlarDao
import kotlinx.android.synthetic.main.songs_layout.*
class SongsFragment:Fragment(R.layout.songs_layout) {
    var adapter=AdapterSongs()
    private lateinit var dao:QosiqlarDao
    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        recyclerSongs.adapter=adapter
        dao=QosiqlarDatabase.getInstance(requireContext()).dao()
        adapter.models=dao.getAllQosiqlar()
    }
}<file_sep>/app/src/main/java/com/example/ayaziy/data/model/Qosiqlar.kt
package com.example.ayaziy.data.model

import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey

@Entity(tableName = "qosiqlar")
data class Qosiqlar(
    @PrimaryKey val id:Int,
    @ColumnInfo(name="name")
    val name:String,
    @ColumnInfo(name="text")
    val text:String,
    @ColumnInfo(name="is_favorite")
    var favorite:Int,
    @ColumnInfo(name="type")
    val type:Int
)<file_sep>/app/src/main/java/com/example/ayaziy/data/dao/QosiqlarDao.kt
package com.example.ayaziy.data.dao

import androidx.room.Dao
import androidx.room.Query
import com.example.ayaziy.data.model.Qosiqlar

@Dao
interface QosiqlarDao {
    @Query("SELECT * FROM qosiqlar")
    fun getAllQosiqlar():List<Qosiqlar>
}<file_sep>/app/src/main/java/com/example/ayaziy/MainActivity.kt
package com.example.ayaziy

import android.os.Bundle
import android.view.Menu
import androidx.appcompat.app.ActionBarDrawerToggle
import com.google.android.material.navigation.NavigationView

import androidx.drawerlayout.widget.DrawerLayout
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.Toolbar

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        val toolbar: Toolbar = findViewById(R.id.toolbar)
        setSupportActionBar(toolbar)

        val drawerLayout: DrawerLayout = findViewById(R.id.drawer_layout)
        val navView: NavigationView = findViewById(R.id.nav_view)
        val toggle= ActionBarDrawerToggle(this,drawerLayout,R.string.navigation_drawer_open,R.string.navigation_drawer_close)
        drawerLayout.addDrawerListener(toggle)
        toggle.syncState()

        navView.setNavigationItemSelectedListener {
            when(it.itemId){
                R.layout.omirlik_joli->{
                    supportFragmentManager.beginTransaction().replace(R.id.fragment_container,OmirlikJoliFragment()).commit()
                    return@setNavigationItemSelectedListener true
                }
            }
            return@setNavigationItemSelectedListener false
        }
        supportFragmentManager.beginTransaction().replace(R.id.fragment_container,HomeFragment()).commit()
    }

    override fun onCreateOptionsMenu(menu: Menu): Boolean {
        menuInflater.inflate(R.menu.main, menu)
        return true
    }


}<file_sep>/app/src/main/java/com/example/ayaziy/HomeFragment.kt
package com.example.ayaziy

import android.content.Context
import android.os.Bundle
import android.view.View
import androidx.fragment.app.Fragment
import kotlinx.android.synthetic.main.home.*

class HomeFragment:Fragment(R.layout.home) {
    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        songs.setOnClickListener {
            requireActivity().supportFragmentManager.beginTransaction().replace(R.id.fragment_container,SongsFragment()).commit()

        }
        poems.setOnClickListener {

        }
        videos.setOnClickListener {

        }
        fotos.setOnClickListener {

        }
    }
}<file_sep>/app/src/main/java/com/example/ayaziy/AdapterSongs.kt
package com.example.ayaziy

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Adapter
import androidx.recyclerview.widget.RecyclerView
import com.example.ayaziy.data.model.Qosiqlar
import kotlinx.android.synthetic.main.item_songs.view.*

class AdapterSongs:RecyclerView.Adapter<AdapterSongs.ViewHolderSongs>() {

    var models:List<Qosiqlar> = listOf()
    set(value) {
        field=value
        notifyDataSetChanged()
    }


inner class ViewHolderSongs(itemView: View):RecyclerView.ViewHolder(itemView){
    fun populateModel(qosiq:Qosiqlar){
        itemView.itemSongs.text=qosiq.name
    }
}

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolderSongs {
        var itemView=LayoutInflater.from(parent.context).inflate(R.layout.item_songs,parent,false)
        return ViewHolderSongs(itemView)
    }

    override fun getItemCount(): Int {
     return models.size
    }

    override fun onBindViewHolder(holder: ViewHolderSongs, position: Int) {
        holder.populateModel(models[position])
    }
}<file_sep>/app/src/main/java/com/example/ayaziy/data/QosiqlarDatabase.kt
package com.example.ayaziy.data

import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import com.example.ayaziy.data.dao.QosiqlarDao
import com.example.ayaziy.data.model.Qosiqlar


@Database(entities = [Qosiqlar::class],version = 1)
abstract class QosiqlarDatabase:RoomDatabase() {
    companion object{
        private lateinit var INSTANCE:QosiqlarDatabase
        fun getInstance(context: Context):QosiqlarDatabase=
            Room.databaseBuilder(
                context,
                QosiqlarDatabase::class.java,
                "database.db"
            )
                .createFromAsset("database.db")
                .allowMainThreadQueries()
                .build()
    }
    abstract fun dao():QosiqlarDao
}