diff --git a/orion-viewer/build.gradle b/orion-viewer/build.gradle index cd8d60128..6933e80d8 100644 --- a/orion-viewer/build.gradle +++ b/orion-viewer/build.gradle @@ -19,6 +19,7 @@ project.ext { dependencies { implementation 'androidx.appcompat:appcompat:1.6.1' + implementation 'androidx.preference:preference-ktx:1.2.1' //tab layout implementation 'com.google.android.material:material:1.9.0' implementation project(':tree-view-list-android') @@ -28,7 +29,11 @@ dependencies { implementation project(":nativeLibs:djvuModule") implementation project(":nativeLibs:mupdfModule") + androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' androidTestImplementation 'androidx.test:core:1.5.0' + androidTestImplementation 'androidx.test:core-ktx:1.5.0' + androidTestImplementation 'androidx.test.ext:junit:1.1.5' + androidTestImplementation 'androidx.test.ext:junit-ktx:1.1.5' androidTestImplementation 'androidx.test:runner:1.5.2' androidTestImplementation 'androidx.test:rules:1.5.0' diff --git a/orion-viewer/src/androidTest/kotlin/universe/constellation/orion/viewer/test/RenderingAndNavigationTest.kt b/orion-viewer/src/androidTest/kotlin/universe/constellation/orion/viewer/test/RenderingAndNavigationTest.kt index b560621eb..35af9d3fd 100644 --- a/orion-viewer/src/androidTest/kotlin/universe/constellation/orion/viewer/test/RenderingAndNavigationTest.kt +++ b/orion-viewer/src/androidTest/kotlin/universe/constellation/orion/viewer/test/RenderingAndNavigationTest.kt @@ -16,6 +16,7 @@ import universe.constellation.orion.viewer.prefs.initalizer import universe.constellation.orion.viewer.test.framework.BookDescription import universe.constellation.orion.viewer.test.framework.InstrumentationTestCase import universe.constellation.orion.viewer.test.framework.SingleThreadRenderer +import universe.constellation.orion.viewer.test.framework.openTestBook import universe.constellation.orion.viewer.view.Scene import java.util.concurrent.CountDownLatch diff --git a/orion-viewer/src/androidTest/kotlin/universe/constellation/orion/viewer/test/RotationTest.kt b/orion-viewer/src/androidTest/kotlin/universe/constellation/orion/viewer/test/RotationTest.kt index 0b6224179..cb1d83eac 100644 --- a/orion-viewer/src/androidTest/kotlin/universe/constellation/orion/viewer/test/RotationTest.kt +++ b/orion-viewer/src/androidTest/kotlin/universe/constellation/orion/viewer/test/RotationTest.kt @@ -1,24 +1,18 @@ package universe.constellation.orion.viewer.test -import android.content.Intent import android.content.pm.ActivityInfo -import android.net.Uri import org.junit.Assert import org.junit.Ignore import org.junit.Test +import universe.constellation.orion.viewer.test.framework.BookDescription import universe.constellation.orion.viewer.test.framework.InstrumentationTestCase -import universe.constellation.orion.viewer.test.framework.TestUtil -import java.util.concurrent.CountDownLatch class RotationTest : InstrumentationTestCase() { @Test @Ignore fun testRotation() { - val file = extractFileFromTestData(TestUtil.SICP) - val intent = Intent() - intent.data = Uri.fromFile(file) - startActivityWithBook(intent) + startActivityWithBook(BookDescription.SICP.toOpenIntent()) val view = activity.view val width = view.sceneWidth diff --git a/orion-viewer/src/androidTest/kotlin/universe/constellation/orion/viewer/test/espresso/CheckTapZoneWelcomeScreen.kt b/orion-viewer/src/androidTest/kotlin/universe/constellation/orion/viewer/test/espresso/CheckTapZoneWelcomeScreen.kt new file mode 100644 index 000000000..4fae1b4d5 --- /dev/null +++ b/orion-viewer/src/androidTest/kotlin/universe/constellation/orion/viewer/test/espresso/CheckTapZoneWelcomeScreen.kt @@ -0,0 +1,64 @@ +package universe.constellation.orion.viewer.test.espresso + +import android.content.Intent +import androidx.test.espresso.Espresso.* +import androidx.test.espresso.action.ViewActions +import androidx.test.espresso.assertion.ViewAssertions.doesNotExist +import androidx.test.espresso.assertion.ViewAssertions.matches +import androidx.test.espresso.matcher.ViewMatchers.isDisplayed +import androidx.test.espresso.matcher.ViewMatchers.withId +import androidx.test.ext.junit.rules.activityScenarioRule +import androidx.test.ext.junit.runners.AndroidJUnit4 +import androidx.test.platform.app.InstrumentationRegistry +import org.hamcrest.Matchers.* +import org.junit.Assert.assertFalse +import org.junit.Assert.assertTrue +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith +import universe.constellation.orion.viewer.OrionViewerActivity +import universe.constellation.orion.viewer.R +import universe.constellation.orion.viewer.prefs.GlobalOptions +import universe.constellation.orion.viewer.prefs.OrionApplication +import universe.constellation.orion.viewer.test.framework.BookDescription +import universe.constellation.orion.viewer.test.framework.InstrumentationTestCase + +abstract class CheckTapZoneWelcomeScreen(private val showTapHelp: Boolean, intent: Intent) : InstrumentationTestCase() { + + @get:Rule + var activityScenarioRule = activityScenarioRule(intent.apply { + if (showTapHelp) { + putExtra(GlobalOptions.SHOW_TAP_HELP, true) + } else { + putExtra(GlobalOptions.SHOW_TAP_HELP, false) + } + }) + +} +@RunWith(AndroidJUnit4::class) +class NoBookNoWelcome: CheckTapZoneWelcomeScreen(true, BookDescription.SICP.toOpenIntent().apply { data = null;}) { + @Test + fun testWelcome() { + val options = + (InstrumentationRegistry.getInstrumentation().targetContext.applicationContext as OrionApplication).options + onView(withId(R.id.tap_help_close)).check(doesNotExist()) + assertTrue(options.isShowTapHelp) + } +} + +@RunWith(AndroidJUnit4::class) +class BookWithWelcome: CheckTapZoneWelcomeScreen(true, BookDescription.SICP.toOpenIntent()) { + @Test + fun testWelcome() { + val options = + (InstrumentationRegistry.getInstrumentation().targetContext.applicationContext as OrionApplication).options + assertTrue(options.isShowTapHelp) + onView(withId(R.id.tap_help_close)).check(matches(isDisplayed())) + onView(withId(R.id.tap_help_close)).perform(ViewActions.click()) + onView(withId(R.id.tap_help_close)).check(matches(isDisplayed())) + onView(withId(R.id.tap_help_close)).check(doesNotExist()) +// +// assertFalse(options.isShowTapHelp) + + } +} \ No newline at end of file diff --git a/orion-viewer/src/androidTest/kotlin/universe/constellation/orion/viewer/test/framework/BaseTest.kt b/orion-viewer/src/androidTest/kotlin/universe/constellation/orion/viewer/test/framework/BaseTest.kt index 6c7ea90f1..3ffb8b229 100644 --- a/orion-viewer/src/androidTest/kotlin/universe/constellation/orion/viewer/test/framework/BaseTest.kt +++ b/orion-viewer/src/androidTest/kotlin/universe/constellation/orion/viewer/test/framework/BaseTest.kt @@ -1,23 +1,12 @@ package universe.constellation.orion.viewer.test.framework -import android.content.Context -import androidx.test.platform.app.InstrumentationRegistry import androidx.test.rule.GrantPermissionRule import org.junit.Rule -/** - * User: mike - * Date: 19.10.13 - * Time: 13:45 - */ abstract class BaseTest : TestUtil { @Rule @JvmField val mRuntimePermissionRule: GrantPermissionRule = GrantPermissionRule.grant(android.Manifest.permission.WRITE_EXTERNAL_STORAGE, android.Manifest.permission.READ_EXTERNAL_STORAGE) - override fun getOrionTestContext(): Context { - return InstrumentationRegistry.getInstrumentation().targetContext - } - } \ No newline at end of file diff --git a/orion-viewer/src/androidTest/kotlin/universe/constellation/orion/viewer/test/framework/BookTest.kt b/orion-viewer/src/androidTest/kotlin/universe/constellation/orion/viewer/test/framework/BookTest.kt index b903d3644..a527929f7 100644 --- a/orion-viewer/src/androidTest/kotlin/universe/constellation/orion/viewer/test/framework/BookTest.kt +++ b/orion-viewer/src/androidTest/kotlin/universe/constellation/orion/viewer/test/framework/BookTest.kt @@ -1,15 +1,19 @@ package universe.constellation.orion.viewer.test.framework +import android.content.Intent import android.graphics.Point +import android.net.Uri +import android.os.Bundle import org.junit.After import org.junit.runner.RunWith import org.junit.runners.Parameterized +import universe.constellation.orion.viewer.BuildConfig +import universe.constellation.orion.viewer.OrionViewerActivity @RunWith(Parameterized::class) abstract class BookTest(path: String) : BaseTest() { protected val document by lazy { openTestBook(path) } - @After fun close() { document.destroy() @@ -26,5 +30,17 @@ enum class BookDescription( ) { SICP(TestUtil.SICP, 762, "", 15, 139, Point(662, 885)), ALICE(TestUtil.ALICE, 77, null, 0, pageSize = Point(2481, 3508)), - DJVU_SPEC(TestUtil.DJVU_SPEC, 71, null, 1, 100, Point(2539, 3295)) + DJVU_SPEC(TestUtil.DJVU_SPEC, 71, null, 1, 100, Point(2539, 3295)); + + fun toOpenIntent(): Intent { + val path = extractFileFromTestData(path) + return Intent(Intent.ACTION_VIEW).apply { + setClassName( + BuildConfig.APPLICATION_ID, + OrionViewerActivity::class.qualifiedName!! + ) + data = Uri.fromFile(path) + addCategory(Intent.CATEGORY_DEFAULT) + } + } } \ No newline at end of file diff --git a/orion-viewer/src/androidTest/kotlin/universe/constellation/orion/viewer/test/framework/InstrumentationTestCase.kt b/orion-viewer/src/androidTest/kotlin/universe/constellation/orion/viewer/test/framework/InstrumentationTestCase.kt index c09246f01..f69b2338f 100644 --- a/orion-viewer/src/androidTest/kotlin/universe/constellation/orion/viewer/test/framework/InstrumentationTestCase.kt +++ b/orion-viewer/src/androidTest/kotlin/universe/constellation/orion/viewer/test/framework/InstrumentationTestCase.kt @@ -20,8 +20,6 @@ abstract class InstrumentationTestCase : TestUtil { val activity: OrionViewerActivity get() = mActivityRule.activity - override fun getOrionTestContext(): Context = mActivityRule.activity.orionContext - fun getController() : Controller = mActivityRule.activity.controller!! fun startActivityWithBook(intent: Intent) { diff --git a/orion-viewer/src/androidTest/kotlin/universe/constellation/orion/viewer/test/framework/TestUtil.kt b/orion-viewer/src/androidTest/kotlin/universe/constellation/orion/viewer/test/framework/TestUtil.kt index b46c56767..110098f0b 100644 --- a/orion-viewer/src/androidTest/kotlin/universe/constellation/orion/viewer/test/framework/TestUtil.kt +++ b/orion-viewer/src/androidTest/kotlin/universe/constellation/orion/viewer/test/framework/TestUtil.kt @@ -9,42 +9,34 @@ import java.io.File import java.io.FileOutputStream import java.io.IOException -/** - * User: mike - * Date: 20.10.13 - * Time: 8:32 - */ - -interface TestUtil { - - fun openTestBook(relativePath: String) : DocumentWithCaching { - val fileOnSdcard = extractFileFromTestData(relativePath) - return FileUtil.openFile(fileOnSdcard) - } - - fun extractFileFromTestData(fileName: String): File { - val outFile = File(testFolder, fileName) - if (outFile.exists()) { - return outFile - } - try { - outFile.parentFile!!.mkdirs() - outFile.createNewFile() - } catch (e: IOException) { - throw RuntimeException("Couldn't create new file " + outFile.absolutePath, e) - } - - val input = this.javaClass.classLoader!!.getResourceAsStream(getFileUnderTestData(fileName)) - val bufferedOutputStream = FileOutputStream(outFile).buffered() - input.buffered().copyTo(bufferedOutputStream) - bufferedOutputStream.close() +fun openTestBook(relativePath: String) : DocumentWithCaching { + val fileOnSdcard = extractFileFromTestData(relativePath) + return FileUtil.openFile(fileOnSdcard) +} + +fun extractFileFromTestData(fileName: String): File { + val outFile = File(TestUtil.testFolder, fileName) + if (outFile.exists()) { return outFile } + try { + outFile.parentFile!!.mkdirs() + outFile.createNewFile() + } catch (e: IOException) { + throw RuntimeException("Couldn't create new file " + outFile.absolutePath, e) + } - fun getFileUnderTestData(relativePath: String): String = "testData/$relativePath" + val input = ClassLoader.getSystemClassLoader().getResourceAsStream(getFileUnderTestData(fileName)) + val bufferedOutputStream = FileOutputStream(outFile).buffered() + input.buffered().copyTo(bufferedOutputStream) + bufferedOutputStream.close() + return outFile +} - fun getOrionTestContext(): Context +fun getFileUnderTestData(relativePath: String): String = "testData/$relativePath" + +interface TestUtil { companion object { val testFolder: File = File(Environment.getExternalStorageDirectory(), "orion") diff --git a/orion-viewer/src/main/java/universe/constellation/orion/viewer/OrionBaseActivity.kt b/orion-viewer/src/main/java/universe/constellation/orion/viewer/OrionBaseActivity.kt index 5b099fa1d..9bba58b77 100644 --- a/orion-viewer/src/main/java/universe/constellation/orion/viewer/OrionBaseActivity.kt +++ b/orion-viewer/src/main/java/universe/constellation/orion/viewer/OrionBaseActivity.kt @@ -20,6 +20,7 @@ package universe.constellation.orion.viewer import android.annotation.SuppressLint +import android.content.Intent import android.content.SharedPreferences import android.content.pm.ActivityInfo import android.content.pm.PackageManager diff --git a/orion-viewer/src/main/java/universe/constellation/orion/viewer/OrionViewerActivity.kt b/orion-viewer/src/main/java/universe/constellation/orion/viewer/OrionViewerActivity.kt index e4dd5c61d..86cd8ea1b 100644 --- a/orion-viewer/src/main/java/universe/constellation/orion/viewer/OrionViewerActivity.kt +++ b/orion-viewer/src/main/java/universe/constellation/orion/viewer/OrionViewerActivity.kt @@ -202,6 +202,7 @@ class OrionViewerActivity : OrionBaseActivity(viewerType = Device.VIEWER_ACTIVIT return } + processAdditionalOptionsInIntent(intent) openFileWithGrantedPermissions(intent) } @@ -1071,9 +1072,9 @@ class OrionViewerActivity : OrionBaseActivity(viewerType = Device.VIEWER_ACTIVIT } fun showTapDialogIfNeeded() { + println("tap") if (++tapHelpCounter < 2) return if (globalOptions.isShowTapHelp && !orionContext.isTesting) { - globalOptions.saveBooleanProperty(GlobalOptions.SHOW_TAP_HELP, false) TapHelpDialog(this).showDialog() } } @@ -1093,6 +1094,13 @@ class OrionViewerActivity : OrionBaseActivity(viewerType = Device.VIEWER_ACTIVIT } } + private fun processAdditionalOptionsInIntent(intent: Intent) { + if (intent.hasExtra(GlobalOptions.SHOW_TAP_HELP)) { + val showTapHelp = intent.getBooleanExtra(GlobalOptions.SHOW_TAP_HELP, false) + globalOptions.saveBooleanProperty(GlobalOptions.SHOW_TAP_HELP, showTapHelp) + } + } + companion object { val BOOK_MENU_ITEMS = setOf(R.id.search_menu_item, diff --git a/orion-viewer/src/main/java/universe/constellation/orion/viewer/dialog/TapHelpDialog.java b/orion-viewer/src/main/java/universe/constellation/orion/viewer/dialog/TapHelpDialog.java index bb44d603a..dbd3b51f6 100644 --- a/orion-viewer/src/main/java/universe/constellation/orion/viewer/dialog/TapHelpDialog.java +++ b/orion-viewer/src/main/java/universe/constellation/orion/viewer/dialog/TapHelpDialog.java @@ -8,6 +8,7 @@ import universe.constellation.orion.viewer.Action; import universe.constellation.orion.viewer.OrionViewerActivity; import universe.constellation.orion.viewer.R; +import universe.constellation.orion.viewer.prefs.GlobalOptions; import universe.constellation.orion.viewer.prefs.OrionTapActivity; /** @@ -58,7 +59,10 @@ public TapHelpDialog(OrionViewerActivity activity) { ImageView view = dialog.findViewById(R.id.tap_help_close); view.setVisibility(View.VISIBLE); view.setClickable(true); - view.setOnClickListener(v -> dialog.dismiss()); + view.setOnClickListener(v -> { + dialog.dismiss(); + activity.getGlobalOptions().saveBooleanProperty(GlobalOptions.SHOW_TAP_HELP, false); + }); } public void showDialog() { diff --git a/orion-viewer/src/main/java/universe/constellation/orion/viewer/prefs/GlobalOptions.java b/orion-viewer/src/main/java/universe/constellation/orion/viewer/prefs/GlobalOptions.java index 44b448640..39a4fe9aa 100644 --- a/orion-viewer/src/main/java/universe/constellation/orion/viewer/prefs/GlobalOptions.java +++ b/orion-viewer/src/main/java/universe/constellation/orion/viewer/prefs/GlobalOptions.java @@ -325,20 +325,6 @@ public boolean isEinkOptimization() { return getBooleanProperty(EINK_OPTIMIZATION, false); } -// public Integer getInteger(String key) { -// if (!prefValues.containsKey(key)) { -// String value = prefs.getString(key, null); -// Integer newIntValue = null; -// if (value == null || "".equals(value)) { -// return null; -// } else { -// newIntValue = Integer.valueOf(value); -// } -// prefValues.put(key, newIntValue); -// } -// return (Integer) prefValues.get(key); -// } - public int getIntFromStringProperty(String key, int defaultValue) { if (!prefValues.containsKey(key)) { String value = prefs.getString(key, null);