Professional Documents
Culture Documents
Setup Layout, Setup Retrofit, Pembuatan Detail Halaman, Custom Dialog, Halaman Login
Setup Layout, Setup Retrofit, Pembuatan Detail Halaman, Custom Dialog, Halaman Login
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<!--
android:shape
Keyword. Defines the type of shape. Valid values are:
rectangle : A rectangle that fills the containing View.
This is the default shape.
oval : An oval shape that fits the dimensions of the
containing View.
line : A horizontal line that spans the width of the
containing View. This
shape requires the <stroke> element to define the
width of the line.
ring : A ring shape.
-->
<shape android:shape="oval">
<solid android:color="#f3f3f3"/>
<corners android:radius="6dp" />
<stroke
android:width="4dp"
android:color="#fff" ></stroke>
<size android:width="50dp" android:height="50dp"/>
</shape>
</item>
</selector>
<RelativeLayout
android:layout_marginTop="6dp"
android:layout_marginBottom="6dp"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_marginTop="26dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<androidx.cardview.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/card_penulis"
app:cardCornerRadius="4dp"
app:cardElevation="0dp"
android:layout_width="match_parent"
android:layout_height="130dp"
app:cardBackgroundColor="#f3f3f3"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp">
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_marginTop="38dp"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_margin="6dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/tv_nama_anggota"
android:layout_marginTop="5dp"
android:gravity="center"
android:ellipsize="marquee"
android:maxLines="2"
android:layout_gravity="center"
android:textSize="16sp"
android:text="Nama"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="match_parent"
/>
<TextView
android:id="@+id/tv_posisi_anggota"
android:gravity="center"
android:ellipsize="marquee"
android:maxLines="2"
android:layout_gravity="center"
android:textSize="18sp"
android:text="loading.."
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="match_parent"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
<ImageView
android:background="@drawable/bg_circle_imageview"
android:layout_centerHorizontal="true"
android:padding="6dp"
android:src="@mipmap/ic_launcher"
android:id="@+id/img_anggota"
android:adjustViewBounds="true"
android:layout_width="60dp"
android:layout_height="60dp"
/>
</RelativeLayout>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.fragment.anggota.AnggotaFragment">
<ImageView
android:layout_width="match_parent"
android:layout_height="170dp"
android:src="@drawable/bg_half_circle" />
<TextView
android:fontFamily="@font/poppinsbold"
android:id="@+id/tv_welcome"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:text="Selamat Datang"
android:textColor="@color/warnaPutih"
android:textSize="20sp"
android:textStyle="bold" />
<androidx.recyclerview.widget.RecyclerView
android:layout_below="@+id/tv_welcome"
android:layout_margin="16dp"
android:id="@+id/rv_anggota"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<ProgressBar
android:visibility="gone"
android:layout_centerInParent="true"
android:id="@+id/progress_circular_anggota"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout>
rv_anggota.layoutManager = GridLayoutManager(activity, 2)
getData()
if (response?.isSuccessful!!){
progress_circular_anggota.visibility = View.GONE
//tampilkan data nya dibagian ini
val list = ArrayList<ResponseData>()
var dataPosisi = response.body().size
//perulangan untuk data
for (posisi in 0 until dataPosisi){
var dataLooping = response.body().get(posisi)
list.add(dataLooping)
}
var adapterAnggota = AdapterAnggota(list)
rv_anggota.adapter = adapterAnggota
} else{
progress_circular_anggota.visibility = View.GONE
Toast.makeText(activity,"Gagal dapatkan data",
Toast.LENGTH_LONG).show()
}
}
} )
}
android:usesCleartextTraffic="true"
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int):
AdapterAnggota.MyHolder {
val view =
LayoutInflater.from(parent.context).inflate(R.layout.item_anggota,parent,false
)
return MyHolder(view)
}
holder.itemView.tv_nama_anggota.text = list[position].nama
holder.itemView.tv_posisi_anggota.text = list[position].jabatan
holder.itemView.setOnClickListener {
val intent = Intent(holder.itemView.context,
DetailAnggotaActivity::class.java)
intent.putExtra("NAMA",list[position].nama)
intent.putExtra("JK",list[position].jk)
intent.putExtra("STATUS",list[position].status)
intent.putExtra("JABATAN",list[position].jabatan)
holder.itemView.context.startActivity(intent)
}
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent"
android:layout_margin="16dp"
tools:context=".ui.activity.detail_anggota.DetailAnggotaActivity">
<TextView
android:textSize="18sp"
android:id="@+id/tv_nama_anggota_detail"
android:text="Nama"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/tv_kelamin_anggota_detail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Jenis Kelamin"
android:textSize="18sp" />
<TextView
android:textSize="18sp"
android:id="@+id/tv_status_anggota_detail"
android:text="Status"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<TextView
android:textSize="18sp"
android:id="@+id/tv_posisi_anggota_detail"
android:text="Posisi"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
<activity android:name=".ui.activity.detail_anggota.DetailAnggotaActivity"
android:theme="@style/AppTheme"
></activity>
13. Membuat Layout item_view_login.xml
Klik kanan Layout -> klik new -> Klik Layout Resource File -> tulis nama “item_view_login”
Lengkapi kode xml pada file item_view_login.xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_margin="16dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:layout_marginRight="16dp"
android:layout_marginLeft="16dp"
android:id="@+id/edt_username"
android:hint="Username"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<EditText
android:layout_marginRight="16dp"
android:layout_marginLeft="16dp"
android:id="@+id/edt_pass"
android:hint="Password"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<LinearLayout
android:layout_marginBottom="40dp"
android:layout_marginRight="16dp"
android:layout_marginLeft="16dp"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/btn_cancel"
android:layout_margin="10dp"
android:layout_weight="1"
android:textColor="#fff"
android:background="#E91E63"
android:text="Cancel"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<Button
android:id="@+id/btn_login"
android:layout_margin="10dp"
android:layout_weight="1"
android:textColor="#fff"
android:background="#2196F3"
android:text="Login"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>
<androidx.recyclerview.widget.RecyclerView
android:layout_margin="16dp"
android:id="@+id/rv_anggota_admin"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<ProgressBar
android:visibility="gone"
android:layout_centerInParent="true"
android:id="@+id/progress_circular_anggota_admin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout>
rv_anggota_admin.layoutManager = LinearLayoutManager(this)
adminLogin()
//getData()
//onclcik button
mDialogView.btn_login.setOnClickListener {
//logic login
var userName = mDialogView.edt_username.text.toString()
var pass = mDialogView.edt_pass.text.toString()
if(userName.isEmpty()){
Toast.makeText(this,"Data tidak bisa kosong",
Toast.LENGTH_LONG).show()
}
else if(pass.isEmpty()){
Toast.makeText(this,"Data tidak bisa kosong",
Toast.LENGTH_LONG).show()
} else{
if (userName.equals("admin") && pass.equals("admin")){
Toast.makeText(this,"Berhasil Login",
Toast.LENGTH_LONG).show()
// UserSession(this).makeSession("admin")
mAlerDialog.dismiss()
} else{
Toast.makeText(this,"Gagal Login",
Toast.LENGTH_LONG).show()
}
}
}
mDialogView.btn_cancel.setOnClickListener {
finish()
}
//validasi untuk cek kalo sudah login
// if (UserSession(this).hasSession()){
// mAlerDialog.dismiss()
// }
}
}
android:id="@+id/img_setting"
img_setting.setOn.javaClickListener {
startActivity(Intent(activity, AdminActivity::class.java))
}