Skip to content

Commit af18564

Browse files
committed
添加个人中心和项目tab
1 parent cd9af3c commit af18564

File tree

163 files changed

+3612
-138
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

163 files changed

+3612
-138
lines changed

.idea/gradle.xml

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,13 @@ android {
1111

1212
dependencies {
1313

14+
implementation project(path: ':common')
15+
implementation project(path: ':service')
1416
if (!singleModule.toBoolean()) {
1517
implementation project(path: ':home')
16-
implementation project(path: ':common')
1718
implementation project(path: ':webview')
19+
implementation project(path: ':personal')
20+
implementation project(path: ':project')
21+
implementation project(path: ':login')
1822
}
1923
}
Lines changed: 79 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,111 @@
11
package com.fuusy.jetpackkt
22

3+
import android.os.Bundle
4+
import android.util.Log
5+
import android.view.View
36
import androidx.fragment.app.Fragment
47
import androidx.fragment.app.FragmentActivity
8+
import androidx.lifecycle.LiveData
9+
import androidx.lifecycle.Observer
10+
import androidx.navigation.NavController
511
import androidx.viewpager2.adapter.FragmentStateAdapter
612
import com.alibaba.android.arouter.facade.annotation.Route
713
import com.fuusy.common.base.BaseActivity
14+
import com.fuusy.common.ktx.setupWithNavController
815
import com.fuusy.common.support.Constants
916
import com.fuusy.home.ui.HomeFragment
1017
import com.fuusy.jetpackkt.databinding.ActivityMainBinding
18+
import com.fuusy.personal.PersonalFragment
19+
import com.fuusy.project.ui.ProjectFragment
20+
21+
private const val TAG = "MainActivity"
1122

1223
@Route(path = Constants.PATH_MAIN)
1324
class MainActivity : BaseActivity<ActivityMainBinding>() {
25+
private var currentNavController: LiveData<NavController>? = null
26+
27+
companion object {
28+
private const val INDEX_HOME = 0
29+
private const val INDEX_PROJECT = 1
30+
private const val INDEX_PERSONAL = 2
31+
}
32+
33+
private val fragments = mapOf<Int, Fragment>(
34+
INDEX_HOME to HomeFragment(),
35+
INDEX_PROJECT to ProjectFragment(),
36+
INDEX_PERSONAL to PersonalFragment()
37+
)
1438

1539
override fun getLayoutId(): Int {
1640
return R.layout.activity_main
1741
}
1842

1943
private lateinit var mFragmentAdapter: VpFragmentAdapter
2044

21-
override fun initData() {
22-
mFragmentAdapter = VpFragmentAdapter(this)
23-
mBinding?.vpFragment?.adapter = mFragmentAdapter
24-
mBinding?.vpFragment?.isUserInputEnabled = false
45+
override fun initData(savedInstanceState: Bundle?) {
46+
setupBottomNavigationBar()
47+
currentNavController
2548

49+
// mFragmentAdapter = VpFragmentAdapter(this, fragments)
50+
// mBinding?.run {
51+
// BnvMediator(navView,vpFragment){bnv,vp2->
52+
// vp2.isUserInputEnabled = false
53+
// }.attach()
54+
// }
55+
// mBinding?.vpFragment?.adapter = mFragmentAdapter
56+
}
2657

58+
override fun onRestoreInstanceState(savedInstanceState: Bundle) {
59+
super.onRestoreInstanceState(savedInstanceState)
60+
setupBottomNavigationBar()
2761
}
2862

29-
class VpFragmentAdapter(fragment: FragmentActivity) : FragmentStateAdapter(fragment) {
63+
class VpFragmentAdapter(fragment: FragmentActivity, private val fragments: Map<Int, Fragment>) :
64+
FragmentStateAdapter(fragment) {
3065
override fun getItemCount(): Int {
31-
return 1
66+
return fragments.size
3267
}
3368

3469
override fun createFragment(position: Int): Fragment {
35-
return HomeFragment()
70+
return fragments[position] ?: error("ViewPager接收参数index越界")
71+
72+
}
73+
}
74+
3675

76+
/**
77+
* navigation绑定BottomNavigationView
78+
*/
79+
private fun setupBottomNavigationBar() {
80+
val navGraphIds =
81+
listOf(R.navigation.navi_home, R.navigation.navi_project, R.navigation.navi_personal)
82+
83+
mBinding.run {
84+
Log.d(TAG, "setupBottomNavigationBar: ")
3785
}
86+
val controller = mBinding?.navView?.setupWithNavController(
87+
navGraphIds = navGraphIds,
88+
fragmentManager = supportFragmentManager,
89+
containerId = R.id.nav_host_container,
90+
intent = intent
91+
)
92+
controller?.observe(this, Observer { navController ->
93+
//setupActionBarWithNavController(navController)
94+
navController.addOnDestinationChangedListener { controller, destination, arguments ->
95+
run {
96+
val id = destination.id
97+
if (id == R.id.projectContentFragment) {
98+
mBinding?.navView?.visibility = View.GONE
99+
} else {
100+
mBinding?.navView?.visibility = View.VISIBLE
101+
}
102+
}
103+
}
104+
})
105+
currentNavController = controller
106+
}
107+
108+
override fun onSupportNavigateUp(): Boolean {
109+
return currentNavController?.value?.navigateUp() ?: false
38110
}
39111
}

app/src/main/java/com/fuusy/jetpackkt/MainApp.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.fuusy.jetpackkt
22

33
import android.app.Application
4+
import android.content.Context
5+
import androidx.multidex.MultiDex
46
import com.alibaba.android.arouter.launcher.ARouter
57

68
class MainApp : Application() {
@@ -17,4 +19,9 @@ class MainApp : Application() {
1719
ARouter.openDebug()
1820
}
1921
}
22+
23+
override fun attachBaseContext(base: Context?) {
24+
super.attachBaseContext(base)
25+
MultiDex.install(base)
26+
}
2027
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<vector android:height="24dp" android:tint="#FF4500"
2+
android:viewportHeight="24" android:viewportWidth="24"
3+
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
4+
<path android:fillColor="@android:color/white" android:pathData="M14,4l2.29,2.29 -2.88,2.88 1.42,1.42 2.88,-2.88L20,10L20,4zM10,4L4,4v6l2.29,-2.29 4.71,4.7L11,20h2v-8.41l-5.29,-5.3z"/>
5+
</vector>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<vector android:height="24dp" android:tint="#FF4500"
2+
android:viewportHeight="24" android:viewportWidth="24"
3+
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
4+
<path android:fillColor="@android:color/white" android:pathData="M10,20v-6h4v6h5v-8h3L12,3 2,12h3v8z"/>
5+
</vector>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<vector android:height="24dp" android:tint="#FF4500"
2+
android:viewportHeight="24" android:viewportWidth="24"
3+
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
4+
<path android:fillColor="@android:color/white" android:pathData="M12,5.9c1.16,0 2.1,0.94 2.1,2.1s-0.94,2.1 -2.1,2.1S9.9,9.16 9.9,8s0.94,-2.1 2.1,-2.1m0,9c2.97,0 6.1,1.46 6.1,2.1v1.1L5.9,18.1L5.9,17c0,-0.64 3.13,-2.1 6.1,-2.1M12,4C9.79,4 8,5.79 8,8s1.79,4 4,4 4,-1.79 4,-4 -1.79,-4 -4,-4zM12,13c-2.67,0 -8,1.34 -8,4v3h16v-3c0,-2.66 -5.33,-4 -8,-4z"/>
5+
</vector>
Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,33 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<layout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto">
2+
<layout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto">
4+
35
<data>
46

57
</data>
6-
<androidx.constraintlayout.widget.ConstraintLayout
7-
android:id="@+id/container"
8-
android:layout_width="match_parent"
9-
android:layout_height="match_parent">
108

11-
<androidx.viewpager2.widget.ViewPager2
12-
android:id="@+id/vp_fragment"
13-
android:layout_width="match_parent"
14-
android:layout_height="0dp"
15-
app:layout_constraintBottom_toTopOf="@id/nav_view"
16-
app:layout_constraintTop_toTopOf="parent"/>
9+
<LinearLayout
10+
android:id="@+id/container"
11+
android:layout_width="match_parent"
12+
android:layout_height="match_parent"
13+
android:orientation="vertical"
14+
android:background="@color/color_ffffff">
15+
16+
<androidx.fragment.app.FragmentContainerView
17+
android:id="@+id/nav_host_container"
18+
android:layout_width="match_parent"
19+
android:layout_height="0dp"
20+
android:layout_weight="1"/>
1721

1822
<com.google.android.material.bottomnavigation.BottomNavigationView
19-
android:id="@+id/nav_view"
20-
android:layout_width="0dp"
21-
android:layout_height="wrap_content"
22-
android:layout_marginStart="0dp"
23-
android:layout_marginEnd="0dp"
24-
android:background="?android:attr/windowBackground"
25-
app:layout_constraintBottom_toBottomOf="parent"
26-
app:layout_constraintLeft_toLeftOf="parent"
27-
app:layout_constraintRight_toRightOf="parent"
28-
app:menu="@menu/bottom_nav_menu"/>
23+
android:id="@+id/nav_view"
24+
android:layout_width="match_parent"
25+
android:layout_height="wrap_content"
26+
android:background="?android:attr/windowBackground"
27+
app:layout_constraintBottom_toBottomOf="parent"
28+
app:layout_constraintLeft_toLeftOf="parent"
29+
app:layout_constraintRight_toRightOf="parent"
30+
app:menu="@menu/bottom_nav_menu" />
2931

30-
</androidx.constraintlayout.widget.ConstraintLayout>
32+
</LinearLayout>
3133
</layout>

app/src/main/res/menu/bottom_nav_menu.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@
33

44
<item
55
android:id="@+id/navigation_home"
6-
android:icon="@drawable/ic_home_black_24dp"
6+
android:icon="@drawable/ic_baseline_home_24"
77
android:title="@string/title_home"/>
88

99
<item
1010
android:id="@+id/navigation_dashboard"
11-
android:icon="@drawable/ic_dashboard_black_24dp"
11+
android:icon="@drawable/ic_baseline_call_split_24"
1212
android:title="@string/title_dashboard"/>
1313

1414
<item
15-
android:id="@+id/navigation_notifications"
16-
android:icon="@drawable/ic_notifications_black_24dp"
15+
android:id="@+id/navigation_personal"
16+
android:icon="@drawable/ic_baseline_person_outline_24"
1717
android:title="@string/title_notifications"/>
1818

1919
</menu>

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@
33
<color name="colorPrimary">#6200EE</color>
44
<color name="colorPrimaryDark">#3700B3</color>
55
<color name="colorAccent">#03DAC5</color>
6+
7+
68
</resources>

0 commit comments

Comments
 (0)