Skip to content

Commit

Permalink
renamed files
Browse files Browse the repository at this point in the history
  • Loading branch information
kulloveth committed May 1, 2020
2 parents ca68a5d + 392964a commit 265b66e
Show file tree
Hide file tree
Showing 12 changed files with 81 additions and 77 deletions.
3 changes: 3 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ dependencies {
// Room components
implementation "androidx.room:room-runtime:$rootProject.roomVersion"
kapt "androidx.room:room-compiler:$rootProject.roomVersion"
implementation "androidx.room:room-ktx:$rootProject.roomVersion"
androidTestImplementation "androidx.room:room-testing:$rootProject.roomVersion"

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

// Lifecycle components
Expand All @@ -55,6 +57,7 @@ dependencies {
// Material design
implementation "com.google.android.material:material:$rootProject.materialVersion"

//Expandable
implementation 'com.thoughtbot:expandablerecyclerview:1.3'
implementation 'com.thoughtbot:expandablecheckrecyclerview:1.4'

Expand Down
3 changes: 2 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".data.ui.MainActivity">
<activity android:name=".ui.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -19,80 +19,80 @@ class DataGenerator {
}

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


}

fun africaCountrys(): ArrayList<Country> {
val coun = ArrayList<Country>()
coun.add(Country("South Africa"))
coun.add(Country("Nigeria"))
coun.add(Country("Kenya"))
coun.add(Country("Ghana"))
coun.add(Country("Ethiopia"))
return coun
val counntries = ArrayList<Country>()
counntries.add(Country("South Africa"))
counntries.add(Country("Nigeria"))
counntries.add(Country("Kenya"))
counntries.add(Country("Ghana"))
counntries.add(Country("Ethiopia"))
return counntries
}

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

fun northAmericaCountrys(): ArrayList<Country> {
val coun = ArrayList<Country>()
val counntries = ArrayList<Country>()

coun.add(Country("United States"))
coun.add(Country("Mexico"))
coun.add(Country("Cuba"))
coun.add(Country("Green Land"))
return coun
counntries.add(Country("United States"))
counntries.add(Country("Mexico"))
counntries.add(Country("Cuba"))
counntries.add(Country("Green Land"))
return counntries


}

fun southAmericaCountrys(): ArrayList<Country> {
val coun = ArrayList<Country>()
coun.add(Country("Brazil"))
coun.add(Country("Argentina"))
coun.add(Country("Columbia"))
coun.add(Country("Peru"))
coun.add(Country("Chile"))
val counntries = ArrayList<Country>()
counntries.add(Country("Brazil"))
counntries.add(Country("Argentina"))
counntries.add(Country("Columbia"))
counntries.add(Country("Peru"))
counntries.add(Country("Chile"))

return coun
return counntries


}

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

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

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import android.view.View
import android.widget.ImageView
import android.widget.TextView
import com.developer.kulloveth.expandablelistsamplewithroom.R
import com.developer.kulloveth.expandablelistsamplewithroom.data.model.Continents
import com.developer.kulloveth.expandablelistsamplewithroom.data.model.Continent
import com.developer.kulloveth.expandablelistsamplewithroom.data.model.Country
import com.thoughtbot.expandablerecyclerview.viewholders.ChildViewHolder
import com.thoughtbot.expandablerecyclerview.viewholders.GroupViewHolder
Expand All @@ -22,7 +22,7 @@ class ContinentViewHolder(itemView: View) : GroupViewHolder(itemView) {
val continentName = itemView.findViewById<TextView>(R.id.continent)
val arrow = itemView.findViewById<ImageView>(R.id.arrow)

fun bind(continent: Continents) {
fun bind(continent: Continent) {
continentName.text = continent.continentName
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ package com.developer.kulloveth.expandablelistsamplewithroom.data.model
import androidx.lifecycle.LiveData
import com.developer.kulloveth.expandablelistsamplewithroom.data.db.ContinentDao

class Repository(val continentDao: ContinentDao) {

class Repository( continentDao: ContinentDao) {

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ 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
Expand All @@ -15,5 +14,5 @@ interface ContinentDao {
fun getAllContinent(): LiveData<List<ContinentEntity>>

@Insert(onConflict = OnConflictStrategy.IGNORE)
fun insert(continent: ContinentEntity)
suspend fun insert(continent: ContinentEntity)
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,36 @@ import androidx.room.RoomDatabase
import androidx.sqlite.db.SupportSQLiteDatabase
import com.developer.kulloveth.expandablelistsamplewithroom.data.DataGenerator
import com.developer.kulloveth.expandablelistsamplewithroom.data.model.ContinentEntity
import java.util.concurrent.Executors
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch

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

public abstract class PlaceDatabase : RoomDatabase() {
abstract class ContinentDatabase : RoomDatabase() {

abstract fun continentDao(): ContinentDao


companion object {
@Volatile
private var INSTANCE: PlaceDatabase? = null
private var INSTANCE: ContinentDatabase? = null

fun getDatabase(context: Context): PlaceDatabase {
fun getDatabase(context: Context, scope: CoroutineScope): ContinentDatabase {

return INSTANCE ?: synchronized(this) {
INSTANCE ?: buildDatabase(context).also {
INSTANCE ?: buildDatabase(context, scope).also {
INSTANCE = it
}
}
}

private fun buildDatabase(context: Context): PlaceDatabase {
return Room.databaseBuilder(context, PlaceDatabase::class.java, "place_db")
private fun buildDatabase(context: Context, scope: CoroutineScope): ContinentDatabase {
return Room.databaseBuilder(context, ContinentDatabase::class.java, "place_db")
.addCallback(object : RoomDatabase.Callback() {
override fun onCreate(db: SupportSQLiteDatabase) {
super.onCreate(db)

Executors.newSingleThreadExecutor().execute {
scope.launch {
INSTANCE?.let {
for (continent: ContinentEntity in DataGenerator.getContinents()) {
it.continentDao().insert(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ package com.developer.kulloveth.expandablelistsamplewithroom.data.model
import com.thoughtbot.expandablerecyclerview.models.ExpandableGroup


data class Continents(
data class Continent(
val continentName: String, val countries: List<Country>
): ExpandableGroup<Country>(continentName, countries)
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import android.view.ViewGroup
import com.developer.kulloveth.expandablelistsamplewithroom.R
import com.developer.kulloveth.expandablelistsamplewithroom.data.ContinentViewHolder
import com.developer.kulloveth.expandablelistsamplewithroom.data.CountryViewHolder
import com.developer.kulloveth.expandablelistsamplewithroom.data.model.Continents
import com.developer.kulloveth.expandablelistsamplewithroom.data.model.Continent
import com.developer.kulloveth.expandablelistsamplewithroom.data.model.Country
import com.thoughtbot.expandablerecyclerview.ExpandableRecyclerViewAdapter
import com.thoughtbot.expandablerecyclerview.models.ExpandableGroup
Expand Down Expand Up @@ -43,7 +43,7 @@ class ContinentAdapter(groups: List<ExpandableGroup<*>>?) :
flatPosition: Int,
group: ExpandableGroup<*>?
) {
val continents: Continents = group as Continents
holder?.bind(continents)
val continent: Continent = group as Continent
holder?.bind(continent)
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.developer.kulloveth.expandablelistsamplewithroom.data.ui
package com.developer.kulloveth.expandablelistsamplewithroom.ui

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
Expand All @@ -8,12 +8,13 @@ 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 com.developer.kulloveth.expandablelistsamplewithroom.data.model.Continent
import com.developer.kulloveth.expandablelistsamplewithroom.data.ui.ContinentAdapter
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() {
lateinit var viewModel: MainActivityViewModel
val continents = ArrayList<Continents>()
val continents = ArrayList<Continent>()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
Expand All @@ -24,7 +25,7 @@ class MainActivity : AppCompatActivity() {
// Log.d("countr", " $it")
for (con: ContinentEntity in it) {

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

Log.d("countr", " $continents")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.developer.kulloveth.expandablelistsamplewithroom.data.ui
package com.developer.kulloveth.expandablelistsamplewithroom.ui

import android.app.Application
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.LiveData
import com.developer.kulloveth.expandablelistsamplewithroom.data.db.PlaceDatabase
import androidx.lifecycle.viewModelScope
import com.developer.kulloveth.expandablelistsamplewithroom.data.db.ContinentDatabase
import com.developer.kulloveth.expandablelistsamplewithroom.data.model.ContinentEntity
import com.developer.kulloveth.expandablelistsamplewithroom.data.model.Continents
import com.developer.kulloveth.expandablelistsamplewithroom.data.model.Repository

class MainActivityViewModel(application: Application) : AndroidViewModel(application) {
Expand All @@ -16,7 +16,7 @@ class MainActivityViewModel(application: Application) : AndroidViewModel(applica


init {
val continentDao = PlaceDatabase.getDatabase(application).continentDao()
val continentDao = ContinentDatabase.getDatabase(application, viewModelScope).continentDao()
repository = Repository(continentDao)
continents = repository.allContinents
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/countrys_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_height="50dp"
android:padding="0dp">

<TextView
Expand Down

0 comments on commit 265b66e

Please sign in to comment.