mirror of
https://github.com/Aviortheking/CA_Contest.git
synced 2025-04-22 10:52:11 +00:00
first view
This commit is contained in:
parent
d7702dc164
commit
f0dfb2e67c
@ -1,6 +1,8 @@
|
||||
plugins {
|
||||
id 'com.android.application'
|
||||
id 'kotlin-android'
|
||||
id 'kotlin-android-extensions'
|
||||
id 'kotlin-kapt'
|
||||
}
|
||||
|
||||
android {
|
||||
@ -14,6 +16,14 @@ android {
|
||||
versionName "1.0"
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
|
||||
javaCompileOptions {
|
||||
annotationProcessorOptions {
|
||||
arguments =
|
||||
["room.schemaLocation": "$projectDir/schemas".toString()]
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
@ -36,9 +46,18 @@ dependencies {
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||
implementation 'androidx.core:core-ktx:1.3.2'
|
||||
implementation 'androidx.appcompat:appcompat:1.2.0'
|
||||
implementation 'com.google.android.material:material:1.2.1'
|
||||
implementation 'com.google.android.material:material:1.3.0'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
|
||||
implementation 'androidx.recyclerview:recyclerview:1.1.0'
|
||||
implementation 'com.google.android.material:material:1.3.0'
|
||||
implementation 'androidx.room:room-runtime:2.2.6'
|
||||
implementation 'androidx.preference:preference:1.1.1'
|
||||
implementation 'androidx.room:room-runtime:2.2.6'
|
||||
implementation 'com.squareup.picasso:picasso:2.71828'
|
||||
implementation 'com.squareup.okhttp:okhttp:2.2.0'
|
||||
implementation 'com.squareup.okhttp:okhttp-urlconnection:2.2.0'
|
||||
testImplementation 'junit:junit:4.+'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
|
||||
annotationProcessor 'androidx.room:room-compiler:2.2.6'
|
||||
}
|
@ -1,7 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.example.ca_contest">
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
@ -9,13 +10,15 @@
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/Theme.CA_Contest">
|
||||
<activity android:name=".MainActivity">
|
||||
<activity android:name=".ListCountryActivity">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity android:name=".MainActivity">
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
14
app/src/main/java/com/example/ca_contest/Country.kt
Normal file
14
app/src/main/java/com/example/ca_contest/Country.kt
Normal file
@ -0,0 +1,14 @@
|
||||
package com.example.ca_contest
|
||||
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
import java.text.SimpleDateFormat
|
||||
|
||||
@Entity(tableName = "country")
|
||||
class Country(
|
||||
@PrimaryKey(autoGenerate = true)
|
||||
val countryId: Long = 0,
|
||||
val country: String? = null,
|
||||
val capitalCity: String? = null,
|
||||
val continent: String? = null,
|
||||
val date: SimpleDateFormat? = null)
|
40
app/src/main/java/com/example/ca_contest/CountryAdapter.kt
Normal file
40
app/src/main/java/com/example/ca_contest/CountryAdapter.kt
Normal file
@ -0,0 +1,40 @@
|
||||
package com.example.ca_contest
|
||||
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.TextView
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
|
||||
class CountryAdapter(private var listCountry: MutableList<Country>) :
|
||||
RecyclerView.Adapter<CountryAdapter.CountryViewHolder>()
|
||||
{
|
||||
// Crée chaque vue item à afficher :
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CountryViewHolder
|
||||
{
|
||||
val viewCourse = LayoutInflater.from(parent.context)
|
||||
.inflate(R.layout.item_list, parent, false)
|
||||
return CountryViewHolder(viewCourse)
|
||||
}
|
||||
|
||||
// Renseigne le contenu de chaque vue item :
|
||||
override fun onBindViewHolder(holder: CountryViewHolder, position: Int)
|
||||
{
|
||||
holder.textViewLibelleCourse.text = listCountry[position].country
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int = listCountry.size
|
||||
// ViewHolder :
|
||||
inner class CountryViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView)
|
||||
{
|
||||
val textViewLibelleCourse: TextView = itemView.findViewById(R.id.list_country)
|
||||
init
|
||||
{
|
||||
textViewLibelleCourse.setOnClickListener {
|
||||
val country = listCountry[adapterPosition]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
package com.example.ca_contest
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.ContextWrapper
|
||||
import android.content.Intent
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.View
|
||||
import android.widget.ImageView
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import com.example.ca_contest.dao.AppDatabaseHelper
|
||||
import com.squareup.picasso.Picasso;
|
||||
import kotlinx.android.synthetic.main.activity_list_country.*
|
||||
import java.io.File
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
import kotlin.collections.ArrayList
|
||||
|
||||
class ListCountryActivity : AppCompatActivity() {
|
||||
private lateinit var countryAdapter: CountryAdapter
|
||||
// private lateinit var imageView: ImageView
|
||||
@SuppressLint("SimpleDateFormat")
|
||||
override fun onCreate(savedInstanceState: Bundle?)
|
||||
{
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_list_country)
|
||||
|
||||
// imageView = findViewById(R.id.image)
|
||||
// à ajouter pour de meilleures performances :
|
||||
list_country.setHasFixedSize(true)
|
||||
|
||||
// layout manager, décrivant comment les items sont disposés :
|
||||
val layoutManager = LinearLayoutManager(this)
|
||||
list_country.layoutManager = layoutManager
|
||||
// contenu d'exemple :
|
||||
val listCountry: List<Country> = AppDatabaseHelper
|
||||
.getDatabase(this)
|
||||
.countryDAO()
|
||||
.getListCountry()
|
||||
|
||||
// Picasso.get()
|
||||
// .load("http://www.geognos.com/api/en/countries/flag/FR.png")
|
||||
// .fit()
|
||||
// .centerCrop() // ou centerInside()
|
||||
// .into(imageView)
|
||||
|
||||
}
|
||||
|
||||
fun addCountry(view: View) {
|
||||
// val intent = Intent(this, CountrySelectorActivity::class.java)
|
||||
// startActivity(intent)
|
||||
//
|
||||
// finish()
|
||||
}
|
||||
|
||||
fun deleteCountry(view: View) {
|
||||
|
||||
}
|
||||
|
||||
}
|
11
app/src/main/java/com/example/ca_contest/dao/AppDatabase.kt
Normal file
11
app/src/main/java/com/example/ca_contest/dao/AppDatabase.kt
Normal file
@ -0,0 +1,11 @@
|
||||
package com.example.ca_contest.dao
|
||||
|
||||
import androidx.room.Database
|
||||
import androidx.room.RoomDatabase
|
||||
import com.example.ca_contest.Country
|
||||
|
||||
@Database(entities = [Country::class], version = 1)
|
||||
abstract class AppDatabase : RoomDatabase()
|
||||
{
|
||||
abstract fun countryDAO(): CountryDAO
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package com.example.ca_contest.dao
|
||||
|
||||
import android.content.Context
|
||||
import androidx.room.Room
|
||||
|
||||
class AppDatabaseHelper(context: Context)
|
||||
{
|
||||
// Bloc de code "static" :
|
||||
companion object
|
||||
{
|
||||
// Helper :
|
||||
private lateinit var databaseHelper: AppDatabaseHelper
|
||||
// Getter instance :
|
||||
fun getDatabase(context: Context): AppDatabase
|
||||
{
|
||||
if (!::databaseHelper.isInitialized)
|
||||
{
|
||||
databaseHelper = AppDatabaseHelper(context)
|
||||
}
|
||||
return databaseHelper.database
|
||||
}
|
||||
}
|
||||
// Base de données :
|
||||
val database: AppDatabase = Room
|
||||
.databaseBuilder(context.applicationContext, AppDatabase::class.java, "courses.db")
|
||||
.allowMainThreadQueries()
|
||||
.build()
|
||||
}
|
16
app/src/main/java/com/example/ca_contest/dao/CountryDAO.kt
Normal file
16
app/src/main/java/com/example/ca_contest/dao/CountryDAO.kt
Normal file
@ -0,0 +1,16 @@
|
||||
package com.example.ca_contest.dao
|
||||
|
||||
import androidx.room.*
|
||||
import com.example.ca_contest.Country
|
||||
|
||||
@Dao
|
||||
abstract class CountryDAO {
|
||||
@Query("SELECT * FROM country")
|
||||
abstract fun getListCountry(): List<Country>
|
||||
@Insert
|
||||
abstract fun insert(vararg country: Country)
|
||||
@Update
|
||||
abstract fun update(vararg country: Country)
|
||||
@Delete
|
||||
abstract fun delete(vararg country: Country)
|
||||
}
|
11
app/src/main/res/drawable-anydpi/ic_trash.xml
Normal file
11
app/src/main/res/drawable-anydpi/ic_trash.xml
Normal file
@ -0,0 +1,11 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="#E5446E"
|
||||
android:alpha="0.8">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M6,19c0,1.1 0.9,2 2,2h8c1.1,0 2,-0.9 2,-2V7H6v12zM19,4h-3.5l-1,-1h-5l-1,1H5v2h14V4z"/>
|
||||
</vector>
|
BIN
app/src/main/res/drawable-hdpi/ic_trash.png
Normal file
BIN
app/src/main/res/drawable-hdpi/ic_trash.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 206 B |
BIN
app/src/main/res/drawable-mdpi/ic_trash.png
Normal file
BIN
app/src/main/res/drawable-mdpi/ic_trash.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 146 B |
BIN
app/src/main/res/drawable-xhdpi/ic_trash.png
Normal file
BIN
app/src/main/res/drawable-xhdpi/ic_trash.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 205 B |
BIN
app/src/main/res/drawable-xxhdpi/ic_trash.png
Normal file
BIN
app/src/main/res/drawable-xxhdpi/ic_trash.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 252 B |
36
app/src/main/res/layout/activity_list_country.xml
Normal file
36
app/src/main/res/layout/activity_list_country.xml
Normal file
@ -0,0 +1,36 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".ListCountryActivity">
|
||||
|
||||
<!-- <ImageView-->
|
||||
<!-- android:id="@+id/image"-->
|
||||
<!-- android:layout_width="match_parent"-->
|
||||
<!-- android:layout_height="match_parent"-->
|
||||
<!-- tools:ignore="MissingConstraints" />-->
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/list_country"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintBottom_toTopOf="@id/bouton_retour"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/bouton_retour"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="50dp"
|
||||
android:background="@color/purple_200"
|
||||
android:onClick="addCountry"
|
||||
android:text="AJOUTER UN PAYS"
|
||||
android:textColor="@android:color/white"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"/>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
38
app/src/main/res/layout/item_list.xml
Normal file
38
app/src/main/res/layout/item_list.xml
Normal file
@ -0,0 +1,38 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/list_country"
|
||||
android:layout_width="359dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="center_horizontal"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/delete"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@color/white"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
android:onClick="deleteCountry"
|
||||
android:src="@drawable/ic_trash" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</FrameLayout>
|
Loading…
x
Reference in New Issue
Block a user