2020-12-28 15:20:31 +01:00
|
|
|
package com.h.pixeldroid.posts
|
2020-10-04 23:27:06 +02:00
|
|
|
|
|
|
|
import android.os.Bundle
|
|
|
|
import android.view.View
|
2020-12-29 22:14:32 +01:00
|
|
|
import androidx.lifecycle.lifecycleScope
|
2020-12-28 15:20:31 +01:00
|
|
|
import com.h.pixeldroid.R
|
2021-01-13 01:28:08 +01:00
|
|
|
import com.h.pixeldroid.databinding.ActivityReportBinding
|
2020-12-26 12:10:54 +01:00
|
|
|
import com.h.pixeldroid.utils.BaseActivity
|
2021-01-13 01:28:08 +01:00
|
|
|
import com.h.pixeldroid.utils.api.objects.Status
|
2020-12-29 22:14:32 +01:00
|
|
|
import retrofit2.HttpException
|
|
|
|
import java.io.IOException
|
2020-10-04 23:27:06 +02:00
|
|
|
|
2020-12-11 16:53:12 +01:00
|
|
|
class ReportActivity : BaseActivity() {
|
2020-10-04 23:27:06 +02:00
|
|
|
|
2021-01-13 01:28:08 +01:00
|
|
|
private lateinit var binding: ActivityReportBinding
|
|
|
|
|
2020-10-04 23:27:06 +02:00
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
|
super.onCreate(savedInstanceState)
|
2021-01-13 01:28:08 +01:00
|
|
|
binding = ActivityReportBinding.inflate(layoutInflater)
|
|
|
|
setContentView(binding.root)
|
|
|
|
|
2020-10-04 23:27:06 +02:00
|
|
|
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
|
|
|
supportActionBar?.setTitle(R.string.report)
|
|
|
|
|
|
|
|
val status = intent.getSerializableExtra(Status.POST_TAG) as Status?
|
|
|
|
|
2021-01-13 01:28:08 +01:00
|
|
|
binding.reportTargetTextview.text = getString(R.string.report_target).format(status?.account?.acct)
|
2020-10-04 23:27:06 +02:00
|
|
|
|
|
|
|
|
2021-01-13 01:28:08 +01:00
|
|
|
binding.reportButton.setOnClickListener{
|
|
|
|
binding.reportButton.visibility = View.INVISIBLE
|
|
|
|
binding.reportProgressBar.visibility = View.VISIBLE
|
2020-10-04 23:27:06 +02:00
|
|
|
|
2021-01-13 01:28:08 +01:00
|
|
|
binding.textInputLayout.editText?.isEnabled = false
|
2020-10-04 23:27:06 +02:00
|
|
|
|
2021-04-20 14:07:18 +02:00
|
|
|
val api = apiHolder.api ?: apiHolder.setToCurrentUser()
|
2020-10-04 23:27:06 +02:00
|
|
|
|
2020-12-29 22:14:32 +01:00
|
|
|
lifecycleScope.launchWhenCreated {
|
|
|
|
try {
|
2021-04-18 22:32:50 +02:00
|
|
|
api.report(
|
|
|
|
status?.account?.id!!,
|
|
|
|
listOf(status),
|
|
|
|
binding.textInputLayout.editText?.text.toString()
|
|
|
|
)
|
2020-10-04 23:27:06 +02:00
|
|
|
|
2020-12-29 22:14:32 +01:00
|
|
|
reportStatus(true)
|
|
|
|
} catch (exception: IOException) {
|
|
|
|
reportStatus(false)
|
|
|
|
} catch (exception: HttpException) {
|
|
|
|
reportStatus(false)
|
|
|
|
}
|
|
|
|
}
|
2020-10-04 23:27:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-29 22:14:32 +01:00
|
|
|
private fun reportStatus(success: Boolean){
|
|
|
|
if(success){
|
2021-01-13 01:28:08 +01:00
|
|
|
binding.reportProgressBar.visibility = View.GONE
|
|
|
|
binding.reportButton.isEnabled = false
|
|
|
|
binding.reportButton.text = getString(R.string.reported)
|
|
|
|
binding.reportButton.visibility = View.VISIBLE
|
2020-12-29 22:14:32 +01:00
|
|
|
} else {
|
2021-01-13 01:28:08 +01:00
|
|
|
binding.textInputLayout.error = getString(R.string.report_error)
|
|
|
|
binding.reportButton.visibility = View.VISIBLE
|
|
|
|
binding.textInputLayout.editText?.isEnabled = true
|
|
|
|
binding.reportProgressBar.visibility = View.GONE
|
2020-12-29 22:14:32 +01:00
|
|
|
}
|
|
|
|
}
|
2020-10-04 23:27:06 +02:00
|
|
|
|
|
|
|
override fun onSupportNavigateUp(): Boolean {
|
|
|
|
onBackPressed()
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|