Ajout de multiple commentaires

Signed-off-by: Avior <florian.bouillon@delta-wings.net>
This commit is contained in:
Florian Bouillon 2021-02-19 17:19:48 +01:00
parent b2248425ca
commit 941916eced
12 changed files with 18 additions and 5 deletions

View File

@ -23,9 +23,12 @@ import retrofit2.Callback
import retrofit2.Response
import kotlin.collections.ArrayList
class CountrySelectorActivity : AppCompatActivity() {
companion object {
const val PROGRESS_BAR_TITLE = "Récupération des pays..."
}
private var data: ArrayList<Country> = ArrayList()
override fun onCreate(savedInstanceState: Bundle?) {
@ -35,7 +38,7 @@ class CountrySelectorActivity : AppCompatActivity() {
// Progress Bar
val progressDialog = ProgressDialog(this)
progressDialog.setTitle("Récupération des pays...")
progressDialog.setTitle(PROGRESS_BAR_TITLE)
progressDialog.setCancelable(false)
progressDialog.show()

View File

@ -12,20 +12,20 @@ import com.example.ca_contest.dao.AppDatabaseHelper
import java.util.*
class MainActivity : AppCompatActivity() {
private lateinit var countryAdapter: HomepageCountryAdapter
// private lateinit var imageView: ImageView
override fun onCreate(savedInstanceState: Bundle?)
{
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
// Initialize RecyclerView
val recycler = findViewById<RecyclerView>(R.id.list_country)
recycler.setHasFixedSize(true)
val layoutManager = LinearLayoutManager(this)
recycler.layoutManager = layoutManager
// Fetch Items in Database
val adapter = HomepageCountryAdapter(
AppDatabaseHelper
.getDatabase(this)

View File

@ -11,6 +11,7 @@ import androidx.recyclerview.widget.RecyclerView
import com.example.ca_contest.api.Country
import com.squareup.picasso.Picasso
// Adapter for the CountrySelector
class CountryAdapter(list: ArrayList<Country>) : RecyclerView.Adapter<CountryAdapter.CountryViewHolder>() {
private var list: ArrayList<Country> = ArrayList()

View File

@ -11,6 +11,7 @@ import androidx.recyclerview.widget.RecyclerView
import com.example.ca_contest.dao.Country
import com.squareup.picasso.Picasso
// Adapter for the homepage
class HomepageCountryAdapter(list: List<Country>) : RecyclerView.Adapter<HomepageCountryAdapter.CountryViewHolder>() {
private var list: List<Country> = ArrayList()

View File

@ -6,6 +6,7 @@ import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
// API Client
object ApiClient {
var BASE_URL:String="https://restcountries.eu/"

View File

@ -3,6 +3,7 @@ package com.example.ca_contest.api
import retrofit2.Call
import retrofit2.http.GET
// functions to get the differents elements
interface ApiInterface {
@GET("rest/v2/all")

View File

@ -3,6 +3,7 @@ package com.example.ca_contest.api
import com.google.gson.annotations.Expose
import com.google.gson.annotations.SerializedName
// Model for The API
data class Country(
@Expose
@SerializedName("name")

View File

@ -5,6 +5,7 @@ import androidx.room.Database
import androidx.room.RoomDatabase
import androidx.room.TypeConverters
// Database Manager
@Database(entities = [Country::class], version = 1)
@TypeConverters(Converters::class)
abstract class AppDatabase : RoomDatabase()

View File

@ -3,6 +3,7 @@ package com.example.ca_contest.dao
import android.content.Context
import androidx.room.Room
// Helper for the Database System
class AppDatabaseHelper(context: Context)
{
// Bloc de code "static" :

View File

@ -4,6 +4,7 @@ import androidx.room.Entity
import androidx.room.PrimaryKey
import java.util.Date
// Model for the country
@Entity(tableName = "country")
class Country(
@PrimaryKey(autoGenerate = true)

View File

@ -2,9 +2,10 @@ package com.example.ca_contest.dao
import androidx.room.*
// DAO for the Country
@Dao
abstract class CountryDAO {
@Query("SELECT * FROM country")
@Query("SELECT * FROM country ORDER BY date ASC")
abstract fun getListCountry(): List<Country>
@Insert
abstract fun insert(vararg country: Country)

View File

@ -3,6 +3,7 @@ package com.example.ca_contest.libs
import androidx.room.TypeConverter
import java.util.*
// Convert from and to a Java Date Object to a SQL Date
class Converters {
@TypeConverter
fun fromTimestamp(value: Long?): Date? {