Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ android {

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
androidExtensions {
experimental = true
}

buildTypes {
release {
Expand All @@ -30,6 +33,7 @@ dependencies {
implementation 'androidx.core:core-ktx:1.3.1'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".InfoFilmActivity">

</activity>
</application>

</manifest>
6 changes: 6 additions & 0 deletions app/src/main/java/com/example/androidpractice2020/Film.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.example.androidpractice2020


data class Film(
val id: Int, val name: String, val text: String, var imageView: Int
)
14 changes: 14 additions & 0 deletions app/src/main/java/com/example/androidpractice2020/FilmAdapter.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.example.androidpractice2020

import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
class FilmAdapter(
private var list: List<Film>,
private var itemClick: (Int) -> Unit
) : RecyclerView.Adapter<FilmHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): FilmHolder = FilmHolder.create(parent, itemClick)

override fun onBindViewHolder(holder: FilmHolder, position: Int) = holder.bind(list[position])

override fun getItemCount(): Int = list.size
}
29 changes: 29 additions & 0 deletions app/src/main/java/com/example/androidpractice2020/FilmHolder.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.example.androidpractice2020

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import kotlinx.android.extensions.LayoutContainer
import kotlinx.android.synthetic.main.film_item.*

class FilmHolder(
override val containerView: View,
var itemClick: (Int) -> Unit
) : RecyclerView.ViewHolder(containerView), LayoutContainer {
fun bind(film: Film) {
film_name.text = film.name
film_image.setImageResource(film.imageView)
itemView.setOnClickListener {
itemClick(film.id)
}
}

companion object {
fun create(parent: ViewGroup, itemClick: (Int) -> Unit): FilmHolder =
FilmHolder(
LayoutInflater.from(parent.context).inflate(R.layout.film_item, parent, false),
itemClick
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.example.androidpractice2020

class FilmRepository {
val arraylist = listOf(
Film(0, "Довод", "Главный герой — секретный агент, который проходит жестокий тест на надежность и присоединяется к невероятной миссии.",R.drawable.dovod),
Film(1,"Бэтмен", "По словам автора, это будет самая молодая версия героя, который прошёл через личную трагедию, и всё, что он делает, будет его реакцией на это.", R.drawable.batman),
Film(2, "Джокер", "Американский психологический триллер режиссёра Тодда Филлипса по сценарию, написанному Филлипсом совместно со Скоттом Сильвером.", R.drawable.joker)
)

fun find(id: Int): Film {
return this.arraylist[id]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.example.androidpractice2020

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import kotlinx.android.synthetic.main.film_info.*

class InfoFilmActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.film_info)
val id = intent.extras?.getInt("id")
val film = id?.let { FilmRepository().find(it) }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FilmRepository().find(it)?also {
imageView.setImageResource(it.imageView)
....
}

if (film != null) {
imageView.setImageResource(film.imageView)
}
textView6.text = id.toString()
textView3.text = film?.name
textView5.text = film?.text
}
}
10 changes: 10 additions & 0 deletions app/src/main/java/com/example/androidpractice2020/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
package com.example.androidpractice2020

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.recyclerview.widget.DividerItemDecoration
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val list = list_film
list.addItemDecoration(DividerItemDecoration(this, DividerItemDecoration.VERTICAL))
list.adapter = FilmAdapter(FilmRepository().arraylist) {
val intent = Intent(this, InfoFilmActivity::class.java)
intent.putExtra("id", it)
startActivity(intent)
}
}
}
Binary file added app/src/main/res/drawable-v24/batman.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-v24/dovod.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-v24/joker.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 7 additions & 8 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@
android:layout_height="match_parent"
tools:context=".MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/list_film"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:itemCount="8"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:listitem="@layout/film_item" />

</androidx.constraintlayout.widget.ConstraintLayout>
79 changes: 79 additions & 0 deletions app/src/main/res/layout/film_info.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?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">

<ImageView
android:id="@+id/imageView"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginTop="56dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="80dp"
android:layout_marginLeft="10dp"
android:text="Имя"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/imageView" />

<TextView
android:id="@+id/textView3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginLeft="10dp"
app:layout_constraintTop_toBottomOf="@+id/textView" />

<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:layout_marginLeft="10dp"
android:text="Id фильма"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView3" />

<TextView
android:id="@+id/textView6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginLeft="10dp"
app:layout_constraintTop_toBottomOf="@+id/textView4" />


<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:text="Подробнее о фильме"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginLeft="10dp"
app:layout_constraintTop_toBottomOf="@+id/textView6" />

<TextView
android:id="@+id/textView5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginLeft="10dp"
app:layout_constraintTop_toBottomOf="@+id/textView2" />


</androidx.constraintlayout.widget.ConstraintLayout>
31 changes: 31 additions & 0 deletions app/src/main/res/layout/film_item.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="78dp"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

72

android:background="?attr/selectableItemBackground"
android:paddingStart="16dp"
android:paddingEnd="16dp">

<TextView
android:id="@+id/film_name"
android:layout_width="200dp"
android:layout_height="24dp"
android:textColor="@android:color/black"
android:textSize="16sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="Название фильма" />

<ImageView
android:id="@+id/film_image"
android:layout_width="56dp"
android:layout_height="56dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>