Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Splash screen + adopt fix for bottom navigation view for MainFrag…
…ment + add new tab
- Loading branch information
1 parent
56a7894
commit c35f738
Showing
42 changed files
with
437 additions
and
396 deletions.
There are no files selected for viewing
55 changes: 1 addition & 54 deletions
55
app/src/main/java/com/aaglobal/jnc_playground/RootActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,6 @@ | ||
package com.aaglobal.jnc_playground | ||
|
||
import android.os.Bundle | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.lifecycle.LiveData | ||
import androidx.lifecycle.Observer | ||
import androidx.navigation.NavController | ||
import androidx.navigation.ui.setupActionBarWithNavController | ||
import com.aaglobal.jnc_playground.extensions.setupWithNavController | ||
import com.google.android.material.bottomnavigation.BottomNavigationView | ||
|
||
class RootActivity : AppCompatActivity() { | ||
|
||
private var currentNavController: LiveData<NavController>? = null | ||
|
||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_root) | ||
if (savedInstanceState == null) { | ||
setupBottomNavigationBar() | ||
} // Else, need to wait for onRestoreInstanceState | ||
} | ||
|
||
override fun onRestoreInstanceState(savedInstanceState: Bundle) { | ||
super.onRestoreInstanceState(savedInstanceState) | ||
// Now that BottomNavigationBar has restored its instance state | ||
// and its selectedItemId, we can proceed with setting up the | ||
// BottomNavigationBar with Navigation | ||
setupBottomNavigationBar() | ||
} | ||
|
||
/** | ||
* Called on first creation and when restoring state. | ||
*/ | ||
private fun setupBottomNavigationBar() { | ||
val bottomNavigationView = findViewById<BottomNavigationView>(R.id.bottom_nav) | ||
|
||
val navGraphIds = listOf(R.navigation.home_nav_graph, R.navigation.dashboard_nav_graph, R.navigation.notifications_nav_graph) | ||
|
||
// Setup the bottom navigation view with a list of navigation graphs | ||
val controller = bottomNavigationView.setupWithNavController( | ||
navGraphIds = navGraphIds, | ||
fragmentManager = supportFragmentManager, | ||
containerId = R.id.nav_host_container, | ||
intent = intent | ||
) | ||
|
||
// Whenever the selected controller changes, setup the action bar. | ||
controller.observe(this, Observer { navController -> | ||
setupActionBarWithNavController(navController) | ||
}) | ||
currentNavController = controller | ||
} | ||
|
||
override fun onSupportNavigateUp(): Boolean { | ||
return currentNavController?.value?.navigateUp() ?: false | ||
} | ||
} | ||
class RootActivity : AppCompatActivity(R.layout.activity_root) |
37 changes: 0 additions & 37 deletions
37
app/src/main/java/com/aaglobal/jnc_playground/ui/dashboard/DashboardFragment.kt
This file was deleted.
Oops, something went wrong.
24 changes: 0 additions & 24 deletions
24
app/src/main/java/com/aaglobal/jnc_playground/ui/dashboard/DashboardViewModel.kt
This file was deleted.
Oops, something went wrong.
6 changes: 0 additions & 6 deletions
6
app/src/main/java/com/aaglobal/jnc_playground/ui/graphic/GraphicFragment.kt
This file was deleted.
Oops, something went wrong.
31 changes: 0 additions & 31 deletions
31
app/src/main/java/com/aaglobal/jnc_playground/ui/home/HomeFragment.kt
This file was deleted.
Oops, something went wrong.
13 changes: 0 additions & 13 deletions
13
app/src/main/java/com/aaglobal/jnc_playground/ui/home/HomeViewModel.kt
This file was deleted.
Oops, something went wrong.
60 changes: 60 additions & 0 deletions
60
app/src/main/java/com/aaglobal/jnc_playground/ui/main/MainFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.aaglobal.jnc_playground.ui.main | ||
|
||
import android.os.Bundle | ||
import android.view.View | ||
import androidx.fragment.app.Fragment | ||
import androidx.lifecycle.LiveData | ||
import androidx.navigation.NavController | ||
import com.aaglobal.jnc_playground.R | ||
import com.aaglobal.jnc_playground.extensions.setupWithNavController | ||
import kotlinx.android.synthetic.main.fragment_main.* | ||
|
||
/** | ||
* Main fragment -- container for bottom navigation | ||
*/ | ||
class MainFragment : Fragment(R.layout.fragment_main) { | ||
|
||
private var currentNavController: LiveData<NavController>? = null | ||
|
||
|
||
override fun onViewStateRestored(savedInstanceState: Bundle?) { | ||
super.onViewStateRestored(savedInstanceState) | ||
// Now that BottomNavigationBar has restored its instance state | ||
// and its selectedItemId, we can proceed with setting up the | ||
// BottomNavigationBar with Navigation | ||
setupBottomNavigationBar() | ||
} | ||
|
||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
if (savedInstanceState == null) { | ||
setupBottomNavigationBar() | ||
} | ||
} | ||
|
||
|
||
/** | ||
* Called on first creation and when restoring state. | ||
*/ | ||
private fun setupBottomNavigationBar() { | ||
val navGraphIds = listOf( | ||
R.navigation.search__nav_graph, | ||
R.navigation.favorites__nav_graph, | ||
R.navigation.responses__nav_graph, | ||
R.navigation.profile__nav_graph | ||
) | ||
|
||
// Setup the bottom navigation view with a list of navigation graphs | ||
val controller = fragment_main__bottom_navigation.setupWithNavController( | ||
navGraphIds = navGraphIds, | ||
fragmentManager = requireActivity().supportFragmentManager, | ||
containerId = R.id.fragment_main__nav_host_container, | ||
intent = requireActivity().intent | ||
) | ||
|
||
currentNavController = controller | ||
} | ||
|
||
|
||
} |
31 changes: 0 additions & 31 deletions
31
app/src/main/java/com/aaglobal/jnc_playground/ui/notifications/NotificationsFragment.kt
This file was deleted.
Oops, something went wrong.
13 changes: 0 additions & 13 deletions
13
app/src/main/java/com/aaglobal/jnc_playground/ui/notifications/NotificationsViewModel.kt
This file was deleted.
Oops, something went wrong.
27 changes: 27 additions & 0 deletions
27
app/src/main/java/com/aaglobal/jnc_playground/ui/splash/SplashFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.aaglobal.jnc_playground.ui.splash | ||
|
||
import android.os.Bundle | ||
import android.view.View | ||
import androidx.fragment.app.Fragment | ||
import androidx.fragment.app.viewModels | ||
import androidx.lifecycle.Observer | ||
import androidx.navigation.fragment.findNavController | ||
import com.aaglobal.jnc_playground.R | ||
|
||
|
||
class SplashFragment : Fragment(R.layout.fragment_splash) { | ||
|
||
private val splashViewModel: SplashViewModel by viewModels() | ||
|
||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
|
||
splashViewModel.isInProgress.observe(viewLifecycleOwner, Observer { isInProgress -> | ||
if (isInProgress.not()) { | ||
findNavController().navigate(R.id.action__SplashFragment__to__MainFragment) | ||
} | ||
}) | ||
} | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
app/src/main/java/com/aaglobal/jnc_playground/ui/splash/SplashViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.aaglobal.jnc_playground.ui.splash | ||
|
||
import androidx.lifecycle.LiveData | ||
import androidx.lifecycle.MutableLiveData | ||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import kotlinx.coroutines.delay | ||
import kotlinx.coroutines.launch | ||
|
||
|
||
class SplashViewModel : ViewModel() { | ||
|
||
private val _isInProgress = MutableLiveData(true) | ||
|
||
val isInProgress: LiveData<Boolean> = _isInProgress | ||
|
||
|
||
init { | ||
// Add special delay for splash screen | ||
viewModelScope.launch { | ||
delay(2000L) | ||
_isInProgress.value = false | ||
} | ||
} | ||
|
||
} |
8 changes: 8 additions & 0 deletions
8
...src/main/java/com/aaglobal/jnc_playground/ui/tabs/favorites/FavoritesContainerFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.aaglobal.jnc_playground.ui.tabs.favorites | ||
|
||
import androidx.fragment.app.Fragment | ||
import com.aaglobal.jnc_playground.R | ||
|
||
|
||
class FavoritesContainerFragment : Fragment(R.layout.fragment_favorites_container) { | ||
} |
8 changes: 8 additions & 0 deletions
8
app/src/main/java/com/aaglobal/jnc_playground/ui/tabs/profile/ProfileContainerFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.aaglobal.jnc_playground.ui.tabs.profile | ||
|
||
import androidx.fragment.app.Fragment | ||
import com.aaglobal.jnc_playground.R | ||
|
||
|
||
class ProfileContainerFragment : Fragment(R.layout.fragment_profile_container) { | ||
} |
8 changes: 8 additions & 0 deletions
8
...src/main/java/com/aaglobal/jnc_playground/ui/tabs/responses/ResponsesContainerFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.aaglobal.jnc_playground.ui.tabs.responses | ||
|
||
import androidx.fragment.app.Fragment | ||
import com.aaglobal.jnc_playground.R | ||
|
||
|
||
class ResponsesContainerFragment : Fragment(R.layout.fragment_responses_container) { | ||
} |
8 changes: 8 additions & 0 deletions
8
app/src/main/java/com/aaglobal/jnc_playground/ui/tabs/search/SearchContainerFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.aaglobal.jnc_playground.ui.tabs.search | ||
|
||
import androidx.fragment.app.Fragment | ||
import com.aaglobal.jnc_playground.R | ||
|
||
|
||
class SearchContainerFragment : Fragment(R.layout.fragment_search_container) { | ||
} |
Oops, something went wrong.