From 0ec8c1ce45547e544bd34ba120cd8992202cf239 Mon Sep 17 00:00:00 2001 From: leca Date: Sat, 14 Sep 2024 23:54:10 +0300 Subject: [PATCH] first commit --- .gitignore | 150 ++++++++++++++ .idea/.gitignore | 3 + .idea/compiler.xml | 6 + .idea/deploymentTargetSelector.xml | 10 + .idea/gradle.xml | 18 ++ .idea/kotlinc.xml | 6 + .idea/misc.xml | 9 + .idea/vcs.xml | 6 + app/.gitignore | 1 + app/build.gradle.kts | 58 ++++++ app/proguard-rules.pro | 21 ++ .../ExampleInstrumentedTest.kt | 24 +++ app/src/main/AndroidManifest.xml | 32 +++ .../MainActivity.kt | 61 ++++++ .../barcodescannerforemployees/Parser.kt | 44 +++++ .../barcodescannerforemployees/Product.kt | 7 + .../ProductContract.kt | 12 ++ .../barcodescannerforemployees/Requester.kt | 28 +++ .../SecondFragment.kt | 44 +++++ .../StorageController.kt | 28 +++ .../addProductFragment.kt | 63 ++++++ .../shelfContract.kt | 11 ++ .../res/drawable/ic_launcher_background.xml | 74 +++++++ .../res/drawable/ic_launcher_foreground.xml | 31 +++ app/src/main/res/layout/activity_main.xml | 35 ++++ .../main/res/layout/add_product_fragment.xml | 33 ++++ app/src/main/res/layout/content_main.xml | 20 ++ app/src/main/res/layout/fragment_second.xml | 34 ++++ app/src/main/res/menu/menu_main.xml | 9 + .../res/mipmap-anydpi-v26/ic_launcher.xml | 6 + .../mipmap-anydpi-v26/ic_launcher_round.xml | 6 + app/src/main/res/mipmap-hdpi/ic_launcher.webp | Bin 0 -> 1404 bytes .../res/mipmap-hdpi/ic_launcher_round.webp | Bin 0 -> 2898 bytes app/src/main/res/mipmap-mdpi/ic_launcher.webp | Bin 0 -> 982 bytes .../res/mipmap-mdpi/ic_launcher_round.webp | Bin 0 -> 1772 bytes .../main/res/mipmap-xhdpi/ic_launcher.webp | Bin 0 -> 1900 bytes .../res/mipmap-xhdpi/ic_launcher_round.webp | Bin 0 -> 3918 bytes .../main/res/mipmap-xxhdpi/ic_launcher.webp | Bin 0 -> 2884 bytes .../res/mipmap-xxhdpi/ic_launcher_round.webp | Bin 0 -> 5914 bytes .../main/res/mipmap-xxxhdpi/ic_launcher.webp | Bin 0 -> 3844 bytes .../res/mipmap-xxxhdpi/ic_launcher_round.webp | Bin 0 -> 7778 bytes app/src/main/res/navigation/nav_graph.xml | 28 +++ app/src/main/res/values-land/dimens.xml | 3 + app/src/main/res/values-night/themes.xml | 7 + app/src/main/res/values-v23/themes.xml | 8 + app/src/main/res/values-w1240dp/dimens.xml | 3 + app/src/main/res/values-w600dp/dimens.xml | 3 + app/src/main/res/values/colors.xml | 5 + app/src/main/res/values/dimens.xml | 3 + app/src/main/res/values/strings.xml | 10 + app/src/main/res/values/themes.xml | 9 + app/src/main/res/xml/backup_rules.xml | 14 ++ .../main/res/xml/data_extraction_rules.xml | 20 ++ .../ExampleUnitTest.kt | 17 ++ build.gradle.kts | 5 + gradle.properties | 23 +++ gradle/libs.versions.toml | 32 +++ gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 59203 bytes gradle/wrapper/gradle-wrapper.properties | 6 + gradlew | 185 ++++++++++++++++++ gradlew.bat | 89 +++++++++ settings.gradle.kts | 23 +++ 62 files changed, 1383 insertions(+) create mode 100644 .gitignore create mode 100644 .idea/.gitignore create mode 100644 .idea/compiler.xml create mode 100644 .idea/deploymentTargetSelector.xml create mode 100644 .idea/gradle.xml create mode 100644 .idea/kotlinc.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/vcs.xml create mode 100644 app/.gitignore create mode 100644 app/build.gradle.kts create mode 100644 app/proguard-rules.pro create mode 100644 app/src/androidTest/java/org/foxarmy/barcodescannerforemployees/ExampleInstrumentedTest.kt create mode 100644 app/src/main/AndroidManifest.xml create mode 100644 app/src/main/java/org/foxarmy/barcodescannerforemployees/MainActivity.kt create mode 100644 app/src/main/java/org/foxarmy/barcodescannerforemployees/Parser.kt create mode 100644 app/src/main/java/org/foxarmy/barcodescannerforemployees/Product.kt create mode 100644 app/src/main/java/org/foxarmy/barcodescannerforemployees/ProductContract.kt create mode 100644 app/src/main/java/org/foxarmy/barcodescannerforemployees/Requester.kt create mode 100644 app/src/main/java/org/foxarmy/barcodescannerforemployees/SecondFragment.kt create mode 100644 app/src/main/java/org/foxarmy/barcodescannerforemployees/StorageController.kt create mode 100644 app/src/main/java/org/foxarmy/barcodescannerforemployees/addProductFragment.kt create mode 100644 app/src/main/java/org/foxarmy/barcodescannerforemployees/shelfContract.kt create mode 100644 app/src/main/res/drawable/ic_launcher_background.xml create mode 100644 app/src/main/res/drawable/ic_launcher_foreground.xml create mode 100644 app/src/main/res/layout/activity_main.xml create mode 100644 app/src/main/res/layout/add_product_fragment.xml create mode 100644 app/src/main/res/layout/content_main.xml create mode 100644 app/src/main/res/layout/fragment_second.xml create mode 100644 app/src/main/res/menu/menu_main.xml create mode 100644 app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml create mode 100644 app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml create mode 100644 app/src/main/res/mipmap-hdpi/ic_launcher.webp create mode 100644 app/src/main/res/mipmap-hdpi/ic_launcher_round.webp create mode 100644 app/src/main/res/mipmap-mdpi/ic_launcher.webp create mode 100644 app/src/main/res/mipmap-mdpi/ic_launcher_round.webp create mode 100644 app/src/main/res/mipmap-xhdpi/ic_launcher.webp create mode 100644 app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp create mode 100644 app/src/main/res/mipmap-xxhdpi/ic_launcher.webp create mode 100644 app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp create mode 100644 app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp create mode 100644 app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp create mode 100644 app/src/main/res/navigation/nav_graph.xml create mode 100644 app/src/main/res/values-land/dimens.xml create mode 100644 app/src/main/res/values-night/themes.xml create mode 100644 app/src/main/res/values-v23/themes.xml create mode 100644 app/src/main/res/values-w1240dp/dimens.xml create mode 100644 app/src/main/res/values-w600dp/dimens.xml create mode 100644 app/src/main/res/values/colors.xml create mode 100644 app/src/main/res/values/dimens.xml create mode 100644 app/src/main/res/values/strings.xml create mode 100644 app/src/main/res/values/themes.xml create mode 100644 app/src/main/res/xml/backup_rules.xml create mode 100644 app/src/main/res/xml/data_extraction_rules.xml create mode 100644 app/src/test/java/org/foxarmy/barcodescannerforemployees/ExampleUnitTest.kt create mode 100644 build.gradle.kts create mode 100644 gradle.properties create mode 100644 gradle/libs.versions.toml create mode 100644 gradle/wrapper/gradle-wrapper.jar create mode 100644 gradle/wrapper/gradle-wrapper.properties create mode 100755 gradlew create mode 100644 gradlew.bat create mode 100644 settings.gradle.kts diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ab0fbe8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,150 @@ +<<<<<<< HEAD +# ---> Node +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +lerna-debug.log* +.pnpm-debug.log* + +# Diagnostic reports (https://nodejs.org/api/report.html) +report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage +*.lcov + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +jspm_packages/ + +# Snowpack dependency directory (https://snowpack.dev/) +web_modules/ + +# TypeScript cache +*.tsbuildinfo + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Optional stylelint cache +.stylelintcache + +# Microbundle cache +.rpt2_cache/ +.rts2_cache_cjs/ +.rts2_cache_es/ +.rts2_cache_umd/ + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variable files +.env +.env.development.local +.env.test.local +.env.production.local +.env.local + +# parcel-bundler cache (https://parceljs.org/) +.cache +.parcel-cache + +# Next.js build output +.next +out + +# Nuxt.js build / generate output +.nuxt +dist + +# Gatsby files +.cache/ +# Comment in the public line in if your project uses Gatsby and not Next.js +# https://nextjs.org/blog/next-9-1#public-directory-support +# public + +# vuepress build output +.vuepress/dist + +# vuepress v2.x temp and cache directory +.temp +.cache + +# Docusaurus cache and generated files +.docusaurus + +# Serverless directories +.serverless/ + +# FuseBox cache +.fusebox/ + +# DynamoDB Local files +.dynamodb/ + +# TernJS port file +.tern-port + +# Stores VSCode versions used for testing VSCode extensions +.vscode-test + +# yarn v2 +.yarn/cache +.yarn/unplugged +.yarn/build-state.yml +.yarn/install-state.gz +.pnp.* + +======= +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild +.cxx +local.properties +>>>>>>> 2733d8d (first commit) diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..b589d56 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/deploymentTargetSelector.xml b/.idea/deploymentTargetSelector.xml new file mode 100644 index 0000000..b268ef3 --- /dev/null +++ b/.idea/deploymentTargetSelector.xml @@ -0,0 +1,10 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..e76fb07 --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,18 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/kotlinc.xml b/.idea/kotlinc.xml new file mode 100644 index 0000000..fdf8d99 --- /dev/null +++ b/.idea/kotlinc.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..d7916a5 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,9 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/app/build.gradle.kts b/app/build.gradle.kts new file mode 100644 index 0000000..9fb7385 --- /dev/null +++ b/app/build.gradle.kts @@ -0,0 +1,58 @@ +plugins { + alias(libs.plugins.android.application) + alias(libs.plugins.kotlin.android) +} + +android { + namespace = "org.foxarmy.barcodescannerforemployees" + compileSdk = 34 + + defaultConfig { + applicationId = "org.foxarmy.barcodescannerforemployees" + minSdk = 24 + targetSdk = 34 + versionCode = 1 + versionName = "1.0" + + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + isMinifyEnabled = false + proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro") + } + } + compileOptions { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 + } + kotlinOptions { + jvmTarget = "1.8" + } + buildFeatures { + viewBinding = true + } +} +var cameraxVersion = "1.0.1" +dependencies { + + implementation(libs.androidx.core.ktx) + implementation(libs.androidx.appcompat) + implementation(libs.material) + implementation(libs.androidx.constraintlayout) + implementation(libs.androidx.navigation.fragment.ktx) + implementation(libs.androidx.navigation.ui.ktx) + testImplementation(libs.junit) + androidTestImplementation(libs.androidx.junit) + androidTestImplementation(libs.androidx.espresso.core) + + // Barcode scanning API + implementation (libs.barcode.scanning) +// CameraX library + + implementation ("androidx.camera:camera-camera2:$cameraxVersion") + implementation ("androidx.camera:camera-lifecycle:$cameraxVersion") + implementation (libs.androidx.camera.view) + implementation ("com.google.android.gms:play-services-code-scanner:16.1.0") +} \ No newline at end of file diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/app/src/androidTest/java/org/foxarmy/barcodescannerforemployees/ExampleInstrumentedTest.kt b/app/src/androidTest/java/org/foxarmy/barcodescannerforemployees/ExampleInstrumentedTest.kt new file mode 100644 index 0000000..c5d7260 --- /dev/null +++ b/app/src/androidTest/java/org/foxarmy/barcodescannerforemployees/ExampleInstrumentedTest.kt @@ -0,0 +1,24 @@ +package org.foxarmy.barcodescannerforemployees + +import androidx.test.platform.app.InstrumentationRegistry +import androidx.test.ext.junit.runners.AndroidJUnit4 + +import org.junit.Test +import org.junit.runner.RunWith + +import org.junit.Assert.* + +/** + * Instrumented test, which will execute on an Android device. + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +@RunWith(AndroidJUnit4::class) +class ExampleInstrumentedTest { + @Test + fun useAppContext() { + // Context of the app under test. + val appContext = InstrumentationRegistry.getInstrumentation().targetContext + assertEquals("org.foxarmy.barcodescannerforemployees", appContext.packageName) + } +} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..7109216 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/org/foxarmy/barcodescannerforemployees/MainActivity.kt b/app/src/main/java/org/foxarmy/barcodescannerforemployees/MainActivity.kt new file mode 100644 index 0000000..026da17 --- /dev/null +++ b/app/src/main/java/org/foxarmy/barcodescannerforemployees/MainActivity.kt @@ -0,0 +1,61 @@ +package org.foxarmy.barcodescannerforemployees + +import android.os.Bundle +import com.google.android.material.snackbar.Snackbar +import androidx.appcompat.app.AppCompatActivity +import androidx.navigation.findNavController +import androidx.navigation.ui.AppBarConfiguration +import androidx.navigation.ui.navigateUp +import androidx.navigation.ui.setupActionBarWithNavController +import android.view.Menu +import android.view.MenuItem +import android.widget.Toast +import org.foxarmy.barcodescannerforemployees.databinding.ActivityMainBinding + +class MainActivity : AppCompatActivity() { + + private lateinit var appBarConfiguration: AppBarConfiguration + private lateinit var binding: ActivityMainBinding + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + + binding = ActivityMainBinding.inflate(layoutInflater) + setContentView(binding.root) + + setSupportActionBar(binding.toolbar) + + val navController = findNavController(R.id.nav_host_fragment_content_main) + appBarConfiguration = AppBarConfiguration(navController.graph) + setupActionBarWithNavController(navController, appBarConfiguration) + + binding.addProductFab.setOnClickListener { view -> +// Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) +// .setAction("Action", null) +// .setAnchorView(R.id.add_product_fab).show() + Toast.makeText(applicationContext, "Test", Toast.LENGTH_SHORT) + } + } + + override fun onCreateOptionsMenu(menu: Menu): Boolean { + // Inflate the menu; this adds items to the action bar if it is present. + menuInflater.inflate(R.menu.menu_main, menu) + return true + } + + override fun onOptionsItemSelected(item: MenuItem): Boolean { + // Handle action bar item clicks here. The action bar will + // automatically handle clicks on the Home/Up button, so long + // as you specify a parent activity in AndroidManifest.xml. + return when (item.itemId) { + R.id.action_settings -> true + else -> super.onOptionsItemSelected(item) + } + } + + override fun onSupportNavigateUp(): Boolean { + val navController = findNavController(R.id.nav_host_fragment_content_main) + return navController.navigateUp(appBarConfiguration) + || super.onSupportNavigateUp() + } +} \ No newline at end of file diff --git a/app/src/main/java/org/foxarmy/barcodescannerforemployees/Parser.kt b/app/src/main/java/org/foxarmy/barcodescannerforemployees/Parser.kt new file mode 100644 index 0000000..12fe481 --- /dev/null +++ b/app/src/main/java/org/foxarmy/barcodescannerforemployees/Parser.kt @@ -0,0 +1,44 @@ +package org.foxarmy.barcodescannerforemployees + +class Parser constructor(payloadStartRegex: String, payloadEndRegex: String, payloadRegex: String){ + val payloadStartRegex: String = payloadStartRegex + val payloadEndRegex: String = payloadEndRegex + val payloadRegex: String = payloadRegex + + fun parse(text: String): MutableList { + + val payloadStart = Regex(payloadStartRegex) + val payloadEnd = Regex(payloadEndRegex) + val payload = Regex(payloadRegex) + + val startFound = payloadStart.find(text)?.value.toString() + val payloadStartIndex = text.indexOf(startFound) + var clearText = text.removeRange( + 0, + if (payloadStartIndex < 0) 0 else payloadStartIndex + ) + + val endFound = payloadEnd.find(clearText)?.value.toString() + val payloadEndIndex = clearText.indexOf(endFound) + clearText = clearText.removeRange( + if (payloadEndIndex < 0) 0 else payloadEndIndex - 1, + clearText.length + ) + + println(clearText) + + var products = payload.findAll(clearText).toMutableList() + + for (product in products) { + println(product.value) + } + + return mutableListOf() + } +} + +fun main () { + val p = Parser("""\""", """\<\/table\>""", """[ёЁ\u0401\u0451\u0410-\u044f\d\w\s]{16,}""") + p.parse(Requester("https://barcode-list.ru", "barcode/RU/Поиск.htm?barcode=4680036915828", ).request("4680036915828")) +// println(Requester("https://barcode-list.ru", "barcode/RU/Поиск.htm?barcode=4680036915828", ).request("4680036915828")) +} \ No newline at end of file diff --git a/app/src/main/java/org/foxarmy/barcodescannerforemployees/Product.kt b/app/src/main/java/org/foxarmy/barcodescannerforemployees/Product.kt new file mode 100644 index 0000000..df834e0 --- /dev/null +++ b/app/src/main/java/org/foxarmy/barcodescannerforemployees/Product.kt @@ -0,0 +1,7 @@ +package org.foxarmy.barcodescannerforemployees + +class Product constructor(name:String, netWeight: Double) { + var name: String = name + var netWeight: Double = netWeight + var imageFile: String = "" +} \ No newline at end of file diff --git a/app/src/main/java/org/foxarmy/barcodescannerforemployees/ProductContract.kt b/app/src/main/java/org/foxarmy/barcodescannerforemployees/ProductContract.kt new file mode 100644 index 0000000..e840d00 --- /dev/null +++ b/app/src/main/java/org/foxarmy/barcodescannerforemployees/ProductContract.kt @@ -0,0 +1,12 @@ +package org.foxarmy.barcodescannerforemployees + +import android.provider.BaseColumns + +//object ProductContract { +// object ProductEntry :BaseColumns { +// const val TABLE_NAME = "products" +// const val PRODUCT_NAME = "name" +// const val PRODUCT_NET_WEIGHT = "net_weight" +// const val IMAGE_FILENAME = "image_filename" +// } +//} \ No newline at end of file diff --git a/app/src/main/java/org/foxarmy/barcodescannerforemployees/Requester.kt b/app/src/main/java/org/foxarmy/barcodescannerforemployees/Requester.kt new file mode 100644 index 0000000..1693e59 --- /dev/null +++ b/app/src/main/java/org/foxarmy/barcodescannerforemployees/Requester.kt @@ -0,0 +1,28 @@ +package org.foxarmy.barcodescannerforemployees + +import java.net.HttpURLConnection +import java.net.URL + +class Requester constructor(siteName:String, endpoint: String) { + var siteName: String = siteName + var endpoint: String = endpoint + + fun request (productId: String): String { + val url = URL("${siteName}/$endpoint") + + var response: String = "" + + with(url.openConnection() as HttpURLConnection) { + requestMethod = "GET" // optional default is GET + + println("\nSent 'GET' request to URL : $url; Response Code : $responseCode") + + inputStream.bufferedReader().use { + it.lines().forEach { line -> + response += line //+ '\n' + } + } + } + return response + } +} \ No newline at end of file diff --git a/app/src/main/java/org/foxarmy/barcodescannerforemployees/SecondFragment.kt b/app/src/main/java/org/foxarmy/barcodescannerforemployees/SecondFragment.kt new file mode 100644 index 0000000..0d087cb --- /dev/null +++ b/app/src/main/java/org/foxarmy/barcodescannerforemployees/SecondFragment.kt @@ -0,0 +1,44 @@ +package org.foxarmy.barcodescannerforemployees + +import android.os.Bundle +import androidx.fragment.app.Fragment +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.navigation.fragment.findNavController +import org.foxarmy.barcodescannerforemployees.databinding.FragmentSecondBinding + +/** + * A simple [Fragment] subclass as the second destination in the navigation. + */ +class SecondFragment : Fragment() { + + private var _binding: FragmentSecondBinding? = null + + // This property is only valid between onCreateView and + // onDestroyView. + private val binding get() = _binding!! + + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View { + + _binding = FragmentSecondBinding.inflate(inflater, container, false) + return binding.root + + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + + binding.buttonSecond.setOnClickListener { + findNavController().navigate(R.id.action_SecondFragment_to_FirstFragment) + } + } + + override fun onDestroyView() { + super.onDestroyView() + _binding = null + } +} \ No newline at end of file diff --git a/app/src/main/java/org/foxarmy/barcodescannerforemployees/StorageController.kt b/app/src/main/java/org/foxarmy/barcodescannerforemployees/StorageController.kt new file mode 100644 index 0000000..be757ba --- /dev/null +++ b/app/src/main/java/org/foxarmy/barcodescannerforemployees/StorageController.kt @@ -0,0 +1,28 @@ +package org.foxarmy.barcodescannerforemployees + +import android.content.Context +import android.provider.BaseColumns + +object ProductContract { + object ProductEntry :BaseColumns { + const val TABLE_NAME = "products" + const val PRODUCT_NAME = "name" + const val PRODUCT_NET_WEIGHT = "net_weight" + const val IMAGE_FILENAME = "image_filename" + } +} + +class StorageController(context: Context) { + val context = context + + fun initStorage() { + val productContract = ProductContract + val SQL_CREATE_ENTRIES = + "CREATE TABLE ${ProductContract.ProductEntry.TABLE_NAME} (" + + "${BaseColumns._ID} INTEGER PRIMARY KEY," + + "${ProductContract.ProductEntry.PRODUCT_NAME} TEXT," + + "${ProductContract.ProductEntry.PRODUCT_NET_WEIGHT} TEXT" + + "${ProductContract.ProductEntry.IMAGE_FILENAME} TEXT)" + + } +} \ No newline at end of file diff --git a/app/src/main/java/org/foxarmy/barcodescannerforemployees/addProductFragment.kt b/app/src/main/java/org/foxarmy/barcodescannerforemployees/addProductFragment.kt new file mode 100644 index 0000000..c1cb451 --- /dev/null +++ b/app/src/main/java/org/foxarmy/barcodescannerforemployees/addProductFragment.kt @@ -0,0 +1,63 @@ +package org.foxarmy.barcodescannerforemployees + +//import com.google.mlkit.vision.codescanner.GmsBarcodeScannerOptions +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.Toast +import androidx.fragment.app.Fragment +import com.google.mlkit.vision.barcode.common.Barcode +import com.google.mlkit.vision.codescanner.GmsBarcodeScannerOptions +import com.google.mlkit.vision.codescanner.GmsBarcodeScanning +import org.foxarmy.barcodescannerforemployees.databinding.AddProductFragmentBinding + +/** + * A simple [Fragment] subclass as the default destination in the navigation. + */ +class addProductFragment : Fragment() { + + private var _binding: AddProductFragmentBinding? = null + + // This property is only valid between onCreateView and + // onDestroyView. + private val binding get() = _binding!! + + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View { + + _binding = AddProductFragmentBinding.inflate(inflater, container, false) + return binding.root + + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + + binding.scanButton.setOnClickListener { +// findNavController().navigate(R.id.action_FirstFragment_to_SecondFragment) +// Toast.makeText(requireContext(), "Test", Toast.LENGTH_LONG).show() + val options = GmsBarcodeScannerOptions.Builder() + .setBarcodeFormats( + Barcode.FORMAT_EAN_13) + .build() + val scanner = GmsBarcodeScanning.getClient(requireContext()) + scanner.startScan() + .addOnSuccessListener { barcode -> + // Task completed successfully + //Toast.makeText(requireContext(), barcode.rawValue, Toast.LENGTH_LONG).show() + binding.productName.setText(barcode.rawValue) + } + .addOnFailureListener { e -> + Toast.makeText(requireContext(), "Failed to scan barcode. Please, try again", Toast.LENGTH_LONG).show() + } + } + } + + override fun onDestroyView() { + super.onDestroyView() + _binding = null + } +} \ No newline at end of file diff --git a/app/src/main/java/org/foxarmy/barcodescannerforemployees/shelfContract.kt b/app/src/main/java/org/foxarmy/barcodescannerforemployees/shelfContract.kt new file mode 100644 index 0000000..dd6c0e7 --- /dev/null +++ b/app/src/main/java/org/foxarmy/barcodescannerforemployees/shelfContract.kt @@ -0,0 +1,11 @@ +package org.foxarmy.barcodescannerforemployees + +import android.provider.BaseColumns + +object ShelfContract { + object ShelfEntry : BaseColumns { + const val TABLE_NAME = "shelf" + const val PRODUCT_ID = "product_id" + const val EXPIRE_DATE = "expire_date" + } +} \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_launcher_background.xml b/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..956b344 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/drawable/ic_launcher_foreground.xml b/app/src/main/res/drawable/ic_launcher_foreground.xml new file mode 100644 index 0000000..1ee1493 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_foreground.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..c2a2fe6 --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/add_product_fragment.xml b/app/src/main/res/layout/add_product_fragment.xml new file mode 100644 index 0000000..87dbd13 --- /dev/null +++ b/app/src/main/res/layout/add_product_fragment.xml @@ -0,0 +1,33 @@ + + + +