-
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.
- Loading branch information
Showing
5 changed files
with
188 additions
and
0 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
13 changes: 13 additions & 0 deletions
13
app/src/main/java/com/project/jangburich/api/response/home/GetWalletDataResponse.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,13 @@ | ||
package com.project.jangburich.api.response.home | ||
|
||
data class GetWalletDataResponse( | ||
val point: Int, | ||
val purchaseHistories: List<PurchaseHistory> | ||
) | ||
|
||
data class PurchaseHistory( | ||
val date: String, | ||
val amount: Int, | ||
val transactionTitle: String, | ||
val transactionType: String | ||
) |
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
62 changes: 62 additions & 0 deletions
62
app/src/main/java/com/project/jangburich/ui/home/adapter/WalletAdapter.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,62 @@ | ||
package com.project.jangburich.ui.home.adapter | ||
|
||
import android.content.Context | ||
import android.view.LayoutInflater | ||
import android.view.ViewGroup | ||
import androidx.recyclerview.widget.RecyclerView | ||
import com.bumptech.glide.Glide | ||
import com.project.jangburich.api.response.home.PurchaseHistory | ||
import com.project.jangburich.databinding.RowWalletPaymentBinding | ||
import com.project.jangburich.ui.MainActivity | ||
|
||
class WalletAdapter( | ||
private var activity: MainActivity, | ||
private var purchaseHistories: List<PurchaseHistory> | ||
) : | ||
RecyclerView.Adapter<WalletAdapter.ViewHolder>() { | ||
|
||
private var onItemClickListener: ((Int) -> Unit)? = null | ||
private var context: Context? = null | ||
private var selectedPosition: Int = 0 | ||
|
||
fun setOnItemClickListener(listener: (Int) -> Unit) { | ||
onItemClickListener = listener | ||
} | ||
|
||
fun updateList(newPurchaseHistories: List<PurchaseHistory>) { | ||
purchaseHistories = newPurchaseHistories | ||
notifyDataSetChanged() | ||
} | ||
|
||
|
||
interface OnItemClickListener { | ||
fun onItemClick(position: Int) {} | ||
} | ||
|
||
var itemClickListener: OnItemClickListener? = null | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { | ||
context = parent.context | ||
val binding = | ||
RowWalletPaymentBinding.inflate(LayoutInflater.from(parent.context), parent, false) | ||
|
||
return ViewHolder(binding) | ||
} | ||
|
||
override fun onBindViewHolder(holder: ViewHolder, position: Int) { | ||
holder.title.text = purchaseHistories[position].transactionTitle | ||
holder.description.text = purchaseHistories[position].transactionType | ||
holder.paymentValue.text = purchaseHistories[position].amount.toString() | ||
holder.date.text = purchaseHistories[position].date | ||
} | ||
|
||
override fun getItemCount() = purchaseHistories.size | ||
|
||
inner class ViewHolder(val binding: RowWalletPaymentBinding) : | ||
RecyclerView.ViewHolder(binding.root) { | ||
val title = binding.textViewTitle | ||
val description = binding.textViewDescription | ||
val date = binding.textViewDate | ||
val paymentValue = binding.textViewPaymentValue | ||
} | ||
} |
84 changes: 84 additions & 0 deletions
84
app/src/main/java/com/project/jangburich/ui/home/viewModel/WalletViewModel.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,84 @@ | ||
package com.project.jangburich.ui.home.viewModel | ||
|
||
import android.content.Intent | ||
import android.net.Uri | ||
import android.util.Log | ||
import androidx.lifecycle.MutableLiveData | ||
import androidx.lifecycle.ViewModel | ||
import com.project.jangburich.api.ApiClient | ||
import com.project.jangburich.api.TokenManager | ||
import com.project.jangburich.api.request.home.ReadyKakaoPayRequest | ||
import com.project.jangburich.api.response.BaseResponse | ||
import com.project.jangburich.api.response.home.GetWalletDataResponse | ||
import com.project.jangburich.api.response.home.PurchaseHistory | ||
import com.project.jangburich.api.response.home.ReadyKakaoPayResponse | ||
import com.project.jangburich.ui.MainActivity | ||
import retrofit2.Call | ||
import retrofit2.Callback | ||
import retrofit2.Response | ||
|
||
class WalletViewModel: ViewModel() { | ||
|
||
var userPoint = MutableLiveData<Int>() | ||
|
||
var purchaseHistoryList = MutableLiveData<MutableList<PurchaseHistory>>() | ||
|
||
init { | ||
purchaseHistoryList.value = mutableListOf<PurchaseHistory>() | ||
} | ||
|
||
fun getWalletData(activity: MainActivity) { | ||
|
||
var tempPurchaseHistory = mutableListOf<PurchaseHistory>() | ||
|
||
val apiClient = ApiClient(activity) | ||
val tokenManager = TokenManager(activity) | ||
|
||
apiClient.apiService.getWalletData("Bearer ${tokenManager.getAccessToken()}").enqueue(object : | ||
Callback<BaseResponse<GetWalletDataResponse>> { | ||
override fun onResponse( | ||
call: Call<BaseResponse<GetWalletDataResponse>>, | ||
response: Response<BaseResponse<GetWalletDataResponse>> | ||
) { | ||
Log.d("##", "onResponse 성공: " + response.body().toString()) | ||
if (response.isSuccessful) { | ||
// 정상적으로 통신이 성공된 경우 | ||
val result: BaseResponse<GetWalletDataResponse>? = response.body() | ||
Log.d("##", "onResponse 성공: " + result?.toString()) | ||
|
||
userPoint.value = result?.data?.point | ||
|
||
if (!(result?.data?.purchaseHistories.isNullOrEmpty())) { | ||
for (i in 0 until result?.data?.purchaseHistories?.size!!) { | ||
var date = result.data.purchaseHistories[i].date | ||
var amount = result.data.purchaseHistories[i].amount | ||
var transactionTitle = result.data.purchaseHistories[i].transactionTitle | ||
var transactionType = result.data.purchaseHistories[i].transactionType | ||
|
||
var t1 = PurchaseHistory(date, amount, transactionTitle, transactionType) | ||
|
||
tempPurchaseHistory.add(t1) | ||
} | ||
} | ||
|
||
purchaseHistoryList.value = tempPurchaseHistory | ||
|
||
} else { | ||
// 통신이 실패한 경우(응답코드 3xx, 4xx 등) | ||
var result: BaseResponse<GetWalletDataResponse>? = response.body() | ||
Log.d("##", "onResponse 실패") | ||
Log.d("##", "onResponse 실패: " + response.code()) | ||
Log.d("##", "onResponse 실패: " + response.body()) | ||
val errorBody = response.errorBody()?.string() // 에러 응답 데이터를 문자열로 얻음 | ||
Log.d("##", "Error Response: $errorBody") | ||
|
||
} | ||
} | ||
|
||
override fun onFailure(call: Call<BaseResponse<GetWalletDataResponse>>, t: Throwable) { | ||
// 통신 실패 | ||
Log.d("##", "onFailure 에러: " + t.message.toString()) | ||
} | ||
}) | ||
} | ||
} |