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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
7 changes: 0 additions & 7 deletions README.md

This file was deleted.

1 change: 0 additions & 1 deletion lection02/.idea/.name

This file was deleted.

139 changes: 139 additions & 0 deletions lection02/.idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions lection02/.idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package com.mycompany.helloworld

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.floatingactionbutton.FloatingActionButton

class HelloActivity : AppCompatActivity() {

private val movies = generateMovieList().toMutableList()

var adapter: MovieAdapter? = null

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.hello_activity)
val rvMovieList: RecyclerView = findViewById(R.id.hello_activity__rv_movie_list)
adapter = MovieAdapter(movies)
rvMovieList.adapter = adapter
rvMovieList.layoutManager = LinearLayoutManager(this)
val button: FloatingActionButton = findViewById(R.id.hello_activity__fab_add_movie)
button.setOnClickListener { onClick() }
}

private fun onClick() {
movies.add(
Movie(
"Мой новый фильм",
"Здесь описание фильма",
0
)
)
adapter?.notifyDataSetChanged()
}
}

private fun generateMovieList(): List<Movie> {
return listOf(
Movie(
"Побег из Шоушенка",
"Оказавшись в тюрьме под названием Шоушенк, он сталкивается с жестокостью и беззаконием, царящими по обе стороны решетки. Каждый, кто попадает в эти стены, становится их рабом до конца жизни",
R.drawable.movie_1
), Movie(
"Матрица",
"Жизнь Томаса Андерсона разделена на две части: днём он — самый обычный офисный работник, получающий нагоняи от начальства, а ночью превращается в хакера по имени Нео, и нет места в сети, куда он не смог бы дотянуться",
R.drawable.movie_2
), Movie(
"Как приручить дракона",
"Вы узнаете историю подростка Иккинга, которому не слишком близки традиции его героического племени, много лет ведущего войну с драконами",
R.drawable.movie_3
), Movie(
"12 стульев",
"Во время революции и последовавшего за ней краткого периода военного коммунизма многие прятали свои ценности как можно надежнее",
R.drawable.movie_4
), Movie(
"Зеленая книга",
"Утонченный светский лев, богатый и талантливый музыкант нанимает в качестве водителя и телохранителя человека, который менее всего подходит для этой работы",
R.drawable.movie_5
), Movie(
"Пираты Карибского моря: Проклятие Черной жемчужины",
"Жизнь харизматичного авантюриста, капитана Джека Воробья, полная увлекательных приключений, резко меняется, когда его заклятый враг — капитан Барбосса — похищает корабль Джека, Черную Жемчужину, а затем нападает на Порт Ройал и крадет прекрасную дочь губернатора, Элизабет Свонн.",
R.drawable.movie_6
), Movie(
"Гарри Поттер и философский камень",
"Жизнь десятилетнего Гарри Поттера нельзя назвать сладкой: его родители умерли, едва ему исполнился год, а от дяди и тётки, взявших сироту на воспитание, достаются лишь тычки да подзатыльники",
R.drawable.movie_7
)
)
}
3 changes: 3 additions & 0 deletions lection02/app/src/main/java/com/mycompany/helloworld/Movie.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.mycompany.helloworld

data class Movie(val title: String, val description: String, val picture: Int)
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.mycompany.helloworld

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import android.widget.Toast
import androidx.recyclerview.widget.RecyclerView

class MovieAdapter(private val movies: List<Movie>) :
RecyclerView.Adapter<MovieAdapter.MovieViewHolder>() {

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MovieViewHolder {
val view = LayoutInflater.from(parent.context).inflate(R.layout.movie_item, parent, false)
return MovieViewHolder(view)
}

override fun onBindViewHolder(holder: MovieViewHolder, position: Int) {
val movie = movies[position]
holder.bind(movie)
}

override fun getItemCount(): Int {
println("Movies size = ${movies.size}")
return movies.size
}

class MovieViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {

private val tvName: TextView = itemView.findViewById(R.id.movie_item__tv_name)
private val tvDescription: TextView = itemView.findViewById(R.id.movie_item__tv_description)
private val ivPoster: ImageView = itemView.findViewById(R.id.movie_item__iv_poster)

init {
itemView.setOnClickListener {
Toast.makeText(
itemView.context,
tvName.text,
Toast.LENGTH_SHORT
).show()
}
}

fun bind(movie: Movie) {
tvName.text = movie.title
tvDescription.text = movie.description
ivPoster.setImageResource(movie.picture)
}

}


}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions lection02/app/src/main/res/layout/hello_activity.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/hello_activity__rv_movie_list"
android:layout_width="411dp"
android:layout_height="730dp"
android:background="@color/red"
android:rotation="8"
app:layout_constraintBottom_toTopOf="@+id/hello_activity__fab_add_movie"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
/>

<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/hello_activity__fab_add_movie"
android:layout_width="56dp"
android:layout_height="56dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="32dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:srcCompat="@android:drawable/ic_input_add" />

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

<ImageView
android:id="@+id/movie_item__iv_poster"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp"
android:scaleType="centerCrop"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:src="@drawable/movie_1" />

<TextView
android:id="@+id/movie_item__tv_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
android:ellipsize="end"
android:maxLines="1"
android:textSize="16sp"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@+id/movie_item__tv_description"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/movie_item__iv_poster"
app:layout_constraintTop_toTopOf="@+id/movie_item__iv_poster"
app:layout_constraintVertical_chainStyle="packed"
tools:text="fkasjdhfjkadshfkjashdfjkhasdjkhfjkasddsfdsffdsfdsfdsfsdfsdfhfjhasdf" />

<TextView
android:id="@+id/movie_item__tv_description"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="20dp"
android:ellipsize="end"
android:maxLines="2"
app:layout_constraintBottom_toBottomOf="@+id/movie_item__iv_poster"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/movie_item__iv_poster"
app:layout_constraintTop_toBottomOf="@+id/movie_item__tv_name"
tools:text="fkasjdhfjkadshfkjashdfjkhasdjkhfjkasdhfjhasdf" />

</androidx.constraintlayout.widget.ConstraintLayout>
18 changes: 0 additions & 18 deletions lection02/build.gradle

This file was deleted.

Binary file removed lection02/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
Loading