diff --git a/app/build.gradle b/app/build.gradle index 4332a31..11f80ea 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -4,12 +4,13 @@ plugins { } android { - compileSdk 32 + namespace 'otus.gpb.homework.viewandresources' + compileSdk 34 defaultConfig { applicationId "otus.gpb.homework.viewandresources" minSdk 23 - targetSdk 32 + targetSdk 34 versionCode 1 versionName "1.0" @@ -23,17 +24,20 @@ android { } } compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 + sourceCompatibility JavaVersion.VERSION_17 + targetCompatibility JavaVersion.VERSION_17 } kotlinOptions { - jvmTarget = '1.8' + jvmTarget = '17' + } + buildFeatures { + viewBinding = true } } dependencies { - implementation 'androidx.core:core-ktx:1.9.0' - implementation 'androidx.appcompat:appcompat:1.5.1' - implementation 'com.google.android.material:material:1.6.1' + implementation 'androidx.core:core-ktx:1.13.1' + implementation 'androidx.appcompat:appcompat:1.7.0' + implementation 'com.google.android.material:material:1.12.0' implementation 'androidx.constraintlayout:constraintlayout:2.1.4' } \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 608e135..8cb07e6 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,7 +1,6 @@ + xmlns:tools="http://schemas.android.com/tools"> + android:exported="false" + android:label="Cart" /> + android:exported="false" + android:label="Contacts" /> diff --git a/app/src/main/java/otus/gpb/homework/viewandresources/Item.kt b/app/src/main/java/otus/gpb/homework/viewandresources/Item.kt new file mode 100644 index 0000000..f362da7 --- /dev/null +++ b/app/src/main/java/otus/gpb/homework/viewandresources/Item.kt @@ -0,0 +1,38 @@ +package otus.gpb.homework.viewandresources + +import android.content.Context +import android.util.AttributeSet +import android.view.LayoutInflater +import android.widget.LinearLayout +import androidx.core.content.withStyledAttributes +import otus.gpb.homework.viewandresources.databinding.ItemBinding + +class Item @JvmOverloads constructor( + context: Context, + attrs: AttributeSet? = null, + defStyleAttr: Int = 0, +) : LinearLayout(context, attrs, defStyleAttr) { + private val binding: ItemBinding = ItemBinding.inflate(LayoutInflater.from(context), this) + + init { + initParams(attrs, defStyleAttr) + } + + private fun initParams(attrs: AttributeSet?, defStyleAttr: Int) = with(binding) { + context.withStyledAttributes(attrs, R.styleable.Item, defStyleAttr) { + val imageResId = getResourceId(R.styleable.Item_itemImage, 0) + if (imageResId != 0) { + itemImage.setImageResource(imageResId) + } + + val name = getString(R.styleable.Item_itemName) ?: "Name" + itemName.text = name + + val description = getString(R.styleable.Item_itemDescription) ?: "Description" + itemDescription.text = description + + val price = getString(R.styleable.Item_itemPrice) ?: "Price" + itemPrice.text = price + } + } +} \ No newline at end of file diff --git a/app/src/main/java/otus/gpb/homework/viewandresources/MainActivity.kt b/app/src/main/java/otus/gpb/homework/viewandresources/MainActivity.kt index 22b779c..8968ff8 100644 --- a/app/src/main/java/otus/gpb/homework/viewandresources/MainActivity.kt +++ b/app/src/main/java/otus/gpb/homework/viewandresources/MainActivity.kt @@ -1,10 +1,11 @@ package otus.gpb.homework.viewandresources +import android.app.AlertDialog import android.content.Intent import android.os.Bundle +import android.view.LayoutInflater import android.widget.Button import androidx.appcompat.app.AppCompatActivity -import com.google.android.material.dialog.MaterialAlertDialogBuilder class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { @@ -19,9 +20,10 @@ class MainActivity : AppCompatActivity() { } findViewById