Skip to content

Instantly share code, notes, and snippets.

import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
class FoodAdapter : RecyclerView.Adapter<FoodViewHolder>() {
private val items = mutableListOf<Food>()
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): FoodViewHolder {
return FoodViewHolder.create(parent)
}
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import kotlinx.android.synthetic.main.item_food.view.*
class FoodViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
private val menuTextView = itemView.itemFoodMenu
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/itemFoodMenu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.core:core-ktx:1.2.0'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8
}
class MainActivity : AppCompatActivity() {
private val service = RetrofitClient.getUniService()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
GlobalScope.launch(Dispatchers.IO) {
class RetrofitClient {
companion object {
private var uniService: UniService? = null
fun getUniService(): UniService {
if (uniService == null) {
uniService = Retrofit.Builder()
.baseUrl("https://service-cms.istanbul.edu.tr/api/webclient/")
data class Food(
@SerializedName("tarih") val date: String?,
@SerializedName("menu") val menu: String?,
@SerializedName("kalori") val calorie: String?
)
data class FoodItems(
@SerializedName("items") val items: List<Food>?,
@SerializedName("kahvalti") val breakfast: List<Food>?,
@SerializedName("ogle") val lunch: List<Food>?,
@SerializedName("aksam") val dinner: List<Food>?,
@SerializedName("kumanya") val stores: List<Food>?,
@SerializedName("diyet") val diet: List<Food>?,
@SerializedName("vegan") val vegan: List<Food>?,
@SerializedName("cocuk") val child: List<Food>?
)
interface UniService {
@GET("f_getData?siteKey=5B765FE7627B4BCEA73B723C5523789E&EID=4E00590053005F006D004C00500035005500720059003100")
suspend fun getFoodList(): FoodResponse
}