-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
636 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.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(); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
app/src/main/java/me/gilo/wc/adapter/viewholder/CouponViewHolder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
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.Coupon | ||
|
||
class CouponViewHolder(val context: Context, itemView: View) : | ||
RecyclerView.ViewHolder(itemView) { | ||
|
||
fun renderView(coupon: Coupon) { | ||
val tvTitle = itemView.findViewById<TextView>(R.id.tvTitle) | ||
val tvDescription = itemView.findViewById<TextView>(R.id.tvDescription) | ||
|
||
tvTitle.text = coupon.code.toUpperCase() | ||
tvDescription.text = Html.fromHtml(coupon.description) | ||
} | ||
|
||
|
||
} |
4 changes: 1 addition & 3 deletions
4
app/src/main/java/me/gilo/wc/adapter/viewholder/MenuViewHolder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 0 additions & 3 deletions
3
app/src/main/java/me/gilo/wc/adapter/viewholder/ProductViewHolder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,26 @@ | ||
package me.gilo.wc.ui | ||
|
||
import android.app.Activity | ||
import android.content.Context | ||
import android.os.Bundle | ||
import android.support.design.widget.Snackbar | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.support.v7.widget.LinearLayoutManager | ||
import android.support.v7.widget.RecyclerView | ||
import android.support.v7.app.AppCompatActivity | ||
import io.github.inflationx.viewpump.ViewPumpContextWrapper | ||
import me.gilo.wc.R | ||
|
||
import kotlinx.android.synthetic.main.activity_menu.* | ||
import kotlinx.android.synthetic.main.content_menu.* | ||
import me.gilo.wc.adapter.MenuAdapter | ||
import java.util.ArrayList | ||
import me.gilo.wc.ui.state.ProgressDialogFragment | ||
|
||
open class BaseActivity : AppCompatActivity() { | ||
|
||
private lateinit var progressDialog : ProgressDialogFragment | ||
|
||
override fun attachBaseContext(newBase: Context) { | ||
super.attachBaseContext(ViewPumpContextWrapper.wrap(newBase)) | ||
} | ||
|
||
fun showLoading(title: String, message: String) { | ||
val manager = supportFragmentManager | ||
progressDialog = ProgressDialogFragment.newInstance(title, message) | ||
progressDialog.isCancelable = false | ||
progressDialog.show(manager, "progress") | ||
} | ||
|
||
fun stopShowingLoading() { | ||
progressDialog.dismiss() | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
59 changes: 59 additions & 0 deletions
59
app/src/main/java/me/gilo/wc/ui/coupon/AddCouponActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package me.gilo.wc.ui.coupon | ||
|
||
import android.os.Bundle | ||
import kotlinx.android.synthetic.main.activity_add_coupon.* | ||
import kotlinx.android.synthetic.main.content_add_coupon.* | ||
import me.gilo.wc.R | ||
import me.gilo.wc.ui.BaseActivity | ||
import me.gilo.woodroid.Woocommerce | ||
import me.gilo.woodroid.models.Coupon | ||
import retrofit2.Call | ||
import retrofit2.Callback | ||
import retrofit2.Response | ||
|
||
class AddCouponActivity : BaseActivity() { | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_add_coupon) | ||
setSupportActionBar(toolbar) | ||
|
||
bCreate.setOnClickListener { submit() } | ||
|
||
} | ||
|
||
private fun submit() { | ||
val code = etCode.text.toString() | ||
val description = etDescription.text.toString() | ||
|
||
val coupon = Coupon() | ||
coupon.code = code | ||
coupon.description = description | ||
|
||
createCoupon(coupon) | ||
} | ||
|
||
private fun createCoupon(coupon: Coupon) { | ||
showLoading("Loading", "This won't take long") | ||
|
||
val woocommerce = Woocommerce.Builder() | ||
.setSiteUrl("http://157.230.131.179") | ||
.setApiVersion(Woocommerce.API_V2) | ||
.setConsumerKey("ck_26c61abd7eeff238d87dc56585bf26cb2d1a1ec3") | ||
.setConsumerSecret("cs_062e8e3a7ae0ce08fdebc0c39f8f834d5e87598e") | ||
.build() | ||
|
||
woocommerce.Coupon().create(coupon).enqueue(object : Callback<Coupon> { | ||
override fun onResponse(call: Call<Coupon>, response: Response<Coupon>) { | ||
val couponResponse = response.body() | ||
stopShowingLoading() | ||
finish() | ||
} | ||
|
||
override fun onFailure(call: Call<Coupon>, t: Throwable) { | ||
stopShowingLoading() | ||
} | ||
}) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package me.gilo.wc.ui.coupon | ||
|
||
import android.content.Intent | ||
import android.os.Bundle | ||
import android.support.v7.widget.LinearLayoutManager | ||
import kotlinx.android.synthetic.main.activity_coupon.* | ||
import kotlinx.android.synthetic.main.content_coupon.* | ||
import me.gilo.wc.R | ||
import me.gilo.wc.adapter.CouponAdapter | ||
import me.gilo.wc.ui.BaseActivity | ||
import me.gilo.woodroid.Woocommerce | ||
import me.gilo.woodroid.models.Coupon | ||
import retrofit2.Call | ||
import retrofit2.Callback | ||
import retrofit2.Response | ||
import java.util.* | ||
|
||
class CouponActivity : BaseActivity() { | ||
|
||
|
||
lateinit var adapter : CouponAdapter | ||
lateinit var coupons: ArrayList<Coupon> | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_coupon) | ||
setSupportActionBar(toolbar) | ||
|
||
title = "Coupon" | ||
|
||
val layoutManager = LinearLayoutManager(baseContext, LinearLayoutManager.VERTICAL, false) | ||
rvCoupons.layoutManager = layoutManager | ||
rvCoupons.isNestedScrollingEnabled = false | ||
|
||
coupons = ArrayList() | ||
|
||
adapter = CouponAdapter(coupons) | ||
rvCoupons.adapter = adapter | ||
|
||
coupons() | ||
|
||
fab.setOnClickListener{ | ||
startActivity(Intent(baseContext, AddCouponActivity::class.java)) | ||
} | ||
|
||
} | ||
|
||
//Not best practise, but works for purposes of demo | ||
private fun coupons() { | ||
val woocommerce = Woocommerce.Builder() | ||
.setSiteUrl("http://157.230.131.179") | ||
.setApiVersion(Woocommerce.API_V2) | ||
.setConsumerKey("ck_26c61abd7eeff238d87dc56585bf26cb2d1a1ec3") | ||
.setConsumerSecret("cs_062e8e3a7ae0ce08fdebc0c39f8f834d5e87598e") | ||
.build() | ||
|
||
woocommerce.Coupon().coupons().enqueue(object : Callback<List<Coupon>> { | ||
override fun onResponse(call: Call<List<Coupon>>, response: Response<List<Coupon>>) { | ||
val couponResponse = response.body() | ||
for (coupon in couponResponse!!) { | ||
coupons.add(coupon) | ||
} | ||
|
||
adapter.notifyDataSetChanged() | ||
} | ||
|
||
override fun onFailure(call: Call<List<Coupon>>, t: Throwable) { | ||
|
||
} | ||
}) | ||
} | ||
|
||
} |
53 changes: 53 additions & 0 deletions
53
app/src/main/java/me/gilo/wc/ui/state/ProgressDialogFragment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package me.gilo.wc.ui.state; | ||
|
||
import android.os.Bundle; | ||
import android.support.v4.app.DialogFragment; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.TextView; | ||
import me.gilo.wc.R; | ||
|
||
|
||
public class ProgressDialogFragment extends DialogFragment { | ||
|
||
private static final String ARG_TITLE= "title"; | ||
private static final String ARG_MESSAGE= "message"; | ||
|
||
String title = ""; | ||
String message = ""; | ||
|
||
public ProgressDialogFragment() { | ||
Bundle args = new Bundle(); | ||
args.putString(ARG_TITLE, title); | ||
args.putString(ARG_MESSAGE, message); | ||
setArguments(args); | ||
} | ||
|
||
public static ProgressDialogFragment newInstance(String title, String message) { | ||
ProgressDialogFragment fragment = new ProgressDialogFragment(); | ||
Bundle args = new Bundle(); | ||
args.putString(ARG_TITLE, title); | ||
args.putString(ARG_MESSAGE, message); | ||
fragment.setArguments(args); | ||
return fragment; | ||
} | ||
|
||
@Override | ||
public View onCreateView(LayoutInflater inflater, ViewGroup container, | ||
Bundle savedInstanceState) { | ||
View view = inflater.inflate(R.layout.loading_view, container); | ||
TextView tvTitle = view.findViewById(R.id.tvProgress_title); | ||
TextView tvMessage = view.findViewById(R.id.tvProgress_message); | ||
|
||
title = getArguments().getString(ARG_TITLE); | ||
message = getArguments().getString(ARG_MESSAGE); | ||
|
||
|
||
tvTitle.setText(title); | ||
tvMessage.setText(message); | ||
|
||
return view; | ||
} | ||
|
||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<android.support.design.widget.CoordinatorLayout | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
tools:context=".ui.coupon.AddCouponActivity"> | ||
|
||
<android.support.design.widget.AppBarLayout | ||
android:layout_height="wrap_content" | ||
android:layout_width="match_parent" | ||
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:popupTheme="@style/AppTheme.PopupOverlay"/> | ||
|
||
</android.support.design.widget.AppBarLayout> | ||
|
||
<include layout="@layout/content_add_coupon"/> | ||
|
||
</android.support.design.widget.CoordinatorLayout> |
Oops, something went wrong.