feat: initial functional release of Stock Pignon
@@ -0,0 +1,26 @@
|
||||
package com.stock.pignon;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.test.platform.app.InstrumentationRegistry;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Instrumented test, which will execute on an Android device.
|
||||
*
|
||||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
|
||||
*/
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class ExampleInstrumentedTest {
|
||||
@Test
|
||||
public void useAppContext() {
|
||||
// Context of the app under test.
|
||||
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
|
||||
assertEquals("com.stock.pignon", appContext.getPackageName());
|
||||
}
|
||||
}
|
||||
23
app/src/main/AndroidManifest.xml
Normal file
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.stock.pignon">
|
||||
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/Theme.Pignon">
|
||||
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
</manifest>
|
||||
BIN
app/src/main/assets/images/FD.jpg
Normal file
|
After Width: | Height: | Size: 8.7 KiB |
BIN
app/src/main/assets/images/RD.jpg
Normal file
|
After Width: | Height: | Size: 11 KiB |
BIN
app/src/main/assets/images/_velo.jpg
Normal file
|
After Width: | Height: | Size: 81 KiB |
BIN
app/src/main/assets/images/axeRapide.jpg
Normal file
|
After Width: | Height: | Size: 6.4 KiB |
BIN
app/src/main/assets/images/axeRoue.jpg
Normal file
|
After Width: | Height: | Size: 5.5 KiB |
BIN
app/src/main/assets/images/bequille.jpg
Normal file
|
After Width: | Height: | Size: 3.7 KiB |
BIN
app/src/main/assets/images/boitierPedalier.jpg
Normal file
|
After Width: | Height: | Size: 9.7 KiB |
BIN
app/src/main/assets/images/cable.jpg
Normal file
|
After Width: | Height: | Size: 6.6 KiB |
BIN
app/src/main/assets/images/cadre.jpg
Normal file
|
After Width: | Height: | Size: 8.2 KiB |
BIN
app/src/main/assets/images/cassette.jpg
Normal file
|
After Width: | Height: | Size: 15 KiB |
BIN
app/src/main/assets/images/chaine.jpg
Normal file
|
After Width: | Height: | Size: 17 KiB |
BIN
app/src/main/assets/images/cintre.jpg
Normal file
|
After Width: | Height: | Size: 4.9 KiB |
BIN
app/src/main/assets/images/collierSelle.jpg
Normal file
|
After Width: | Height: | Size: 11 KiB |
BIN
app/src/main/assets/images/disque.jpg
Normal file
|
After Width: | Height: | Size: 14 KiB |
BIN
app/src/main/assets/images/etrierDisque.jpg
Normal file
|
After Width: | Height: | Size: 13 KiB |
BIN
app/src/main/assets/images/etrierPatin.jpg
Normal file
|
After Width: | Height: | Size: 8.0 KiB |
BIN
app/src/main/assets/images/fourche.jpg
Normal file
|
After Width: | Height: | Size: 5.7 KiB |
BIN
app/src/main/assets/images/gaine.jpg
Normal file
|
After Width: | Height: | Size: 8.7 KiB |
BIN
app/src/main/assets/images/gardeBoue.jpg
Normal file
|
After Width: | Height: | Size: 5.8 KiB |
BIN
app/src/main/assets/images/jeuDirection.jpg
Normal file
|
After Width: | Height: | Size: 10 KiB |
BIN
app/src/main/assets/images/lampe.jpg
Normal file
|
After Width: | Height: | Size: 7.9 KiB |
BIN
app/src/main/assets/images/manivelleDroite.jpg
Normal file
|
After Width: | Height: | Size: 11 KiB |
BIN
app/src/main/assets/images/manivelleGauche.jpg
Normal file
|
After Width: | Height: | Size: 7.0 KiB |
BIN
app/src/main/assets/images/merci.gif
Normal file
|
After Width: | Height: | Size: 477 KiB |
BIN
app/src/main/assets/images/moyeuArriere.jpg
Normal file
|
After Width: | Height: | Size: 9.5 KiB |
BIN
app/src/main/assets/images/moyeuAvant.jpg
Normal file
|
After Width: | Height: | Size: 5.8 KiB |
BIN
app/src/main/assets/images/patins.jpg
Normal file
|
After Width: | Height: | Size: 12 KiB |
BIN
app/src/main/assets/images/pedales.jpg
Normal file
|
After Width: | Height: | Size: 11 KiB |
BIN
app/src/main/assets/images/pedalierComplet.jpg
Normal file
|
After Width: | Height: | Size: 14 KiB |
BIN
app/src/main/assets/images/plateau.jpg
Normal file
|
After Width: | Height: | Size: 19 KiB |
BIN
app/src/main/assets/images/pneu.jpg
Normal file
|
After Width: | Height: | Size: 9.0 KiB |
BIN
app/src/main/assets/images/poigneeCombo.jpg
Normal file
|
After Width: | Height: | Size: 11 KiB |
BIN
app/src/main/assets/images/poigneeGachette.jpg
Normal file
|
After Width: | Height: | Size: 7.0 KiB |
BIN
app/src/main/assets/images/poigneeTournante.jpg
Normal file
|
After Width: | Height: | Size: 7.9 KiB |
BIN
app/src/main/assets/images/poigneefrein.jpg
Normal file
|
After Width: | Height: | Size: 26 KiB |
BIN
app/src/main/assets/images/poignees.jpg
Normal file
|
After Width: | Height: | Size: 16 KiB |
BIN
app/src/main/assets/images/porteBagage.jpg
Normal file
|
After Width: | Height: | Size: 11 KiB |
BIN
app/src/main/assets/images/portebidon.jpg
Normal file
|
After Width: | Height: | Size: 16 KiB |
BIN
app/src/main/assets/images/potenceHeadset.jpg
Normal file
|
After Width: | Height: | Size: 8.6 KiB |
BIN
app/src/main/assets/images/potencePlongeur.jpg
Normal file
|
After Width: | Height: | Size: 5.9 KiB |
BIN
app/src/main/assets/images/rayon.jpg
Normal file
|
After Width: | Height: | Size: 4.0 KiB |
BIN
app/src/main/assets/images/roueLibre.jpg
Normal file
|
After Width: | Height: | Size: 24 KiB |
BIN
app/src/main/assets/images/rouearriere.jpg
Normal file
|
After Width: | Height: | Size: 15 KiB |
BIN
app/src/main/assets/images/roueavant.jpg
Normal file
|
After Width: | Height: | Size: 14 KiB |
BIN
app/src/main/assets/images/selle.jpg
Normal file
|
After Width: | Height: | Size: 8.3 KiB |
BIN
app/src/main/assets/images/tigePlongeur.jpg
Normal file
|
After Width: | Height: | Size: 5.0 KiB |
BIN
app/src/main/assets/images/tigeSelle.jpg
Normal file
|
After Width: | Height: | Size: 6.6 KiB |
BIN
app/src/main/assets/images/visserie.jpg
Normal file
|
After Width: | Height: | Size: 10 KiB |
BIN
app/src/main/assets/images/visseriefrein.jpg
Normal file
|
After Width: | Height: | Size: 13 KiB |
BIN
app/src/main/assets/images/visseriepedalier.jpg
Normal file
|
After Width: | Height: | Size: 11 KiB |
BIN
app/src/main/assets/images/visserieroue.jpg
Normal file
|
After Width: | Height: | Size: 18 KiB |
BIN
app/src/main/assets/images/visserietransmission.jpg
Normal file
|
After Width: | Height: | Size: 7.4 KiB |
112
app/src/main/assets/pieces.json
Normal file
@@ -0,0 +1,112 @@
|
||||
{
|
||||
"globalItems": [
|
||||
{"name": "Visserie classique", "minPrice": 0, "maxPrice": 1, "image": "visserie"}
|
||||
],
|
||||
"categories": [
|
||||
{
|
||||
"name": "Structure",
|
||||
"bgColor": "#FF0000",
|
||||
"textColor": "#000000",
|
||||
"items": [
|
||||
{"name": "Cadre", "minPrice": 20, "maxPrice": 40, "image": "cadre"},
|
||||
{"name": "Selle", "minPrice": 1, "maxPrice": 7, "image": "selle"},
|
||||
{"name": "Tige de selle", "minPrice": 1, "maxPrice": 10, "image": "tigeselle"},
|
||||
{"name": "Collier de selle", "minPrice": 1, "maxPrice": 4, "image": "collierselle"}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Direction",
|
||||
"bgColor": "#CC00FF",
|
||||
"textColor": "#000000",
|
||||
"items": [
|
||||
{"name": "Fourche", "minPrice": 10, "maxPrice": 20, "image": "fourche"},
|
||||
{"name": "Jeu de direction", "minPrice": 1, "maxPrice": 8, "image": "jeudirection"},
|
||||
{"name": "Potence headset", "minPrice": 2, "maxPrice": 8, "image": "potenceheadset"},
|
||||
{"name": "Potence plongeur", "minPrice": 2, "maxPrice": 8, "image": "potenceplongeur"},
|
||||
{"name": "Tige plongeur", "minPrice": 1, "maxPrice": 4, "image": "tigeplongeur"}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Guidon",
|
||||
"bgColor": "#F16000",
|
||||
"textColor": "#000000",
|
||||
"items": [
|
||||
{"name": "Poignée combo", "minPrice": 2, "maxPrice": 8, "image": "poigneecombo"},
|
||||
{"name": "Poignée frein", "minPrice": 2, "maxPrice": 8, "image": "poigneefrein"},
|
||||
{"name": "Poignée gachette", "minPrice": 2, "maxPrice": 8, "image": "poigneegachette"},
|
||||
{"name": "Poignée tournante", "minPrice": 2, "maxPrice": 6, "image": "poigneetournante"},
|
||||
{"name": "Gaine", "minPrice": 0, "maxPrice": 2, "image": "gaine"},
|
||||
{"name": "Câble", "minPrice": 0, "maxPrice": 1, "image": "cable"},
|
||||
{"name": "Poignée", "minPrice": 1, "maxPrice": 4, "image": "poignees"},
|
||||
{"name": "Cintre", "minPrice": 5, "maxPrice": 10,"image": "cintre"}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Freins",
|
||||
"bgColor": "#FF00FF",
|
||||
"textColor": "#000000",
|
||||
"items": [
|
||||
{"name": "Étrier patin", "minPrice": 2, "maxPrice": 8, "image": "etrierpatin"},
|
||||
{"name": "Étrier disque", "minPrice": 2, "maxPrice": 8, "image": "etrierdisque"},
|
||||
{"name": "Patins", "minPrice": 1, "maxPrice": 2, "image": "patins"},
|
||||
{"name": "Disque", "minPrice": 1, "maxPrice": 5, "image": "disque"},
|
||||
{"name": "Visserie frein", "minPrice": 0, "maxPrice": 1, "image": "visseriefrein"}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Roue",
|
||||
"bgColor": "#0000FF",
|
||||
"textColor": "#FFFFFF",
|
||||
"items": [
|
||||
{"name": "Roue avant", "minPrice": 20, "maxPrice": 40, "image": "roueavant"},
|
||||
{"name": "Roue arrière", "minPrice": 20, "maxPrice": 40, "image": "rouearriere"},
|
||||
{"name": "Axe rapide", "minPrice": 1, "maxPrice": 2, "image": "axerapide"},
|
||||
{"name": "Axe roue", "minPrice": 1, "maxPrice": 3, "image": "axeroue"},
|
||||
{"name": "Rayon", "minPrice": 0, "maxPrice": 2, "image": "rayon"},
|
||||
{"name": "Moyeu avant", "minPrice": 2, "maxPrice": 8, "image": "moyeuavant"},
|
||||
{"name": "Moyeu arrière", "minPrice": 2, "maxPrice": 10, "image": "moyeuarriere"},
|
||||
{"name": "Pneu", "minPrice": 10, "maxPrice": 20, "image": "pneu"},
|
||||
{"name": "Visserie roue", "minPrice": 0, "maxPrice": 1, "image": "visserieroue"}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Transmission",
|
||||
"bgColor": "#FFCC00",
|
||||
"textColor": "#000000",
|
||||
"items": [
|
||||
{"name": "Dérailleur avant", "minPrice": 2, "maxPrice": 10, "image": "fd"},
|
||||
{"name": "Dérailleur arrière", "minPrice": 4, "maxPrice": 12, "image": "rd"},
|
||||
{"name": "Cassette", "minPrice": 2, "maxPrice": 6, "image": "cassette"},
|
||||
{"name": "Roue libre", "minPrice": 2, "maxPrice": 6, "image": "rouelibre"},
|
||||
{"name": "Chaîne", "minPrice": 2, "maxPrice": 6, "image": "chaine"},
|
||||
{"name": "Visserie transmission", "minPrice": 0, "maxPrice": 1, "image": "visserietransmission"}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Pédalier",
|
||||
"bgColor": "#00FFFF",
|
||||
"textColor": "#000000",
|
||||
"items": [
|
||||
{"name": "Boîtier pédalier", "minPrice": 4, "maxPrice": 12, "image": "boitierpedalier"},
|
||||
{"name": "Manivelle gauche", "minPrice": 4, "maxPrice": 12, "image": "manivellegauche"},
|
||||
{"name": "Manivelle droite", "minPrice": 4, "maxPrice": 12, "image": "manivelledroite"},
|
||||
{"name": "Pédalier complet", "minPrice": 6, "maxPrice": 15, "image": "pedaliercomplet"},
|
||||
{"name": "Pédales", "minPrice": 2, "maxPrice": 8, "image": "pedales"},
|
||||
{"name": "Plateau", "minPrice": 2, "maxPrice": 8, "image": "plateau"},
|
||||
{"name": "Visserie pédalier", "minPrice": 0, "maxPrice": 1, "image": "visseriepedalier"}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Accessoires",
|
||||
"bgColor": "#00FF00",
|
||||
"textColor": "#000000",
|
||||
"items": [
|
||||
{"name": "Béquille", "minPrice": 2, "maxPrice": 8, "image": "bequille"},
|
||||
{"name": "Garde boue", "minPrice": 2, "maxPrice": 8, "image": "gardeboue"},
|
||||
{"name": "Lampe", "minPrice": 1, "maxPrice": 5, "image": "lampe"},
|
||||
{"name": "Porte bagage", "minPrice": 2, "maxPrice": 10, "image": "portebagage"},
|
||||
{"name": "Porte bidon", "minPrice": 0, "maxPrice": 1, "image": "portebidon"}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
BIN
app/src/main/ic_launcher-playstore.png
Normal file
|
After Width: | Height: | Size: 115 KiB |
207
app/src/main/java/com/stock/pignon/CartActionHelper.java
Normal file
@@ -0,0 +1,207 @@
|
||||
// CartActionHelper.java
|
||||
package com.stock.pignon;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Handler;
|
||||
import android.os.Environment;
|
||||
import android.text.Html;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.GridLayout;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
|
||||
/**
|
||||
* Action on shopping cart: validation, clearing, and persistence
|
||||
*/
|
||||
public class CartActionHelper {
|
||||
|
||||
private static final String TAG = "CartActionHelper";
|
||||
|
||||
/**
|
||||
* Resets the cart data and refreshes UI
|
||||
*/
|
||||
public static void emptyCart(LinearLayout cartList, Context activity) {
|
||||
CartManager.clear();
|
||||
CartViewHelper.updateCartView(cartList, activity);
|
||||
|
||||
if (activity instanceof MainActivity) {
|
||||
GridLayout grid = ((MainActivity) activity).findViewById(R.id.gridPieces);
|
||||
refreshGridQuantities(grid);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles checkout process: shows summary, saves to disk on confirmation
|
||||
* and redirects the user after a success message
|
||||
*/
|
||||
public static void validateCart(LinearLayout cartList, Context activity) {
|
||||
List<CartItem> items = CartManager.getItems();
|
||||
if (items.isEmpty()) return;
|
||||
|
||||
// Build a readable HTML summary for the confirmation dialog
|
||||
StringBuilder recap = new StringBuilder();
|
||||
|
||||
// Show a line for each item
|
||||
for (CartItem item : items) {
|
||||
recap.append(activity.getString(R.string.popup_item,
|
||||
item.getQuantity(),
|
||||
item.getName(),
|
||||
item.getTotalMin(),
|
||||
item.getTotalMax()));
|
||||
}
|
||||
|
||||
// Show total price range
|
||||
recap.append(activity.getString(R.string.popup_total,
|
||||
CartManager.getGlobalTotalMin(),
|
||||
CartManager.getGlobalTotalMax()));
|
||||
|
||||
// Build dialog with HTML summary and buttons
|
||||
new AlertDialog.Builder(activity)
|
||||
.setTitle(activity.getString(R.string.popup_name))
|
||||
.setMessage(Html.fromHtml(recap.toString()))
|
||||
.setPositiveButton("Oui", (dialog, which) -> {
|
||||
// Save to storage
|
||||
saveCartToExternalFile(items);
|
||||
|
||||
// Clear current session
|
||||
CartManager.clear();
|
||||
CartViewHelper.updateCartView(cartList, activity);
|
||||
|
||||
// Show success message and close
|
||||
showSuccessAndRedirect(activity);
|
||||
})
|
||||
.setNegativeButton("Non", null)
|
||||
.show();
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a thank you popup and returns to the main menu after 2 seconds.
|
||||
*/
|
||||
private static void showSuccessAndRedirect(Context activity) {
|
||||
AlertDialog merciDialog = new AlertDialog.Builder(activity)
|
||||
.setMessage(activity.getString(R.string.popup_end))
|
||||
// Info popup, not cancelable
|
||||
.setCancelable(false)
|
||||
.create();
|
||||
merciDialog.show();
|
||||
|
||||
|
||||
new Handler().postDelayed(() -> {
|
||||
// Close dialog
|
||||
merciDialog.dismiss();
|
||||
// Go to home if not already
|
||||
if (!(activity instanceof MainActivity)) {
|
||||
Intent intent = new Intent(activity, MainActivity.class);
|
||||
// Clear the backstack so the user can't "go back" to a validated cart
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
||||
activity.startActivity(intent);
|
||||
}
|
||||
}, 2000);
|
||||
}
|
||||
|
||||
/**
|
||||
* Merges current cart items with the existing stock file on the SD Card.
|
||||
*/
|
||||
private static void saveCartToExternalFile(List<CartItem> cartItems) {
|
||||
File stockFile = new File(Environment.getExternalStorageDirectory(), Config.STOCK_FILE_NAME);
|
||||
Gson gson = new Gson();
|
||||
Map<String, Integer> stockMap;
|
||||
|
||||
// Load data into a Map (Key: Item Name, Value: Total Quantity)
|
||||
stockMap = loadExistingStock(stockFile, gson);
|
||||
|
||||
// Merge with new items from current cart
|
||||
for (CartItem item : cartItems) {
|
||||
// Get previous quantity
|
||||
Integer qtyObj = stockMap.get(item.getName());
|
||||
int currentQty = (qtyObj != null) ? qtyObj : 0;
|
||||
// Add
|
||||
stockMap.put(item.getName(), currentQty + item.getQuantity());
|
||||
}
|
||||
|
||||
// Overwrite the file with updated data
|
||||
// Needs WRITE_EXTERNAL_STORAGE permission
|
||||
try (FileOutputStream fos = new FileOutputStream(stockFile);
|
||||
@SuppressWarnings("CharsetObjectCanBeUsed")
|
||||
OutputStreamWriter writer = new OutputStreamWriter(fos, "UTF-8")) {
|
||||
|
||||
// Writing directly to the stream
|
||||
gson.toJson(stockMap, writer);
|
||||
Log.i(TAG, "Stock updated successfully at: " + stockFile.getAbsolutePath());
|
||||
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "Failed to write stock file", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the current stock file. If the file is missing or corrupted, returns an empty map.
|
||||
*/
|
||||
private static Map<String, Integer> loadExistingStock(File stockFile, Gson gson) {
|
||||
if (!stockFile.exists()) return new HashMap<>();
|
||||
|
||||
try (FileInputStream fis = new FileInputStream(stockFile);
|
||||
@SuppressWarnings("CharsetObjectCanBeUsed")
|
||||
InputStreamReader reader = new InputStreamReader(fis, "UTF-8")) {
|
||||
|
||||
// Type definition for Map required by GSON : <String, Integer>
|
||||
Type type = new TypeToken<Map<String, Integer>>(){}.getType();
|
||||
// Read and fill map
|
||||
Map<String, Integer> result = gson.fromJson(reader, type);
|
||||
|
||||
return (result != null) ? result : new HashMap<>();
|
||||
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "Error reading existing stock, starting fresh", e);
|
||||
return new HashMap<>();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the UI grid to reflect quantities.
|
||||
*/
|
||||
public static void refreshGridQuantities(GridLayout grid) {
|
||||
if (grid == null) return;
|
||||
|
||||
// Iterate through all child views in the grid
|
||||
for (int i = 0; i < grid.getChildCount(); i++) {
|
||||
View itemView = grid.getChildAt(i);
|
||||
|
||||
// Locate the name and quantity views inside the current item layout
|
||||
TextView nameView = itemView.findViewById(R.id.itemName);
|
||||
TextView qtyView = itemView.findViewById(R.id.qtyView);
|
||||
|
||||
|
||||
if (nameView != null && qtyView != null) {
|
||||
// Match names
|
||||
String itemName = nameView.getText().toString();
|
||||
|
||||
// Fetch current quantity from centralized CartManager
|
||||
CartItem cartItem = CartManager.getItemByName(itemName);
|
||||
int quantity = (cartItem != null) ? cartItem.getQuantity() : 0;
|
||||
|
||||
// Update the visual counter
|
||||
qtyView.setText(String.valueOf(quantity));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
27
app/src/main/java/com/stock/pignon/CartItem.java
Normal file
@@ -0,0 +1,27 @@
|
||||
// CartItem.java
|
||||
package com.stock.pignon;
|
||||
|
||||
public class CartItem {
|
||||
private final String name;
|
||||
private final int minPrice;
|
||||
private final int maxPrice;
|
||||
private int quantity;
|
||||
private final String imageFile; // Image name without extension
|
||||
|
||||
public CartItem(String name, int minPrice, int maxPrice, int quantity, String imageFile) {
|
||||
this.name = name;
|
||||
this.minPrice = minPrice;
|
||||
this.maxPrice = maxPrice;
|
||||
this.quantity = quantity;
|
||||
this.imageFile = imageFile;
|
||||
}
|
||||
|
||||
public String getName() { return name; }
|
||||
public int getMinPrice() { return minPrice; }
|
||||
public int getMaxPrice() { return maxPrice; }
|
||||
public int getQuantity() { return quantity; }
|
||||
public void setQuantity(int quantity) { this.quantity = quantity; }
|
||||
public int getTotalMin() { return minPrice * quantity; }
|
||||
public int getTotalMax() { return maxPrice * quantity; }
|
||||
public String getImageFile() { return imageFile; }
|
||||
}
|
||||
60
app/src/main/java/com/stock/pignon/CartManager.java
Normal file
@@ -0,0 +1,60 @@
|
||||
// CartManager.java
|
||||
package com.stock.pignon;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CartManager {
|
||||
// Unified and global list for whole application
|
||||
private static final List<CartItem> items = new ArrayList<>();
|
||||
|
||||
// Private constructor: utility class, it should not be instantiated
|
||||
private CartManager() {}
|
||||
|
||||
// Returns the direct reference to the list to save memory on older devices
|
||||
public static List<CartItem> getItems() {
|
||||
return items;
|
||||
}
|
||||
|
||||
public static CartItem getItemByName(String name) {
|
||||
if (name == null) return null;
|
||||
for (CartItem item : items) {
|
||||
// if item.getName() is null, avoid crash
|
||||
if (item != null && name.equals(item.getName())) return item;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// Logic for adding, updating or removing items based on quantity, prevents duplicate entries
|
||||
public static void addOrUpdateItem(String name, int minPrice, int maxPrice, int quantity, String imageFile) {
|
||||
CartItem current = getItemByName(name);
|
||||
|
||||
if (current != null) {
|
||||
if (quantity <= 0) {
|
||||
items.remove(current);
|
||||
} else {
|
||||
current.setQuantity(quantity);
|
||||
}
|
||||
} else if (quantity > 0) {
|
||||
items.add(new CartItem(name, minPrice, maxPrice, quantity, imageFile));
|
||||
}
|
||||
}
|
||||
|
||||
// Range-based pricing
|
||||
|
||||
public static int getGlobalTotalMin() {
|
||||
int total = 0;
|
||||
for (CartItem item : items) total += item.getTotalMin();
|
||||
return total;
|
||||
}
|
||||
|
||||
public static int getGlobalTotalMax() {
|
||||
int total = 0;
|
||||
for (CartItem item : items) total += item.getTotalMax();
|
||||
return total;
|
||||
}
|
||||
|
||||
public static void clear() {
|
||||
items.clear();
|
||||
}
|
||||
}
|
||||
165
app/src/main/java/com/stock/pignon/CartViewHelper.java
Normal file
@@ -0,0 +1,165 @@
|
||||
// CartViewHelper.java
|
||||
package com.stock.pignon;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Typeface;
|
||||
import android.graphics.drawable.GradientDrawable;
|
||||
import android.util.TypedValue;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* UI Helper to dynamically build and update cart's list
|
||||
*/
|
||||
public class CartViewHelper {
|
||||
|
||||
/**
|
||||
* Refreshes the entire cart side-panel or list
|
||||
* Clears everything and rebuild on current CartManager data
|
||||
*/
|
||||
public static void updateCartView(LinearLayout cartList, Context context) {
|
||||
if (cartList == null) return;
|
||||
|
||||
// Clear and get current items
|
||||
cartList.removeAllViews();
|
||||
List<CartItem> cartItems = CartManager.getItems();
|
||||
|
||||
// If empty cart, show it to user
|
||||
if (cartItems.isEmpty()) {
|
||||
TextView empty = new TextView(context);
|
||||
empty.setText(context.getString(R.string.cart_empty));
|
||||
empty.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20);
|
||||
empty.setGravity(Gravity.CENTER);
|
||||
empty.setPadding(0, 50, 0, 0);
|
||||
cartList.addView(empty);
|
||||
|
||||
updateTotalDisplay(context, 0, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
// Build list and calculate total at the same time
|
||||
int totalMin = 0;
|
||||
int totalMax = 0;
|
||||
|
||||
for (CartItem item : cartItems) {
|
||||
totalMin += item.getTotalMin();
|
||||
totalMax += item.getTotalMax();
|
||||
|
||||
// Create and add the row view
|
||||
cartList.addView(createCartItemView(item, cartList, context));
|
||||
}
|
||||
|
||||
// Display global price range at the end
|
||||
updateTotalDisplay(context, totalMin, totalMax);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the global price range at the bottom of the screen
|
||||
*/
|
||||
private static void updateTotalDisplay(Context context, int min, int max) {
|
||||
TextView totalView = ((Activity) context).findViewById(R.id.totalView);
|
||||
if (totalView != null) {
|
||||
// Using string resources
|
||||
totalView.setText(context.getString(R.string.price_range, min, max, "€"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a horizontal row for a single cart item
|
||||
* Layout: [image] [name / [quantity / price]] [remove button]
|
||||
*/
|
||||
private static View createCartItemView(CartItem item, LinearLayout cartList, Context context) {
|
||||
LinearLayout row = new LinearLayout(context);
|
||||
row.setOrientation(LinearLayout.HORIZONTAL);
|
||||
row.setGravity(Gravity.CENTER_VERTICAL);
|
||||
|
||||
// Layout parameters
|
||||
LinearLayout.LayoutParams rowParams = new LinearLayout.LayoutParams(
|
||||
LinearLayout.LayoutParams.MATCH_PARENT,
|
||||
LinearLayout.LayoutParams.WRAP_CONTENT);
|
||||
rowParams.setMargins(0, 10, 0, 10);
|
||||
row.setLayoutParams(rowParams);
|
||||
|
||||
// Image
|
||||
ImageView image = new ImageView(context);
|
||||
ImageLoader.loadImage(image, item.getImageFile(),200,200);
|
||||
LinearLayout.LayoutParams imgParams = new LinearLayout.LayoutParams(100, 100);
|
||||
imgParams.setMargins(0, 0, 20, 0);
|
||||
image.setLayoutParams(imgParams);
|
||||
row.addView(image);
|
||||
|
||||
// Sublayout for name + [quantity + price]
|
||||
LinearLayout infoLayout = new LinearLayout(context);
|
||||
infoLayout.setOrientation(LinearLayout.VERTICAL);
|
||||
infoLayout.setLayoutParams(new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1f));
|
||||
|
||||
// Name
|
||||
TextView nameView = new TextView(context);
|
||||
nameView.setText(item.getName());
|
||||
nameView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
|
||||
nameView.setTypeface(null, Typeface.BOLD);
|
||||
infoLayout.addView(nameView);
|
||||
|
||||
// Quantity and price range
|
||||
TextView detailsView = new TextView(context);
|
||||
String details = context.getString(R.string.cart_item, item.getQuantity(), item.getTotalMin(), item.getTotalMax());
|
||||
detailsView.setText(details);
|
||||
detailsView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
|
||||
infoLayout.addView(detailsView);
|
||||
|
||||
row.addView(infoLayout);
|
||||
|
||||
// Remove button
|
||||
row.addView(createRemoveButton(item, cartList, context));
|
||||
|
||||
return row;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the delete button
|
||||
*/
|
||||
private static Button createRemoveButton(CartItem item, LinearLayout cartList, Context context) {
|
||||
Button btn = new Button(context);
|
||||
btn.setText("✖");
|
||||
btn.setTextSize(18);
|
||||
btn.setTextColor(Color.WHITE);
|
||||
btn.setGravity(Gravity.CENTER);
|
||||
|
||||
// Conversion DP to PX for consistent size on all screens
|
||||
float scale = context.getResources().getDisplayMetrics().density;
|
||||
int sizePx = (int) (48 * scale + 0.5f);
|
||||
|
||||
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(sizePx, sizePx);
|
||||
btn.setLayoutParams(params);
|
||||
|
||||
// Background: grey rounded rectangle (API 17 fallback)
|
||||
GradientDrawable shape = new GradientDrawable();
|
||||
shape.setColor(Color.parseColor("#E53935")); // Reddish to indicate delete
|
||||
shape.setCornerRadius(4 * scale);
|
||||
btn.setBackground(shape);
|
||||
|
||||
btn.setOnClickListener(v -> {
|
||||
// setting quantity to 0 removes the item
|
||||
CartManager.addOrUpdateItem(
|
||||
item.getName(),
|
||||
item.getMinPrice(),
|
||||
item.getMaxPrice(),
|
||||
0, // Setting quantity to 0 triggers removal
|
||||
item.getImageFile()
|
||||
);
|
||||
|
||||
// visual refresh of the cart list
|
||||
updateCartView(cartList, context);
|
||||
});
|
||||
|
||||
return btn;
|
||||
}
|
||||
}
|
||||
25
app/src/main/java/com/stock/pignon/Category.java
Normal file
@@ -0,0 +1,25 @@
|
||||
// Category.java
|
||||
package com.stock.pignon;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Category {
|
||||
@SuppressWarnings("unused")
|
||||
private String name;
|
||||
@SuppressWarnings("unused")
|
||||
private String bgColor;
|
||||
@SuppressWarnings("unused")
|
||||
private String textColor;
|
||||
@SuppressWarnings("unused")
|
||||
private List<Item> items;
|
||||
|
||||
public String getName() { return name; }
|
||||
public String getBgColor() { return bgColor; }
|
||||
public String getTextColor() { return textColor; }
|
||||
|
||||
// Avoid crash if json isn't readable
|
||||
public List<Item> getItems() {
|
||||
return items != null ? items : new ArrayList<>();
|
||||
}
|
||||
}
|
||||
16
app/src/main/java/com/stock/pignon/Config.java
Normal file
@@ -0,0 +1,16 @@
|
||||
// Config.java
|
||||
package com.stock.pignon;
|
||||
|
||||
public class Config {
|
||||
// Folder on sd card
|
||||
public static final String EXTERNAL_DIR_NAME = "stock_pignon";
|
||||
|
||||
// Folder on sd card
|
||||
public static final String IMAGES_SUBDIR_NAME = "images";
|
||||
|
||||
// Input json
|
||||
public static final String PIECES_FILE_NAME = "pieces.json";
|
||||
|
||||
// Output json
|
||||
public static final String STOCK_FILE_NAME = "stock.json";
|
||||
}
|
||||
84
app/src/main/java/com/stock/pignon/DataLoader.java
Normal file
@@ -0,0 +1,84 @@
|
||||
// DataLoader.java
|
||||
package com.stock.pignon;
|
||||
|
||||
import android.os.Environment;
|
||||
import android.util.Log;
|
||||
import com.google.gson.Gson;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DataLoader {
|
||||
private static final String TAG = "DataLoader"; // For readable logs
|
||||
private static final String EXTERNAL_DIR = Config.EXTERNAL_DIR_NAME;
|
||||
private static final String PIECES_FILE = Config.PIECES_FILE_NAME;
|
||||
|
||||
// Raw data
|
||||
private static List<Category> cachedCategories = new ArrayList<>();
|
||||
private static List<Item> cachedGlobals = new ArrayList<>();
|
||||
|
||||
|
||||
public static void loadData() {
|
||||
File dir = new File(Environment.getExternalStorageDirectory(), EXTERNAL_DIR);
|
||||
File jsonFile = new File(dir, PIECES_FILE);
|
||||
|
||||
// Check if file exist
|
||||
if (!jsonFile.exists()) {
|
||||
Log.e(TAG, "File doesn't exist : " + jsonFile.getAbsolutePath());
|
||||
return;
|
||||
}
|
||||
|
||||
// Optimized read
|
||||
// Try-with-resources ensures streams are automatically closed, avoid memory leaks
|
||||
try (FileInputStream fis = new FileInputStream(jsonFile);
|
||||
@SuppressWarnings("CharsetObjectCanBeUsed")
|
||||
InputStreamReader reader = new InputStreamReader(fis, "UTF-8")) {
|
||||
|
||||
// From json to java object
|
||||
Gson gson = new Gson();
|
||||
// Internal class needed for Gson
|
||||
CategoriesWrapper wrapper = gson.fromJson(reader, CategoriesWrapper.class);
|
||||
|
||||
// Extract lists from wrapper with null-safety
|
||||
if (wrapper != null) {
|
||||
cachedGlobals = wrapper.globalItems != null ? wrapper.globalItems : new ArrayList<>();
|
||||
cachedCategories = wrapper.categories != null ? wrapper.categories : new ArrayList<>();
|
||||
|
||||
}
|
||||
} catch (java.io.FileNotFoundException e) {
|
||||
Log.e(TAG, "Can't find file", e);
|
||||
} catch (java.io.IOException e) {
|
||||
Log.e(TAG, "Read error (I/O)", e);
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "Parsing JSON error", e);
|
||||
}
|
||||
}
|
||||
|
||||
// Compromise between CPU usage and memory usage : keep cache raw data and combinate global and specific items at call
|
||||
public static List<Item> getItemsForCategory(String categoryName) {
|
||||
|
||||
// Add global items
|
||||
List<Item> combinedList = new ArrayList<>(cachedGlobals);
|
||||
|
||||
// Add specific items
|
||||
for (Category cat : cachedCategories) {
|
||||
if (cat.getName().equals(categoryName)) {
|
||||
combinedList.addAll(cat.getItems());
|
||||
break;
|
||||
}
|
||||
}
|
||||
return combinedList;
|
||||
}
|
||||
|
||||
public static List<Category> getCategories() {
|
||||
return cachedCategories;
|
||||
}
|
||||
|
||||
// Internal class for Gson
|
||||
private static class CategoriesWrapper {
|
||||
List<Item> globalItems;
|
||||
List<Category> categories;
|
||||
}
|
||||
}
|
||||
61
app/src/main/java/com/stock/pignon/ImageLoader.java
Normal file
@@ -0,0 +1,61 @@
|
||||
// ImageLoader.java
|
||||
package com.stock.pignon;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.os.Environment;
|
||||
import android.widget.ImageView;
|
||||
import java.io.File;
|
||||
|
||||
public class ImageLoader {
|
||||
|
||||
/**
|
||||
* Load image from /sdcard/Pignon/, priority JPG then PNG
|
||||
* If image not found, default fallback
|
||||
*/
|
||||
public static void loadImage(ImageView imageView, String fileName, int reqWidth, int reqHeight) {
|
||||
File storageRoot = Environment.getExternalStorageDirectory();
|
||||
File baseDir = new File(storageRoot, Config.EXTERNAL_DIR_NAME);
|
||||
File dir = new File(baseDir, Config.IMAGES_SUBDIR_NAME);
|
||||
|
||||
File imgFileJpg = new File(dir, fileName + ".jpg");
|
||||
File imgFilePng = new File(dir, fileName + ".png");
|
||||
File imgFile = imgFileJpg.exists() ? imgFileJpg : (imgFilePng.exists() ? imgFilePng : null);
|
||||
|
||||
if (imgFile != null && imgFile.exists()) {
|
||||
BitmapFactory.Options options = new BitmapFactory.Options();
|
||||
|
||||
// Check image size without loading
|
||||
options.inJustDecodeBounds = true;
|
||||
BitmapFactory.decodeFile(imgFile.getAbsolutePath(), options);
|
||||
|
||||
// Compute size reduction
|
||||
options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
|
||||
|
||||
// Load reduce size
|
||||
options.inJustDecodeBounds = false;
|
||||
Bitmap bmp = BitmapFactory.decodeFile(imgFile.getAbsolutePath(), options);
|
||||
|
||||
if (bmp != null) {
|
||||
imageView.setImageBitmap(bmp);
|
||||
} else {
|
||||
imageView.setImageResource(android.R.drawable.ic_menu_report_image);
|
||||
}
|
||||
} else {
|
||||
// Fallback Android
|
||||
imageView.setImageResource(android.R.drawable.ic_menu_report_image);
|
||||
}
|
||||
}
|
||||
|
||||
private static int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight) {
|
||||
int inSampleSize = 1;
|
||||
if (options.outHeight > reqHeight || options.outWidth > reqWidth) {
|
||||
final int halfHeight = options.outHeight / 2;
|
||||
final int halfWidth = options.outWidth / 2;
|
||||
while ((halfHeight / inSampleSize) >= reqHeight && (halfWidth / inSampleSize) >= reqWidth) {
|
||||
inSampleSize *= 2;
|
||||
}
|
||||
}
|
||||
return inSampleSize;
|
||||
}
|
||||
}
|
||||
22
app/src/main/java/com/stock/pignon/Item.java
Normal file
@@ -0,0 +1,22 @@
|
||||
// Item.java
|
||||
package com.stock.pignon;
|
||||
|
||||
public class Item {
|
||||
@SuppressWarnings("unused")
|
||||
private String name;
|
||||
@SuppressWarnings("unused")
|
||||
private int minPrice;
|
||||
@SuppressWarnings("unused")
|
||||
private int maxPrice;
|
||||
@SuppressWarnings("unused")
|
||||
private String image;
|
||||
|
||||
// Empty constructor for GSON
|
||||
public Item() {}
|
||||
|
||||
public String getName() { return name; }
|
||||
public int getMinPrice() { return minPrice; }
|
||||
public int getMaxPrice() { return maxPrice; }
|
||||
public String getImage() { return image; }
|
||||
}
|
||||
|
||||
304
app/src/main/java/com/stock/pignon/MainActivity.java
Normal file
@@ -0,0 +1,304 @@
|
||||
package com.stock.pignon;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.GradientDrawable;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.util.TypedValue;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.GridLayout;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import android.os.Environment;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Main Activity: Central Dashboard for the application.
|
||||
* Manages category navigation and item selection within a single screen.
|
||||
*/
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
|
||||
private static final String TAG = "MainActivity";
|
||||
|
||||
// UI Components
|
||||
private LinearLayout cartList;
|
||||
private LinearLayout homeLayout;
|
||||
private LinearLayout categoryItemsLayout;
|
||||
private LinearLayout categoriesLayout;
|
||||
private GridLayout gridPieces;
|
||||
private ImageView mainImage;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
// Hide Android bar
|
||||
View decorView = getWindow().getDecorView();
|
||||
int uiOptions = View.SYSTEM_UI_FLAG_LOW_PROFILE | View.SYSTEM_UI_FLAG_FULLSCREEN;
|
||||
decorView.setSystemUiVisibility(uiOptions);
|
||||
|
||||
// View Binding
|
||||
cartList = findViewById(R.id.cartList);
|
||||
homeLayout = findViewById(R.id.homeLayout);
|
||||
categoryItemsLayout = findViewById(R.id.categoryItemsLayout);
|
||||
categoriesLayout = findViewById(R.id.categoriesLayout);
|
||||
gridPieces = findViewById(R.id.gridPieces);
|
||||
mainImage = findViewById(R.id.mainImage);
|
||||
|
||||
// Setup Back Button
|
||||
Button backBtn = findViewById(R.id.backToHomeBtn);
|
||||
if (backBtn != null) {
|
||||
backBtn.setOnClickListener(v -> showHome());
|
||||
}
|
||||
|
||||
// Copy assets to sd card if not founded
|
||||
copyAssetsIfEmpty();
|
||||
// Get data from sd card
|
||||
DataLoader.loadData();
|
||||
|
||||
// Initial UI Setup
|
||||
setupCategoriesMenu();
|
||||
loadMainImage();
|
||||
|
||||
// Initial cart visual sync
|
||||
CartViewHelper.updateCartView(cartList, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the left sidebar with category buttons using DataLoader's cache.
|
||||
*/
|
||||
private void setupCategoriesMenu() {
|
||||
List<Category> categories = DataLoader.getCategories();
|
||||
if (categories == null || categories.isEmpty()) {
|
||||
Log.w(TAG, "No categories found to display.");
|
||||
return;
|
||||
}
|
||||
|
||||
categoriesLayout.removeAllViews();
|
||||
for (Category category : categories) {
|
||||
Button btn = createCategoryButton(category);
|
||||
// On click, we show the items for this specific category
|
||||
btn.setOnClickListener(v -> showCategory(category.getName()));
|
||||
categoriesLayout.addView(btn);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Styles category buttons based on the new Category getters.
|
||||
*/
|
||||
private Button createCategoryButton(Category category) {
|
||||
Button btn = new Button(this);
|
||||
btn.setText(category.getName());
|
||||
btn.setTextSize(TypedValue.COMPLEX_UNIT_SP, 24);
|
||||
|
||||
float density = getResources().getDisplayMetrics().density;
|
||||
float radiusPx = 3 * density;
|
||||
|
||||
// Apply background color with transparency (70% alpha)
|
||||
if (category.getBgColor() != null) {
|
||||
try {
|
||||
int color = Color.parseColor(category.getBgColor());
|
||||
int alpha = (int) (0.7 * 255);
|
||||
color = (color & 0x00FFFFFF) | (alpha << 24);
|
||||
|
||||
GradientDrawable shape = new GradientDrawable();
|
||||
shape.setColor(color);
|
||||
shape.setCornerRadius(radiusPx);
|
||||
btn.setBackground(shape);
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "Error parsing bgColor for: " + category.getName());
|
||||
}
|
||||
}
|
||||
|
||||
// Apply text color
|
||||
if (category.getTextColor() != null) {
|
||||
try {
|
||||
btn.setTextColor(Color.parseColor(category.getTextColor()));
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "Error parsing textColor for: " + category.getName());
|
||||
}
|
||||
}
|
||||
|
||||
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
|
||||
LinearLayout.LayoutParams.MATCH_PARENT,
|
||||
LinearLayout.LayoutParams.WRAP_CONTENT
|
||||
);
|
||||
params.setMargins(0, 5, 0, 5);
|
||||
btn.setLayoutParams(params);
|
||||
|
||||
return btn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Switches center view to display the grid of items.
|
||||
* Uses DataLoader.getItemsForCategory() to get the merged list.
|
||||
*/
|
||||
private void showCategory(String categoryName) {
|
||||
homeLayout.setVisibility(View.GONE);
|
||||
categoryItemsLayout.setVisibility(View.VISIBLE);
|
||||
|
||||
gridPieces.removeAllViews();
|
||||
|
||||
// Calculate item width for a 4-column grid
|
||||
int gridWidth = getResources().getDisplayMetrics().widthPixels - dpToPx(370);
|
||||
int itemWidth = gridWidth / 4;
|
||||
|
||||
// Fetch the PRE-MERGED list (globals + specifics) from DataLoader
|
||||
List<Item> itemsToDisplay = DataLoader.getItemsForCategory(categoryName);
|
||||
|
||||
for (Item item : itemsToDisplay) {
|
||||
View itemView = LayoutInflater.from(this).inflate(R.layout.item_piece, gridPieces, false);
|
||||
|
||||
// Apply width to the inflated view
|
||||
GridLayout.LayoutParams params = (GridLayout.LayoutParams) itemView.getLayoutParams();
|
||||
if (params == null) {
|
||||
params = new GridLayout.LayoutParams();
|
||||
}
|
||||
params.width = itemWidth;
|
||||
itemView.setLayoutParams(params);
|
||||
|
||||
bindItemToView(itemView, item);
|
||||
gridPieces.addView(itemView);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Connects Item data to the inflated layout piece.
|
||||
*/
|
||||
private void bindItemToView(View itemView, Item item) {
|
||||
TextView nom = itemView.findViewById(R.id.itemName);
|
||||
TextView prix = itemView.findViewById(R.id.itemPrice);
|
||||
ImageView img = itemView.findViewById(R.id.itemImage);
|
||||
TextView qtyView = itemView.findViewById(R.id.qtyView);
|
||||
|
||||
nom.setText(item.getName());
|
||||
prix.setText(getString(R.string.price_range, item.getMinPrice(), item.getMaxPrice(), "€"));
|
||||
|
||||
// Use your existing ImageLoader helper
|
||||
ImageLoader.loadImage(img, item.getImage(),200,200);
|
||||
|
||||
// Sync visual quantity with CartManager
|
||||
CartItem existing = CartManager.getItemByName(item.getName());
|
||||
int currentQty = (existing != null) ? existing.getQuantity() : 0;
|
||||
qtyView.setText(String.valueOf(currentQty));
|
||||
|
||||
// Listeners for + and - buttons
|
||||
itemView.findViewById(R.id.plusBtn).setOnClickListener(v -> updateItemQty(item, qtyView, 1));
|
||||
itemView.findViewById(R.id.minusBtn).setOnClickListener(v -> updateItemQty(item, qtyView, -1));
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the local counter and the global cart state simultaneously.
|
||||
*/
|
||||
private void updateItemQty(Item item, TextView qtyView, int delta) {
|
||||
int current = Integer.parseInt(qtyView.getText().toString());
|
||||
int next = Math.max(0, current + delta);
|
||||
|
||||
qtyView.setText(String.valueOf(next));
|
||||
|
||||
// Central data update
|
||||
CartManager.addOrUpdateItem(item.getName(), item.getMinPrice(), item.getMaxPrice(), next, item.getImage());
|
||||
|
||||
// Refresh sidebar cart list
|
||||
CartViewHelper.updateCartView(cartList, this);
|
||||
}
|
||||
|
||||
private void showHome() {
|
||||
categoryItemsLayout.setVisibility(View.GONE);
|
||||
homeLayout.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
private void loadMainImage() {
|
||||
// Fallback for home screen image
|
||||
ImageLoader.loadImage(mainImage, "_velo", 800,800);
|
||||
}
|
||||
|
||||
// --- Button Actions (linked via android:onClick in XML) ---
|
||||
|
||||
public void emptyCart(View view) {
|
||||
CartActionHelper.emptyCart(cartList, this);
|
||||
}
|
||||
|
||||
public void validateCart(View view) {
|
||||
CartActionHelper.validateCart(cartList, this);
|
||||
}
|
||||
|
||||
private int dpToPx(int dp) {
|
||||
return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, getResources().getDisplayMetrics());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
// Ensure cart is up to date if returning to the activity
|
||||
CartViewHelper.updateCartView(cartList, this);
|
||||
}
|
||||
|
||||
private void copyAssetsIfEmpty() {
|
||||
File folder = new File(Environment.getExternalStorageDirectory(), Config.EXTERNAL_DIR_NAME);
|
||||
|
||||
// First safety : is folder already in sdcard ?
|
||||
if (!folder.exists()) {
|
||||
// Second safety : are we able to create folder ?
|
||||
if (folder.mkdirs()) {
|
||||
// Copy JSON file
|
||||
copyFileFromAssets(Config.PIECES_FILE_NAME, new File(folder, Config.PIECES_FILE_NAME));
|
||||
|
||||
// Copy images subfolder
|
||||
File imgFolder = new File(folder, Config.IMAGES_SUBDIR_NAME);
|
||||
if (imgFolder.mkdirs()) {
|
||||
copyFolderFromAssets(Config.IMAGES_SUBDIR_NAME, imgFolder);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void copyFolderFromAssets(String assetDirName, File destDir) {
|
||||
try {
|
||||
String[] files = getAssets().list(assetDirName);
|
||||
if (files != null) {
|
||||
// For every image
|
||||
for (String fileName : files) {
|
||||
// Create source path
|
||||
String assetPath = assetDirName + "/" + fileName;
|
||||
// Create dest path
|
||||
File destFile = new File(destDir, fileName);
|
||||
// Copy
|
||||
copyFileFromAssets(assetPath, destFile);
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Log.e("MainActivity", "Erreur listing assets: " + assetDirName, e);
|
||||
}
|
||||
}
|
||||
|
||||
private void copyFileFromAssets(String assetName, File destFile) {
|
||||
// Optimized read
|
||||
// Try-with-resources ensures streams are automatically closed, avoid memory leaks
|
||||
try (InputStream in = getAssets().open(assetName);
|
||||
OutputStream out = new FileOutputStream(destFile)) {
|
||||
|
||||
byte[] buffer = new byte[1024];
|
||||
int read;
|
||||
while ((read = in.read(buffer)) != -1) {
|
||||
out.write(buffer, 0, read);
|
||||
}
|
||||
Log.d("MainActivity", "Succès : " + assetName + " copié.");
|
||||
|
||||
} catch (IOException e) {
|
||||
Log.e("MainActivity", "Erreur copie asset: " + assetName, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
30
app/src/main/res/drawable-v24/ic_launcher_foreground.xml
Normal file
@@ -0,0 +1,30 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:aapt="http://schemas.android.com/aapt"
|
||||
android:width="108dp"
|
||||
android:height="108dp"
|
||||
android:viewportWidth="108"
|
||||
android:viewportHeight="108">
|
||||
<path android:pathData="M31,63.928c0,0 6.4,-11 12.1,-13.1c7.2,-2.6 26,-1.4 26,-1.4l38.1,38.1L107,108.928l-32,-1L31,63.928z">
|
||||
<aapt:attr name="android:fillColor">
|
||||
<gradient
|
||||
android:endX="85.84757"
|
||||
android:endY="92.4963"
|
||||
android:startX="42.9492"
|
||||
android:startY="49.59793"
|
||||
android:type="linear">
|
||||
<item
|
||||
android:color="#44000000"
|
||||
android:offset="0.0" />
|
||||
<item
|
||||
android:color="#00000000"
|
||||
android:offset="1.0" />
|
||||
</gradient>
|
||||
</aapt:attr>
|
||||
</path>
|
||||
<path
|
||||
android:fillColor="#FFFFFF"
|
||||
android:fillType="nonZero"
|
||||
android:pathData="M65.3,45.828l3.8,-6.6c0.2,-0.4 0.1,-0.9 -0.3,-1.1c-0.4,-0.2 -0.9,-0.1 -1.1,0.3l-3.9,6.7c-6.3,-2.8 -13.4,-2.8 -19.7,0l-3.9,-6.7c-0.2,-0.4 -0.7,-0.5 -1.1,-0.3C38.8,38.328 38.7,38.828 38.9,39.228l3.8,6.6C36.2,49.428 31.7,56.028 31,63.928h46C76.3,56.028 71.8,49.428 65.3,45.828zM43.4,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2c-0.3,-0.7 -0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C45.3,56.528 44.5,57.328 43.4,57.328L43.4,57.328zM64.6,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2s-0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C66.5,56.528 65.6,57.328 64.6,57.328L64.6,57.328z"
|
||||
android:strokeWidth="1"
|
||||
android:strokeColor="#00000000" />
|
||||
</vector>
|
||||
170
app/src/main/res/drawable/ic_launcher_background.xml
Normal file
@@ -0,0 +1,170 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="108dp"
|
||||
android:height="108dp"
|
||||
android:viewportWidth="108"
|
||||
android:viewportHeight="108">
|
||||
<path
|
||||
android:fillColor="#3DDC84"
|
||||
android:pathData="M0,0h108v108h-108z" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M9,0L9,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,0L19,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M29,0L29,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M39,0L39,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M49,0L49,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M59,0L59,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M69,0L69,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M79,0L79,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M89,0L89,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M99,0L99,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,9L108,9"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,19L108,19"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,29L108,29"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,39L108,39"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,49L108,49"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,59L108,59"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,69L108,69"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,79L108,79"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,89L108,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,99L108,99"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,29L89,29"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,39L89,39"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,49L89,49"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,59L89,59"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,69L89,69"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,79L89,79"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M29,19L29,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M39,19L39,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M49,19L49,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M59,19L59,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M69,19L69,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M79,19L79,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
</vector>
|
||||
65
app/src/main/res/layout/activity_main.xml
Normal file
@@ -0,0 +1,65 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- activity_main.xml -->
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="horizontal"
|
||||
android:background="#ffffff">
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/contentFrame"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/homeLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="horizontal"
|
||||
android:paddingLeft="20dp">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/categoriesLayout"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:gravity="center_vertical"/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/mainImage"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:scaleType="fitCenter" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/categoryItemsLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:visibility="gone"
|
||||
android:padding="10dp">
|
||||
|
||||
<Button
|
||||
android:id="@+id/backToHomeBtn"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="← Retour" />
|
||||
|
||||
<ScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<GridLayout
|
||||
android:id="@+id/gridPieces"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:columnCount="4" />
|
||||
</ScrollView>
|
||||
</LinearLayout>
|
||||
</FrameLayout>
|
||||
|
||||
<include layout="@layout/partial_cart" />
|
||||
|
||||
</LinearLayout>
|
||||
72
app/src/main/res/layout/item_piece.xml
Normal file
@@ -0,0 +1,72 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- item_piece.xml -->
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="0dp"
|
||||
android:background="#FFFFFF"
|
||||
android:padding="5dp"
|
||||
android:gravity="center"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/itemImage"
|
||||
android:layout_width="150dp"
|
||||
android:layout_height="150dp"
|
||||
android:scaleType="centerCrop"
|
||||
android:src="@mipmap/ic_launcher" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/itemName"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
tools:text="Item name"
|
||||
android:textSize="20sp"
|
||||
android:layout_marginTop="0dp"
|
||||
android:lines="1"
|
||||
android:ellipsize="end" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/itemPrice"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
tools:text="Price"
|
||||
android:textSize="20sp" />
|
||||
|
||||
<!-- Quantity layout -->
|
||||
<LinearLayout
|
||||
android:id="@+id/qtyLayout"
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="0dp"
|
||||
android:gravity="center">
|
||||
|
||||
<Button
|
||||
android:id="@+id/minusBtn"
|
||||
android:layout_width="64dp"
|
||||
android:layout_height="64dp"
|
||||
android:text="-"
|
||||
android:textSize="24sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/qtyView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="1"
|
||||
android:textSize="22sp"
|
||||
android:layout_marginStart="10dp"
|
||||
android:layout_marginEnd="10dp"
|
||||
android:gravity="center"
|
||||
android:focusable="false"
|
||||
android:focusableInTouchMode="false" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/plusBtn"
|
||||
android:layout_width="64dp"
|
||||
android:layout_height="64dp"
|
||||
android:text="+"
|
||||
android:textSize="24sp" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
84
app/src/main/res/layout/partial_cart.xml
Normal file
@@ -0,0 +1,84 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- partial_panier.xml -->
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/cartContainer"
|
||||
android:layout_width="350dp"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:background="#DDDDDD"
|
||||
android:padding="10dp"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/cart_name"
|
||||
android:textSize="22sp"
|
||||
android:textStyle="bold"
|
||||
android:gravity="center"
|
||||
android:paddingBottom="10dp"
|
||||
android:textColor="#333333"/>
|
||||
|
||||
<ScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
android:fadeScrollbars="false">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/cartList"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical" />
|
||||
</ScrollView>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:background="#E0E0E0"
|
||||
android:padding="10dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/totalView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
tools:text="Total: 0 - 0 €"
|
||||
android:textStyle="bold"
|
||||
android:textSize="24sp"
|
||||
android:gravity="center"
|
||||
android:paddingBottom="10dp"
|
||||
android:textColor="#000000"/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:weightSum="2">
|
||||
|
||||
<Button
|
||||
android:id="@+id/clearCartBtn"
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="60dp"
|
||||
android:text="@string/cart_empty_btn"
|
||||
android:textSize="18sp"
|
||||
android:textColor="#FFFFFF"
|
||||
android:background="#E53935"
|
||||
android:layout_marginEnd="5dp"
|
||||
android:onClick="emptyCart"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/validateCartBtn"
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="60dp"
|
||||
android:text="@string/cart_validate_btn"
|
||||
android:textSize="18sp"
|
||||
android:textColor="#FFFFFF"
|
||||
android:background="#43A047"
|
||||
android:layout_marginStart="5dp"
|
||||
android:onClick="validateCart"/>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
5
app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
Normal file
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<background android:drawable="@color/ic_launcher_background"/>
|
||||
<foreground android:drawable="@mipmap/ic_launcher_foreground"/>
|
||||
</adaptive-icon>
|
||||
5
app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml
Normal file
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<background android:drawable="@color/ic_launcher_background"/>
|
||||
<foreground android:drawable="@mipmap/ic_launcher_foreground"/>
|
||||
</adaptive-icon>
|
||||
BIN
app/src/main/res/mipmap-hdpi/ic_launcher.webp
Normal file
|
After Width: | Height: | Size: 2.7 KiB |
BIN
app/src/main/res/mipmap-hdpi/ic_launcher_foreground.webp
Normal file
|
After Width: | Height: | Size: 5.4 KiB |
BIN
app/src/main/res/mipmap-hdpi/ic_launcher_round.webp
Normal file
|
After Width: | Height: | Size: 4.7 KiB |
BIN
app/src/main/res/mipmap-mdpi/ic_launcher.webp
Normal file
|
After Width: | Height: | Size: 1.6 KiB |
BIN
app/src/main/res/mipmap-mdpi/ic_launcher_foreground.webp
Normal file
|
After Width: | Height: | Size: 2.9 KiB |
BIN
app/src/main/res/mipmap-mdpi/ic_launcher_round.webp
Normal file
|
After Width: | Height: | Size: 2.7 KiB |
BIN
app/src/main/res/mipmap-xhdpi/ic_launcher.webp
Normal file
|
After Width: | Height: | Size: 4.0 KiB |
BIN
app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.webp
Normal file
|
After Width: | Height: | Size: 8.9 KiB |
BIN
app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp
Normal file
|
After Width: | Height: | Size: 7.0 KiB |
BIN
app/src/main/res/mipmap-xxhdpi/ic_launcher.webp
Normal file
|
After Width: | Height: | Size: 7.3 KiB |
BIN
app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.webp
Normal file
|
After Width: | Height: | Size: 18 KiB |
BIN
app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp
Normal file
|
After Width: | Height: | Size: 13 KiB |
BIN
app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp
Normal file
|
After Width: | Height: | Size: 12 KiB |
BIN
app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.webp
Normal file
|
After Width: | Height: | Size: 28 KiB |
BIN
app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp
Normal file
|
After Width: | Height: | Size: 19 KiB |
10
app/src/main/res/values-night/themes.xml
Normal file
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<style name="Theme.Pignon" parent="Theme.AppCompat.Light.DarkActionBar">
|
||||
<item name="colorPrimary">@color/purple_500</item>
|
||||
<item name="colorPrimaryDark">@color/purple_700</item>
|
||||
<item name="colorAccent">@color/teal_200</item>
|
||||
</style>
|
||||
|
||||
</resources>
|
||||
6
app/src/main/res/values/colors.xml
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<color name="purple_500">#FF6200EE</color>
|
||||
<color name="purple_700">#FF3700B3</color>
|
||||
<color name="teal_200">#FF03DAC5</color>
|
||||
</resources>
|
||||
4
app/src/main/res/values/ic_launcher_background.xml
Normal file
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<color name="ic_launcher_background">#0049AE</color>
|
||||
</resources>
|
||||
18
app/src/main/res/values/strings.xml
Normal file
@@ -0,0 +1,18 @@
|
||||
<resources>
|
||||
<string name="app_name">Atelier du Pignon - Pièces à prix libre</string>
|
||||
|
||||
<string name="cart_name">Mes sacoches</string>
|
||||
<string name="cart_validate_btn">Valider</string>
|
||||
<string name="cart_empty_btn">Vider</string>
|
||||
<string name="cart_empty">Sacoches vides</string>
|
||||
<string name="cart_item">Quantité : %1$d (%2$d - %3$d €)</string>
|
||||
|
||||
<string name="currency">€</string>
|
||||
<string name="price_range">%1$d - %2$d %3$s</string>
|
||||
|
||||
<string name="popup_name">Mes sacoches</string>
|
||||
<string name="popup_item"><![CDATA[<b>%1$d x %2$s</b> : %3$d - %4$d €<br>]]></string>
|
||||
<string name="popup_total"><![CDATA[<br><b>Contribution consciente dans la petite boîte : %1$d - %2$d €</b>]]></string>
|
||||
<string name="popup_end">Sacoches sauvegardées, merci !</string>
|
||||
|
||||
</resources>
|
||||
12
app/src/main/res/values/themes.xml
Normal file
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<style name="Theme.Pignon" parent="Theme.AppCompat.Light.DarkActionBar">
|
||||
<item name="colorPrimary">@color/purple_500</item>
|
||||
<item name="colorPrimaryDark">@color/purple_700</item>
|
||||
<item name="colorAccent">@color/teal_200</item>
|
||||
|
||||
<item name="actionBarSize">40dp</item>
|
||||
</style>
|
||||
|
||||
</resources>
|
||||
17
app/src/test/java/com/stock/pignon/ExampleUnitTest.java
Normal file
@@ -0,0 +1,17 @@
|
||||
package com.stock.pignon;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Example local unit test, which will execute on the development machine (host).
|
||||
*
|
||||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
|
||||
*/
|
||||
public class ExampleUnitTest {
|
||||
@Test
|
||||
public void addition_isCorrect() {
|
||||
assertEquals(4, 2 + 2);
|
||||
}
|
||||
}
|
||||