diff --git a/app/build.gradle b/app/build.gradle index 3ed80a0..7d3b0e4 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -114,6 +114,9 @@ dependencies { testImplementation testFixtures(project(':core')) androidTestImplementation testFixtures(project(':core')) + + // case specific + implementation project(":examplecase:example-navcontroller") } apply from: '../gradlescripts/pull-screenshots.gradle' \ No newline at end of file diff --git a/build.gradle b/build.gradle index b40d313..d055725 100644 --- a/build.gradle +++ b/build.gradle @@ -2,6 +2,7 @@ buildscript { ext.kotlin_version = "1.6.10" ext.detekt_version = "1.19.0" + ext.navigation_version = "2.4.2" repositories { mavenCentral() google() @@ -11,6 +12,7 @@ buildscript { classpath 'com.android.tools.build:gradle:7.1.3' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath "org.jlleitschuh.gradle:ktlint-gradle:10.2.1" + classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$navigation_version" } } diff --git a/examplecase/example-navcontroller/.gitignore b/examplecase/example-navcontroller/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/examplecase/example-navcontroller/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/examplecase/example-navcontroller/build.gradle b/examplecase/example-navcontroller/build.gradle new file mode 100644 index 0000000..914af41 --- /dev/null +++ b/examplecase/example-navcontroller/build.gradle @@ -0,0 +1,67 @@ +plugins { + id 'com.android.library' + id 'org.jetbrains.kotlin.android' + id 'androidx.navigation.safeargs.kotlin' +} + +android { + compileSdk 31 + + defaultConfig { + minSdk 21 + targetSdk 31 + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + consumerProguardFiles "consumer-rules.pro" + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + kotlinOptions { + jvmTarget = '1.8' + } + sourceSets { + androidTest { + java.srcDirs += "src/sharedTest/java" + assets.srcDirs += files("$projectDir/schemas".toString()) + } + test { + java.srcDirs += "src/sharedTest/java" + java.srcDirs += "src/robolectricTest/java" + resources.srcDirs += files("$projectDir/schemas".toString()) + } + } + + // needed for androidTest + packagingOptions { + exclude 'META-INF/LGPL2.1' + exclude 'META-INF/AL2.0' + exclude 'META-INF/LICENSE.md' + exclude 'META-INF/LICENSE-notice.md' + } +} + +dependencies { + implementation "androidx.core:core-ktx:$androidx_core_version" + implementation "androidx.appcompat:appcompat:$androidx_appcompat_version" + implementation "com.google.android.material:material:$androidx_material_version" + implementation "androidx.navigation:navigation-fragment-ktx:$navigation_version" + implementation "androidx.navigation:navigation-ui-ktx:$navigation_version" + + debugImplementation "androidx.fragment:fragment-testing:1.5.3" + + applyAppTestDependenciesTo(this) + + testImplementation "androidx.navigation:navigation-testing:$navigation_version" + testImplementation project(':test-util-android') + androidTestImplementation project(':test-util-android') + androidTestImplementation "androidx.navigation:navigation-testing:$navigation_version" +} \ No newline at end of file diff --git a/examplecase/example-navcontroller/consumer-rules.pro b/examplecase/example-navcontroller/consumer-rules.pro new file mode 100644 index 0000000..e69de29 diff --git a/examplecase/example-navcontroller/proguard-rules.pro b/examplecase/example-navcontroller/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /dev/null +++ b/examplecase/example-navcontroller/proguard-rules.pro @@ -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 \ No newline at end of file diff --git a/examplecase/example-navcontroller/src/main/AndroidManifest.xml b/examplecase/example-navcontroller/src/main/AndroidManifest.xml new file mode 100644 index 0000000..84f7369 --- /dev/null +++ b/examplecase/example-navcontroller/src/main/AndroidManifest.xml @@ -0,0 +1,8 @@ + + + + + + + \ No newline at end of file diff --git a/examplecase/example-navcontroller/src/main/java/org/fnives/test/showcase/examplecase/navcontroller/DetailFragment.kt b/examplecase/example-navcontroller/src/main/java/org/fnives/test/showcase/examplecase/navcontroller/DetailFragment.kt new file mode 100644 index 0000000..f5e58d3 --- /dev/null +++ b/examplecase/example-navcontroller/src/main/java/org/fnives/test/showcase/examplecase/navcontroller/DetailFragment.kt @@ -0,0 +1,17 @@ +package org.fnives.test.showcase.examplecase.navcontroller + +import android.os.Bundle +import android.view.View +import android.widget.TextView +import androidx.fragment.app.Fragment +import androidx.navigation.fragment.navArgs + +class DetailFragment : Fragment(R.layout.fragment_detail) { + + private val args by navArgs() + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + (view as TextView).text = getString(R.string.home_item, args.position) + } +} \ No newline at end of file diff --git a/examplecase/example-navcontroller/src/main/java/org/fnives/test/showcase/examplecase/navcontroller/HomeFragment.kt b/examplecase/example-navcontroller/src/main/java/org/fnives/test/showcase/examplecase/navcontroller/HomeFragment.kt new file mode 100644 index 0000000..322ee50 --- /dev/null +++ b/examplecase/example-navcontroller/src/main/java/org/fnives/test/showcase/examplecase/navcontroller/HomeFragment.kt @@ -0,0 +1,44 @@ +package org.fnives.test.showcase.examplecase.navcontroller + +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.Button +import androidx.fragment.app.Fragment +import androidx.navigation.fragment.findNavController +import androidx.recyclerview.widget.LinearLayoutManager +import androidx.recyclerview.widget.RecyclerView + +class HomeFragment : Fragment(R.layout.fragment_home) { + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + val recycler = view.findViewById(R.id.recycler) + recycler.layoutManager = LinearLayoutManager(view.context) + recycler.adapter = Adapter(onClick = { + if (findNavController().currentDestination?.id != R.id.homeFragment) return@Adapter + findNavController().navigate(HomeFragmentDirections.actionHomeFragmentToDetailFragment(it)) + }) + } + + class ViewHolder(view: View) : RecyclerView.ViewHolder(view) { + constructor(parent: ViewGroup) : this(LayoutInflater.from(parent.context).inflate(R.layout.item_home, parent, false)) + } + + class Adapter( + private val count: Int = 30, + private val onClick: (Int) -> Unit, + ) : RecyclerView.Adapter() { + override fun getItemCount(): Int = count + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder = + ViewHolder(parent) + + override fun onBindViewHolder(holder: ViewHolder, position: Int) { + val context = holder.itemView.context + (holder.itemView as Button).text = context.getString(R.string.home_item, position) + holder.itemView.setOnClickListener { onClick(position) } + } + } +} \ No newline at end of file diff --git a/examplecase/example-navcontroller/src/main/java/org/fnives/test/showcase/examplecase/navcontroller/NavControllerActivity.kt b/examplecase/example-navcontroller/src/main/java/org/fnives/test/showcase/examplecase/navcontroller/NavControllerActivity.kt new file mode 100644 index 0000000..83eaf44 --- /dev/null +++ b/examplecase/example-navcontroller/src/main/java/org/fnives/test/showcase/examplecase/navcontroller/NavControllerActivity.kt @@ -0,0 +1,15 @@ +package org.fnives.test.showcase.examplecase.navcontroller + +import android.os.Bundle +import androidx.appcompat.app.AppCompatActivity + +// to see the actual screen, not just in test use: +// adb shell am start -n org.fnives.test.showcase/org.fnives.test.showcase.examplecase.navcontroller.NavControllerActivity +// after installing the apk +class NavControllerActivity : AppCompatActivity() { + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_nav_controller) + } +} \ No newline at end of file diff --git a/examplecase/example-navcontroller/src/main/res/layout/activity_nav_controller.xml b/examplecase/example-navcontroller/src/main/res/layout/activity_nav_controller.xml new file mode 100644 index 0000000..1c1ef79 --- /dev/null +++ b/examplecase/example-navcontroller/src/main/res/layout/activity_nav_controller.xml @@ -0,0 +1,28 @@ + + + + + + + + \ No newline at end of file diff --git a/examplecase/example-navcontroller/src/main/res/layout/fragment_detail.xml b/examplecase/example-navcontroller/src/main/res/layout/fragment_detail.xml new file mode 100644 index 0000000..c4fe6a9 --- /dev/null +++ b/examplecase/example-navcontroller/src/main/res/layout/fragment_detail.xml @@ -0,0 +1,10 @@ + + + + \ No newline at end of file diff --git a/examplecase/example-navcontroller/src/main/res/layout/fragment_home.xml b/examplecase/example-navcontroller/src/main/res/layout/fragment_home.xml new file mode 100644 index 0000000..ea78406 --- /dev/null +++ b/examplecase/example-navcontroller/src/main/res/layout/fragment_home.xml @@ -0,0 +1,8 @@ + + \ No newline at end of file diff --git a/examplecase/example-navcontroller/src/main/res/layout/item_home.xml b/examplecase/example-navcontroller/src/main/res/layout/item_home.xml new file mode 100644 index 0000000..580482b --- /dev/null +++ b/examplecase/example-navcontroller/src/main/res/layout/item_home.xml @@ -0,0 +1,9 @@ + +