Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 32 additions & 12 deletions app/src/androidTest/java/com/nmc/android/ui/LauncherActivityIT.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,55 @@
*/
package com.nmc.android.ui

import android.content.Intent
import android.view.View
import androidx.test.core.app.launchActivity
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import com.owncloud.android.AbstractIT
import com.owncloud.android.R
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
class LauncherActivityIT : AbstractIT() {

private val instrumentation get() = InstrumentationRegistry.getInstrumentation()

@Test
fun testSplashScreenWithEmptyTitlesShouldHideTitles() {
launchActivity<LauncherActivity>().onActivity { activity ->
assertEquals(View.VISIBLE, activity.findViewById<View>(R.id.ivSplash).visibility)
assertEquals(View.GONE, activity.findViewById<View>(R.id.splashScreenBold).visibility)
assertEquals(View.GONE, activity.findViewById<View>(R.id.splashScreenNormal).visibility)
}
val activity = launchLauncherActivity()

assertEquals(View.VISIBLE, activity.findViewById<View>(R.id.ivSplash).visibility)
assertEquals(View.GONE, activity.findViewById<View>(R.id.splashScreenBold).visibility)
assertEquals(View.GONE, activity.findViewById<View>(R.id.splashScreenNormal).visibility)
}

@Test
fun testSplashScreenWithTitlesShouldShowTitles() {
launchActivity<LauncherActivity>().onActivity { activity ->
activity.setSplashTitles("Example", "Cloud")
val activity = launchLauncherActivity()

instrumentation.runOnMainSync { activity.setSplashTitles("Example", "Cloud") }

assertEquals(View.VISIBLE, activity.findViewById<View>(R.id.ivSplash).visibility)
assertEquals(View.VISIBLE, activity.findViewById<View>(R.id.splashScreenBold).visibility)
assertEquals(View.VISIBLE, activity.findViewById<View>(R.id.splashScreenNormal).visibility)
}

@Test
fun testSplashScreenWithEmptyTitlesShouldNotDelayNextScreen() {
val activity = launchLauncherActivity()

instrumentation.waitForIdleSync()

assertTrue(activity.isFinishing)
}

private fun launchLauncherActivity(): LauncherActivity {
val intent = Intent(targetContext, LauncherActivity::class.java)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)

assertEquals(View.VISIBLE, activity.findViewById<View>(R.id.ivSplash).visibility)
assertEquals(View.VISIBLE, activity.findViewById<View>(R.id.splashScreenBold).visibility)
assertEquals(View.VISIBLE, activity.findViewById<View>(R.id.splashScreenNormal).visibility)
}
return instrumentation.startActivitySync(intent) as LauncherActivity
}
}
41 changes: 25 additions & 16 deletions app/src/main/java/com/nmc/android/ui/LauncherActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import android.content.Intent
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.text.TextUtils
import android.view.View
import androidx.annotation.VisibleForTesting
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
Expand All @@ -25,6 +24,7 @@ import com.owncloud.android.ui.activity.BaseActivity
import com.owncloud.android.ui.activity.FileDisplayActivity
import com.owncloud.android.ui.activity.SettingsActivity
import javax.inject.Inject
import kotlin.time.Duration.Companion.milliseconds

class LauncherActivity : BaseActivity() {

Expand Down Expand Up @@ -56,30 +56,39 @@ class LauncherActivity : BaseActivity() {
}

private fun updateTitleVisibility() {
if (TextUtils.isEmpty(resources.getString(R.string.splashScreenBold))) {
if (resources.getString(R.string.splashScreenBold).isEmpty()) {
binding.splashScreenBold.visibility = View.GONE
}
if (TextUtils.isEmpty(resources.getString(R.string.splashScreenNormal))) {
if (resources.getString(R.string.splashScreenNormal).isEmpty()) {
binding.splashScreenNormal.visibility = View.GONE
}
}

private fun hasBrandedTitle(): Boolean = resources.getString(R.string.splashScreenBold).isNotEmpty() ||
resources.getString(R.string.splashScreenNormal).isNotEmpty()

private fun scheduleSplashScreen() {
Handler(Looper.getMainLooper()).postDelayed({
if (user.isPresent) {
if (MDMConfig.enforceProtection(this) && appPreferences.lockPreference == SettingsActivity.LOCK_NONE) {
startActivity(Intent(this, SettingsActivity::class.java))
} else {
startActivity(Intent(this, FileDisplayActivity::class.java))
}
} else {
startActivity(Intent(this, AuthenticatorActivity::class.java))
}
finish()
}, SPLASH_DURATION)
val duration = if (hasBrandedTitle()) SPLASH_DURATION else NO_SPLASH_DURATION

Handler(Looper.getMainLooper()).postDelayed({ openNextScreen() }, duration.inWholeMilliseconds)
}

private fun openNextScreen() {
val nextScreen = when {
!user.isPresent -> AuthenticatorActivity::class.java

MDMConfig.enforceProtection(this) &&
appPreferences.lockPreference == SettingsActivity.LOCK_NONE -> SettingsActivity::class.java

else -> FileDisplayActivity::class.java
}

startActivity(Intent(this, nextScreen))
finish()
}

companion object {
const val SPLASH_DURATION = 1500L
private val SPLASH_DURATION = 1500.milliseconds
private val NO_SPLASH_DURATION = 100.milliseconds
}
}
Loading