|
@@ -36,12 +36,14 @@ import java.io.File
|
|
|
* @since 2021/8/1 11:46 下午
|
|
|
*/
|
|
|
@AndroidEntryPoint
|
|
|
-class ShowProductFragment : BaseFragment<BackstageFragmentShowProductBinding, ShowProductFragmentVM>() {
|
|
|
+class ShowProductFragment :
|
|
|
+ BaseFragment<BackstageFragmentShowProductBinding, ShowProductFragmentVM>() {
|
|
|
private val TAG = "ShowProductFragment"
|
|
|
private var productAdapter: ProductAdapter? = null
|
|
|
override val mViewModel: ShowProductFragmentVM by viewModels()
|
|
|
override fun createVB() = BackstageFragmentShowProductBinding.inflate(layoutInflater)
|
|
|
var okCancelDialog: OKCancelDialog? = null
|
|
|
+ var productPosition = -1
|
|
|
|
|
|
|
|
|
override fun BackstageFragmentShowProductBinding.initView() {
|
|
@@ -64,7 +66,9 @@ class ShowProductFragment : BaseFragment<BackstageFragmentShowProductBinding, Sh
|
|
|
// showOkCancelDialog(data)
|
|
|
// }else if(data =="PIC"){
|
|
|
// 切换图片
|
|
|
+ productPosition = position
|
|
|
showOkCancelDialog(data!!)
|
|
|
+ Log.d(TAG, "onClickListener: " + productAdapter!!.productList[position].imgID)
|
|
|
// }
|
|
|
}
|
|
|
})
|
|
@@ -96,6 +100,18 @@ class ShowProductFragment : BaseFragment<BackstageFragmentShowProductBinding, Sh
|
|
|
SpUtils.putString(MMKVName.PRODUCT_DATA, toJson)
|
|
|
ToastUtil.switchToastStyleToSuccess(UiUtil.getStringRes(R.string.backstage_update_success))
|
|
|
}
|
|
|
+ tvReset.setOnClickListener {
|
|
|
+ for (i in 0 until mBinding.priceRvProduct.layoutManager!!.childCount) {
|
|
|
+ productAdapter!!.productList[i].customImg = ""
|
|
|
+ productAdapter!!.productList[i].customName = ""
|
|
|
+ productAdapter!!.productList[i].isSelected=true
|
|
|
+ }
|
|
|
+
|
|
|
+ val toJson = Gson().toJson(productAdapter?.productList)
|
|
|
+ Log.d(TAG, "toJson : " + toJson)
|
|
|
+ SpUtils.putString(MMKVName.PRODUCT_DATA, toJson)
|
|
|
+ ToastUtil.switchToastStyleToSuccess("已重置商品设置")
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
override fun initObserve() {
|
|
@@ -147,19 +163,25 @@ class ShowProductFragment : BaseFragment<BackstageFragmentShowProductBinding, Sh
|
|
|
* 获取系统系统相册权限
|
|
|
*/
|
|
|
private fun permissions() {
|
|
|
- if (ContextCompat.checkSelfPermission(requireContext(), Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
|
|
|
+ if (ContextCompat.checkSelfPermission(
|
|
|
+ requireContext(),
|
|
|
+ Manifest.permission.WRITE_EXTERNAL_STORAGE
|
|
|
+ ) != PackageManager.PERMISSION_GRANTED
|
|
|
+ ) {
|
|
|
// 请求权限
|
|
|
requestPermissions(arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), PHOTO)
|
|
|
+ Log.d(TAG, "permissions: 1")
|
|
|
} else {
|
|
|
// 已经有权限,直接打开系统相册
|
|
|
choosePhoto()
|
|
|
+ Log.d(TAG, "permissions: 2")
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private fun choosePhoto() {
|
|
|
// 打开系统相册
|
|
|
- Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI)
|
|
|
-// startActivityForResult(picture, 2) // 这里传入的请求码为2
|
|
|
+ val intent = Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI)
|
|
|
+ startActivityForResult(intent, 2) // 这里传入的请求码为2
|
|
|
}
|
|
|
|
|
|
|
|
@@ -170,7 +192,11 @@ class ShowProductFragment : BaseFragment<BackstageFragmentShowProductBinding, Sh
|
|
|
* @param permissions
|
|
|
* @param grantResults
|
|
|
*/
|
|
|
- override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
|
|
|
+ override fun onRequestPermissionsResult(
|
|
|
+ requestCode: Int,
|
|
|
+ permissions: Array<out String>,
|
|
|
+ grantResults: IntArray
|
|
|
+ ) {
|
|
|
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
|
|
|
if (requestCode == PHOTO) {
|
|
|
if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
|
@@ -198,7 +224,7 @@ class ShowProductFragment : BaseFragment<BackstageFragmentShowProductBinding, Sh
|
|
|
if (!isFilePathWithExtension) {
|
|
|
// 获取文件路径
|
|
|
path = File(ReaderUtils.getRealPathFromUri(requireContext(), uri))
|
|
|
- Log.d("YourFragment", "onActivityResult: 当前位置: path"+path)
|
|
|
+ Log.d("YourFragment", "onActivityResult: 当前位置: path" + path)
|
|
|
Log.d("YourFragment", "onActivityResult: 商品名: {goodsBean.nameChinese}")
|
|
|
|
|
|
// 将文件路径存入 Map
|
|
@@ -208,9 +234,10 @@ class ShowProductFragment : BaseFragment<BackstageFragmentShowProductBinding, Sh
|
|
|
|
|
|
// 将选择的图片路径保存到 Hawk 中
|
|
|
// Hawk.put("image", picture)
|
|
|
+ productAdapter!!.productList[productPosition].customImg = path.toString()
|
|
|
|
|
|
// 刷新适配器
|
|
|
- mBinding.priceRvProduct.adapter?.notifyItemChanged(currentPosition)
|
|
|
+ mBinding.priceRvProduct.adapter?.notifyItemChanged(productPosition)
|
|
|
}
|
|
|
}
|
|
|
}
|