-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Initial Project structure and nested recycler view files
- Loading branch information
Showing
46 changed files
with
1,019 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
24 changes: 24 additions & 0 deletions
24
app/src/androidTest/java/io/navendra/nestedrecycler/ExampleInstrumentedTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
31 changes: 31 additions & 0 deletions
31
app/src/main/java/io/navendra/nestedrecycler/models/ChildDataFactory.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
|
||
|
||
} |
6 changes: 6 additions & 0 deletions
6
app/src/main/java/io/navendra/nestedrecycler/models/ChildModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = "" | ||
) |
27 changes: 27 additions & 0 deletions
27
app/src/main/java/io/navendra/nestedrecycler/models/ParentDataFactory.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
app/src/main/java/io/navendra/nestedrecycler/models/ParentModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
32
app/src/main/java/io/navendra/nestedrecycler/views/MainActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
} | ||
|
||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
app/src/main/java/io/navendra/nestedrecycler/views/adapters/ChildAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
app/src/main/java/io/navendra/nestedrecycler/views/adapters/ParentAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
Oops, something went wrong.