Added home page and categories page on sample app

This commit is contained in:
gilokimu 2019-03-06 05:53:47 +03:00
parent 11ffd08276
commit 9786252c78
28 changed files with 735 additions and 21 deletions

View File

@ -12,6 +12,16 @@
android:roundIcon="@mipmap/ic_launcher_round" android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/AppTheme"> android:theme="@style/AppTheme">
<activity
android:name=".ui.home.HomeActivity"
android:label="@string/title_activity_home"
android:theme="@style/AppTheme.NoActionBar">
</activity>
<activity
android:name=".ui.category.CategoryActivity"
android:label="@string/title_activity_category"
android:theme="@style/AppTheme.NoActionBar">
</activity>
<activity <activity
android:name=".ui.product.NavigatioDrawerActivity" android:name=".ui.product.NavigatioDrawerActivity"
android:label="@string/title_activity_navigatio_drawer" android:label="@string/title_activity_navigatio_drawer"

View File

@ -1,18 +1,9 @@
package me.gilo.wc package me.gilo.wc
import android.content.Intent import android.content.Intent
import android.support.v7.app.AppCompatActivity
import android.os.Bundle import android.os.Bundle
import kotlinx.android.synthetic.main.activity_main.* import android.support.v7.app.AppCompatActivity
import me.gilo.wc.ui.MenuActivity import me.gilo.wc.ui.home.HomeActivity
import me.gilo.wc.ui.product.ShopActivity
import me.gilo.woodroid.Woocommerce
import me.gilo.woodroid.models.Coupon
import me.gilo.woodroid.models.Product
import java.util.ArrayList
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response
class MainActivity : AppCompatActivity() { class MainActivity : AppCompatActivity() {
@ -22,7 +13,7 @@ class MainActivity : AppCompatActivity() {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main) setContentView(R.layout.activity_main)
startActivity(Intent(baseContext, ShopActivity::class.java)); startActivity(Intent(baseContext, HomeActivity::class.java))
finish() finish()
} }

View File

@ -0,0 +1,34 @@
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();
}
}

View File

@ -0,0 +1,30 @@
package me.gilo.wc.adapter.viewholder
import android.content.Context
import android.support.v7.widget.RecyclerView
import android.text.Html
import android.view.View
import android.widget.TextView
import me.gilo.wc.R
import me.gilo.woodroid.models.Category
class CategoryViewHolder(val context: Context, itemView: View) :
RecyclerView.ViewHolder(itemView) {
fun renderView(category: Category) {
val tvTitle = itemView.findViewById<TextView>(R.id.tvTitle)
val tvDescription = itemView.findViewById<TextView>(R.id.tvDescription)
tvTitle.text = category.name
tvDescription.text = Html.fromHtml(category.description)
// itemView.setOnClickListener{
// val intent = Intent(context, CouponActivity::class.java)
// intent.putExtra("couponId", coupon.id)
//
// context.startActivity(intent)
// }
}
}

View File

@ -3,6 +3,7 @@ package me.gilo.wc.di;
import dagger.Module; import dagger.Module;
import dagger.android.ContributesAndroidInjector; import dagger.android.ContributesAndroidInjector;
import me.gilo.wc.MainActivity; import me.gilo.wc.MainActivity;
import me.gilo.wc.ui.home.HomeActivity;
import me.gilo.wc.ui.product.ProductActivity; import me.gilo.wc.ui.product.ProductActivity;
import me.gilo.wc.ui.product.ShopActivity; import me.gilo.wc.ui.product.ShopActivity;
@ -18,4 +19,7 @@ abstract class ActivitiesModule {
@ContributesAndroidInjector @ContributesAndroidInjector
abstract ProductActivity contributesProductActivity(); abstract ProductActivity contributesProductActivity();
@ContributesAndroidInjector
abstract HomeActivity contributesHomeActivity();
} }

View File

@ -6,6 +6,7 @@ import dagger.Binds;
import dagger.Module; import dagger.Module;
import dagger.multibindings.IntoMap; import dagger.multibindings.IntoMap;
import me.gilo.wc.utils.ViewModelFactory; import me.gilo.wc.utils.ViewModelFactory;
import me.gilo.wc.viewmodels.CategoryViewModel;
import me.gilo.wc.viewmodels.ProductViewModel; import me.gilo.wc.viewmodels.ProductViewModel;
@ -16,7 +17,12 @@ public abstract class ViewModelModule {
@Binds @Binds
@IntoMap @IntoMap
@ViewModelKey(ProductViewModel.class) @ViewModelKey(ProductViewModel.class)
abstract ViewModel bindUserViewModel(ProductViewModel viewModel); abstract ViewModel bindProductViewModel(ProductViewModel viewModel);
@Binds
@IntoMap
@ViewModelKey(CategoryViewModel.class)
abstract ViewModel bindCategoryViewModel(CategoryViewModel viewModel);
@Binds @Binds
abstract ViewModelProvider.Factory bindViewModelFactory(ViewModelFactory factory); abstract ViewModelProvider.Factory bindViewModelFactory(ViewModelFactory factory);

View File

@ -0,0 +1,73 @@
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;
}
}

