Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private fun createCompany() {
- val name = getCompanyName()
- val address = Input.optional(getCompanyAddress())
- val phone = Input.optional(getCompanyPhone())
- val email = Input.optional(getCompanyEmail())
- val logo= Input.optional(getCompanyLogo())
- val detail= Input.optional(getCompanyDetail())
- doAsync {
- val client = MyApolloClient.getMyApolloClient()
- runOnUiThread {
- progress.visibility = View.VISIBLE
- activity?.window?.setFlags(
- WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,
- WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
- )
- }
- client.mutate(CreateCompanyMutation(name,address,phone,email,logo,detail))
- .enqueue(object : ApolloCall.Callback<CreateCompanyMutation.Data>(){
- override fun onFailure(e: ApolloException) {
- Log.e("message", e.message.toString())
- if (e.message.equals("HTTP 400 Bad Request")) {
- runOnUiThread {
- progress.visibility = View.GONE
- val builder = AlertDialog.Builder(context!!)
- builder.setTitle(getString(R.string.error400title))
- builder.setMessage(getString(R.string.error400message))
- builder.setPositiveButton(getString(R.string.OK)) { _, _ -> }
- val alert: AlertDialog = builder.create()
- alert.show()
- }
- }
- if (e.message.equals("Failed to execute http call")) {
- runOnUiThread {
- progress.visibility = View.GONE
- val builder = AlertDialog.Builder(context!!)
- builder.setTitle(getString(R.string.error400title))
- builder.setMessage(getString(R.string.Offline))
- builder.setPositiveButton(getString(R.string.OK)) { _, _ -> }
- val alert: AlertDialog = builder.create()
- alert.show()
- }
- }
- }
- override fun onResponse(response: Response<CreateCompanyMutation.Data>) {
- val company = response.data()?.CreateCompany()
- if (response.errors().size > 0) {
- for (error in response.errors()) {
- runOnUiThread {
- progress.visibility = View.GONE
- val builder = AlertDialog.Builder(context!!)
- builder.setTitle(getString(R.string.Information))
- builder.setMessage(error.message())
- builder.setPositiveButton(getString(R.string.OK)) { _, _ -> }
- val alert: AlertDialog = builder.create()
- alert.show()
- }
- }
- } else {
- runOnUiThread {
- progress.visibility = View.GONE
- val builder = AlertDialog.Builder(context!!)
- builder.setTitle(getString(R.string.Information))
- builder.setMessage(getString(R.string.CompanyCreated))
- builder.setPositiveButton(getString(R.string.OK)) { _, _ ->
- onBackPressed()
- }
- val alert: AlertDialog = builder.create()
- alert.show()
- }
- }
- }
- })
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement