-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
utilize component layout annotation and refactor ComponentManager to …
…ComponentFactory
- Loading branch information
Showing
18 changed files
with
191 additions
and
41 deletions.
There are no files selected for viewing
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,19 @@ | ||
apply plugin: 'kotlin' | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
compileKotlin { | ||
kotlinOptions { | ||
jvmTarget = "1.8" | ||
} | ||
} | ||
compileTestKotlin { | ||
kotlinOptions { | ||
jvmTarget = "1.8" | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" | ||
} |
9 changes: 9 additions & 0 deletions
9
annotation/src/main/java/com/seannajera/dkouple/ComponentAnnotations.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,9 @@ | ||
package com.seannajera.dkouple | ||
|
||
@Retention(AnnotationRetention.RUNTIME) | ||
@Target(AnnotationTarget.CLASS) | ||
annotation class DKoupleComponent(val layoutId: Int) | ||
|
||
@Retention(AnnotationRetention.SOURCE) | ||
@Target(AnnotationTarget.CLASS) | ||
annotation class DKoupleView(val layoutId: Int) |
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
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 |
---|---|---|
@@ -1,11 +1,23 @@ | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.seannajera.dkouple"> | ||
xmlns:tools="http://schemas.android.com/tools" | ||
package="com.seannajera.dkouple"> | ||
|
||
<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" /> | ||
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" | ||
tools:ignore="AllowBackup,GoogleAppIndexingWarning"> | ||
|
||
<activity android:name=".MainActivity" | ||
android:label="@string/app_name"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
</manifest> |
23 changes: 23 additions & 0 deletions
23
example/src/main/java/com/seannajera/dkouple/ItemComponent.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,23 @@ | ||
package com.seannajera.dkouple | ||
|
||
import android.view.View | ||
import android.widget.TextView | ||
|
||
@DKoupleComponent(R.layout.component_item) | ||
data class ItemComponent(override val id: String, val name: String) : Component { | ||
|
||
override fun contentSameAs(otherComponent: Any): Boolean { | ||
return this == (otherComponent as? ItemComponent) | ||
} | ||
} | ||
|
||
class ItemView(view: View) : ComponentView<ItemComponent>(view) { | ||
|
||
private val nameView: TextView by lazy { view.findViewById<TextView>(R.id.item_component_name) } | ||
|
||
override fun onViewUpdate(previous: ItemComponent?, current: ItemComponent) { | ||
if (previous?.name != current.name) { | ||
nameView.text = current.name | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
example/src/main/java/com/seannajera/dkouple/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,26 @@ | ||
package com.seannajera.dkouple | ||
|
||
import android.os.Bundle | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.recyclerview.widget.RecyclerView | ||
|
||
class MainActivity : AppCompatActivity() { | ||
|
||
private val componentFactory: ComponentFactory = MainComponentFactory() | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_main) | ||
|
||
val recyclerView = findViewById<RecyclerView>(R.id.recyclerview_main) | ||
|
||
val componentAdapter = ComponentAdapter(componentFactory) | ||
recyclerView.adapter = componentAdapter | ||
|
||
componentAdapter.applyComponents( | ||
listOf( | ||
ItemComponent("1", "First Item") | ||
) | ||
) | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
example/src/main/java/com/seannajera/dkouple/MainComponentFactory.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,12 @@ | ||
package com.seannajera.dkouple | ||
|
||
import android.view.View | ||
|
||
class MainComponentFactory : ComponentFactory { | ||
override fun createView(layoutId: Int, view: View): ComponentView<out Component> { | ||
return when (layoutId) { | ||
R.layout.component_item -> ItemView(view) | ||
else -> throw IllegalArgumentException("Could not find layout resource with id: $layoutId") | ||
} | ||
} | ||
} |
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,15 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout 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" | ||
android:orientation="vertical" | ||
tools:context=".MainActivity"> | ||
|
||
<androidx.recyclerview.widget.RecyclerView | ||
android:id="@+id/recyclerview_main" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" /> | ||
</LinearLayout> |
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,10 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<TextView xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:id="@+id/item_component_name" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:padding="16dp" | ||
android:textSize="16sp" | ||
android:textStyle="bold" | ||
tools:text="Some Items" /> |
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
<resources> | ||
<string name="app_name">ComponentView</string> | ||
<string name="app_name">DKouple</string> | ||
</resources> |
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
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
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
7 changes: 7 additions & 0 deletions
7
library/src/main/java/com/seannajera/dkouple/ComponentFactory.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,7 @@ | ||
package com.seannajera.dkouple | ||
|
||
import android.view.View | ||
|
||
interface ComponentFactory { | ||
fun createView(layoutId: Int, view: View): ComponentView<out Component> | ||
} |
8 changes: 0 additions & 8 deletions
8
library/src/main/java/com/seannajera/dkouple/ComponentManager.kt
This file was deleted.
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
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
include ':example', ':library' | ||
include ':example', ':annotation', ':library' | ||
rootProject.name='DKouple' |