Skip to content

Commit

Permalink
:refactor: revise layout color
Browse files Browse the repository at this point in the history
  • Loading branch information
kmkim2689 committed Oct 24, 2024
1 parent 5b9887a commit c7c80aa
Show file tree
Hide file tree
Showing 14 changed files with 98 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class HomeFragment : Fragment() {

private fun observeFeedData() {
viewModel.feedData.observe(viewLifecycleOwner) { pagingData ->
lifecycleScope.launch {
viewLifecycleOwner.lifecycleScope.launch {
withContext(Dispatchers.Main) {
adapter.submitData(pagingData)
}
Expand Down Expand Up @@ -95,7 +95,7 @@ class HomeFragment : Fragment() {
binding.viewModel = viewModel
binding.homeRcView.adapter = adapter

lifecycleScope.launch {
viewLifecycleOwner.lifecycleScope.launch {
adapter.loadStateFlow.collect { loadStates ->
binding.swipeRefreshLayout.isRefreshing = loadStates.refresh is LoadState.Loading
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import androidx.lifecycle.lifecycleScope
import androidx.navigation.fragment.findNavController
import androidx.paging.LoadState
import androidx.recyclerview.widget.GridLayoutManager
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.Dispatchers
Expand Down Expand Up @@ -55,6 +56,7 @@ class ProfileFragment : Fragment() {
binding.layoutManager = layoutManager
viewModel.items.observe(viewLifecycleOwner) { pagingData ->
viewLifecycleOwner.lifecycleScope.launch(Dispatchers.Main) {
binding.swipeRefreshLayout.isRefreshing = false
adapter.submitData(pagingData)
}
}
Expand All @@ -79,10 +81,28 @@ class ProfileFragment : Fragment() {
}
}
}
initSwipeRefreshLayout()
}

override fun onDestroyView() {
super.onDestroyView()
_binding = null
}

private fun initSwipeRefreshLayout() {
viewLifecycleOwner.lifecycleScope.launch {
adapter.loadStateFlow.collect { loadState ->
binding.swipeRefreshLayout.isRefreshing = loadState.refresh is LoadState.Loading
}
}

binding.swipeRefreshLayout.setOnRefreshListener {
refreshData()
}
}

private fun refreshData() {
viewModel.loadData()
binding.swipeRefreshLayout.isRefreshing = false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import androidx.paging.Pager
import androidx.paging.PagingConfig
import androidx.paging.PagingData
import androidx.paging.cachedIn
import androidx.paging.liveData
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import net.pengcook.android.presentation.core.model.RecipeForList
import net.pengcook.android.presentation.core.util.Event
import javax.inject.Inject
Expand All @@ -24,11 +24,36 @@ class ProfileViewModel
val uiEvent: LiveData<Event<ProfileUiEvent>>
get() = _uiEvent

val items: LiveData<PagingData<ProfileViewItem>> =
Pager(
config = PagingConfig(pageSize = 30, initialLoadSize = 30),
pagingSourceFactory = { profilePagingSource },
).liveData.cachedIn(viewModelScope)
private val _items: MutableLiveData<PagingData<ProfileViewItem>> = MutableLiveData()
val items: LiveData<PagingData<ProfileViewItem>>
get() = _items

init {
loadData()
}

fun loadData() {
println("loadData")
val pager =
Pager(
config = PagingConfig(pageSize = 30, initialLoadSize = 30),
pagingSourceFactory = {
profilePagingSourceFactory.create(
initialPageNumber = 0,
profileFeedType = ProfileFeedType.MyFeed,
)
},
)

viewModelScope.launch {
pager.flow
.cachedIn(viewModelScope)
.collect { pagingData ->
println("collected")
_items.value = pagingData
}
}
}

override fun onLeftButtonClick() {
_uiEvent.value = Event(ProfileUiEvent.NavigateToEditProfile)
Expand All @@ -42,12 +67,12 @@ class ProfileViewModel
_uiEvent.value = Event(ProfileUiEvent.NavigateToRecipeDetail(recipe))
}

private val profilePagingSource: ProfilePagingSource by lazy {
profilePagingSourceFactory.create(
initialPageNumber = 0,
profileFeedType = ProfileFeedType.MyFeed,
)
}
// private val profilePagingSource: ProfilePagingSource by lazy {
// profilePagingSourceFactory.create(
// initialPageNumber = 0,
// profileFeedType = ProfileFeedType.MyFeed,
// )
// }
}

sealed interface ProfileUiEvent {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{comment.userName}"
android:textColor="@color/yellow_strong"
android:textColor="@color/text_color"
android:textSize="16sp"
android:textStyle="bold"
android:layout_marginStart="4dp"
app:layout_constraintStart_toEndOf="@id/tv_username_title"
app:layout_constraintTop_toTopOf="@id/tv_username_title"
app:visibility="@{!comment.mine}"
Expand All @@ -73,9 +74,10 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@{comment.message}"
android:textColor="@color/yellow_strong"
android:textColor="@color/text_color"
android:textSize="16sp"
android:textStyle="bold"
android:layout_marginStart="4dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/tv_comment_title"
app:layout_constraintTop_toTopOf="@id/tv_comment_title"
Expand Down Expand Up @@ -148,7 +150,7 @@
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:text="@string/report_title_bottom"
android:textColor="@color/yellow_strong"
android:textColor="@color/text_color"
android:textSize="16sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
Expand Down
24 changes: 18 additions & 6 deletions android/app/src/main/res/layout/fragment_profile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,27 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"/>

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_profile"
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/swipe_refresh_layout"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintTop_toBottomOf="@id/abl_profile"
app:layout_constraintBottom_toBottomOf="parent"
android:adapter="@{adapter}"
app:layoutManager="@{layoutManager}"
android:paddingHorizontal="12dp"/>
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/abl_profile"
app:layout_constraintVertical_bias="1.0">

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_profile"
android:layout_width="match_parent"
android:layout_height="0dp"
android:adapter="@{adapter}"
android:paddingHorizontal="12dp"
app:layoutManager="@{layoutManager}" />

</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>


</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
3 changes: 2 additions & 1 deletion android/app/src/main/res/layout/item_feed.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="wrap_content"
android:background="@color/home_item_background">

<!-- Recipe image -->
<ImageView
Expand Down
4 changes: 2 additions & 2 deletions android/app/src/main/res/layout/item_report_reason.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@
tools:text="Report Reason"
android:paddingVertical="16dp"
android:text="@{reason.message}"
android:textColor="@color/white"
android:textColor="@color/text_color"
android:textStyle="bold"
android:gravity="center"
android:textSize="14sp"
android:background="@color/yellow_medium" />
android:background="@color/button_color" />

<com.google.android.material.divider.MaterialDivider
android:layout_width="0dp"
Expand Down
2 changes: 1 addition & 1 deletion android/app/src/main/res/layout/item_step_recipe.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
android:id="@+id/iv_thumbnail_recipe"
android:layout_width="0dp"
android:layout_height="0dp"
android:scaleType="fitXY"
android:scaleType="centerCrop"
app:imageUrl="@{recipeStep.image}"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
Expand Down
2 changes: 1 addition & 1 deletion android/app/src/main/res/layout/item_textfield_medium.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="none"
android:lines="4"
android:minLines="4"
android:background="@drawable/bg_radius_outlined"
android:hint="@{hintContent}"
android:importantForAutofill="no"
Expand Down
2 changes: 1 addition & 1 deletion android/app/src/main/res/menu/menu_detail_mine.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/action_delete"
android:title="Delete" />
android:title="@string/menu_delete" />
</menu>
4 changes: 2 additions & 2 deletions android/app/src/main/res/menu/menu_detail_other.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/action_report"
android:title="Report" />
android:title="@string/menu_report" />
<item
android:id="@+id/action_block"
android:title="Block" />
android:title="@string/menu_block" />
</menu>
3 changes: 3 additions & 0 deletions android/app/src/main/res/values-ko-rKR/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -150,5 +150,8 @@
<string name="alert_message_fill_form">์™„๋ฃŒ๋˜์ง€ ์•Š์€ ํผ์ด ์žˆ์Šต๋‹ˆ๋‹ค.</string>
<string name="comments">Comments</string>
<string name="comment_delete">์‚ญ์ œํ•˜๊ธฐ</string>
<string name="menu_delete">์‚ญ์ œํ•˜๊ธฐ</string>
<string name="menu_report">์‹ ๊ณ ํ•˜๊ธฐ</string>
<string name="menu_block">์ฐจ๋‹จํ•˜๊ธฐ</string>

</resources>
2 changes: 1 addition & 1 deletion android/app/src/main/res/values-night/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<style name="Theme.Pengcook" parent="Base.Theme.Pengcook">
<item name="android:windowBackground">@color/screen_background</item>
<item name="android:windowLightStatusBar">true</item>
<item name="android:windowLightStatusBar">false</item>
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:navigationBarColor">@android:color/transparent</item>
<item name="android:enforceNavigationBarContrast" tools:targetApi="q">false</item>
Expand Down
3 changes: 3 additions & 0 deletions android/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -150,5 +150,8 @@
<string name="category_japanese">Japanese</string>
<string name="category_chinese">Chinese</string>
<string name="comment_delete">Delete my comment</string>
<string name="menu_delete">Delete</string>
<string name="menu_report">Report</string>
<string name="menu_block">Block</string>

</resources>

0 comments on commit c7c80aa

Please sign in to comment.