Skip to content
Draft
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
17 changes: 15 additions & 2 deletions inventory-app/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,13 @@ android {
viewBinding true
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

kotlinOptions {
jvmTarget = '17'
jvmTarget = '1.8'
}
}

Expand All @@ -41,15 +46,23 @@ dependencies {

implementation "com.squareup.okhttp3:okhttp:4.12.0"
implementation "com.squareup.retrofit2:retrofit:2.11.0"
implementation "com.squareup.retrofit2:converter-gson:2.11.0"

implementation "org.apache.poi:poi-ooxml-lite:5.2.5"
// Apache POI for Excel and Streaming Reader
implementation "org.apache.poi:poi:5.2.5"
implementation "org.apache.poi:poi-ooxml:5.2.5"
// Using excel-streaming-reader for memory efficiency (batch processing of large files)
implementation "com.github.pjfanning:excel-streaming-reader:4.2.1"

implementation "com.journeyapps:zxing-android-embedded:4.3.0"
implementation "com.google.zxing:core:3.5.3"

implementation "com.google.dagger:hilt-android:2.51"
kapt "com.google.dagger:hilt-compiler:2.51"

implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.7.0"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.7.0"
implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.7.0"
implementation "androidx.activity:activity-ktx:1.9.0"
implementation "androidx.fragment:fragment-ktx:1.6.2"
}
29 changes: 23 additions & 6 deletions inventory-app/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,21 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.inventory">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />

<application
android:name=".InventoryApplication"
android:allowBackup="true"
android:label="@string/app_name"
android:supportsRtl="true">
<activity
android:name="com.example.inventory.ui.settings.SettingsActivity"
android:exported="false" />
android:label="Inventory App"
android:supportsRtl="true"
android:theme="@style/Theme.AppCompat.Light.DarkActionBar"
tools:replace="android:theme">

<activity
android:name="com.example.inventory.ui.MainActivity"
android:name=".ui.main.MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity
android:name=".ui.settings.SettingsActivity"
android:exported="false"
android:parentActivityName=".ui.main.MainActivity"/>

<activity
android:name="com.journeyapps.barcodescanner.CaptureActivity"
android:screenOrientation="fullSensor"
tools:replace="android:screenOrientation" />

</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.example.inventory

import android.app.Application
import dagger.hilt.android.HiltAndroidApp

@HiltAndroidApp
class InventoryApplication : Application()
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package com.example.inventory.data

import androidx.room.Database
import androidx.room.RoomDatabase
import com.example.inventory.data.dao.InventoryDao
import com.example.inventory.data.entity.Item
import com.example.inventory.data.entity.WarehouseStock

@Database(entities = [Item::class, WarehouseStock::class], version = 1)
@Database(entities = [Item::class, WarehouseStock::class], version = 1, exportSchema = false)
abstract class AppDatabase : RoomDatabase() {
abstract fun itemDao(): ItemDao
abstract fun warehouseStockDao(): WarehouseStockDao
abstract fun inventoryDao(): InventoryDao
}
14 changes: 0 additions & 14 deletions inventory-app/app/src/main/java/com/example/inventory/data/Item.kt

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.example.inventory.data.api

import okhttp3.ResponseBody
import retrofit2.Response
import retrofit2.http.GET
import retrofit2.http.Streaming
import retrofit2.http.Url

interface DownloadService {
@Streaming
@GET
suspend fun downloadFile(@Url url: String): Response<ResponseBody>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.example.inventory.data.dao

import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Transaction
import com.example.inventory.data.entity.Item
import com.example.inventory.data.entity.WarehouseStock

@Dao
interface InventoryDao {

@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertItems(items: List<Item>): List<Long>

@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertStocks(stocks: List<WarehouseStock>)

@Query("SELECT * FROM items WHERE code = :code LIMIT 1")
suspend fun getItemByCode(code: String): Item?

@Query("SELECT * FROM warehouse_stocks WHERE itemId = :itemId AND quantity > 0")
suspend fun getStocksByItemId(itemId: Long): List<WarehouseStock>

@Query("DELETE FROM items")
suspend fun clearAllItems()

@Query("DELETE FROM warehouse_stocks")
suspend fun clearAllStocks()

@Transaction
suspend fun clearAndInsertBatch(items: List<Item>, stocks: Map<String, List<WarehouseStock>>) {
// This method is tricky because we need IDs for stocks.
// It's better to handle logic in Repository to insert items, get IDs, then insert stocks.
// But for batch processing, we might want to do it differently.
// Actually, if we use code as a reference in stock it might be easier but requirement says:
// "Item (id, code, name, price) and WarehouseStock (itemId, warehouseName, quantity)"

// So we will just provide basic insert methods and handle logic in repository/usecase.
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.example.inventory.data.entity

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

@Entity(
tableName = "items",
indices = [Index(value = ["code"], unique = true)]
)
data class Item(
@PrimaryKey(autoGenerate = true)
val id: Long = 0,
val code: String,
val name: String,
val price: Double
)
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.example.inventory.data
package com.example.inventory.data.entity

import androidx.room.Entity
import androidx.room.ForeignKey
import androidx.room.Index
import androidx.room.PrimaryKey

@Entity(
tableName = "warehouse_stock",
primaryKeys = ["itemId", "warehouseName"],
tableName = "warehouse_stocks",
foreignKeys = [
ForeignKey(
entity = Item::class,
Expand All @@ -15,9 +15,11 @@ import androidx.room.Index
onDelete = ForeignKey.CASCADE
)
],
indices = [Index("itemId"), Index("warehouseName")]
indices = [Index(value = ["itemId"])]
)
data class WarehouseStock(
@PrimaryKey(autoGenerate = true)
val id: Long = 0,
val itemId: Long,
val warehouseName: String,
val quantity: Int
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.example.inventory.di

import android.content.Context
import androidx.room.Room
import com.example.inventory.data.AppDatabase
import com.example.inventory.data.dao.InventoryDao
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
object DatabaseModule {

@Provides
@Singleton
fun provideDatabase(@ApplicationContext context: Context): AppDatabase {
return Room.databaseBuilder(
context,
AppDatabase::class.java,
"inventory_db"
).fallbackToDestructiveMigration().build()
}

@Provides
fun provideInventoryDao(database: AppDatabase): InventoryDao {
return database.inventoryDao()
}
}
Loading