-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…hood-life PR : 동네생활 & 프로필 & 네트워크
- Loading branch information
Showing
48 changed files
with
1,303 additions
and
28 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
6 changes: 6 additions & 0 deletions
6
app/src/main/java/org/sopt/carrot/core/ui/utils/Extensions.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,6 @@ | ||
package org.sopt.carrot.core.ui.utils | ||
|
||
import android.content.res.Resources | ||
|
||
|
||
fun Int.fromDpToPx(): Int = (this * Resources.getSystem().displayMetrics.density).toInt() |
15 changes: 15 additions & 0 deletions
15
app/src/main/java/org/sopt/carrot/data/api/CarrotService.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,15 @@ | ||
package org.sopt.carrot.data.api | ||
|
||
import org.sopt.carrot.data.model.neighborhoodlife.LivesResponse | ||
import retrofit2.http.GET | ||
import retrofit2.http.Query | ||
|
||
interface CarrotService { | ||
@GET("api/lives") | ||
fun getLives( | ||
@Query("category") category: String | ||
): LivesResponse | ||
|
||
@GET("api/lives") | ||
suspend fun getLives(): LivesResponse | ||
} |
33 changes: 33 additions & 0 deletions
33
app/src/main/java/org/sopt/carrot/data/api/RetrofitManager.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,33 @@ | ||
package org.sopt.carrot.data.api | ||
|
||
import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory | ||
import kotlinx.serialization.json.Json | ||
import okhttp3.MediaType.Companion.toMediaType | ||
import okhttp3.OkHttpClient | ||
import okhttp3.logging.HttpLoggingInterceptor | ||
import org.sopt.carrot.BuildConfig | ||
import retrofit2.Retrofit | ||
|
||
object RetrofitManager { | ||
private const val BASE_URL = BuildConfig.BASE_URL | ||
|
||
private val httpLoggingInterceptor = HttpLoggingInterceptor() | ||
.setLevel(HttpLoggingInterceptor.Level.BODY) | ||
|
||
private val okHttpClient = OkHttpClient.Builder() | ||
.addInterceptor(httpLoggingInterceptor) | ||
.build() | ||
|
||
val retrofit: Retrofit = | ||
Retrofit.Builder() | ||
.baseUrl(BASE_URL) | ||
.client(okHttpClient) | ||
.addConverterFactory(Json.asConverterFactory("application/json".toMediaType())) | ||
.build() | ||
|
||
inline fun <reified T> create(): T = retrofit.create<T>(T::class.java) | ||
} | ||
|
||
object RetrofitServicePool { | ||
val carrotService = RetrofitManager.create<CarrotService>() | ||
} |
19 changes: 19 additions & 0 deletions
19
app/src/main/java/org/sopt/carrot/data/datasource/remote/NeighborhoodLifeRemoteDatasource.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,19 @@ | ||
package org.sopt.carrot.data.datasource.remote | ||
|
||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.async | ||
import kotlinx.coroutines.withContext | ||
import org.sopt.carrot.data.api.CarrotService | ||
import org.sopt.carrot.data.model.neighborhoodlife.LivesDataResponse | ||
|
||
class NeighborhoodLifeRemoteDatasource( | ||
private val carrotService: CarrotService | ||
) { | ||
suspend fun getLives(): List<LivesDataResponse> { | ||
return withContext(Dispatchers.IO) { | ||
async { | ||
carrotService.getLives().data | ||
}.await() | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
app/src/main/java/org/sopt/carrot/data/model/neighborhoodlife/LivesDataResponse.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,22 @@ | ||
package org.sopt.carrot.data.model.neighborhoodlife | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class LivesDataResponse( | ||
@SerialName("lifeId") | ||
val lifeId: Int, | ||
@SerialName("lifeCategoryContent") | ||
val lifeCategoryContent: String, | ||
@SerialName("lifeTitle") | ||
val lifeTitle: String, | ||
@SerialName("lifeContent") | ||
val lifeContent: String, | ||
@SerialName("contentInformation") | ||
val contentInformation: String, | ||
@SerialName("likeCount") | ||
val likeCount: Int, | ||
@SerialName("commentCount") | ||
val commentCount: Int, | ||
) |
15 changes: 15 additions & 0 deletions
15
app/src/main/java/org/sopt/carrot/data/model/neighborhoodlife/LivesResponse.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,15 @@ | ||
package org.sopt.carrot.data.model.neighborhoodlife | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class LivesResponse( | ||
@SerialName("code") | ||
val code: Int, | ||
@SerialName("message") | ||
val message: String, | ||
@SerialName("data") | ||
val data: List<LivesDataResponse> | ||
) | ||
|
15 changes: 15 additions & 0 deletions
15
app/src/main/java/org/sopt/carrot/data/repo/NeighborhoodLifeRepository.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,15 @@ | ||
package org.sopt.carrot.data.repo | ||
|
||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.withContext | ||
import org.sopt.carrot.data.datasource.remote.NeighborhoodLifeRemoteDatasource | ||
import org.sopt.carrot.data.model.neighborhoodlife.LivesDataResponse | ||
|
||
class NeighborhoodLifeRepository( | ||
private val neighborhoodLifeRemoteDatasource: NeighborhoodLifeRemoteDatasource | ||
) { | ||
suspend fun getLives(): List<LivesDataResponse> = | ||
withContext(Dispatchers.IO) { | ||
neighborhoodLifeRemoteDatasource.getLives() | ||
} | ||
} |
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
14 changes: 14 additions & 0 deletions
14
...n/java/org/sopt/carrot/presentation/neighborhoodlife/NeighborhoodLifeViewModelProvider.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,14 @@ | ||
package org.sopt.carrot.presentation.neighborhoodlife | ||
|
||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.ViewModelProvider | ||
import org.sopt.carrot.data.repo.NeighborhoodLifeRepository | ||
|
||
class NeighborhoodLifeViewModelProvider( | ||
private val neighborhoodLifeRepository: NeighborhoodLifeRepository | ||
) : ViewModelProvider.Factory { | ||
override fun <T : ViewModel> create(modelClass: Class<T>): T { | ||
return modelClass.getConstructor(NeighborhoodLifeRepository::class.java) | ||
.newInstance(neighborhoodLifeRepository) | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
app/src/main/java/org/sopt/carrot/presentation/neighborhoodlife/NeighborhoodViewModel.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,28 @@ | ||
package org.sopt.carrot.presentation.neighborhoodlife | ||
|
||
import androidx.lifecycle.LiveData | ||
import androidx.lifecycle.MutableLiveData | ||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import kotlinx.coroutines.launch | ||
import org.sopt.carrot.data.model.neighborhoodlife.LivesDataResponse | ||
import org.sopt.carrot.data.repo.NeighborhoodLifeRepository | ||
|
||
class NeighborhoodViewModel( | ||
private val neighborhoodLifeRepository: NeighborhoodLifeRepository | ||
): ViewModel() { | ||
private val _livesList = MutableLiveData<List<LivesDataResponse>>() | ||
val livesList: LiveData<List<LivesDataResponse>> get() = _livesList | ||
|
||
fun getLives() { | ||
viewModelScope.launch { | ||
kotlin.runCatching { | ||
neighborhoodLifeRepository.getLives() | ||
}.onSuccess { | ||
_livesList.value = it | ||
}.onFailure { | ||
_livesList.value = emptyList() | ||
} | ||
} | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...src/main/java/org/sopt/carrot/presentation/neighborhoodlife/adapter/CarouselTagAdapter.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,40 @@ | ||
package org.sopt.carrot.presentation.neighborhoodlife.adapter | ||
|
||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.recyclerview.widget.ListAdapter | ||
import androidx.recyclerview.widget.RecyclerView | ||
import org.sopt.carrot.core.ui.view.ItemDiffCallback | ||
import org.sopt.carrot.databinding.ItemTopicBinding | ||
import org.sopt.carrot.presentation.neighborhoodlife.dummy.carouselTagList | ||
|
||
class CarouselTagAdapter : ListAdapter<String, CarouselTagViewHolder>( | ||
ItemDiffCallback<String>( | ||
onItemsTheSame = { old, new -> old == new }, | ||
onContentsTheSame = { old, new -> old === new } | ||
) | ||
) { | ||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CarouselTagViewHolder { | ||
return CarouselTagViewHolder( | ||
ItemTopicBinding.inflate( | ||
LayoutInflater.from(parent.context), | ||
parent, | ||
false | ||
) | ||
) | ||
} | ||
|
||
override fun onBindViewHolder(holder: CarouselTagViewHolder, position: Int) { | ||
holder.bind(currentList[position]) | ||
} | ||
} | ||
|
||
class CarouselTagViewHolder( | ||
private val binding: ItemTopicBinding | ||
) : RecyclerView.ViewHolder(binding.root) { | ||
fun bind(item: String) { | ||
if (item == carouselTagList[0]) binding.ivTopic.visibility = View.VISIBLE | ||
binding.tvTopicTitle.text = item | ||
} | ||
} |
Oops, something went wrong.