Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 123 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ plugins {
android {
namespace = "com.example.create_account"
compileSdk = 35
buildToolsVersion = "35.0.0" // Build Tools sürümü eklendi

defaultConfig {
applicationId = "com.example.create_account"
Expand All @@ -31,12 +32,11 @@ android {
targetCompatibility = JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = "11"
jvmTarget = "11" // JVM hedefi doğru ve Gradle ile uyumlu
}
}

dependencies {

implementation(libs.androidx.core.ktx)
implementation(libs.androidx.appcompat)
implementation(libs.material)
Expand All @@ -45,4 +45,4 @@ dependencies {
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.espresso.core)
}
}
11 changes: 7 additions & 4 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@
android:theme="@style/Theme.Create_Account"
tools:targetApi="31">

<!-- MainActivity tanımı -->
<!-- RecipeActivity tanımı -->
<activity
android:name=".RecipeActivity"
android:exported="false" />

<!-- MainActivity tanımı (giriş ekranı) -->
<activity
android:name=".MainActivity"
android:exported="true">
Expand All @@ -27,13 +32,11 @@
</intent-filter>
</activity>

<!-- MainActivity2 tanımı -->
<!-- MainActivity2 tanımı (kayıt ekranı) -->
<activity
android:name=".MainActivity2"
android:exported="true" />



</application>

</manifest>
4 changes: 3 additions & 1 deletion app/src/main/java/com/example/create_account/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ class MainActivity : AppCompatActivity() {
if (isValid) {
if (credentialsManager.isHardcodedCredentials(email, password)) {
Toast.makeText(this, "Login successful!", Toast.LENGTH_SHORT).show()
val intent = Intent(this, MainActivity2::class.java)

// Geçişi RecipeActivity'ye yönlendir
val intent = Intent(this, RecipeActivity::class.java)
startActivity(intent)
} else {
Toast.makeText(this, "Invalid credentials!", Toast.LENGTH_SHORT).show()
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/java/com/example/create_account/Recipe.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.example.create_account

data class Recipe(
val id: Int,
val name: String,
val imageResId: Int,
val description: String
)
67 changes: 67 additions & 0 deletions app/src/main/java/com/example/create_account/RecipeActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.example.create_account

import android.content.Intent
import android.os.Bundle
import android.widget.Button
import android.widget.Toast
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.SearchView // Doğru sınıfı import ettik
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import kotlinx.coroutines.flow.collectLatest

class RecipeActivity : AppCompatActivity() {

private val viewModel: RecipeViewModel by viewModels()
private lateinit var recipeAdapter: RecipeAdapter

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

// RecyclerView'i bul ve ayarla
val recyclerView = findViewById<RecyclerView>(R.id.recipeRecyclerView)
recipeAdapter = RecipeAdapter(
emptyList(),
onItemClick = { recipe ->
Toast.makeText(this, "Clicked: ${recipe.name}", Toast.LENGTH_SHORT).show()
},
onButtonClick = { recipe ->
Toast.makeText(this, "Liked: ${recipe.name}", Toast.LENGTH_SHORT).show()
}
)
recyclerView.layoutManager = LinearLayoutManager(this)
recyclerView.adapter = recipeAdapter

// SearchView'i ayarla
val searchView = findViewById<SearchView>(R.id.recipeSearchView) // Doğru sınıfı kullandık
searchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener {
override fun onQueryTextSubmit(query: String?): Boolean {
return true
}

override fun onQueryTextChange(newText: String?): Boolean {
viewModel.searchRecipes(newText.orEmpty())
return true
}
})

// ViewModel'den filtrelenmiş tarifleri gözlemle
lifecycleScope.launchWhenStarted {
viewModel.recipesFlow.collectLatest { recipes ->
recipeAdapter.updateRecipes(recipes)
}
}

// Çıkış butonu ayarı
val logoutButton = findViewById<Button>(R.id.logoutButton)
logoutButton.setOnClickListener {
// MainActivity'ye yönlendir
val intent = Intent(this, MainActivity::class.java)
startActivity(intent)
finish() // Bu activity'yi kapat
}
}
}
48 changes: 48 additions & 0 deletions app/src/main/java/com/example/create_account/RecipeAdapter.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.example.create_account

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView

class RecipeAdapter(
private var recipes: List<Recipe>, // Listeyi güncellenebilir yapmak için "var" olarak değiştirildi
private val onItemClick: (Recipe) -> Unit,
private val onButtonClick: (Recipe) -> Unit
) : RecyclerView.Adapter<RecipeAdapter.RecipeViewHolder>() {

// ViewHolder tanımı
inner class RecipeViewHolder(view: View) : RecyclerView.ViewHolder(view) {
val image: ImageView = view.findViewById(R.id.recipeImageView)
val name: TextView = view.findViewById(R.id.recipeNameTextView)
val likeButton: Button = view.findViewById(R.id.likeButton)
}

// ViewHolder oluşturma
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecipeViewHolder {
val view = LayoutInflater.from(parent.context)
.inflate(R.layout.item_recipe, parent, false)
return RecipeViewHolder(view)
}

// ViewHolder'ı bağlama
override fun onBindViewHolder(holder: RecipeViewHolder, position: Int) {
val recipe = recipes[position]
holder.image.setImageResource(recipe.imageResId) // Resmi ayarla
holder.name.text = recipe.name // İsmi ayarla
holder.itemView.setOnClickListener { onItemClick(recipe) } // Tıklama olayı
holder.likeButton.setOnClickListener { onButtonClick(recipe) } // Buton tıklama olayı
}

// Listedeki eleman sayısını döndür
override fun getItemCount(): Int = recipes.size

// Listeyi güncellemek için bir fonksiyon
fun updateRecipes(newRecipes: List<Recipe>) {
recipes = newRecipes // Yeni listeyle güncelle
notifyDataSetChanged() // Adapter'e değişiklik olduğunu bildir
}
}
35 changes: 35 additions & 0 deletions app/src/main/java/com/example/create_account/RecipeViewModel.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.example.create_account

import androidx.lifecycle.ViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.update

class RecipeViewModel : ViewModel() {

// Tüm tarifler
private val allRecipes = listOf(
Recipe(1, "Pasta", R.drawable.pasta_image, "Delicious pasta with creamy sauce."),
Recipe(2, "Burger", R.drawable.burger_image, "Juicy beef burger with cheese."),
Recipe(3, "Pizza", R.drawable.pizza_image, "Classic Margherita pizza.")
)

// Filtrelenmiş tarifler için StateFlow
private val _recipesFlow = MutableStateFlow(allRecipes)
val recipesFlow: StateFlow<List<Recipe>> = _recipesFlow

// Arama sorgusunu işleyen fonksiyon
fun searchRecipes(query: String) {
if (query.length < 3) {
// Sorgu kısa ise tüm tarifleri göster
_recipesFlow.update { allRecipes }
} else {
// Sorguya uygun tarifleri filtrele
val filteredRecipes = allRecipes.filter { recipe ->
recipe.name.contains(query, ignoreCase = true) ||
recipe.description.contains(query, ignoreCase = true)
}
_recipesFlow.update { filteredRecipes }
}
}
}
Binary file added app/src/main/res/drawable/burger_image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/pasta_image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/pizza_image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/recipe_image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions app/src/main/res/layout/activitiy_main2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,14 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/registerButton" />

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recipeRecyclerView"
android:layout_width="47dp"
android:layout_height="154dp"
android:layout_marginStart="16dp"
android:layout_marginTop="68dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />


</androidx.constraintlayout.widget.ConstraintLayout>
4 changes: 4 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,8 @@
app:layout_constraintStart_toEndOf="@+id/newMemberText"
app:layout_constraintTop_toBottomOf="@+id/proceedButton" />





</androidx.constraintlayout.widget.ConstraintLayout>
Loading