-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from depromeet/feature/impl-main-tab-set
바텀 네비게이션 탭 구현, color, dimen, theme 속성 파일 추가
- Loading branch information
Showing
26 changed files
with
433 additions
and
195 deletions.
There are no files selected for viewing
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,58 @@ | ||
/* | ||
* Copyright 2018 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package kr.tooni.tooni.base.arch | ||
|
||
import androidx.lifecycle.Observer | ||
|
||
/** | ||
* Used as a wrapper for data that is exposed via a LiveData that represents an event. | ||
*/ | ||
open class Event<out T>(private val content: T) { | ||
|
||
var hasBeenHandled = false | ||
private set // Allow external read but not write | ||
|
||
/** | ||
* Returns the content and prevents its use again. | ||
*/ | ||
fun getContentIfNotHandled(): T? { | ||
return if (hasBeenHandled) { | ||
null | ||
} else { | ||
hasBeenHandled = true | ||
content | ||
} | ||
} | ||
|
||
/** | ||
* Returns the content, even if it's already been handled. | ||
*/ | ||
fun peekContent(): T = content | ||
} | ||
|
||
/** | ||
* An [Observer] for [Event]s, simplifying the pattern of checking if the [Event]'s content has | ||
* already been handled. | ||
* | ||
* [onEventUnhandledContent] is *only* called if the [Event]'s contents has not been handled. | ||
*/ | ||
class EventObserver<T>(private val onEventUnhandledContent: (T) -> Unit) : Observer<Event<T>> { | ||
override fun onChanged(event: Event<T>?) { | ||
event?.getContentIfNotHandled()?.let { value -> | ||
onEventUnhandledContent(value) | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
19 changes: 0 additions & 19 deletions
19
app/src/main/kotlin/kr/tooni/tooni/data/response/CharactersResponse.kt
This file was deleted.
Oops, something went wrong.
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,16 @@ | ||
/* | ||
* Created by Leo on 2021. 05. 19 .. | ||
*/ | ||
package kr.tooni.tooni.extensions | ||
|
||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.lifecycle.LiveData | ||
import kr.tooni.tooni.base.arch.Event | ||
import kr.tooni.tooni.base.arch.EventObserver | ||
|
||
fun <T> AppCompatActivity.observeEvent( | ||
liveData: LiveData<Event<T>>, | ||
action: (T) -> Unit | ||
) { | ||
liveData.observe(this, EventObserver { action(it) }) | ||
} |
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,10 @@ | ||
/* | ||
* Created by Leo on 2021. 05. 19 .. | ||
*/ | ||
package kr.tooni.tooni.extensions | ||
|
||
import android.content.Context | ||
import androidx.annotation.DrawableRes | ||
import androidx.core.content.ContextCompat | ||
|
||
fun Context.getDrawableCompat(@DrawableRes resourceId: Int) = ContextCompat.getDrawable(this, resourceId) |
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,25 @@ | ||
/* | ||
* Created by Leo on 2021. 04. 17 .. | ||
*/ | ||
package kr.tooni.tooni.extensions | ||
|
||
import android.graphics.drawable.Drawable | ||
import androidx.annotation.ColorRes | ||
import androidx.annotation.DrawableRes | ||
import androidx.core.content.ContextCompat | ||
import androidx.fragment.app.Fragment | ||
import androidx.lifecycle.LiveData | ||
import kr.tooni.tooni.base.arch.Event | ||
import kr.tooni.tooni.base.arch.EventObserver | ||
|
||
fun Fragment.getDrawableCompat(@DrawableRes resourceId: Int): Drawable? { | ||
return requireContext().getDrawableCompat(resourceId) | ||
} | ||
fun Fragment.getColor(@ColorRes colorId: Int) = ContextCompat.getColor(requireContext(), colorId) | ||
|
||
inline fun <T> Fragment.observeEvent( | ||
liveData: LiveData<Event<T>>, | ||
crossinline action: (T) -> Unit | ||
) { | ||
liveData.observe(viewLifecycleOwner, EventObserver { action(it) }) | ||
} |
15 changes: 0 additions & 15 deletions
15
app/src/main/kotlin/kr/tooni/tooni/extensions/FragmentActivity.kt
This file was deleted.
Oops, something went wrong.
79 changes: 79 additions & 0 deletions
79
app/src/main/kotlin/kr/tooni/tooni/features/MainActivity.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,79 @@ | ||
package kr.tooni.tooni.features | ||
|
||
import android.os.Bundle | ||
import androidx.activity.viewModels | ||
import androidx.fragment.app.Fragment | ||
import androidx.fragment.app.FragmentTransaction | ||
import kr.tooni.tooni.R | ||
import kr.tooni.tooni.base.BaseActivity | ||
import kr.tooni.tooni.databinding.ActivityMainBinding | ||
import kr.tooni.tooni.features.day.DayWebtoonFragment | ||
|
||
class MainActivity : BaseActivity<ActivityMainBinding>(R.layout.activity_main) { | ||
|
||
private val viewModel by viewModels<MainViewModel>() | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
initView() | ||
setInitialTab() | ||
setBottomNavigationItemSelectedListener() | ||
} | ||
|
||
private fun initView() { | ||
binding.viewModel = viewModel | ||
binding.lifecycleOwner = this | ||
} | ||
|
||
private fun setInitialTab() { | ||
showPhotoFragment() | ||
} | ||
|
||
private fun setBottomNavigationItemSelectedListener() { | ||
binding.bottomNavigationView.setOnNavigationItemSelectedListener { menuItem -> | ||
when (menuItem.itemId) { | ||
R.id.home_1 -> showPhotoFragment() | ||
R.id.home_2 -> showPhotoFragment() | ||
R.id.home_3 -> showPhotoFragment() | ||
R.id.home_4 -> showPhotoFragment() | ||
else -> throw IllegalArgumentException("${menuItem.itemId} is invalid itemId") | ||
} | ||
|
||
return@setOnNavigationItemSelectedListener true | ||
} | ||
} | ||
|
||
private fun showPhotoFragment() { | ||
val tag = DayWebtoonFragment::class.java.name | ||
|
||
supportFragmentManager.findFragmentByTag(tag) | ||
?.let { fragment -> | ||
showFragment(fragment) | ||
} | ||
?: addFragment( | ||
fragment = DayWebtoonFragment.newInstance(), | ||
tag = tag | ||
) | ||
} | ||
|
||
private fun addFragment(fragment: Fragment, tag: String) = | ||
supportFragmentManager | ||
.beginTransaction() | ||
.hideFragments() | ||
.add(R.id.container, fragment, tag) | ||
.commitAllowingStateLoss() | ||
|
||
private fun showFragment(fragment: Fragment) = | ||
supportFragmentManager | ||
.beginTransaction() | ||
.hideFragments() | ||
.show(fragment) | ||
.commitAllowingStateLoss() | ||
|
||
private fun FragmentTransaction.hideFragments(): FragmentTransaction = | ||
this.apply { | ||
supportFragmentManager | ||
.fragments | ||
.forEach { fragment -> hide(fragment) } | ||
} | ||
} |
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 @@ | ||
/* | ||
* Created by Leo on 2021. 04. 17 .. | ||
*/ | ||
package kr.tooni.tooni.features | ||
|
||
import kr.tooni.tooni.base.BaseViewModel | ||
|
||
class MainViewModel : BaseViewModel() |
Oops, something went wrong.