-
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.
Related to: #886
- Loading branch information
Showing
36 changed files
with
662 additions
and
319 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 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
23 changes: 0 additions & 23 deletions
23
android/2023-emmsale/app/src/main/java/com/emmsale/data/apiModel/response/MyPostResponse.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
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
15 changes: 0 additions & 15 deletions
15
android/2023-emmsale/app/src/main/java/com/emmsale/data/mapper/MyPostMapper.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
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 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 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 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
13 changes: 0 additions & 13 deletions
13
android/2023-emmsale/app/src/main/java/com/emmsale/data/service/MyPostService.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
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
55 changes: 55 additions & 0 deletions
55
.../2023-emmsale/app/src/main/java/com/emmsale/presentation/ui/myFeedList/MyFeedsFragment.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,55 @@ | ||
package com.emmsale.presentation.ui.myFeedList | ||
|
||
import android.os.Bundle | ||
import android.view.View | ||
import androidx.fragment.app.viewModels | ||
import com.emmsale.R | ||
import com.emmsale.databinding.FragmentMyFeedsBinding | ||
import com.emmsale.presentation.base.NetworkFragment | ||
import com.emmsale.presentation.common.recyclerView.DividerItemDecoration | ||
import com.emmsale.presentation.ui.feedDetail.FeedDetailActivity | ||
import com.emmsale.presentation.ui.myFeedList.recyclerView.MyFeedAdapter | ||
import dagger.hilt.android.AndroidEntryPoint | ||
|
||
@AndroidEntryPoint | ||
class MyFeedsFragment : NetworkFragment<FragmentMyFeedsBinding>(R.layout.fragment_my_feeds) { | ||
|
||
override val viewModel: MyFeedsViewModel by viewModels() | ||
|
||
private val myFeedAdapter: MyFeedAdapter by lazy { | ||
MyFeedAdapter(onItemClick = ::navigateToDetail) | ||
} | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
setupDataBinding() | ||
setupRecyclerView() | ||
|
||
observeMyFeeds() | ||
} | ||
|
||
private fun setupDataBinding() { | ||
binding.vm = viewModel | ||
} | ||
|
||
private fun setupRecyclerView() { | ||
binding.rvMyFeeds.apply { | ||
adapter = myFeedAdapter | ||
itemAnimator = null | ||
addItemDecoration(DividerItemDecoration(context = context)) | ||
} | ||
} | ||
|
||
private fun observeMyFeeds() { | ||
viewModel.myFeeds.observe(viewLifecycleOwner) { myFeeds -> | ||
myFeedAdapter.submitList(myFeeds) | ||
} | ||
} | ||
|
||
private fun navigateToDetail(feedId: Long) { | ||
FeedDetailActivity.startActivity( | ||
requireContext(), | ||
feedId = feedId, | ||
) | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
...2023-emmsale/app/src/main/java/com/emmsale/presentation/ui/myFeedList/MyFeedsViewModel.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,37 @@ | ||
package com.emmsale.presentation.ui.myFeedList | ||
|
||
import androidx.lifecycle.LiveData | ||
import androidx.lifecycle.MutableLiveData | ||
import com.emmsale.data.model.Feed | ||
import com.emmsale.data.repository.interfaces.FeedRepository | ||
import com.emmsale.presentation.base.RefreshableViewModel | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import kotlinx.coroutines.Job | ||
import javax.inject.Inject | ||
|
||
@HiltViewModel | ||
class MyFeedsViewModel @Inject constructor( | ||
private val feedRepository: FeedRepository, | ||
) : RefreshableViewModel() { | ||
|
||
private val _myFeeds: MutableLiveData<List<Feed>> = MutableLiveData(emptyList()) | ||
val myFeeds: LiveData<List<Feed>> = _myFeeds | ||
|
||
init { | ||
fetchMyFeeds() | ||
} | ||
|
||
private fun fetchMyFeeds(): Job = fetchData( | ||
fetchData = { feedRepository.getMyFeeds() }, | ||
onSuccess = { | ||
_myFeeds.value = it.sortedByDescending { feed -> feed.createdAt } | ||
}, | ||
) | ||
|
||
override fun refresh(): Job = refreshData( | ||
refresh = { feedRepository.getMyFeeds() }, | ||
onSuccess = { | ||
_myFeeds.value = it.sortedByDescending { feed -> feed.createdAt } | ||
}, | ||
) | ||
} |
31 changes: 31 additions & 0 deletions
31
...le/app/src/main/java/com/emmsale/presentation/ui/myFeedList/recyclerView/MyFeedAdapter.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,31 @@ | ||
package com.emmsale.presentation.ui.myFeedList.recyclerView | ||
|
||
import android.view.ViewGroup | ||
import androidx.recyclerview.widget.DiffUtil | ||
import androidx.recyclerview.widget.ListAdapter | ||
import com.emmsale.data.model.Feed | ||
|
||
class MyFeedAdapter( | ||
private val onItemClick: (recruitmentId: Long) -> Unit, | ||
) : ListAdapter<Feed, MyFeedViewHolder>( | ||
object : DiffUtil.ItemCallback<Feed>() { | ||
override fun areItemsTheSame( | ||
oldItem: Feed, | ||
newItem: Feed, | ||
): Boolean = oldItem == newItem | ||
|
||
override fun areContentsTheSame( | ||
oldItem: Feed, | ||
newItem: Feed, | ||
): Boolean = oldItem.id == newItem.id | ||
}, | ||
) { | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyFeedViewHolder { | ||
return MyFeedViewHolder.create(parent, onItemClick) | ||
} | ||
|
||
override fun onBindViewHolder(holder: MyFeedViewHolder, position: Int) { | ||
holder.bind(getItem(position)) | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...app/src/main/java/com/emmsale/presentation/ui/myFeedList/recyclerView/MyFeedViewHolder.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,32 @@ | ||
package com.emmsale.presentation.ui.myFeedList.recyclerView | ||
|
||
import android.view.LayoutInflater | ||
import android.view.ViewGroup | ||
import androidx.recyclerview.widget.RecyclerView | ||
import com.emmsale.data.model.Feed | ||
import com.emmsale.databinding.ItemMyFeedBinding | ||
|
||
class MyFeedViewHolder( | ||
private val binding: ItemMyFeedBinding, | ||
navigateToDetail: (feedId: Long) -> Unit, | ||
) : RecyclerView.ViewHolder(binding.root) { | ||
|
||
init { | ||
itemView.setOnClickListener { navigateToDetail(binding.feed!!.id) } | ||
} | ||
|
||
fun bind(feed: Feed) { | ||
binding.feed = feed | ||
} | ||
|
||
companion object { | ||
fun create( | ||
parent: ViewGroup, | ||
onItemClick: (feedId: Long) -> Unit, | ||
): MyFeedViewHolder { | ||
val binding = | ||
ItemMyFeedBinding.inflate(LayoutInflater.from(parent.context), parent, false) | ||
return MyFeedViewHolder(binding, onItemClick) | ||
} | ||
} | ||
} |
Oops, something went wrong.