Merge pull request #3 from Aviortheking/first_view

Ajout de multiple commentaires
This commit is contained in:
Florian Bouillon 2021-02-19 17:20:37 +01:00 committed by GitHub
commit dab68ee0b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 18 additions and 5 deletions

View File

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

View File

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

View File

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

View File

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

View File

@ -3,6 +3,7 @@ package com.example.ca_contest.api
import retrofit2.Call import retrofit2.Call
import retrofit2.http.GET import retrofit2.http.GET
// functions to get the differents elements
interface ApiInterface { interface ApiInterface {
@GET("rest/v2/all") @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.Expose
import com.google.gson.annotations.SerializedName import com.google.gson.annotations.SerializedName
// Model for The API
data class Country( data class Country(
@Expose @Expose
@SerializedName("name") @SerializedName("name")

View File

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

View File

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

View File

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

View File

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

View File

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