From 6177e0d51f13dc1ecdbcceac1acdbe8925bd4ab8 Mon Sep 17 00:00:00 2001 From: Raphael Date: Mon, 10 Mar 2025 16:54:05 +0100 Subject: [PATCH] many things done --- .../com/dreamteam/timelapse/ImageAdapter.kt | 124 +++++++-------- .../dreamteam/timelapse/data/Confirmation.kt | 14 +- .../dreamteam/timelapse/data/Measurement.kt | 26 +-- .../com/dreamteam/timelapse/data/Project.kt | 148 +++++++++--------- .../com/dreamteam/timelapse/data/Video.kt | 22 +-- app/src/main/res/layout/item_image.xml | 12 +- .../layout/project_create_dialog_layout.xml | 60 +++---- 7 files changed, 203 insertions(+), 203 deletions(-) diff --git a/app/src/main/java/com/dreamteam/timelapse/ImageAdapter.kt b/app/src/main/java/com/dreamteam/timelapse/ImageAdapter.kt index bcf452a..6dc97ff 100644 --- a/app/src/main/java/com/dreamteam/timelapse/ImageAdapter.kt +++ b/app/src/main/java/com/dreamteam/timelapse/ImageAdapter.kt @@ -1,62 +1,62 @@ -package com.dreamteam.timelapse - -import android.content.Context -import android.graphics.Bitmap -import android.util.Log -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import android.widget.ImageView -import android.widget.Toast -import androidx.recyclerview.widget.RecyclerView -import com.bumptech.glide.Glide -import com.bumptech.glide.request.target.SimpleTarget -import java.io.File -import java.io.FileOutputStream -import java.io.IOException -import com.bumptech.glide.request.transition.Transition - - - -class ImageAdapter(private val imageUrls: List) : RecyclerView.Adapter() { - - // ViewHolder qui contient l'ImageView - class ImageViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { - val imageView: ImageView = itemView.findViewById(R.id.imageView) - } - - override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ImageViewHolder { - val view = LayoutInflater.from(parent.context).inflate(R.layout.item_image, parent, false) - return ImageViewHolder(view) - } - - override fun onBindViewHolder(holder: ImageViewHolder, position: Int) { - val imageUrl = imageUrls[position] - //Log.e("ImageAdapter", imageUrl) - Glide.with(holder.itemView.context) - .load(imageUrl) // Charge l'image via Glide - .into(holder.imageView) // Affiche l'image dans l'ImageView - } - private fun downloadImage(url: String, context: Context) { - Glide.with(context) - .asBitmap() - .load(url) - .into(object : SimpleTarget() { - override fun onResourceReady(resource: Bitmap, transition: Transition?) { - // Save the image to the app's internal storage - val file = File(context.filesDir, "downloaded_image.jpg") - try { - val fileOutputStream = FileOutputStream(file) - resource.compress(Bitmap.CompressFormat.JPEG, 100, fileOutputStream) - fileOutputStream.flush() - fileOutputStream.close() - Toast.makeText(context, "Image downloaded successfully", Toast.LENGTH_SHORT).show() - } catch (e: IOException) { - e.printStackTrace() - Toast.makeText(context, "Error downloading image", Toast.LENGTH_SHORT).show() - } - } - }) - } - override fun getItemCount(): Int = imageUrls.size -} +package com.dreamteam.timelapse + +import android.content.Context +import android.graphics.Bitmap +import android.util.Log +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.ImageView +import android.widget.Toast +import androidx.recyclerview.widget.RecyclerView +import com.bumptech.glide.Glide +import com.bumptech.glide.request.target.SimpleTarget +import java.io.File +import java.io.FileOutputStream +import java.io.IOException +import com.bumptech.glide.request.transition.Transition + + + +class ImageAdapter(private val imageUrls: List) : RecyclerView.Adapter() { + + // ViewHolder qui contient l'ImageView + class ImageViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { + val imageView: ImageView = itemView.findViewById(R.id.imageView) + } + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ImageViewHolder { + val view = LayoutInflater.from(parent.context).inflate(R.layout.item_image, parent, false) + return ImageViewHolder(view) + } + + override fun onBindViewHolder(holder: ImageViewHolder, position: Int) { + val imageUrl = imageUrls[position] + //Log.e("ImageAdapter", imageUrl) + Glide.with(holder.itemView.context) + .load(imageUrl) // Charge l'image via Glide + .into(holder.imageView) // Affiche l'image dans l'ImageView + } + private fun downloadImage(url: String, context: Context) { + Glide.with(context) + .asBitmap() + .load(url) + .into(object : SimpleTarget() { + override fun onResourceReady(resource: Bitmap, transition: Transition?) { + // Save the image to the app's internal storage + val file = File(context.filesDir, "downloaded_image.jpg") + try { + val fileOutputStream = FileOutputStream(file) + resource.compress(Bitmap.CompressFormat.JPEG, 100, fileOutputStream) + fileOutputStream.flush() + fileOutputStream.close() + Toast.makeText(context, "Image downloaded successfully", Toast.LENGTH_SHORT).show() + } catch (e: IOException) { + e.printStackTrace() + Toast.makeText(context, "Error downloading image", Toast.LENGTH_SHORT).show() + } + } + }) + } + override fun getItemCount(): Int = imageUrls.size +} diff --git a/app/src/main/java/com/dreamteam/timelapse/data/Confirmation.kt b/app/src/main/java/com/dreamteam/timelapse/data/Confirmation.kt index 03efc2d..2ea969b 100644 --- a/app/src/main/java/com/dreamteam/timelapse/data/Confirmation.kt +++ b/app/src/main/java/com/dreamteam/timelapse/data/Confirmation.kt @@ -1,8 +1,8 @@ -package com.dreamteam.timelapse.data - -data class Confirmation ( - val message: String, - val id: Int -){ - +package com.dreamteam.timelapse.data + +data class Confirmation ( + val message: String, + val id: Int +){ + } \ No newline at end of file diff --git a/app/src/main/java/com/dreamteam/timelapse/data/Measurement.kt b/app/src/main/java/com/dreamteam/timelapse/data/Measurement.kt index 7a88cef..24da778 100644 --- a/app/src/main/java/com/dreamteam/timelapse/data/Measurement.kt +++ b/app/src/main/java/com/dreamteam/timelapse/data/Measurement.kt @@ -1,14 +1,14 @@ -package com.dreamteam.timelapse.data - -import java.util.Date - -data class Measurement( - val id: Int, - val project_id: Int, - val timestamp: Date, - val path: String, - val temperature: Float, - val humidity: Float, - val order_id: Int -) { +package com.dreamteam.timelapse.data + +import java.util.Date + +data class Measurement( + val id: Int, + val project_id: Int, + val timestamp: Date, + val path: String, + val temperature: Float, + val humidity: Float, + val order_id: Int +) { } \ No newline at end of file diff --git a/app/src/main/java/com/dreamteam/timelapse/data/Project.kt b/app/src/main/java/com/dreamteam/timelapse/data/Project.kt index 5a4370f..62010fe 100644 --- a/app/src/main/java/com/dreamteam/timelapse/data/Project.kt +++ b/app/src/main/java/com/dreamteam/timelapse/data/Project.kt @@ -1,74 +1,74 @@ -package com.dreamteam.timelapse.data - -import android.os.Parcel -import android.os.Parcelable -import android.util.Log -import com.dreamteam.timelapse.R -import java.util.Date - -//{ -// "id": 1, -// "creation": "2024-10-24T13:46:04.513Z", -// "status": "test", -// "description": "Projet de Test", -// "titre": "Test Project" -//} -data class Project( - val id: Int, - val name: String, - val description: String, - val start_date: Date, - val status: Int, - val thumbnail_url: String? -) : Parcelable { - - fun getStatusText(): String{ - Log.i("Project", "Status $status being trasnlated") - val statusArr = arrayOf("Brouillon", "En Cours", "Terminé", "Annulé") - return statusArr[status] - } - fun getStatusColor(): Int{ - return when (status) { - 0 -> R.color.brouillon - 1 -> R.color.en_cours - 2 -> R.color.termine - 3 -> R.color.annule - else -> R.color.default_badge - } - } - - // Constructor to recreate from Parcel - constructor(parcel: Parcel) : this( - parcel.readInt(), - parcel.readString() ?: "", - parcel.readString() ?: "", - Date(parcel.readLong()), - parcel.readInt(), - parcel.readString() - ) - - // Write object to Parcel - override fun writeToParcel(parcel: Parcel, flags: Int) { - parcel.writeInt(id) - parcel.writeString(name) - parcel.writeString(description) - parcel.writeLong(start_date.time) - parcel.writeInt(status) - } - - // Describe the contents of the Parcel - override fun describeContents(): Int = 0 - - companion object CREATOR : Parcelable.Creator { - override fun createFromParcel(parcel: Parcel): Project { - return Project(parcel) - } - - override fun newArray(size: Int): Array { - return arrayOfNulls(size) - } - } -// fun getThumbnail(): String { -// return images[0] -// } -} +package com.dreamteam.timelapse.data + +import android.os.Parcel +import android.os.Parcelable +import android.util.Log +import com.dreamteam.timelapse.R +import java.util.Date + +//{ +// "id": 1, +// "creation": "2024-10-24T13:46:04.513Z", +// "status": "test", +// "description": "Projet de Test", +// "titre": "Test Project" +//} +data class Project( + val id: Int, + val name: String, + val description: String, + val start_date: Date, + val status: Int, + val thumbnail_url: String? +) : Parcelable { + + fun getStatusText(): String{ + Log.i("Project", "Status $status being trasnlated") + val statusArr = arrayOf("Brouillon", "En Cours", "Terminé", "Annulé") + return statusArr[status] + } + fun getStatusColor(): Int{ + return when (status) { + 0 -> R.color.brouillon + 1 -> R.color.en_cours + 2 -> R.color.termine + 3 -> R.color.annule + else -> R.color.default_badge + } + } + + // Constructor to recreate from Parcel + constructor(parcel: Parcel) : this( + parcel.readInt(), + parcel.readString() ?: "", + parcel.readString() ?: "", + Date(parcel.readLong()), + parcel.readInt(), + parcel.readString() + ) + + // Write object to Parcel + override fun writeToParcel(parcel: Parcel, flags: Int) { + parcel.writeInt(id) + parcel.writeString(name) + parcel.writeString(description) + parcel.writeLong(start_date.time) + parcel.writeInt(status) + } + + // Describe the contents of the Parcel + override fun describeContents(): Int = 0 + + companion object CREATOR : Parcelable.Creator { + override fun createFromParcel(parcel: Parcel): Project { + return Project(parcel) + } + + override fun newArray(size: Int): Array { + return arrayOfNulls(size) + } + } +// fun getThumbnail(): String { +// return images[0] +// } +} diff --git a/app/src/main/java/com/dreamteam/timelapse/data/Video.kt b/app/src/main/java/com/dreamteam/timelapse/data/Video.kt index 8e65ed9..fb1fa93 100644 --- a/app/src/main/java/com/dreamteam/timelapse/data/Video.kt +++ b/app/src/main/java/com/dreamteam/timelapse/data/Video.kt @@ -1,12 +1,12 @@ -package com.dreamteam.timelapse.data - -data class Video ( - val id: Int, - val project_id: Int, - val measurement_ids: List, - val video_file: String?, - val resolution:String, - val duration: Int, - val status: Int, //0 pas fini, 1 fini - val name: String +package com.dreamteam.timelapse.data + +data class Video ( + val id: Int, + val project_id: Int, + val measurement_ids: List, + val video_file: String?, + val resolution:String, + val duration: Int, + val status: Int, //0 pas fini, 1 fini + val name: String ){} \ No newline at end of file diff --git a/app/src/main/res/layout/item_image.xml b/app/src/main/res/layout/item_image.xml index d996c76..8f7c67e 100644 --- a/app/src/main/res/layout/item_image.xml +++ b/app/src/main/res/layout/item_image.xml @@ -1,7 +1,7 @@ - - + \ No newline at end of file diff --git a/app/src/main/res/layout/project_create_dialog_layout.xml b/app/src/main/res/layout/project_create_dialog_layout.xml index 30d0ab0..3788a40 100644 --- a/app/src/main/res/layout/project_create_dialog_layout.xml +++ b/app/src/main/res/layout/project_create_dialog_layout.xml @@ -1,31 +1,31 @@ - - - - - - - - - + + + + + + + + + \ No newline at end of file