mirror of
https://github.com/Aviortheking/CA-Mad-Rental.git
synced 2025-04-22 19:02:15 +00:00
Merge pull request #3 from Aviortheking/first_view
Ajout de multiple commentaires
This commit is contained in:
commit
b24b8426c3
@ -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()
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
|
@ -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/"
|
||||
|
@ -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")
|
||||
|
@ -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")
|
||||
|
@ -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()
|
||||
|
@ -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" :
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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? {
|
||||
|
Loading…
x
Reference in New Issue
Block a user