diff --git a/build.gradle b/build.gradle
index 8ec48d7a..5e184229 100644
--- a/build.gradle
+++ b/build.gradle
@@ -4,6 +4,7 @@ plugins {
id 'com.android.library' version '8.4.0' apply false
id 'org.jetbrains.kotlin.android' version '1.9.23' apply false
id "io.gitlab.arturbosch.detekt" version "1.21.0"
+ id 'org.jetbrains.kotlin.jvm' version '1.9.23' apply false
}
task clean(type: Delete) {
diff --git a/payload/.gitignore b/payload/.gitignore
new file mode 100644
index 00000000..42afabfd
--- /dev/null
+++ b/payload/.gitignore
@@ -0,0 +1 @@
+/build
\ No newline at end of file
diff --git a/payload/build.gradle.kts b/payload/build.gradle.kts
new file mode 100644
index 00000000..93244c76
--- /dev/null
+++ b/payload/build.gradle.kts
@@ -0,0 +1,43 @@
+plugins {
+ id("com.android.library")
+ id("org.jetbrains.kotlin.android")
+ id("kotlin-parcelize")
+}
+
+android {
+ namespace = "ru.tilman.payload"
+ compileSdk = 34
+
+ defaultConfig {
+ minSdk = 23
+
+ testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
+ consumerProguardFiles("consumer-rules.pro")
+ }
+
+ buildTypes {
+ release {
+ isMinifyEnabled = false
+ proguardFiles(
+ getDefaultProguardFile("proguard-android-optimize.txt"),
+ "proguard-rules.pro"
+ )
+ }
+ }
+ compileOptions {
+ sourceCompatibility = JavaVersion.VERSION_1_8
+ targetCompatibility = JavaVersion.VERSION_1_8
+ }
+ kotlinOptions {
+ jvmTarget = "1.8"
+ }
+}
+
+dependencies {
+ implementation("androidx.core:core-ktx:1.13.1")
+ implementation("androidx.appcompat:appcompat:1.6.1")
+ implementation("com.google.android.material:material:1.12.0")
+ testImplementation("junit:junit:4.13.2")
+ androidTestImplementation("androidx.test.ext:junit:1.2.1")
+ androidTestImplementation("androidx.test.espresso:espresso-core:3.6.1")
+}
\ No newline at end of file
diff --git a/payload/consumer-rules.pro b/payload/consumer-rules.pro
new file mode 100644
index 00000000..e69de29b
diff --git a/payload/proguard-rules.pro b/payload/proguard-rules.pro
new file mode 100644
index 00000000..481bb434
--- /dev/null
+++ b/payload/proguard-rules.pro
@@ -0,0 +1,21 @@
+# Add project specific ProGuard rules here.
+# You can control the set of applied configuration files using the
+# proguardFiles setting in build.gradle.
+#
+# For more details, see
+# http://developer.android.com/guide/developing/tools/proguard.html
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+# public *;
+#}
+
+# Uncomment this to preserve the line number information for
+# debugging stack traces.
+#-keepattributes SourceFile,LineNumberTable
+
+# If you keep the line number information, uncomment this to
+# hide the original source file name.
+#-renamesourcefileattribute SourceFile
\ No newline at end of file
diff --git a/payload/src/main/java/ru/tilman/payload/Payload.kt b/payload/src/main/java/ru/tilman/payload/Payload.kt
new file mode 100644
index 00000000..71252594
--- /dev/null
+++ b/payload/src/main/java/ru/tilman/payload/Payload.kt
@@ -0,0 +1,14 @@
+package ru.tilman.payload
+
+import android.os.Parcelable
+import kotlinx.parcelize.Parcelize
+
+
+const val PAYLOAD_KEY = "payload_key"
+
+@Parcelize
+data class Payload(
+ val title: String,
+ val year: String,
+ val description: String
+) : Parcelable
\ No newline at end of file
diff --git a/receiver/build.gradle b/receiver/build.gradle
index 243c0925..8bca5c8c 100644
--- a/receiver/build.gradle
+++ b/receiver/build.gradle
@@ -57,4 +57,5 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.12.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
+ implementation project(':payload')
}
\ No newline at end of file
diff --git a/receiver/src/main/AndroidManifest.xml b/receiver/src/main/AndroidManifest.xml
index e2f6ea6c..92e13aaa 100644
--- a/receiver/src/main/AndroidManifest.xml
+++ b/receiver/src/main/AndroidManifest.xml
@@ -1,6 +1,5 @@
-
+
+ android:theme="@style/Theme.Activities">
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/receiver/src/main/java/otus/gpb/homework/activities/receiver/ReceiverActivity.kt b/receiver/src/main/java/otus/gpb/homework/activities/receiver/ReceiverActivity.kt
index b3fe360c..3c188fd2 100644
--- a/receiver/src/main/java/otus/gpb/homework/activities/receiver/ReceiverActivity.kt
+++ b/receiver/src/main/java/otus/gpb/homework/activities/receiver/ReceiverActivity.kt
@@ -1,12 +1,62 @@
package otus.gpb.homework.activities.receiver
import android.os.Bundle
+import android.widget.ImageView
+import android.widget.TextView
+import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
+import androidx.appcompat.content.res.AppCompatResources
+import androidx.core.content.IntentCompat
+import ru.tilman.payload.PAYLOAD_KEY
+import ru.tilman.payload.Payload
class ReceiverActivity : AppCompatActivity() {
+
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_receiver)
+ val payload = IntentCompat.getParcelableExtra(intent, PAYLOAD_KEY, Payload::class.java)
+ if (payload == null) {
+ Toast.makeText(this, getString(R.string.payliad_not_found), Toast.LENGTH_SHORT).show()
+ return
+ }
+
+ val imageVies = findViewById(R.id.posterImageView)
+ val imageId = runCatching { imageVies.getImageIdByTitle(payload) }
+ .getOrElse {
+ Toast.makeText(
+ this,
+ String.format(getString(R.string.image_not_found), payload.title),
+ Toast.LENGTH_SHORT
+ ).show()
+ return
+ }
+ imageVies.setImageDrawable(getDrawableById(imageId))
+
+ findViewById(R.id.titleTextView)
+ .apply { text = payload.title }
+ findViewById(R.id.descriptionTextView)
+ .apply { text = payload.description }
+ findViewById(R.id.yearTextView)
+ .apply { text = payload.year }
+
+ }
+
+ /**
+ * Отступление от задания по рекомендации IDE использован [AppCompatResources]
+ * */
+ private fun getDrawableById(imageId: Int) =
+ AppCompatResources.getDrawable(this, imageId)
+
+ private fun ImageView.getImageIdByTitle(it: Payload) = when (it.title) {
+ context.getString(R.string.niceguys_title) -> R.drawable.niceguys
+ context.getString(R.string.interstellar_title) -> R.drawable.interstellar
+ else -> throw IllegalArgumentException(
+ String.format(
+ context.getString(R.string.title_not_found),
+ it.title
+ )
+ )
}
}
diff --git a/receiver/src/main/res/values/strings.xml b/receiver/src/main/res/values/strings.xml
index 47a1c9b0..771318a3 100644
--- a/receiver/src/main/res/values/strings.xml
+++ b/receiver/src/main/res/values/strings.xml
@@ -1,3 +1,8 @@
Receiver
+ Славные парни
+ Интерстеллар
+ Фильм \'%s\' не найден(
+ Не переданы данные для поиска
+ Рисунок к фильму \'%s\' не найден
\ No newline at end of file
diff --git a/sender/build.gradle b/sender/build.gradle
index 9854ad15..4956af1a 100644
--- a/sender/build.gradle
+++ b/sender/build.gradle
@@ -1,6 +1,7 @@
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
+ id 'kotlin-parcelize'
}
android {
@@ -40,4 +41,6 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.12.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
+ implementation project(':payload')
+// implementation 'androidx.activity:activity:1.10.1'
}
\ No newline at end of file
diff --git a/sender/src/main/AndroidManifest.xml b/sender/src/main/AndroidManifest.xml
index 1bddc002..74df87b6 100644
--- a/sender/src/main/AndroidManifest.xml
+++ b/sender/src/main/AndroidManifest.xml
@@ -7,6 +7,16 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
- android:theme="@style/Theme.Activities" />
+ android:theme="@style/Theme.Activities">
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/sender/src/main/java/otus/gpb/homework/activities/sender/Payload.kt b/sender/src/main/java/otus/gpb/homework/activities/sender/Payload.kt
deleted file mode 100644
index 5a0b139e..00000000
--- a/sender/src/main/java/otus/gpb/homework/activities/sender/Payload.kt
+++ /dev/null
@@ -1,7 +0,0 @@
-package otus.gpb.homework.activities.sender
-
-data class Payload(
- val title: String,
- val year: String,
- val description: String
-)
\ No newline at end of file
diff --git a/sender/src/main/java/otus/gpb/homework/activities/sender/SenderActivity.kt b/sender/src/main/java/otus/gpb/homework/activities/sender/SenderActivity.kt
new file mode 100644
index 00000000..f9390f9a
--- /dev/null
+++ b/sender/src/main/java/otus/gpb/homework/activities/sender/SenderActivity.kt
@@ -0,0 +1,130 @@
+package otus.gpb.homework.activities.sender
+
+import android.content.ActivityNotFoundException
+import android.content.Intent
+import android.net.Uri
+import android.os.Bundle
+import android.util.Log
+import android.widget.Button
+import android.widget.Toast
+import androidx.activity.enableEdgeToEdge
+import androidx.appcompat.app.AppCompatActivity
+import androidx.core.view.ViewCompat
+import androidx.core.view.WindowInsetsCompat
+import otus.gpb.homework.activities.receiver.R
+import ru.tilman.payload.PAYLOAD_KEY
+import ru.tilman.payload.Payload
+import kotlin.random.Random
+
+class SenderActivity : AppCompatActivity() {
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ enableEdgeToEdge()
+ setContentView(R.layout.activity_sender)
+ ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
+ val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
+ v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
+ insets
+ }
+
+ findViewById