commit
8e49de29da
@ -4,6 +4,8 @@ apply plugin: 'kotlin-android'
|
||||
|
||||
apply plugin: 'kotlin-android-extensions'
|
||||
|
||||
apply plugin: 'kotlin-kapt'
|
||||
|
||||
android {
|
||||
compileSdkVersion 28
|
||||
defaultConfig {
|
||||
@ -43,7 +45,10 @@ android {
|
||||
ext {
|
||||
arch_version = '1.1.1'
|
||||
support_lib_version = '28.0.0'
|
||||
dagger_version = '2.14.1'
|
||||
dagger_version = '2.15'
|
||||
}
|
||||
kapt {
|
||||
generateStubs = true
|
||||
}
|
||||
|
||||
|
||||
@ -91,8 +96,8 @@ dependencies {
|
||||
implementation "com.google.dagger:dagger:$dagger_version"
|
||||
implementation "com.google.dagger:dagger-android:$dagger_version"
|
||||
implementation "com.google.dagger:dagger-android-support:$dagger_version"
|
||||
annotationProcessor "com.google.dagger:dagger-android-processor:$dagger_version"
|
||||
annotationProcessor "com.google.dagger:dagger-compiler:$dagger_version"
|
||||
kapt "com.google.dagger:dagger-android-processor:$dagger_version"
|
||||
kapt "com.google.dagger:dagger-compiler:$dagger_version"
|
||||
|
||||
implementation 'com.squareup.retrofit2:retrofit:2.3.0'
|
||||
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
package="me.gilo.wc">
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
@ -12,7 +13,8 @@
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme"
|
||||
android:usesCleartextTraffic="true">
|
||||
android:usesCleartextTraffic="true"
|
||||
tools:ignore="GoogleAppIndexingWarning">
|
||||
<activity
|
||||
android:name=".ui.order.OrderActivity"
|
||||
android:label="@string/title_activity_order"
|
||||
|
||||
@ -3,8 +3,8 @@ package me.gilo.wc;
|
||||
public class Config {
|
||||
public static String currencySymbol = "Ksh.";
|
||||
|
||||
public static String siteUrl = "http://192.168.100.61/shop/index.php";
|
||||
public static String consumerKey = "ck_da34628a4a69128001876492b842be4cd3c76bf8";
|
||||
public static String consumerSecret = "cs_c3c70248288a60bc21a0cddc81acdc018df1632d";
|
||||
public static String siteUrl = "http://aklin.ir/wp";
|
||||
public static String consumerKey = "ck_c559b86adc5460395e3ae483b852201615d29712";
|
||||
public static String consumerSecret = "cs_5aaa22e54cd35fd42e490ab12c22afb4d99b6225";
|
||||
|
||||
}
|
||||
|
||||
@ -4,31 +4,20 @@ import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.support.v7.app.AppCompatActivity
|
||||
import com.google.firebase.auth.FirebaseAuth
|
||||
import me.gilo.raison.ui.user.onboarding.SignInActivity
|
||||
import me.gilo.raison.ui.user.onboarding.SignUpActivity
|
||||
import me.gilo.wc.ui.customer.BasicCustomerDetailsActivity
|
||||
import me.gilo.wc.ui.customer.BillingAddressActivity
|
||||
import me.gilo.wc.ui.customer.ShippingAddressActivity
|
||||
import me.gilo.wc.ui.home.HomeActivity
|
||||
import me.gilo.wc.ui.onboarding.AnonymousSignInActivity
|
||||
import me.gilo.wc.ui.order.MyOrdersActivity
|
||||
import me.gilo.wc.ui.product.ProductActivity
|
||||
|
||||
class MainActivity : AppCompatActivity() {
|
||||
|
||||
val TAG = "MainActivity";
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_main)
|
||||
|
||||
|
||||
if(FirebaseAuth.getInstance().currentUser != null) {
|
||||
if (FirebaseAuth.getInstance().currentUser != null) {
|
||||
startActivity(Intent(baseContext, MyOrdersActivity::class.java))
|
||||
}else{
|
||||
} else {
|
||||
startActivity(Intent(baseContext, AnonymousSignInActivity::class.java))
|
||||
}
|
||||
|
||||
finish()
|
||||
|
||||
}
|
||||
|
||||
@ -1,32 +0,0 @@
|
||||
package me.gilo.wc;
|
||||
|
||||
import android.app.Application;
|
||||
import dagger.android.AndroidInjector;
|
||||
import dagger.android.DaggerApplication;
|
||||
import io.github.inflationx.calligraphy3.CalligraphyConfig;
|
||||
import io.github.inflationx.calligraphy3.CalligraphyInterceptor;
|
||||
import io.github.inflationx.viewpump.ViewPump;
|
||||
import me.gilo.wc.di.DaggerAppComponent;
|
||||
|
||||
public class WcApp extends DaggerApplication {
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
|
||||
ViewPump.init(ViewPump.builder()
|
||||
.addInterceptor(new CalligraphyInterceptor(
|
||||
new CalligraphyConfig.Builder()
|
||||
.setDefaultFontPath("fonts/GT-America-Regular.otf")
|
||||
.setFontAttrId(R.attr.fontPath)
|
||||
.build()))
|
||||
.build());
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AndroidInjector<? extends DaggerApplication> applicationInjector() {
|
||||
return DaggerAppComponent.create();
|
||||
}
|
||||
}
|
||||
35
app/src/main/java/me/gilo/wc/WcApp.kt
Normal file
35
app/src/main/java/me/gilo/wc/WcApp.kt
Normal file
@ -0,0 +1,35 @@
|
||||
package me.gilo.wc
|
||||
|
||||
import android.app.Application
|
||||
import dagger.android.AndroidInjector
|
||||
import dagger.android.DaggerApplication
|
||||
import io.github.inflationx.calligraphy3.CalligraphyConfig
|
||||
import io.github.inflationx.calligraphy3.CalligraphyInterceptor
|
||||
import io.github.inflationx.viewpump.ViewPump
|
||||
import me.gilo.wc.di.DaggerAppComponent
|
||||
|
||||
class WcApp : DaggerApplication() {
|
||||
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
|
||||
ViewPump.init(
|
||||
ViewPump.builder()
|
||||
.addInterceptor(
|
||||
CalligraphyInterceptor(
|
||||
CalligraphyConfig.Builder()
|
||||
.setDefaultFontPath("fonts/GT-America-Regular.otf")
|
||||
.setFontAttrId(R.attr.fontPath)
|
||||
.build()
|
||||
)
|
||||
)
|
||||
.build()
|
||||
)
|
||||
|
||||
|
||||
}
|
||||
|
||||
override fun applicationInjector(): AndroidInjector<out DaggerApplication> {
|
||||
return DaggerAppComponent.create()
|
||||
}
|
||||
}
|
||||
@ -1,37 +0,0 @@
|
||||
package me.gilo.wc.adapter;
|
||||
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.ViewGroup;
|
||||
import me.gilo.wc.R;
|
||||
import me.gilo.wc.adapter.viewholder.CartViewHolder;
|
||||
import me.gilo.wc.adapter.viewholder.CategoryViewHolder;
|
||||
import me.gilo.wc.models.CartLineItem;
|
||||
import me.gilo.woodroid.models.CartItem;
|
||||
import me.gilo.woodroid.models.Category;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CartAdapter extends RecyclerView.Adapter<CartViewHolder> {
|
||||
private List<CartLineItem> cartLineItems;
|
||||
|
||||
public CartAdapter(List<CartLineItem> cartLineItems) {
|
||||
this.cartLineItems = cartLineItems;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CartViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
return new CartViewHolder(parent.getContext(), LayoutInflater.from(parent.getContext()).inflate(R.layout.single_cart_item, parent, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(CartViewHolder holder, int position) {
|
||||
holder.renderView(cartLineItems.get(position));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return cartLineItems.size() == 0 ? 0 : cartLineItems.size();
|
||||
}
|
||||
}
|
||||
30
app/src/main/java/me/gilo/wc/adapter/CartAdapter.kt
Normal file
30
app/src/main/java/me/gilo/wc/adapter/CartAdapter.kt
Normal file
@ -0,0 +1,30 @@
|
||||
package me.gilo.wc.adapter
|
||||
|
||||
import android.support.v7.widget.RecyclerView
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import me.gilo.wc.R
|
||||
import me.gilo.wc.adapter.viewholder.CartViewHolder
|
||||
import me.gilo.wc.adapter.viewholder.CategoryViewHolder
|
||||
import me.gilo.wc.models.CartLineItem
|
||||
import me.gilo.woodroid.models.CartItem
|
||||
import me.gilo.woodroid.models.Category
|
||||
|
||||
class CartAdapter(private val cartLineItems: List<CartLineItem>) : RecyclerView.Adapter<CartViewHolder>() {
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CartViewHolder {
|
||||
return CartViewHolder(
|
||||
parent.context,
|
||||
LayoutInflater.from(parent.context).inflate(R.layout.single_cart_item, parent, false)
|
||||
)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: CartViewHolder, position: Int) {
|
||||
holder.renderView(cartLineItems[position])
|
||||
}
|
||||
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
return if (cartLineItems.isEmpty()) 0 else cartLineItems.size
|
||||
}
|
||||
}
|
||||
@ -1,34 +0,0 @@
|
||||
package me.gilo.wc.adapter;
|
||||
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.ViewGroup;
|
||||
import me.gilo.wc.R;
|
||||
import me.gilo.wc.adapter.viewholder.CategoryViewHolder;
|
||||
import me.gilo.woodroid.models.Category;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CategoryAdapter extends RecyclerView.Adapter<CategoryViewHolder> {
|
||||
private List<Category> categories;
|
||||
|
||||
public CategoryAdapter(List<Category> categories) {
|
||||
this.categories = categories;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CategoryViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
return new CategoryViewHolder(parent.getContext(), LayoutInflater.from(parent.getContext()).inflate(R.layout.single_category_item, parent, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(CategoryViewHolder holder, int position) {
|
||||
holder.renderView(categories.get(position));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return categories.size() == 0 ? 0 : categories.size();
|
||||
}
|
||||
}
|
||||
27
app/src/main/java/me/gilo/wc/adapter/CategoryAdapter.kt
Normal file
27
app/src/main/java/me/gilo/wc/adapter/CategoryAdapter.kt
Normal file
@ -0,0 +1,27 @@
|
||||
package me.gilo.wc.adapter
|
||||
|
||||
import android.support.v7.widget.RecyclerView
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import me.gilo.wc.R
|
||||
import me.gilo.wc.adapter.viewholder.CategoryViewHolder
|
||||
import me.gilo.woodroid.models.Category
|
||||
|
||||
class CategoryAdapter(private val categories: List<Category>) : RecyclerView.Adapter<CategoryViewHolder>() {
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CategoryViewHolder {
|
||||
return CategoryViewHolder(
|
||||
parent.context,
|
||||
LayoutInflater.from(parent.context).inflate(R.layout.single_category_item, parent, false)
|
||||
)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: CategoryViewHolder, position: Int) {
|
||||
holder.renderView(categories[position])
|
||||
}
|
||||
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
return if (categories.isEmpty()) 0 else categories.size
|
||||
}
|
||||
}
|
||||
@ -1,34 +0,0 @@
|
||||
package me.gilo.wc.adapter;
|
||||
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.ViewGroup;
|
||||
import me.gilo.wc.R;
|
||||
import me.gilo.wc.adapter.viewholder.CouponViewHolder;
|
||||
import me.gilo.woodroid.models.Coupon;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CouponAdapter extends RecyclerView.Adapter<CouponViewHolder> {
|
||||
private List<Coupon> coupons;
|
||||
|
||||
public CouponAdapter(List<Coupon> coupons) {
|
||||
this.coupons = coupons;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CouponViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
return new CouponViewHolder(parent.getContext(), LayoutInflater.from(parent.getContext()).inflate(R.layout.single_coupon_item, parent, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(CouponViewHolder holder, int position) {
|
||||
holder.renderView(coupons.get(position));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return coupons.size() == 0 ? 0 : coupons.size();
|
||||
}
|
||||
}
|
||||
27
app/src/main/java/me/gilo/wc/adapter/CouponAdapter.kt
Normal file
27
app/src/main/java/me/gilo/wc/adapter/CouponAdapter.kt
Normal file
@ -0,0 +1,27 @@
|
||||
package me.gilo.wc.adapter
|
||||
|
||||
import android.support.v7.widget.RecyclerView
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import me.gilo.wc.R
|
||||
import me.gilo.wc.adapter.viewholder.CouponViewHolder
|
||||
import me.gilo.woodroid.models.Coupon
|
||||
|
||||
class CouponAdapter(private val coupons: List<Coupon>) : RecyclerView.Adapter<CouponViewHolder>() {
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CouponViewHolder {
|
||||
return CouponViewHolder(
|
||||
parent.context,
|
||||
LayoutInflater.from(parent.context).inflate(R.layout.single_coupon_item, parent, false)
|
||||
)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: CouponViewHolder, position: Int) {
|
||||
holder.renderView(coupons[position])
|
||||
}
|
||||
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
return if (coupons.size == 0) 0 else coupons.size
|
||||
}
|
||||
}
|
||||
@ -1,34 +0,0 @@
|
||||
package me.gilo.wc.adapter;
|
||||
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.ViewGroup;
|
||||
import me.gilo.wc.R;
|
||||
import me.gilo.wc.adapter.viewholder.ProductViewHolder;
|
||||
import me.gilo.woodroid.models.Product;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class HomeProductAdapter extends RecyclerView.Adapter<ProductViewHolder> {
|
||||
private List<Product> products;
|
||||
|
||||
public HomeProductAdapter(List<Product> products) {
|
||||
this.products = products;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProductViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
return new ProductViewHolder(parent.getContext(), LayoutInflater.from(parent.getContext()).inflate(R.layout.single_home_product_item, parent, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(ProductViewHolder holder, int position) {
|
||||
holder.renderView(products.get(position));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return products.size() == 0 ? 0 : products.size();
|
||||
}
|
||||
}
|
||||
27
app/src/main/java/me/gilo/wc/adapter/HomeProductAdapter.kt
Normal file
27
app/src/main/java/me/gilo/wc/adapter/HomeProductAdapter.kt
Normal file
@ -0,0 +1,27 @@
|
||||
package me.gilo.wc.adapter
|
||||
|
||||
import android.support.v7.widget.RecyclerView
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import me.gilo.wc.R
|
||||
import me.gilo.wc.adapter.viewholder.ProductViewHolder
|
||||
import me.gilo.woodroid.models.Product
|
||||
|
||||
class HomeProductAdapter(private val products: List<Product>) : RecyclerView.Adapter<ProductViewHolder>() {
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ProductViewHolder {
|
||||
return ProductViewHolder(
|
||||
parent.context,
|
||||
LayoutInflater.from(parent.context).inflate(R.layout.single_home_product_item, parent, false)
|
||||
)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: ProductViewHolder, position: Int) {
|
||||
holder.renderView(products[position])
|
||||
}
|
||||
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
return if (products.isEmpty()) 0 else products.size
|
||||
}
|
||||
}
|
||||
@ -1,34 +0,0 @@
|
||||
package me.gilo.wc.adapter;
|
||||
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.ViewGroup;
|
||||
import me.gilo.wc.R;
|
||||
import me.gilo.wc.adapter.viewholder.ProductViewHolder;
|
||||
import me.gilo.woodroid.models.Product;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ListAdapter extends RecyclerView.Adapter<ProductViewHolder> {
|
||||
private List<Product> products;
|
||||
|
||||
public ListAdapter(List<Product> products) {
|
||||
this.products = products;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProductViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
return new ProductViewHolder(parent.getContext(), LayoutInflater.from(parent.getContext()).inflate(R.layout.single_product_item, parent, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(ProductViewHolder holder, int position) {
|
||||
holder.renderView(products.get(position));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return products.size() == 0 ? 0 : products.size();
|
||||
}
|
||||
}
|
||||
27
app/src/main/java/me/gilo/wc/adapter/ListAdapter.kt
Normal file
27
app/src/main/java/me/gilo/wc/adapter/ListAdapter.kt
Normal file
@ -0,0 +1,27 @@
|
||||
package me.gilo.wc.adapter
|
||||
|
||||
import android.support.v7.widget.RecyclerView
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import me.gilo.wc.R
|
||||
import me.gilo.wc.adapter.viewholder.ProductViewHolder
|
||||
import me.gilo.woodroid.models.Product
|
||||
|
||||
class ListAdapter(private val products: List<Product>) : RecyclerView.Adapter<ProductViewHolder>() {
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ProductViewHolder {
|
||||
return ProductViewHolder(
|
||||
parent.context,
|
||||
LayoutInflater.from(parent.context).inflate(R.layout.single_product_item, parent, false)
|
||||
)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: ProductViewHolder, position: Int) {
|
||||
holder.renderView(products[position])
|
||||
}
|
||||
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
return if (products.isEmpty()) 0 else products.size
|
||||
}
|
||||
}
|
||||
@ -1,36 +0,0 @@
|
||||
package me.gilo.wc.adapter;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.ViewGroup;
|
||||
import me.gilo.wc.R;
|
||||
import me.gilo.wc.adapter.viewholder.MenuViewHolder;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class MenuAdapter extends RecyclerView.Adapter<MenuViewHolder> {
|
||||
private List<String> titles;
|
||||
|
||||
public MenuAdapter( List<String> titles) {
|
||||
this.titles = titles;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MenuViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
return new MenuViewHolder(parent.getContext(), LayoutInflater.from(parent.getContext()).inflate(R.layout.single_menu_item, parent, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(MenuViewHolder holder, int position) {
|
||||
holder.renderView(titles.get(position));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return titles.size() == 0 ? 0 : titles.size();
|
||||
}
|
||||
}
|
||||
30
app/src/main/java/me/gilo/wc/adapter/MenuAdapter.kt
Normal file
30
app/src/main/java/me/gilo/wc/adapter/MenuAdapter.kt
Normal file
@ -0,0 +1,30 @@
|
||||
package me.gilo.wc.adapter
|
||||
|
||||
import android.app.Activity
|
||||
import android.support.v7.app.AppCompatActivity
|
||||
import android.support.v7.widget.RecyclerView
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import me.gilo.wc.R
|
||||
import me.gilo.wc.adapter.viewholder.MenuViewHolder
|
||||
|
||||
import java.util.HashMap
|
||||
|
||||
class MenuAdapter(private val titles: List<String>) : RecyclerView.Adapter<MenuViewHolder>() {
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MenuViewHolder {
|
||||
return MenuViewHolder(
|
||||
parent.context,
|
||||
LayoutInflater.from(parent.context).inflate(R.layout.single_menu_item, parent, false)
|
||||
)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: MenuViewHolder, position: Int) {
|
||||
holder.renderView(titles[position])
|
||||
}
|
||||
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
return if (titles.isEmpty()) 0 else titles.size
|
||||
}
|
||||
}
|
||||
@ -1,36 +0,0 @@
|
||||
package me.gilo.wc.adapter;
|
||||
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.ViewGroup;
|
||||
import me.gilo.wc.R;
|
||||
import me.gilo.wc.adapter.viewholder.CategoryViewHolder;
|
||||
import me.gilo.wc.adapter.viewholder.OrderViewHolder;
|
||||
import me.gilo.woodroid.models.Category;
|
||||
import me.gilo.woodroid.models.Order;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class OrderAdapter extends RecyclerView.Adapter<OrderViewHolder> {
|
||||
private List<Order> orders;
|
||||
|
||||
public OrderAdapter(List<Order> orders) {
|
||||
this.orders = orders;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OrderViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
return new OrderViewHolder(parent.getContext(), LayoutInflater.from(parent.getContext()).inflate(R.layout.single_order_item, parent, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(OrderViewHolder holder, int position) {
|
||||
holder.renderView(orders.get(position));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return orders.size() == 0 ? 0 : orders.size();
|
||||
}
|
||||
}
|
||||
29
app/src/main/java/me/gilo/wc/adapter/OrderAdapter.kt
Normal file
29
app/src/main/java/me/gilo/wc/adapter/OrderAdapter.kt
Normal file
@ -0,0 +1,29 @@
|
||||
package me.gilo.wc.adapter
|
||||
|
||||
import android.support.v7.widget.RecyclerView
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import me.gilo.wc.R
|
||||
import me.gilo.wc.adapter.viewholder.CategoryViewHolder
|
||||
import me.gilo.wc.adapter.viewholder.OrderViewHolder
|
||||
import me.gilo.woodroid.models.Category
|
||||
import me.gilo.woodroid.models.Order
|
||||
|
||||
class OrderAdapter(private val orders: List<Order>) : RecyclerView.Adapter<OrderViewHolder>() {
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): OrderViewHolder {
|
||||
return OrderViewHolder(
|
||||
parent.context,
|
||||
LayoutInflater.from(parent.context).inflate(R.layout.single_order_item, parent, false)
|
||||
)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: OrderViewHolder, position: Int) {
|
||||
holder.renderView(orders[position])
|
||||
}
|
||||
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
return if (orders.isEmpty()) 0 else orders.size
|
||||
}
|
||||
}
|
||||
@ -1,35 +0,0 @@
|
||||
package me.gilo.wc.adapter;
|
||||
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.ViewGroup;
|
||||
import me.gilo.wc.R;
|
||||
import me.gilo.wc.adapter.viewholder.MenuViewHolder;
|
||||
import me.gilo.wc.adapter.viewholder.ProductViewHolder;
|
||||
import me.gilo.woodroid.models.Product;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ProductAdapter extends RecyclerView.Adapter<ProductViewHolder> {
|
||||
private List<Product> products;
|
||||
|
||||
public ProductAdapter(List<Product> products) {
|
||||
this.products = products;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProductViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
return new ProductViewHolder(parent.getContext(), LayoutInflater.from(parent.getContext()).inflate(R.layout.single_product_item, parent, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(ProductViewHolder holder, int position) {
|
||||
holder.renderView(products.get(position));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return products.size() == 0 ? 0 : products.size();
|
||||
}
|
||||
}
|
||||
28
app/src/main/java/me/gilo/wc/adapter/ProductAdapter.kt
Normal file
28
app/src/main/java/me/gilo/wc/adapter/ProductAdapter.kt
Normal file
@ -0,0 +1,28 @@
|
||||
package me.gilo.wc.adapter
|
||||
|
||||
import android.support.v7.widget.RecyclerView
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import me.gilo.wc.R
|
||||
import me.gilo.wc.adapter.viewholder.MenuViewHolder
|
||||
import me.gilo.wc.adapter.viewholder.ProductViewHolder
|
||||
import me.gilo.woodroid.models.Product
|
||||
|
||||
class ProductAdapter(private val products: List<Product>) : RecyclerView.Adapter<ProductViewHolder>() {
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ProductViewHolder {
|
||||
return ProductViewHolder(
|
||||
parent.context,
|
||||
LayoutInflater.from(parent.context).inflate(R.layout.single_product_item, parent, false)
|
||||
)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: ProductViewHolder, position: Int) {
|
||||
holder.renderView(products[position])
|
||||
}
|
||||
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
return if (products.isEmpty()) 0 else products.size
|
||||
}
|
||||
}
|
||||
@ -1,36 +0,0 @@
|
||||
package me.gilo.wc.adapter;
|
||||
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.ViewGroup;
|
||||
import me.gilo.wc.R;
|
||||
import me.gilo.wc.adapter.viewholder.ProductReviewViewHolder;
|
||||
import me.gilo.wc.adapter.viewholder.ProductViewHolder;
|
||||
import me.gilo.woodroid.models.Product;
|
||||
import me.gilo.woodroid.models.ProductReview;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ProductReviewAdapter extends RecyclerView.Adapter<ProductReviewViewHolder> {
|
||||
private List<ProductReview> reviews;
|
||||
|
||||
public ProductReviewAdapter(List<ProductReview> reviews) {
|
||||
this.reviews = reviews;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProductReviewViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
return new ProductReviewViewHolder(parent.getContext(), LayoutInflater.from(parent.getContext()).inflate(R.layout.single_product_review, parent, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(ProductReviewViewHolder holder, int position) {
|
||||
holder.renderView(reviews.get(position));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return reviews.size() == 0 ? 0 : reviews.size();
|
||||
}
|
||||
}
|
||||
29
app/src/main/java/me/gilo/wc/adapter/ProductReviewAdapter.kt
Normal file
29
app/src/main/java/me/gilo/wc/adapter/ProductReviewAdapter.kt
Normal file
@ -0,0 +1,29 @@
|
||||
package me.gilo.wc.adapter
|
||||
|
||||
import android.support.v7.widget.RecyclerView
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import me.gilo.wc.R
|
||||
import me.gilo.wc.adapter.viewholder.ProductReviewViewHolder
|
||||
import me.gilo.wc.adapter.viewholder.ProductViewHolder
|
||||
import me.gilo.woodroid.models.Product
|
||||
import me.gilo.woodroid.models.ProductReview
|
||||
|
||||
class ProductReviewAdapter(private val reviews: List<ProductReview>) : RecyclerView.Adapter<ProductReviewViewHolder>() {
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ProductReviewViewHolder {
|
||||
return ProductReviewViewHolder(
|
||||
parent.context,
|
||||
LayoutInflater.from(parent.context).inflate(R.layout.single_product_review, parent, false)
|
||||
)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: ProductReviewViewHolder, position: Int) {
|
||||
holder.renderView(reviews[position])
|
||||
}
|
||||
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
return if (reviews.isEmpty()) 0 else reviews.size
|
||||
}
|
||||
}
|
||||
@ -1,25 +0,0 @@
|
||||
package me.gilo.wc.common;
|
||||
|
||||
import android.arch.lifecycle.LiveData;
|
||||
import android.support.annotation.NonNull;
|
||||
import com.google.android.gms.tasks.OnCompleteListener;
|
||||
import com.google.android.gms.tasks.Task;
|
||||
|
||||
|
||||
public final class CompletionGenericLiveData<T> extends LiveData<Resource<T>> implements OnCompleteListener<T> {
|
||||
|
||||
|
||||
public CompletionGenericLiveData() {
|
||||
setValue(new Resource<>(Status.LOADING));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void onComplete(@NonNull Task<T> task) {
|
||||
if (task.isSuccessful()) {
|
||||
setValue(new Resource<T>(task.getResult()));
|
||||
} else {
|
||||
setValue(new Resource<>(task.getException()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,21 @@
|
||||
package me.gilo.wc.common
|
||||
|
||||
import android.arch.lifecycle.LiveData
|
||||
import com.google.android.gms.tasks.OnCompleteListener
|
||||
import com.google.android.gms.tasks.Task
|
||||
|
||||
|
||||
class CompletionGenericLiveData<T> : LiveData<Resource<T>>(), OnCompleteListener<T> {
|
||||
init {
|
||||
value = Resource(Status.LOADING)
|
||||
}
|
||||
|
||||
override fun onComplete(task: Task<T>) {
|
||||
if (task.isSuccessful) {
|
||||
setValue(Resource(task.result!!))
|
||||
} else {
|
||||
setValue(Resource(task.exception!!))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,66 +0,0 @@
|
||||
package me.gilo.wc.di;
|
||||
|
||||
import dagger.Module;
|
||||
import dagger.android.ContributesAndroidInjector;
|
||||
import me.gilo.raison.ui.user.onboarding.SignInActivity;
|
||||
import me.gilo.raison.ui.user.onboarding.SignUpActivity;
|
||||
import me.gilo.wc.MainActivity;
|
||||
import me.gilo.wc.ui.WooDroidActivity;
|
||||
import me.gilo.wc.ui.customer.BasicCustomerDetailsActivity;
|
||||
import me.gilo.wc.ui.customer.BillingAddressActivity;
|
||||
import me.gilo.wc.ui.customer.ProfileActivity;
|
||||
import me.gilo.wc.ui.customer.ShippingAddressActivity;
|
||||
import me.gilo.wc.ui.home.HomeActivity;
|
||||
import me.gilo.wc.ui.onboarding.AnonymousSignInActivity;
|
||||
import me.gilo.wc.ui.order.MyOrdersActivity;
|
||||
import me.gilo.wc.ui.order.OrderActivity;
|
||||
import me.gilo.wc.ui.product.CartActivity;
|
||||
import me.gilo.wc.ui.product.ProductActivity;
|
||||
import me.gilo.wc.ui.product.ShopActivity;
|
||||
|
||||
@Module
|
||||
abstract class ActivitiesModule {
|
||||
|
||||
@ContributesAndroidInjector
|
||||
abstract MainActivity contributesMainActivity();
|
||||
|
||||
@ContributesAndroidInjector
|
||||
abstract ShopActivity contributesShopActivity();
|
||||
|
||||
@ContributesAndroidInjector
|
||||
abstract ProductActivity contributesProductActivity();
|
||||
|
||||
@ContributesAndroidInjector
|
||||
abstract HomeActivity contributesHomeActivity();
|
||||
|
||||
@ContributesAndroidInjector
|
||||
abstract SignInActivity contributesSignInActivity();
|
||||
|
||||
@ContributesAndroidInjector
|
||||
abstract SignUpActivity contributesSignUpActivity();
|
||||
|
||||
@ContributesAndroidInjector
|
||||
abstract BasicCustomerDetailsActivity contributesBasicCustomerDetailsActivity();
|
||||
|
||||
@ContributesAndroidInjector
|
||||
abstract BillingAddressActivity contributesBillingAddressActivity();
|
||||
|
||||
@ContributesAndroidInjector
|
||||
abstract ShippingAddressActivity contributesShippingAddressActivity();
|
||||
|
||||
@ContributesAndroidInjector
|
||||
abstract CartActivity contributesCartActivity();
|
||||
|
||||
@ContributesAndroidInjector
|
||||
abstract ProfileActivity contributesProfileActivity();
|
||||
|
||||
@ContributesAndroidInjector
|
||||
abstract AnonymousSignInActivity contributesAnonymousSignInActivity();
|
||||
|
||||
@ContributesAndroidInjector
|
||||
abstract MyOrdersActivity contributesMyOrdersActivity();
|
||||
|
||||
@ContributesAndroidInjector
|
||||
abstract OrderActivity contributesOrderActivity();
|
||||
|
||||
}
|
||||
66
app/src/main/java/me/gilo/wc/di/ActivitiesModule.kt
Normal file
66
app/src/main/java/me/gilo/wc/di/ActivitiesModule.kt
Normal file
@ -0,0 +1,66 @@
|
||||
package me.gilo.wc.di
|
||||
|
||||
import dagger.Module
|
||||
import dagger.android.ContributesAndroidInjector
|
||||
import me.gilo.raison.ui.user.onboarding.SignInActivity
|
||||
import me.gilo.raison.ui.user.onboarding.SignUpActivity
|
||||
import me.gilo.wc.MainActivity
|
||||
import me.gilo.wc.ui.WooDroidActivity
|
||||
import me.gilo.wc.ui.customer.BasicCustomerDetailsActivity
|
||||
import me.gilo.wc.ui.customer.BillingAddressActivity
|
||||
import me.gilo.wc.ui.customer.ProfileActivity
|
||||
import me.gilo.wc.ui.customer.ShippingAddressActivity
|
||||
import me.gilo.wc.ui.home.HomeActivity
|
||||
import me.gilo.wc.ui.onboarding.AnonymousSignInActivity
|
||||
import me.gilo.wc.ui.order.MyOrdersActivity
|
||||
import me.gilo.wc.ui.order.OrderActivity
|
||||
import me.gilo.wc.ui.product.CartActivity
|
||||
import me.gilo.wc.ui.product.ProductActivity
|
||||
import me.gilo.wc.ui.product.ShopActivity
|
||||
|
||||
@Module
|
||||
internal abstract class ActivitiesModule {
|
||||
|
||||
@ContributesAndroidInjector
|
||||
internal abstract fun contributesMainActivity(): MainActivity
|
||||
|
||||
@ContributesAndroidInjector
|
||||
internal abstract fun contributesShopActivity(): ShopActivity
|
||||
|
||||
@ContributesAndroidInjector
|
||||
internal abstract fun contributesProductActivity(): ProductActivity
|
||||
|
||||
@ContributesAndroidInjector
|
||||
internal abstract fun contributesHomeActivity(): HomeActivity
|
||||
|
||||
@ContributesAndroidInjector
|
||||
internal abstract fun contributesSignInActivity(): SignInActivity
|
||||
|
||||
@ContributesAndroidInjector
|
||||
internal abstract fun contributesSignUpActivity(): SignUpActivity
|
||||
|
||||
@ContributesAndroidInjector
|
||||
internal abstract fun contributesBasicCustomerDetailsActivity(): BasicCustomerDetailsActivity
|
||||
|
||||
@ContributesAndroidInjector
|
||||
internal abstract fun contributesBillingAddressActivity(): BillingAddressActivity
|
||||
|
||||
@ContributesAndroidInjector
|
||||
internal abstract fun contributesShippingAddressActivity(): ShippingAddressActivity
|
||||
|
||||
@ContributesAndroidInjector
|
||||
internal abstract fun contributesCartActivity(): CartActivity
|
||||
|
||||
@ContributesAndroidInjector
|
||||
internal abstract fun contributesProfileActivity(): ProfileActivity
|
||||
|
||||
@ContributesAndroidInjector
|
||||
internal abstract fun contributesAnonymousSignInActivity(): AnonymousSignInActivity
|
||||
|
||||
@ContributesAndroidInjector
|
||||
internal abstract fun contributesMyOrdersActivity(): MyOrdersActivity
|
||||
|
||||
@ContributesAndroidInjector
|
||||
internal abstract fun contributesOrderActivity(): OrderActivity
|
||||
|
||||
}
|
||||
@ -1,25 +0,0 @@
|
||||
package me.gilo.wc.di;
|
||||
|
||||
|
||||
import dagger.Component;
|
||||
import dagger.android.AndroidInjector;
|
||||
import dagger.android.DaggerApplication;
|
||||
import dagger.android.support.AndroidSupportInjectionModule;
|
||||
import me.gilo.wc.WcApp;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
|
||||
@Singleton
|
||||
@Component(modules = {
|
||||
AndroidSupportInjectionModule.class,
|
||||
ViewModelModule.class,
|
||||
FirebaseModule.class,
|
||||
ActivitiesModule.class,
|
||||
AppModule.class
|
||||
})
|
||||
interface AppComponent extends AndroidInjector<DaggerApplication> {
|
||||
|
||||
void inject(WcApp app);
|
||||
|
||||
}
|
||||
19
app/src/main/java/me/gilo/wc/di/AppComponent.kt
Normal file
19
app/src/main/java/me/gilo/wc/di/AppComponent.kt
Normal file
@ -0,0 +1,19 @@
|
||||
package me.gilo.wc.di
|
||||
|
||||
|
||||
import dagger.Component
|
||||
import dagger.android.AndroidInjector
|
||||
import dagger.android.DaggerApplication
|
||||
import dagger.android.support.AndroidSupportInjectionModule
|
||||
import me.gilo.wc.WcApp
|
||||
|
||||
import javax.inject.Singleton
|
||||
|
||||
|
||||
@Singleton
|
||||
@Component(modules = [AndroidSupportInjectionModule::class, ViewModelModule::class, FirebaseModule::class, ActivitiesModule::class, AppModule::class])
|
||||
internal interface AppComponent : AndroidInjector<DaggerApplication> {
|
||||
|
||||
fun inject(app: WcApp)
|
||||
|
||||
}
|
||||
@ -1,39 +0,0 @@
|
||||
package me.gilo.wc.di;
|
||||
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
import me.gilo.wc.Config;
|
||||
import me.gilo.wc.WcApp;
|
||||
import me.gilo.woodroid.Woocommerce;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
@Module
|
||||
public class AppModule {
|
||||
|
||||
WcApp app;
|
||||
|
||||
void AppModule(WcApp application) {
|
||||
app = application;
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
WcApp providesApplication() {
|
||||
return app;
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
Woocommerce providesWoocommerce() {
|
||||
Woocommerce woocommerce = Woocommerce.Builder()
|
||||
.setSiteUrl(Config.siteUrl)
|
||||
.setApiVersion(Woocommerce.API_V3)
|
||||
.setConsumerKey(Config.consumerKey)
|
||||
.setConsumerSecret(Config.consumerSecret)
|
||||
.build();
|
||||
|
||||
return woocommerce;
|
||||
}
|
||||
|
||||
}
|
||||
38
app/src/main/java/me/gilo/wc/di/AppModule.kt
Normal file
38
app/src/main/java/me/gilo/wc/di/AppModule.kt
Normal file
@ -0,0 +1,38 @@
|
||||
package me.gilo.wc.di
|
||||
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import me.gilo.wc.Config
|
||||
import me.gilo.wc.WcApp
|
||||
import me.gilo.woodroid.Woocommerce
|
||||
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Module
|
||||
class AppModule {
|
||||
|
||||
internal var app: WcApp? = null
|
||||
|
||||
internal fun AppModule(application: WcApp) {
|
||||
app = application
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
internal fun providesApplication(): WcApp {
|
||||
return app!!
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
internal fun providesWoocommerce(): Woocommerce {
|
||||
|
||||
return Woocommerce.Builder()
|
||||
.setSiteUrl(Config.siteUrl)
|
||||
.setApiVersion(Woocommerce.API_V3)
|
||||
.setConsumerKey(Config.consumerKey)
|
||||
.setConsumerSecret(Config.consumerSecret)
|
||||
.build()
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,46 +0,0 @@
|
||||
package me.gilo.wc.di;
|
||||
|
||||
import com.google.firebase.firestore.CollectionReference;
|
||||
import com.google.firebase.firestore.FirebaseFirestore;
|
||||
import com.google.firebase.storage.FirebaseStorage;
|
||||
import com.google.firebase.storage.StorageReference;
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
|
||||
@Module
|
||||
class FirebaseModule {
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
FirebaseFirestore providesFirestore() {
|
||||
FirebaseFirestore db = FirebaseFirestore.getInstance();
|
||||
return db;
|
||||
}
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
@Named("storage")
|
||||
StorageReference providesStorage() {
|
||||
return FirebaseStorage.getInstance().getReference();
|
||||
}
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
@Named("users")
|
||||
CollectionReference providesUsers() {
|
||||
return getFirestoreInstance().collection("users");
|
||||
}
|
||||
|
||||
FirebaseFirestore getFirestoreInstance(){
|
||||
FirebaseFirestore db = FirebaseFirestore.getInstance();
|
||||
|
||||
return db;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
41
app/src/main/java/me/gilo/wc/di/FirebaseModule.kt
Normal file
41
app/src/main/java/me/gilo/wc/di/FirebaseModule.kt
Normal file
@ -0,0 +1,41 @@
|
||||
package me.gilo.wc.di
|
||||
|
||||
import com.google.firebase.firestore.CollectionReference
|
||||
import com.google.firebase.firestore.FirebaseFirestore
|
||||
import com.google.firebase.storage.FirebaseStorage
|
||||
import com.google.firebase.storage.StorageReference
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
|
||||
import javax.inject.Named
|
||||
import javax.inject.Singleton
|
||||
|
||||
|
||||
@Module
|
||||
internal class FirebaseModule {
|
||||
|
||||
private val firestoreInstance: FirebaseFirestore
|
||||
get() = FirebaseFirestore.getInstance()
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
fun providesFirestore(): FirebaseFirestore {
|
||||
return FirebaseFirestore.getInstance()
|
||||
}
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
@Named("storage")
|
||||
fun providesStorage(): StorageReference {
|
||||
return FirebaseStorage.getInstance().reference
|
||||
}
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
@Named("users")
|
||||
fun providesUsers(): CollectionReference {
|
||||
return firestoreInstance.collection("users")
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -1,62 +0,0 @@
|
||||
package me.gilo.wc.di;
|
||||
|
||||
import android.arch.lifecycle.ViewModel;
|
||||
import android.arch.lifecycle.ViewModelProvider;
|
||||
import com.google.firebase.firestore.CollectionReference;
|
||||
import dagger.Binds;
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
import dagger.multibindings.IntoMap;
|
||||
import me.gilo.wc.ui.order.MyOrdersActivity;
|
||||
import me.gilo.wc.utils.ViewModelFactory;
|
||||
import me.gilo.wc.viewmodels.*;
|
||||
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
@Module
|
||||
public abstract class ViewModelModule {
|
||||
|
||||
|
||||
@Binds
|
||||
@IntoMap
|
||||
@ViewModelKey(UserViewModel.class)
|
||||
abstract ViewModel bindUserViewModel(UserViewModel viewModel);
|
||||
|
||||
@Binds
|
||||
@IntoMap
|
||||
@ViewModelKey(ProductViewModel.class)
|
||||
abstract ViewModel bindProductViewModel(ProductViewModel viewModel);
|
||||
|
||||
@Binds
|
||||
@IntoMap
|
||||
@ViewModelKey(CategoryViewModel.class)
|
||||
abstract ViewModel bindCategoryViewModel(CategoryViewModel viewModel);
|
||||
|
||||
@Binds
|
||||
@IntoMap
|
||||
@ViewModelKey(CustomerViewModel.class)
|
||||
abstract ViewModel bindCustomerViewModel(CustomerViewModel viewModel);
|
||||
|
||||
@Binds
|
||||
@IntoMap
|
||||
@ViewModelKey(CartViewModel.class)
|
||||
abstract ViewModel bindCartViewModel(CartViewModel viewModel);
|
||||
|
||||
@Binds
|
||||
@IntoMap
|
||||
@ViewModelKey(OrderViewModel.class)
|
||||
abstract ViewModel bindOrderViewModel(OrderViewModel viewModel);
|
||||
|
||||
@Binds
|
||||
@IntoMap
|
||||
@ViewModelKey(ReviewViewModel.class)
|
||||
abstract ViewModel bindReviewViewModel(ReviewViewModel viewModel);
|
||||
|
||||
@Binds
|
||||
abstract ViewModelProvider.Factory bindViewModelFactory(ViewModelFactory factory);
|
||||
|
||||
|
||||
}
|
||||
61
app/src/main/java/me/gilo/wc/di/ViewModelModule.kt
Normal file
61
app/src/main/java/me/gilo/wc/di/ViewModelModule.kt
Normal file
@ -0,0 +1,61 @@
|
||||
package me.gilo.wc.di
|
||||
|
||||
import android.arch.lifecycle.ViewModel
|
||||
import android.arch.lifecycle.ViewModelProvider
|
||||
import com.google.firebase.firestore.CollectionReference
|
||||
import dagger.Binds
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import dagger.multibindings.IntoMap
|
||||
import me.gilo.wc.ui.order.MyOrdersActivity
|
||||
import me.gilo.wc.utils.ViewModelFactory
|
||||
import me.gilo.wc.viewmodels.*
|
||||
|
||||
import javax.inject.Named
|
||||
import javax.inject.Singleton
|
||||
|
||||
|
||||
@Module
|
||||
abstract class ViewModelModule {
|
||||
|
||||
|
||||
@Binds
|
||||
@IntoMap
|
||||
@ViewModelKey(UserViewModel::class)
|
||||
internal abstract fun bindUserViewModel(viewModel: UserViewModel): ViewModel
|
||||
|
||||
@Binds
|
||||
@IntoMap
|
||||
@ViewModelKey(ProductViewModel::class)
|
||||
internal abstract fun bindProductViewModel(viewModel: ProductViewModel): ViewModel
|
||||
|
||||
@Binds
|
||||
@IntoMap
|
||||
@ViewModelKey(CategoryViewModel::class)
|
||||
internal abstract fun bindCategoryViewModel(viewModel: CategoryViewModel): ViewModel
|
||||
|
||||
@Binds
|
||||
@IntoMap
|
||||
@ViewModelKey(CustomerViewModel::class)
|
||||
internal abstract fun bindCustomerViewModel(viewModel: CustomerViewModel): ViewModel
|
||||
|
||||
@Binds
|
||||
@IntoMap
|
||||
@ViewModelKey(CartViewModel::class)
|
||||
internal abstract fun bindCartViewModel(viewModel: CartViewModel): ViewModel
|
||||
|
||||
@Binds
|
||||
@IntoMap
|
||||
@ViewModelKey(OrderViewModel::class)
|
||||
internal abstract fun bindOrderViewModel(viewModel: OrderViewModel): ViewModel
|
||||
|
||||
@Binds
|
||||
@IntoMap
|
||||
@ViewModelKey(ReviewViewModel::class)
|
||||
internal abstract fun bindReviewViewModel(viewModel: ReviewViewModel): ViewModel
|
||||
|
||||
@Binds
|
||||
internal abstract fun bindViewModelFactory(factory: ViewModelFactory): ViewModelProvider.Factory
|
||||
|
||||
|
||||
}
|
||||
@ -1,113 +0,0 @@
|
||||
package me.gilo.wc.repo;
|
||||
|
||||
|
||||
import android.arch.lifecycle.Observer;
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.net.Uri;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.util.Log;
|
||||
import com.google.android.gms.tasks.OnCompleteListener;
|
||||
import com.google.android.gms.tasks.OnSuccessListener;
|
||||
import com.google.android.gms.tasks.Task;
|
||||
import com.google.firebase.auth.FirebaseAuth;
|
||||
import com.google.firebase.firestore.*;
|
||||
import com.google.firebase.storage.StorageReference;
|
||||
import com.google.firebase.storage.UploadTask;
|
||||
import me.gilo.wc.common.CompletionGenericLiveData;
|
||||
import me.gilo.wc.common.QueryLiveData;
|
||||
import me.gilo.wc.common.WooLiveData;
|
||||
import me.gilo.wc.models.CartLineItem;
|
||||
import me.gilo.wc.utils.AppUtils;
|
||||
import me.gilo.woodroid.Woocommerce;
|
||||
import me.gilo.woodroid.models.LineItem;
|
||||
import me.gilo.woodroid.models.Product;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class CartRepository {
|
||||
|
||||
@Inject
|
||||
Woocommerce woocommerce;
|
||||
|
||||
private final CollectionReference cart;
|
||||
|
||||
@Inject
|
||||
public CartRepository() {
|
||||
this.cart = FirebaseFirestore.getInstance()
|
||||
.collection("users")
|
||||
.document(FirebaseAuth.getInstance().getCurrentUser().getUid())
|
||||
.collection("cart");
|
||||
|
||||
}
|
||||
|
||||
public QueryLiveData<CartLineItem> cart() {
|
||||
return new QueryLiveData<>(cart, CartLineItem.class);
|
||||
}
|
||||
|
||||
public CompletionGenericLiveData<Void> deleteItem(CartLineItem cartLineItem) {
|
||||
final CompletionGenericLiveData<Void> completion = new CompletionGenericLiveData();
|
||||
cart.document(cartLineItem.getId()).delete().addOnCompleteListener(completion);
|
||||
|
||||
return completion;
|
||||
}
|
||||
|
||||
public CompletionGenericLiveData<Void> setQuantity(CartLineItem cartLineItem, int quantity) {
|
||||
final CompletionGenericLiveData<Void> completion = new CompletionGenericLiveData();
|
||||
cartLineItem.setQuantity(quantity);
|
||||
|
||||
cart.document(cartLineItem.getId()).set(cartLineItem).addOnCompleteListener(completion);
|
||||
|
||||
return completion;
|
||||
}
|
||||
|
||||
public CompletionGenericLiveData<Void> deleteItems() {
|
||||
final CompletionGenericLiveData<Void> completion = new CompletionGenericLiveData();
|
||||
deleteCartItems().addOnCompleteListener(completion);
|
||||
return completion;
|
||||
}
|
||||
|
||||
|
||||
private Task<Void> deleteCartItems() {
|
||||
return cart.getFirestore().runTransaction(transaction -> {
|
||||
cart.get().addOnCompleteListener(task -> {
|
||||
if (task.isSuccessful()) {
|
||||
for (QueryDocumentSnapshot document : task.getResult()) {
|
||||
cart.document(document.getId()).delete();
|
||||
}
|
||||
|
||||
} else {
|
||||
}
|
||||
});
|
||||
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public CompletionGenericLiveData<DocumentReference> addToCart(Product product) {
|
||||
final CompletionGenericLiveData<DocumentReference> completion = new CompletionGenericLiveData();
|
||||
|
||||
CartLineItem lineItem = new CartLineItem();
|
||||
lineItem.setProductId(product.getId());
|
||||
lineItem.setProduct(product);
|
||||
lineItem.setQuantity(1);
|
||||
|
||||
cart.add(lineItem).addOnCompleteListener(completion);
|
||||
|
||||
return completion;
|
||||
|
||||
}
|
||||
|
||||
public WooLiveData<Map<String, LineItem>> cart(Context context) {
|
||||
final WooLiveData<Map<String, LineItem>> callBack = new WooLiveData();
|
||||
woocommerce.CartRepository(context).cart().enqueue(callBack);
|
||||
|
||||
return callBack;
|
||||
}
|
||||
|
||||
}
|
||||
96
app/src/main/java/me/gilo/wc/repo/CartRepository.kt
Normal file
96
app/src/main/java/me/gilo/wc/repo/CartRepository.kt
Normal file
@ -0,0 +1,96 @@
|
||||
package me.gilo.wc.repo
|
||||
|
||||
|
||||
import android.content.Context
|
||||
import com.google.android.gms.tasks.Task
|
||||
import com.google.firebase.auth.FirebaseAuth
|
||||
import com.google.firebase.firestore.CollectionReference
|
||||
import com.google.firebase.firestore.DocumentReference
|
||||
import com.google.firebase.firestore.FirebaseFirestore
|
||||
import me.gilo.wc.common.CompletionGenericLiveData
|
||||
import me.gilo.wc.common.QueryLiveData
|
||||
import me.gilo.wc.common.WooLiveData
|
||||
import me.gilo.wc.models.CartLineItem
|
||||
import me.gilo.woodroid.Woocommerce
|
||||
import me.gilo.woodroid.models.LineItem
|
||||
import me.gilo.woodroid.models.Product
|
||||
import javax.inject.Inject
|
||||
|
||||
open class CartRepository @Inject
|
||||
constructor() {
|
||||
|
||||
@Inject
|
||||
lateinit var woocommerce: Woocommerce
|
||||
|
||||
|
||||
private val cart: CollectionReference = FirebaseFirestore.getInstance()
|
||||
.collection("users")
|
||||
.document(FirebaseAuth.getInstance().currentUser!!.uid)
|
||||
.collection("cart")
|
||||
|
||||
fun cart(): QueryLiveData<CartLineItem> {
|
||||
return QueryLiveData(cart, CartLineItem::class.java)
|
||||
}
|
||||
|
||||
fun deleteItem(cartLineItem: CartLineItem): CompletionGenericLiveData<Void> {
|
||||
val completion = CompletionGenericLiveData<Void>()
|
||||
cart.document(cartLineItem.getId()).delete().addOnCompleteListener(completion)
|
||||
|
||||
return completion
|
||||
}
|
||||
|
||||
fun setQuantity(cartLineItem: CartLineItem, quantity: Int): CompletionGenericLiveData<Void> {
|
||||
val completion = CompletionGenericLiveData<Void>()
|
||||
cartLineItem.setQuantity(quantity)
|
||||
|
||||
cart.document(cartLineItem.getId()).set(cartLineItem).addOnCompleteListener(completion)
|
||||
|
||||
return completion
|
||||
}
|
||||
|
||||
fun deleteItems(): CompletionGenericLiveData<Void> {
|
||||
val completion = CompletionGenericLiveData<Void>()
|
||||
deleteCartItems().addOnCompleteListener(completion)
|
||||
return completion
|
||||
}
|
||||
|
||||
|
||||
private fun deleteCartItems(): Task<Void> {
|
||||
return cart.firestore.runTransaction {
|
||||
cart.get().addOnCompleteListener { task ->
|
||||
if (task.isSuccessful) {
|
||||
for (document in task.result!!) {
|
||||
cart.document(document.id).delete()
|
||||
}
|
||||
|
||||
} else {
|
||||
}
|
||||
}
|
||||
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun addToCart(product: Product): CompletionGenericLiveData<DocumentReference> {
|
||||
val completion = CompletionGenericLiveData<DocumentReference>()
|
||||
|
||||
val lineItem = CartLineItem()
|
||||
lineItem.setProductId(product.id)
|
||||
lineItem.product = product
|
||||
lineItem.setQuantity(1)
|
||||
|
||||
cart.add(lineItem).addOnCompleteListener(completion)
|
||||
|
||||
return completion
|
||||
|
||||
}
|
||||
|
||||
fun cart(context: Context): WooLiveData<Map<String, LineItem>> {
|
||||
val callBack = WooLiveData<Map<String, LineItem>>()
|
||||
woocommerce!!.CartRepository(context).cart().enqueue(callBack)
|
||||
|
||||
return callBack
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,73 +0,0 @@
|
||||
package me.gilo.wc.repo;
|
||||
|
||||
|
||||
import me.gilo.wc.common.WooLiveData;
|
||||
import me.gilo.woodroid.Woocommerce;
|
||||
import me.gilo.woodroid.models.Category;
|
||||
import me.gilo.woodroid.models.filters.ProductCategoryFilter;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.List;
|
||||
|
||||
public class CategoryRepository {
|
||||
|
||||
@Inject
|
||||
Woocommerce woocommerce;
|
||||
|
||||
@Inject
|
||||
public CategoryRepository() {
|
||||
}
|
||||
|
||||
|
||||
public WooLiveData<Category> create(Category category) {
|
||||
final WooLiveData<Category> callBack = new WooLiveData();
|
||||
|
||||
woocommerce.CategoryRepository().create(category).enqueue(callBack);
|
||||
return callBack;
|
||||
}
|
||||
|
||||
|
||||
public WooLiveData<Category> category(int id) {
|
||||
final WooLiveData<Category> callBack = new WooLiveData();
|
||||
|
||||
woocommerce.CategoryRepository().category(id).enqueue(callBack);
|
||||
return callBack;
|
||||
}
|
||||
|
||||
public WooLiveData<List<Category>> categories() {
|
||||
final WooLiveData<List<Category>> callBack = new WooLiveData();
|
||||
|
||||
woocommerce.CategoryRepository().categories().enqueue(callBack);
|
||||
return callBack;
|
||||
}
|
||||
|
||||
public WooLiveData<List<Category>> categories(ProductCategoryFilter productCategoryFilter) {
|
||||
final WooLiveData<List<Category>> callBack = new WooLiveData();
|
||||
|
||||
woocommerce.CategoryRepository().categories(productCategoryFilter).enqueue(callBack);
|
||||
return callBack;
|
||||
}
|
||||
|
||||
public WooLiveData<Category> update(int id, Category category) {
|
||||
final WooLiveData<Category> callBack = new WooLiveData();
|
||||
|
||||
woocommerce.CategoryRepository().update(id, category).enqueue(callBack);
|
||||
return callBack;
|
||||
}
|
||||
|
||||
public WooLiveData<Category> delete(int id) {
|
||||
final WooLiveData<Category> callBack = new WooLiveData();
|
||||
|
||||
woocommerce.CategoryRepository().delete(id).enqueue(callBack);
|
||||
return callBack;
|
||||
}
|
||||
|
||||
public WooLiveData<Category> delete(int id, boolean force) {
|
||||
final WooLiveData<Category> callBack = new WooLiveData();
|
||||
|
||||
woocommerce.CategoryRepository().delete(id, force).enqueue(callBack);
|
||||
return callBack;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
69
app/src/main/java/me/gilo/wc/repo/CategoryRepository.kt
Normal file
69
app/src/main/java/me/gilo/wc/repo/CategoryRepository.kt
Normal file
@ -0,0 +1,69 @@
|
||||
package me.gilo.wc.repo
|
||||
|
||||
|
||||
import me.gilo.wc.common.WooLiveData
|
||||
import me.gilo.woodroid.Woocommerce
|
||||
import me.gilo.woodroid.models.Category
|
||||
import me.gilo.woodroid.models.filters.ProductCategoryFilter
|
||||
|
||||
import javax.inject.Inject
|
||||
|
||||
class CategoryRepository @Inject
|
||||
constructor() {
|
||||
|
||||
@Inject
|
||||
lateinit var woocommerce: Woocommerce
|
||||
|
||||
|
||||
fun create(category: Category): WooLiveData<Category> {
|
||||
val callBack = WooLiveData<Category>()
|
||||
|
||||
woocommerce!!.CategoryRepository().create(category).enqueue(callBack)
|
||||
return callBack
|
||||
}
|
||||
|
||||
|
||||
fun category(id: Int): WooLiveData<Category> {
|
||||
val callBack = WooLiveData<Category>()
|
||||
|
||||
woocommerce!!.CategoryRepository().category(id).enqueue(callBack)
|
||||
return callBack
|
||||
}
|
||||
|
||||
fun categories(): WooLiveData<List<Category>> {
|
||||
val callBack = WooLiveData<List<Category>>()
|
||||
|
||||
woocommerce!!.CategoryRepository().categories().enqueue(callBack)
|
||||
return callBack
|
||||
}
|
||||
|
||||
fun categories(productCategoryFilter: ProductCategoryFilter): WooLiveData<List<Category>> {
|
||||
val callBack = WooLiveData<List<Category>>()
|
||||
|
||||
woocommerce!!.CategoryRepository().categories(productCategoryFilter).enqueue(callBack)
|
||||
return callBack
|
||||
}
|
||||
|
||||
fun update(id: Int, category: Category): WooLiveData<Category> {
|
||||
val callBack = WooLiveData<Category>()
|
||||
|
||||
woocommerce!!.CategoryRepository().update(id, category).enqueue(callBack)
|
||||
return callBack
|
||||
}
|
||||
|
||||
fun delete(id: Int): WooLiveData<Category> {
|
||||
val callBack = WooLiveData<Category>()
|
||||
|
||||
woocommerce!!.CategoryRepository().delete(id).enqueue(callBack)
|
||||
return callBack
|
||||
}
|
||||
|
||||
fun delete(id: Int, force: Boolean): WooLiveData<Category> {
|
||||
val callBack = WooLiveData<Category>()
|
||||
|
||||
woocommerce!!.CategoryRepository().delete(id, force).enqueue(callBack)
|
||||
return callBack
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -1,83 +0,0 @@
|
||||
package me.gilo.wc.repo;
|
||||
|
||||
|
||||
import com.google.firebase.auth.FirebaseAuth;
|
||||
import me.gilo.wc.common.WooLiveData;
|
||||
import me.gilo.woodroid.Woocommerce;
|
||||
import me.gilo.woodroid.models.Customer;
|
||||
import me.gilo.woodroid.models.Customer;
|
||||
import me.gilo.woodroid.models.filters.CustomerFilter;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.List;
|
||||
|
||||
public class CustomerRepository {
|
||||
|
||||
@Inject
|
||||
Woocommerce woocommerce;
|
||||
|
||||
|
||||
@Inject
|
||||
public CustomerRepository() {
|
||||
|
||||
}
|
||||
|
||||
public WooLiveData<Customer> create(Customer customer) {
|
||||
final WooLiveData<Customer> callBack = new WooLiveData();
|
||||
woocommerce.CustomerRepository().create(customer).enqueue(callBack);
|
||||
return callBack;
|
||||
}
|
||||
|
||||
public WooLiveData<List<Customer>> currentCustomer() {
|
||||
final WooLiveData<List<Customer>> callBack = new WooLiveData();
|
||||
CustomerFilter customerFilter = new CustomerFilter();
|
||||
customerFilter.setEmail(FirebaseAuth.getInstance().getCurrentUser().getEmail());
|
||||
|
||||
woocommerce.CustomerRepository().customers(customerFilter).enqueue(callBack);
|
||||
return callBack;
|
||||
}
|
||||
|
||||
|
||||
public WooLiveData<Customer> customer(int id) {
|
||||
final WooLiveData<Customer> callBack = new WooLiveData();
|
||||
woocommerce.CustomerRepository().customer(id).enqueue(callBack);
|
||||
return callBack;
|
||||
}
|
||||
|
||||
public WooLiveData<List<Customer>> customers() {
|
||||
final WooLiveData<List<Customer>> callBack = new WooLiveData();
|
||||
|
||||
woocommerce.CustomerRepository().customers().enqueue(callBack);
|
||||
|
||||
return callBack;
|
||||
}
|
||||
|
||||
public WooLiveData<List<Customer>> customers(CustomerFilter customerFilter) {
|
||||
final WooLiveData<List<Customer>> callBack = new WooLiveData();
|
||||
woocommerce.CustomerRepository().customers(customerFilter).enqueue(callBack);
|
||||
return callBack;
|
||||
}
|
||||
|
||||
public WooLiveData<Customer> update(int id, Customer customer) {
|
||||
final WooLiveData<Customer> callBack = new WooLiveData();
|
||||
woocommerce.CustomerRepository().update(id, customer).enqueue(callBack);
|
||||
|
||||
return callBack;
|
||||
}
|
||||
|
||||
public WooLiveData<Customer> delete(int id) {
|
||||
final WooLiveData<Customer> callBack = new WooLiveData();
|
||||
woocommerce.CustomerRepository().delete(id).enqueue(callBack);
|
||||
|
||||
return callBack;
|
||||
}
|
||||
|
||||
public WooLiveData<Customer> delete(int id, boolean force) {
|
||||
final WooLiveData<Customer> callBack = new WooLiveData();
|
||||
woocommerce.CustomerRepository().delete(id, force).enqueue(callBack);
|
||||
|
||||
return callBack;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
76
app/src/main/java/me/gilo/wc/repo/CustomerRepository.kt
Normal file
76
app/src/main/java/me/gilo/wc/repo/CustomerRepository.kt
Normal file
@ -0,0 +1,76 @@
|
||||
package me.gilo.wc.repo
|
||||
|
||||
|
||||
import com.google.firebase.auth.FirebaseAuth
|
||||
import me.gilo.wc.common.WooLiveData
|
||||
import me.gilo.woodroid.Woocommerce
|
||||
import me.gilo.woodroid.models.Customer
|
||||
import me.gilo.woodroid.models.filters.CustomerFilter
|
||||
|
||||
import javax.inject.Inject
|
||||
|
||||
class CustomerRepository @Inject
|
||||
constructor() {
|
||||
|
||||
@Inject
|
||||
lateinit var woocommerce: Woocommerce
|
||||
|
||||
fun create(customer: Customer): WooLiveData<Customer> {
|
||||
val callBack = WooLiveData<Customer>()
|
||||
woocommerce!!.CustomerRepository().create(customer).enqueue(callBack)
|
||||
return callBack
|
||||
}
|
||||
|
||||
fun currentCustomer(): WooLiveData<List<Customer>> {
|
||||
val callBack = WooLiveData<List<Customer>>()
|
||||
val customerFilter = CustomerFilter()
|
||||
customerFilter.email = FirebaseAuth.getInstance().currentUser!!.email
|
||||
|
||||
woocommerce!!.CustomerRepository().customers(customerFilter).enqueue(callBack)
|
||||
return callBack
|
||||
}
|
||||
|
||||
|
||||
fun customer(id: Int): WooLiveData<Customer> {
|
||||
val callBack = WooLiveData<Customer>()
|
||||
woocommerce!!.CustomerRepository().customer(id).enqueue(callBack)
|
||||
return callBack
|
||||
}
|
||||
|
||||
fun customers(): WooLiveData<List<Customer>> {
|
||||
val callBack = WooLiveData<List<Customer>>()
|
||||
|
||||
woocommerce!!.CustomerRepository().customers().enqueue(callBack)
|
||||
|
||||
return callBack
|
||||
}
|
||||
|
||||
fun customers(customerFilter: CustomerFilter): WooLiveData<List<Customer>> {
|
||||
val callBack = WooLiveData<List<Customer>>()
|
||||
woocommerce!!.CustomerRepository().customers(customerFilter).enqueue(callBack)
|
||||
return callBack
|
||||
}
|
||||
|
||||
fun update(id: Int, customer: Customer): WooLiveData<Customer> {
|
||||
val callBack = WooLiveData<Customer>()
|
||||
woocommerce!!.CustomerRepository().update(id, customer).enqueue(callBack)
|
||||
|
||||
return callBack
|
||||
}
|
||||
|
||||
fun delete(id: Int): WooLiveData<Customer> {
|
||||
val callBack = WooLiveData<Customer>()
|
||||
woocommerce!!.CustomerRepository().delete(id).enqueue(callBack)
|
||||
|
||||
return callBack
|
||||
}
|
||||
|
||||
fun delete(id: Int, force: Boolean): WooLiveData<Customer> {
|
||||
val callBack = WooLiveData<Customer>()
|
||||
woocommerce!!.CustomerRepository().delete(id, force).enqueue(callBack)
|
||||
|
||||
return callBack
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -1,111 +0,0 @@
|
||||
package me.gilo.wc.repo;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import android.util.Log;
|
||||
import com.google.android.gms.tasks.Continuation;
|
||||
import com.google.android.gms.tasks.OnFailureListener;
|
||||
import com.google.android.gms.tasks.Task;
|
||||
import com.google.firebase.firestore.CollectionReference;
|
||||
import com.google.firebase.firestore.DocumentReference;
|
||||
import com.google.firebase.firestore.DocumentSnapshot;
|
||||
import com.google.firebase.firestore.FirebaseFirestore;
|
||||
import me.gilo.wc.models.Identifiable;
|
||||
import me.gilo.wc.models.Repository;
|
||||
|
||||
|
||||
/**
|
||||
* Manages data access for Firebase
|
||||
*/
|
||||
public class FirebaseRepository<TEntity extends Identifiable<String>> implements Repository<TEntity, String> {
|
||||
|
||||
private static final String TAG = "FirebaseRepository";
|
||||
|
||||
private final Class<TEntity> entityClass;
|
||||
|
||||
private final CollectionReference collectionReference;
|
||||
private final String collectionName;
|
||||
|
||||
|
||||
public FirebaseRepository(Class<TEntity> entityClass, String collectionName) {
|
||||
this.collectionName = collectionName;
|
||||
this.entityClass = entityClass;
|
||||
|
||||
FirebaseFirestore db = FirebaseFirestore.getInstance();
|
||||
this.collectionReference = db.collection(this.collectionName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Task<Boolean> exists(final String documentName) {
|
||||
DocumentReference documentReference = collectionReference.document(documentName);
|
||||
Log.i(TAG, "Checking existence of '" + documentName + "' in '" + collectionName + "'.");
|
||||
|
||||
return documentReference.get().continueWith(new Continuation<DocumentSnapshot, Boolean>() {
|
||||
@Override
|
||||
public Boolean then(@NonNull Task<DocumentSnapshot> task) {
|
||||
Log.d(TAG,"Checking if '" + documentName + "' exists in '" + collectionName +"'.");
|
||||
return task.getResult().exists();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Task<TEntity> get(String id) {
|
||||
final String documentName = id;
|
||||
DocumentReference documentReference = collectionReference.document(documentName);
|
||||
Log.i(TAG, "Getting '" + documentName + "' in '" + collectionName + "'.");
|
||||
|
||||
return documentReference.get().continueWith(new Continuation<DocumentSnapshot, TEntity>() {
|
||||
@Override
|
||||
public TEntity then(@NonNull Task<DocumentSnapshot> task) throws Exception {
|
||||
DocumentSnapshot documentSnapshot = task.getResult();
|
||||
if (documentSnapshot.exists()) {
|
||||
return documentSnapshot.toObject(entityClass);
|
||||
} else {
|
||||
Log.d(TAG, "Document '" + documentName + "' does not exist in '" + collectionName + "'.");
|
||||
return entityClass.newInstance();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Task<Void> create(TEntity entity) {
|
||||
final String documentName = entity.getEntityKey();
|
||||
DocumentReference documentReference = collectionReference.document(documentName);
|
||||
Log.i(TAG, "Creating '" + documentName + "' in '" + collectionName + "'.");
|
||||
return documentReference.set(entity).addOnFailureListener(new OnFailureListener() {
|
||||
@Override
|
||||
public void onFailure(@NonNull Exception e) {
|
||||
Log.d(TAG, "There was an error creating '" + documentName + "' in '" + collectionName + "'!", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Task<Void> update(TEntity entity) {
|
||||
final String documentName = entity.getEntityKey();
|
||||
DocumentReference documentReference = collectionReference.document(documentName);
|
||||
Log.i(TAG, "Updating '" + documentName + "' in '" + collectionName + "'.");
|
||||
|
||||
return documentReference.set(entity).addOnFailureListener(new OnFailureListener() {
|
||||
@Override
|
||||
public void onFailure(@NonNull Exception e) {
|
||||
Log.d(TAG, "There was an error updating '" + documentName + "' in '" + collectionName + "'.", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Task<Void> delete(final String documentName) {
|
||||
DocumentReference documentReference = collectionReference.document(documentName);
|
||||
Log.i(TAG, "Deleting '" + documentName + "' in '" + collectionName + "'.");
|
||||
|
||||
return documentReference.delete().addOnFailureListener(new OnFailureListener() {
|
||||
@Override
|
||||
public void onFailure(@NonNull Exception e) {
|
||||
Log.d(TAG, "There was an error deleting '" + documentName + "' in '" + collectionName + "'.", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
102
app/src/main/java/me/gilo/wc/repo/FirebaseRepository.kt
Normal file
102
app/src/main/java/me/gilo/wc/repo/FirebaseRepository.kt
Normal file
@ -0,0 +1,102 @@
|
||||
package me.gilo.wc.repo
|
||||
|
||||
import android.util.Log
|
||||
import com.google.android.gms.tasks.Continuation
|
||||
import com.google.android.gms.tasks.OnFailureListener
|
||||
import com.google.android.gms.tasks.Task
|
||||
import com.google.firebase.firestore.CollectionReference
|
||||
import com.google.firebase.firestore.DocumentReference
|
||||
import com.google.firebase.firestore.DocumentSnapshot
|
||||
import com.google.firebase.firestore.FirebaseFirestore
|
||||
import me.gilo.wc.models.Identifiable
|
||||
import me.gilo.wc.models.Repository
|
||||
|
||||
|
||||
/**
|
||||
* Manages data access for Firebase
|
||||
*/
|
||||
open class FirebaseRepository<TEntity : Identifiable<String>>(
|
||||
private val entityClass: Class<TEntity>,
|
||||
private val collectionName: String
|
||||
) : Repository<TEntity, String> {
|
||||
|
||||
private val collectionReference: CollectionReference
|
||||
|
||||
|
||||
init {
|
||||
|
||||
val db = FirebaseFirestore.getInstance()
|
||||
this.collectionReference = db.collection(this.collectionName)
|
||||
}
|
||||
|
||||
override fun exists(documentName: String): Task<Boolean> {
|
||||
val documentReference = collectionReference.document(documentName)
|
||||
Log.i(TAG, "Checking existence of '$documentName' in '$collectionName'.")
|
||||
|
||||
return documentReference.get().continueWith { task ->
|
||||
Log.d(TAG, "Checking if '$documentName' exists in '$collectionName'.")
|
||||
task.result!!.exists()
|
||||
}
|
||||
}
|
||||
|
||||
override fun get(id: String): Task<TEntity> {
|
||||
val documentReference = collectionReference.document(id)
|
||||
Log.i(TAG, "Getting '$id' in '$collectionName'.")
|
||||
|
||||
return documentReference.get().continueWith { task ->
|
||||
val documentSnapshot = task.result
|
||||
if (documentSnapshot!!.exists()) {
|
||||
documentSnapshot.toObject(entityClass)
|
||||
} else {
|
||||
Log.d(TAG, "Document '$id' does not exist in '$collectionName'.")
|
||||
entityClass.newInstance()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun create(entity: TEntity): Task<Void> {
|
||||
val documentName = entity.entityKey
|
||||
val documentReference = collectionReference.document(documentName)
|
||||
Log.i(TAG, "Creating '$documentName' in '$collectionName'.")
|
||||
return documentReference.set(entity).addOnFailureListener { e ->
|
||||
Log.d(
|
||||
TAG,
|
||||
"There was an error creating '$documentName' in '$collectionName'!",
|
||||
e
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
override fun update(entity: TEntity): Task<Void> {
|
||||
val documentName = entity.entityKey
|
||||
val documentReference = collectionReference.document(documentName)
|
||||
Log.i(TAG, "Updating '$documentName' in '$collectionName'.")
|
||||
|
||||
return documentReference.set(entity).addOnFailureListener { e ->
|
||||
Log.d(
|
||||
TAG,
|
||||
"There was an error updating '$documentName' in '$collectionName'.",
|
||||
e
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
override fun delete(documentName: String): Task<Void> {
|
||||
val documentReference = collectionReference.document(documentName)
|
||||
Log.i(TAG, "Deleting '$documentName' in '$collectionName'.")
|
||||
|
||||
return documentReference.delete().addOnFailureListener { e ->
|
||||
Log.d(
|
||||
TAG,
|
||||
"There was an error deleting '$documentName' in '$collectionName'.",
|
||||
e
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
private val TAG = "FirebaseRepository"
|
||||
}
|
||||
|
||||
}
|
||||
@ -3,6 +3,7 @@ package me.gilo.wc.ui
|
||||
import android.content.Context
|
||||
import android.support.v7.app.AppCompatActivity
|
||||
import io.github.inflationx.viewpump.ViewPumpContextWrapper
|
||||
import me.gilo.wc.Config
|
||||
import me.gilo.wc.ui.state.ProgressDialogFragment
|
||||
import me.gilo.woodroid.Woocommerce
|
||||
|
||||
@ -11,10 +12,10 @@ open class BaseActivity : AppCompatActivity() {
|
||||
private lateinit var progressDialog : ProgressDialogFragment
|
||||
|
||||
val woocommerce = Woocommerce.Builder()
|
||||
.setSiteUrl("http://157.230.131.179")
|
||||
.setSiteUrl(Config.siteUrl)
|
||||
.setApiVersion(Woocommerce.API_V3)
|
||||
.setConsumerKey("ck_26c61abd7eeff238d87dc56585bf26cb2d1a1ec3")
|
||||
.setConsumerSecret("cs_062e8e3a7ae0ce08fdebc0c39f8f834d5e87598e")
|
||||
.setConsumerKey(Config.consumerKey)
|
||||
.setConsumerSecret(Config.consumerSecret)
|
||||
.build()
|
||||
|
||||
|
||||
|
||||
@ -40,7 +40,6 @@ abstract class WooDroidActivity<T : ViewModel> : BaseActivity() {
|
||||
startActivity(Intent(baseContext, SignInActivity::class.java))
|
||||
finish()
|
||||
}
|
||||
|
||||
cart()
|
||||
}
|
||||
|
||||
|
||||
@ -4,28 +4,18 @@ import android.arch.lifecycle.Observer
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.support.design.widget.Snackbar
|
||||
import android.support.v7.app.AppCompatActivity
|
||||
import android.widget.Toast
|
||||
import io.github.inflationx.viewpump.ViewPumpContextWrapper
|
||||
import me.gilo.wc.R
|
||||
|
||||
import kotlinx.android.synthetic.main.activity_anonymous_sign_in.*
|
||||
import kotlinx.android.synthetic.main.content_sign_in.*
|
||||
import me.gilo.raison.ui.user.onboarding.SignUpActivity
|
||||
import me.gilo.wc.common.BaseActivity
|
||||
import me.gilo.wc.common.Status
|
||||
import me.gilo.wc.ui.WooDroidActivity
|
||||
import me.gilo.wc.ui.home.HomeActivity
|
||||
import me.gilo.wc.ui.state.ProgressDialogFragment
|
||||
import me.gilo.wc.viewmodels.UserViewModel
|
||||
import java.util.regex.Matcher
|
||||
import java.util.regex.Pattern
|
||||
|
||||
class AnonymousSignInActivity : WooDroidActivity<UserViewModel>() {
|
||||
|
||||
|
||||
override lateinit var viewModel : UserViewModel
|
||||
override lateinit var viewModel: UserViewModel
|
||||
|
||||
override fun attachBaseContext(newBase: Context) {
|
||||
super.attachBaseContext(ViewPumpContextWrapper.wrap(newBase))
|
||||
@ -41,30 +31,29 @@ class AnonymousSignInActivity : WooDroidActivity<UserViewModel>() {
|
||||
}
|
||||
|
||||
private fun anonymousSignIn() {
|
||||
viewModel.anonymousSignIn().observe(this, Observer {
|
||||
response->
|
||||
when (response!!.status()){
|
||||
Status.LOADING ->{
|
||||
showLoading("Setting you up with an account", "This will only take a short while")
|
||||
}
|
||||
viewModel.anonymousSignIn().observe(this, Observer { response ->
|
||||
when (response!!.status()) {
|
||||
Status.LOADING -> {
|
||||
showLoading("Setting you up with an account", "This will only take a short while")
|
||||
}
|
||||
|
||||
Status.SUCCESS ->{
|
||||
stopShowingLoading()
|
||||
startActivity(Intent(baseContext, HomeActivity::class.java))
|
||||
|
||||
}
|
||||
|
||||
Status.ERROR ->{
|
||||
stopShowingLoading()
|
||||
Toast.makeText(baseContext, "Something went wrong", Toast.LENGTH_LONG).show()
|
||||
}
|
||||
|
||||
Status.EMPTY ->{
|
||||
stopShowingLoading()
|
||||
}
|
||||
Status.SUCCESS -> {
|
||||
stopShowingLoading()
|
||||
startActivity(Intent(baseContext, HomeActivity::class.java))
|
||||
|
||||
}
|
||||
})
|
||||
|
||||
Status.ERROR -> {
|
||||
stopShowingLoading()
|
||||
Toast.makeText(baseContext, "Something went wrong", Toast.LENGTH_LONG).show()
|
||||
}
|
||||
|
||||
Status.EMPTY -> {
|
||||
stopShowingLoading()
|
||||
}
|
||||
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,16 +1,17 @@
|
||||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||
|
||||
buildscript {
|
||||
ext.kotlin_version = '1.3.11'
|
||||
ext.kotlin_version = '1.3.31'
|
||||
ext.kotlin_version = '1.3.31'
|
||||
repositories {
|
||||
google()
|
||||
jcenter()
|
||||
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:3.5.0-alpha10'
|
||||
classpath 'com.android.tools.build:gradle:3.4.1'
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
classpath 'com.google.gms:google-services:4.0.1'
|
||||
classpath 'com.google.gms:google-services:4.2.0'
|
||||
// NOTE: Do not place your application dependencies here; they belong
|
||||
// in the individual module build.gradle files
|
||||
}
|
||||
|
||||
@ -1,4 +1,6 @@
|
||||
apply plugin: 'com.android.library'
|
||||
apply plugin: 'kotlin-android-extensions'
|
||||
apply plugin: 'kotlin-android'
|
||||
|
||||
android {
|
||||
compileSdkVersion 28
|
||||
@ -51,6 +53,10 @@ dependencies {
|
||||
implementation 'com.fasterxml.jackson.core:jackson-databind:2.9.8'
|
||||
|
||||
implementation 'com.squareup.okhttp3:okhttp-urlconnection:3.0.0-RC1'
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
|
||||
|
||||
|
||||
}
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
@ -17,24 +17,24 @@ public class Woocommerce {
|
||||
public static final ApiVersion API_V2 = ApiVersion.API_VERSION2;
|
||||
public static final ApiVersion API_V3 = ApiVersion.API_VERSION3;
|
||||
|
||||
final OrderNoteRepository orderNoteRepository;
|
||||
final RefundRepository refundRepository;
|
||||
final AttributeRepository attributeRepository;
|
||||
final AttributeTermRepository attributeTermRepository;
|
||||
final CategoryRepository categoryRepository;
|
||||
final ShippingClassRepository shippingClassRepository;
|
||||
final TagRepository tagRepository;
|
||||
final VariationRepository variationRepository;
|
||||
final CouponRepository couponRepository;
|
||||
final CustomerRepository customerRepository;
|
||||
final OrderRepository orderRepository;
|
||||
final ProductRepository productRepository;
|
||||
final ReviewRepository reviewRepository;
|
||||
final ReportsRepository reportsRepository;
|
||||
final CartRepository cartRepository;
|
||||
final PaymentGatewayRepository paymentGatewayRepository;
|
||||
final SettingsRepository settingsRepository;
|
||||
final ShippingMethodRepository shippingMethodRepository;
|
||||
private final OrderNoteRepository orderNoteRepository;
|
||||
private final RefundRepository refundRepository;
|
||||
private final AttributeRepository attributeRepository;
|
||||
private final AttributeTermRepository attributeTermRepository;
|
||||
private final CategoryRepository categoryRepository;
|
||||
private final ShippingClassRepository shippingClassRepository;
|
||||
private final TagRepository tagRepository;
|
||||
private final VariationRepository variationRepository;
|
||||
private final CouponRepository couponRepository;
|
||||
private final CustomerRepository customerRepository;
|
||||
private final OrderRepository orderRepository;
|
||||
private final ProductRepository productRepository;
|
||||
private final ReviewRepository reviewRepository;
|
||||
private final ReportsRepository reportsRepository;
|
||||
private final CartRepository cartRepository;
|
||||
private final PaymentGatewayRepository paymentGatewayRepository;
|
||||
private final SettingsRepository settingsRepository;
|
||||
private final ShippingMethodRepository shippingMethodRepository;
|
||||
|
||||
public static Builder Builder(){
|
||||
return new Builder();
|
||||
|
||||
@ -76,11 +76,11 @@ public class ListFilter {
|
||||
}
|
||||
|
||||
public void setAfter(Date date) {
|
||||
setAfter(Converter.getDateString(date));
|
||||
setAfter(Converter.INSTANCE.getDateString(date));
|
||||
}
|
||||
|
||||
public void setBefore(Date date) {
|
||||
setBefore(Converter.getDateString(date));
|
||||
setBefore(Converter.INSTANCE.getDateString(date));
|
||||
}
|
||||
|
||||
public void setBefore(String before) {
|
||||
|
||||
@ -1,105 +0,0 @@
|
||||
package me.gilo.woodroid.repo;
|
||||
|
||||
import android.content.Context;
|
||||
import me.gilo.woodroid.data.api.CartAPI;
|
||||
import me.gilo.woodroid.data.cookie.AddCookiesInterceptor;
|
||||
import me.gilo.woodroid.data.cookie.ReceivedCookiesInterceptor;
|
||||
import me.gilo.woodroid.models.LineItem;
|
||||
import me.gilo.woodroid.models.filters.CartFilter;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.logging.HttpLoggingInterceptor;
|
||||
import retrofit2.Retrofit;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.converter.gson.GsonConverterFactory;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class CartRepository{
|
||||
|
||||
CartAPI apiService;
|
||||
Retrofit retrofit;
|
||||
|
||||
String baseUrl;
|
||||
|
||||
public CartRepository(String baseUrl, String consumerKey, String consumerSecret) {
|
||||
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
|
||||
loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
|
||||
|
||||
|
||||
OkHttpClient client = new OkHttpClient.Builder()
|
||||
.addInterceptor(loggingInterceptor)
|
||||
.readTimeout(30, TimeUnit.SECONDS)
|
||||
.writeTimeout(30, TimeUnit.SECONDS)
|
||||
.connectTimeout(15, TimeUnit.SECONDS)
|
||||
.build();
|
||||
|
||||
retrofit = new Retrofit.Builder()
|
||||
.baseUrl(baseUrl)
|
||||
.addConverterFactory(GsonConverterFactory.create())
|
||||
.client(client)
|
||||
.build();
|
||||
|
||||
this.baseUrl = baseUrl;
|
||||
|
||||
apiService = retrofit.create(CartAPI.class);
|
||||
}
|
||||
|
||||
public void turnOnCookies(Context context){
|
||||
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
|
||||
loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
|
||||
|
||||
OkHttpClient client = new OkHttpClient.Builder()
|
||||
.addInterceptor(new AddCookiesInterceptor(context))
|
||||
.addInterceptor(new ReceivedCookiesInterceptor(context))
|
||||
.addInterceptor(loggingInterceptor)
|
||||
.readTimeout(30, TimeUnit.SECONDS)
|
||||
.writeTimeout(30, TimeUnit.SECONDS)
|
||||
.connectTimeout(15, TimeUnit.SECONDS)
|
||||
.build();
|
||||
|
||||
retrofit = new Retrofit.Builder()
|
||||
.baseUrl(baseUrl)
|
||||
.addConverterFactory(GsonConverterFactory.create())
|
||||
.client(client)
|
||||
.build();
|
||||
|
||||
apiService = retrofit.create(CartAPI.class);
|
||||
}
|
||||
|
||||
public Call<String> clear() {
|
||||
return apiService.clear();
|
||||
}
|
||||
|
||||
|
||||
public Call<Integer> count(int id) {
|
||||
return apiService.count();
|
||||
}
|
||||
|
||||
public Call<Map<String, LineItem>> cart() {
|
||||
return apiService.list();
|
||||
}
|
||||
|
||||
public Call<Map<String, LineItem>> addToCart(LineItem lineItem) {
|
||||
return apiService.addToCart(lineItem);
|
||||
}
|
||||
|
||||
public Call<String> delete(String cardId) {
|
||||
CartFilter cartFilter = new CartFilter(cardId);
|
||||
return apiService.delete(cartFilter);
|
||||
}
|
||||
|
||||
public Call<String> restore(String cardId) {
|
||||
CartFilter cartFilter = new CartFilter(cardId);
|
||||
return apiService.restore(cartFilter);
|
||||
}
|
||||
|
||||
public Call<String> update(String cardId, int quantity) {
|
||||
CartFilter cartFilter = new CartFilter(cardId);
|
||||
cartFilter.setQuantity(quantity);
|
||||
|
||||
return apiService.update(cartFilter);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,99 @@
|
||||
package me.gilo.woodroid.repo
|
||||
|
||||
import android.content.Context
|
||||
import me.gilo.woodroid.data.api.CartAPI
|
||||
import me.gilo.woodroid.data.cookie.AddCookiesInterceptor
|
||||
import me.gilo.woodroid.data.cookie.ReceivedCookiesInterceptor
|
||||
import me.gilo.woodroid.models.LineItem
|
||||
import me.gilo.woodroid.models.filters.CartFilter
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.logging.HttpLoggingInterceptor
|
||||
import retrofit2.Retrofit
|
||||
import retrofit2.Call
|
||||
import retrofit2.converter.gson.GsonConverterFactory
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
class CartRepository(internal var baseUrl: String, consumerKey: String, consumerSecret: String) {
|
||||
|
||||
internal var apiService: CartAPI
|
||||
internal var retrofit: Retrofit
|
||||
|
||||
init {
|
||||
val loggingInterceptor = HttpLoggingInterceptor()
|
||||
loggingInterceptor.level = HttpLoggingInterceptor.Level.BODY
|
||||
|
||||
|
||||
val client = OkHttpClient.Builder()
|
||||
.addInterceptor(loggingInterceptor)
|
||||
.readTimeout(30, TimeUnit.SECONDS)
|
||||
.writeTimeout(30, TimeUnit.SECONDS)
|
||||
.connectTimeout(15, TimeUnit.SECONDS)
|
||||
.build()
|
||||
|
||||
retrofit = Retrofit.Builder()
|
||||
.baseUrl(baseUrl)
|
||||
.addConverterFactory(GsonConverterFactory.create())
|
||||
.client(client)
|
||||
.build()
|
||||
|
||||
apiService = retrofit.create(CartAPI::class.java)
|
||||
}
|
||||
|
||||
fun turnOnCookies(context: Context) {
|
||||
val loggingInterceptor = HttpLoggingInterceptor()
|
||||
loggingInterceptor.level = HttpLoggingInterceptor.Level.BODY
|
||||
|
||||
val client = OkHttpClient.Builder()
|
||||
.addInterceptor(AddCookiesInterceptor(context))
|
||||
.addInterceptor(ReceivedCookiesInterceptor(context))
|
||||
.addInterceptor(loggingInterceptor)
|
||||
.readTimeout(30, TimeUnit.SECONDS)
|
||||
.writeTimeout(30, TimeUnit.SECONDS)
|
||||
.connectTimeout(15, TimeUnit.SECONDS)
|
||||
.build()
|
||||
|
||||
retrofit = Retrofit.Builder()
|
||||
.baseUrl(baseUrl)
|
||||
.addConverterFactory(GsonConverterFactory.create())
|
||||
.client(client)
|
||||
.build()
|
||||
|
||||
apiService = retrofit.create(CartAPI::class.java)
|
||||
}
|
||||
|
||||
fun clear(): Call<String> {
|
||||
return apiService.clear()
|
||||
}
|
||||
|
||||
|
||||
fun count(id: Int): Call<Int> {
|
||||
return apiService.count()
|
||||
}
|
||||
|
||||
fun cart(): Call<Map<String, LineItem>> {
|
||||
return apiService.list()
|
||||
}
|
||||
|
||||
fun addToCart(lineItem: LineItem): Call<Map<String, LineItem>> {
|
||||
return apiService.addToCart(lineItem)
|
||||
}
|
||||
|
||||
fun delete(cardId: String): Call<String> {
|
||||
val cartFilter = CartFilter(cardId)
|
||||
return apiService.delete(cartFilter)
|
||||
}
|
||||
|
||||
fun restore(cardId: String): Call<String> {
|
||||
val cartFilter = CartFilter(cardId)
|
||||
return apiService.restore(cartFilter)
|
||||
}
|
||||
|
||||
fun update(cardId: String, quantity: Int): Call<String> {
|
||||
val cartFilter = CartFilter(cardId)
|
||||
cartFilter.quantity = quantity
|
||||
|
||||
return apiService.update(cartFilter)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -1,12 +0,0 @@
|
||||
package me.gilo.woodroid.utils;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
public class Converter {
|
||||
|
||||
public static String getDateString(Date date){
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
|
||||
return sdf.format(date);
|
||||
}
|
||||
}
|
||||
13
woodroid/src/main/java/me/gilo/woodroid/utils/Converter.kt
Normal file
13
woodroid/src/main/java/me/gilo/woodroid/utils/Converter.kt
Normal file
@ -0,0 +1,13 @@
|
||||
package me.gilo.woodroid.utils
|
||||
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Date
|
||||
import java.util.Locale
|
||||
|
||||
object Converter {
|
||||
|
||||
fun getDateString(date: Date): String {
|
||||
val sdf = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX", Locale.getDefault())
|
||||
return sdf.format(date)
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user