Advertisement
Guest User

Untitled

a guest
Aug 19th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 4.08 KB | None | 0 0
  1. private fun createCompany()  {
  2.         val name = getCompanyName()
  3.         val address = Input.optional(getCompanyAddress())
  4.         val phone = Input.optional(getCompanyPhone())
  5.         val email = Input.optional(getCompanyEmail())
  6.         val logo= Input.optional(getCompanyLogo())
  7.         val detail= Input.optional(getCompanyDetail())
  8.  
  9.         doAsync {
  10.             val client = MyApolloClient.getMyApolloClient()
  11.             runOnUiThread {
  12.                 progress.visibility = View.VISIBLE
  13.                 activity?.window?.setFlags(
  14.                     WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,
  15.                     WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
  16.                 )
  17.             }
  18.             client.mutate(CreateCompanyMutation(name,address,phone,email,logo,detail))
  19.                 .enqueue(object : ApolloCall.Callback<CreateCompanyMutation.Data>(){
  20.                     override fun onFailure(e: ApolloException) {
  21.                         Log.e("message", e.message.toString())
  22.                         if (e.message.equals("HTTP 400 Bad Request")) {
  23.                             runOnUiThread {
  24.                                 progress.visibility = View.GONE
  25.                                 val builder = AlertDialog.Builder(context!!)
  26.                                 builder.setTitle(getString(R.string.error400title))
  27.                                 builder.setMessage(getString(R.string.error400message))
  28.                                 builder.setPositiveButton(getString(R.string.OK)) { _, _ -> }
  29.                                 val alert: AlertDialog = builder.create()
  30.                                 alert.show()
  31.                             }
  32.                         }
  33.                         if (e.message.equals("Failed to execute http call")) {
  34.                             runOnUiThread {
  35.                                 progress.visibility = View.GONE
  36.                                 val builder = AlertDialog.Builder(context!!)
  37.                                 builder.setTitle(getString(R.string.error400title))
  38.                                 builder.setMessage(getString(R.string.Offline))
  39.                                 builder.setPositiveButton(getString(R.string.OK)) { _, _ -> }
  40.                                 val alert: AlertDialog = builder.create()
  41.                                 alert.show()
  42.                             }
  43.                         }
  44.                     }
  45.                     override fun onResponse(response: Response<CreateCompanyMutation.Data>) {
  46.                         val company = response.data()?.CreateCompany()
  47.  
  48.                         if (response.errors().size > 0) {
  49.                             for (error in response.errors()) {
  50.                                 runOnUiThread {
  51.                                     progress.visibility = View.GONE
  52.                                     val builder = AlertDialog.Builder(context!!)
  53.                                     builder.setTitle(getString(R.string.Information))
  54.                                     builder.setMessage(error.message())
  55.                                     builder.setPositiveButton(getString(R.string.OK)) { _, _ -> }
  56.                                     val alert: AlertDialog = builder.create()
  57.                                     alert.show()
  58.                                 }
  59.                             }
  60.                         } else {
  61.                         runOnUiThread {
  62.                             progress.visibility = View.GONE
  63.                             val builder = AlertDialog.Builder(context!!)
  64.                             builder.setTitle(getString(R.string.Information))
  65.                             builder.setMessage(getString(R.string.CompanyCreated))
  66.                             builder.setPositiveButton(getString(R.string.OK)) { _, _ ->
  67.                                 onBackPressed()
  68.                             }
  69.                             val alert: AlertDialog = builder.create()
  70.                             alert.show()
  71.                         }
  72.                     }
  73.                     }
  74.                 })
  75.         }
  76.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement