Skip to content

Commit

Permalink
(#2) Add Login feature
Browse files Browse the repository at this point in the history
  • Loading branch information
myung6024 committed Nov 23, 2019
1 parent fe1b3cf commit 27a6e8e
Show file tree
Hide file tree
Showing 33 changed files with 570 additions and 210 deletions.
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<activity
android:name=".app.notices.NoticesActivity"
android:theme="@style/AppTheme.NoActionBar"/>
<activity android:name=".app.auth.LoginActivity" />
<activity android:name=".app.login.LoginActivity" />
<activity android:name=".app.attendees.AttendeesActivity" />
</application>

Expand Down
4 changes: 3 additions & 1 deletion app/src/main/java/com/mashup/MashupApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.app.Application
import com.facebook.stetho.Stetho
import com.jakewharton.threetenabp.AndroidThreeTen
import com.mashup.app.attendees.AttendeesModule
import com.mashup.app.login.LoginModule
import com.mashup.app.noticedetail.NoticeDetailModule
import com.mashup.app.notices.NoticeModule
import com.mashup.di.ApiModule
Expand Down Expand Up @@ -31,7 +32,8 @@ class MashupApplication : Application() {
NetworkModule,
NoticeModule,
NoticeDetailModule,
AttendeesModule
AttendeesModule,
LoginModule
))
}
initJSR310()
Expand Down
33 changes: 21 additions & 12 deletions app/src/main/java/com/mashup/SplashActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,41 @@ package com.mashup
import android.content.Intent
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.mashup.app.login.LoginActivity
import com.mashup.app.notices.NoticesActivity
import com.mashup.repository.NoticesRepository
import com.mashup.repository.notice.NoticesRepository
import com.mashup.repository.user.UserRepository
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.schedulers.Schedulers
import org.koin.android.ext.android.inject

class SplashActivity : AppCompatActivity() {
private val userRepository: UserRepository by inject()
private val noticesRepository: NoticesRepository by inject()
private val compositeDisposable = CompositeDisposable()

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_splash)

compositeDisposable.add(
noticesRepository
.getNoticeList(true)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe({
startActivity(Intent(this, NoticesActivity::class.java))
finish()
}, {
it.printStackTrace()
}))
if (userRepository.hasAuthToken()) {
compositeDisposable.add(
noticesRepository
.getNoticeList(true)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe({
startActivity(Intent(this, NoticesActivity::class.java))
finish()
}, {
it.printStackTrace()
})
)
} else {
startActivity(Intent(this, LoginActivity::class.java))
finish()
}
}

override fun onDestroy() {
Expand Down
15 changes: 4 additions & 11 deletions app/src/main/java/com/mashup/api/notice/NoticeService.kt
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
package com.mashup.api.notice

import com.mashup.model.Notice
import com.mashup.model.VoteStatus
import com.mashup.api.notice.request.AttendanceUpdateRequest
import com.mashup.repository.notice.remote.response.NoticeListResponse
import io.reactivex.Completable
import io.reactivex.Flowable
import retrofit2.http.*

interface NoticeService {

@GET("api/v1/notice/list?size=10")
fun getNotice(@Query("type") type: String, @Query("page") page: Int): Flowable<List<Notice>>


@GET("api/v1/notice/active/list?type=public&size=10")
fun getRecentPublicNotice(): Flowable<List<Notice>>

@GET("api/notices/")
fun getNoticeList(): Flowable<List<Notice>>
fun getNoticeList(): Flowable<NoticeListResponse>

@PATCH("api/notices/attendances/{id}/")
fun updateNoticeAttendance(@Path("id") userId: Int, @Body voteStatus: VoteStatus): Completable
fun updateNoticeAttendance(@Header("Authorization") token: String, @Path("id") noticeId: Int, @Body attendanceUpdateRequest: AttendanceUpdateRequest): Completable

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.mashup.api.notice.request

import com.google.gson.annotations.SerializedName
import com.mashup.model.VoteStatus

data class AttendanceUpdateRequest(
@SerializedName("vote") val voteStatus: VoteStatus
)
13 changes: 4 additions & 9 deletions app/src/main/java/com/mashup/api/user/UserService.kt
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
package com.mashup.api.user

import com.mashup.api.user.request.UserLoginRequest
import com.mashup.api.user.request.UserRegisterRequest
import com.mashup.model.User
import com.mashup.api.user.request.AuthTokenRequest
import com.mashup.model.AuthToken
import io.reactivex.Flowable
import retrofit2.http.Body
import retrofit2.http.POST

interface UserService {

@POST("api/v1/register/member")
fun register(@Body request: UserRegisterRequest): Flowable<User>


@POST("api/v1/login")
fun login(@Body request: UserLoginRequest): Flowable<User>
@POST("api/members/auth-token/")
fun getAuthToken(@Body request: AuthTokenRequest): Flowable<AuthToken>

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.mashup.api.user.request

import com.google.gson.annotations.SerializedName

data class AuthTokenRequest(
@SerializedName("username") val name: String,
@SerializedName("email") val email: String,
@SerializedName("password") val password: String
)

This file was deleted.

This file was deleted.

62 changes: 0 additions & 62 deletions app/src/main/java/com/mashup/app/auth/LoginActivity.kt

This file was deleted.

39 changes: 0 additions & 39 deletions app/src/main/java/com/mashup/app/auth/LoginViewModel.kt

This file was deleted.

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

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.mashup.R

class LoginActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.login_activity)
if (savedInstanceState == null) {
supportFragmentManager.beginTransaction()
.replace(R.id.container, LoginFragment.newInstance())
.commitNow()
}
}
}
56 changes: 56 additions & 0 deletions app/src/main/java/com/mashup/app/login/LoginFragment.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.mashup.app.login

import android.content.Intent
import android.os.Bundle
import android.view.LayoutInflater
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.databinding.LoginFragmentBinding
import com.mashup.util.EventObserver
import com.mashup.util.setupSnackbar
import org.koin.androidx.viewmodel.ext.android.viewModel

class LoginFragment : Fragment() {

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

private val viewModel: LoginViewModel by viewModel()
private lateinit var viewDataBinding: LoginFragmentBinding


override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View {
viewDataBinding = LoginFragmentBinding.inflate(inflater, container, false).apply {
viewmodel = viewModel
}
return viewDataBinding.root
}

override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
viewDataBinding.setLifecycleOwner(this.viewLifecycleOwner)
setupSnackbar()
setupEventObserver()
}

private fun setupSnackbar() {
view?.setupSnackbar(this, viewModel.snackbarText, Snackbar.LENGTH_SHORT)
}

private fun setupEventObserver() {
viewModel.isLoginSuccess.observe(this, EventObserver {
if (it) {
activity?.finishAffinity()
val intent = Intent(this.context, NoticesActivity::class.java)
startActivity(intent)
}
})
}
}
8 changes: 8 additions & 0 deletions app/src/main/java/com/mashup/app/login/LoginModule.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.mashup.app.login

import org.koin.androidx.viewmodel.dsl.viewModel
import org.koin.dsl.module

val LoginModule = module {
viewModel { LoginViewModel(get()) }
}
Loading

0 comments on commit 27a6e8e

Please sign in to comment.