Skip to content

Commit

Permalink
Merge pull request #5 from EstefaniaGuardado/task/#4_create-detailRow…
Browse files Browse the repository at this point in the history
…Activity

Task/#4 create detail row activity
  • Loading branch information
Estefania Chavez Guardado committed Apr 11, 2018
2 parents 611973d + daa0d14 commit 8e82e4a
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 5 deletions.
Binary file modified .idea/caches/build_file_checksums.ser
Binary file not shown.
2 changes: 1 addition & 1 deletion .idea/misc.xml

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

2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ android {

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
Expand Down
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".DetailRowActivity"></activity>
</application>

</manifest>
19 changes: 16 additions & 3 deletions app/src/main/java/Adapter/ListRowAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,35 @@ package Adapter
import Model.Product
import android.R.attr.*
import android.content.Context
import android.content.Intent
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.myrefriapp.R
import android.widget.TextView
import android.widget.Toast
import com.myrefriapp.DetailRowActivity
import org.w3c.dom.Text


class ListRowAdapter (val context: Context, val listProducts: List<Product>) : RecyclerView.Adapter<ListRowAdapter.ViewHolder>() {

class ViewHolder(view: View, ctx: Context, products: ArrayList<Product>): RecyclerView.ViewHolder(view){
class ViewHolder(val view: View, val ctx: Context, val products: ArrayList<Product>): RecyclerView.ViewHolder(view), View.OnClickListener {
val name: TextView = view.findViewById<View>(R.id.name) as TextView
val detail: TextView = view.findViewById<View>(R.id.detail) as TextView

init {
view.setOnClickListener(this)
}

override fun onClick(v: View?) {
val position: Int = adapterPosition
val product: Product = products.get(position)
val intent:Intent = Intent(ctx, DetailRowActivity::class.java)
intent.putExtra("name", product.name)
intent.putExtra("detail", product.detail)
ctx.startActivity(intent)
}
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
Expand All @@ -34,6 +48,5 @@ class ListRowAdapter (val context: Context, val listProducts: List<Product>) : R
override fun getItemCount(): Int {
return listProducts.size
}

}

21 changes: 21 additions & 0 deletions app/src/main/java/com/myrefriapp/DetailRowActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.myrefriapp

import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.widget.TextView

class DetailRowActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_detail_row)

val extras: Bundle = intent.extras
if (!extras.isEmpty){
val productName: TextView = findViewById(R.id.productName)
productName.setText(extras.getString("name"))
val productDetail: TextView = findViewById(R.id.productDetail)
productDetail.setText(extras.getString("detail"))
}
}
}
36 changes: 36 additions & 0 deletions app/src/main/res/layout/activity_detail_row.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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"
tools:context=".DetailRowActivity">

<TextView
android:id="@+id/productName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:text="TextView"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.077" />

<TextView
android:id="@+id/productDetail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:text="TextView"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/productName"
app:layout_constraintVertical_bias="0.071" />
</android.support.constraint.ConstraintLayout>

0 comments on commit 8e82e4a

Please sign in to comment.