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
21e47254
Commit
21e47254
authored
Aug 26, 2020
by
Alfansyah Fadlian
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'dev' of
https://git.mdd.co.id:44195/muhammadsuryono/meser
into dashboard
parents
b0c11049
928de6d8
Hide whitespace changes
Inline
Side-by-side
Showing
19 changed files
with
347 additions
and
57 deletions
+347
-57
build.gradle
app/build.gradle
+1
-1
CartActivity.java
app/src/main/java/com/yono/messeripos/CartActivity.java
+26
-2
FormProductActivity.java
...rc/main/java/com/yono/messeripos/FormProductActivity.java
+3
-1
MainActivity.java
app/src/main/java/com/yono/messeripos/MainActivity.java
+137
-19
CartAdapter.java
...rc/main/java/com/yono/messeripos/adapter/CartAdapter.java
+25
-7
CategoryAdapter.java
...ain/java/com/yono/messeripos/adapter/CategoryAdapter.java
+13
-6
ProductAdapter.java
...main/java/com/yono/messeripos/adapter/ProductAdapter.java
+6
-10
CategoryServise.java
...java/com/yono/messeripos/api/service/CategoryServise.java
+6
-0
CartDaos.java
app/src/main/java/com/yono/messeripos/daos/CartDaos.java
+4
-1
CategoryModels.java
.../main/java/com/yono/messeripos/models/CategoryModels.java
+12
-1
MainViewModels.java
.../main/java/com/yono/messeripos/models/MainViewModels.java
+34
-6
MainViewModelsCart.java
...n/java/com/yono/messeripos/models/MainViewModelsCart.java
+2
-0
ProductCartModels.java
...in/java/com/yono/messeripos/models/ProductCartModels.java
+4
-0
CartRepositories.java
...va/com/yono/messeripos/repositories/CartRepositories.java
+4
-0
Utils.java
app/src/main/java/com/yono/messeripos/utils/Utils.java
+32
-0
no.jpg
app/src/main/res/drawable/no.jpg
+0
-0
activity_main.xml
app/src/main/res/layout/activity_main.xml
+33
-1
item_cart.xml
app/src/main/res/layout/item_cart.xml
+2
-2
item_category.xml
app/src/main/res/layout/item_category.xml
+3
-0
No files found.
app/build.gradle
View file @
21e47254
...
...
@@ -6,7 +6,7 @@ android {
defaultConfig
{
applicationId
"com.yono.messeripos"
minSdkVersion
2
3
minSdkVersion
2
2
targetSdkVersion
30
versionCode
1
versionName
"1.0"
...
...
app/src/main/java/com/yono/messeripos/CartActivity.java
View file @
21e47254
...
...
@@ -51,7 +51,6 @@ public class CartActivity extends AppCompatActivity {
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
setContentView
(
R
.
layout
.
activity_cart
);
Window
w
=
getWindow
();
w
.
setFlags
(
WindowManager
.
LayoutParams
.
FLAG_LAYOUT_NO_LIMITS
,
WindowManager
.
LayoutParams
.
FLAG_LAYOUT_NO_LIMITS
);
...
...
@@ -63,6 +62,7 @@ public class CartActivity extends AppCompatActivity {
toolbars
.
setNavigationOnClickListener
(
view
->
onBackPressed
());
recyclerView
=
findViewById
(
R
.
id
.
rvCart
);
cartAdapter
=
new
CartAdapter
();
LinearLayoutManager
llm
=
new
LinearLayoutManager
(
this
);
recyclerView
.
setLayoutManager
(
llm
);
...
...
@@ -76,12 +76,36 @@ public class CartActivity extends AppCompatActivity {
@Override
public
void
onChanged
(
List
<
ProductCartModels
>
productCartModels
)
{
if
(
productCartModels
!=
null
){
cartAdapter
=
new
CartAdapter
(
CartActivity
.
this
,
productCartModels
);
cartAdapter
.
set
CartAdapter
(
CartActivity
.
this
,
productCartModels
);
recyclerView
.
setAdapter
(
cartAdapter
);
}
}
});
cartAdapter
.
setListener
(
new
CartAdapter
.
CartListener
()
{
@Override
public
void
onDelete
(
ProductCartModels
productCartModels
)
{
modelsCart
.
deleteCart
(
productCartModels
);
}
@Override
public
void
onUpdateQuantityPlus
(
ProductCartModels
productCartModels
)
{
}
@Override
public
void
onUpdateQuantityMinus
(
ProductCartModels
productCartModels
)
{
}
@Override
public
void
onCheckout
(
ProductCartModels
productCartModels
)
{
}
});
//
// counter = Integer.parseInt(tvQtyView.getText().toString());
// prices = Integer.parseInt(tvPrice.getText().toString());
...
...
app/src/main/java/com/yono/messeripos/FormProductActivity.java
View file @
21e47254
...
...
@@ -21,6 +21,7 @@ import android.widget.Toast;
import
androidx.annotation.NonNull
;
import
androidx.annotation.Nullable
;
import
androidx.annotation.RequiresApi
;
import
androidx.appcompat.app.AppCompatActivity
;
import
androidx.core.content.ContextCompat
;
import
androidx.core.content.FileProvider
;
...
...
@@ -150,12 +151,13 @@ public class FormProductActivity extends AppCompatActivity {
}
// if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
// Log.d("Get filepath photo", "" + file.get
Name
());
// Log.d("Get filepath photo", "" + file.get
AbsolutePath
());
// binding.setPhoto(file.getAbsolutePath());
// productModels.setImageProduct(file.getName());
// }
}
@RequiresApi
(
api
=
Build
.
VERSION_CODES
.
M
)
@Override
public
void
onRequestPermissionsResult
(
int
requestCode
,
@NonNull
String
[]
permissions
,
@NonNull
int
[]
grantResults
)
{
super
.
onRequestPermissionsResult
(
requestCode
,
permissions
,
grantResults
);
...
...
app/src/main/java/com/yono/messeripos/MainActivity.java
View file @
21e47254
package
com
.
yono
.
messeripos
;
import
android.annotation.SuppressLint
;
import
android.app.ProgressDialog
;
import
android.content.Intent
;
import
android.os.Build
;
import
android.os.Bundle
;
...
...
@@ -14,7 +16,9 @@ import android.widget.ImageView;
import
android.widget.TextView
;
import
android.widget.Toast
;
import
androidx.annotation.NonNull
;
import
androidx.annotation.RequiresApi
;
import
androidx.appcompat.app.AlertDialog
;
import
androidx.appcompat.app.AppCompatActivity
;
import
androidx.appcompat.widget.Toolbar
;
import
androidx.databinding.DataBindingUtil
;
...
...
@@ -26,6 +30,7 @@ import androidx.recyclerview.widget.LinearLayoutManager;
import
com.google.android.material.appbar.MaterialToolbar
;
import
com.google.android.material.button.MaterialButton
;
import
com.google.android.material.snackbar.Snackbar
;
import
com.yono.messeripos.adapter.CartAdapter
;
import
com.yono.messeripos.adapter.ProductAdapter
;
import
com.yono.messeripos.databinding.ActivityMainBinding
;
...
...
@@ -43,6 +48,7 @@ import com.yono.messeripos.models.MainViewModels;
import
com.yono.messeripos.models.ProductModels
;
import
com.yono.messeripos.response.DataResponse
;
import
java.lang.reflect.Array
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.stream.Collector
;
...
...
@@ -66,6 +72,8 @@ public class MainActivity extends AppCompatActivity {
ProductAdapter
adapter
=
new
ProductAdapter
();
binding
=
DataBindingUtil
.
setContentView
(
this
,
R
.
layout
.
activity_main
);
binding
.
rvProduct
.
setAdapter
(
adapter
);
binding
.
appBarUpdate
.
setVisibility
(
View
.
GONE
);
showLoading
(
true
);
categoryAdapter
=
new
CategoryAdapter
();
productAdapter
=
new
ProductAdapter
();
...
...
@@ -87,7 +95,16 @@ public class MainActivity extends AppCompatActivity {
startActivity
(
new
Intent
(
getApplicationContext
(),
CartActivity
.
class
));
}
else
if
(
id
==
R
.
id
.
update
){
status_update
=
true
;
binding
.
topAppBar
.
setVisibility
(
View
.
GONE
);
binding
.
rvCategory
.
setVisibility
(
View
.
GONE
);
binding
.
appBarUpdate
.
setVisibility
(
View
.
VISIBLE
);
MaterialToolbar
toolbars
=
findViewById
(
R
.
id
.
appBarUpdate
);
setSupportActionBar
(
toolbars
);
getSupportActionBar
().
setDisplayHomeAsUpEnabled
(
true
);
getSupportActionBar
().
setDisplayShowHomeEnabled
(
true
);
getSupportActionBar
().
setTitle
(
"Update Product"
);
toolbars
.
setNavigationOnClickListener
(
view
->
updateFinish
());
productAdapter
.
notifyDataSetChanged
();
}
else
if
(
id
==
R
.
id
.
create
)
{
startActivity
(
new
Intent
(
getApplicationContext
(),
FormProductActivity
.
class
));
...
...
@@ -119,6 +136,40 @@ public class MainActivity extends AppCompatActivity {
mainViewModels
=
ViewModelProviders
.
of
(
this
).
get
(
MainViewModels
.
class
);
binding
.
imgEmpty
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
view
)
{
showLoading
(
true
);
mainViewModels
.
getProduct
().
observe
(
MainActivity
.
this
,
new
Observer
<
DataResponse
<
List
<
ProductModels
<
CategoryModels
>>>>()
{
@Override
public
void
onChanged
(
DataResponse
<
List
<
ProductModels
<
CategoryModels
>>>
listDataResponse
)
{
if
(
listDataResponse
!=
null
)
{
List
<
ProductModels
<
CategoryModels
>>
productModels
=
listDataResponse
.
getData
();
ArrayList
<
ProductModels
>
productModelsArrayList
=
new
ArrayList
<>();
productModelsArrayList
.
addAll
(
productModels
);
showLoading
(
false
);
if
(
productModelsArrayList
==
null
){
binding
.
rvProduct
.
setVisibility
(
View
.
GONE
);
binding
.
imgEmpty
.
setVisibility
(
View
.
VISIBLE
);
showLoading
(
false
);
}
else
{
productAdapter
.
setProduct
(
MainActivity
.
this
,
productModelsArrayList
);
binding
.
rvProduct
.
setLayoutManager
(
new
GridLayoutManager
(
MainActivity
.
this
,
2
));
binding
.
rvProduct
.
setAdapter
(
productAdapter
);
productAdapter
.
notifyDataSetChanged
();
showLoading
(
false
);
}
}
String
js
=
new
Gson
().
toJson
(
listDataResponse
);
Log
.
d
(
"Get data from products"
,
"Response "
+
js
);
}
});
}
});
mainViewModels
.
getProduct
().
observe
(
this
,
new
Observer
<
DataResponse
<
List
<
ProductModels
<
CategoryModels
>>>>()
{
@Override
public
void
onChanged
(
DataResponse
<
List
<
ProductModels
<
CategoryModels
>>>
listDataResponse
)
{
...
...
@@ -127,9 +178,16 @@ public class MainActivity extends AppCompatActivity {
ArrayList
<
ProductModels
>
productModelsArrayList
=
new
ArrayList
<>();
productModelsArrayList
.
addAll
(
productModels
);
productAdapter
.
setProduct
(
MainActivity
.
this
,
productModelsArrayList
);
binding
.
rvProduct
.
setLayoutManager
(
new
GridLayoutManager
(
MainActivity
.
this
,
2
));
binding
.
rvProduct
.
setAdapter
(
productAdapter
);
showLoading
(
false
);
if
(
productModelsArrayList
.
isEmpty
()){
binding
.
rvProduct
.
setVisibility
(
View
.
GONE
);
binding
.
imgEmpty
.
setVisibility
(
View
.
VISIBLE
);
binding
.
imgEmpty
.
bringToFront
();
}
else
{
productAdapter
.
setProduct
(
MainActivity
.
this
,
productModelsArrayList
);
binding
.
rvProduct
.
setLayoutManager
(
new
GridLayoutManager
(
MainActivity
.
this
,
2
));
binding
.
rvProduct
.
setAdapter
(
productAdapter
);
}
}
...
...
@@ -155,7 +213,6 @@ public class MainActivity extends AppCompatActivity {
@RequiresApi
(
api
=
Build
.
VERSION_CODES
.
N
)
@Override
public
void
onChanged
(
List
<
ProductCartModels
>
productCartModels
)
{
String
s
=
new
Gson
().
toJson
(
productCartModels
);
if
(
productCartModels
.
isEmpty
()){
mainViewModelsCart
.
insertCart
(
new
ProductCartModels
(
1233
,
...
...
@@ -166,24 +223,69 @@ public class MainActivity extends AppCompatActivity {
0
));
Log
.
i
(
"Add data cart"
,
"onChanged: Berhasil ditambahkan"
);
}
else
{
// ProductCartModels productCartModels2 = (ProductCartModels) productCartModels.stream().map(productCartModels1 -> {
// productCartModels1.setQuantity_orders(productCartModels1.getQuantity_orders()+1);
// return productCartModels1;
// });
productCartModels
.
stream
().
map
(
productCartModels1
->
{
Log
.
d
(
"click cart"
,
"onChanged: "
+
s
);
productCartModels1
.
setQuantity_orders
(
productCartModels1
.
getQuantity_orders
()+
1
);
// mainViewModelsCart.updateCart(productCartModels1);
return
productCartModels1
;
}).
collect
(
Collectors
.
toList
());
}
else
{
startActivity
(
new
Intent
(
MainActivity
.
this
,
CartActivity
.
class
));
}
}
});
}
});
categoryAdapter
.
setListener
(
new
CategoryAdapter
.
CategoryListener
()
{
@Override
public
void
onGetProduct
(
CategoryModels
categoryModels
)
{
showLoading
(
true
);
ProgressDialog
progressDialog
=
new
ProgressDialog
(
MainActivity
.
this
);
progressDialog
.
setMessage
(
"Loading..."
);
progressDialog
.
show
();
mainViewModels
.
getProductByCategory
(
categoryModels
.
getIdCategory
()).
observe
(
MainActivity
.
this
,
new
Observer
<
List
<
CategoryModels
<
List
<
ProductModels
>>>>()
{
@Override
public
void
onChanged
(
List
<
CategoryModels
<
List
<
ProductModels
>>>
categoryModels
)
{
ProductModels
productModels
=
new
ProductModels
();
for
(
CategoryModels
<
List
<
ProductModels
>>
pd
:
categoryModels
){
for
(
ProductModels
ps
:
pd
.
getProductCategory
()){
Log
.
i
(
"eeee"
,
"onChanged: "
+
ps
.
getProductName
());
productModels
.
setIdProduct
(
ps
.
getIdProduct
());
productModels
.
setProductName
(
ps
.
getProductName
());
productModels
.
setStockProduct
(
ps
.
getStockProduct
());
productModels
.
setPriceProduct
(
ps
.
getPriceProduct
());
productModels
.
setImageProduct
(
ps
.
getImageProduct
());
}
Log
.
i
(
"ddddd"
,
"onChanged: "
+
pd
.
getProductCategory
());
}
// List<ProductModels> pdf = (List<ProductModels>) productModels;
ArrayList
<
ProductModels
>
pdModel
=
new
ArrayList
<>();
productAdapter
.
setProduct
(
MainActivity
.
this
,
pdModel
);
productAdapter
.
notifyDataSetChanged
();
showLoading
(
false
);
progressDialog
.
dismiss
();
if
(
pdModel
.
isEmpty
()){
binding
.
rvProduct
.
setVisibility
(
View
.
GONE
);
binding
.
imgEmpty
.
setVisibility
(
View
.
VISIBLE
);
}
else
{
binding
.
rvProduct
.
setVisibility
(
View
.
VISIBLE
);
binding
.
imgEmpty
.
setVisibility
(
View
.
GONE
);
}
// binding.rvProduct.setLayoutManager(new GridLayoutManager(MainActivity.this, 2));
// binding.rvProduct.setAdapter(productAdapter);
}
}
);
}
});
}
private
void
updateFinish
()
{
status_update
=
false
;
binding
.
topAppBar
.
setVisibility
(
View
.
VISIBLE
);
binding
.
rvCategory
.
setVisibility
(
View
.
VISIBLE
);
binding
.
appBarUpdate
.
setVisibility
(
View
.
GONE
);
productAdapter
.
notifyDataSetChanged
();
}
@Override
...
...
@@ -192,9 +294,25 @@ public class MainActivity extends AppCompatActivity {
final
MenuItem
menuItem
=
menu
.
findItem
(
R
.
id
.
menu_cart
);
View
actionView
=
menuItem
.
getActionView
();
txtBadge
=
actionView
.
findViewById
(
R
.
id
.
cart_badge
);
return
true
;
}
@Override
public
boolean
onOptionsItemSelected
(
@NonNull
MenuItem
item
)
{
int
id
=
item
.
getItemId
();
if
(
id
==
R
.
id
.
menu_cart
){
Toast
.
makeText
(
MainActivity
.
this
,
"dfjhgkjdfgkdfg"
,
Toast
.
LENGTH_LONG
).
show
();
}
return
super
.
onOptionsItemSelected
(
item
);
}
@SuppressLint
(
"ResourceAsColor"
)
public
void
showLoading
(
boolean
isLoading
)
{
if
(
isLoading
)
{
binding
.
pbLoading
.
setVisibility
(
View
.
VISIBLE
);
}
else
{
binding
.
pbLoading
.
setVisibility
(
View
.
GONE
);
}
}
}
\ No newline at end of file
app/src/main/java/com/yono/messeripos/adapter/CartAdapter.java
View file @
21e47254
...
...
@@ -14,7 +14,9 @@ import com.google.gson.Gson;
import
com.yono.messeripos.R
;
import
com.yono.messeripos.databinding.ItemCartBinding
;
import
com.yono.messeripos.models.CartModels
;
import
com.yono.messeripos.models.CategoryModels
;
import
com.yono.messeripos.models.ProductCartModels
;
import
com.yono.messeripos.utils.Utils
;
import
java.text.NumberFormat
;
import
java.util.ArrayList
;
...
...
@@ -26,8 +28,25 @@ public class CartAdapter extends RecyclerView.Adapter<CartAdapter.MyViewHolder>
private
List
<
ProductCartModels
>
cartModels
;
private
int
price
;
Context
context
;
Utils
utils
=
new
Utils
();
public
CartAdapter
(
Context
context
,
List
<
ProductCartModels
>
cartModels
)
{
public
interface
CartListener
{
void
onDelete
(
ProductCartModels
productCartModels
);
void
onUpdateQuantityPlus
(
ProductCartModels
productCartModels
);
void
onUpdateQuantityMinus
(
ProductCartModels
productCartModels
);
void
onCheckout
(
ProductCartModels
productCartModels
);
}
private
CartListener
listener
;
public
void
setListener
(
CartListener
listener
)
{
this
.
listener
=
listener
;
}
public
void
setCartAdapter
(
Context
context
,
List
<
ProductCartModels
>
cartModels
)
{
this
.
cartModels
=
cartModels
;
this
.
context
=
context
;
// String gs = new Gson().toJson(cartModels);
...
...
@@ -59,6 +78,7 @@ public class CartAdapter extends RecyclerView.Adapter<CartAdapter.MyViewHolder>
}
public
class
MyViewHolder
extends
RecyclerView
.
ViewHolder
{
private
long
subtotal
=
0
;
private
ItemCartBinding
binding
;
public
MyViewHolder
(
@NonNull
ItemCartBinding
binding
)
{
...
...
@@ -68,14 +88,12 @@ public class CartAdapter extends RecyclerView.Adapter<CartAdapter.MyViewHolder>
public
void
bindData
(
ProductCartModels
cartModels
)
{
binding
.
setCarts
(
cartModels
);
// price = binding.getPrice(
);
binding
.
setPrice
(
utils
.
convertPrice
(
"Rp. "
,
cartModels
.
getPrice_orders
())
);
}
subtotal
=
cartModels
.
getPrice_orders
()
*
cartModels
.
getQuantity_orders
();
private
NumberFormat
setToRp
()
{
Locale
ID
=
new
Locale
(
"in"
,
"ID"
);
binding
.
setSubTotal
(
utils
.
convertPrice
(
"Rp. "
,
subtotal
));
return
NumberFormat
.
getCurrencyInstance
(
ID
);
}
}
}
}
app/src/main/java/com/yono/messeripos/adapter/CategoryAdapter.java
View file @
21e47254
...
...
@@ -12,6 +12,7 @@ import androidx.recyclerview.widget.RecyclerView;
import
com.yono.messeripos.R
;
import
com.yono.messeripos.databinding.ItemCategoryBinding
;
import
com.yono.messeripos.models.CategoryModels
;
import
com.yono.messeripos.models.ProductModels
;
import
java.util.ArrayList
;
...
...
@@ -20,6 +21,17 @@ public class CategoryAdapter extends RecyclerView.Adapter<CategoryAdapter.MyView
private
ArrayList
<
CategoryModels
>
categoryModels
;
Context
context
;
public
interface
CategoryListener
{
void
onGetProduct
(
CategoryModels
categoryModels
);
}
private
CategoryListener
listener
;
public
void
setListener
(
CategoryListener
listener
)
{
this
.
listener
=
listener
;
}
public
void
setCategoriAdapter
(
Context
context
,
ArrayList
<
CategoryModels
>
categoryModels
){
this
.
categoryModels
=
categoryModels
;
this
.
context
=
context
;
...
...
@@ -58,12 +70,7 @@ public class CategoryAdapter extends RecyclerView.Adapter<CategoryAdapter.MyView
public
void
binData
(
CategoryModels
categoryModels
){
binding
.
setCategory
(
categoryModels
);
binding
.
cvCategory
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
view
)
{
binding
.
cvCategory
.
toggle
();
}
});
binding
.
cvCategory
.
setOnClickListener
(
view
->
listener
.
onGetProduct
(
categoryModels
));
}
}
}
app/src/main/java/com/yono/messeripos/adapter/ProductAdapter.java
View file @
21e47254
...
...
@@ -28,6 +28,7 @@ import com.yono.messeripos.models.CartModels;
import
com.yono.messeripos.models.MainViewModelsCart
;
import
com.yono.messeripos.models.ProductCartModels
;
import
com.yono.messeripos.models.ProductModels
;
import
com.yono.messeripos.utils.Utils
;
import
java.text.DecimalFormat
;
import
java.text.DecimalFormatSymbols
;
...
...
@@ -37,6 +38,7 @@ public class ProductAdapter extends RecyclerView.Adapter<ProductAdapter.MyViewHo
private
ArrayList
<
ProductModels
>
productModels
=
new
ArrayList
<>();
Context
context
;
MainViewModelsCart
mainViewModelsCart
;
Utils
utils
=
new
Utils
();
public
interface
ProductListener
{
void
onUpdate
(
ProductModels
product
);
...
...
@@ -97,21 +99,15 @@ public class ProductAdapter extends RecyclerView.Adapter<ProductAdapter.MyViewHo
public
void
bindData
(
ProductModels
products
)
{
binding
.
setProducts
(
products
);
DecimalFormat
rupiah
=
(
DecimalFormat
)
DecimalFormat
.
getCurrencyInstance
();
DecimalFormatSymbols
format
=
new
DecimalFormatSymbols
();
format
.
setCurrencySymbol
(
"Rp. "
);
format
.
setMonetaryDecimalSeparator
(
','
);
format
.
setGroupingSeparator
(
'.'
);
rupiah
.
setDecimalFormatSymbols
(
format
);
binding
.
setPrice
(
rupiah
.
format
(
products
.
getPriceProduct
()));
binding
.
setPrice
(
utils
.
convertPrice
(
"Rp. "
,
products
.
getPriceProduct
()));
binding
.
setImage
(
products
.
getImageProduct
());
if
(!
MainActivity
.
status_update
)
{
binding
.
btnDelete
.
setVisibility
(
View
.
GONE
);
binding
.
btnEdit
.
setVisibility
(
View
.
GONE
);
}
else
{
binding
.
btnDelete
.
setVisibility
(
View
.
VISIBLE
);
binding
.
btnEdit
.
setVisibility
(
View
.
VISIBLE
);
}
if
(
products
.
getStockProduct
()
==
0
)
{
...
...
app/src/main/java/com/yono/messeripos/api/service/CategoryServise.java
View file @
21e47254
...
...
@@ -2,14 +2,20 @@ package com.yono.messeripos.api.service;
import
com.yono.messeripos.api.ApiHelper
;
import
com.yono.messeripos.models.CategoryModels
;
import
com.yono.messeripos.models.ProductModels
;
import
com.yono.messeripos.response.DataResponse
;
import
java.util.List
;
import
retrofit2.Call
;
import
retrofit2.http.GET
;
import
retrofit2.http.Path
;
import
retrofit2.http.Query
;
public
interface
CategoryServise
{
@GET
(
ApiHelper
.
VERSI_API_1
+
"categories"
)
Call
<
DataResponse
<
List
<
CategoryModels
>>>
getCategory
();
@GET
(
ApiHelper
.
VERSI_API_1
+
"categories-join/{id}"
)
Call
<
DataResponse
<
List
<
CategoryModels
<
List
<
ProductModels
>>>>>
getCategoryById
(
@Path
(
"id"
)
int
id
);
}
app/src/main/java/com/yono/messeripos/daos/CartDaos.java
View file @
21e47254
...
...
@@ -25,9 +25,12 @@ public interface CartDaos {
@Insert
(
onConflict
=
OnConflictStrategy
.
IGNORE
)
public
void
insertProduct
(
ProductCartModels
product
);
@Update
@Update
(
onConflict
=
OnConflictStrategy
.
IGNORE
)
public
void
updateProduct
(
ProductCartModels
product
);
@Query
(
"UPDATE carts SET quantity_orders = :qty WHERE id = :idCart"
)
public
void
updateCart
(
long
qty
,
long
idCart
);
@Delete
public
void
deleteProduct
(
ProductCartModels
product
);
...
...
app/src/main/java/com/yono/messeripos/models/CategoryModels.java
View file @
21e47254
...
...
@@ -2,13 +2,16 @@ package com.yono.messeripos.models;
import
com.google.gson.annotations.SerializedName
;
public
class
CategoryModels
{
public
class
CategoryModels
<
T
>
{
@SerializedName
(
"id"
)
private
int
idCategory
;
@SerializedName
(
"name"
)
private
String
nameCategory
;
@SerializedName
(
"product"
)
private
T
productCategory
;
public
int
getIdCategory
()
{
return
idCategory
;
}
...
...
@@ -24,4 +27,12 @@ public class CategoryModels {
public
void
setNameCategory
(
String
nameCategory
)
{
this
.
nameCategory
=
nameCategory
;
}
public
T
getProductCategory
()
{
return
productCategory
;
}
public
void
setProductCategory
(
T
productCategory
)
{
this
.
productCategory
=
productCategory
;
}
}
app/src/main/java/com/yono/messeripos/models/MainViewModels.java
View file @
21e47254
...
...
@@ -2,6 +2,7 @@ package com.yono.messeripos.models;
import
android.util.Log
;
import
androidx.lifecycle.LiveData
;
import
androidx.lifecycle.MutableLiveData
;
import
androidx.lifecycle.ViewModel
;
...
...
@@ -21,6 +22,7 @@ import retrofit2.Response;
public
class
MainViewModels
extends
ViewModel
{
MutableLiveData
<
DataResponse
<
List
<
ProductModels
<
CategoryModels
>>>>
productList
;
MutableLiveData
<
List
<
CategoryModels
<
List
<
ProductModels
>>>>
productByCategory
;
MutableLiveData
<
DataResponse
<
List
<
CategoryModels
>>>
categoryList
;
MutableLiveData
<
DataResponse
<
UsersModels
>>
usersLogin
;
...
...
@@ -29,18 +31,45 @@ public class MainViewModels extends ViewModel {
public
MainViewModels
(){
productList
=
new
MutableLiveData
<>();
categoryList
=
new
MutableLiveData
<>();
productByCategory
=
new
MutableLiveData
<>();
}
public
Mutable
LiveData
<
DataResponse
<
List
<
ProductModels
<
CategoryModels
>>>>
getProduct
(){
public
LiveData
<
DataResponse
<
List
<
ProductModels
<
CategoryModels
>>>>
getProduct
(){
getProductList
();
return
productList
;
}
public
Mutable
LiveData
<
DataResponse
<
List
<
CategoryModels
>>>
getCategory
(){
public
LiveData
<
DataResponse
<
List
<
CategoryModels
>>>
getCategory
(){
getCategoryList
();
return
categoryList
;
}
public
LiveData
<
List
<
CategoryModels
<
List
<
ProductModels
>>>>
getProductByCategory
(
int
id
){
getDataProductByCategory
(
id
);
return
productByCategory
;
}
private
void
getDataProductByCategory
(
int
id
)
{
CategoryServise
categoryServise
=
client
.
Client
(
CategoryServise
.
class
);
categoryServise
.
getCategoryById
(
id
).
enqueue
(
new
Callback
<
DataResponse
<
List
<
CategoryModels
<
List
<
ProductModels
>>>>>()
{
@Override
public
void
onResponse
(
Call
<
DataResponse
<
List
<
CategoryModels
<
List
<
ProductModels
>>>>>
call
,
Response
<
DataResponse
<
List
<
CategoryModels
<
List
<
ProductModels
>>>>>
response
)
{
String
js
=
new
Gson
().
toJson
(
response
.
body
());
Log
.
i
(
"Get data by category"
,
"onResponse: "
+
js
);
if
(
response
!=
null
){
productByCategory
.
setValue
(
response
.
body
().
getData
());
}
}
@Override
public
void
onFailure
(
Call
<
DataResponse
<
List
<
CategoryModels
<
List
<
ProductModels
>>>>>
call
,
Throwable
t
)
{
Log
.
e
(
"Error!"
,
"onFailure: "
,
t
);
}
});
}
public
MutableLiveData
<
DataResponse
<
UsersModels
>>
checkLogin
(
UsersModels
usersModels
){
usersLogin
=
new
MutableLiveData
<>();
PeriksaLogin
(
usersModels
);
...
...
@@ -67,25 +96,24 @@ public class MainViewModels extends ViewModel {
});
}
private
void
getProductList
()
{
ProductService
productService
=
client
.
Client
(
ProductService
.
class
);
productService
.
getProducts
().
enqueue
(
new
Callback
<
DataResponse
<
List
<
ProductModels
<
CategoryModels
>>>>()
{
@Override
public
void
onResponse
(
Call
<
DataResponse
<
List
<
ProductModels
<
CategoryModels
>>>>
call
,
Response
<
DataResponse
<
List
<
ProductModels
<
CategoryModels
>>>>
response
)
{
public
void
onResponse
(
Call
<
DataResponse
<
List
<
ProductModels
<
CategoryModels
>>>>
call
,
Response
<
DataResponse
<
List
<
ProductModels
<
CategoryModels
>>>>
response
)
{
if
(
response
.
body
()
!=
null
){
productList
.
setValue
(
response
.
body
());
}
else
{
productList
.
setValue
(
null
);
}
String
js
=
new
Gson
().
toJson
(
response
.
body
());
Log
.
d
(
"Get Data"
,
"Response "
+
js
);
}
@Override
public
void
onFailure
(
Call
<
DataResponse
<
List
<
ProductModels
<
CategoryModels
>>>>
call
,
Throwable
t
)
{
Log
.
e
(
"Error get product"
,
"Response "
+
t
.
getMessage
());
}
});
}
...
...
app/src/main/java/com/yono/messeripos/models/MainViewModelsCart.java
View file @
21e47254
...
...
@@ -42,6 +42,8 @@ public class MainViewModelsCart extends AndroidViewModel {
public
void
deleteCart
(
ProductCartModels
productCartModels
){
cartRepositories
.
delete
(
productCartModels
);}
public
void
updateQtyCart
(
long
qty
,
long
id
){
cartRepositories
.
updateQty
(
qty
,
id
);}
public
LiveData
<
List
<
ProductCartModels
>>
getCartById
(
long
id
){
return
cartRepositories
.
getDataById
(
id
);
}
...
...
app/src/main/java/com/yono/messeripos/models/ProductCartModels.java
View file @
21e47254
...
...
@@ -32,6 +32,10 @@ public class ProductCartModels implements Parcelable {
@SerializedName
(
"grand_total"
)
private
int
grand_total_orders
;
public
ProductCartModels
(){
}
public
ProductCartModels
(
int
id_orders
,
long
quantity_orders
,
int
id_product_orders
,
...
...
app/src/main/java/com/yono/messeripos/repositories/CartRepositories.java
View file @
21e47254
...
...
@@ -35,6 +35,10 @@ public class CartRepositories {
LocalDatabase
.
databaseWriterExecutor
.
execute
(()
->
cartDaos
.
deleteProduct
(
productCartModels
));
}
public
void
updateQty
(
long
qty
,
long
id
){
LocalDatabase
.
databaseWriterExecutor
.
execute
(()
->
cartDaos
.
updateCart
(
qty
,
id
));
}
public
LiveData
<
List
<
ProductCartModels
>>
getDataById
(
long
id
){
return
cartDaos
.
getCartById
(
id
);
}
...
...
app/src/main/java/com/yono/messeripos/utils/Utils.java
0 → 100644
View file @
21e47254
package
com
.
yono
.
messeripos
.
utils
;
import
java.text.DecimalFormat
;
import
java.text.DecimalFormatSymbols
;
public
class
Utils
{
public
String
convertPrice
(
String
mataUang
,
int
nilai
){
DecimalFormat
rupiah
=
(
DecimalFormat
)
DecimalFormat
.
getCurrencyInstance
();
DecimalFormatSymbols
format
=
new
DecimalFormatSymbols
();
format
.
setCurrencySymbol
(
mataUang
);
format
.
setMonetaryDecimalSeparator
(
','
);
format
.
setGroupingSeparator
(
'.'
);
rupiah
.
setDecimalFormatSymbols
(
format
);
return
rupiah
.
format
(
nilai
);
}
public
String
convertPrice
(
String
mataUang
,
long
nilai
){
DecimalFormat
rupiah
=
(
DecimalFormat
)
DecimalFormat
.
getCurrencyInstance
();
DecimalFormatSymbols
format
=
new
DecimalFormatSymbols
();
format
.
setCurrencySymbol
(
mataUang
);
format
.
setMonetaryDecimalSeparator
(
','
);
format
.
setGroupingSeparator
(
'.'
);
rupiah
.
setDecimalFormatSymbols
(
format
);
return
rupiah
.
format
(
nilai
);
}
}
app/src/main/res/drawable/no.jpg
0 → 100644
View file @
21e47254
28.4 KB
app/src/main/res/layout/activity_main.xml
View file @
21e47254
...
...
@@ -14,6 +14,8 @@
android:layout_height=
"match_parent"
tools:context=
".MainActivity"
>
<com.google.android.material.appbar.AppBarLayout
android:id=
"@+id/topBar"
android:layout_width=
"match_parent"
...
...
@@ -22,9 +24,20 @@
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintTop_toTopOf=
"parent"
android:paddingTop=
"20dp"
android:paddingStart=
"15dp"
tools:ignore=
"RtlSymmetry"
>
<com.google.android.material.appbar.MaterialToolbar
android:id=
"@+id/appBarUpdate"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:elevation=
"0dp"
android:paddingTop=
"0dp"
android:background=
"@drawable/gradient"
style=
"@style/Widget.MaterialComponents.Toolbar.Primary"
xmlns:android=
"http://schemas.android.com/apk/res/android"
>
</com.google.android.material.appbar.MaterialToolbar>
<com.google.android.material.appbar.MaterialToolbar
android:id=
"@+id/topAppBar"
android:layout_width=
"match_parent"
...
...
@@ -59,6 +72,25 @@
android:layout_marginTop=
"10dp"
tools:listitem=
"@layout/item_category"
/>
<ImageView
android:id=
"@+id/imgEmpty"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:visibility=
"gone"
android:src=
"@drawable/no"
app:layout_constraintTop_toBottomOf=
"@id/rvCategory"
/>
<ProgressBar
android:id=
"@+id/pbLoading"
android:indeterminateTint=
"@color/colorAccent"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:backgroundTint=
"@color/colorAccent"
app:layout_constraintTop_toTopOf=
"parent"
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintEnd_toEndOf=
"parent"
/>
<!-- Scrollable content -->
<androidx.recyclerview.widget.RecyclerView
android:id=
"@+id/rvProduct"
...
...
app/src/main/res/layout/item_cart.xml
View file @
21e47254
...
...
@@ -17,7 +17,7 @@
type=
"String"
/>
<variable
name=
"
product_name
"
name=
"
subTotal
"
type=
"String"
/>
</data>
...
...
@@ -88,7 +88,7 @@
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:fontFamily=
"@font/roboto"
android:text=
"@
string/hint_price
"
android:text=
"@
{subTotal}
"
android:textFontWeight=
"600"
android:textSize=
"16sp"
app:layout_constraintBottom_toBottomOf=
"@id/tvQuantity"
...
...
app/src/main/res/layout/item_category.xml
View file @
21e47254
...
...
@@ -19,6 +19,9 @@
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:backgroundTint=
"#2041B8"
android:clickable=
"true"
android:focusable=
"true"
android:checkable=
"true"
app:cardCornerRadius=
"40dp"
>
...
...
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