-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- bottom navigation - initial qr scanner - add menu fragment & view model
- Loading branch information
Showing
18 changed files
with
440 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
app/src/main/java/com/jaylangkung/bpkpd/menu/home/HomeFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.jaylangkung.bpkpd.menu.home | ||
|
||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.fragment.app.Fragment | ||
import androidx.lifecycle.ViewModelProvider | ||
import com.jaylangkung.bpkpd.databinding.FragmentHomeBinding | ||
import com.jaylangkung.bpkpd.viewModel.HomeViewModel | ||
import com.jaylangkung.bpkpd.viewModel.ViewModelFactory | ||
|
||
class HomeFragment : Fragment() { | ||
private var _binding: FragmentHomeBinding? = null | ||
private val binding get() = _binding!! | ||
|
||
private lateinit var viewModel: HomeViewModel | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
arguments?.let { | ||
|
||
} | ||
} | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? | ||
): View { | ||
_binding = FragmentHomeBinding.inflate(inflater, container, false) | ||
val factory = ViewModelFactory.getInstance() | ||
viewModel = ViewModelProvider(this, factory)[HomeViewModel::class.java] | ||
|
||
return binding.root | ||
} | ||
|
||
override fun onDestroyView() { | ||
super.onDestroyView() | ||
_binding = null | ||
} | ||
|
||
} |
74 changes: 74 additions & 0 deletions
74
app/src/main/java/com/jaylangkung/bpkpd/menu/scan/ScanQrFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package com.jaylangkung.bpkpd.menu.scan | ||
|
||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.fragment.app.Fragment | ||
import androidx.lifecycle.ViewModelProvider | ||
import com.budiyev.android.codescanner.AutoFocusMode | ||
import com.budiyev.android.codescanner.CodeScanner | ||
import com.budiyev.android.codescanner.DecodeCallback | ||
import com.budiyev.android.codescanner.ErrorCallback | ||
import com.budiyev.android.codescanner.ScanMode | ||
import com.jaylangkung.bpkpd.databinding.FragmentScanQrBinding | ||
import com.jaylangkung.bpkpd.utils.Constants | ||
import com.jaylangkung.bpkpd.utils.ErrorHandler | ||
import com.jaylangkung.bpkpd.utils.MySharedPreferences | ||
import com.jaylangkung.bpkpd.viewModel.ScanQrViewModel | ||
import com.jaylangkung.bpkpd.viewModel.ViewModelFactory | ||
import es.dmoral.toasty.Toasty | ||
|
||
class ScanQrFragment : Fragment() { | ||
private var _binding: FragmentScanQrBinding? = null | ||
private val binding get() = _binding!! | ||
private lateinit var viewModel: ScanQrViewModel | ||
private lateinit var myPreferences: MySharedPreferences | ||
private lateinit var codeScanner: CodeScanner | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? | ||
): View { | ||
_binding = FragmentScanQrBinding.inflate(inflater, container, false) | ||
val factory = ViewModelFactory.getInstance() | ||
viewModel = ViewModelProvider(this, factory)[ScanQrViewModel::class.java] | ||
myPreferences = MySharedPreferences(requireContext()) | ||
|
||
val idadmin = myPreferences.getValue(Constants.USER_IDADMIN).toString() | ||
val tokenAuth = myPreferences.getValue(Constants.TokenAuth).toString() | ||
|
||
binding.apply { | ||
codeScanner = CodeScanner(requireContext(), scannerView).apply { | ||
camera = CodeScanner.CAMERA_BACK | ||
formats = CodeScanner.ALL_FORMATS | ||
autoFocusMode = AutoFocusMode.CONTINUOUS | ||
scanMode = ScanMode.SINGLE | ||
isAutoFocusEnabled = true | ||
isFlashEnabled = false | ||
startPreview() | ||
|
||
decodeCallback = DecodeCallback { | ||
requireActivity().runOnUiThread { | ||
// viewModel.getQrCode(it.text, idadmin, tokenAuth) | ||
} | ||
} | ||
errorCallback = ErrorCallback { | ||
requireActivity().runOnUiThread { | ||
ErrorHandler().responseHandler( | ||
requireContext(), "codeScanner | errorCallback", it.message.toString() | ||
) | ||
Toasty.error(requireContext(), it.message.toString(), Toasty.LENGTH_LONG).show() | ||
} | ||
} | ||
} | ||
} | ||
|
||
return binding.root | ||
} | ||
|
||
override fun onDestroyView() { | ||
super.onDestroyView() | ||
_binding = null | ||
} | ||
|
||
} |
35 changes: 35 additions & 0 deletions
35
app/src/main/java/com/jaylangkung/bpkpd/menu/setting/SettingFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.jaylangkung.bpkpd.menu.setting | ||
|
||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.fragment.app.Fragment | ||
import androidx.lifecycle.ViewModelProvider | ||
import com.jaylangkung.bpkpd.databinding.FragmentSettingBinding | ||
import com.jaylangkung.bpkpd.viewModel.SettingViewModel | ||
import com.jaylangkung.bpkpd.viewModel.ViewModelFactory | ||
|
||
class SettingFragment : Fragment() { | ||
private var _binding: FragmentSettingBinding? = null | ||
private val binding get() = _binding!! | ||
|
||
private lateinit var viewModel: SettingViewModel | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View { | ||
_binding = FragmentSettingBinding.inflate(inflater, container, false) | ||
val factory = ViewModelFactory.getInstance() | ||
viewModel = ViewModelProvider(this, factory)[SettingViewModel::class.java] | ||
|
||
return binding.root | ||
} | ||
|
||
override fun onDestroyView() { | ||
super.onDestroyView() | ||
_binding = null | ||
} | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
app/src/main/java/com/jaylangkung/bpkpd/viewModel/HomeViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.jaylangkung.bpkpd.viewModel | ||
|
||
import androidx.lifecycle.ViewModel | ||
|
||
class HomeViewModel : ViewModel() { | ||
// TODO: Implement the ViewModel | ||
} |
7 changes: 7 additions & 0 deletions
7
app/src/main/java/com/jaylangkung/bpkpd/viewModel/ScanQrViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.jaylangkung.bpkpd.viewModel | ||
|
||
import androidx.lifecycle.ViewModel | ||
|
||
class ScanQrViewModel : ViewModel() { | ||
// TODO: Implement the ViewModel | ||
} |
7 changes: 7 additions & 0 deletions
7
app/src/main/java/com/jaylangkung/bpkpd/viewModel/SettingViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.jaylangkung.bpkpd.viewModel | ||
|
||
import androidx.lifecycle.ViewModel | ||
|
||
class SettingViewModel : ViewModel() { | ||
// TODO: Implement the ViewModel | ||
} |
35 changes: 35 additions & 0 deletions
35
app/src/main/java/com/jaylangkung/bpkpd/viewModel/ViewModelFactory.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.jaylangkung.bpkpd.viewModel | ||
|
||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.ViewModelProvider | ||
|
||
@Suppress("UNCHECKED_CAST") | ||
class ViewModelFactory private constructor() : ViewModelProvider.NewInstanceFactory() { | ||
|
||
override fun <T : ViewModel> create(modelClass: Class<T>): T { | ||
return if (modelClass.isAssignableFrom(HomeViewModel::class.java)) { | ||
HomeViewModel() as T | ||
} else if (modelClass.isAssignableFrom(ScanQrViewModel::class.java)) { | ||
ScanQrViewModel() as T | ||
} else if (modelClass.isAssignableFrom(SettingViewModel::class.java)) { | ||
SettingViewModel() as T | ||
} else { | ||
throw IllegalArgumentException("Unknown ViewModel class: ${modelClass.name}") | ||
} | ||
} | ||
|
||
companion object { | ||
@Volatile | ||
private var INSTANCE: ViewModelFactory? = null | ||
|
||
@JvmStatic | ||
fun getInstance(): ViewModelFactory { | ||
if (INSTANCE == null) { | ||
synchronized(ViewModelFactory::class.java) { | ||
INSTANCE = ViewModelFactory() | ||
} | ||
} | ||
return INSTANCE as ViewModelFactory | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="24dp" | ||
android:height="24dp" | ||
android:tint="#000000" | ||
android:viewportWidth="24" | ||
android:viewportHeight="24"> | ||
<path | ||
android:fillColor="@android:color/white" | ||
android:pathData="M10,19v-5h4v5c0,0.55 0.45,1 1,1h3c0.55,0 1,-0.45 1,-1v-7h1.7c0.46,0 0.68,-0.57 0.33,-0.87L12.67,3.6c-0.38,-0.34 -0.96,-0.34 -1.34,0l-8.36,7.53c-0.34,0.3 -0.13,0.87 0.33,0.87H5v7c0,0.55 0.45,1 1,1h3c0.55,0 1,-0.45 1,-1z" /> | ||
</vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="24dp" | ||
android:height="24dp" | ||
android:viewportWidth="512" | ||
android:viewportHeight="512"> | ||
<path | ||
android:fillColor="#FFFFFF" | ||
android:pathData="M87.2,82c-1.8,1.1 -4.1,3.4 -5.2,5.2 -1.9,3.2 -2,5.2 -2,56.8 0,51.6 0.1,53.6 2,56.8 3,4.8 7.5,7.2 14,7.2 6.5,-0 11,-2.4 14,-7.2 1.9,-3.2 2,-5.2 2,-46.1l0,-42.7 42.8,-0c40.8,-0 42.8,-0.1 46,-2 4.8,-3 7.2,-7.5 7.2,-14 0,-6.5 -2.4,-11 -7.2,-14 -3.2,-1.9 -5.2,-2 -56.8,-2 -51.6,-0 -53.6,0.1 -56.8,2z" | ||
android:strokeColor="#00000000" /> | ||
<path | ||
android:fillColor="#FFFFFF" | ||
android:pathData="M311.2,82c-4.8,3 -7.2,7.5 -7.2,14 0,6.5 2.4,11 7.2,14 3.2,1.9 5.2,2 46.1,2l42.7,-0 0,42.7c0,40.9 0.1,42.9 2,46.1 3,4.8 7.5,7.2 14,7.2 6.5,-0 11,-2.4 14,-7.2 1.9,-3.2 2,-5.2 2,-56.8 0,-51.6 -0.1,-53.6 -2,-56.8 -1.1,-1.8 -3.4,-4.1 -5.2,-5.2 -3.2,-1.9 -5.2,-2 -56.8,-2 -51.6,-0 -53.6,0.1 -56.8,2z" | ||
android:strokeColor="#00000000" /> | ||
<path | ||
android:fillColor="#FFFFFF" | ||
android:pathData="M23.2,242c-4.8,3 -7.2,7.5 -7.2,14 0,6.5 2.4,11 7.2,14 3.3,2 5.6,2 232.8,2 227.2,-0 229.5,-0 232.8,-2 4.8,-3 7.2,-7.5 7.2,-14 0,-6.5 -2.4,-11 -7.2,-14 -3.3,-2 -5.6,-2 -232.8,-2 -227.2,-0 -229.5,-0 -232.8,2z" | ||
android:strokeColor="#00000000" /> | ||
<path | ||
android:fillColor="#FFFFFF" | ||
android:pathData="M87.2,306c-1.8,1.1 -4.1,3.4 -5.2,5.2 -1.9,3.2 -2,5.2 -2,56.8 0,51.6 0.1,53.6 2,56.8 1.1,1.8 3.4,4.1 5.2,5.2 3.2,1.9 5.2,2 56.8,2 51.6,-0 53.6,-0.1 56.8,-2 4.8,-3 7.2,-7.5 7.2,-14 0,-6.5 -2.4,-11 -7.2,-14 -3.2,-1.9 -5.2,-2 -46,-2l-42.8,-0 0,-42.8c0,-40.8 -0.1,-42.8 -2,-46 -1.1,-1.8 -3.4,-4.1 -5.2,-5.2 -4.5,-2.7 -13.1,-2.7 -17.6,-0z" | ||
android:strokeColor="#00000000" /> | ||
<path | ||
android:fillColor="#FFFFFF" | ||
android:pathData="M407.2,306c-1.8,1.1 -4.1,3.4 -5.2,5.2 -1.9,3.2 -2,5.2 -2,46l0,42.8 -42.7,-0c-40.9,-0 -42.9,0.1 -46.1,2 -4.8,3 -7.2,7.5 -7.2,14 0,6.5 2.4,11 7.2,14 3.2,1.9 5.2,2 56.8,2 51.6,-0 53.6,-0.1 56.8,-2 1.8,-1.1 4.1,-3.4 5.2,-5.2 1.9,-3.2 2,-5.2 2,-56.8 0,-51.6 -0.1,-53.6 -2,-56.8 -1.1,-1.8 -3.4,-4.1 -5.2,-5.2 -4.5,-2.7 -13.1,-2.7 -17.6,-0z" | ||
android:strokeColor="#00000000" /> | ||
</vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="24dp" | ||
android:height="24dp" | ||
android:tint="#000000" | ||
android:viewportWidth="24" | ||
android:viewportHeight="24"> | ||
<path | ||
android:fillColor="@android:color/white" | ||
android:pathData="M19.43,12.98c0.04,-0.32 0.07,-0.64 0.07,-0.98s-0.03,-0.66 -0.07,-0.98l2.11,-1.65c0.19,-0.15 0.24,-0.42 0.12,-0.64l-2,-3.46c-0.12,-0.22 -0.39,-0.3 -0.61,-0.22l-2.49,1c-0.52,-0.4 -1.08,-0.73 -1.69,-0.98l-0.38,-2.65C14.46,2.18 14.25,2 14,2h-4c-0.25,0 -0.46,0.18 -0.49,0.42l-0.38,2.65c-0.61,0.25 -1.17,0.59 -1.69,0.98l-2.49,-1c-0.23,-0.09 -0.49,0 -0.61,0.22l-2,3.46c-0.13,0.22 -0.07,0.49 0.12,0.64l2.11,1.65c-0.04,0.32 -0.07,0.65 -0.07,0.98s0.03,0.66 0.07,0.98l-2.11,1.65c-0.19,0.15 -0.24,0.42 -0.12,0.64l2,3.46c0.12,0.22 0.39,0.3 0.61,0.22l2.49,-1c0.52,0.4 1.08,0.73 1.69,0.98l0.38,2.65c0.03,0.24 0.24,0.42 0.49,0.42h4c0.25,0 0.46,-0.18 0.49,-0.42l0.38,-2.65c0.61,-0.25 1.17,-0.59 1.69,-0.98l2.49,1c0.23,0.09 0.49,0 0.61,-0.22l2,-3.46c0.12,-0.22 0.07,-0.49 -0.12,-0.64l-2.11,-1.65zM12,15.5c-1.93,0 -3.5,-1.57 -3.5,-3.5s1.57,-3.5 3.5,-3.5 3.5,1.57 3.5,3.5 -1.57,3.5 -3.5,3.5z" /> | ||
</vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.