mirror of
https://github.com/Aviortheking/CA-Mad-Rental.git
synced 2025-04-23 19:32:13 +00:00
Ajout de multiple commentaires
Signed-off-by: Avior <florian.bouillon@delta-wings.net>
This commit is contained in:
parent
b2248425ca
commit
941916eced
@ -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()
|
||||||
|
|
||||||
|
@ -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)
|
||||||
|
@ -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()
|
||||||
|
@ -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()
|
||||||
|
@ -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/"
|
||||||
|
@ -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")
|
||||||
|
@ -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")
|
||||||
|
@ -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()
|
||||||
|
@ -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" :
|
||||||
|
@ -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)
|
||||||
|
@ -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)
|
||||||
|
@ -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? {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user