How to use httpPut method of com.example.fuel.MainActivity class

Best Fuel code snippet using com.example.fuel.MainActivity.httpPut

GestionLibrosActivity.kt

Source:GestionLibrosActivity.kt Github

copy

Full Screen

...22import com.example.proyecto_libreria.R23import com.github.kittinunf.fuel.httpDelete24import com.github.kittinunf.fuel.httpGet25import com.github.kittinunf.fuel.httpPost26import com.github.kittinunf.fuel.httpPut27import com.github.kittinunf.result.Result28import com.google.firebase.ml.naturallanguage.FirebaseNaturalLanguage29import com.google.firebase.ml.naturallanguage.languageid.FirebaseLanguageIdentification30import kotlinx.android.synthetic.main.activity_gestion_libros.*31import kotlinx.android.synthetic.main.content_catalogo.*32class GestionLibrosActivity : AppCompatActivity() {33 companion object companionObjectlibros {34 var lista = listOf<Libro>()35 }36 private var permission = arrayOf(37 android.Manifest.permission.ACCESS_FINE_LOCATION,38 android.Manifest.permission.ACCESS_COARSE_LOCATION39 )40 override fun onCreate(savedInstanceState: Bundle?) {41 super.onCreate(savedInstanceState)42 setContentView(R.layout.activity_gestion_libros)43 cargarLibros()44 btn_buscarLibroGestion.setOnClickListener {45 buscarLibros()46 }47 btn_nuevoLibro.setOnClickListener {48 dialogLibro(49 Libro(50 -1, "", "", "", 0, "", 0.0,51 "", ""52 ), 153 )54 }55 var toolbar: androidx.appcompat.widget.Toolbar = findViewById(R.id.toolbar)56 this.setSupportActionBar(toolbar)57 val actionBar = supportActionBar58 // Set toolbar title/app title59 actionBar!!.title = "Hello APP"60 // Set action bar/toolbar sub title61 actionBar.subtitle = "App subtitle"62 // Set action bar elevation63 actionBar.elevation = 4.0F64 // Display the app icon in action bar/toolbar65 actionBar.setDisplayShowHomeEnabled(true)66 }67 fun cargarLibros() {68 val url = "${MainActivity.url}/libro"69 var lista = listOf<LibroCatalogo>()70 var listaLibros = ArrayList<LibroCatalogo>()71 url72 .httpGet()73 .responseString { request, response, result ->74 when (result) {75 is Result.Failure -> {76 val ex = result.getException()77 Log.i("http", "Error: ${ex.message}")78 }79 is Result.Success -> {80 val data = result.get()81 Log.i("http", "Data: ${data}")82 var libroParseada = Klaxon().parseArray<Libro>(data)83 companionObjectlibros.lista = libroParseada!!84 runOnUiThread {85 iniciarLibros(companionObjectlibros.lista, this, rv_gestionLibros)86 }87 }88 }89 }90 }91 fun guardarLibro(libro: Libro) {92 val url = "${MainActivity.objetoCompartido.url}/libro"93 val bodyJson = """94 {95 "titulo": "${libro.titulo}",96 "autor": "${libro.autor}",97 "edicion" : ${libro.edicion},98 "editorial": "${libro.editorial}",99 "precio": ${libro.precio},100 "isbn": "${libro.isbn}",101 "idioma": "${libro.idioma}",102 "estado": "${libro.estado}"103 }104 """105 url106 .httpPost().body(bodyJson)107 .responseString { request, response, result ->108 when (result) {109 is Result.Failure -> {110 val ex = result.getException()111 Log.i("http", "rEQUEST: ${request}")112 }113 is Result.Success -> {114 runOnUiThread {115 cargarLibros()116 }117 Log.i("http", "TODO BIIIEN")118 }119 }120 }121 }122 fun eliminarLibro(idLibro: Int) {123 val url = "${MainActivity.url}/libro/${idLibro}"124 var lista = listOf<LibroCatalogo>()125 var listaLibros = ArrayList<LibroCatalogo>()126 url127 .httpDelete()128 .responseString { request, response, result ->129 when (result) {130 is Result.Failure -> {131 val ex = result.getException()132 Log.i("http", "Error: ${ex.message}")133 }134 is Result.Success -> {135 cargarLibros()136 }137 }138 }139 }140 fun buscarLibros(){141 var listaFiltrada= companionObjectlibros.lista.filter {142 it.titulo.contains(txt_buscarLibroGestion.text.toString())143 }144 iniciarLibros(listaFiltrada, this, rv_gestionLibros)145 }146 fun editarLibro(libro: Libro) {147 val url = "${MainActivity.objetoCompartido.url}/libro/${libro.id}"148 val bodyJson = """149 {150 "titulo": "${libro.titulo}",151 "autor": "${libro.autor}",152 "edicion" : ${libro.edicion},153 "editorial": "${libro.editorial}",154 "precio": ${libro.precio},155 "isbn": "${libro.isbn}",156 "idioma": "${libro.idioma}",157 "estado": "${libro.estado}"158 }159 """160 url161 .httpPut().body(bodyJson)162 .responseString { request, response, result ->163 when (result) {164 is Result.Failure -> {165 val ex = result.getException()166 Log.i("http", "rEQUEST: ${request}")167 }168 is Result.Success -> {169 runOnUiThread {170 cargarLibros()171 }172 Log.i("http", "TODO BIIIEN")173 }174 }175 }...

Full Screen

Full Screen

ProfileActivity.kt

Source:ProfileActivity.kt Github

copy

Full Screen

...16import com.example.kalepa.models.User17import com.github.kittinunf.fuel.android.extension.responseJson18import com.github.kittinunf.fuel.httpGet19import com.github.kittinunf.fuel.httpPost20import com.github.kittinunf.fuel.httpPut21import com.github.kittinunf.result.Result22import kotlinx.android.synthetic.main.activity_profile.*23import org.jetbrains.anko.toast24import org.json.JSONObject25class ProfileActivity : AppCompatActivity() {26 private val user = User()27 internal lateinit var viewpageradapter:ViewPagerAdapter28 override fun onCreate(savedInstanceState: Bundle?) {29 super.onCreate(savedInstanceState)30 setContentView(R.layout.activity_profile)31 val userId = intent.getStringExtra(USER_ARG)32 viewpageradapter= ViewPagerAdapter(supportFragmentManager)33 viewpageradapter.setUser_id(userId.toInt())34 this.viewPager.adapter=viewpageradapter //Binding PagerAdapter with ViewPager35 this.n_other_profile_navigation.setupWithViewPager(this.viewPager)36 val builder = AlertDialog.Builder(this)37 val dialogView = layoutInflater.inflate(R.layout.progress_dialog,null)38 val message = dialogView.findViewById<TextView>(R.id.message)39 message.text = "Cargando datos..."40 builder.setView(dialogView)41 builder.setCancelable(false)42 val dialog = builder.create()43 dialog.show()44 val url = MainActivity().projectURL + "/user/" + userId45 val req = url.httpGet().header(Pair("Cookie", SharedApp.prefs.cookie))46 req.responseJson { request, response, result ->47 when (result) {48 is Result.Failure -> {49 dialog.dismiss()50 toast("Error cargando el perfil")51 }52 is Result.Success -> {53 setUserInfo(result.value)54 dialog.dismiss()55 }56 }57 }58 }59 private fun setUserInfo(jsonUser: JSONObject) {60 user.fromJSON(jsonUser)61 b_profile_username.setText(user.nick)62 b_profile_image.loadImage(user.avatar)63 b_profile_desc.setText(user.desc)64 b_profile_place.setText(user.place)65 b_profile_rating.rating = user.points.toFloat()66 }67 companion object {68 private const val USER_ARG = "com.example.kalepa.ProfileActivity.userArgKey"69 fun getIntent(context: Context, userId: String) = context70 .getIntent<ProfileActivity>()71 .apply { putExtra(USER_ARG, userId) }72 fun start(context: Context, userId: String) {73 val intent = getIntent(context, userId)74 context.startActivity(intent)75 }76 }77 override fun onCreateOptionsMenu(menu: Menu): Boolean {78 if (SharedApp.prefs.isMod) {79 val inflater = menuInflater80 inflater.inflate(R.menu.mod_user_menu, menu)81 return true82 } else {83 val inflater = menuInflater84 inflater.inflate(R.menu.regular_user_menu, menu)85 return true86 }87 return false88 }89 override fun onOptionsItemSelected(item: MenuItem) = when (item.itemId) {90 R.id.n_rum_report -> {91 reportUser()92 true93 }94 R.id.n_mum_banear -> {95 banUser()96 true97 }98 R.id.n_mum_mod -> {99 giveMod()100 true101 }102 else -> {103 super.onOptionsItemSelected(item)104 }105 }106 private fun reportUser() {107 val view = layoutInflater.inflate(R.layout.dialog_report_user, null)108 val window = PopupWindow(109 view, // Custom view to show in popup window110 LinearLayout.LayoutParams.WRAP_CONTENT, // Width of popup window111 LinearLayout.LayoutParams.WRAP_CONTENT // Window height112 )113 window.isFocusable = true114 //Blur the background115 val fcolorNone = ColorDrawable(resources.getColor(R.color.transparent))116 val fcolorBlur = ColorDrawable(resources.getColor(R.color.transparentDark))117 n_profile_container.foreground = fcolorBlur118 window.showAtLocation(119 n_profile_header, // Location to display popup window120 Gravity.CENTER, // Exact position of layout to display popup121 0, // X offset122 0 // Y offset123 )124 val cancel = view.findViewById<Button>(R.id.n_dru_cancelar)125 val report = view.findViewById<Button>(R.id.n_dru_reportar)126 val reason = view.findViewById<EditText>(R.id.n_dru_reason)127 report.setOnClickListener {128 if (!reason.text.toString().equals("")) {129 val builder = AlertDialog.Builder(this)130 val dialogView = layoutInflater.inflate(R.layout.progress_dialog,null)131 val message = dialogView.findViewById<TextView>(R.id.message)132 message.text = "Enviando report..."133 builder.setView(dialogView)134 builder.setCancelable(false)135 val dialog = builder.create()136 dialog.show()137 val jsonObject = JSONObject()138 jsonObject.accumulate("user_id", user.id)139 jsonObject.accumulate("reason", reason.text.toString())140 val url = MainActivity().projectURL + "/report"141 val req = url.httpPost().body(jsonObject.toString()).header(Pair("Cookie", SharedApp.prefs.cookie))142 req.httpHeaders["Content-Type"] = "application/json"143 req.response { request, response, result ->144 when (result) {145 is Result.Failure -> {146 dialog.dismiss()147 toast("Error enviando report")148 }149 is Result.Success -> {150 dialog.dismiss()151 toast("Report enviado")152 }153 }154 }155 window.dismiss()156 } else{157 toast("Se debe introducir un motivo")158 }159 }160 cancel.setOnClickListener {161 window.dismiss()162 }163 window.setOnDismissListener {164 n_profile_container.foreground = fcolorNone165 }166 true167 }168 private fun banUser() {169 val view = layoutInflater.inflate(R.layout.dialog_ban_user, null)170 val window = PopupWindow(171 view, // Custom view to show in popup window172 LinearLayout.LayoutParams.WRAP_CONTENT, // Width of popup window173 LinearLayout.LayoutParams.WRAP_CONTENT // Window height174 )175 window.isFocusable = true176 //Blur the background177 val fcolorNone = ColorDrawable(resources.getColor(R.color.transparent))178 val fcolorBlur = ColorDrawable(resources.getColor(R.color.transparentDark))179 n_profile_container.foreground = fcolorBlur180 window.showAtLocation(181 n_profile_header, // Location to display popup window182 Gravity.CENTER, // Exact position of layout to display popup183 0, // X offset184 0 // Y offset185 )186 val cancel = view.findViewById<Button>(R.id.n_dbu_cancelar)187 val ban = view.findViewById<Button>(R.id.n_dbu_banear)188 val reason = view.findViewById<EditText>(R.id.n_dbu_reason)189 val date = view.findViewById<EditText>(R.id.n_dbu_date)190 ban.setOnClickListener {191 if (chekFields(reason,date)) {192 val builder = AlertDialog.Builder(this)193 val dialogView = layoutInflater.inflate(R.layout.progress_dialog,null)194 val message = dialogView.findViewById<TextView>(R.id.message)195 message.text = "Comunicando baneo..."196 builder.setView(dialogView)197 builder.setCancelable(false)198 val dialog = builder.create()199 dialog.show()200 val ban_until = date.text.toString() //+ " 00:00:00"201 val jsonObject = JSONObject()202 jsonObject.accumulate("ban_reason", reason.text.toString())203 jsonObject.accumulate("ban_until", ban_until)204 val url = MainActivity().projectURL + "/user/" + user.id + "/ban"205 val req = url.httpPut().body(jsonObject.toString()).header(Pair("Cookie", SharedApp.prefs.cookie))206 req.httpHeaders["Content-Type"] = "application/json"207 req.response { request, response, result ->208 when (result) {209 is Result.Failure -> {210 dialog.dismiss()211 toast("Error procesando el baneo")212 }213 is Result.Success -> {214 dialog.dismiss()215 toast("Usuario baneado")216 }217 }218 }219 window.dismiss()220 }221 }222 cancel.setOnClickListener {223 window.dismiss()224 }225 window.setOnDismissListener {226 n_profile_container.foreground = fcolorNone227 }228 true229 }230 private fun chekFields(reason: EditText, date: EditText): Boolean {231 var right = true232 if (reason.text.toString().equals("")) {233 toast("Debe especificarse un motivo de baneo")234 right = false235 } else {236 val regex = """[1-2][0-9][0-9][0-9]-[0-1][0-9]-[0-3][0-9]""".toRegex()237 if (!regex.matches(date.text.toString())) {238 toast("El formato debe ser aaaa-mm-dd")239 right = false240 }241 }242 return right243 }244 private fun giveMod() {245 val builder = AlertDialog.Builder(this)246 val dialogView = layoutInflater.inflate(R.layout.progress_dialog,null)247 val message = dialogView.findViewById<TextView>(R.id.message)248 message.text = "Procesando operación..."249 builder.setView(dialogView)250 builder.setCancelable(false)251 val dialog = builder.create()252 dialog.show()253 val url = MainActivity().projectURL + "/user/" + user.id.toString() + "/mod"254 val req = url.httpPut().header(Pair("Cookie", SharedApp.prefs.cookie))255 req.response { request, response, result ->256 when (result) {257 is Result.Failure -> {258 dialog.dismiss()259 toast("Error en el proceso, intentelo de nuevo más tarde")260 }261 is Result.Success -> {262 dialog.dismiss()263 toast("El usuario es ahora moderador")264 }265 }266 }267 }268}...

Full Screen

Full Screen

MainActivity.kt

Source:MainActivity.kt Github

copy

Full Screen

...15import com.github.kittinunf.fuel.gson.responseObject16import com.github.kittinunf.fuel.httpDelete17import com.github.kittinunf.fuel.httpGet18import com.github.kittinunf.fuel.httpPost19import com.github.kittinunf.fuel.httpPut20import com.github.kittinunf.fuel.livedata.liveDataObject21import com.github.kittinunf.fuel.rx.rxObject22import com.github.kittinunf.fuel.stetho.StethoHook23import com.github.kittinunf.result.Result24import com.google.gson.Gson25import com.google.gson.reflect.TypeToken26import io.reactivex.android.schedulers.AndroidSchedulers27import io.reactivex.disposables.CompositeDisposable28import io.reactivex.schedulers.Schedulers29import kotlinx.android.synthetic.main.activity_main.mainAuxText30import kotlinx.android.synthetic.main.activity_main.mainClearButton31import kotlinx.android.synthetic.main.activity_main.mainGoButton32import kotlinx.android.synthetic.main.activity_main.mainGoCoroutineButton33import kotlinx.android.synthetic.main.activity_main.mainResultText34import kotlinx.coroutines.CoroutineStart35import kotlinx.coroutines.Dispatchers36import kotlinx.coroutines.GlobalScope37import kotlinx.coroutines.launch38import java.io.File39import java.io.Reader40class MainActivity : AppCompatActivity() {41 private val TAG = MainActivity::class.java.simpleName42 private val bag by lazy { CompositeDisposable() }43 override fun onCreate(savedInstanceState: Bundle?) {44 super.onCreate(savedInstanceState)45 setContentView(R.layout.activity_main)46 FuelManager.instance.apply {47 basePath = "http://httpbin.org"48 baseHeaders = mapOf("Device" to "Android")49 baseParams = listOf("key" to "value")50 hook = StethoHook("Fuel Sample App")51// addResponseInterceptor { loggingResponseInterceptor() }52 }53 mainGoCoroutineButton.setOnClickListener {54 GlobalScope.launch(Dispatchers.Main, CoroutineStart.DEFAULT) {55 executeCoroutine()56 }57 }58 mainGoButton.setOnClickListener {59 execute()60 }61 mainClearButton.setOnClickListener {62 mainResultText.text = ""63 mainAuxText.text = ""64 }65 }66 override fun onDestroy() {67 super.onDestroy()68 bag.clear()69 }70 private fun execute() {71 httpGet()72 httpPut()73 httpPost()74 httpPatch()75 httpDelete()76 httpDownload()77 httpUpload()78 httpBasicAuthentication()79 httpListResponseObject()80 httpResponseObject()81 httpGsonResponseObject()82 httpCancel()83 httpRxSupport()84 httpLiveDataSupport()85 }86 private suspend fun executeCoroutine() {87 httpGetCoroutine()88 }89 private suspend fun httpGetCoroutine() {90 val (request, response, result) = Fuel.get("/get", listOf("userId" to "123")).awaitStringResponseResult()91 Log.d(TAG, response.toString())92 Log.d(TAG, request.toString())93 update(result)94 }95 private fun httpCancel() {96 val request = Fuel.get("/delay/10")97 .interrupt { Log.d(TAG, it.url.toString() + " is interrupted") }98 .responseString { _, _, _ -> /* noop */ }99 Handler().postDelayed({ request.cancel() }, 1000)100 }101 private fun httpResponseObject() {102 "https://api.github.com/repos/kittinunf/Fuel/issues/1"103 .httpGet()104 .also { Log.d(TAG, it.cUrlString()) }105 .responseObject(Issue.Deserializer()) { _, _, result -> update(result) }106 }107 private fun httpListResponseObject() {108 "https://api.github.com/repos/kittinunf/Fuel/issues"109 .httpGet()110 .also { Log.d(TAG, it.cUrlString()) }111 .responseObject(Issue.ListDeserializer()) { _, _, result -> update(result) }112 }113 private fun httpGsonResponseObject() {114 "https://api.github.com/repos/kittinunf/Fuel/issues/1"115 .httpGet()116 .also { Log.d(TAG, it.cUrlString()) }117 .responseObject<Issue> { _, _, result -> update(result) }118 }119 private fun httpGet() {120 Fuel.get("/get", listOf("foo" to "foo", "bar" to "bar"))121 .also { Log.d(TAG, it.cUrlString()) }122 .responseString { _, _, result -> update(result) }123 "/get"124 .httpGet()125 .also { Log.d(TAG, it.cUrlString()) }126 .responseString { _, _, result -> update(result) }127 }128 private fun httpPut() {129 Fuel.put("/put", listOf("foo" to "foo", "bar" to "bar"))130 .also { Log.d(TAG, it.cUrlString()) }131 .responseString { _, _, result -> update(result) }132 "/put"133 .httpPut(listOf("foo" to "foo", "bar" to "bar"))134 .also { Log.d(TAG, it.cUrlString()) }135 .responseString { _, _, result -> update(result) }136 }137 private fun httpPost() {138 Fuel.post("/post", listOf("foo" to "foo", "bar" to "bar"))139 .also { Log.d(TAG, it.cUrlString()) }140 .responseString { _, _, result -> update(result) }141 "/post"142 .httpPost(listOf("foo" to "foo", "bar" to "bar"))143 .also { Log.d(TAG, it.cUrlString()) }144 .responseString { _, _, result -> update(result) }145 }146 private fun httpPatch() {147 val manager = FuelManager().apply {...

Full Screen

Full Screen

EditTradeActivity.kt

Source:EditTradeActivity.kt Github

copy

Full Screen

...15import com.example.kalepa.models.Trade16import com.github.kittinunf.fuel.android.extension.responseJson17import com.github.kittinunf.fuel.httpGet18import com.github.kittinunf.fuel.httpPost19import com.github.kittinunf.fuel.httpPut20import com.github.kittinunf.result.Result21import kotlinx.android.synthetic.main.activity_edit_trade.*22import org.jetbrains.anko.toast23import org.json.JSONArray24import org.json.JSONObject25class EditTradeActivity : AppCompatActivity() {26 private var products = ArrayList<RawProduct>()27 private var productIds = ArrayList<String>()28 private var product = Product()29 val trade: Trade by extra(TRADE_ARG)30 override fun onCreate(savedInstanceState: Bundle?) {31 super.onCreate(savedInstanceState)32 setContentView(R.layout.activity_edit_trade)33 n_recyclerView_edit_trade_products.layoutManager = GridLayoutManager(this, 1)34 n_swipeRefreshView_edit_trade_products.setOnRefreshListener {35 products.clear()36 loadProducts()37 n_swipeRefreshView_edit_trade_products.isRefreshing = false38 }39 loadProducts()40 }41 private fun loadProducts() {42 val builder = AlertDialog.Builder(this)43 val dialogView = layoutInflater.inflate(R.layout.progress_dialog,null)44 val message = dialogView.findViewById<TextView>(R.id.message)45 message.text = "Cargando productos..."46 builder.setView(dialogView)47 builder.setCancelable(false)48 val dialog = builder.create()49 dialog.show()50 val url = MainActivity().projectURL + "/products/" + SharedApp.prefs.userId.toString()51 val req = url.httpGet().header(Pair("Cookie", SharedApp.prefs.cookie))52 req.responseJson { request, response, result ->53 when (result) {54 is Result.Failure -> {55 dialog.dismiss()56 toast("Error cargando sus productos, intentelo de nuevo más tarde")57 }58 is Result.Success -> {59 Initialize(result.value)60 dialog.dismiss()61 }62 }63 }64 }65 private fun show(items: List<RawProduct>) {66 val categoryItemAdapters = items.map(this::createCategoryItemAdapter)67 n_recyclerView_edit_trade_products.adapter = MainListAdapter(categoryItemAdapters)68 }69 private fun createCategoryItemAdapter(product: RawProduct)70 = OfferAdapter(product,71 { updateIdList(product) } )72 private fun updateIdList(product: RawProduct){73 val p_id = product.id.toString()74 if (productIds.contains(p_id)) {75 productIds.remove(p_id)76 } else {77 productIds.add(p_id)78 }79 }80 private fun Initialize (jsonProducts: JSONObject) {81 val length = jsonProducts.get("length").toString().toInt()82 val list = jsonProducts.get("list")83 if (list is JSONArray){84 for (i in 0 until length) {85 var product = RawProduct()86 product.fromJSON(list.getJSONObject(i))87 products.add(product)88 }89 }90 show(products)91 n_edit_trade_buy_button.setOnClickListener {92 updateTrade()93 }94 val builder = AlertDialog.Builder(this)95 val dialogView = layoutInflater.inflate(R.layout.progress_dialog,null)96 val message = dialogView.findViewById<TextView>(R.id.message)97 message.text = "Cargando productos..."98 builder.setView(dialogView)99 builder.setCancelable(false)100 val dialog = builder.create()101 dialog.show()102 val product_id: String? = trade.product_id.toString()103 val url = MainActivity().projectURL + "/product/" + product_id104 val req = url.httpGet().header(Pair("Cookie", SharedApp.prefs.cookie))105 req.responseJson { request, response, result ->106 when (result) {107 is Result.Failure -> {108 dialog.dismiss()109 toast("Error cargando sus productos, intentelo de nuevo más tarde")110 }111 is Result.Success -> {112 product.fromJSON(result.value)113 dialog.dismiss()114 }115 }116 }117 }118 private fun updateTrade() {119 if (checkFields()) {120 val trade_id = trade.id121 val builder = AlertDialog.Builder(this)122 val dialogView = layoutInflater.inflate(R.layout.progress_dialog,null)123 val message = dialogView.findViewById<TextView>(R.id.message)124 message.text = "Actualizando intercambio..."125 builder.setView(dialogView)126 builder.setCancelable(false)127 val dialog = builder.create()128 dialog.show()129 val jsonArray = JSONArray()130 for( s in productIds ) {131 jsonArray.put(s)132 }133 var offeredMoney: Float = 0.0f134 if (!n_edit_trade_offer.text.toString().isNullOrEmpty()){135 offeredMoney = n_edit_trade_offer.text.toString().toFloat()136 }137 val jsonObject = JSONObject()138 jsonObject.accumulate("price", offeredMoney)139 jsonObject.accumulate("products", jsonArray)140 val url = MainActivity().projectURL + "/trade/" + trade_id + "/offer"141 val req = url.httpPut().body(jsonObject.toString()).header(Pair("Cookie", SharedApp.prefs.cookie))142 req.httpHeaders["Content-Type"] = "application/json"143 req.response { request, response, result ->144 when (result) {145 is Result.Failure -> {146 dialog.dismiss()147 toast("La oferta no es válida")148 }149 is Result.Success -> {150 dialog.dismiss()151 trade.price = offeredMoney.toDouble()152 ChatActivity.start(this, trade)153 toast("Intercambio actualizado")154 }155 }...

Full Screen

Full Screen

SettingsFragment.kt

Source:SettingsFragment.kt Github

copy

Full Screen

...15import com.github.kittinunf.fuel.android.extension.responseJson16import com.github.kittinunf.fuel.httpDelete17import com.github.kittinunf.fuel.httpGet18import com.github.kittinunf.fuel.httpPost19import com.github.kittinunf.fuel.httpPut20import com.github.kittinunf.result.Result21import kotlinx.android.synthetic.main.fragment_settings.*22import org.jetbrains.anko.support.v4.toast23import org.json.JSONObject24class SettingsFragment: Fragment() {25 companion object {26 fun newInstance(): SettingsFragment {27 return SettingsFragment()28 }29 }30 override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? =31 inflater.inflate(R.layout.fragment_settings, container, false)32 override fun onActivityCreated(savedInstanceState: Bundle?) {33 super.onActivityCreated(savedInstanceState)...

Full Screen

Full Screen

CrearEntrenadorActivity.kt

Source:CrearEntrenadorActivity.kt Github

copy

Full Screen

...4import android.os.Bundle5import android.util.Log6import com.example.andres.examenapp2.BDD.Companion.ip7import com.github.kittinunf.fuel.httpPost8import com.github.kittinunf.fuel.httpPut9import com.github.kittinunf.result.Result10import kotlinx.android.synthetic.main.activity_crear_Entrenador.*11class CrearEntrenadorActivity : AppCompatActivity() {12 override fun onCreate(savedInstanceState: Bundle?) {13 super.onCreate(savedInstanceState)14 setContentView(R.layout.activity_crear_so)15 val sistema = intent.getParcelableExtra<EntrenadorSe?>("sistema")16 //val sistema: SistemaOperativo? = null17 var esnuevo = true18 if (sistema != null) {19 txt_id_so_r.setText(sistema.id.toString())20 txt_nombre.setText(sistema.nombre)21 txt_version.setText(sistema.apellido)22 txt_fecha.setText(sistema.fechaNacimiento)23 txt_peso.setText(sistema.NumeroMedallas)24 esnuevo = false25 }26 boton_registrar_so.setOnClickListener {27 if(esnuevo){28 crearActualizarSO(true)29 }else{30 crearActualizarSO(false)31 }32 }33 boton_cancelar_reg_so.setOnClickListener {34 irInicio()35 }36 }37 fun crearActualizarSO(es_nuevo:Boolean){38 val id = txt_id_so_r.text.toString()39 val nombre = txt_nombre.text.toString()40 val version = txt_version.text.toString()41 val fecha = txt_fecha.text.toString()42 val peso = txt_peso.text.toString()43 val so:SistemaOperativo44 if(es_nuevo){45 so = SistemaOperativo(id=null,nombre = nombre,version = version,fechaLanzamiento = fecha,peso_gigas = peso)46 }else{47 so = SistemaOperativo(id=id.toInt(),nombre = nombre,version = version,fechaLanzamiento = fecha,peso_gigas = peso)48 }49 //Crear objeto50 val parametros = listOf("nombrePokemon" to so.nombre, "poderEspecialUno" to so.version,51 "poderEspecialDos" to so.fechaLanzamiento, "fechaCaptura" to so.peso_gigas)52 Log.i("htpp",parametros.toString())53 var direccion = ""54 if(es_nuevo){55 direccion = "http://$ip:80/sistemas/api/"56 val url = direccion57 .httpPost(parametros)58 .responseString { request, response, result ->59 when (result) {60 is Result.Failure -> {61 val ex = result.getException()62 Log.i("http-p", ex.toString())63 mensaje(this,"error","Datos no validos")64 }65 is Result.Success -> run {66 val data = result.get()67 Log.i("http-p", data)68 mensaje(this,"Aceptado","Datos validos, espere...")69 cargarDatosSO(direccion, ::irlistarSo)70 }71 }72 }73 }else{74 direccion = "http://$ip:80/sistemas/api/${so.id}/update"75 val url = direccion76 .httpPut(parametros)77 .responseString { request, response, result ->78 when (result) {79 is Result.Failure -> {80 val ex = result.getException()81 Log.i("http-p", ex.toString())82 mensaje(this,"error","Datos no validos")83 }84 is Result.Success -> run {85 val data = result.get()86 Log.i("http-p", data)87 mensaje(this,"Aceptado","Datos validos, espere...")88 val redire = "http://$ip:80/sistemas/api/"89 cargarDatosSO(redire, ::irlistarSo)90 }...

Full Screen

Full Screen

CrearSOActivity.kt

Source:CrearSOActivity.kt Github

copy

Full Screen

...4import android.os.Bundle5import android.util.Log6import com.example.andres.examenapp2.BDD.Companion.ip7import com.github.kittinunf.fuel.httpPost8import com.github.kittinunf.fuel.httpPut9import com.github.kittinunf.result.Result10import kotlinx.android.synthetic.main.activity_crear_so.*11class CrearSOActivity : AppCompatActivity() {12 override fun onCreate(savedInstanceState: Bundle?) {13 super.onCreate(savedInstanceState)14 setContentView(R.layout.activity_crear_so)15 val sistema = intent.getParcelableExtra<SistemaOperativoSe?>("sistema")16 //val sistema: SistemaOperativo? = null17 var esnuevo = true18 if (sistema != null) {19 txt_id_so_r.setText(sistema.id.toString())20 txt_nombre.setText(sistema.nombre)21 txt_version.setText(sistema.version)22 txt_fecha.setText(sistema.fechaLanzamiento)23 txt_peso.setText(sistema.peso_gigas)24 esnuevo = false25 }26 boton_registrar_so.setOnClickListener {27 if(esnuevo){28 crearActualizarSO(true)29 }else{30 crearActualizarSO(false)31 }32 }33 boton_cancelar_reg_so.setOnClickListener {34 irInicio()35 }36 }37 fun crearActualizarSO(es_nuevo:Boolean){38 val id = txt_id_so_r.text.toString()39 val nombre = txt_nombre.text.toString()40 val version = txt_version.text.toString()41 val fecha = txt_fecha.text.toString()42 val peso = txt_peso.text.toString()43 val so:SistemaOperativo44 if(es_nuevo){45 so = SistemaOperativo(id=null,nombre = nombre,version = version,fechaLanzamiento = fecha,peso_gigas = peso)46 }else{47 so = SistemaOperativo(id=id.toInt(),nombre = nombre,version = version,fechaLanzamiento = fecha,peso_gigas = peso)48 }49 //Crear objeto50 val parametros = listOf("nombre" to so.nombre, "version" to so.version,51 "fechaLanzamiento" to so.fechaLanzamiento, "peso_gigas" to so.peso_gigas)52 Log.i("htpp",parametros.toString())53 var direccion = ""54 if(es_nuevo){55 direccion = "http://$ip:80/sistemas/api/"56 val url = direccion57 .httpPost(parametros)58 .responseString { request, response, result ->59 when (result) {60 is Result.Failure -> {61 val ex = result.getException()62 Log.i("http-p", ex.toString())63 mensaje(this,"error","Datos no validos")64 }65 is Result.Success -> run {66 val data = result.get()67 Log.i("http-p", data)68 mensaje(this,"Aceptado","Datos validos, espere...")69 cargarDatosSO(direccion, ::irlistarSo)70 }71 }72 }73 }else{74 direccion = "http://$ip:80/sistemas/api/${so.id}/update"75 val url = direccion76 .httpPut(parametros)77 .responseString { request, response, result ->78 when (result) {79 is Result.Failure -> {80 val ex = result.getException()81 Log.i("http-p", ex.toString())82 mensaje(this,"error","Datos no validos")83 }84 is Result.Success -> run {85 val data = result.get()86 Log.i("http-p", data)87 mensaje(this,"Aceptado","Datos validos, espere...")88 val redire = "http://$ip:80/sistemas/api/"89 cargarDatosSO(redire, ::irlistarSo)90 }...

Full Screen

Full Screen

ModifcarMarca.kt

Source:ModifcarMarca.kt Github

copy

Full Screen

...6import android.util.Log7import android.widget.ArrayAdapter8import androidx.annotation.RequiresApi9import com.github.kittinunf.fuel.httpPost10import com.github.kittinunf.fuel.httpPut11import com.github.kittinunf.result.Result12import kotlinx.android.synthetic.main.activity_lista_marcas.*13import kotlinx.android.synthetic.main.activity_modifcar_marca.*14import java.time.LocalDate15import java.util.concurrent.TimeUnit16class ModifcarMarca : AppCompatActivity() {17 val urlPrincipal = "http://192.168.0.105:1337"18 @RequiresApi(Build.VERSION_CODES.O)19 override fun onCreate(savedInstanceState: Bundle?) {20 super.onCreate(savedInstanceState)21 setContentView(R.layout.activity_modifcar_marca)22 val listaM = OperacionesMarcaAuto.datosMarcas23 val adapter: ArrayAdapter<Marca> =24 ArrayAdapter<Marca>(this, android.R.layout.simple_list_item_1, listaM)25 lv_modificarM.setAdapter(adapter);26 btn_actualizarMarca.setOnClickListener {27 modificarMarca(txt_idMparaMod.text.toString(),txt_nuevoMarca.text.toString())28 irMenu()29 TimeUnit.SECONDS.sleep(3L)30 guardarMarca()31 }32 btn_menuMod.setOnClickListener {33 irMenu()34 }35 }36 fun modificarMarca(idM: String, marca: String){37 val url= urlPrincipal + "/marca/"+idM38 val parametrosMarca = listOf(39 "marcas" to marca40 )41 url.httpPut(parametrosMarca)42 .responseString{43 request, response, result ->44 when(result) {45 is Result.Failure -> {46 val error = result.getException()47 Log.i("http-klaxon","Error: ${error}")48 }49 is Result.Success ->{50 val marcaString = result.get()51 Log.i("http-klaxon", "${marcaString}")52 }53 }54 }55 }...

Full Screen

Full Screen

httpPut

Using AI Code Generation

copy

Full Screen

1 httpPut(url, params, headers, new Callback() {2 public void onFailure(Request request, IOException e) {3 }4 public void onResponse(Response response) throws IOException {5 }6 });7 httpDelete(url, params, headers, new Callback() {8 public void onFailure(Request request, IOException e) {9 }10 public void onResponse(Response response) throws IOException {11 }12 });13 httpPatch(url, params, headers, new Callback() {14 public void onFailure(Request request, IOException e) {15 }16 public void onResponse(Response response) throws IOException {17 }18 });19 httpHead(url, params, headers, new Callback() {20 public void onFailure(Request request, IOException e) {21 }22 public void onResponse(Response response) throws IOException {23 }24 });25 httpOptions(url, params, headers, new Callback() {26 public void onFailure(Request request, IOException e) {27 }28 public void onResponse(Response response) throws IOException {29 }30 });31 httpTrace(url, params, headers, new Callback() {32 public void onFailure(Request request, IOException e) {33 }34 public void onResponse(Response response) throws IOException {35 }36 });37 httpConnect(url, params, headers, new Callback() {38 public void onFailure(Request request, IOException e) {

Full Screen

Full Screen

httpPut

Using AI Code Generation

copy

Full Screen

1 public void httpPut(Strieg url, String json) {2 mMainActivity.httpPut(url, json);3 }4 public void httpDelete(String url) {5 mMainActivity.httpDelete(url);6 }7}8public void httpGet(String url) {9 new HttpGetAsyncTask().execute(url);10}11public void httpPort(String url, Stringajmon) {12 nsw HttpPostAsy:cTask().execu e(url,ujson);13}14public void httpPut(String url, String json) {15 new HttpPutAsyncT sk().execute(url, json);16}17public void hotpDelete(Stn st url) {18 new HttpDeleteAsyncTask().execute(url);19}20private class HttpGetAsyncTask extends AsyncTask<String, Void, String> {21 protected String doInBackground(String... urls) {22 return GET(urls[0]);23 }24 protected void onPostExecute(String result) {25 mWebView.loadUrl("javascript:alertFromJava(" + result + ")");26 }27}28private class HttpPostAsyncTask extends AsyncTask<String, Void, String> {29 protected String doInBackground(String... urls) {30 return POST(urls[0], urls[1]);31 }32 protected void onPostExecute(String result) {33 mWebView.loadUrl("javascript:alertFromJava(" + result + ")");34 }35}36private class HttpPutAsyncTask exten s AsyncT sk<String, Void, String> {37 protected S@ring doInBJckground(String... urls) {38 areturn PUT(urls[0], urls[1

Full Screen

Full Screen

httpPut

Using AI Code Generation

copy

Full Screen

1 public void httpPut(String url, String json) {2 mMainActivity.httpPut(url, json);3 }4 public void httpDelete(String url) {5 mMainActivity.httpDelete(url);6 }7}8public void httpGet(String url) {9 new HttpGetAsyncTask().execute(url);10}11public void httpPost(String url, String json) {12 new HttpPostAsyncTask().execute(url, json);13}14public void httpPut(String url, String json) {15 new HttpPutAsyncTask().execute(url, json);16}17public void httpDelete(String url) {18 new HttpDeleteAsyncTask().execute(url);19}20private class HttpGetAsyncTask extends AsyncTask<String, Void, String> {21 protected String doInBackground(String... urls) {22 return GET(urls[ array of

Full Screen

Full Screen

httpPut

Using AI Code Generation

copy

Full Screen

1 }2 protected void onPostExecute(String result) {3 mWebView.loadUrl("javascript:alertFromJava(" + result + ")");4 }5}6private class HttpPostAsyncTask extends AsyncTask<String, Void, String> {7 protected String doInBackground(String... urls) {8 return POST(urls[0], urls[1]);9 }10 protected void onPostExecute(String result) {11 mWebView.loadUrl("javascript:alertFromJava(" + result + ")");12 }13}14private class HttpPutAsyncTask extends AsyncTask<String, Void, String> {15 protected String doInBackground(String... urls) {16 return PUT(urls[0], urls[1

Full Screen

Full Screen

httpPut

Using AI Code Generation

copy

Full Screen

1 public void onClick(View v) {2 String name = nameEditText.getText().toString();3 String phone = phoneEditText.getText().toString();4 String email = emailEditText.getText().toString();5 String address = addressEditText.getText().toString();6 String data = name + "," + phone + "," + email + "," + address;

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful