Skip to content

Commit edc2787

Browse files
committed
Add splashing screen
1 parent b4b9e32 commit edc2787

File tree

18 files changed

+234
-6
lines changed

18 files changed

+234
-6
lines changed

app/build.gradle

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ android {
2424
defaultConfig {
2525
applicationId "com.jerry.blescanner"
2626

27-
versionCode 5
28-
versionName "1.0.0"
27+
versionCode 7
28+
versionName "1.0.2"
2929

3030
buildConfigField "String", "BASE_URL", "\"https://api-proxy.ofcom.org.uk/\""
3131
buildConfigField "String", "KEY", "\"\""
@@ -94,6 +94,7 @@ android {
9494
dependencies {
9595
implementation project(":base-modiule")
9696
implementation project(":jetpack-design-lib")
97+
implementation project(":features:splash")
9798
implementation project(":features:bluetooth")
9899

99100
// LeakCanary //app only
@@ -104,7 +105,6 @@ dependencies {
104105
implementation("com.google.firebase:firebase-crashlytics-ktx")
105106
implementation("com.google.firebase:firebase-analytics-ktx")
106107

107-
108108
}
109109

110110
// Allow references to generated code {https://developer.android.com/training/dependency-injection/hilt-android}

app/src/main/AndroidManifest.xml

+10-3
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,26 @@
2828
android:label="@string/app_name"
2929
android:roundIcon="@mipmap/ic_launcher_round"
3030
android:supportsRtl="true"
31-
android:theme="@style/Theme.BleScanner"
31+
android:theme="@style/Theme.App.Starting"
3232
tools:targetApi="31">
33+
3334
<activity
34-
android:name="com.jerry.blescanner.features.bluetooth.presentation.BluetoothActivity"
35+
android:name="com.jerry.blescanner.features.splash.presentation.SplashActivity"
3536
android:exported="true"
3637
android:label="@string/app_name"
37-
android:theme="@style/Theme.BleScanner">
38+
android:theme="@style/Theme.App.Starting">
3839
<intent-filter>
3940
<action android:name="android.intent.action.MAIN" />
4041

4142
<category android:name="android.intent.category.LAUNCHER" />
4243
</intent-filter>
4344
</activity>
45+
46+
<activity
47+
android:name="com.jerry.blescanner.features.bluetooth.presentation.BluetoothActivity"
48+
android:exported="true"
49+
android:label="@string/app_name"
50+
android:theme="@style/Theme.BleScanner"/>
4451
</application>
4552

4653
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:duration="1000">
4+
5+
<propertyValuesHolder
6+
android:propertyName="rotation"
7+
android:valueType="floatType"
8+
android:valueFrom="0.0"
9+
android:valueTo="360.0"/>
10+
11+
<propertyValuesHolder
12+
android:propertyName="scaleX"
13+
android:valueType="floatType"
14+
android:valueFrom="0.0"
15+
android:valueTo="0.4"/>
16+
17+
<propertyValuesHolder
18+
android:propertyName="scaleY"
19+
android:valueType="floatType"
20+
android:valueFrom="0.0"
21+
android:valueTo="0.4"/>
22+
23+
</objectAnimator>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<animated-vector xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:drawable="@drawable/logo">
4+
5+
<target
6+
android:animation="@animator/logo_animator"
7+
android:name="animationGroup"/>
8+
9+
</animated-vector>

app/src/main/res/drawable/logo.xml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<vector android:height="24dp" android:tint="#2334A2"
2+
android:viewportHeight="24" android:viewportWidth="24"
3+
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
4+
<!--animation-->
5+
<group
6+
android:name="animationGroup"
7+
android:pivotX="12"
8+
android:pivotY="12">
9+
<path android:fillColor="@android:color/white" android:pathData="M17.71,7.71L12,2h-1v7.59L6.41,5 5,6.41 10.59,12 5,17.59 6.41,19 11,14.41L11,22h1l5.71,-5.71 -4.3,-4.29 4.3,-4.29zM13,5.83l1.88,1.88L13,9.59L13,5.83zM14.88,16.29L13,18.17v-3.76l1.88,1.88z"/>
10+
</group>
11+
</vector>

app/src/main/res/values/themes.xml

+6
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,10 @@
22
<resources>
33

44
<style name="Theme.BleScanner" parent="android:Theme.Material.Light.NoActionBar" />
5+
6+
<style name="Theme.App.Starting" parent="Theme.SplashScreen">
7+
<item name="windowSplashScreenBackground">@color/black</item>
8+
<item name="postSplashScreenTheme">@style/Theme.BleScanner</item>
9+
<item name="windowSplashScreenAnimatedIcon">@drawable/animated_logo</item>
10+
</style>
511
</resources>

build.gradle

+2
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ buildscript {
6969
lifecycle_runtime_compose_version = "2.6.2"
7070

7171
jetpack_navigation_compose_version = "2.5.3"
72+
73+
core_splachscreen_version = '1.0.1'
7274
}
7375

7476
repositories {

common-library.gradle

+3
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,7 @@ dependencies {
4747

4848
//permission
4949
implementation "com.google.accompanist:accompanist-permissions:$permission_verion"
50+
51+
//splashscreen
52+
implementation "androidx.core:core-splashscreen:$core_splachscreen_version"
5053
}

features/splash/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

features/splash/build.gradle

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
plugins {
2+
id 'com.android.library'
3+
id 'org.jetbrains.kotlin.android'
4+
id 'com.google.dagger.hilt.android'
5+
}
6+
7+
apply from: "$project.rootDir/common-android-version.gradle"
8+
apply from: "$project.rootDir/common-library.gradle"
9+
apply from: "$project.rootDir/jacoco.gradle"
10+
apply from: "$project.rootDir/jetpack-compose.gradle"
11+
12+
13+
android {
14+
namespace 'com.jerry.blescanner.features.splash'
15+
}
16+
17+
18+
dependencies {
19+
implementation project(":base-modiule")
20+
implementation project(":jetpack-design-lib")
21+
implementation project(":features:bluetooth")
22+
23+
// testImplementation project(":shared-test")
24+
// androidTestImplementation project(":shared-test")
25+
26+
}

features/splash/consumer-rules.pro

Whitespace-only changes.

features/splash/proguard-rules.pro

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.jerry.blescanner.features.splash
2+
3+
import androidx.test.platform.app.InstrumentationRegistry
4+
import androidx.test.ext.junit.runners.AndroidJUnit4
5+
6+
import org.junit.Test
7+
import org.junit.runner.RunWith
8+
9+
import org.junit.Assert.*
10+
11+
/**
12+
* Instrumented test, which will execute on an Android device.
13+
*
14+
* See [testing documentation](http://d.android.com/tools/testing).
15+
*/
16+
@RunWith(AndroidJUnit4::class)
17+
class ExampleInstrumentedTest {
18+
@Test
19+
fun useAppContext() {
20+
// Context of the app under test.
21+
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22+
assertEquals("com.jerry.blescanner.features.splash.test", appContext.packageName)
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
3+
4+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.jerry.blescanner.features.splash.presentation
2+
3+
4+
import android.content.Intent
5+
import android.os.Bundle
6+
import androidx.activity.ComponentActivity
7+
import androidx.activity.viewModels
8+
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
9+
import androidx.lifecycle.Lifecycle
10+
import androidx.lifecycle.lifecycleScope
11+
import androidx.lifecycle.repeatOnLifecycle
12+
import com.jerry.blescanner.features.bluetooth.presentation.BluetoothActivity
13+
import com.jerry.blescanner.features.splash.presentation.viewmodel.SplashViewModel
14+
15+
import dagger.hilt.android.AndroidEntryPoint
16+
import kotlinx.coroutines.flow.collectLatest
17+
import kotlinx.coroutines.launch
18+
19+
@AndroidEntryPoint
20+
class SplashActivity : ComponentActivity() {
21+
22+
private val viewModel by viewModels<SplashViewModel>()
23+
24+
override fun onCreate(savedInstanceState: Bundle?) {
25+
super.onCreate(savedInstanceState)
26+
27+
installSplashScreen().apply {
28+
setKeepOnScreenCondition {
29+
viewModel.isReady != null
30+
}
31+
}
32+
33+
lifecycleScope.launch {
34+
repeatOnLifecycle(Lifecycle.State.STARTED) {
35+
viewModel.isReady.collectLatest {
36+
it?.let {
37+
startActivity(Intent(this@SplashActivity, BluetoothActivity::class.java))
38+
this@SplashActivity.finish()
39+
}
40+
41+
}
42+
}
43+
}
44+
}
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.jerry.blescanner.features.splash.presentation.viewmodel
2+
3+
import androidx.lifecycle.ViewModel
4+
import androidx.lifecycle.viewModelScope
5+
import dagger.hilt.android.lifecycle.HiltViewModel
6+
import kotlinx.coroutines.delay
7+
import kotlinx.coroutines.flow.MutableStateFlow
8+
import kotlinx.coroutines.flow.asStateFlow
9+
import kotlinx.coroutines.launch
10+
import javax.inject.Inject
11+
12+
13+
@HiltViewModel
14+
class SplashViewModel @Inject constructor(
15+
16+
): ViewModel() {
17+
18+
private val _isReady = MutableStateFlow<Boolean?>( null)
19+
val isReady = _isReady.asStateFlow()
20+
21+
init {
22+
viewModelScope.launch {
23+
delay(1000)
24+
_isReady.value = true
25+
}
26+
}
27+
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.jerry.blescanner.features.splash
2+
3+
import org.junit.jupiter.api.Assertions.assertEquals
4+
import org.junit.jupiter.api.Test
5+
6+
7+
/**
8+
* Example local unit test, which will execute on the development machine (host).
9+
*
10+
* See [testing documentation](http://d.android.com/tools/testing).
11+
*/
12+
class ExampleUnitTest {
13+
@Test
14+
fun addition_isCorrect() {
15+
assertEquals(4, 2 + 2)
16+
}
17+
}

settings.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ include ':app'
2020
include ':base-modiule'
2121
include ':jetpack-design-lib'
2222
include ':features:bluetooth'
23+
include ':features:splash'

0 commit comments

Comments
 (0)