Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Single item screen #1

Open
wants to merge 46 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
dc89f3e
Changed Oncreate component
Oct 10, 2023
d75ee74
Merge remote-tracking branch 'origin/barcode'
Oct 10, 2023
b9ed625
Get Items with user email and bind them to homeScreen cards in progress.
Liideli Oct 11, 2023
00c711b
Merge branch 'master' into singleItemScreen
Liideli Oct 11, 2023
4704e7f
Get Items with user email and bind them to homeScreen cards in progress.
Liideli Oct 11, 2023
ceff596
navigation
Oct 11, 2023
63d138b
Update and delate are now in the DAO, viewmodel and repository (Datab…
MattiaTraple Oct 11, 2023
9ac1cbc
Update and delate are now in the DAO, viewmodel and repository (Datab…
MattiaTraple Oct 11, 2023
6cb2efb
Changed navigation and added SingleItemScreen
Oct 11, 2023
001919e
Merge branch 'navigation' into singleItemScreen
MattiaTraple Oct 11, 2023
5384866
Navigation fixed, modified CameraScanViewModel initializing, some sty…
Liideli Oct 11, 2023
83ce684
Merge remote-tracking branch 'origin/singleItemScreen' into singleIte…
Liideli Oct 11, 2023
17a41e1
Merge latest updates on branch singleItemScreen.
Liideli Oct 11, 2023
feeb04b
Update and delate are now in the DAO, viewmodel and repository (Datab…
MattiaTraple Oct 12, 2023
47269a9
Update and delate are now in the DAO, viewmodel and repository (Datab…
MattiaTraple Oct 12, 2023
0090c1d
Merge remote-tracking branch 'origin/singleItemScreen' into singleIte…
MattiaTraple Oct 12, 2023
12cabbf
Added logout
Oct 12, 2023
1664d08
Navigation from ItemCard to clothesDetailScreen.
Liideli Oct 12, 2023
b7d5182
Roope modification
MattiaTraple Oct 12, 2023
d24a9c0
Merge remote-tracking branch 'origin/singleItemScreen' into singleIte…
MattiaTraple Oct 12, 2023
6b98e9b
delate is working
MattiaTraple Oct 12, 2023
48885a6
In progress.
Liideli Oct 12, 2023
19001c2
Delate doesn't work
MattiaTraple Oct 12, 2023
2fb3252
Merge remote-tracking branch 'origin/singleItemScreen' into singleIte…
MattiaTraple Oct 12, 2023
b4ae845
In progress Yes.
Liideli Oct 12, 2023
a8d0148
Delate doesn't work
MattiaTraple Oct 12, 2023
4da4b98
Merge remote-tracking branch 'origin/singleItemScreen' into singleIte…
MattiaTraple Oct 12, 2023
9afcde7
Addition
Oct 12, 2023
028f665
Merge remote-tracking branch 'origin/singleItemScreen' into singleIte…
Oct 12, 2023
9393038
Addition
Oct 12, 2023
955c203
Addition
Oct 12, 2023
1ca9041
Added icons.
Liideli Oct 12, 2023
1a0bcbb
Merge remote-tracking branch 'origin/singleItemScreen' into singleIte…
Liideli Oct 12, 2023
b338eed
Added icons.
Liideli Oct 12, 2023
323f8d1
Design
Oct 12, 2023
83cc3ba
Graphics adaptation
MattiaTraple Oct 12, 2023
1e7df24
Merge remote-tracking branch 'origin/singleItemScreen' into singleIte…
MattiaTraple Oct 12, 2023
de20b59
Merge remote-tracking branch 'origin/singleItemScreen' into singleIte…
Oct 12, 2023
869753f
Update
MattiaTraple Oct 12, 2023
b278f02
Merge branch 'singleItemScreen' of https://github.com/Liideli/MyClose…
MattiaTraple Oct 12, 2023
09beaff
This is the version with delete button. Modify button is not working …
Liideli Oct 12, 2023
8844e2f
Update- no delate
MattiaTraple Oct 12, 2023
59db7d2
Merge remote-tracking branch 'origin/deleteVersion' into singleItemSc…
MattiaTraple Oct 12, 2023
820c236
Update- no delate
MattiaTraple Oct 12, 2023
2736ef2
Update- no delate
MattiaTraple Oct 12, 2023
5c33a84
Update- no delate
MattiaTraple Oct 12, 2023
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
Binary file added AppOpen.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ dependencies {
implementation("androidx.compose.ui:ui-tooling-preview")
implementation("androidx.compose.material3:material3")
implementation("androidx.appcompat:appcompat:1.6.1")
implementation("androidx.compose.ui:ui-text-google-fonts:1.5.3")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
Expand Down
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

<application
android:name=".MyApplication"
android:screenOrientation="portrait"
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
Expand Down
Binary file added app/src/main/ic_launcher-playstore.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,19 @@ import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.util.Log
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.graphics.asImageBitmap
import androidx.compose.ui.unit.dp
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import java.io.InputStream
Expand All @@ -29,7 +34,8 @@ class ImgDisplay {
bitmap= showImg(url)?.asImageBitmap()
}
bitmap?.let { bitmap ->
Image(bitmap = bitmap, contentDescription = "downloaded picture")
Image(modifier = Modifier.size(300.dp)
.clip(RoundedCornerShape(16.dp)), bitmap = bitmap, contentDescription = "downloaded picture" )
}
}

Expand Down
48 changes: 44 additions & 4 deletions app/src/main/java/com/example/mycloset/App/LoginPreviewApp.kt
Original file line number Diff line number Diff line change
@@ -1,22 +1,37 @@
package com.example.mycloset.App

import androidx.camera.view.LifecycleCameraController
import androidx.compose.animation.Crossfade
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.lifecycle.viewmodel.compose.viewModel
import com.example.mycloset.AppViewModelProvider
import com.example.mycloset.BarcodeWorkingSet.CameraScanViewModel
import com.example.mycloset.DatabaseWorkingset.ProductViewModel
import com.example.mycloset.Views.HomeScreen
import com.example.mycloset.Views.LoginScreen
import com.example.mycloset.Views.MainScreen
import com.example.mycloset.Views.ProductScanView
import com.example.mycloset.Views.SignUpScreen
import com.example.mycloset.Views.SingleItemScreen
import com.example.mycloset.Views.UpdateSingleItem
import com.example.mycloset.navigation.LoginAppRouter
import com.example.mycloset.navigation.Screen


@Composable
fun LoginApp(){
fun LoginApp(cameraController: LifecycleCameraController){
val productViewModel: ProductViewModel = viewModel(factory = AppViewModelProvider.Factory)
// ViewModel for handling camera and barcode scanning logic
val viewModel: CameraScanViewModel = viewModel(factory = AppViewModelProvider.Factory)

Surface(modifier = Modifier.fillMaxSize(),
color = Color.White
) {
Crossfade(targetState = LoginAppRouter.currentScreen) { currentState ->
Crossfade(targetState = LoginAppRouter.currentScreen, label = "") { currentState ->
when(currentState.value){
is Screen.SignupScreen ->{
SignUpScreen()
Expand All @@ -25,10 +40,35 @@ fun LoginApp(){
LoginScreen()
}
is Screen.HomeScreen ->{
//HomeScreen()
HomeScreen(productViewModel)
}
is Screen.ProductScanView ->{
ProductScanView(
productViewModel,
barcodesFlow = viewModel.barcodesFlow,
cameraController,
torchEnabledFlow = viewModel.torchFlow,
onTorchButtonClicked = {
// Toggle torch status when the button is clicked
cameraController.enableTorch(!viewModel.torchFlow.value)
viewModel.updateTorchEnabled()
}
)
}
is Screen.MainScreen -> {
MainScreen()
}


is Screen.SingleItemScreen ->{
SingleItemScreen(productViewModel)
}
is Screen.UpdateSingleScreen->{
UpdateSingleItem(productViewModel)
}
}

}
}
}
}

6 changes: 6 additions & 0 deletions app/src/main/java/com/example/mycloset/AppContainer.kt
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package com.example.mycloset

import android.content.Context
import com.example.mycloset.DatabaseWorkingset.OfflineProductRepository
import com.example.mycloset.DatabaseWorkingset.ProductDatabase
import com.example.mycloset.DatabaseWorkingset.ProductRepository


/**
* App container for Dependency injection.
*/
interface AppContainer {
val appDatabase: ProductDatabase
val productRepository: ProductRepository
}

class AppDataContainer(private val context: Context) :
Expand All @@ -17,4 +20,7 @@ class AppDataContainer(private val context: Context) :
override val appDatabase: ProductDatabase by lazy {
ProductDatabase.getInstance(context)
}
override val productRepository: ProductRepository by lazy {
OfflineProductRepository(ProductDatabase.getInstance(context).productDao())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.lifecycle.ViewModelProvider.AndroidViewModelFactory
import androidx.lifecycle.viewmodel.CreationExtras
import androidx.lifecycle.viewmodel.initializer
import androidx.lifecycle.viewmodel.viewModelFactory
import com.example.mycloset.BarcodeWorkingSet.CameraScanViewModel
import com.example.mycloset.DatabaseWorkingset.ProductViewModel

/**
Expand All @@ -14,9 +15,13 @@ object AppViewModelProvider {
val Factory = viewModelFactory {
initializer {
ProductViewModel(
productDao = MyApplication().container.appDatabase.productDao()
productDao = MyApplication().container.appDatabase.productDao(),
productRepository = MyApplication().container.productRepository
)
}
addInitializer(CameraScanViewModel::class) {
CameraScanViewModel()
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/com/example/mycloset/BarcodeModel.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

data class BarcodeModel(var barcode: String)
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.example.mycloset.BarcodeWorkingSet
import com.example.mycloset.ApiWorkingSet.RetrofitObject

//
var APY_KEY:String="3nupb3et7t5lbqlhhhspyrh3si1wu0"
var APY_KEY:String="i4fwimwj7nx49wkp564w68s0xaf04q"

//class for using the barcode-lookup API
class BarcodeRepository{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.example.mycloset.DatabaseWorkingset

import androidx.room.Query
import kotlinx.coroutines.flow.Flow

class OfflineProductRepository(private val productDao: ProductDao) : ProductRepository {
override fun getAllProductsWithEmailStream(userEmail: String) = productDao.getProductsWithEmail(userEmail)

override fun getAllProductWithBarcodeStream(barcodeNumber: String) = productDao.getProductWithBarcode(barcodeNumber)

override suspend fun updateProductDetailsStream(product: ProductEntity) = productDao.updateProductDetails(product)

override suspend fun deleteProductStream(barcodeNumber: String) = productDao.deleteProduct(barcodeNumber)

//override fun getSingleProductStream(barcode:String,userEmail: String)=productDao.getSingleProduct(barcode,userEmail)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,29 @@ import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import com.example.mycloset.DatabaseWorkingset.ProductEntity
import androidx.room.Update
import kotlinx.coroutines.flow.Flow

@Dao
interface ProductDao {
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertProduct(product: ProductEntity)

// Get all products
@Query("SELECT * FROM products")
suspend fun getAllProducts(): List<ProductEntity>
fun getAllProducts(): Flow<List<ProductEntity>>

// Get products of logged in user
@Query("SELECT * from products WHERE userEmail = :userEmail")
fun getProductsWithEmail(userEmail: String): Flow<List<ProductEntity>>

@Query("SELECT * from products WHERE barcodeNumber=:barcodeNumber")
fun getProductWithBarcode(barcodeNumber: String): Flow<List<ProductEntity>>

@Update
suspend fun updateProductDetails(product: ProductEntity)

//@Query("DELETE FROM products WHERE barcodeNumber = :barcodeNumber")
@Query("DELETE FROM products WHERE barcodeNumber = :barcodeNumber")
suspend fun deleteProduct(barcodeNumber: String)
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import androidx.room.Room
import androidx.room.RoomDatabase


@Database(entities = [ProductEntity::class], version = 1, exportSchema = false)
@Database(entities = [ProductEntity::class], version = 3, exportSchema = false)
abstract class ProductDatabase : RoomDatabase() {
abstract fun productDao(): ProductDao

Expand All @@ -26,12 +26,4 @@ abstract class ProductDatabase : RoomDatabase() {
.build()
}
}
}

class DatabaseManager(context: Context) {
private val database = ProductDatabase.getInstance(context)

suspend fun insertProduct(product: ProductEntity) {
database.productDao().insertProduct(product)
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
package com.example.mycloset.DatabaseWorkingset

import androidx.room.Entity
import androidx.room.PrimaryKey

@Entity(tableName = "products")
@Entity(tableName = "products",primaryKeys = ["barcodeNumber", "userEmail"])
data class ProductEntity(
@PrimaryKey val barcodeNumber: String,
val barcodeNumber: String,
val userEmail: String,
val model: String,
val title: String,
val category: String,
val brand: String,
val color: String,
val material: String,
val size: String,
var model: String,
var title: String,
var category: String,
var brand: String,
var color: String,
var material: String,
var size: String,
val images: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.example.mycloset.DatabaseWorkingset

import kotlinx.coroutines.flow.Flow

// Repository that provides insert, update, delete, and retrieve of [Product] from a given data source.
interface ProductRepository {
fun getAllProductsWithEmailStream(userEmail: String): Flow<List<ProductEntity>>
fun getAllProductWithBarcodeStream(barcodeNumber: String): Flow<List<ProductEntity>>
suspend fun updateProductDetailsStream(product: ProductEntity)
suspend fun deleteProductStream(barcodeNumber: String)
}
Loading