Skip to content

Commit

Permalink
Added Initial Project structure and nested recycler view files
Browse files Browse the repository at this point in the history
  • Loading branch information
navi25 committed Sep 8, 2018
1 parent 133235f commit d2a4feb
Show file tree
Hide file tree
Showing 46 changed files with 1,019 additions and 0 deletions.
29 changes: 29 additions & 0 deletions .idea/codeStyles/Project.xml

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

34 changes: 34 additions & 0 deletions .idea/misc.xml

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

9 changes: 9 additions & 0 deletions .idea/modules.xml

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

12 changes: 12 additions & 0 deletions .idea/runConfigurations.xml

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

6 changes: 6 additions & 0 deletions .idea/vcs.xml

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

1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
37 changes: 37 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion 27
defaultConfig {
applicationId "io.navendra.nestedrecycler"
minSdkVersion 23
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'

implementation 'com.android.support:recyclerview-v7:27.1.1'
implementation 'com.android.support:cardview-v7:27.1.1'

testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
21 changes: 21 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package io.navendra.nestedrecycler

import android.support.test.InstrumentationRegistry
import android.support.test.runner.AndroidJUnit4

import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getTargetContext()
assertEquals("io.navendra.nestedrecycler", appContext.packageName)
}
}
21 changes: 21 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="io.navendra.nestedrecycler">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".views.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package io.navendra.nestedrecycler.models

import io.navendra.nestedrecycler.R
import java.util.*

object ChildDataFactory{

private val random = Random()

private val titles = arrayListOf( "Aviator", "Now you can See me", "God Father", "Mission Impossible", "3 idiots")

private fun randomTitle() : String{
val index = random.nextInt(titles.size)
return titles[index]
}

private fun randomImage() : Int{
return R.drawable.aviator
}

fun getChildren(count : Int) : List<ChildModel>{
val children = mutableListOf<ChildModel>()
repeat(count){
val child = ChildModel(randomImage(), randomTitle())
children.add(child)
}
return children
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package io.navendra.nestedrecycler.models

data class ChildModel(
val image : Int = -1,
val title : String = ""
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package io.navendra.nestedrecycler.models

import java.util.*

object ParentDataFactory{
private val random = Random()

private val titles = arrayListOf( "Now Playing", "Classic", "Comedy", "Thriller", "Action", "Horror", "TV Series")

private fun randomTitle() : String{
val index = random.nextInt(titles.size)
return titles[index]
}

private fun randomChildren() : List<ChildModel>{
return ChildDataFactory.getChildren(20)
}

fun getParents(count : Int) : List<ParentModel>{
val parents = mutableListOf<ParentModel>()
repeat(count){
val parent = ParentModel(randomTitle(), randomChildren())
parents.add(parent)
}
return parents
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package io.navendra.nestedrecycler.models

data class ParentModel (
val title : String = "",
val children : List<ChildModel>
)
32 changes: 32 additions & 0 deletions app/src/main/java/io/navendra/nestedrecycler/views/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package io.navendra.nestedrecycler.views

import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
import android.widget.LinearLayout
import io.navendra.nestedrecycler.R
import io.navendra.nestedrecycler.models.ParentDataFactory
import io.navendra.nestedrecycler.views.adapters.ParentAdapter
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() {

lateinit var recyclerView: RecyclerView
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

initRecycler()
}

private fun initRecycler(){
recyclerView = rv_parent

recyclerView.apply {
layoutManager = LinearLayoutManager(this@MainActivity, LinearLayout.VERTICAL, false)
adapter = ParentAdapter(ParentDataFactory.getParents(40))
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package io.navendra.nestedrecycler.views.adapters

import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import io.navendra.nestedrecycler.R
import io.navendra.nestedrecycler.models.ChildModel
import kotlinx.android.synthetic.main.child_recycler.view.*

class ChildAdapter(private val children : List<ChildModel>) : RecyclerView.Adapter<ChildAdapter.ViewHolder>(){
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val v = LayoutInflater.from(parent.context).inflate(R.layout.child_recycler,parent,false)
return ViewHolder(v)
}

override fun getItemCount(): Int {
return children.size
}

override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val child = children[position]
holder.imageView.setImageResource(child.image)
holder.textView.text = child.title
}


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

val textView : TextView = itemView.child_textView
val imageView: ImageView = itemView.child_imageView

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package io.navendra.nestedrecycler.views.adapters

import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import android.widget.TextView
import io.navendra.nestedrecycler.R
import io.navendra.nestedrecycler.models.ParentModel
import kotlinx.android.synthetic.main.parent_recycler.view.*

class ParentAdapter(private val parents : List<ParentModel>) : RecyclerView.Adapter<ParentAdapter.ViewHolder>(){
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val v = LayoutInflater.from(parent.context).inflate(R.layout.parent_recycler,parent,false)
return ViewHolder(v)
}

override fun getItemCount(): Int {
return parents.size
}

override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val parent = parents[position]
holder.textView.text = parent.title
holder.recyclerView.apply {
layoutManager = LinearLayoutManager(holder.recyclerView.context, LinearLayout.HORIZONTAL, false)
adapter = ChildAdapter(parent.children)
}
}


inner class ViewHolder(itemView : View) : RecyclerView.ViewHolder(itemView){
val recyclerView : RecyclerView = itemView.rv_child
val textView:TextView = itemView.textView
}
}
Loading

0 comments on commit d2a4feb

Please sign in to comment.