View File

@ -0,0 +1,103 @@
package me.gilo.wc.ui.home
import android.os.Bundle
import android.support.v4.app.Fragment
import android.support.v7.widget.LinearLayoutManager
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import kotlinx.android.synthetic.main.fragment_category.*
import me.gilo.wc.R
import me.gilo.wc.adapter.CategoryAdapter
import me.gilo.wc.common.Status
import me.gilo.wc.viewmodels.CategoryViewModel
import me.gilo.woodroid.models.Category
import java.util.*
class CategoryFragment : Fragment() {
lateinit var viewModel: CategoryViewModel
val TAG = "CategoryFragment"
lateinit var adapter: CategoryAdapter
lateinit var categories: ArrayList<Category>
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
arguments?.let {
}
}
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
return inflater.inflate(R.layout.fragment_category, container, false)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
viewModel = (activity as HomeActivity).getViewModel(CategoryViewModel::class.java)
val layoutManager = LinearLayoutManager(activity, LinearLayoutManager.VERTICAL, false)
rvCategory.layoutManager = layoutManager
rvCategory.isNestedScrollingEnabled = false
categories = ArrayList()
adapter = CategoryAdapter(categories)
rvCategory.adapter = adapter
categories()
}
private fun categories() {
viewModel.categories().observe(this, android.arch.lifecycle.Observer { response ->
when (response!!.status()) {
Status.LOADING -> {
}
Status.SUCCESS -> {
categories.clear()
val categoriesResponse = response.data()
for (category in categoriesResponse) {
categories.add(category)
}
adapter.notifyDataSetChanged()
}
Status.ERROR -> {
}
Status.EMPTY -> {
}
}
})
}
companion object {
@JvmStatic
fun newInstance() =
CategoryFragment().apply {
arguments = Bundle().apply {
}
}
}
}

View File

@ -0,0 +1,52 @@
package me.gilo.wc.ui.home
import android.content.Context
import android.os.Bundle
import android.support.design.widget.BottomNavigationView
import android.support.v4.app.Fragment
import io.github.inflationx.viewpump.ViewPumpContextWrapper
import kotlinx.android.synthetic.main.activity_home.*
import me.gilo.wc.R
import me.gilo.wc.common.BaseActivity
class HomeActivity : BaseActivity() {
override fun attachBaseContext(newBase: Context) {
super.attachBaseContext(ViewPumpContextWrapper.wrap(newBase))
}
private val mOnNavigationItemSelectedListener = BottomNavigationView.OnNavigationItemSelectedListener { item ->
var selectedFragment: Fragment? = HomeFragment.newInstance()
when (item.itemId) {
R.id.navigation_home -> {
selectedFragment = HomeFragment.newInstance()
}
R.id.navigation_deals -> {
selectedFragment = CategoryFragment.newInstance()
}
R.id.navigation_account -> {
selectedFragment = ProfileFragment.newInstance()
}
}
val transaction = supportFragmentManager.beginTransaction()
transaction.replace(R.id.container, selectedFragment!!)
transaction.commit()
true
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_home)
navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener)
val transaction = supportFragmentManager.beginTransaction()
transaction.replace(R.id.container, HomeFragment.newInstance())
transaction.commit()
}
}

View File

@ -0,0 +1,48 @@
package me.gilo.wc.ui.home
import android.os.Bundle
import android.support.v4.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import me.gilo.wc.R
import me.gilo.wc.viewmodels.ProductViewModel
class HomeFragment : Fragment() {
lateinit var viewModel: ProductViewModel
val TAG = "HomeFragment"
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
arguments?.let {
}
}
override fun onCreateView(inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?): View {
return inflater.inflate(R.layout.fragment_home, container, false)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
}
companion object {
@JvmStatic
fun newInstance() =
HomeFragment().apply {
arguments = Bundle().apply {
}
}
}
}

View File

