NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

package com.example.kartasemar.activity;

import androidx.appcompat.app.AppCompatActivity;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.TextView;
import android.widget.Toast;

import com.example.kartasemar.Interface.ApiClient;
import com.example.kartasemar.Model.DefaultResponse;
import com.example.kartasemar.Model.TambahProduk;
import com.example.kartasemar.R;
import com.example.kartasemar.storage.SharedPrefManager;

public class MitraTambahProdukActivity extends AppCompatActivity implements View.OnClickListener {
EditText editText, editTextNamaProduk, editTextDeskripsi, editTextHarga, editTextJumlah;
TextView textView;
RadioButton rbRajut, rbBatik, rbDaurulang;

private int kategori = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_mitra_tambah);

editTextNamaProduk = findViewById(R.id.editTextEditMitraNamaProduk);
editTextDeskripsi = findViewById(R.id.editTextDeskripsi);
editTextHarga = findViewById(R.id.editTextHarga);
editTextJumlah = findViewById(R.id.editTextJumlah);

rbBatik = findViewById(R.id.radioButtonBatik);
rbRajut = findViewById(R.id.radioButtonRajut);
rbDaurulang = findViewById(R.id.radioButtonDaurulang);

rbBatik.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
kategori = 79;
}
});

rbRajut.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
kategori = 87;
}
});

rbDaurulang.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
kategori = 86;
}
});

editText = findViewById(R.id.editTextEditMitraNamaProduk);
textView = findViewById( R.id.textviewcount);
editText.addTextChangedListener(new TextWatcher() {

@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {

}

@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {

}

@Override
public void afterTextChanged(Editable editable) {
String currentText = editable.toString();
int currentLength = currentText.length();
textView.setText(currentLength + "/100");
}
});

findViewById(R.id.btn_tambahproduk).setOnClickListener(this);
findViewById(R.id.btn_batal).setOnClickListener(this);
}

/*@Override
protected void onStart() {
super.onStart();
if(SharedPrefManager.getInstance(this).isLoggedIn()){
Intent intent = new Intent(this, LoginMitra.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
}
}*/


private void tambahProduk() {
int user_id = 37;
String nama_produk = editTextNamaProduk.getText().toString().trim();
String deskripsi_produk = editTextDeskripsi.getText().toString().trim();
int sub_kategori_produk = 47;
int toko_produk = 15;
int ketersediaan_produk = 1;
int status_produk = 1;
String harga = editTextHarga.getText().toString().trim();
int harga_produk = Integer.parseInt(harga);
int berat_produk = 1000;
String jumlah = editTextHarga.getText().toString().trim();
int jumlah_produk = Integer.parseInt(jumlah);
String gambar_produk = "uploads/biru_putih.png";

if (nama_produk.isEmpty()) {
editTextNamaProduk.setError("Masa produk kamu gaada namanya?");
editTextNamaProduk.requestFocus();
return;
}
if (deskripsi_produk.isEmpty()) {
editTextDeskripsi.setError("Isiin deskripsi produknya dong");
editTextDeskripsi.requestFocus();
return;
}

/* if (harga_produk.isEmpty()) {
editTextHarga.setError("Produk kamu mau dijual gratis nih?");
editTextHarga.requestFocus();
return;
}
if (jumlah_produk.isEmpty()) {
editTextJumlah.setError("Ah kamu ga niat jualan");
editTextJumlah.requestFocus();
return;
} */

Call<TambahProduk> call = ApiClient
.getInstance()
.getApi()
.tambahProduk(user_id, nama_produk, deskripsi_produk, kategori, sub_kategori_produk, toko_produk,
harga_produk, berat_produk, jumlah_produk, ketersediaan_produk, status_produk, gambar_produk);

call.enqueue(new Callback<TambahProduk>() {
@Override
public void onResponse(Call<TambahProduk> call, Response<TambahProduk> response) {
if (response.code() == 201) {

TambahProduk dr = response.body();
Toast.makeText(MitraTambahProdukActivity.this, dr.getMessage(), Toast.LENGTH_LONG).show();

} else if (response.code() == 422) {
Toast.makeText(MitraTambahProdukActivity.this, "User already exist", Toast.LENGTH_LONG).show();
}
}

@Override
public void onFailure(Call<TambahProduk> call, Throwable t) {
Toast.makeText(MitraTambahProdukActivity.this, t.getMessage(), Toast.LENGTH_LONG).show();
}
});
}


@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_tambahproduk:
tambahProduk();

startActivity(new Intent(this, MitraActivity.class));

case R.id.btn_batal:

startActivity(new Intent(this, MitraActivity.class));

break;
}
}
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.