Commit d61428bf authored by Muhammad Suryono's avatar Muhammad Suryono

Merge branch 'dev' into cart

parents 45af8af4 975b22fd
......@@ -25,6 +25,10 @@ android {
enabled = true
}
viewBinding {
enabled = true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
......@@ -41,6 +45,11 @@ dependencies {
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
implementation 'com.github.bumptech.glide:glide:4.3.1'
def room_version = "2.2.5"
implementation "androidx.room:room-runtime:$room_version"
annotationProcessor "androidx.room:room-compiler:$room_version"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
......
......@@ -12,8 +12,18 @@ import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.core.content.ContextCompat;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProviders;
import com.google.android.material.appbar.MaterialToolbar;
import com.google.gson.Gson;
import com.yono.messeripos.models.CategoryModels;
import com.yono.messeripos.models.MainViewModels;
import com.yono.messeripos.models.ProductModels;
import com.yono.messeripos.response.DataResponse;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends AppCompatActivity {
......@@ -44,6 +54,11 @@ public class MainActivity extends AppCompatActivity {
return true;
}
});
MainViewModels mainViewModels = ViewModelProviders.of(this).get(MainViewModels.class);
mainViewModels.getProduct();
mainViewModels.getCategory();
}
}
\ No newline at end of file
......@@ -4,14 +4,22 @@ import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import androidx.appcompat.app.AppCompatActivity;
public class SplashScreen extends AppCompatActivity {
ImageView img;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
img = findViewById(R.id.image_splash);
Animation animation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.zoom_in);
img.startAnimation(animation);
new Handler(Looper.getMainLooper()).postDelayed(()->{
startActivity(new Intent(SplashScreen.this, MainActivity.class));
......
package com.yono.messeripos.adapter;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
public class CartAdapter extends RecyclerView.Adapter<CartAdapter.MyViewHolder> {
@NonNull
@Override
public CartAdapter.MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
return null;
}
@Override
public void onBindViewHolder(@NonNull CartAdapter.MyViewHolder holder, int position) {
}
@Override
public int getItemCount() {
return 0;
}
public class MyViewHolder extends RecyclerView.ViewHolder {
public MyViewHolder(@NonNull View itemView) {
super(itemView);
}
}
}
package com.yono.messeripos.adapter;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
public class CategoryAdapter extends RecyclerView.Adapter<CategoryAdapter.MyViewHolder> {
@NonNull
@Override
public CategoryAdapter.MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
return null;
}
@Override
public void onBindViewHolder(@NonNull CategoryAdapter.MyViewHolder holder, int position) {
}
@Override
public int getItemCount() {
return 0;
}
public class MyViewHolder extends RecyclerView.ViewHolder {
public MyViewHolder(@NonNull View itemView) {
super(itemView);
}
}
}
package com.yono.messeripos.adapter;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
public class ProductAdapter extends RecyclerView.Adapter<ProductAdapter.MyViewHolder> {
@NonNull
@Override
public ProductAdapter.MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
return null;
}
@Override
public void onBindViewHolder(@NonNull ProductAdapter.MyViewHolder holder, int position) {
}
@Override
public int getItemCount() {
return 0;
}
public class MyViewHolder extends RecyclerView.ViewHolder {
public MyViewHolder(@NonNull View itemView) {
super(itemView);
}
}
}
package com.yono.messeripos.api;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
public class ApiHelper {
public static final String BASE_URL = "https://rest-api-meser.herokuapp.com/";
public static final String VERSI_API_1 = "api/v1/";
public static Retrofit request(String baseUrl){
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(baseUrl)
.addConverterFactory(GsonConverterFactory.create())
.build();
return retrofit;
}
}
package com.yono.messeripos.api.client;
import com.yono.messeripos.api.ApiHelper;
public class Client {
public <T> T Client(Class<T> service){
return ApiHelper.request(ApiHelper.BASE_URL).create(service);
}
}
package com.yono.messeripos.api.service;
import com.yono.messeripos.api.ApiHelper;
import com.yono.messeripos.models.CategoryModels;
import com.yono.messeripos.response.DataResponse;
import java.util.List;
import retrofit2.Call;
import retrofit2.http.GET;
public interface CategoryServise {
@GET(ApiHelper.VERSI_API_1+"categories")
Call<DataResponse<List<CategoryModels>>> getCategory();
}
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;
public interface ProductService {
@GET(ApiHelper.VERSI_API_1+"products-join")
Call<DataResponse<List<ProductModels<CategoryModels>>>> getProducts();
}
package com.yono.messeripos.daos;
import androidx.room.Dao;
@Dao
public interface CartDaos {
}
package com.yono.messeripos.database;
import androidx.room.Database;
import androidx.room.RoomDatabase;
import com.yono.messeripos.daos.CartDaos;
import com.yono.messeripos.models.ProductCartModels;
@Database(entities = {ProductCartModels.class}, version = 1, exportSchema = false)
public abstract class LocalDatabase extends RoomDatabase {
public abstract CartDaos cartDaos();
private static volatile LocalDatabase INSTANCE;
private static final int NUMBER_OF_THREADS = 407;
}
package com.yono.messeripos.models;
import com.google.gson.annotations.SerializedName;
public class CartModels<T> {
@SerializedName("id")
private String idOrders;
@SerializedName("products")
private T dataOrders;
public String getIdOrders() {
return idOrders;
}
public void setIdOrders(String idOrders) {
this.idOrders = idOrders;
}
public T getDataOrders() {
return dataOrders;
}
public void setDataOrders(T dataOrders) {
this.dataOrders = dataOrders;
}
}
package com.yono.messeripos.models;
import com.google.gson.annotations.SerializedName;
public class CategoryModels {
@SerializedName("id")
private int idCategory;
@SerializedName("name")
private String nameCategory;
public int getIdCategory() {
return idCategory;
}
public void setIdCategory(int idCategory) {
this.idCategory = idCategory;
}
public String getNameCategory() {
return nameCategory;
}
public void setNameCategory(String nameCategory) {
this.nameCategory = nameCategory;
}
}
package com.yono.messeripos.models;
import android.util.Log;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;
import com.google.gson.Gson;
import com.yono.messeripos.api.client.Client;
import com.yono.messeripos.api.service.CategoryServise;
import com.yono.messeripos.api.service.ProductService;
import com.yono.messeripos.response.DataResponse;
import java.util.ArrayList;
import java.util.List;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
public class MainViewModels extends ViewModel {
MutableLiveData<DataResponse<List<ProductModels<List<CategoryModels>>>>> productList;
MutableLiveData<DataResponse<List<CategoryModels>>> categoryList;
Client client = new Client();
public MainViewModels(){ productList = new MutableLiveData<>();}
public MutableLiveData<DataResponse<List<ProductModels<List<CategoryModels>>>>> getProduct(){
getProductList();
return productList;
}
public MutableLiveData<DataResponse<List<CategoryModels>>> getCategory(){
getCategoryList();
return categoryList;
}
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) {
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());
}
});
}
private void getCategoryList(){
CategoryServise categoryServise = client.Client(CategoryServise.class);
categoryServise.getCategory().enqueue(new Callback<DataResponse<List<CategoryModels>>>() {
@Override
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);
}
@Override
public void onFailure(Call<DataResponse<List<CategoryModels>>> call, Throwable t) {
Log.e("Error get product", "Response "+t.getMessage());
}
});
}
}
package com.yono.messeripos.models;
import android.os.Parcel;
import android.os.Parcelable;
import androidx.room.Entity;
import androidx.room.PrimaryKey;
import com.google.gson.annotations.SerializedName;
@Entity(tableName = "carts")
public class ProductCartModels implements Parcelable {
@PrimaryKey(autoGenerate = true)
@SerializedName("id")
private long id;
@SerializedName("id_orders")
private int id_orders;
@SerializedName("quantity")
private long quantity_orders;
@SerializedName("product_id")
private int id_product_orders;
@SerializedName("product_name")
private String product_name_orders;
@SerializedName("price")
private long price_orders;
@SerializedName("grand_total")
private int grand_total_orders;
public ProductCartModels(long id, int id_orders, long quantity_orders,
int id_product_orders, String product_name_orders, long price_orders,
int grand_total_orders) {
this.id = id;
this.id_orders = id_orders;
this.quantity_orders = quantity_orders;
this.id_product_orders = id_product_orders;
this.product_name_orders = product_name_orders;
this.price_orders = price_orders;
this.grand_total_orders = grand_total_orders;
}
protected ProductCartModels(Parcel in) {
id = in.readLong();
id_orders = in.readInt();
quantity_orders = in.readLong();
id_product_orders = in.readInt();
product_name_orders = in.readString();
price_orders = in.readLong();
grand_total_orders = in.readInt();
}
public static final Creator<ProductCartModels> CREATOR = new Creator<ProductCartModels>() {
@Override
public ProductCartModels createFromParcel(Parcel in) {
return new ProductCartModels(in);
}
@Override
public ProductCartModels[] newArray(int size) {
return new ProductCartModels[size];
}
};
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel parcel, int i) {
parcel.writeLong(id);
parcel.writeInt(id_orders);
parcel.writeLong(quantity_orders);
parcel.writeLong(price_orders);
parcel.writeString(product_name_orders);
parcel.writeInt(grand_total_orders);
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public int getId_orders() {
return id_orders;
}
public void setId_orders(int id_orders) {
this.id_orders = id_orders;
}
public long getQuantity_orders() {
return quantity_orders;
}
public void setQuantity_orders(long quantity_orders) {
this.quantity_orders = quantity_orders;
}
public int getId_product_orders() {
return id_product_orders;
}
public void setId_product_orders(int id_product_orders) {
this.id_product_orders = id_product_orders;
}
public String getProduct_name_orders() {
return product_name_orders;
}
public void setProduct_name_orders(String product_name_orders) {
this.product_name_orders = product_name_orders;
}
public long getPrice_orders() {
return price_orders;
}
public void setPrice_orders(long price_orders) {
this.price_orders = price_orders;
}
public int getGrand_total_orders() {
return grand_total_orders;
}
public void setGrand_total_orders(int grand_total_orders) {
this.grand_total_orders = grand_total_orders;
}
}
......@@ -2,11 +2,11 @@ package com.yono.messeripos.models;
import com.google.gson.annotations.SerializedName;
public class ProductModels {
@SerializedName("id_product")
public class ProductModels<T> {
@SerializedName("id")
private int idProduct;
@SerializedName("product_name")
@SerializedName("name")
private String productName;
@SerializedName("price")
......@@ -14,4 +14,47 @@ public class ProductModels {
@SerializedName("stock")
private int stockProduct;
@SerializedName("category")
private T categoryProduct;
public int getIdProduct() {
return idProduct;
}
public void setIdProduct(int idProduct) {
this.idProduct = idProduct;
}
public String getProductName() {
return productName;
}
public void setProductName(String productName) {
this.productName = productName;
}
public int getPriceProduct() {
return priceProduct;
}
public void setPriceProduct(int priceProduct) {
this.priceProduct = priceProduct;
}
public int getStockProduct() {
return stockProduct;
}
public void setStockProduct(int stockProduct) {
this.stockProduct = stockProduct;
}
public T getCategoryProduct() {
return categoryProduct;
}
public void setCategoryProduct(T categoryProduct) {
this.categoryProduct = categoryProduct;
}
}
package com.yono.messeripos.models;
import com.google.gson.annotations.SerializedName;
public class UsersModels {
@SerializedName("username")
private String usernameUsers;
@SerializedName("password")
private String passwordUsers;
public String getUsernameUsers() {
return usernameUsers;
}
public void setUsernameUsers(String usernameUsers) {
this.usernameUsers = usernameUsers;
}
public String getPasswordUsers() {
return passwordUsers;
}
public void setPasswordUsers(String passwordUsers) {
this.passwordUsers = passwordUsers;
}
}
package com.yono.messeripos.response;
import androidx.appcompat.app.AppCompatActivity;
import com.google.gson.annotations.SerializedName;
public class DataResponse<T> {
......@@ -7,13 +9,12 @@ public class DataResponse<T> {
@SerializedName("status")
private Boolean statusData;
@SerializedName("messages")
@SerializedName("message")
private String messageData;
@SerializedName("data")
private T data;
public Boolean getStatusData() {
return statusData;
}
......
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1000"
android:fromXScale="2"
android:fromYScale="2"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="4"
android:toYScale="4" >
</scale>
</set>
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimaryDark">
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
......@@ -6,6 +6,7 @@
android:background="@color/colorPrimaryDark">
<ImageView
android:id="@+id/image_splash"
android:layout_width="100dp"
android:layout_height="100dp"
android:src="@drawable/ic_meser_icon"
......
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