@ -0,0 +1,49 @@
package me.gilo.wc.ui.home
import android.os.Bundle
import android.support.v4.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import me.gilo.wc.R
import me.gilo.wc.viewmodels.ProductViewModel
class ProfileFragment : Fragment() {
lateinit var viewModel: ProductViewModel
val TAG = "ProfileFragment"
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
arguments?.let {
}
}
override fun onCreateView(inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?): View {
return inflater.inflate(R.layout.fragment_profile, container, false)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
}
companion object {
@JvmStatic
fun newInstance() =
ProfileFragment().apply {
arguments = Bundle().apply {
}
}
}
}

View File

@ -0,0 +1,51 @@
package me.gilo.wc.viewmodels;
import android.arch.lifecycle.ViewModel;
import me.gilo.wc.common.WooLiveData;
import me.gilo.wc.repo.CategoryRepository;
import me.gilo.woodroid.models.Category;
import me.gilo.woodroid.models.filters.ProductCategoryFilter;
import javax.inject.Inject;
import java.util.List;
public final class CategoryViewModel extends ViewModel {
private final CategoryRepository categoryRepository;
@Inject
CategoryViewModel(CategoryRepository categoryRepository) {
this.categoryRepository = categoryRepository;
}
public WooLiveData<Category> create(Category category) {
return categoryRepository.create(category);
}
public WooLiveData<Category> category(int id) {
return categoryRepository.category(id);
}
public WooLiveData<List<Category>> categories() {
return categoryRepository.categories();
}
public WooLiveData<List<Category>> categories(ProductCategoryFilter productCategoryFilter) {
return categoryRepository.categories();
}
public WooLiveData<Category> update(int id, Category category) {
return categoryRepository.update(id, category);
}
public WooLiveData<Category> delete(int id) {
return categoryRepository.delete(id);
}
public WooLiveData<Category> delete(int id, boolean force) {
return categoryRepository.delete(id, force);
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 315 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<vector android:height="24.0dip" android:width="24.0dip" android:viewportWidth="24.0" android:viewportHeight="24.0"
xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#00000000" android:pathData="M12,8m-3,0a3,3 0,1 1,6 0a3,3 0,1 1,-6 0" android:strokeColor="#ff9aa0a6" android:strokeWidth="2.0" />
<path android:fillColor="#ff9aa0a6" android:pathData="M12,13c-2.7,0 -8,1.3 -8,4v3h16v-3C20,14.3 14.7,13 12,13zM18,18H6v-1c0.2,-0.7 3.3,-2 6,-2s5.8,1.3 6,2V18z" />
</vector>

Binary file not shown.

After

Width:  |  Height:  |  Size: 315 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<vector android:height="24.0dip" android:width="24.0dip" android:viewportWidth="24.0" android:viewportHeight="24.0"
xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#00000000" android:pathData="M12,8m-3,0a3,3 0,1 1,6 0a3,3 0,1 1,-6 0" android:strokeColor="#ff9aa0a6" android:strokeWidth="2.0" />
<path android:fillColor="#ff9aa0a6" android:pathData="M12,13c-2.7,0 -8,1.3 -8,4v3h16v-3C20,14.3 14.7,13 12,13zM18,18H6v-1c0.2,-0.7 3.3,-2 6,-2s5.8,1.3 6,2V18z" />
</vector>

View File

@ -0,0 +1,47 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".ui.home.HomeActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:title="WooDroid"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<LinearLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
/>
<android.support.design.widget.BottomNavigationView
android:id="@+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="0dp"
android:layout_marginEnd="0dp"
android:layout_gravity="bottom"
android:background="?android:attr/windowBackground"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:menu="@menu/navigation" />
</LinearLayout>

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:showIn="@layout/activity_home"
tools:context=".ui.home.HomeActivity">
</android.support.constraint.ConstraintLayout>

View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="16dp"
android:id="@+id/rvCategory"
>
</android.support.v7.widget.RecyclerView>
</android.support.constraint.ConstraintLayout>

View File

@ -0,0 +1,71 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/bg"
android:orientation="vertical"
tools:ignore="MissingPrefix"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/rect_white"
android:orientation="vertical"
>
<TextView
android:id="@+id/tvTitle"
fontPath="@string/font_medium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp"
android:layout_marginRight="16dp"
android:gravity="left"
android:text="This is an example of a title"
android:textColor="@color/text"
android:textSize="18sp"/>
<TextView
android:id="@+id/tvDescription"
fontPath="@string/font_regular"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginTop="8dp"
android:layout_marginRight="16dp"
android:gravity="left"
android:text="@string/lorem"
android:maxLines="6"
android:lineSpacingMultiplier="1.2"
android:textColor="@color/text_black_5"
android:textSize="14sp"/>
<TextView
android:id="@+id/tvCallToAction"
fontPath="@string/font_regular"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginRight="0dp"
android:layout_marginBottom="0dp"
android:gravity="left"
android:padding="16dp"
android:text="Call to Action"
android:textColor="#1c5c9a"
android:textSize="14sp"/>
</LinearLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/bg"
android:orientation="vertical"
tools:ignore="MissingPrefix">
</android.support.v4.widget.NestedScrollView>

View File

@ -0,0 +1,45 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:background="@drawable/rect_white"
android:elevation="2dp"
android:orientation="vertical"
tools:ignore="MissingPrefix">
<TextView
android:id="@+id/tvTitle"
fontPath="@string/font_medium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp"
android:layout_marginRight="16dp"
android:gravity="left"
android:textColor="@color/text"
android:textSize="18sp" />
<TextView
android:id="@+id/tvDescription"
fontPath="@string/font_regular"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginTop="8dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="16dp"
android:gravity="left"
android:maxLines="2"
android:lineSpacingMultiplier="1.2"
android:textColor="@color/text_black_5"
android:textSize="14sp" />
</LinearLayout>

View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/navigation_home"
android:icon="@drawable/ic_home"
android:title="Home" />
<item
android:id="@+id/navigation_deals"
android:icon="@drawable/ic_local_activity"
android:title="Categories" />
<item
android:id="@+id/navigation_account"
android:icon="@drawable/ic_profile"
android:title="Profile" />
</menu>

View File

@ -23,10 +23,13 @@
<string name="action_settings">Settings</string> <string name="action_settings">Settings</string>
<string-array name="sort"> <string-array name="sort">
<item>Popularity</item> <item>Popularity</item>
<item>Date added</item> <item>Date added</item>
<item>Price lowest first</item> <item>Price lowest first</item>
<item>Price highest first</item> <item>Price highest first</item>
</string-array> </string-array>
<string name="title_activity_category">CategoryActivity</string>
<string name="title_activity_home">HomeActivity</string>
<string name="lorem">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry\'s standard dummy text ever since the 1500s</string>
</resources> </resources>

View File

@ -0,0 +1,24 @@
package me.gilo.woodroid.data.cookie;
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;
import java.io.IOException;
public class DemoCookieInterceptor implements Interceptor {
@Override
public Response intercept(Interceptor.Chain chain) throws IOException {
Request.Builder builder = chain.request().newBuilder();
builder.addHeader("Cookie", "wordpress_logged_in_9073cf57240df660c1e240d327cc46cb=gilo%7C1551794958%7CJx1NTnn0f6wuYlN5a0PmTJxYcPlr1sUUqpr659EKCcG%7C802c643a30a82bf7aa6350b5fb5dd005c019b2e1b1d59566ef0c426e33126eae");
builder.addHeader("Cookie", "woocommerce_cart_hash=d9ec6c9bf0d307629c2a981362735284");
builder.addHeader("Cookie", "wp_woocommerce_session_9073cf57240df660c1e240d327cc46cb=1%7C%7C1551796439%7C%7C1551792839%7C%7Ce6deec897575a9a84bb4a672abf2ed72");
return chain.proceed(builder.build());
}
}

View File

@ -2,8 +2,7 @@ package me.gilo.woodroid.repo;
import android.content.Context; import android.content.Context;
import me.gilo.woodroid.data.api.CartAPI; import me.gilo.woodroid.data.api.CartAPI;
import me.gilo.woodroid.data.cookie.AddCookiesInterceptor; import me.gilo.woodroid.data.cookie.DemoCookieInterceptor;
import me.gilo.woodroid.data.cookie.ReceivedCookiesInterceptor;
import me.gilo.woodroid.models.LineItem; import me.gilo.woodroid.models.LineItem;
import me.gilo.woodroid.models.filters.CartFilter; import me.gilo.woodroid.models.filters.CartFilter;
import okhttp3.OkHttpClient; import okhttp3.OkHttpClient;
@ -50,8 +49,9 @@ public class CartRepository{
loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY); loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient client = new OkHttpClient.Builder() OkHttpClient client = new OkHttpClient.Builder()
.addInterceptor(new AddCookiesInterceptor(context)) // .addInterceptor(new AddCookiesInterceptor(context))
.addInterceptor(new ReceivedCookiesInterceptor(context)) // .addInterceptor(new ReceivedCookiesInterceptor(context))
.addInterceptor(new DemoCookieInterceptor())
.addInterceptor(loggingInterceptor) .addInterceptor(loggingInterceptor)
.readTimeout(30, TimeUnit.SECONDS) .readTimeout(30, TimeUnit.SECONDS)
.writeTimeout(30, TimeUnit.SECONDS) .writeTimeout(30, TimeUnit.SECONDS)