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
20daad65
Commit
20daad65
authored
Aug 24, 2020
by
Alfansyah Fadlian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
product binding
parent
251fb334
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
43 additions
and
34 deletions
+43
-34
MainActivity.java
app/src/main/java/com/yono/messeripos/MainActivity.java
+26
-4
ProductAdapter.java
...main/java/com/yono/messeripos/adapter/ProductAdapter.java
+16
-26
activity_main.xml
app/src/main/res/layout/activity_main.xml
+0
-3
item_list.xml
app/src/main/res/layout/item_list.xml
+1
-1
No files found.
app/src/main/java/com/yono/messeripos/MainActivity.java
View file @
20daad65
...
@@ -33,13 +33,14 @@ import com.yono.messeripos.response.DataResponse;
...
@@ -33,13 +33,14 @@ import com.yono.messeripos.response.DataResponse;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Locale
;
public
class
MainActivity
extends
AppCompatActivity
{
public
class
MainActivity
extends
AppCompatActivity
{
MaterialToolbar
toolbar
;
MaterialToolbar
toolbar
;
MainViewModels
mainViewModels
;
MainViewModels
mainViewModels
;
ActivityMainBinding
binding
;
ActivityMainBinding
binding
;
CategoryAdapter
categoryAdapter
;
CategoryAdapter
categoryAdapter
;
ProductAdapter
productAdapter
;
@Override
@Override
...
@@ -52,10 +53,10 @@ public class MainActivity extends AppCompatActivity {
...
@@ -52,10 +53,10 @@ public class MainActivity extends AppCompatActivity {
// setContentView(R.layout.activity_main);
// setContentView(R.layout.activity_main);
categoryAdapter
=
new
CategoryAdapter
();
categoryAdapter
=
new
CategoryAdapter
();
productAdapter
=
new
ProductAdapter
();
binding
=
DataBindingUtil
.
setContentView
(
this
,
R
.
layout
.
activity_main
);
binding
=
DataBindingUtil
.
setContentView
(
this
,
R
.
layout
.
activity_main
);
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
KITKAT
)
{
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
KITKAT
)
{
Window
w
=
getWindow
();
Window
w
=
getWindow
();
w
.
setFlags
(
WindowManager
.
LayoutParams
.
FLAG_LAYOUT_NO_LIMITS
,
WindowManager
.
LayoutParams
.
FLAG_LAYOUT_NO_LIMITS
);
w
.
setFlags
(
WindowManager
.
LayoutParams
.
FLAG_LAYOUT_NO_LIMITS
,
WindowManager
.
LayoutParams
.
FLAG_LAYOUT_NO_LIMITS
);
...
@@ -81,7 +82,7 @@ public class MainActivity extends AppCompatActivity {
...
@@ -81,7 +82,7 @@ public class MainActivity extends AppCompatActivity {
mainViewModels
.
getCategory
().
observe
(
this
,
new
Observer
<
DataResponse
<
List
<
CategoryModels
>>>()
{
mainViewModels
.
getCategory
().
observe
(
this
,
new
Observer
<
DataResponse
<
List
<
CategoryModels
>>>()
{
@Override
@Override
public
void
onChanged
(
DataResponse
<
List
<
CategoryModels
>>
listDataResponse
)
{
public
void
onChanged
(
DataResponse
<
List
<
CategoryModels
>>
listDataResponse
)
{
if
(
listDataResponse
!=
null
){
if
(
listDataResponse
!=
null
)
{
List
<
CategoryModels
>
categoryModels
=
listDataResponse
.
getData
();
List
<
CategoryModels
>
categoryModels
=
listDataResponse
.
getData
();
ArrayList
<
CategoryModels
>
categoryModelsArrayList
=
new
ArrayList
<>();
ArrayList
<
CategoryModels
>
categoryModelsArrayList
=
new
ArrayList
<>();
...
@@ -93,10 +94,31 @@ public class MainActivity extends AppCompatActivity {
...
@@ -93,10 +94,31 @@ public class MainActivity extends AppCompatActivity {
}
}
String
js
=
new
Gson
().
toJson
(
listDataResponse
);
String
js
=
new
Gson
().
toJson
(
listDataResponse
);
Log
.
d
(
"Get data from category"
,
"Response "
+
js
);
Log
.
d
(
"Get data from category"
,
"Response "
+
js
);
}
}
});
});
mainViewModels
=
ViewModelProviders
.
of
(
this
).
get
(
MainViewModels
.
class
);
mainViewModels
.
getProduct
().
observe
(
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
);
productAdapter
.
setProduct
(
MainActivity
.
this
,
productModelsArrayList
);
binding
.
rvCategory
.
setLayoutManager
(
new
LinearLayoutManager
(
MainActivity
.
this
,
LinearLayoutManager
.
HORIZONTAL
,
false
));
binding
.
rvCategory
.
setAdapter
(
categoryAdapter
);
}
String
js
=
new
Gson
().
toJson
(
listDataResponse
);
Log
.
d
(
"Get data from products"
,
"Response "
+
js
);
}
});
}
}
...
...
app/src/main/java/com/yono/messeripos/adapter/ProductAdapter.java
View file @
20daad65
...
@@ -10,50 +10,41 @@ import androidx.databinding.DataBindingUtil;
...
@@ -10,50 +10,41 @@ import androidx.databinding.DataBindingUtil;
import
androidx.recyclerview.widget.RecyclerView
;
import
androidx.recyclerview.widget.RecyclerView
;
import
com.yono.messeripos.R
;
import
com.yono.messeripos.R
;
import
com.yono.messeripos.databinding.ItemCategoryBinding
;
import
com.yono.messeripos.databinding.ItemListBinding
;
import
com.yono.messeripos.databinding.ItemListBinding
;
import
com.yono.messeripos.models.CategoryModels
;
import
com.yono.messeripos.models.ProductModels
;
import
com.yono.messeripos.models.ProductModels
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.List
;
public
class
ProductAdapter
extends
RecyclerView
.
Adapter
<
ProductAdapter
.
MyViewHolder
>
{
public
class
ProductAdapter
extends
RecyclerView
.
Adapter
<
ProductAdapter
.
MyViewHolder
>
{
private
List
<
ProductModels
>
productModels
;
private
Array
List
<
ProductModels
>
productModels
;
Context
context
;
Context
context
;
public
interface
ProductListener
{
void
onUpdate
(
ProductModels
product
);
void
onDelete
(
ProductModels
product
);
}
private
ProductListener
listener
;
public
void
setListener
(
ProductListener
listener
)
{
this
.
listener
=
listener
;
}
public
void
setProducts
(
List
<
ProductModels
>
product
)
{
this
.
productModels
=
product
;
public
void
setProduct
(
Context
context
,
ArrayList
<
ProductModels
>
productModels
){
this
.
productModels
=
productModels
;
this
.
context
=
context
;
notifyDataSetChanged
();
notifyDataSetChanged
();
}
}
@NonNull
@NonNull
@Override
@Override
public
ProductAdapter
.
MyViewHolder
onCreateViewHolder
(
@NonNull
ViewGroup
parent
,
int
viewType
)
{
public
ProductAdapter
.
MyViewHolder
onCreateViewHolder
(
@NonNull
ViewGroup
parent
,
int
viewType
)
{
return
new
MyViewHolder
(
ItemListBinding
itemListBinding
=
DataBindingUtil
.
inflate
(
DataBindingUtil
.
inflate
(
LayoutInflater
.
from
(
parent
.
getContext
()),
LayoutInflater
.
from
(
parent
.
getContext
()),
R
.
layout
.
item_list
,
R
.
layout
.
item_list
,
parent
,
false
parent
,
)
false
);
);
return
new
MyViewHolder
(
itemListBinding
);
}
}
@Override
@Override
public
void
onBindViewHolder
(
@NonNull
ProductAdapter
.
MyViewHolder
holder
,
int
position
)
{
public
void
onBindViewHolder
(
@NonNull
ProductAdapter
.
MyViewHolder
holder
,
int
position
)
{
holder
.
bindData
(
productModels
.
get
(
position
)
,
listener
);
holder
.
bindData
(
productModels
.
get
(
position
));
}
}
@Override
@Override
...
@@ -64,15 +55,14 @@ public class ProductAdapter extends RecyclerView.Adapter<ProductAdapter.MyViewHo
...
@@ -64,15 +55,14 @@ public class ProductAdapter extends RecyclerView.Adapter<ProductAdapter.MyViewHo
public
class
MyViewHolder
extends
RecyclerView
.
ViewHolder
{
public
class
MyViewHolder
extends
RecyclerView
.
ViewHolder
{
private
ItemListBinding
binding
;
private
ItemListBinding
binding
;
public
MyViewHolder
(
@NonNull
ItemListBinding
binding
)
{
public
MyViewHolder
(
@NonNull
ItemListBinding
binding
)
{
super
(
binding
.
getRoot
());
super
(
binding
.
getRoot
());
this
.
binding
=
binding
;
this
.
binding
=
binding
;
}
}
public
void
bindData
(
ProductModels
product
Models
,
ProductListener
listener
)
{
public
void
bindData
(
ProductModels
product
s
)
{
binding
.
setProduct
(
productModel
s
);
binding
.
setProduct
s
(
product
s
);
}
}
}
}
}
}
app/src/main/res/layout/activity_main.xml
View file @
20daad65
...
@@ -3,9 +3,6 @@
...
@@ -3,9 +3,6 @@
xmlns:app=
"http://schemas.android.com/apk/res-auto"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
xmlns:tools=
"http://schemas.android.com/tools"
>
xmlns:tools=
"http://schemas.android.com/tools"
>
<data>
<data>
<variable
<variable
name=
"mainView"
name=
"mainView"
...
...
app/src/main/res/layout/item_list.xml
View file @
20daad65
...
@@ -5,7 +5,7 @@
...
@@ -5,7 +5,7 @@
<data>
<data>
<variable
<variable
name=
"product"
name=
"product
s
"
type=
"com.yono.messeripos.models.ProductModels"
/>
type=
"com.yono.messeripos.models.ProductModels"
/>
</data>
</data>
...
...
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