Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 8

Nama : Agustinus Marianto keraf

Nim : 20182205126
Kls : TI.65

1. Script Android Manifest


package com.stimikakba.Agustinus_20182205126.mid_pemrog_mobile
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.widget.Toast
import androidx.recyclerview.widget.GridLayoutManager
import com.google.gson.Gson
import kotlinx.android.synthetic.main.activity_main.*
import retrofit2.Call
import retrofit2.Response

class MainActivity : AppCompatActivity() {


override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

//set RecycLerview Layoumanager


rv_news.layoutManager = GridLayoutManager(this,1)
getData()
}
private fun getData() {
ApiRetrofit.create().getNews("1Si0UVIA3uLLQ-
gkioN_mPBnv0owXS0qRvYEbwv8GdEU", "Sheet1")
.enqueue(object : retrofit2.Callback<ResponseNews> {
override fun onResponse(call: Call<ResponseNews>, response:
Response<ResponseNews>) {
//Respon Sukses
Log.e("TAG", "Sukses Terima Data $
{Gson().toJson(response.body()?.data)}")
val adapter = AdapterNews(response.body()?.data as
ArrayList<DataItem>)
rv_news.adapter = adapter
adapter.notifyDataSetChanged()
}

override fun onFailure(call: Call<ResponseNews>, t:


Throwable) {
//Respon Error
Toast.makeText(this@MainActivity,"Error Terima Data",
Toast.LENGTH_LONG).show()
}
})
}
}

2. Script Adapter New


package com.stimikakba.Agustinus_20182205126.mid_pemrog_mobile

import android.content.Intent
import android.text.Layout
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.view.menu.ActionMenuItemView
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import kotlinx.android.synthetic.main.item_news.view.*

class AdapterNews (val list: ArrayList<DataItem>) :


RecyclerView.Adapter<AdapterNews.MyHolder>()
{
inner class MyHolder (itemView: View) :
RecyclerView.ViewHolder(itemView){

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int):


AdapterNews.MyHolder {
val view =
LayoutInflater.from(parent.context).inflate(R.layout.item_news, parent,
false)
return MyHolder(view)
}

override fun onBindViewHolder(holder: AdapterNews.MyHolder, position:


Int) {
holder.itemView.tv_judul.text = list[position].namaBerita

Glide.with(holder.itemView.context)
.load(list[position].urlImage)
.into(holder.itemView.img_news)

holder.itemView.setOnClickListener {
val intent = Intent(holder.itemView.context,
DetailActivity::class.java)
intent.putExtra("JUDUL",list[position].namaBerita)
intent.putExtra("DETAIL", list[position].isiBerita)
intent.putExtra("IMG", list[position].urlImage)

holder.itemView.context.startActivity(intent)
}
}

override fun getItemCount(): Int {


return list.size
}
}

3. Script ApiRetrofit
package com.stmikakba. Agustinus_20182205126.mid_pemrog_mobile

import com.bumptech.glide.load.model.stream.BaseGlideUrlLoader
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import retrofit2.create
import java.util.concurrent.TimeUnit

class ApiRetrofit {
companion object {

fun create(): ApiService {


val
BASEURL="https://script.google.com/macros/s/AKfycbzctxBEOf7kp94IBYM0GVQOmIY
VgAiTScj_6iKh9ITGh8m2MRLp/"
val interceptor = HttpLoggingInterceptor()
interceptor.level = HttpLoggingInterceptor.Level.BODY

val httpClient = OkHttpClient.Builder()


.connectTimeout(60, TimeUnit.SECONDS)
.readTimeout(60L, TimeUnit.SECONDS)
.writeTimeout(60L, TimeUnit.SECONDS)
.addInterceptor(interceptor)
.build()

val retrofit = Retrofit.Builder()


.addConverterFactory(GsonConverterFactory.create())
.baseUrl(BASEURL)
.client(httpClient)
.build()
return retrofit.create(ApiService::class.java)
}
}
}

4. Script Apiservice
package com.stmikakba.Agustinus_20182205126.mid_pemrog_mobile

import retrofit2.Call
import retrofit2.http.GET
import retrofit2.http.Query

interface ApiService {
@GET("exec")
fun getNews (@Query("id") id : String,
@Query("sheet") sheet : String)
: Call<ResponseNews>
}

5. Script DataItem
package com.stmikakba. Agustinus_20182205126.mid_pemrog_mobile

import com.google.gson.annotations.SerializedName

data class DataItem(

@field:SerializedName("")
val jsonMember: String? = null,

@field:SerializedName("nama_berita")
val namaBerita: String? = null,
@field:SerializedName("keterangan")
val keterangan: String? = null,

@field:SerializedName("sumber")
val sumber: String? = null,

@field:SerializedName("tanggal")
val tanggal: String? = null,

@field:SerializedName("timestamp")
val timestamp: String? = null,

@field:SerializedName("isi_berita")
val isiBerita: String? = null,

@field:SerializedName("url_image")
val urlImage: String? = null
)

6. Script DetailActivity
package com.stmikakba. Agustinus_20182205126.mid_pemrog_mobile

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.webkit.WebChromeClient
import com.bumptech.glide.Glide
import kotlinx.android.synthetic.main.activity_detail.*
import kotlinx.android.synthetic.main.item_news.*
import kotlinx.android.synthetic.main.item_news.img_news
import kotlinx.android.synthetic.main.item_news.tv_judul

class DetailActivity : AppCompatActivity() {


override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_detail)

tv_judul.text = intent.getStringExtra("JUDUL")
val img = intent.getStringExtra("IMG")

Glide.with(this).load(img).into(img_news)
web.webChromeClient = WebChromeClient()
web.settings.javaScriptEnabled = true
web.loadData(intent.getStringExtra("DETAIL").toString(),
"text/html", "UTF-8")
}
}

