Skip to content

Commit

Permalink
(#2) add setting feature
Browse files Browse the repository at this point in the history
  • Loading branch information
myung jun Hyun authored and myung6024 committed Nov 26, 2019
1 parent 709381c commit bf5b9b3
Show file tree
Hide file tree
Showing 28 changed files with 244 additions and 47 deletions.
2 changes: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ android {
buildTypes {
debug {
buildConfigField "String", "BASE_URL", "\"https://mashup.lhy.kr/\""
buildConfigField "String", "FEED_BACK_EMAIL", "\"[email protected]\""
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
buildConfigField "String", "BASE_URL", "\"\""
buildConfigField "String", "FEED_BACK_EMAIL", "\"[email protected]\""
}
}
dataBinding {
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 @@ -7,6 +7,7 @@ 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.app.setting.SettingModule
import com.mashup.di.ApiModule
import com.mashup.di.ApplicationModule
import com.mashup.di.NetworkModule
Expand All @@ -33,7 +34,8 @@ class MashupApplication : Application() {
NoticeModule,
NoticeDetailModule,
AttendeesModule,
LoginModule
LoginModule,
SettingModule
))
}
initJSR310()
Expand Down
9 changes: 5 additions & 4 deletions app/src/main/java/com/mashup/app/notices/NoticesFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class NoticesFragment : Fragment() {
val viewModel = viewDataBinding.viewmodel
if (viewModel != null) {
listAdapter = NoticeAdapter(viewModel)
viewDataBinding.tasksList.itemAnimator = null
viewDataBinding.tasksList.adapter = listAdapter
}
}
Expand All @@ -59,25 +60,25 @@ class NoticesFragment : Fragment() {
}

private fun setupEventObserver() {
viewModel.itemChangedEvent.observe(this, EventObserver { position ->
viewModel.itemChangedEvent.observe(viewLifecycleOwner, EventObserver { position ->
listAdapter.notifyItemChanged(position)
})

viewModel.showDetailEvent.observe(this, EventObserver { notice ->
viewModel.showDetailEvent.observe(viewLifecycleOwner, EventObserver { notice ->
val intent = Intent(this@NoticesFragment.context, NoticeDetailActivity::class.java).apply {
putExtra(NoticeDetailFragment.EXTRA_NOTICE, notice)
}
startActivityForResult(intent, NoticeDetailFragment.REQUEST_NOTICE_ACTION)
})

viewModel.onException.observe(this, EventObserver { exception ->
viewModel.onException.observe(viewLifecycleOwner, EventObserver { exception ->
if (exception) {
activity?.finishAffinity()
}
startActivity(Intent(this@NoticesFragment.context, LoginActivity::class.java))
})

viewModel.showAttendeesEvent.observe(this, EventObserver { attendees ->
viewModel.showAttendeesEvent.observe(viewLifecycleOwner, EventObserver { attendees ->
val intent = Intent(this@NoticesFragment.context, AttendeesActivity::class.java).apply {
putParcelableArrayListExtra(
AttendeesFragment.EXTRA_ATTENDANCE_LIST,
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/java/com/mashup/app/setting/SettingBindings.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.mashup.app.setting

import android.graphics.Paint
import android.widget.TextView
import androidx.databinding.BindingAdapter
import com.mashup.BuildConfig

@BindingAdapter("app:email")
fun TextView.setEmailText(string: String) {
text = string
paintFlags = Paint.UNDERLINE_TEXT_FLAG
}
58 changes: 47 additions & 11 deletions app/src/main/java/com/mashup/app/setting/SettingFragment.kt
Original file line number Diff line number Diff line change
@@ -1,32 +1,68 @@
package com.mashup.app.setting

import androidx.lifecycle.ViewModelProviders
import android.content.Intent
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.mashup.app.login.LoginFragment
import com.mashup.databinding.SettingFragmentBinding
import com.mashup.util.EventObserver
import org.koin.androidx.viewmodel.ext.android.viewModel
import com.mashup.BuildConfig
import com.mashup.R
import com.mashup.app.login.LoginActivity


class SettingFragment : Fragment() {

companion object {
fun newInstance() = SettingFragment()
}
private val viewModel: SettingViewModel by viewModel()
private lateinit var viewDataBinding: SettingFragmentBinding

private lateinit var viewModel: SettingViewModel

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

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

private fun setupEventObserver() {
viewModel.logoutEvent.observe(viewLifecycleOwner, EventObserver {
if (it) {
activity?.finishAffinity()
val intent = Intent(this.context, LoginActivity::class.java)
startActivity(intent)
}
})

viewModel.sendEmailEvent.observe(viewLifecycleOwner, EventObserver {
if (it) {
val intent = Intent(Intent.ACTION_SEND).apply {
val addressees: Array<String> = arrayOf(BuildConfig.FEED_BACK_EMAIL)
putExtra(Intent.EXTRA_EMAIL, addressees)
putExtra(
Intent.EXTRA_SUBJECT,
"<" + getString(R.string.app_name) + " " + getString(R.string.setting_send_feedback_email_title) + ">"
)
putExtra(
Intent.EXTRA_TEXT,
"앱 버전 (AppVersion):${BuildConfig.VERSION_NAME}\n기기명 (Device):\n안드로이드 OS (Android OS):\n내용 (Content):\n"
)
type = "message/rfc822"
}
startActivity(intent)
}
})
}
}
8 changes: 8 additions & 0 deletions app/src/main/java/com/mashup/app/setting/SettingModule.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.mashup.app.setting

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

val SettingModule = module {
viewModel { SettingViewModel(get()) }
}
23 changes: 21 additions & 2 deletions app/src/main/java/com/mashup/app/setting/SettingViewModel.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,26 @@
package com.mashup.app.setting

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.mashup.repository.user.UserRepository
import com.mashup.util.Event

class SettingViewModel : ViewModel() {
// TODO: Implement the ViewModel
class SettingViewModel(
private val userRepository: UserRepository
) : ViewModel() {
private val _logoutEvent = MutableLiveData<Event<Boolean>>()
val logoutEvent: LiveData<Event<Boolean>> = _logoutEvent

private val _sendEmailEvent = MutableLiveData<Event<Boolean>>()
val sendEmailEvent: LiveData<Event<Boolean>> = _sendEmailEvent

fun sendFeedBackEmail() {
_sendEmailEvent.value = Event(true)
}

fun onClickLogoutButton() {
userRepository.logout()
_logoutEvent.value = Event(true)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,9 @@ class DefaultUserRepository(
private val PREF_KEY_AUTH_TOKEN = "authToken"
private val prefs: SharedPreferences = context.getSharedPreferences(PREFS_FILENAME, 0)

private lateinit var cachedAuthToken: AuthToken
private var cachedAuthToken: AuthToken? = null

override fun getCachedAuthToken(): AuthToken? {
return if (::cachedAuthToken.isInitialized) {
cachedAuthToken
} else {
null
}
}
override fun getCachedAuthToken(): AuthToken? = cachedAuthToken

override fun hasAuthToken(): Boolean {
val jsonString = prefs.getString(PREF_KEY_AUTH_TOKEN, "")
Expand All @@ -51,7 +45,7 @@ class DefaultUserRepository(
}

override fun getAuthToken(request: AuthTokenRequest): Flowable<AuthToken> {
if (::cachedAuthToken.isInitialized) {
if (cachedAuthToken != null) {
return Flowable.just(cachedAuthToken)
} else {
val jsonString = prefs.getString(PREF_KEY_AUTH_TOKEN, "")
Expand All @@ -71,4 +65,9 @@ class DefaultUserRepository(
saveAuthToken(it)
}
}

override fun logout() {
cachedAuthToken = null
prefs.edit().clear().apply()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ interface UserRepository {
fun getCachedAuthToken(): AuthToken?

fun getAuthToken(request: AuthTokenRequest): Flowable<AuthToken>

fun logout()
}
Binary file added app/src/main/res/drawable-hdpi/icon_log_out.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-hdpi/icon_meeting.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-hdpi/icon_setting.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-mdpi/icon_log_out.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-mdpi/icon_meeting.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-mdpi/icon_setting.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xhdpi/icon_log_out.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xhdpi/icon_meeting.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xhdpi/icon_setting.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xxhdpi/icon_log_out.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xxhdpi/icon_meeting.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xxhdpi/icon_setting.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion app/src/main/res/layout/notice_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
android:layout_marginStart="30dp"
android:layout_marginEnd="30dp"
android:layout_marginBottom="50dp"
android:onClick="@{() -> viewmodel.onClickItem(notice)}">
android:onClick="@{() -> viewmodel.onClickItem(notice)}"
app:cardElevation="8dp"
app:cardCornerRadius="8dp">

<LinearLayout
android:layout_width="match_parent"
Expand Down
Loading

0 comments on commit bf5b9b3

Please sign in to comment.