Skip to content

Commit

Permalink
Camera and Manual Input ID
Browse files Browse the repository at this point in the history
okay
  • Loading branch information
whyfoo committed Jan 3, 2022
1 parent 81c8e94 commit 678e134
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 15 deletions.
3 changes: 3 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
<uses-feature android:name="android.hardware.camera"
android:required="true" />

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

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
Expand Down
60 changes: 51 additions & 9 deletions app/src/main/java/com/trolle/trolleapp/HomeFragment.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package com.trolle.trolleapp

import android.app.AlertDialog
import android.content.*
import android.os.Bundle
import android.provider.MediaStore
import android.text.InputType
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import android.widget.EditText
import androidx.navigation.Navigation
import com.trolle.trolleapp.databinding.FragmentHomeBinding

Expand All @@ -32,16 +35,55 @@ class HomeFragment : Fragment() {

binding.imageViewBarcode.setOnClickListener{

val takePhotoIntent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
startActivityForResult(takePhotoIntent, 1)


// val alertDialog = AlertDialog.Builder(requireContext())
// alertDialog.apply {
// setTitle("Success!")
// setMessage("Your smartphone has successfully connected with Trolley ID = (ID). " +
// " Happy Shopping!")
// setPositiveButton("OK") { dialog, which ->
// Navigation.findNavController(view).navigate(R.id.payFragment)
// }
// alertDialog.setNegativeButton("Cancel") { dialog, which ->
// dialog.cancel()
// }
// }
// alertDialog.create().show()
}

binding.imageViewInput.setOnClickListener {

val input = EditText(context)
input.setHint("Enter ID")
input.inputType = InputType.TYPE_CLASS_NUMBER


val alertDialog = AlertDialog.Builder(requireContext())
alertDialog.apply {
setTitle("Success!")
setMessage("Your smartphone has successfully connected with Trolley ID = (ID). " +
" Happy Shopping!")
setPositiveButton("OK") { _, _ ->
//Toast.makeText(requireContext(), "yes", Toast.LENGTH_SHORT).show()
Navigation.findNavController(view).navigate(R.id.payFragment)
}.create().show()
alertDialog.setTitle("Input Trolley ID")
alertDialog.setView(input)
alertDialog.setPositiveButton("Connect") { dialog, which ->
var input = input.text.toString()

val alertDialogStatus = AlertDialog.Builder(requireContext())
alertDialogStatus.apply {
setTitle("Success!")
setMessage("Your smartphone has successfully connected with Trolley ID = " + input +
" Happy Shopping!")
setPositiveButton("OK") { dialog, which ->
Navigation.findNavController(view).navigate(R.id.payFragment)
}
alertDialogStatus.setNegativeButton("Cancel") { dialog, which ->
dialog.cancel()
}
}
alertDialogStatus.create().show()
}
alertDialog.setNegativeButton("Cancel") { dialog, which ->
dialog.cancel()
}.create().show()
}
}
}
12 changes: 6 additions & 6 deletions app/src/main/res/layout/fragment_home.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,17 @@
/>

<com.google.android.material.button.MaterialButton
style="@style/Widget.MaterialComponents.Button.TextButton"
android:id="@+id/image_view_input"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:backgroundTint="@color/white"
android:fontFamily="@font/nunito_family"
android:padding="12dp"
android:text="@string/manually_input_the_id"
android:textStyle="bold"
android:fontFamily="@font/nunito_family"
style="@style/Widget.MaterialComponents.Button.TextButton"
app:icon="@drawable/ic_baseline_edit_24"
android:backgroundTint="@color/white"
app:cornerRadius="15dp"
android:padding="12dp"
/>
app:icon="@drawable/ic_baseline_edit_24" />

</LinearLayout>

Expand Down

0 comments on commit 678e134

Please sign in to comment.