diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml
new file mode 100644
index 0000000..7643783
--- /dev/null
+++ b/.idea/codeStyles/Project.xml
@@ -0,0 +1,123 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ xmlns:android
+
+ ^$
+
+
+
+
+
+
+
+
+ xmlns:.*
+
+ ^$
+
+
+ BY_NAME
+
+
+
+
+
+
+ .*:id
+
+ http://schemas.android.com/apk/res/android
+
+
+
+
+
+
+
+
+ .*:name
+
+ http://schemas.android.com/apk/res/android
+
+
+
+
+
+
+
+
+ name
+
+ ^$
+
+
+
+
+
+
+
+
+ style
+
+ ^$
+
+
+
+
+
+
+
+
+ .*
+
+ ^$
+
+
+ BY_NAME
+
+
+
+
+
+
+ .*
+
+ http://schemas.android.com/apk/res/android
+
+
+ ANDROID_ATTRIBUTE_ORDER
+
+
+
+
+
+
+ .*
+
+ .*
+
+
+ BY_NAME
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml
new file mode 100644
index 0000000..7643783
--- /dev/null
+++ b/.idea/codeStyles/Project.xml
@@ -0,0 +1,123 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ xmlns:android
+
+ ^$
+
+
+
+
+
+
+
+
+ xmlns:.*
+
+ ^$
+
+
+ BY_NAME
+
+
+
+
+
+
+ .*:id
+
+ http://schemas.android.com/apk/res/android
+
+
+
+
+
+
+
+
+ .*:name
+
+ http://schemas.android.com/apk/res/android
+
+
+
+
+
+
+
+
+ name
+
+ ^$
+
+
+
+
+
+
+
+
+ style
+
+ ^$
+
+
+
+
+
+
+
+
+ .*
+
+ ^$
+
+
+ BY_NAME
+
+
+
+
+
+
+ .*
+
+ http://schemas.android.com/apk/res/android
+
+
+ ANDROID_ATTRIBUTE_ORDER
+
+
+
+
+
+
+ .*
+
+ .*
+
+
+ BY_NAME
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml
new file mode 100644
index 0000000..79ee123
--- /dev/null
+++ b/.idea/codeStyles/codeStyleConfig.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml
new file mode 100644
index 0000000..7643783
--- /dev/null
+++ b/.idea/codeStyles/Project.xml
@@ -0,0 +1,123 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ xmlns:android
+
+ ^$
+
+
+
+
+
+
+
+
+ xmlns:.*
+
+ ^$
+
+
+ BY_NAME
+
+
+
+
+
+
+ .*:id
+
+ http://schemas.android.com/apk/res/android
+
+
+
+
+
+
+
+
+ .*:name
+
+ http://schemas.android.com/apk/res/android
+
+
+
+
+
+
+
+
+ name
+
+ ^$
+
+
+
+
+
+
+
+
+ style
+
+ ^$
+
+
+
+
+
+
+
+
+ .*
+
+ ^$
+
+
+ BY_NAME
+
+
+
+
+
+
+ .*
+
+ http://schemas.android.com/apk/res/android
+
+
+ ANDROID_ATTRIBUTE_ORDER
+
+
+
+
+
+
+ .*
+
+ .*
+
+
+ BY_NAME
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml
new file mode 100644
index 0000000..79ee123
--- /dev/null
+++ b/.idea/codeStyles/codeStyleConfig.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
new file mode 100644
index 0000000..fb7f4a8
--- /dev/null
+++ b/.idea/compiler.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml
new file mode 100644
index 0000000..7643783
--- /dev/null
+++ b/.idea/codeStyles/Project.xml
@@ -0,0 +1,123 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ xmlns:android
+
+ ^$
+
+
+
+
+
+
+
+
+ xmlns:.*
+
+ ^$
+
+
+ BY_NAME
+
+
+
+
+
+
+ .*:id
+
+ http://schemas.android.com/apk/res/android
+
+
+
+
+
+
+
+
+ .*:name
+
+ http://schemas.android.com/apk/res/android
+
+
+
+
+
+
+
+
+ name
+
+ ^$
+
+
+
+
+
+
+
+
+ style
+
+ ^$
+
+
+
+
+
+
+
+
+ .*
+
+ ^$
+
+
+ BY_NAME
+
+
+
+
+
+
+ .*
+
+ http://schemas.android.com/apk/res/android
+
+
+ ANDROID_ATTRIBUTE_ORDER
+
+
+
+
+
+
+ .*
+
+ .*
+
+
+ BY_NAME
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml
new file mode 100644
index 0000000..79ee123
--- /dev/null
+++ b/.idea/codeStyles/codeStyleConfig.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
new file mode 100644
index 0000000..fb7f4a8
--- /dev/null
+++ b/.idea/compiler.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/gradle.xml b/.idea/gradle.xml
new file mode 100644
index 0000000..36394ad
--- /dev/null
+++ b/.idea/gradle.xml
@@ -0,0 +1,19 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml
new file mode 100644
index 0000000..7643783
--- /dev/null
+++ b/.idea/codeStyles/Project.xml
@@ -0,0 +1,123 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ xmlns:android
+
+ ^$
+
+
+
+
+
+
+
+
+ xmlns:.*
+
+ ^$
+
+
+ BY_NAME
+
+
+
+
+
+
+ .*:id
+
+ http://schemas.android.com/apk/res/android
+
+
+
+
+
+
+
+
+ .*:name
+
+ http://schemas.android.com/apk/res/android
+
+
+
+
+
+
+
+
+ name
+
+ ^$
+
+
+
+
+
+
+
+
+ style
+
+ ^$
+
+
+
+
+
+
+
+
+ .*
+
+ ^$
+
+
+ BY_NAME
+
+
+
+
+
+
+ .*
+
+ http://schemas.android.com/apk/res/android
+
+
+ ANDROID_ATTRIBUTE_ORDER
+
+
+
+
+
+
+ .*
+
+ .*
+
+
+ BY_NAME
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml
new file mode 100644
index 0000000..79ee123
--- /dev/null
+++ b/.idea/codeStyles/codeStyleConfig.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
new file mode 100644
index 0000000..fb7f4a8
--- /dev/null
+++ b/.idea/compiler.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/gradle.xml b/.idea/gradle.xml
new file mode 100644
index 0000000..36394ad
--- /dev/null
+++ b/.idea/gradle.xml
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..cb1a633
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml
new file mode 100644
index 0000000..7643783
--- /dev/null
+++ b/.idea/codeStyles/Project.xml
@@ -0,0 +1,123 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ xmlns:android
+
+ ^$
+
+
+
+
+
+
+
+
+ xmlns:.*
+
+ ^$
+
+
+ BY_NAME
+
+
+
+
+
+
+ .*:id
+
+ http://schemas.android.com/apk/res/android
+
+
+
+
+
+
+
+
+ .*:name
+
+ http://schemas.android.com/apk/res/android
+
+
+
+
+
+
+
+
+ name
+
+ ^$
+
+
+
+
+
+
+
+
+ style
+
+ ^$
+
+
+
+
+
+
+
+
+ .*
+
+ ^$
+
+
+ BY_NAME
+
+
+
+
+
+
+ .*
+
+ http://schemas.android.com/apk/res/android
+
+
+ ANDROID_ATTRIBUTE_ORDER
+
+
+
+
+
+
+ .*
+
+ .*
+
+
+ BY_NAME
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml
new file mode 100644
index 0000000..79ee123
--- /dev/null
+++ b/.idea/codeStyles/codeStyleConfig.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
new file mode 100644
index 0000000..fb7f4a8
--- /dev/null
+++ b/.idea/compiler.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/gradle.xml b/.idea/gradle.xml
new file mode 100644
index 0000000..36394ad
--- /dev/null
+++ b/.idea/gradle.xml
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..cb1a633
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..94a25f7
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml
new file mode 100644
index 0000000..7643783
--- /dev/null
+++ b/.idea/codeStyles/Project.xml
@@ -0,0 +1,123 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ xmlns:android
+
+ ^$
+
+
+
+
+
+
+
+
+ xmlns:.*
+
+ ^$
+
+
+ BY_NAME
+
+
+
+
+
+
+ .*:id
+
+ http://schemas.android.com/apk/res/android
+
+
+
+
+
+
+
+
+ .*:name
+
+ http://schemas.android.com/apk/res/android
+
+
+
+
+
+
+
+
+ name
+
+ ^$
+
+
+
+
+
+
+
+
+ style
+
+ ^$
+
+
+
+
+
+
+
+
+ .*
+
+ ^$
+
+
+ BY_NAME
+
+
+
+
+
+
+ .*
+
+ http://schemas.android.com/apk/res/android
+
+
+ ANDROID_ATTRIBUTE_ORDER
+
+
+
+
+
+
+ .*
+
+ .*
+
+
+ BY_NAME
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml
new file mode 100644
index 0000000..79ee123
--- /dev/null
+++ b/.idea/codeStyles/codeStyleConfig.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
new file mode 100644
index 0000000..fb7f4a8
--- /dev/null
+++ b/.idea/compiler.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/gradle.xml b/.idea/gradle.xml
new file mode 100644
index 0000000..36394ad
--- /dev/null
+++ b/.idea/gradle.xml
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..cb1a633
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..94a25f7
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/build.gradle b/app/build.gradle
index 1ec893a..655a456 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -68,6 +68,9 @@
implementation "androidx.compose.material:material:$composeVersion"
implementation "androidx.compose.foundation:foundation-layout:$composeVersion"
+ // Glide
+ implementation "com.github.bumptech.glide:compose:1.0.0-alpha.1"
+
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0'
diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml
new file mode 100644
index 0000000..7643783
--- /dev/null
+++ b/.idea/codeStyles/Project.xml
@@ -0,0 +1,123 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ xmlns:android
+
+ ^$
+
+
+
+
+
+
+
+
+ xmlns:.*
+
+ ^$
+
+
+ BY_NAME
+
+
+
+
+
+
+ .*:id
+
+ http://schemas.android.com/apk/res/android
+
+
+
+
+
+
+
+
+ .*:name
+
+ http://schemas.android.com/apk/res/android
+
+
+
+
+
+
+
+
+ name
+
+ ^$
+
+
+
+
+
+
+
+
+ style
+
+ ^$
+
+
+
+
+
+
+
+
+ .*
+
+ ^$
+
+
+ BY_NAME
+
+
+
+
+
+
+ .*
+
+ http://schemas.android.com/apk/res/android
+
+
+ ANDROID_ATTRIBUTE_ORDER
+
+
+
+
+
+
+ .*
+
+ .*
+
+
+ BY_NAME
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml
new file mode 100644
index 0000000..79ee123
--- /dev/null
+++ b/.idea/codeStyles/codeStyleConfig.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
new file mode 100644
index 0000000..fb7f4a8
--- /dev/null
+++ b/.idea/compiler.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/gradle.xml b/.idea/gradle.xml
new file mode 100644
index 0000000..36394ad
--- /dev/null
+++ b/.idea/gradle.xml
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..cb1a633
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..94a25f7
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/build.gradle b/app/build.gradle
index 1ec893a..655a456 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -68,6 +68,9 @@
implementation "androidx.compose.material:material:$composeVersion"
implementation "androidx.compose.foundation:foundation-layout:$composeVersion"
+ // Glide
+ implementation "com.github.bumptech.glide:compose:1.0.0-alpha.1"
+
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0'
diff --git a/app/src/main/java/fr/tf1/player/atelierplayermvvm/ui/details/BookDetailActivity.kt b/app/src/main/java/fr/tf1/player/atelierplayermvvm/ui/details/BookDetailActivity.kt
index 66086bd..4f7ab64 100644
--- a/app/src/main/java/fr/tf1/player/atelierplayermvvm/ui/details/BookDetailActivity.kt
+++ b/app/src/main/java/fr/tf1/player/atelierplayermvvm/ui/details/BookDetailActivity.kt
@@ -3,10 +3,9 @@
import android.os.Bundle
import android.widget.ImageView
import android.widget.TextView
-import android.widget.Toast
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
-import com.bumptech.glide.Glide
+import androidx.compose.ui.platform.ComposeView
import dagger.hilt.android.AndroidEntryPoint
import fr.tf1.player.atelierplayermvvm.R
@@ -21,7 +20,11 @@
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
- setContentView(R.layout.book_detail)
+ setContentView(ComposeView(this).apply {
+ setContent {
+ BookDetailScreen(viewModel.viewState)
+ }
+ })
bookTitle = findViewById(R.id.bookTitle)
authorName = findViewById(R.id.authorName)
@@ -29,19 +32,19 @@
bookCover = findViewById(R.id.bookCover)
val bookId = intent.getIntExtra("BOOK_ID", 0)
- viewModel.book.observe(this) { book ->
- if (book != null) {
- bookTitle.text = book.bookName
- authorName.text = book.authorName
- bookDescription.text = book.bookDesc
- Glide.with(this@BookDetailActivity)
- .load(book.picUrl)
- .into(bookCover)
- } else {
- Toast.makeText(this@BookDetailActivity, "No book found", Toast.LENGTH_LONG).show()
- }
-
- }
+// viewModel.book.observe(this) { book ->
+// if (book != null) {
+// bookTitle.text = book.bookName
+// authorName.text = book.authorName
+// bookDescription.text = book.bookDesc
+// Glide.with(this@BookDetailActivity)
+// .load(book.picUrl)
+// .into(bookCover)
+// } else {
+// Toast.makeText(this@BookDetailActivity, "No book found", Toast.LENGTH_LONG).show()
+// }
+//
+// }
viewModel.fetchBookDetail(bookId)
}
}
\ No newline at end of file
diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml
new file mode 100644
index 0000000..7643783
--- /dev/null
+++ b/.idea/codeStyles/Project.xml
@@ -0,0 +1,123 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ xmlns:android
+
+ ^$
+
+
+
+
+
+
+
+
+ xmlns:.*
+
+ ^$
+
+
+ BY_NAME
+
+
+
+
+
+
+ .*:id
+
+ http://schemas.android.com/apk/res/android
+
+
+
+
+
+
+
+
+ .*:name
+
+ http://schemas.android.com/apk/res/android
+
+
+
+
+
+
+
+
+ name
+
+ ^$
+
+
+
+
+
+
+
+
+ style
+
+ ^$
+
+
+
+
+
+
+
+
+ .*
+
+ ^$
+
+
+ BY_NAME
+
+
+
+
+
+
+ .*
+
+ http://schemas.android.com/apk/res/android
+
+
+ ANDROID_ATTRIBUTE_ORDER
+
+
+
+
+
+
+ .*
+
+ .*
+
+
+ BY_NAME
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml
new file mode 100644
index 0000000..79ee123
--- /dev/null
+++ b/.idea/codeStyles/codeStyleConfig.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
new file mode 100644
index 0000000..fb7f4a8
--- /dev/null
+++ b/.idea/compiler.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/gradle.xml b/.idea/gradle.xml
new file mode 100644
index 0000000..36394ad
--- /dev/null
+++ b/.idea/gradle.xml
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..cb1a633
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..94a25f7
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/build.gradle b/app/build.gradle
index 1ec893a..655a456 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -68,6 +68,9 @@
implementation "androidx.compose.material:material:$composeVersion"
implementation "androidx.compose.foundation:foundation-layout:$composeVersion"
+ // Glide
+ implementation "com.github.bumptech.glide:compose:1.0.0-alpha.1"
+
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0'
diff --git a/app/src/main/java/fr/tf1/player/atelierplayermvvm/ui/details/BookDetailActivity.kt b/app/src/main/java/fr/tf1/player/atelierplayermvvm/ui/details/BookDetailActivity.kt
index 66086bd..4f7ab64 100644
--- a/app/src/main/java/fr/tf1/player/atelierplayermvvm/ui/details/BookDetailActivity.kt
+++ b/app/src/main/java/fr/tf1/player/atelierplayermvvm/ui/details/BookDetailActivity.kt
@@ -3,10 +3,9 @@
import android.os.Bundle
import android.widget.ImageView
import android.widget.TextView
-import android.widget.Toast
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
-import com.bumptech.glide.Glide
+import androidx.compose.ui.platform.ComposeView
import dagger.hilt.android.AndroidEntryPoint
import fr.tf1.player.atelierplayermvvm.R
@@ -21,7 +20,11 @@
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
- setContentView(R.layout.book_detail)
+ setContentView(ComposeView(this).apply {
+ setContent {
+ BookDetailScreen(viewModel.viewState)
+ }
+ })
bookTitle = findViewById(R.id.bookTitle)
authorName = findViewById(R.id.authorName)
@@ -29,19 +32,19 @@
bookCover = findViewById(R.id.bookCover)
val bookId = intent.getIntExtra("BOOK_ID", 0)
- viewModel.book.observe(this) { book ->
- if (book != null) {
- bookTitle.text = book.bookName
- authorName.text = book.authorName
- bookDescription.text = book.bookDesc
- Glide.with(this@BookDetailActivity)
- .load(book.picUrl)
- .into(bookCover)
- } else {
- Toast.makeText(this@BookDetailActivity, "No book found", Toast.LENGTH_LONG).show()
- }
-
- }
+// viewModel.book.observe(this) { book ->
+// if (book != null) {
+// bookTitle.text = book.bookName
+// authorName.text = book.authorName
+// bookDescription.text = book.bookDesc
+// Glide.with(this@BookDetailActivity)
+// .load(book.picUrl)
+// .into(bookCover)
+// } else {
+// Toast.makeText(this@BookDetailActivity, "No book found", Toast.LENGTH_LONG).show()
+// }
+//
+// }
viewModel.fetchBookDetail(bookId)
}
}
\ No newline at end of file
diff --git a/app/src/main/java/fr/tf1/player/atelierplayermvvm/ui/details/BookDetailContract.kt b/app/src/main/java/fr/tf1/player/atelierplayermvvm/ui/details/BookDetailContract.kt
new file mode 100644
index 0000000..66dc1c6
--- /dev/null
+++ b/app/src/main/java/fr/tf1/player/atelierplayermvvm/ui/details/BookDetailContract.kt
@@ -0,0 +1,12 @@
+package fr.tf1.player.atelierplayermvvm.ui.details
+
+import fr.tf1.player.atelierplayermvvm.data.model.Book
+
+class BookDetailContract {
+
+ sealed class State {
+ object Loading : State()
+ data class Error(val msg: String) : State()
+ data class Completed(val book: Book) : State()
+ }
+}
\ No newline at end of file
diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml
new file mode 100644
index 0000000..7643783
--- /dev/null
+++ b/.idea/codeStyles/Project.xml
@@ -0,0 +1,123 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ xmlns:android
+
+ ^$
+
+
+
+
+
+
+
+
+ xmlns:.*
+
+ ^$
+
+
+ BY_NAME
+
+
+
+
+
+
+ .*:id
+
+ http://schemas.android.com/apk/res/android
+
+
+
+
+
+
+
+
+ .*:name
+
+ http://schemas.android.com/apk/res/android
+
+
+
+
+
+
+
+
+ name
+
+ ^$
+
+
+
+
+
+
+
+
+ style
+
+ ^$
+
+
+
+
+
+
+
+
+ .*
+
+ ^$
+
+
+ BY_NAME
+
+
+
+
+
+
+ .*
+
+ http://schemas.android.com/apk/res/android
+
+
+ ANDROID_ATTRIBUTE_ORDER
+
+
+
+
+
+
+ .*
+
+ .*
+
+
+ BY_NAME
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml
new file mode 100644
index 0000000..79ee123
--- /dev/null
+++ b/.idea/codeStyles/codeStyleConfig.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
new file mode 100644
index 0000000..fb7f4a8
--- /dev/null
+++ b/.idea/compiler.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/gradle.xml b/.idea/gradle.xml
new file mode 100644
index 0000000..36394ad
--- /dev/null
+++ b/.idea/gradle.xml
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..cb1a633
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..94a25f7
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/build.gradle b/app/build.gradle
index 1ec893a..655a456 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -68,6 +68,9 @@
implementation "androidx.compose.material:material:$composeVersion"
implementation "androidx.compose.foundation:foundation-layout:$composeVersion"
+ // Glide
+ implementation "com.github.bumptech.glide:compose:1.0.0-alpha.1"
+
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0'
diff --git a/app/src/main/java/fr/tf1/player/atelierplayermvvm/ui/details/BookDetailActivity.kt b/app/src/main/java/fr/tf1/player/atelierplayermvvm/ui/details/BookDetailActivity.kt
index 66086bd..4f7ab64 100644
--- a/app/src/main/java/fr/tf1/player/atelierplayermvvm/ui/details/BookDetailActivity.kt
+++ b/app/src/main/java/fr/tf1/player/atelierplayermvvm/ui/details/BookDetailActivity.kt
@@ -3,10 +3,9 @@
import android.os.Bundle
import android.widget.ImageView
import android.widget.TextView
-import android.widget.Toast
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
-import com.bumptech.glide.Glide
+import androidx.compose.ui.platform.ComposeView
import dagger.hilt.android.AndroidEntryPoint
import fr.tf1.player.atelierplayermvvm.R
@@ -21,7 +20,11 @@
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
- setContentView(R.layout.book_detail)
+ setContentView(ComposeView(this).apply {
+ setContent {
+ BookDetailScreen(viewModel.viewState)
+ }
+ })
bookTitle = findViewById(R.id.bookTitle)
authorName = findViewById(R.id.authorName)
@@ -29,19 +32,19 @@
bookCover = findViewById(R.id.bookCover)
val bookId = intent.getIntExtra("BOOK_ID", 0)
- viewModel.book.observe(this) { book ->
- if (book != null) {
- bookTitle.text = book.bookName
- authorName.text = book.authorName
- bookDescription.text = book.bookDesc
- Glide.with(this@BookDetailActivity)
- .load(book.picUrl)
- .into(bookCover)
- } else {
- Toast.makeText(this@BookDetailActivity, "No book found", Toast.LENGTH_LONG).show()
- }
-
- }
+// viewModel.book.observe(this) { book ->
+// if (book != null) {
+// bookTitle.text = book.bookName
+// authorName.text = book.authorName
+// bookDescription.text = book.bookDesc
+// Glide.with(this@BookDetailActivity)
+// .load(book.picUrl)
+// .into(bookCover)
+// } else {
+// Toast.makeText(this@BookDetailActivity, "No book found", Toast.LENGTH_LONG).show()
+// }
+//
+// }
viewModel.fetchBookDetail(bookId)
}
}
\ No newline at end of file
diff --git a/app/src/main/java/fr/tf1/player/atelierplayermvvm/ui/details/BookDetailContract.kt b/app/src/main/java/fr/tf1/player/atelierplayermvvm/ui/details/BookDetailContract.kt
new file mode 100644
index 0000000..66dc1c6
--- /dev/null
+++ b/app/src/main/java/fr/tf1/player/atelierplayermvvm/ui/details/BookDetailContract.kt
@@ -0,0 +1,12 @@
+package fr.tf1.player.atelierplayermvvm.ui.details
+
+import fr.tf1.player.atelierplayermvvm.data.model.Book
+
+class BookDetailContract {
+
+ sealed class State {
+ object Loading : State()
+ data class Error(val msg: String) : State()
+ data class Completed(val book: Book) : State()
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/fr/tf1/player/atelierplayermvvm/ui/details/BookDetailScreen.kt b/app/src/main/java/fr/tf1/player/atelierplayermvvm/ui/details/BookDetailScreen.kt
new file mode 100644
index 0000000..f6c0365
--- /dev/null
+++ b/app/src/main/java/fr/tf1/player/atelierplayermvvm/ui/details/BookDetailScreen.kt
@@ -0,0 +1,38 @@
+package fr.tf1.player.atelierplayermvvm.ui.details
+
+import androidx.compose.foundation.layout.*
+import androidx.compose.material.Text
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.State
+import androidx.compose.ui.Modifier
+import com.bumptech.glide.integration.compose.ExperimentalGlideComposeApi
+import com.bumptech.glide.integration.compose.GlideImage
+import fr.tf1.player.atelierplayermvvm.data.model.Book
+
+@OptIn(ExperimentalGlideComposeApi::class)
+@Composable
+fun BookDetailScreen(viewState: State) {
+ Column(modifier = Modifier.fillMaxSize()) {
+ Row(modifier = Modifier.fillMaxWidth()) {
+ when (val state = viewState.value) {
+ is BookDetailContract.State.Loading -> {
+ Text(text = "Loading")
+ }
+ is BookDetailContract.State.Error -> {
+ val message = state.msg
+ Text(text = message)
+ }
+ is BookDetailContract.State.Completed -> {
+ val book = state.book
+ GlideImage(model = book.picUrl, contentDescription = book.bookName)
+ Column(modifier = Modifier.fillMaxHeight()) {
+ Text(text = book.bookName ?: "")
+ Text(text = book.authorName ?: "")
+ }
+ }
+
+ }
+ }
+ Text(text = "desc")
+ }
+}
\ No newline at end of file
diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml
new file mode 100644
index 0000000..7643783
--- /dev/null
+++ b/.idea/codeStyles/Project.xml
@@ -0,0 +1,123 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ xmlns:android
+
+ ^$
+
+
+
+
+
+
+
+
+ xmlns:.*
+
+ ^$
+
+
+ BY_NAME
+
+
+
+
+
+
+ .*:id
+
+ http://schemas.android.com/apk/res/android
+
+
+
+
+
+
+
+
+ .*:name
+
+ http://schemas.android.com/apk/res/android
+
+
+
+
+
+
+
+
+ name
+
+ ^$
+
+
+
+
+
+
+
+
+ style
+
+ ^$
+
+
+
+
+
+
+
+
+ .*
+
+ ^$
+
+
+ BY_NAME
+
+
+
+
+
+
+ .*
+
+ http://schemas.android.com/apk/res/android
+
+
+ ANDROID_ATTRIBUTE_ORDER
+
+
+
+
+
+
+ .*
+
+ .*
+
+
+ BY_NAME
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml
new file mode 100644
index 0000000..79ee123
--- /dev/null
+++ b/.idea/codeStyles/codeStyleConfig.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
new file mode 100644
index 0000000..fb7f4a8
--- /dev/null
+++ b/.idea/compiler.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/gradle.xml b/.idea/gradle.xml
new file mode 100644
index 0000000..36394ad
--- /dev/null
+++ b/.idea/gradle.xml
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..cb1a633
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..94a25f7
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/build.gradle b/app/build.gradle
index 1ec893a..655a456 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -68,6 +68,9 @@
implementation "androidx.compose.material:material:$composeVersion"
implementation "androidx.compose.foundation:foundation-layout:$composeVersion"
+ // Glide
+ implementation "com.github.bumptech.glide:compose:1.0.0-alpha.1"
+
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0'
diff --git a/app/src/main/java/fr/tf1/player/atelierplayermvvm/ui/details/BookDetailActivity.kt b/app/src/main/java/fr/tf1/player/atelierplayermvvm/ui/details/BookDetailActivity.kt
index 66086bd..4f7ab64 100644
--- a/app/src/main/java/fr/tf1/player/atelierplayermvvm/ui/details/BookDetailActivity.kt
+++ b/app/src/main/java/fr/tf1/player/atelierplayermvvm/ui/details/BookDetailActivity.kt
@@ -3,10 +3,9 @@
import android.os.Bundle
import android.widget.ImageView
import android.widget.TextView
-import android.widget.Toast
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
-import com.bumptech.glide.Glide
+import androidx.compose.ui.platform.ComposeView
import dagger.hilt.android.AndroidEntryPoint
import fr.tf1.player.atelierplayermvvm.R
@@ -21,7 +20,11 @@
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
- setContentView(R.layout.book_detail)
+ setContentView(ComposeView(this).apply {
+ setContent {
+ BookDetailScreen(viewModel.viewState)
+ }
+ })
bookTitle = findViewById(R.id.bookTitle)
authorName = findViewById(R.id.authorName)
@@ -29,19 +32,19 @@
bookCover = findViewById(R.id.bookCover)
val bookId = intent.getIntExtra("BOOK_ID", 0)
- viewModel.book.observe(this) { book ->
- if (book != null) {
- bookTitle.text = book.bookName
- authorName.text = book.authorName
- bookDescription.text = book.bookDesc
- Glide.with(this@BookDetailActivity)
- .load(book.picUrl)
- .into(bookCover)
- } else {
- Toast.makeText(this@BookDetailActivity, "No book found", Toast.LENGTH_LONG).show()
- }
-
- }
+// viewModel.book.observe(this) { book ->
+// if (book != null) {
+// bookTitle.text = book.bookName
+// authorName.text = book.authorName
+// bookDescription.text = book.bookDesc
+// Glide.with(this@BookDetailActivity)
+// .load(book.picUrl)
+// .into(bookCover)
+// } else {
+// Toast.makeText(this@BookDetailActivity, "No book found", Toast.LENGTH_LONG).show()
+// }
+//
+// }
viewModel.fetchBookDetail(bookId)
}
}
\ No newline at end of file
diff --git a/app/src/main/java/fr/tf1/player/atelierplayermvvm/ui/details/BookDetailContract.kt b/app/src/main/java/fr/tf1/player/atelierplayermvvm/ui/details/BookDetailContract.kt
new file mode 100644
index 0000000..66dc1c6
--- /dev/null
+++ b/app/src/main/java/fr/tf1/player/atelierplayermvvm/ui/details/BookDetailContract.kt
@@ -0,0 +1,12 @@
+package fr.tf1.player.atelierplayermvvm.ui.details
+
+import fr.tf1.player.atelierplayermvvm.data.model.Book
+
+class BookDetailContract {
+
+ sealed class State {
+ object Loading : State()
+ data class Error(val msg: String) : State()
+ data class Completed(val book: Book) : State()
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/fr/tf1/player/atelierplayermvvm/ui/details/BookDetailScreen.kt b/app/src/main/java/fr/tf1/player/atelierplayermvvm/ui/details/BookDetailScreen.kt
new file mode 100644
index 0000000..f6c0365
--- /dev/null
+++ b/app/src/main/java/fr/tf1/player/atelierplayermvvm/ui/details/BookDetailScreen.kt
@@ -0,0 +1,38 @@
+package fr.tf1.player.atelierplayermvvm.ui.details
+
+import androidx.compose.foundation.layout.*
+import androidx.compose.material.Text
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.State
+import androidx.compose.ui.Modifier
+import com.bumptech.glide.integration.compose.ExperimentalGlideComposeApi
+import com.bumptech.glide.integration.compose.GlideImage
+import fr.tf1.player.atelierplayermvvm.data.model.Book
+
+@OptIn(ExperimentalGlideComposeApi::class)
+@Composable
+fun BookDetailScreen(viewState: State) {
+ Column(modifier = Modifier.fillMaxSize()) {
+ Row(modifier = Modifier.fillMaxWidth()) {
+ when (val state = viewState.value) {
+ is BookDetailContract.State.Loading -> {
+ Text(text = "Loading")
+ }
+ is BookDetailContract.State.Error -> {
+ val message = state.msg
+ Text(text = message)
+ }
+ is BookDetailContract.State.Completed -> {
+ val book = state.book
+ GlideImage(model = book.picUrl, contentDescription = book.bookName)
+ Column(modifier = Modifier.fillMaxHeight()) {
+ Text(text = book.bookName ?: "")
+ Text(text = book.authorName ?: "")
+ }
+ }
+
+ }
+ }
+ Text(text = "desc")
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/fr/tf1/player/atelierplayermvvm/ui/details/BookDetailViewModel.kt b/app/src/main/java/fr/tf1/player/atelierplayermvvm/ui/details/BookDetailViewModel.kt
index 45517d0..8f8a949 100644
--- a/app/src/main/java/fr/tf1/player/atelierplayermvvm/ui/details/BookDetailViewModel.kt
+++ b/app/src/main/java/fr/tf1/player/atelierplayermvvm/ui/details/BookDetailViewModel.kt
@@ -1,5 +1,7 @@
package fr.tf1.player.atelierplayermvvm.ui.details
+import androidx.compose.runtime.MutableState
+import androidx.compose.runtime.mutableStateOf
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
@@ -7,22 +9,25 @@
import fr.tf1.player.atelierplayermvvm.data.model.Book
import fr.tf1.player.atelierplayermvvm.data.usecases.FetchDetailUseCase
import fr.tf1.player.atelierplayermvvm.data.usecases.FetchListUseCase
+import fr.tf1.player.atelierplayermvvm.ui.list.BookListContract
import kotlinx.coroutines.launch
import javax.inject.Inject
@HiltViewModel
class BookDetailViewModel @Inject constructor(val fetchDetailUseCase: FetchDetailUseCase) :
ViewModel() {
- val book: MutableLiveData
- init {
- book = MutableLiveData()
-
- }
+ private val initialState: BookDetailContract.State = BookDetailContract.State.Loading
+ val viewState: MutableState = mutableStateOf(initialState)
fun fetchBookDetail(bookId: Int) {
viewModelScope.launch {
- book.value = fetchDetailUseCase.fetchBookDetail(bookId)
+ val book = fetchDetailUseCase.fetchBookDetail(bookId)
+ if(book == null) {
+ viewState.value = BookDetailContract.State.Error("Erreur")
+ } else {
+ viewState.value = BookDetailContract.State.Completed(book)
+ }
}
}
}
\ No newline at end of file
diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml
new file mode 100644
index 0000000..7643783
--- /dev/null
+++ b/.idea/codeStyles/Project.xml
@@ -0,0 +1,123 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ xmlns:android
+
+ ^$
+
+
+
+
+
+
+
+
+ xmlns:.*
+
+ ^$
+
+
+ BY_NAME
+
+
+
+
+
+
+ .*:id
+
+ http://schemas.android.com/apk/res/android
+
+
+
+
+
+
+
+
+ .*:name
+
+ http://schemas.android.com/apk/res/android
+
+
+
+
+
+
+
+
+ name
+
+ ^$
+
+
+
+
+
+
+
+
+ style
+
+ ^$
+
+
+
+
+
+
+
+
+ .*
+
+ ^$
+
+
+ BY_NAME
+
+
+
+
+
+
+ .*
+
+ http://schemas.android.com/apk/res/android
+
+
+ ANDROID_ATTRIBUTE_ORDER
+
+
+
+
+
+
+ .*
+
+ .*
+
+
+ BY_NAME
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml
new file mode 100644
index 0000000..79ee123
--- /dev/null
+++ b/.idea/codeStyles/codeStyleConfig.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
new file mode 100644
index 0000000..fb7f4a8
--- /dev/null
+++ b/.idea/compiler.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/gradle.xml b/.idea/gradle.xml
new file mode 100644
index 0000000..36394ad
--- /dev/null
+++ b/.idea/gradle.xml
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..cb1a633
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..94a25f7
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/build.gradle b/app/build.gradle
index 1ec893a..655a456 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -68,6 +68,9 @@
implementation "androidx.compose.material:material:$composeVersion"
implementation "androidx.compose.foundation:foundation-layout:$composeVersion"
+ // Glide
+ implementation "com.github.bumptech.glide:compose:1.0.0-alpha.1"
+
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0'
diff --git a/app/src/main/java/fr/tf1/player/atelierplayermvvm/ui/details/BookDetailActivity.kt b/app/src/main/java/fr/tf1/player/atelierplayermvvm/ui/details/BookDetailActivity.kt
index 66086bd..4f7ab64 100644
--- a/app/src/main/java/fr/tf1/player/atelierplayermvvm/ui/details/BookDetailActivity.kt
+++ b/app/src/main/java/fr/tf1/player/atelierplayermvvm/ui/details/BookDetailActivity.kt
@@ -3,10 +3,9 @@
import android.os.Bundle
import android.widget.ImageView
import android.widget.TextView
-import android.widget.Toast
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
-import com.bumptech.glide.Glide
+import androidx.compose.ui.platform.ComposeView
import dagger.hilt.android.AndroidEntryPoint
import fr.tf1.player.atelierplayermvvm.R
@@ -21,7 +20,11 @@
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
- setContentView(R.layout.book_detail)
+ setContentView(ComposeView(this).apply {
+ setContent {
+ BookDetailScreen(viewModel.viewState)
+ }
+ })
bookTitle = findViewById(R.id.bookTitle)
authorName = findViewById(R.id.authorName)
@@ -29,19 +32,19 @@
bookCover = findViewById(R.id.bookCover)
val bookId = intent.getIntExtra("BOOK_ID", 0)
- viewModel.book.observe(this) { book ->
- if (book != null) {
- bookTitle.text = book.bookName
- authorName.text = book.authorName
- bookDescription.text = book.bookDesc
- Glide.with(this@BookDetailActivity)
- .load(book.picUrl)
- .into(bookCover)
- } else {
- Toast.makeText(this@BookDetailActivity, "No book found", Toast.LENGTH_LONG).show()
- }
-
- }
+// viewModel.book.observe(this) { book ->
+// if (book != null) {
+// bookTitle.text = book.bookName
+// authorName.text = book.authorName
+// bookDescription.text = book.bookDesc
+// Glide.with(this@BookDetailActivity)
+// .load(book.picUrl)
+// .into(bookCover)
+// } else {
+// Toast.makeText(this@BookDetailActivity, "No book found", Toast.LENGTH_LONG).show()
+// }
+//
+// }
viewModel.fetchBookDetail(bookId)
}
}
\ No newline at end of file
diff --git a/app/src/main/java/fr/tf1/player/atelierplayermvvm/ui/details/BookDetailContract.kt b/app/src/main/java/fr/tf1/player/atelierplayermvvm/ui/details/BookDetailContract.kt
new file mode 100644
index 0000000..66dc1c6
--- /dev/null
+++ b/app/src/main/java/fr/tf1/player/atelierplayermvvm/ui/details/BookDetailContract.kt
@@ -0,0 +1,12 @@
+package fr.tf1.player.atelierplayermvvm.ui.details
+
+import fr.tf1.player.atelierplayermvvm.data.model.Book
+
+class BookDetailContract {
+
+ sealed class State {
+ object Loading : State()
+ data class Error(val msg: String) : State()
+ data class Completed(val book: Book) : State()
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/fr/tf1/player/atelierplayermvvm/ui/details/BookDetailScreen.kt b/app/src/main/java/fr/tf1/player/atelierplayermvvm/ui/details/BookDetailScreen.kt
new file mode 100644
index 0000000..f6c0365
--- /dev/null
+++ b/app/src/main/java/fr/tf1/player/atelierplayermvvm/ui/details/BookDetailScreen.kt
@@ -0,0 +1,38 @@
+package fr.tf1.player.atelierplayermvvm.ui.details
+
+import androidx.compose.foundation.layout.*
+import androidx.compose.material.Text
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.State
+import androidx.compose.ui.Modifier
+import com.bumptech.glide.integration.compose.ExperimentalGlideComposeApi
+import com.bumptech.glide.integration.compose.GlideImage
+import fr.tf1.player.atelierplayermvvm.data.model.Book
+
+@OptIn(ExperimentalGlideComposeApi::class)
+@Composable
+fun BookDetailScreen(viewState: State) {
+ Column(modifier = Modifier.fillMaxSize()) {
+ Row(modifier = Modifier.fillMaxWidth()) {
+ when (val state = viewState.value) {
+ is BookDetailContract.State.Loading -> {
+ Text(text = "Loading")
+ }
+ is BookDetailContract.State.Error -> {
+ val message = state.msg
+ Text(text = message)
+ }
+ is BookDetailContract.State.Completed -> {
+ val book = state.book
+ GlideImage(model = book.picUrl, contentDescription = book.bookName)
+ Column(modifier = Modifier.fillMaxHeight()) {
+ Text(text = book.bookName ?: "")
+ Text(text = book.authorName ?: "")
+ }
+ }
+
+ }
+ }
+ Text(text = "desc")
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/fr/tf1/player/atelierplayermvvm/ui/details/BookDetailViewModel.kt b/app/src/main/java/fr/tf1/player/atelierplayermvvm/ui/details/BookDetailViewModel.kt
index 45517d0..8f8a949 100644
--- a/app/src/main/java/fr/tf1/player/atelierplayermvvm/ui/details/BookDetailViewModel.kt
+++ b/app/src/main/java/fr/tf1/player/atelierplayermvvm/ui/details/BookDetailViewModel.kt
@@ -1,5 +1,7 @@
package fr.tf1.player.atelierplayermvvm.ui.details
+import androidx.compose.runtime.MutableState
+import androidx.compose.runtime.mutableStateOf
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
@@ -7,22 +9,25 @@
import fr.tf1.player.atelierplayermvvm.data.model.Book
import fr.tf1.player.atelierplayermvvm.data.usecases.FetchDetailUseCase
import fr.tf1.player.atelierplayermvvm.data.usecases.FetchListUseCase
+import fr.tf1.player.atelierplayermvvm.ui.list.BookListContract
import kotlinx.coroutines.launch
import javax.inject.Inject
@HiltViewModel
class BookDetailViewModel @Inject constructor(val fetchDetailUseCase: FetchDetailUseCase) :
ViewModel() {
- val book: MutableLiveData
- init {
- book = MutableLiveData()
-
- }
+ private val initialState: BookDetailContract.State = BookDetailContract.State.Loading
+ val viewState: MutableState = mutableStateOf(initialState)
fun fetchBookDetail(bookId: Int) {
viewModelScope.launch {
- book.value = fetchDetailUseCase.fetchBookDetail(bookId)
+ val book = fetchDetailUseCase.fetchBookDetail(bookId)
+ if(book == null) {
+ viewState.value = BookDetailContract.State.Error("Erreur")
+ } else {
+ viewState.value = BookDetailContract.State.Completed(book)
+ }
}
}
}
\ No newline at end of file
diff --git a/app/src/main/java/fr/tf1/player/atelierplayermvvm/ui/list/BookListScreen.kt b/app/src/main/java/fr/tf1/player/atelierplayermvvm/ui/list/BookListScreen.kt
index cd98638..948757c 100644
--- a/app/src/main/java/fr/tf1/player/atelierplayermvvm/ui/list/BookListScreen.kt
+++ b/app/src/main/java/fr/tf1/player/atelierplayermvvm/ui/list/BookListScreen.kt
@@ -18,7 +18,7 @@
when (viewState.value) {
is BookListContract.State.Loading -> {
//show loader
- Text(text = "Loading")
+ Text(text = "Loading")
}
is BookListContract.State.Completed -> {
LazyColumn(modifier = Modifier.background(Color.White)) {