7. Script Response New


package com.stmikakba. Agustinus_20182205126.mid_pemrog_mobile

import com.google.gson.annotations.SerializedName

data class ResponseNews(

@field:SerializedName("data")
val data: List<DataItem?>? = null,
@field:SerializedName("status")
val status: String? = null
)

8. Spalsh Screen Aktivity


package com.stmikakba. Agustinus_20182205126.mid_pemrog_mobile

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.os.Handler

class SplashScreenActivity : AppCompatActivity() {


override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_splash_screen)

Handler().postDelayed({
//pindah activity
startActivity(Intent(this, MainActivity::class.java))
},4000)
}
}

9. Script Activity_Main
<?xml version="1.0" encoding="utf-8"?>
<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:layout_height="match_parent"
tools:context=".MainActivity">

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_news"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

</LinearLayout>

10. Script Activity_Detail


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_margin="16dp"
android:layout_width="match_parent"
android:layout_height="match_parent">

<ImageView
android:id="@+id/img_news"
android:scaleType="centerCrop"
android:src="@mipmap/ic_launcher"
android:layout_width="match_parent"
android:layout_height="200dp"/>
<TextView
android:id="@+id/tv_judul"
android:gravity="center"
android:textColor="#fff"
android:textStyle="bold"
android:background="#6A000000"
android:layout_below="@+id/img_news"
android:scrollbarSize="16sp"
android:text="Judul"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>

<WebView
android:id="@+id/web"
android:layout_below="@+id/tv_judul"
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>

</RelativeLayout>

11. Script Spalsh_screen


<?xml version="1.0" encoding="utf-8"?>
<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:layout_height="match_parent"
android:gravity="center"
android:background="@color/purple_200"
tools:context=".SplashScreenActivity">

<TextView
android:text="SELAMAT DATANG"
android:textColor="#fff"
android:textSize="20sp"
android:gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>

</LinearLayout>

12. Script Item_New


13. <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_margin="16dp"
android:layout_width="match_parent"
android:layout_height="220dp">

<ImageView
android:id="@+id/img_news"
android:scaleType="centerCrop"
android:src="@mipmap/ic_launcher"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<TextView
android:id="@+id/tv_judul"
android:gravity="center"
android:textColor="#fff"
android:textStyle="bold"
android:background="#6A000000"
android:layout_alignParentBottom="true"
android:scrollbarSize="16sp"
android:text="Judul"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>

</RelativeLayout>

Hasil Runing Program

You might also like