Commit 610ba835 authored by Alfansyah Fadlian's avatar Alfansyah Fadlian

Merge branch 'dev' of https://git.mdd.co.id:44195/muhammadsuryono/meser into dev

parents 82fc4bab 6d594ba1
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="JDK" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
......
......@@ -3,6 +3,7 @@ package com.yono.messeripos;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
......@@ -11,19 +12,36 @@ import android.view.WindowManager;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.core.content.ContextCompat;
import androidx.databinding.DataBindingUtil;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProviders;
import androidx.recyclerview.widget.LinearLayoutManager;
import com.google.android.material.appbar.MaterialToolbar;
import com.google.gson.Gson;
import com.yono.messeripos.adapter.CategoryAdapter;
import com.yono.messeripos.databinding.ActivityMainBinding;
import com.yono.messeripos.models.CategoryModels;
import com.yono.messeripos.models.MainViewModels;
import com.yono.messeripos.response.DataResponse;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends AppCompatActivity {
MaterialToolbar toolbar;
MainViewModels mainViewModels;
ActivityMainBinding binding;
CategoryAdapter categoryAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// setContentView(R.layout.activity_main);
categoryAdapter = new CategoryAdapter();
binding = DataBindingUtil.setContentView(this, R.layout.activity_main);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
......@@ -46,9 +64,26 @@ public class MainActivity extends AppCompatActivity {
}
});
MainViewModels mainViewModels = ViewModelProviders.of(this).get(MainViewModels.class);
mainViewModels.getProduct();
mainViewModels.getCategory();
mainViewModels = ViewModelProviders.of(this).get(MainViewModels.class);
mainViewModels.getCategory().observe(this, new Observer<DataResponse<List<CategoryModels>>>() {
@Override
public void onChanged(DataResponse<List<CategoryModels>> listDataResponse) {
if (listDataResponse != null){
List<CategoryModels> categoryModels = listDataResponse.getData();
ArrayList<CategoryModels> categoryModelsArrayList = new ArrayList<>();
categoryModelsArrayList.addAll(categoryModels);
categoryAdapter.setCategoriAdapter(MainActivity.this, categoryModelsArrayList);
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 category", "Response "+js);
}
});
}
......
//package com.yono.messeripos;
//
//import android.content.Context;
//
//import androidx.appcompat.app.AppCompatActivity;
//
//import com.google.android.material.appbar.MaterialToolbar;
//
//public class ToolbarApp {
//
// public ToolbarApp(Context context, int toolbar, String title) {
//
// MaterialToolbar toolbars = findViewById(toolbar);
// setSupportActionBar(toolbars);
// getSupportActionBar().setDisplayHomeAsUpEnabled(true);
// getSupportActionBar().setDisplayShowHomeEnabled(true);
// getSupportActionBar().setTitle(title);
// }
//}
package com.yono.messeripos;
import android.content.Context;
public class ToolbarApp {
public ToolbarApp(Context context, int toolbar, String title) {
}
}
package com.yono.messeripos.adapter;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.RecyclerView;
import com.yono.messeripos.R;
import com.yono.messeripos.databinding.ItemCategoryBinding;
import com.yono.messeripos.models.CategoryModels;
import java.util.ArrayList;
public class CategoryAdapter extends RecyclerView.Adapter<CategoryAdapter.MyViewHolder> {
private ArrayList<CategoryModels> categoryModels;
Context context;
public void setCategoriAdapter(Context context, ArrayList<CategoryModels> categoryModels){
this.categoryModels = categoryModels;
this.context = context;
notifyDataSetChanged();
}
@NonNull
@Override
public CategoryAdapter.MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
return null;
ItemCategoryBinding itemCategoryBinding = DataBindingUtil.inflate(
LayoutInflater.from(parent.getContext()),
R.layout.item_category,
parent,
false
);
return new MyViewHolder(itemCategoryBinding);
}
@Override
public void onBindViewHolder(@NonNull CategoryAdapter.MyViewHolder holder, int position) {
holder.binData(categoryModels.get(position));
}
@Override
public int getItemCount() {
return 0;
return categoryModels.size();
}
public class MyViewHolder extends RecyclerView.ViewHolder {
public MyViewHolder(@NonNull View itemView) {
super(itemView);
ItemCategoryBinding binding;
public MyViewHolder(@NonNull ItemCategoryBinding itemView) {
super(itemView.getRoot());
this.binding = itemView;
}
public void binData(CategoryModels categoryModels){
binding.setCategory(categoryModels);
}
}
}
package com.yono.messeripos.daos;
import androidx.lifecycle.LiveData;
import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.OnConflictStrategy;
import androidx.room.Query;
import androidx.room.Update;
import com.yono.messeripos.models.ProductCartModels;
import java.util.List;
@Dao
public interface CartDaos {
@Query("SELECT * FROM carts ORDER BY id DESC")
public LiveData<List<ProductCartModels>> getCart();
@Insert(onConflict = OnConflictStrategy.IGNORE)
public void insertProduct(ProductCartModels product);
@Update
public void updateProduct(ProductCartModels product);
@Delete
public void deleteProduct(ProductCartModels product);
}
package com.yono.messeripos.database;
import android.content.Context;
import androidx.annotation.NonNull;
import androidx.room.Database;
import androidx.room.DatabaseConfiguration;
import androidx.room.InvalidationTracker;
import androidx.room.Room;
import androidx.room.RoomDatabase;
import androidx.sqlite.db.SupportSQLiteOpenHelper;
import com.yono.messeripos.daos.CartDaos;
import com.yono.messeripos.models.ProductCartModels;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@Database(entities = {ProductCartModels.class}, version = 1, exportSchema = false)
public abstract class LocalDatabase extends RoomDatabase {
......@@ -14,4 +24,37 @@ public abstract class LocalDatabase extends RoomDatabase {
private static volatile LocalDatabase INSTANCE;
private static final int NUMBER_OF_THREADS = 407;
public static final ExecutorService databaseWriterExecutor =
Executors.newFixedThreadPool(NUMBER_OF_THREADS);
public static LocalDatabase geDatabase(Context context){
if (INSTANCE == null){
synchronized (LocalDatabase.class){
if (INSTANCE == null){
INSTANCE = Room.databaseBuilder(context.getApplicationContext(),
LocalDatabase.class, "database_meser").build();
}
}
}
return INSTANCE;
}
@NonNull
@Override
protected SupportSQLiteOpenHelper createOpenHelper(DatabaseConfiguration config) {
return null;
}
@NonNull
@Override
protected InvalidationTracker createInvalidationTracker() {
return null;
}
@Override
public void clearAllTables() {
}
}
......@@ -19,14 +19,17 @@ import retrofit2.Callback;
import retrofit2.Response;
public class MainViewModels extends ViewModel {
MutableLiveData<DataResponse<List<ProductModels<List<CategoryModels>>>>> productList;
MutableLiveData<DataResponse<List<ProductModels<CategoryModels>>>> productList;
MutableLiveData<DataResponse<List<CategoryModels>>> categoryList;
Client client = new Client();
public MainViewModels(){ productList = new MutableLiveData<>();}
public MainViewModels(){
productList = new MutableLiveData<>();
categoryList = new MutableLiveData<>();
}
public MutableLiveData<DataResponse<List<ProductModels<List<CategoryModels>>>>> getProduct(){
public MutableLiveData<DataResponse<List<ProductModels<CategoryModels>>>> getProduct(){
getProductList();
return productList;
}
......@@ -43,6 +46,11 @@ public class MainViewModels extends ViewModel {
@Override
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);
}
......@@ -62,6 +70,11 @@ public class MainViewModels extends ViewModel {
public void onResponse(Call<DataResponse<List<CategoryModels>>> call, Response<DataResponse<List<CategoryModels>>> response) {
String js = new Gson().toJson(response.body());
Log.d("Get Data Category", "Response "+js);
if (response.body() != null){
categoryList.setValue(response.body());
}else {
categoryList.setValue(null);
}
}
@Override
......
package com.yono.messeripos.models;
import android.app.Application;
import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.Transformations;
import com.yono.messeripos.repositories.CartRepositories;
import java.util.List;
public class MainViewModelsCart extends AndroidViewModel {
private MutableLiveData<ProductCartModels> cart = new MutableLiveData<>();
private LiveData<List<ProductCartModels>> productsLive;
private CartRepositories cartRepositories;
public void setProduct(ProductCartModels product){this.cart.setValue(product);}
public LiveData<List<ProductCartModels>> getProduct(){return productsLive;}
public MainViewModelsCart(@NonNull Application application) {
super(application);
cartRepositories = new CartRepositories(application);
}
public void insertCart(ProductCartModels productCartModels){cartRepositories.insert(productCartModels);}
public void updateCart(ProductCartModels productCartModels){cartRepositories.update(productCartModels);}
public void deleteCart(ProductCartModels productCartModels){cartRepositories.delete(productCartModels);}
public MutableLiveData<ProductCartModels> getCart(){
return cart;
}
}
package com.yono.messeripos.repositories;
import android.app.Application;
import androidx.lifecycle.LiveData;
import com.yono.messeripos.daos.CartDaos;
import com.yono.messeripos.database.LocalDatabase;
import com.yono.messeripos.models.ProductCartModels;
import java.util.List;
public class CartRepositories {
private CartDaos cartDaos;
private LiveData<List<ProductCartModels>> products;
public CartRepositories(Application application){
LocalDatabase db = LocalDatabase.geDatabase(application);
cartDaos = db.cartDaos();
products = cartDaos.getCart();
}
public void insert(ProductCartModels productCartModels){
LocalDatabase.databaseWriterExecutor.execute(() -> cartDaos.insertProduct(productCartModels));
}
public void update(ProductCartModels productCartModels){
LocalDatabase.databaseWriterExecutor.execute(() -> cartDaos.insertProduct(productCartModels));
}
public void delete(ProductCartModels productCartModels){
LocalDatabase.databaseWriterExecutor.execute(() -> cartDaos.insertProduct(productCartModels));
}
}
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
xmlns:tools="http://schemas.android.com/tools">
<include
android:id="@+id/topBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
layout="@layout/appbar_dashboard">
</include>
<data>
<variable
name="mainView"
type="com.yono.messeripos.models.MainViewModels" />
</data>
<include
android:id="@+id/category"
android:layout_marginTop="10dp"
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/topBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@+id/topBar"
layout="@layout/item_category"/>
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:paddingStart="15dp"
xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Scrollable content -->
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rvProduct"
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/topAppBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:overScrollMode="never"
android:padding="12sp"
app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
app:spanCount="2"
app:layout_constraintTop_toBottomOf="@id/category"
tools:listitem="@layout/item_list" />
app:menu="@menu/home"
android:elevation="0dp"
app:navigationIcon="@drawable/ic_meser"
android:layout_marginTop="30dp"
style="@style/Widget.MaterialComponents.Toolbar.Primary"
>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#fff"
android:hint="Search"
android:paddingStart="10dp"
android:textColorHint="#fff"
android:outlineSpotShadowColor="#fff"
android:textColorHighlight="#fff"
android:drawableStart="@drawable/ic_baseline_search_24"/>
</com.google.android.material.appbar.MaterialToolbar>
</com.google.android.material.appbar.AppBarLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rvCategory"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginStart="5dp"
app:layout_constraintTop_toBottomOf="@id/topBar"
android:layout_marginTop="10dp"
tools:listitem="@layout/item_category" />
<!-- Scrollable content -->
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rvProduct"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:overScrollMode="never"
android:padding="12sp"
app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
app:spanCount="2"
app:layout_constraintTop_toBottomOf="@id/rvCategory"
tools:listitem="@layout/item_list" />
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<HorizontalScrollView
<layout xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_height="60dp"
android:layout_width="match_parent"
android:scrollbars="none">
xmlns:app="http://schemas.android.com/apk/res-auto">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:paddingStart="10dp"
android:paddingTop="5dp"
android:paddingEnd="10dp"
android:orientation="horizontal">
<data>
<variable
name="category"
type="com.yono.messeripos.models.CategoryModels" />
</data>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_height="40dp"
android:layout_width="wrap_content">
<com.google.android.material.card.MaterialCardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:backgroundTint="@color/ic_launcher_background"
app:cardCornerRadius="15dp">
app:cardCornerRadius="40dp">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
......@@ -43,9 +41,11 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/roboto"
android:text="Food"
android:text="@{category.nameCategory}"
android:textStyle="bold"
android:textSize="20sp"
android:textColor="#fff"
tools:text="@tools:sample/full_names"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/image_cat"
......@@ -58,93 +58,5 @@
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>
<com.google.android.material.card.MaterialCardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="@color/ic_launcher_background"
android:layout_marginStart="20dp"
app:cardCornerRadius="15dp">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/image_cat1"
android:layout_width="30dp"
android:layout_height="50dp"
android:src="@drawable/ic_meser"
android:layout_marginStart="10dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.06"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0"
tools:ignore="MissingConstraints" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/roboto"
android:text="Food"
android:textStyle="bold"
android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/image_cat1"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginStart="10dp"
android:layout_marginEnd="40dp"
tools:ignore="MissingConstraints" />
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>
<com.google.android.material.card.MaterialCardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="@color/ic_launcher_background"
android:layout_marginStart="20dp"
app:cardCornerRadius="15dp">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/image_cat2"
android:layout_width="30dp"
android:layout_height="50dp"
android:src="@drawable/ic_meser"
android:layout_marginStart="10dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.06"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0"
tools:ignore="MissingConstraints" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/roboto"
android:text="Food"
android:textStyle="bold"
android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/image_cat2"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginStart="10dp"
android:layout_marginEnd="40dp"
tools:ignore="MissingConstraints" />
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>
</LinearLayout>
</HorizontalScrollView>
\ No newline at end of file
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment