Skip to content

Commit

Permalink
Fix Bug API 21
Browse files Browse the repository at this point in the history
  • Loading branch information
Danboru committed Dec 7, 2017
1 parent e9678a4 commit 5250ebd
Show file tree
Hide file tree
Showing 14 changed files with 226 additions and 156 deletions.
34 changes: 15 additions & 19 deletions app/src/main/java/id/eightstudio/www/orderfoods/Cart.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import android.util.DisplayMetrics;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
Expand Down Expand Up @@ -53,7 +54,6 @@ public class Cart extends AppCompatActivity implements RecyclerViewClickListener
CartAdapter cartAdapter;
OpenHelper openHelper;
SQLiteDatabase sqliteDatabase;
SwipeRefreshLayout swipeRefreshLayout;

CardView viewDetailTotal;

Expand All @@ -63,6 +63,8 @@ protected void onCreate(Bundle savedInstanceState) {
//Set screen agar tidak memiliki toobar dan title
requestWindowFeature(Window.FEATURE_NO_TITLE);
//Set aplikasi ke dalam keadaan fullscreen
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
//Set aplikasi ke dalam keadaan fullscreen
setContentView(R.layout.activity_cart);

//Set statusRefresh
Expand All @@ -78,7 +80,6 @@ protected void onCreate(Bundle savedInstanceState) {
sqliteDatabase = openHelper.getReadableDatabase();

//Init View
swipeRefreshLayout = findViewById(R.id.refreshListCart);
recyclerView = findViewById(R.id.listCart);
recyclerView.setHasFixedSize(true);
layoutManager = new LinearLayoutManager(this);
Expand All @@ -99,8 +100,8 @@ public void onClick(View v) {
loadListFood();

//Hide view when scrolling
CoordinatorLayout.LayoutParams layoutParams = (CoordinatorLayout.LayoutParams) viewDetailTotal.getLayoutParams();
layoutParams.setBehavior(new ViewBehavior());
//CoordinatorLayout.LayoutParams layoutParams = (CoordinatorLayout.LayoutParams) viewDetailTotal.getLayoutParams();
//layoutParams.setBehavior(new ViewBehavior());

}

Expand Down Expand Up @@ -138,10 +139,6 @@ public void onClick(View v) {
if (TextUtils.isEmpty(inputAdress.getText().toString())) {
Toast.makeText(context, "Periksa Alamat Pengiriman", Toast.LENGTH_SHORT).show();
} else {
//Sudah di refresh listnya ?
if (Common.StatusRefresh == false) {
Toast.makeText(context, "Jangan Lupa Refresh Listnya", Toast.LENGTH_SHORT).show();
} else {
//Order >= 1 ?
if (openHelper.getOrderCount() <= 0) {
Toast.makeText(context, "Order Minima 1 item", Toast.LENGTH_SHORT).show();
Expand All @@ -160,7 +157,6 @@ public void onClick(View v) {
Toast.makeText(Cart.this, "Terimakasih", Toast.LENGTH_SHORT).show();
finish();
}
}
}
}
});
Expand Down Expand Up @@ -270,6 +266,15 @@ public void onClick(View v) {
dialog.show();
}

//TODO : Refresh RecyclerView
public void refreshList() {
cart = openHelper.getAllOrderFilter(Common.currentUser.getPhone());
cartAdapter = new CartAdapter(cart, this, this);
recyclerView.setAdapter(cartAdapter);

hitungTotalHarga();
}

//TODO : Menghitung total harga pembelian
private void hitungTotalHarga() {
//Calculate total
Expand All @@ -278,21 +283,12 @@ private void hitungTotalHarga() {
total += (Integer.parseInt(order.getPrice())) * (Integer.parseInt(order.getQuantity()));
}

Locale locale = new Locale("en", "US");
Locale locale = new Locale("in", "ID");
NumberFormat numberFormat = NumberFormat.getCurrencyInstance(locale);

txtTotalPrice.setText(numberFormat.format(total));
//txtTotalPrice.setText("$ " + String.valueOf(total) );

}

//TODO :
public void refreshList() {
cart = openHelper.getAllOrderFilter(Common.currentUser.getPhone());
cartAdapter = new CartAdapter(cart, this, this);
recyclerView.setAdapter(cartAdapter);

hitungTotalHarga();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
Expand Down Expand Up @@ -40,6 +41,8 @@ public class FoodDetail extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Set aplikasi ke dalam keadaan fullscreen
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_food_detail);

//Firebase
Expand All @@ -61,7 +64,7 @@ public void onClick(View v) {

//TODO : Periksa item sudah di keranjang ?
if (openHelper.hasObject(currentFood.getName()) == true) {
Toast.makeText(FoodDetail.this, "Sudah di keranjang", Toast.LENGTH_SHORT).show();
Toast.makeText(FoodDetail.this, "Sudah di Keranjang", Toast.LENGTH_SHORT).show();
} else {

openHelper.addOrder(new Order(foodId,
Expand All @@ -72,7 +75,7 @@ public void onClick(View v) {
Common.currentUser.getPhone()
));

Toast.makeText(FoodDetail.this, "Added to Cart", Toast.LENGTH_SHORT).show();
Toast.makeText(FoodDetail.this, "Berhasil", Toast.LENGTH_SHORT).show();
}
}
});
Expand Down Expand Up @@ -104,7 +107,7 @@ public void onDataChange(DataSnapshot dataSnapshot) {
}

//CurrentFood.getName()
food_price.setText("$ " + currentFood.getPrice());
food_price.setText("Rp " + currentFood.getPrice());
food_name.setText(currentFood.getName());
food_description.setText(currentFood.getDescrption());
}
Expand Down
8 changes: 5 additions & 3 deletions app/src/main/java/id/eightstudio/www/orderfoods/FoodList.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import android.util.Log;
import android.util.TypedValue;
import android.view.View;
import android.view.WindowManager;

import com.firebase.ui.database.FirebaseRecyclerAdapter;
import com.google.firebase.database.DataSnapshot;
Expand Down Expand Up @@ -53,7 +54,7 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

//Set aplikasi ke dalam keadaan fullscreen
//getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

setContentView(R.layout.activity_food_list);
ButterKnife.bind(this);
Expand Down Expand Up @@ -184,6 +185,7 @@ public void loadListFood(String categoryId) {
protected void populateViewHolder(FoodViewHolder viewHolder, Food model, int position) {

viewHolder.food_name.setText(model.getName());
viewHolder.food_price.setText("Rp " + model.getPrice());
Picasso.with(FoodList.this).load(model.getImage()).into(viewHolder.food_image);

final Food local = model;
Expand All @@ -202,11 +204,11 @@ public void onClick(View view, int position, boolean isLonggerPress) {


//Costum grid recycler
recyclerView.addItemDecoration(new GridSpacingItemDecoration(2, dpToPx(2), true));
recyclerView.addItemDecoration(new GridSpacingItemDecoration(2, dpToPx(0), true));
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.setLayoutManager(new GridLayoutManager(this, 2));

// recyclerView.setLayoutManager(layoutManager);
//recyclerView.setLayoutManager(layoutManager);
recyclerView.setAdapter(adapter);

}
Expand Down
11 changes: 8 additions & 3 deletions app/src/main/java/id/eightstudio/www/orderfoods/Home.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.TextView;

Expand Down Expand Up @@ -58,6 +59,7 @@ public class Home extends AppCompatActivity
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Set aplikasi ke dalam keadaan fullscreen
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_home);

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
Expand All @@ -75,9 +77,12 @@ protected void onCreate(Bundle savedInstanceState) {
menuCart = menu.findItem(R.id.nav_cart);
menuOrder = menu.findItem(R.id.nav_orders);

//Set counter Defaulth
setMenuCounter(menuCart.getItemId() , openHelper.getOrderCountFilter(Common.currentUser.getPhone()));
setMenuCounter(menuOrder.getItemId() , 0);

if (openHelper.isTableExists("OrderDetail", true)) {
//Set counter Defaulth
setMenuCounter(menuCart.getItemId(), openHelper.getOrderCountFilter(Common.currentUser.getPhone()));
setMenuCounter(menuOrder.getItemId(), 0);
}

//Floating Action Bar
//Library link https://github.com/andremion/CounterFab
Expand Down
12 changes: 7 additions & 5 deletions app/src/main/java/id/eightstudio/www/orderfoods/OrderStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import android.support.v7.widget.RecyclerView;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.WindowManager;
import android.widget.LinearLayout;

import com.firebase.ui.database.FirebaseRecyclerAdapter;
Expand All @@ -36,7 +37,7 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

//Set aplikasi ke dalam keadaan fullscreen
//getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_order_status);

//Init Firebase
Expand Down Expand Up @@ -71,14 +72,15 @@ protected void populateViewHolder(OrderViewHolder viewHolder, Request model, int
viewHolder.txtOrderId.setText(adapter.getRef(position).getKey());

//Set status berdasarkan id
//Taken from https://stackoverflow.com/questions/30464234/android-lollipop-set-status-bar-text-color
if (status.equals("0")){
viewHolder.txtOrderStatus.setTextColor(getColor(R.color.colorMenunggu));
viewHolder.txtOrderStatus.setTextColor(getResources().getColor(R.color.colorMenunggu));
} else if (status.equals("1")){
viewHolder.txtOrderStatus.setTextColor(getColor(R.color.colorDiProses));
viewHolder.txtOrderStatus.setTextColor(getResources().getColor(R.color.colorDiProses));
} else if (status.equals("2")){
viewHolder.txtOrderStatus.setTextColor(getColor(R.color.colorPengiriman));
viewHolder.txtOrderStatus.setTextColor(getResources().getColor(R.color.colorPengiriman));
} else {
viewHolder.txtOrderStatus.setTextColor(getColor(R.color.colorDiTerima));
viewHolder.txtOrderStatus.setTextColor(getResources().getColor(R.color.colorDiTerima));
}

viewHolder.txtOrderStatus.setText(convertCodeStatus(model.getStatus()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void onBindViewHolder(CartViewHolder holder, final int position) {
.buildRound("" + listOrder.get(position).getQuantity(), Color.RED);
holder.img_cart_count.setImageDrawable(drawable);

Locale locale = new Locale("en", "US");
Locale locale = new Locale("id", "ID");

NumberFormat fmt = NumberFormat.getCurrencyInstance(locale);
int price = (Integer.parseInt(listOrder.get(position).getPrice())) * (Integer.parseInt(listOrder.get(position).getQuantity()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@
public class FoodViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {

public ImageView food_image;
public TextView food_name;
public TextView food_name, food_price;
OnClickListener onClickListener;

public FoodViewHolder(View itemView) {
super(itemView);

food_image = itemView.findViewById(R.id.food_image);
food_name = itemView.findViewById(R.id.food_name);
food_price = itemView.findViewById(R.id.food_price);

itemView.setOnClickListener(this);

Expand Down
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/ic_account_circle_black.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM12,5c1.66,0 3,1.34 3,3s-1.34,3 -3,3 -3,-1.34 -3,-3 1.34,-3 3,-3zM12,19.2c-2.5,0 -4.71,-1.28 -6,-3.22 0.03,-1.99 4,-3.08 6,-3.08 1.99,0 5.97,1.09 6,3.08 -1.29,1.94 -3.5,3.22 -6,3.22z"/>
</vector>
45 changes: 19 additions & 26 deletions app/src/main/res/layout/activity_cart.xml
Original file line number Diff line number Diff line change
@@ -1,32 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
<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"
android:background="@color/colorBackgroundMain"
tools:context="id.eightstudio.www.orderfoods.Cart">

<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/refreshListCart"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.v7.widget.RecyclerView
android:id="@+id/listCart"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

</android.support.v4.widget.SwipeRefreshLayout>

<android.support.v7.widget.CardView
android:id="@+id/viewDetailHarga"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_alignParentBottom="true"
android:layout_gravity="bottom"
app:cardBackgroundColor="@color/colorPrimary"
android:layout_height="100dp">

app:cardBackgroundColor="@color/colorPrimary">

<RelativeLayout
android:layout_width="match_parent"
Expand All @@ -35,27 +23,28 @@
>

<LinearLayout
android:gravity="center_vertical"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center"
>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Total : "
android:text="TOTAL : "
android:textColor="@android:color/white"
android:textSize="20sp"
/>
android:textStyle="bold"
android:textSize="20sp"/>

<TextView
android:id="@+id/total"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="$ 0"
android:text="0"
android:textColor="@android:color/white"
android:textSize="24sp"
android:textStyle="bold"
/>

</LinearLayout>
Expand All @@ -64,12 +53,16 @@
android:id="@+id/btnPlaceOrder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Place Order"
android:layout_alignParentBottom="true"
/>
android:text="Place Order" />

</RelativeLayout>

</android.support.v7.widget.CardView>

</android.support.design.widget.CoordinatorLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/listCart"
android:layout_width="match_parent"
android:layout_height="match_parent" />

</LinearLayout>
Loading

0 comments on commit 5250ebd

Please sign in to comment.