Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
M
meser
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Muhammad Suryono
meser
Commits
22bec9ae
Commit
22bec9ae
authored
Sep 02, 2020
by
iman Fauzi
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'dev' into cart
parents
ba19218c
56aecc45
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
29 deletions
+51
-29
FormProductActivity.java
...rc/main/java/com/yono/messeripos/FormProductActivity.java
+50
-28
Utils.java
app/src/main/java/com/yono/messeripos/utils/Utils.java
+1
-1
No files found.
app/src/main/java/com/yono/messeripos/FormProductActivity.java
View file @
22bec9ae
...
...
@@ -29,6 +29,7 @@ import androidx.lifecycle.ViewModelProviders;
import
com.google.android.material.appbar.MaterialToolbar
;
import
com.google.android.material.bottomsheet.BottomSheetDialogFragment
;
import
com.google.zxing.common.StringUtils
;
import
com.jaredrummler.materialspinner.MaterialSpinner
;
import
com.yono.messeripos.api.client.Client
;
import
com.yono.messeripos.api.service.CategoryServise
;
...
...
@@ -55,7 +56,7 @@ import retrofit2.Response;
public
class
FormProductActivity
extends
AppCompatActivity
{
FormProductBinding
binding
;
ProductModels
productModels
;
ProductModels
productModels
,
productModelsSave
;
File
file
;
MainViewModels
mainViewModels
;
MaterialSpinner
spinner
;
...
...
@@ -66,7 +67,7 @@ public class FormProductActivity extends AppCompatActivity {
String
locationPath
=
null
;
int
idCategorySelected
=
0
;
public
int
id
=
0
;
public
String
categoryName
=
""
;
public
String
categoryName
=
null
;
private
String
[]
permissions
=
new
String
[]{
Manifest
.
permission
.
READ_EXTERNAL_STORAGE
,
Manifest
.
permission
.
WRITE_EXTERNAL_STORAGE
};
...
...
@@ -85,6 +86,7 @@ public class FormProductActivity extends AppCompatActivity {
binding
.
btnAdd
.
setText
(
"Add New Product"
);
productModels
=
new
ProductModels
();
productModelsSave
=
new
ProductModels
();
mainViewModels
=
ViewModelProviders
.
of
(
this
).
get
(
MainViewModels
.
class
);
progressDialog
=
new
ProgressDialog
(
FormProductActivity
.
this
);
progressDialog
.
setMessage
(
"Loading..."
);
...
...
@@ -111,17 +113,17 @@ public class FormProductActivity extends AppCompatActivity {
if
(
productModelsIntent
!=
null
){
isUpdate
=
true
;
productModels
.
setProductName
(
productModelsIntent
.
getProductName
());
productModels
.
setPriceProduct
(
productModelsIntent
.
getPriceProduct
());
productModels
.
setStockProduct
(
productModelsIntent
.
getStockProduct
());
productModels
.
setImageProduct
(
productModelsIntent
.
getImageProduct
());
productModels
Save
.
setProductName
(
productModelsIntent
.
getProductName
());
productModels
Save
.
setPriceProduct
(
productModelsIntent
.
getPriceProduct
());
productModels
Save
.
setStockProduct
(
productModelsIntent
.
getStockProduct
());
productModels
Save
.
setImageProduct
(
productModelsIntent
.
getImageProduct
());
binding
.
setProductForm
(
productModelsIntent
);
binding
.
setPhoto
(
productModelsIntent
.
getImageProduct
());
binding
.
btnAdd
.
setText
(
"UPDATE PRODUCT"
);
}
else
{
productModelsIntent
=
new
ProductModels
(
""
,
0
,
0
,
utils
.
convertImageBase64Resource
(
getResources
(),
R
.
drawable
.
logo_32
));
new
ProductModels
(
""
,
0
,
0
,
utils
.
convertImageBase64Resource
(
getResources
(),
R
.
drawable
.
logo_32
));
}
binding
.
cvProduct
.
setOnClickListener
(
view
->
openFile
());
...
...
@@ -129,6 +131,7 @@ public class FormProductActivity extends AppCompatActivity {
binding
.
btnAddCategory
.
setOnClickListener
(
view
->
addCategory
());
//spinner
setSpinner
(
""
);
setSelectedSpinner
();
setAddListenerCategory
();
...
...
@@ -189,11 +192,14 @@ public class FormProductActivity extends AppCompatActivity {
List
<
String
>
str
=
new
ArrayList
<>();
categoryModels
=
new
ArrayList
<>();
Log
.
i
(
"GET_CATEGORY"
,
"setSpinner: "
+
utils
.
convertGson
(
productModelsIntent
));
if
(
productModelsIntent
.
getCategoryProduct
()
==
0
){
// if (productModelsIntent == null){
// str.add("SELECT CATEGORY");
// }else{
// getCategoryById(productModelsIntent.getIdProduct());
// categoryName = ""
// str.add(categoryName);
// }
str
.
add
(
"SELECT CATEGORY"
);
}
else
{
str
.
add
(
getCategoryById
(
productModelsIntent
.
getIdProduct
()));
}
mainViewModels
.
getCategory
().
observe
(
this
,
listDataResponse
->
{
progressDialog
.
dismiss
();
for
(
CategoryModels
cd:
listDataResponse
.
getData
()){
...
...
@@ -218,27 +224,38 @@ public class FormProductActivity extends AppCompatActivity {
}
private
void
saveProduct
(){
productModels
.
setProductName
(
binding
.
etName
.
getText
().
toString
());
productModels
.
setPriceProduct
(
Integer
.
parseInt
(
binding
.
etPrice
.
getText
().
toString
()));
productModels
.
setStockProduct
(
Integer
.
parseInt
(
binding
.
etStock
.
getText
().
toString
()));
productModels
.
setCategoryProduct
(
getCategory
(
categorySelect
.
get
(
0
)));
productModelsSave
=
new
ProductModels
();
productModelsSave
.
setProductName
(
binding
.
etName
.
getText
().
toString
());
productModelsSave
.
setPriceProduct
(
Integer
.
parseInt
(
binding
.
etPrice
.
getText
().
toString
()));
productModelsSave
.
setStockProduct
(
Integer
.
parseInt
(
binding
.
etStock
.
getText
().
toString
()));
productModelsSave
.
setCategoryProduct
(
getCategory
(
categorySelect
.
get
(
0
)));
if
(
productModelsIntent
==
null
){
productModelsSave
.
setImageProduct
(
productModels
.
getImageProduct
());
}
else
{
if
(
productModels
.
getImageProduct
()
==
null
){
productModelsSave
.
setImageProduct
(
productModelsIntent
.
getImageProduct
());
}
else
{
productModelsSave
.
setImageProduct
(
productModels
.
getImageProduct
());
}
}
Log
.
i
(
"SAVEPRODUCT"
,
"saveProduct: "
+
utils
.
convertGson
(
productModelsSave
));
if
(
isUpdate
){
Log
.
i
(
"update_path"
,
"saveProduct: "
+
locationPath
);
if
(
!
productModels
.
getProductName
().
isEmpty
()
||
productModels
.
getPriceProduct
()
!=
0
||
productModels
.
getStockProduct
()
!=
0
!
productModels
Save
.
getProductName
().
isEmpty
()
||
productModels
Save
.
getPriceProduct
()
!=
0
||
productModels
Save
.
getStockProduct
()
!=
0
){
progressDialog
.
setCancelable
(
false
);
progressDialog
.
show
();
ProductService
productService
=
client
.
Client
(
ProductService
.
class
);
Log
.
i
(
"data_post"
,
"saveProduct: "
+
utils
.
convertGson
(
productModels
));
productService
.
updateProduct
(
productModels
,
productModelsIntent
.
getIdProduct
()).
enqueue
(
new
Callback
<
DataResponse
<
ProductModels
>>()
{
Log
.
i
(
"data_post"
,
"saveProduct: "
+
utils
.
convertGson
(
productModels
Save
));
productService
.
updateProduct
(
productModels
Save
,
productModelsIntent
.
getIdProduct
()).
enqueue
(
new
Callback
<
DataResponse
<
ProductModels
>>()
{
@Override
public
void
onResponse
(
Call
<
DataResponse
<
ProductModels
>>
call
,
Response
<
DataResponse
<
ProductModels
>>
response
)
{
Log
.
i
(
"Success Post"
,
"onResponse: "
+
utils
.
convertGson
(
response
.
body
()
));
Log
.
i
(
"Success Post"
,
"onResponse: "
+
utils
.
convertGson
(
response
));
if
(
response
.
body
()
!=
null
){
new
AlertDialog
.
Builder
(
FormProductActivity
.
this
)
.
setCancelable
(
false
)
...
...
@@ -273,15 +290,16 @@ public class FormProductActivity extends AppCompatActivity {
Log
.
i
(
"save"
,
"saveProduct: "
+
locationPath
);
if
(
fileImage
.
exists
()){
if
(
!
productModels
.
getProductName
().
isEmpty
()
||
productModels
.
getPriceProduct
()
!=
0
||
productModels
.
getStockProduct
()
!=
0
!
productModels
Save
.
getProductName
().
isEmpty
()
||
productModels
Save
.
getPriceProduct
()
!=
0
||
productModels
Save
.
getStockProduct
()
!=
0
){
progressDialog
.
setCancelable
(
false
);
progressDialog
.
show
();
ProductService
productService
=
client
.
Client
(
ProductService
.
class
);
Log
.
i
(
"data_post"
,
"saveProduct: "
+
utils
.
convertGson
(
productModels
));
productService
.
postProduct
(
productModels
).
enqueue
(
new
Callback
<
DataResponse
<
ProductModels
>>()
{
Log
.
i
(
"data_post"
,
"saveProduct: "
+
utils
.
convertGson
(
productModelsSave
.
getProductName
()+
productModelsSave
.
getStockProduct
()+
productModelsSave
.
getPriceProduct
()));
Log
.
i
(
"IMAGE"
,
"saveProduct: "
+
utils
.
convertGson
(
productModelsSave
.
getImageProduct
()));
productService
.
postProduct
(
productModelsSave
).
enqueue
(
new
Callback
<
DataResponse
<
ProductModels
>>()
{
@Override
public
void
onResponse
(
Call
<
DataResponse
<
ProductModels
>>
call
,
Response
<
DataResponse
<
ProductModels
>>
response
)
{
Log
.
i
(
"Success Post"
,
"onResponse: "
+
utils
.
convertGson
(
response
.
body
()));
...
...
@@ -327,6 +345,7 @@ public class FormProductActivity extends AppCompatActivity {
public
void
onResponse
(
Call
<
DataResponse
<
List
<
CategoryModels
>>>
call
,
Response
<
DataResponse
<
List
<
CategoryModels
>>>
response
)
{
Log
.
i
(
"CHDJHD"
,
"getCategory: "
+
utils
.
convertGson
(
response
.
body
()));
id
=
response
.
body
().
getData
().
get
(
0
).
getIdCategory
();
productModels
.
setCategoryProduct
(
id
);
}
@Override
...
...
@@ -343,14 +362,17 @@ public class FormProductActivity extends AppCompatActivity {
@Override
public
void
onResponse
(
Call
<
DataResponse
<
CategoryModels
>>
call
,
Response
<
DataResponse
<
CategoryModels
>>
response
)
{
Log
.
i
(
"ER"
,
"onResponse: "
+
utils
.
convertGson
(
response
.
body
()));
if
(
categoryName
.
isEmpty
()){
categoryName
=
response
.
body
().
getData
().
getNameCategory
();
}
}
@Override
public
void
onFailure
(
Call
<
DataResponse
<
CategoryModels
>>
call
,
Throwable
t
)
{
}
});
Log
.
i
(
"CategoryName"
,
"getCategoryById: "
+
categoryName
);
return
categoryName
;
}
...
...
app/src/main/java/com/yono/messeripos/utils/Utils.java
View file @
22bec9ae
...
...
@@ -133,7 +133,7 @@ public class Utils {
Bitmap
decodeImages
=
BitmapFactory
.
decodeByteArray
(
imageBytes
,
0
,
imageBytes
.
length
);
// Bitmap bf = BitmapFactory.decodeFile(source, options);
Log
.
i
(
"Size bitmap"
,
"decodeImageBase64: "
+
decodeImages
.
getByteCount
());
//
Log.i("Size bitmap", "decodeImageBase64: "+decodeImages.getByteCount());
return
decodeImages
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment