fun requestApi(bearer: String, id: String, data: Uri?, type: Boolean) {
val typeUser = if (type) "tidak" else "ya"
retrofit = ApiConfig.getApiService(Server.BASE_URL).getBacaPostingan("Bearer $bearer", id)
retrofit.enqueue(object : Callback<ResponseGetCurhatanTanggapan> {
override fun onResponse(
call: Call<ResponseGetCurhatanTanggapan>,
response: Response<ResponseGetCurhatanTanggapan>
) {
if (response.isSuccessful) {
val dataResponse = response.body()!!
if (dataResponse.data?.statusPublish == "published") {
tampil()
Log.e("RFK", "onResponse: ${dataResponse.status}", )
var judul : String? = dataResponse.data?.judulCurhatan
val fotoUser = dataResponse.data?.user?.get(0)?.imageUser
val nama = dataResponse.data?.namaPenulis
val namaAnonim = dataResponse.data?.user_anonimous?.get(0)?.nama_anonim
val username = dataResponse.data?.user?.get(0)?.username
val usernameAnonim = dataResponse.data?.user_anonimous?.get(0)?.username_anonim
val fotoAnonim = dataResponse.data?.foto_anonim
val waktu = dataResponse.data?.datePublish
val verified = dataResponse.data?.user?.get(0)?.verified
var follow = dataResponse.data?.follow
val kategori = dataResponse.data?.kategori?.get(0)?.namaKategori
val deskripsi = dataResponse.data?.isiCurhatan
var totalLike = dataResponse.data?.totalLike
var validasiLike = dataResponse.data?.user_like
val totalKomentar = dataResponse.data?.totalKomentar
val totalTanggapan = dataResponse.data?.totalJawabanTanggapan
val totalShare = dataResponse.data?.totalShare
val idKategori = dataResponse.data?.idKategori
val type = dataResponse.data?.typeCurhatan
if (dataResponse.data.foto?.size != 0) {
val dataFile = arrayListOf<String>()
for (i in dataResponse.data.foto?.indices!!) {
dataFile.add(dataResponse.data.foto[i]?.file!!)
}
initGambarOrVideo(dataResponse.data.foto[0]?.type!!, dataFile)
}
if (dataResponse.data.curhatanbro?.size != 0) {
if (dataResponse.data.curhatanbro?.get(0)?.foto_file?.size != 0) {
val dataFile = arrayListOf<String>()
for (i in dataResponse.data.curhatanbro?.get(0)?.foto_file?.indices!!) {
dataFile.add(dataResponse.data.curhatanbro[0]?.foto_file!![i]?.file!!)
}
initGambarOrVideo2(
dataResponse.data.curhatanbro[0]?.foto_file!![0]?.type!!,
dataFile
)
}
}
if (dataResponse.data.audio?.isNotEmpty() == true) {
val dataFile = arrayListOf<String>()
for (i in dataResponse.data.audio.indices) {
dataFile.add(dataResponse.data.audio)
}
voiceNote(dataResponse.data.audio)
}
if (dataResponse.data.curhatanbro.isNotEmpty()) {
if (dataResponse.data.curhatanbro[0]?.audio?.isNotEmpty() == true) {
val dataFile = arrayListOf<String>()
for (i in dataResponse.data.curhatanbro[0]?.audio?.indices!!) {
dataFile.add(dataResponse.data.curhatanbro[0]?.audio!!)
}
voiceNote2(dataResponse.data.curhatanbro[0]?.audio!!)
}
}
if (type == "Curhatan") {
binding.idborderCurhatan.visibility = View.GONE
} else {
/* Kalau tanggapan kesini */
binding.btnLoop.visibility = View.GONE
binding.idborderCurhatan.visibility = View.VISIBLE
/* Jika dari deeplink ini jalan */
if (data != null) {
Log.e("RFK", "onResponse: deep link nih ${dataResponse.data?.idCurhatan}")
requestApiUntukTanggapanKetikaDeepLink(dataResponse.data?.idCurhatan.toString())
} else {
bacaCurhatanDariTanggapan(dataResponse.data?.idCurhatan.toString())
Log.e("RFK", "onResponse: dari biasa ${dataResponse.data?.idCurhatan}")
val foto1 = intent.getStringExtra("foto")
val nama1 = intent.getStringExtra("nama")
judul = intent.getStringExtra("judul")
val deskripsi1 = intent.getStringExtra("deskripsi")
Glide.with(this@BacaCurhatanActivity)
.load(foto1)
.circleCrop()
.placeholder(R.drawable.ic_no_image_available)
.into(binding.idimgPertanyaan1)
binding.idtvNamaPenggunaPertanyaan.text = nama1
Log.e("RFK", "onResponse: judul lur $judul ${judul == null} ${judul == "null"}", )
if (judul != null && judul != "null") {
binding.idtvPertanyaan.text = judul
} else {
binding.idtvPertanyaan.visibility = View.GONE
val layoutParam = binding.idtvDeskripsi.layoutParams as ConstraintLayout.LayoutParams
layoutParam.topMargin = 32
}
binding.idtvDeskripsi.text = deskripsi1
}
}
if (zonaSharedpref.getNamaPengguna() == username || zonaSharedpref.getUsernameAnonim() == username) {
binding.idtvIkuti.visibility = View.GONE
} else {
binding.idtvIkuti.visibility = View.VISIBLE
}
/*Validasi yang posting user asli/anonim*/
Log.e("SELASA.20.06", "onResponse: ${dataResponse.data?.anonymouse} ")
if (dataResponse.data?.anonymouse == "tidak") {
Log.e("SELASA.20.06", "bukan anonim ")
Glide.with(this@BacaCurhatanActivity)
.load(fotoUser)
.circleCrop()
.placeholder(R.drawable.ic_no_image_available)
.into(binding.idimgPertanyaan)
binding.idtvNamapengguna.text = nama
/*Validasi ketika request server untuk Ikuti*/
if (follow != null) {
binding.idtvIkuti.apply {
text = "Mengikuti"
setTextColor(Color.parseColor("#6C757D"))
}
} else {
binding.idtvIkuti.apply {
text = "Ikuti+"
setTextColor(Color.parseColor("#0D6EFD"))
}
}
binding.idtvIkuti.setOnClickListener {
if (follow != null) {
binding.idtvIkuti.apply {
text = "Ikuti+"
setTextColor(Color.parseColor("#0D6EFD"))
}
ikutiUser(username!!, bearer, typeUser)
follow = null
} else {
binding.idtvIkuti.apply {
text = "Mengikuti"
setTextColor(Color.parseColor("#6C757D"))
}
ikutiUser(username!!, bearer, typeUser)
follow = 2
}
}
binding.idimgPertanyaan.setOnClickListener {
melihatProfileOrangLain(username, follow)
}
binding.idtvNamapengguna.setOnClickListener {
melihatProfileOrangLain(username, follow)
}
} else {
Log.e("SELASA.20.06", " anonim ")
Glide.with(this@BacaCurhatanActivity)
.load("http://zonamahasiswa.id/assets/img/avatar1.png")
.circleCrop()
.placeholder(R.drawable.ic_no_image_available)
.into(binding.idimgPertanyaan)
binding.idtvNamapengguna.text = namaAnonim
/*Validasi ketika request server untuk Ikuti*/
if (follow != null) {
binding.idtvIkuti.apply {
text = "Batal Suka"
setTextColor(Color.parseColor("#DC3545"))
}
} else {
binding.idtvIkuti.apply {
text = "Suka"
setTextColor(Color.parseColor("#0D6EFD"))
}
}
binding.idtvIkuti.setOnClickListener {
if (follow != null) {
binding.idtvIkuti.apply {
text = "Suka"
setTextColor(Color.parseColor("#0D6EFD"))
}
ikutiUser(username!!, bearer, typeUser)
follow = null
} else {
binding.idtvIkuti.apply {
text = "Batal Suka"
setTextColor(Color.parseColor("#DC3545"))
}
ikutiUser(username!!, bearer, typeUser)
follow = 2
}
}
binding.idimgPertanyaan.setOnClickListener {
melihatProfileOrangLain(usernameAnonim, follow)
}
binding.idtvNamapengguna.setOnClickListener {
melihatProfileOrangLain(usernameAnonim, follow)
}
}
if (verified != "tidak") {
binding.idiconVerified.visibility = View.VISIBLE
} else {
binding.idiconVerified.visibility = View.GONE
}
/*Validasi ketika request server untuk like*/
if (validasiLike?.toInt() != 0) {
/*Mengubah background like*/
binding.iconLikeForhat.apply {
setImageResource(R.drawable.likelike)
setColorFilter(ContextCompat.getColor(context, R.color.ada_like_forhat))
}
} else {
/*Mengubah background like*/
binding.iconLikeForhat.apply {
setImageResource(R.drawable.like_forhat)
setColorFilter(ContextCompat.getColor(context, R.color.black))
}
}
binding.btnLike.setOnClickListener {
if (validasiLike?.toInt() != 0) {
/*Mengubah value TextView like*/
val valueLike = binding.jumlahLikeForhat.text.toString().toInt() - 1
binding.jumlahLikeForhat.apply {
text = valueLike.toString()
}
/*Mengubah background like*/
binding.iconLikeForhat.apply {
setImageResource(R.drawable.like_forhat)
setColorFilter(ContextCompat.getColor(context, R.color.black))
}
likePostingan(id, bearer, typeUser)
validasiLike = "0"
totalLike = valueLike
} else {
/*Mengubah value TextView like*/
val valueLike = binding.jumlahLikeForhat.text.toString().toInt() + 1
binding.jumlahLikeForhat.apply {
text = valueLike.toString()
}
/*Mengubah background like*/
binding.iconLikeForhat.apply {
setImageResource(R.drawable.likelike)
setColorFilter(ContextCompat.getColor(context, R.color.ada_like_forhat))
}
likePostingan(id, bearer, typeUser)
validasiLike = "1"
totalLike = valueLike
}
}
binding.btnLoop.setOnClickListener {
val intent = Intent(this@BacaCurhatanActivity, TulisTanggapanActivity::class.java)
intent.putExtra(HomeAdapter.ID, getIdCurhatan)
intent.putExtra(HomeAdapter.KEY_BEARER, bearer)
if (dataResponse.data?.anonymouse == "ya") {
intent.putExtra("foto", fotoAnonim)
intent.putExtra("nama", namaAnonim)
intent.putExtra("waktu", waktu)
if (judul == null) {
intent.putExtra("judul", deskripsi)
} else {
intent.putExtra("judul", judul.toString())
}
startActivity(intent)
} else {
intent.putExtra("foto", fotoUser)
intent.putExtra("nama", nama)
intent.putExtra("waktu", waktu)
if (judul == null) {
intent.putExtra("judul", deskripsi)
} else {
intent.putExtra("judul", judul.toString())
}
startActivity(intent)
}
Log.e("SMW", "ID = $getIdCurhatan " )
Log.e("SMW", "FOTO = $fotoUser " )
Log.e("SMW", "NAMA = $nama " )
}
binding.btnShare.setOnClickListener {
val textnya = "https://curhatan-tanggapan.zonamahasiswa.net/?id=${getIdCurhatan}&shareid=${"44492"}"
val shreIntent = Intent(Intent.ACTION_SEND)
shreIntent.setType("text/plain")
shreIntent.putExtra(Intent.EXTRA_TEXT, textnya)
startActivity(Intent.createChooser(shreIntent, "Bagikan dengan"))
requestSharePostingan(getIdCurhatan)
}
binding.idtvKomentaran.text = "$totalKomentar Komentar"
if (judul != null && judul != "null") {
binding.idtvJudulcurhatan.text = judul.toString()
} else {
binding.idtvJudulcurhatan.visibility = View.GONE
val layoutParam = binding.idtvJawaban.layoutParams as ConstraintLayout.LayoutParams
layoutParam.topMargin = 30
}
binding.idtvKategoripertanyaan.text = kategori
binding.idtvWaktuposting.text = waktu
binding.idtvJawaban.text = deskripsi
binding.jumlahLikeForhat.text = totalLike.toString()
binding.jumlahCommentForhat.text = totalKomentar.toString()
binding.jumlahLoop.text = totalTanggapan.toString()
binding.jumlahShareForhat.text = totalShare.toString()
// requestGetFileFotoVideo()
binding.idtvKategoripertanyaan.setOnClickListener {
val intent = Intent(this@BacaCurhatanActivity, ListKategoriActivity::class.java)
intent.putExtra("KATEGORI", idKategori.toString())
startActivity(intent)
}
} else {
postinganSudahDihapus()
}
} else {
error()
}
}
override fun onFailure(call: Call<ResponseGetCurhatanTanggapan>, t: Throwable) {
if (call.isCanceled) {
} else {
error()
}
}
})
}