Skip to content

Commit

Permalink
(#2) Add bottom navigation on MainActivity.
Browse files Browse the repository at this point in the history
  • Loading branch information
myung jun Hyun committed Nov 26, 2019
1 parent a5fcf0d commit f7bb94c
Show file tree
Hide file tree
Showing 20 changed files with 205 additions and 34 deletions.
4 changes: 4 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ dependencies {
implementation "com.google.android.material:material:1.0.0"
implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.1.0'
implementation 'androidx.navigation:navigation-fragment:2.0.0'
implementation 'androidx.navigation:navigation-ui:2.0.0'
implementation 'androidx.navigation:navigation-fragment-ktx:2.0.0'
implementation 'androidx.navigation:navigation-ui-ktx:2.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
Expand Down
8 changes: 5 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".app.noticedetail.NoticeDetailActivity"></activity>
<activity
android:name=".app.main.MainActivity" />
<activity android:name=".app.noticedetail.NoticeDetailActivity" />
<activity android:name=".SplashActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand All @@ -21,9 +23,9 @@
</activity>
<activity
android:name=".app.notices.NoticesActivity"
android:theme="@style/AppTheme.NoActionBar"/>
android:theme="@style/AppTheme.NoActionBar" />
<activity android:name=".app.login.LoginActivity" />
<activity android:name=".app.attendees.AttendeesActivity" />
</application>

</manifest>
</manifest>
4 changes: 2 additions & 2 deletions app/src/main/java/com/mashup/SplashActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import android.os.Bundle
import android.os.Handler
import androidx.appcompat.app.AppCompatActivity
import com.mashup.app.login.LoginActivity
import com.mashup.app.notices.NoticesActivity
import com.mashup.app.main.MainActivity
import com.mashup.repository.notice.NoticesRepository
import com.mashup.repository.user.UserRepository
import io.reactivex.android.schedulers.AndroidSchedulers
Expand All @@ -29,7 +29,7 @@ class SplashActivity : AppCompatActivity() {
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe({
startActivity(Intent(this, NoticesActivity::class.java))
startActivity(Intent(this, MainActivity::class.java))
finish()
}, {
it.printStackTrace()
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/mashup/app/login/LoginFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.google.android.material.snackbar.Snackbar
import com.mashup.app.notices.NoticesActivity
import com.mashup.app.main.MainActivity
import com.mashup.databinding.LoginFragmentBinding
import com.mashup.util.EventObserver
import com.mashup.util.setupSnackbar
Expand Down Expand Up @@ -48,7 +48,7 @@ class LoginFragment : Fragment() {
viewModel.isLoginSuccess.observe(this, EventObserver {
if (it) {
activity?.finishAffinity()
val intent = Intent(this.context, NoticesActivity::class.java)
val intent = Intent(this.context, MainActivity::class.java)
startActivity(intent)
}
})
Expand Down
20 changes: 20 additions & 0 deletions app/src/main/java/com/mashup/app/main/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.mashup.app.main

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.navigation.findNavController
import androidx.navigation.ui.setupWithNavController
import com.google.android.material.bottomnavigation.BottomNavigationView
import com.mashup.R

class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val navView: BottomNavigationView = findViewById(R.id.nav_view)

val navController = findNavController(R.id.nav_host_fragment)
navView.setupWithNavController(navController)
}
}
19 changes: 0 additions & 19 deletions app/src/main/java/com/mashup/app/notices/NoticesActivity.kt

This file was deleted.

32 changes: 32 additions & 0 deletions app/src/main/java/com/mashup/app/setting/SettingFragment.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.mashup.app.setting

import androidx.lifecycle.ViewModelProviders
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.mashup.R

class SettingFragment : Fragment() {

companion object {
fun newInstance() = SettingFragment()
}

private lateinit var viewModel: SettingViewModel

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View {
return inflater.inflate(R.layout.setting_fragment, container, false)
}

override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
viewModel = ViewModelProviders.of(this).get(SettingViewModel::class.java)
// TODO: Use the ViewModel
}

}
7 changes: 7 additions & 0 deletions app/src/main/java/com/mashup/app/setting/SettingViewModel.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.mashup.app.setting

import androidx.lifecycle.ViewModel

class SettingViewModel : ViewModel() {
// TODO: Implement the ViewModel
}
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/ic_dashboard_black_24dp.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M3,13h8L11,3L3,3v10zM3,21h8v-6L3,15v6zM13,21h8L21,11h-8v10zM13,3v6h8L21,3h-8z" />
</vector>
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/ic_home_black_24dp.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M10,20v-6h4v6h5v-8h3L12,3 2,12h3v8z" />
</vector>
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/ic_notifications_black_24dp.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M12,22c1.1,0 2,-0.9 2,-2h-4c0,1.1 0.89,2 2,2zM18,16v-5c0,-3.07 -1.64,-5.64 -4.5,-6.32L13.5,4c0,-0.83 -0.67,-1.5 -1.5,-1.5s-1.5,0.67 -1.5,1.5v0.68C7.63,5.36 6,7.92 6,11v5l-2,2v1h16v-1l-2,-2z" />
</vector>
6 changes: 6 additions & 0 deletions app/src/main/res/drawable/shadow_bottom_to_up.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:startColor="#14000000"
android:endColor="@android:color/transparent"
android:angle="90" />
</shape>
41 changes: 41 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent">

<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/nav_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="0dp"
android:layout_marginEnd="0dp"
android:background="@color/colorWhite"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:menu="@menu/bottom_nav_menu" />

<fragment
android:id="@+id/nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="0dp"
app:defaultNavHost="true"
app:layout_constraintBottom_toTopOf="@id/nav_view"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:navGraph="@navigation/mobile_navigation" />

<View
android:id="@+id/bottom_line"
android:layout_width="match_parent"
android:layout_height="4dp"
app:layout_constraintBottom_toTopOf="@id/nav_view"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:background="@drawable/shadow_bottom_to_up" />

</androidx.constraintlayout.widget.ConstraintLayout>
7 changes: 0 additions & 7 deletions app/src/main/res/layout/notices_activity.xml

This file was deleted.

19 changes: 19 additions & 0 deletions app/src/main/res/layout/setting_fragment.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"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/setting"
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:id="@+id/message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SettingFragment"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

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

<item
android:id="@+id/navigation_notice"
android:icon="@drawable/ic_home_black_24dp"
android:title="@string/title_notice" />

<item
android:id="@+id/navigation_setting"
android:icon="@drawable/ic_dashboard_black_24dp"
android:title="@string/title_setting" />

</menu>
19 changes: 19 additions & 0 deletions app/src/main/res/navigation/mobile_navigation.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/mobile_navigation"
app:startDestination="@+id/navigation_notice">

<fragment
android:id="@+id/navigation_notice"
android:name="com.mashup.app.notices.NoticesFragment"
android:label="@string/title_notice"
tools:layout="@layout/notices_fragment" />

<fragment
android:id="@+id/navigation_setting"
android:name="com.mashup.app.setting.SettingFragment"
android:label="@string/title_setting"
tools:layout="@layout/setting_fragment" />
</navigation>
3 changes: 2 additions & 1 deletion app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
<color name="colorBaseBg">#EBF0F3</color>
<color name="colorEtHint">#DDDDDD</color>

<color name="line">#29000000</color>\
<color name="line">#29000000</color>
<color name="frame_line">#d4d4d4</color>
<color name="text">#525c69</color>
<color name="author">#4b9efd</color>
<color name="colorYellow">#ffb941</color>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@

<string name="login_error_message_empty_text">이메일 혹은 비밀번호를 채워주세요!</string>
<string name="error_message_unknown">알 수 없는 에러가 발생했습니다.</string>
<string name="title_notice">전체공지</string>
<string name="title_setting">설정</string>
</resources>
3 changes: 3 additions & 0 deletions model/src/main/java/com/mashup/model/Notice.kt
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ data class Notice(

fun Notice.mapToPresentation(userId: Int) = apply {
userAttendance = VoteStatus.NONE
voteAbsentCount = 0
voteAttendanceCount = 0
voteUnselectedCount = 0
attendanceSet.forEach { attendance ->
if (attendance.user.pk == userId) {
userAttendance = attendance.vote
Expand Down

0 comments on commit f7bb94c

Please sign in to comment.