Skip to content
This repository has been archived by the owner on Dec 26, 2022. It is now read-only.

Commit

Permalink
[No issue] 2.0.0 work (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
isuPatches authored Dec 17, 2021
1 parent d93cccf commit a741482
Show file tree
Hide file tree
Showing 32 changed files with 505 additions and 196 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,21 @@

##### Breaking

## 2.0.0

##### Enhancements

##### Bug Fixes

##### Breaking

* [No issue] Updates for 2.0.0
- Organization and package structure updates
- Typo fixes
- Enable proguard for sample app
- Instrumentation test updates
- Update documentation for 2.0.0

## 1.2.0

##### Enhancements
Expand Down
15 changes: 9 additions & 6 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ android {
debug {
applicationIdSuffix = ".debug"
isTestCoverageEnabled = true
isMinifyEnabled = false
isShrinkResources = false
isMinifyEnabled = true
isShrinkResources = true
proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-rules-debug.pro")
testProguardFile(file("proguard-rules-test.pro"))
signingConfig = signingConfigs.getByName("debug")
Expand Down Expand Up @@ -91,11 +91,14 @@ android {
}

dependencies {
/*
* Toggle these to test release binary vs. source code
*/

implementation(project(":viewglu"))
// implementation("com.isupatches.android:viewglu:1.0.0") {

// Uncomment for testing with a production artifact
// implementation("com.isupatches.android:viewglu:2.0.0")

// Uncomment for testing with a SNAPSHOT artifact
// implementation("com.isupatches.android:viewglu:2.0.0-SNAPSHOT") {
// isChanging = true
// }

Expand Down
2 changes: 2 additions & 0 deletions app/proguard-rules-common.pro
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
-dontnote

-keepattributes *Annotation*, EnclosingMethod, InnerClasses, Signature
26 changes: 26 additions & 0 deletions app/proguard-rules-debug.pro
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
-dontobfuscate

-include proguard-rules-common.pro

-keepattributes SourceFile, LineNumberTable

-keep class androidx.fragment.app.testing.** { *; }

-keep class androidx.test.core.app.ActivityScenario { *; }
-keep class androidx.test.internal.platform.** { *; }
-keep class androidx.test.internal.runner.** { *; }
-keep class androidx.test.platform.** { *; }
-keep class androidx.test.runner.** { *; }

-keep class androidx.navigation.NavHostController {
createDeepLink();
setNavigatorProvider(...);
}

-keep class androidx.navigation.NavDeepLinkBuilder {
createTaskStackBuilder(...);
setArguments(...);
setDestination(...);
}

-keep class kotlin.jvm.internal.Intrinsics {
checkParameterIsNotNull(...);
checkExpressionValueIsNotNull(...);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright 2021 Patches Klinefelter
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.isupatches.android.viewglu.sample

import androidx.fragment.app.testing.FragmentScenario
import androidx.fragment.app.testing.launchFragmentInContainer
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.isupatches.android.viewglu.sample.testobjects.BaseRobot
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
internal class FragmentBoundTest {

@Test
fun displays() {
val scenario = launchFragmentInContainer<FragmentBound>(themeResId = R.style.AppTheme)
scenario
.boundScreen {
checkTextIsDisplayed(R.string.bound_fragment_text)
}
}
}

private fun FragmentScenario<FragmentBound>.boundScreen(
block: BoundFragmentRobot.() -> Unit
) = BoundFragmentRobot().apply { block() }

private class BoundFragmentRobot : BaseRobot()
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright 2021 Patches Klinefelter
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.isupatches.android.viewglu.sample

import androidx.fragment.app.testing.FragmentScenario
import androidx.fragment.app.testing.launchFragmentInContainer
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.isupatches.android.viewglu.sample.testobjects.BaseRobot
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
internal class FragmentInflatedTest {

@Test
fun displays() {
val scenario = launchFragmentInContainer<FragmentInflated>(themeResId = R.style.AppTheme)
scenario
.inflatedScreen {
checkTextIsDisplayed(R.string.inflated_fragment_text)
}
}
}

private fun FragmentScenario<FragmentInflated>.inflatedScreen(
block: InflatedFragmentRobot.() -> Unit
) = InflatedFragmentRobot().apply { block() }

private class InflatedFragmentRobot : BaseRobot()
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import androidx.test.core.app.ActivityScenario
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import com.isupatches.android.viewglu.sample.testobjects.BaseRobot
import com.isupatches.android.viewglue.sample.R
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,36 @@ package com.isupatches.android.viewglu.sample

import androidx.fragment.app.testing.FragmentScenario
import androidx.fragment.app.testing.launchFragmentInContainer
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.isupatches.android.viewglu.sample.testobjects.BaseRobot
import com.isupatches.android.viewglue.sample.R
import com.isupatches.android.viewglu.sample.testobjects.swipeNext
import com.isupatches.android.viewglu.sample.testobjects.swipePrevious
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
internal class MainFragmentTest {

@Test
fun displays() {
val scenario = launchFragmentInContainer<MainFragment>()
fun displaysBoundFragmentInViewPager() {
val scenario = launchFragmentInContainer<MainFragment>(themeResId = R.style.AppTheme)
scenario
.mainScreen {
checkTextIsDisplayed(R.string.app_name)
swipeNextOnViewPager()
swipePreviousOnViewPager()
checkTextIsDisplayed(R.string.bound_fragment_text)
}
}

@Test
fun displaysInflatedFragmentInViewPager() {
val scenario = launchFragmentInContainer<MainFragment>(themeResId = R.style.AppTheme)
scenario
.mainScreen {
swipeNextOnViewPager()
checkTextIsDisplayed(R.string.inflated_fragment_text)
}
}
}
Expand All @@ -40,4 +55,13 @@ private fun FragmentScenario<MainFragment>.mainScreen(
block: MainFragmentRobot.() -> Unit
) = MainFragmentRobot().apply { block() }

private class MainFragmentRobot : BaseRobot()
private class MainFragmentRobot : BaseRobot() {

fun swipePreviousOnViewPager() {
onView(withId(R.id.viewPager)).perform(swipePrevious())
}

fun swipeNextOnViewPager() {
onView(withId(R.id.viewPager)).perform(swipeNext())
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* Copyright 2021 Patches Klinefelter
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.isupatches.android.viewglu.sample.testobjects

import android.view.View
import androidx.core.view.ViewCompat
import androidx.test.espresso.UiController
import androidx.test.espresso.ViewAction
import androidx.test.espresso.action.ViewActions.swipeDown
import androidx.test.espresso.action.ViewActions.swipeLeft
import androidx.test.espresso.action.ViewActions.swipeRight
import androidx.test.espresso.action.ViewActions.swipeUp
import androidx.test.espresso.matcher.ViewMatchers.isAssignableFrom
import androidx.test.espresso.matcher.ViewMatchers.isDescendantOfA
import androidx.test.espresso.matcher.ViewMatchers.isDisplayingAtLeast
import androidx.viewpager2.widget.ViewPager2
import com.isupatches.android.viewglu.sample.testobjects.SwipeAction.Direction.BACKWARD
import com.isupatches.android.viewglu.sample.testobjects.SwipeAction.Direction.FORWARD
import org.hamcrest.Matcher
import org.hamcrest.Matchers.allOf
import org.hamcrest.Matchers.anyOf

/**
* ViewAction that issues a swipe gesture on a [ViewPager2] to move that ViewPager2 to the next
* page, taking orientation and layout direction into account.
*/
fun swipeNext(): ViewAction {
return SwipeAction(FORWARD)
}

/**
* ViewAction that issues a swipe gesture on a [ViewPager2] to move that ViewPager2 to the previous
* page, taking orientation and layout direction into account.
*/
fun swipePrevious(): ViewAction {
return SwipeAction(BACKWARD)
}

private class SwipeAction(val direction: Direction) : ViewAction {
enum class Direction {
FORWARD,
BACKWARD
}

override fun getDescription(): String = "Swiping $direction"

override fun getConstraints(): Matcher<View> =
allOf(
anyOf(
isAssignableFrom(ViewPager2::class.java),
isDescendantOfA(isAssignableFrom(ViewPager2::class.java))
),
isDisplayingAtLeast(90)
)

override fun perform(uiController: UiController, view: View) {
val vp = if (view is ViewPager2) {
view
} else {
var parent = view.parent
while (parent !is ViewPager2 && parent != null) {
parent = parent.parent
}
parent as ViewPager2
}
val isForward = direction == FORWARD
val swipeAction: ViewAction = if (vp.orientation == ViewPager2.ORIENTATION_HORIZONTAL) {
if (isForward == vp.isRtl()) swipeRight() else swipeLeft()
} else {
if (isForward) swipeUp() else swipeDown()
}
swipeAction.perform(uiController, view)
}

private fun ViewPager2.isRtl(): Boolean {
return ViewCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_RTL
}
}
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.isupatches.android.viewglue.sample">
package="com.isupatches.android.viewglu.sample">

<application
android:allowBackup="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ package com.isupatches.android.viewglu.sample

import android.os.Bundle
import android.view.View
import com.isupatches.android.viewglu.paste
import com.isupatches.android.viewglu.fragment.paste
import com.isupatches.android.viewglu.sample.base.BaseFragmentWithLayout
import com.isupatches.android.viewglue.sample.R
import com.isupatches.android.viewglue.sample.databinding.FragmentWithTextBinding
import com.isupatches.android.viewglu.sample.databinding.FragmentWithTextBinding

internal class FragmentBound : BaseFragmentWithLayout(R.layout.fragment_with_text) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.isupatches.android.viewglu.paste
import com.isupatches.android.viewglu.fragment.paste
import com.isupatches.android.viewglu.sample.base.BaseFragment
import com.isupatches.android.viewglue.sample.R
import com.isupatches.android.viewglue.sample.databinding.FragmentWithTextBinding
import com.isupatches.android.viewglu.sample.databinding.FragmentWithTextBinding

internal class FragmentInflated : BaseFragment() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
*/
package com.isupatches.android.viewglu.sample

import com.isupatches.android.viewglu.paste
import com.isupatches.android.viewglu.appcompat.activity.paste
import com.isupatches.android.viewglu.sample.base.BaseActivity
import com.isupatches.android.viewglue.sample.databinding.ActivityMainBinding
import com.isupatches.android.viewglu.sample.databinding.ActivityMainBinding

internal class MainActivity : BaseActivity() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ import android.view.View
import androidx.fragment.app.Fragment
import androidx.viewpager2.adapter.FragmentStateAdapter
import com.google.android.material.tabs.TabLayoutMediator
import com.isupatches.android.viewglu.paste
import com.isupatches.android.viewglu.fragment.paste
import com.isupatches.android.viewglu.sample.base.BaseFragmentWithLayout
import com.isupatches.android.viewglue.sample.R
import com.isupatches.android.viewglue.sample.databinding.FragmentMainBinding
import com.isupatches.android.viewglu.sample.databinding.FragmentMainBinding

internal class MainFragment : BaseFragmentWithLayout(R.layout.fragment_main) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ object BuildVersions {
const val TARGET_SDK: Int = 31
const val MIN_SDK: Int = 16

const val MODULE_VERSION_CODE: Int = 3
const val MODULE_VERSION_NAME: String = "1.2.0"
const val MODULE_VERSION_CODE: Int = 4
const val MODULE_VERSION_NAME: String = "2.0.0"
}
Loading

0 comments on commit a741482

Please sign in to comment.