Skip to content

Commit

Permalink
complete project done
Browse files Browse the repository at this point in the history
  • Loading branch information
kulloveth committed Apr 27, 2020
1 parent 53babf1 commit ab7e01f
Show file tree
Hide file tree
Showing 16 changed files with 168 additions and 118 deletions.
4 changes: 3 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ android {
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.developer.kulloveth.expandablelistsamplewithroom"
minSdkVersion 15
minSdkVersion 19
targetSdkVersion 29
versionCode 1
versionName "1.0"
Expand Down Expand Up @@ -40,6 +40,8 @@ dependencies {
kapt "androidx.room:room-compiler:$rootProject.roomVersion"
androidTestImplementation "androidx.room:room-testing:$rootProject.roomVersion"

implementation 'com.google.code.gson:gson:2.8.6'

// Lifecycle components
implementation "androidx.lifecycle:lifecycle-extensions:$rootProject.archLifecycleVersion"
kapt "androidx.lifecycle:lifecycle-compiler:$rootProject.archLifecycleVersion"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,104 +1,101 @@
package com.developer.kulloveth.expandablelistsamplewithroom.data

import com.developer.kulloveth.expandablelistsamplewithroom.data.model.ContinentEntity
import com.developer.kulloveth.expandablelistsamplewithroom.data.model.Continents
import com.developer.kulloveth.expandablelistsamplewithroom.data.model.Countrys
import java.sql.Array

class DataGenerator {

companion object {
fun getContinents(): List<Continents> {
fun getContinents(): List<ContinentEntity> {
return listOf(
Continents("Europe", europeCountrys()),
Continents("Africa", africaCountrys()),
Continents("Asia", asiaCountrys()),
Continents("North America", northAmericaCountrys()),
Continents("South America", southAmericaCountrys()),
Continents("Antarctica", antarcticaCountrys()),
Continents("Oceania", oceaniaCountrys()),
Continents("Australia", austrailaCountrys())
ContinentEntity("Europe", europeCountrys()),
ContinentEntity("Africa", africaCountrys()),
ContinentEntity("Asia", asiaCountrys()),
ContinentEntity("North America", northAmericaCountrys()),
ContinentEntity("South America", southAmericaCountrys()),
ContinentEntity("Antarctica", antarcticaCountrys()),
ContinentEntity("Oceania", oceaniaCountrys())
)
}

fun europeCountrys(): List<Countrys> {
return listOf(
Countrys("Germany"),
Countrys("Italy"),
Countrys("France"),
Countrys("United Kingdom"),
Countrys("NertherLand")

)
}
fun europeCountrys(): ArrayList<Countrys> {
val coun = ArrayList<Countrys>()
coun.add(Countrys("Germany"))
coun.add(Countrys("Italy"))
coun.add(Countrys("France"))
coun.add(Countrys("United Kingdom"))
coun.add(Countrys("NertherLand"))
return coun

fun africaCountrys(): List<Countrys> {
return listOf(
Countrys("South Africa"),
Countrys("Nigeria"),
Countrys("Kenya"),
Countrys("Ghana"),
Countrys("Ethiopia")

)
}

fun asiaCountrys(): List<Countrys> {
return listOf(
Countrys("Japan"),
Countrys("India"),
Countrys("Indonesi"),
Countrys("China"),
Countrys("Thailand")
fun africaCountrys(): ArrayList<Countrys> {
val coun = ArrayList<Countrys>()
coun.add(Countrys("South Africa"))
coun.add(Countrys("Nigeria"))
coun.add(Countrys("Kenya"))
coun.add(Countrys("Ghana"))
coun.add(Countrys("Ethiopia"))
return coun
}

)
fun asiaCountrys(): ArrayList<Countrys> {
val coun = ArrayList<Countrys>()
coun.add(Countrys("Japan"))
coun.add(Countrys("India"))
coun.add(Countrys("Indonesi"))
coun.add(Countrys("China"))
coun.add(Countrys("Thailand"))
return coun
}

fun northAmericaCountrys(): List<Countrys> {
return listOf(
Countrys("United States"),
Countrys("Mexico"),
Countrys("Cuba"),
Countrys("Green Land")
fun northAmericaCountrys(): ArrayList<Countrys> {
val coun = ArrayList<Countrys>()

)
}
coun.add(Countrys("United States"))
coun.add(Countrys("Mexico"))
coun.add(Countrys("Cuba"))
coun.add(Countrys("Green Land"))
return coun

fun southAmericaCountrys(): List<Countrys> {
return listOf(
Countrys("Brazil"),
Countrys("Argentina"),
Countrys("Columbia"),
Countrys("Peru"),
Countrys("Chile")

)
}

fun antarcticaCountrys(): List<Countrys> {
return listOf(
Countrys("Esperenza Base"),
Countrys("Villa az Estrellaz"),
Countrys("General Bernando O'Higging"),
Countrys("Bellgrano II base"),
Countrys("Carlini Base")
fun southAmericaCountrys(): ArrayList<Countrys> {
val coun = ArrayList<Countrys>()
coun.add(Countrys("Brazil"))
coun.add(Countrys("Argentina"))
coun.add(Countrys("Columbia"))
coun.add(Countrys("Peru"))
coun.add(Countrys("Chile"))

)
}
return coun

fun oceaniaCountrys(): List<Countrys> {
return listOf(
Countrys("Australia"),
Countrys("Newzeland"),
Countrys("Fiji"),
Countrys("Samao"),
Countrys("Federated States")

)
}

fun austrailaCountrys(): List<Countrys> {
return listOf(
fun antarcticaCountrys(): ArrayList<Countrys> {
val coun = ArrayList<Countrys>()
coun.add(Countrys("Esperenza Base"))
coun.add(Countrys("Villa az Estrellaz"))
coun.add(Countrys("General Bernando O'Higging"))
coun.add(Countrys("Bellgrano II base"))
coun.add(Countrys("Carlini Base"))
return coun
}

)
fun oceaniaCountrys(): ArrayList<Countrys> {
val coun = ArrayList<Countrys>()
coun.add(Countrys("Australia"))
coun.add(Countrys("Newzeland"))
coun.add(Countrys("Fiji"))
coun.add(Countrys("Samao"))
coun.add(Countrys("Federated States"))
return coun
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ class ContinentViewHolder(itemView: View) : GroupViewHolder(itemView) {
val continentName = itemView.findViewById<TextView>(R.id.continent)

fun bind(continent: Continents) {
continentName.text = continent.ContinentName
continentName.text = continent.continentName
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import androidx.lifecycle.LiveData
import com.developer.kulloveth.expandablelistsamplewithroom.data.db.ContinentDao

class Repository(val continentDao: ContinentDao) {
val allContinents: LiveData<List<Continents>> = continentDao.getAllContinent()


val allContinents: LiveData<List<ContinentEntity>> = continentDao.getAllContinent()


}
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import com.developer.kulloveth.expandablelistsamplewithroom.data.model.ContinentEntity
import com.developer.kulloveth.expandablelistsamplewithroom.data.model.Continents


@Dao
interface ContinentDao {
@Query("SELECT * from `continent-table` ORDER BY continent ASC")
fun getAllContinent(): LiveData<List<Continents>>
fun getAllContinent(): LiveData<List<ContinentEntity>>

@Insert(onConflict = OnConflictStrategy.IGNORE)
fun insert(continent: Continents)
fun insert(continent: ContinentEntity)
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,21 @@ import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import androidx.room.TypeConverter
import androidx.sqlite.db.SupportSQLiteDatabase
import com.developer.kulloveth.expandablelistsamplewithroom.data.DataGenerator
import com.developer.kulloveth.expandablelistsamplewithroom.data.model.ContinentConverter
import com.developer.kulloveth.expandablelistsamplewithroom.data.model.ContinentEntity
import com.developer.kulloveth.expandablelistsamplewithroom.data.model.Continents
import com.developer.kulloveth.expandablelistsamplewithroom.data.model.Countrys
import java.util.concurrent.Executors

@Database(entities = arrayOf(Continents::class), version = 1, exportSchema = false)
@Database(entities = arrayOf(ContinentEntity::class), version = 1, exportSchema = false)

public abstract class PlaceDatabase : RoomDatabase() {

abstract fun continentDao(): ContinentDao
abstract fun countryDao(): CountryDao
private var mContext: Context? = null


companion object {
@Volatile
Expand All @@ -38,8 +41,13 @@ public abstract class PlaceDatabase : RoomDatabase() {

Executors.newSingleThreadExecutor().execute {
INSTANCE?.let {
for (continent: Continents in DataGenerator.getContinents()) {
it.continentDao().insert(continent)
for (continent: ContinentEntity in DataGenerator.getContinents()) {
it.continentDao().insert(
ContinentEntity(
continent.continentName,
continent.countrys
)
)
}

}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.developer.kulloveth.expandablelistsamplewithroom.data.model

import androidx.room.TypeConverter
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import java.lang.reflect.Type
import java.util.*


class ContinentConverter {


companion object {
var gson: Gson = Gson()
@TypeConverter @JvmStatic
fun stringToSomeObjectList(data: String?): ArrayList<Countrys> {
val listType: Type =
object : TypeToken<ArrayList<Countrys?>?>() {}.getType()
return gson.fromJson(data, listType)
}

@TypeConverter @JvmStatic
fun someObjectListToString(someObjects: ArrayList<Countrys?>?): String {
return gson.toJson(someObjects)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.developer.kulloveth.expandablelistsamplewithroom.data.model

import android.os.Parcelable
import androidx.room.*
import com.thoughtbot.expandablerecyclerview.models.ExpandableGroup

@Entity(tableName = "continent-table")
@TypeConverters(ContinentConverter::class)
data class ContinentEntity (@PrimaryKey @ColumnInfo(name = "continent") val continentName: String, val countrys: ArrayList<Countrys>
)
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
package com.developer.kulloveth.expandablelistsamplewithroom.data.model

import android.os.Parcelable
import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey
import androidx.room.*
import com.thoughtbot.expandablerecyclerview.models.ExpandableGroup
import kotlinx.android.parcel.Parcelize


@Entity(tableName = "continent-table")

data class Continents(
@PrimaryKey @ColumnInfo(name = "continent") val ContinentName: String,
@ColumnInfo(name = "countrys__layout") val countrys: List<Countrys>
) : ExpandableGroup<Countrys>(ContinentName, countrys)
val continentName: String, val countrys: List<Countrys>
): ExpandableGroup<Countrys>(continentName, countrys)
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,37 @@ package com.developer.kulloveth.expandablelistsamplewithroom.data.ui

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.LinearLayoutManager
import com.developer.kulloveth.expandablelistsamplewithroom.R
import com.developer.kulloveth.expandablelistsamplewithroom.data.model.ContinentEntity
import com.developer.kulloveth.expandablelistsamplewithroom.data.model.Continents
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() {

lateinit var viewModel: MainActivityViewModel
val continents = ArrayList<Continents>()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
viewModel = ViewModelProvider(this)[MainActivityViewModel::class.java]
rvConinent.layoutManager = LinearLayoutManager(this)

viewModel.continents.observe(this, Observer {
// Log.d("countr", " $it")
for (con: ContinentEntity in it) {

val continent = Continents(con.continentName, con.countrys)
continents.add(continent)

Log.d("countr", " $continents")
}
val adapter = ContinentAdapter(continents)
rvConinent.adapter = adapter
})


}
}
Loading

0 comments on commit ab7e01f

Please sign in to comment.