Skip to content

Commit

Permalink
add view for splash
Browse files Browse the repository at this point in the history
  • Loading branch information
frank-nhatvm committed Apr 9, 2022
1 parent 520bbf1 commit 88e3848
Show file tree
Hide file tree
Showing 12 changed files with 178 additions and 4 deletions.
4 changes: 4 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.fatherofapps.androidbase">

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.FatherOfApps"
android:name=".CustomApplication"
>
<activity
android:exported="true"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
package com.fatherofapps.androidbase.activities

import android.os.Bundle
import android.util.Log
import android.view.View
import android.widget.FrameLayout
import com.fatherofapps.androidbase.R
import com.fatherofapps.androidbase.base.activities.BaseActivity
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class MainActivity : BaseActivity(){

private var loadingLayout: FrameLayout? = null

override fun onCreate(savedInstanceState: Bundle?) {
Log.e("Frank","MainActivity")
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
loadingLayout = findViewById(R.id.loadingLayout)
}

override fun showLoading(isShow: Boolean) {
loadingLayout?.visibility = if(isShow) View.VISIBLE else View.GONE
}


}
Original file line number Diff line number Diff line change
@@ -1,17 +1,31 @@
package com.fatherofapps.androidbase.activities

import android.content.Intent
import android.os.Bundle
import android.os.PersistableBundle
import android.util.Log
import android.widget.ImageView
import androidx.appcompat.app.AppCompatActivity
import com.fatherofapps.androidbase.R
import com.fatherofapps.androidbase.activities.MainActivity
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class SplashActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?, persistentState: PersistableBundle?) {
super.onCreate(savedInstanceState, persistentState)

override fun onCreate(savedInstanceState: Bundle?) {
Log.e("Frank","SplashAcitivty")
super.onCreate(savedInstanceState)

setContentView(R.layout.activity_splash)
findViewById<ImageView>(R.id.imgLaunch).postDelayed({
openMainActivity()
}, 3000)
}

private fun openMainActivity() {
val intent = Intent(this, MainActivity::class.java)
startActivity(intent)
finish()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,18 @@ open class BaseFragment : Fragment() {
return getString(R.string.default_notify_title)
}

protected fun registerAllExceptionEvent( viewModel: BaseViewModel,
viewLifecycleOwner: LifecycleOwner){
registerObserverExceptionEvent(viewModel,viewLifecycleOwner)
registerObserverNetworkExceptionEvent(viewModel,viewLifecycleOwner)
registerObserverMessageEvent(viewModel,viewLifecycleOwner)
}

protected fun registerObserverLoadingEvent(viewModel: BaseViewModel,viewLifecycleOwner: LifecycleOwner){
viewModel.isLoading.observe(viewLifecycleOwner,EventObserver{
isShow ->
showLoading(isShow)
})
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import androidx.lifecycle.ViewModel
import com.fatherofapps.androidbase.base.network.BaseNetworkException
import com.fatherofapps.androidbase.base.network.NetworkErrorException
import com.fatherofapps.androidbase.common.Event
import kotlinx.coroutines.CoroutineExceptionHandler
import kotlinx.coroutines.Job

open class BaseViewModel : ViewModel() {

Expand All @@ -29,6 +31,19 @@ open class BaseViewModel : ViewModel() {
var isLoadingMore = MutableLiveData<Event<Boolean>>()
protected set

var parentJob: Job? = null
protected set

protected fun registerJobFinish(){
parentJob?.invokeOnCompletion {
showLoading(false)
}
}

val handler = CoroutineExceptionHandler { _, exception ->
parseErrorCallApi(exception)
}

protected fun showError(messageId: Int) {
errorMessageResourceId.postValue(Event(messageId))
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,28 @@
package com.fatherofapps.androidbase.ui.home

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.fatherofapps.androidbase.base.fragment.BaseFragment
import com.fatherofapps.androidbase.databinding.FragmentHomeBinding
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class HomeFragment : BaseFragment() {


private lateinit var dataBinding: FragmentHomeBinding

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
dataBinding = FragmentHomeBinding.inflate(inflater)
dataBinding.lifecycleOwner = viewLifecycleOwner
return dataBinding.root
}


}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 33 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_height="match_parent">
<androidx.fragment.app.FragmentContainerView
android:id="@+id/container"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="0dp"
app:defaultNavHost="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:navGraph="@navigation/main_nav" />

<FrameLayout
android:id="@+id/loadingLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/darker_gray"
android:clickable="true"
android:elevation="12dp"
android:focusable="true"
android:visibility="gone">

<ProgressBar
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
</FrameLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
19 changes: 19 additions & 0 deletions app/src/main/res/layout/activity_splash.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">

<ImageView
android:id="@+id/imgLaunch"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:src="@drawable/home_spaceship_launch"
android:paddingHorizontal="24dp"
app:layout_constraintDimensionRatio="500:632"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_width="0dp"
android:layout_height="0dp"/>

</androidx.constraintlayout.widget.ConstraintLayout>
23 changes: 23 additions & 0 deletions app/src/main/res/layout/fragment_home.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<data>

</data>

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:text="Home"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
11 changes: 11 additions & 0 deletions app/src/main/res/navigation/main_nav.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_nav"
app:startDestination="@id/homeFragment">

<fragment
android:id="@+id/homeFragment"
android:name="com.fatherofapps.androidbase.ui.home.HomeFragment"
android:label="HomeFragment" />
</navigation>
10 changes: 10 additions & 0 deletions local.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@


## This file must *NOT* be checked into Version Control Systems,
# as it contains information specific to your local configuration.
#
# Location of the SDK. This is only used by Gradle.
# For customization when using a Version Control System, please read the
# header note.
#Tue Mar 22 21:33:40 ICT 2022
sdk.dir=/Users/nhatvu/Library/Android/sdk

0 comments on commit 88e3848

Please sign in to comment.