From 50796a695176b120a05576716e62529ae2b8a7e0 Mon Sep 17 00:00:00 2001 From: Ahmed Al-Omairi Date: Sat, 30 Aug 2025 23:31:19 +0300 Subject: [PATCH] Mulberry View UI first adjustMulberryView functions for M70, M30, M20 --- .../pos/ui/mulberry/MulberryFragment.java | 14 +- .../pos/ui/mulberry/MulberryViewModel.java | 200 +++++++++++++----- .../com/dspread/pos/utils/PosParameters.java | 2 +- .../src/main/res/drawable/ax_pinpad_grey.xml | 179 ++++++++++++++++ .../src/main/res/layout/fragment_mulberry.xml | 25 ++- .../main/res/layout/item_mulberry_card.xml | 5 +- 6 files changed, 365 insertions(+), 60 deletions(-) create mode 100644 pos_android_app/src/main/res/drawable/ax_pinpad_grey.xml diff --git a/pos_android_app/src/main/java/com/dspread/pos/ui/mulberry/MulberryFragment.java b/pos_android_app/src/main/java/com/dspread/pos/ui/mulberry/MulberryFragment.java index 0b92c61..4f2aa1a 100644 --- a/pos_android_app/src/main/java/com/dspread/pos/ui/mulberry/MulberryFragment.java +++ b/pos_android_app/src/main/java/com/dspread/pos/ui/mulberry/MulberryFragment.java @@ -6,6 +6,8 @@ import android.os.Bundle; import android.view.LayoutInflater; import android.view.ViewGroup; +import androidx.recyclerview.widget.RecyclerView; + import com.dspread.pos.common.base.BaseFragment; import com.dspread.pos.TitleProviderListener; import com.dspread.pos.ui.main.MainActivity; @@ -19,7 +21,17 @@ public class MulberryFragment extends BaseFragment { Activity activity = getActivity(); diff --git a/pos_android_app/src/main/java/com/dspread/pos/ui/mulberry/MulberryViewModel.java b/pos_android_app/src/main/java/com/dspread/pos/ui/mulberry/MulberryViewModel.java index fa98ee7..a21f595 100644 --- a/pos_android_app/src/main/java/com/dspread/pos/ui/mulberry/MulberryViewModel.java +++ b/pos_android_app/src/main/java/com/dspread/pos/ui/mulberry/MulberryViewModel.java @@ -7,18 +7,24 @@ import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.os.Build; import android.util.Log; +import android.view.View; +import android.view.ViewGroup; +import android.widget.GridLayout; +import android.widget.ImageView; +import android.widget.LinearLayout; import androidx.annotation.NonNull; +import androidx.cardview.widget.CardView; import androidx.databinding.Observable; import androidx.databinding.ObservableArrayList; import androidx.databinding.ObservableField; import androidx.databinding.ObservableList; -import androidx.lifecycle.LiveData; import androidx.lifecycle.MutableLiveData; +import androidx.recyclerview.widget.GridLayoutManager; +import androidx.recyclerview.widget.RecyclerView; import com.dspread.pos.common.base.BaseAppViewModel; import com.dspread.pos.data.local.PreferencesManager; -import com.dspread.pos.utils.ImageUtils; import com.dspread.pos.utils.PosParameters; import com.dspread.pos.utils.TRACE; import com.dspread.pos_android_app.BR; @@ -35,11 +41,23 @@ import java.util.Map; import me.tatarka.bindingcollectionadapter2.ItemBinding; import me.goldze.mvvmhabit.bus.event.SingleLiveEvent; -import me.goldze.mvvmhabit.base.ItemViewModel; public class MulberryViewModel extends BaseAppViewModel { private static final String TAG = "MulberryVM"; + // Device type constants + private static final int DEVICE_TYPE_SMALL = 1; // D20, D30, D30M + private static final int DEVICE_TYPE_COMPACT = 2; // D70 (wide but small) + private static final int DEVICE_TYPE_LARGE = 3; // D80, D80K, others + + private int currentDeviceType; + + // Device-specific observables + public final ObservableField logoHeight = new ObservableField<>(); + public final ObservableField gridSpanCount = new ObservableField<>(); + public final ObservableField maxNavItems = new ObservableField<>(); + public final ObservableField cardImageSize = new ObservableField<>(); + // UI Observables public final ObservableField mainLogo = new ObservableField<>(); public final ObservableField footerLogo = new ObservableField<>(); @@ -63,23 +81,26 @@ public class MulberryViewModel extends BaseAppViewModel { private final Map imageCache = new HashMap<>(); private final MutableLiveData imagesLoaded = new MutableLiveData<>(false); + // Provide height in pixels, not dp + + + public MulberryViewModel(@NonNull Application application) { super(application); TRACE.i("Mulberry fragment init"); Log.d(TAG, "MulberryViewModel constructor called"); + // Add this to track initialization Log.d(TAG, "ViewModel hash: " + this.hashCode()); - if (Build.MODEL.equalsIgnoreCase("D70") || - Build.MODEL.equalsIgnoreCase("D30") || - Build.MODEL.equalsIgnoreCase("D30M") || - Build.MODEL.equalsIgnoreCase("D80")|| - Build.MODEL.equalsIgnoreCase("D80K")) { - Log.d("Build.MODEL", "MainViewModel: " + Build.MODEL);; - // To-Do set small size of logo ,and grid size 3 by 1 - } - - +// if (Build.MODEL.equalsIgnoreCase("D70") || +// Build.MODEL.equalsIgnoreCase("D30") || +// Build.MODEL.equalsIgnoreCase("D30M") || +// Build.MODEL.equalsIgnoreCase("D80")|| +// Build.MODEL.equalsIgnoreCase("D80K")) { +// Log.d("Build.MODEL", "MainViewModel: " + Build.MODEL);; +// // To-Do set small size of logo ,and grid size 3 by 1 +// } // Observe WebSocket connection status getWebSocketConnectionStatus().observeForever(isConnected -> { @@ -99,6 +120,82 @@ public class MulberryViewModel extends BaseAppViewModel { initialize(); } + public void adjustMulberryView(ImageView logoImageView, + LinearLayout containerLayout, + LinearLayout footerContainer, + LinearLayout centerContainer, + + View rootView + ) { + // Find RecyclerView from root view + + String model = Build.MODEL.toUpperCase(); + int heightPx = 150; // default (~100dp) + int paddingPx = 10 ; // default 10dp + + if (model.contains("D70")) { + heightPx = 20; // 20dp for D70 + paddingPx = 2 ; // 2dp for D70 + + containerLayout.setVisibility(View.GONE); + footerContainer.setVisibility(View.GONE); + centerContainer.setVisibility(View.GONE); + + // Adjust GridLayout columnCount + RecyclerView recyclerView = rootView.findViewById(R.id.mulberryCards_list); + if (recyclerView != null && recyclerView.getLayoutManager() instanceof GridLayoutManager) { + GridLayoutManager layoutManager = (GridLayoutManager) recyclerView.getLayoutManager(); + layoutManager.setSpanCount(3); + // Set padding on the RecyclerView (not LayoutManager) + recyclerView.setPadding(0, 1, 0, 1); + recyclerView.setLayoutManager(layoutManager); + } + // Adjust CardView size + CardView cardView = rootView.findViewById(R.id.widget_card); + if (cardView != null) { + int sizeInPx = 80; // Convert 120dp to pixels + ViewGroup.LayoutParams params = cardView.getLayoutParams(); + params.width = sizeInPx; + params.height = sizeInPx; + cardView.setLayoutParams(params); + } + + for (int i = 0; i < recyclerView.getChildCount(); i++) { + View cardViews = recyclerView.getChildAt(i); + if (cardViews instanceof CardView) { + // Adjust card padding + cardViews.setPadding( 0,0,0,0 + ); + + // Find and resize the ImageView + ImageView imageView = cardView.findViewById(R.id.navImage); + if (imageView != null) { + ViewGroup.LayoutParams params = imageView.getLayoutParams(); + params.width = 80; + params.height = 80; + imageView.setLayoutParams(params); + } + } + } + + } else if ( model.contains("D20")) { + heightPx = 100; // ~80dp for D30/D20 + paddingPx = 8 ; + } else if (model.contains("D30")) { + heightPx = 80; +// containerLayout.setVisibility(View.GONE); + footerContainer.setVisibility(View.GONE); + centerContainer.setVisibility(View.GONE); + paddingPx = 0 ; + } + + ViewGroup.LayoutParams params = logoImageView.getLayoutParams(); + params.height = heightPx; + logoImageView.setLayoutParams(params); + containerLayout.setPadding(0, paddingPx, 0, paddingPx); + + } + private void initialize() { Log.d(TAG, "Initializing ViewModel"); @@ -424,61 +521,74 @@ public class MulberryViewModel extends BaseAppViewModel { JSONArray navItemsArray = new JSONArray(json); List enabledItems = new ArrayList<>(); + // First pass: collect all enabled items with their original JSON data for (int i = 0; i < navItemsArray.length(); i++) { JSONObject itemJson = navItemsArray.getJSONObject(i); - // Use your exact existing model structure NavItemViewModel item = new NavItemViewModel( itemJson.getString("navName"), parseIconSource(itemJson.opt("icon")), itemJson.optInt("position", 0), - itemJson.optBoolean("enabled", true) // Keep enabled status + itemJson.optBoolean("enabled", true), + itemJson // Store the original JSON to preserve page info ); - // Only add enabled items (matching your working version's behavior) if (item.enabled) { enabledItems.add(item); - Log.d(TAG, "Loaded item: " + item.name + - " | Pos: " + item.position + - " | Enabled: " + item.enabled); + Log.d(TAG, "Loaded item: " + item.name + " | Pos: " + item.position + " | Enabled: " + item.enabled); } } - // 2. Sort with position logging (like your working version) + // Sort by position (same as working version) Collections.sort(enabledItems, (i1, i2) -> { Log.v(TAG, "Sorting: " + i1.position + " vs " + i2.position); return Integer.compare(i1.position, i2.position); }); - // 3. Create ViewModels - optimized page ID handling - for (int i = 0; i < enabledItems.size(); i++) { - JSONObject originalJson = navItemsArray.getJSONObject(i); - NavItemViewModel item = enabledItems.get(i); + // Create ViewModels using the original JSON data for page mapping + for (NavItemViewModel item : enabledItems) { + try { + String pageName = item.originalJson.optString("navPage"); + int pageId = PAGE_MAP.containsKey(pageName) ? PAGE_MAP.get(pageName) : NAV_HOME; - // Directly get page ID from the original JSON - String pageName = originalJson.optString("navPage"); - int pageId = PAGE_MAP.containsKey(pageName) - ? PAGE_MAP.get(pageName) - : NAV_HOME; + navItems.add(new MulberryItemViewModel( + this, + item.name, + item.iconSource, + pageId, + null + )); + Log.d(TAG, "Added item: " + item.name + " | Page: " + pageName + " | PageID: " + pageId); - - navItems.add(new MulberryItemViewModel( - this, - item.name, - item.iconSource, - pageId, // Maintain page structure -// null, - null - )); + } catch (Exception e) { + Log.e(TAG, "Error creating ViewModel for item: " + item.name, e); + } } Log.d(TAG, "Loaded " + navItems.size() + " items from prefs"); + } catch (Exception e) { Log.e(TAG, "Error parsing nav items JSON", e); } } + // Updated model class to store original JSON + private static class NavItemViewModel { + String name; + Object iconSource; + int position; + boolean enabled; + JSONObject originalJson; // Store original JSON for page mapping + + NavItemViewModel(String name, Object iconSource, int position, boolean enabled, JSONObject originalJson) { + this.name = name; + this.iconSource = iconSource; + this.position = position; + this.enabled = enabled; + this.originalJson = originalJson; + } + } private Object parseIconSource(Object icon) { if (icon instanceof String) { try { @@ -492,20 +602,6 @@ public class MulberryViewModel extends BaseAppViewModel { return icon; // Return as-is if not string } - // Simple model for navigation items - private static class NavItemViewModel { - String name; - Object iconSource; - int position; - boolean enabled; - - NavItemViewModel(String name, Object iconSource, int position, boolean enabled) { - this.name = name; - this.iconSource = iconSource; - this.position = position; - this.enabled = enabled; - } - } @Override protected void onCleared() { diff --git a/pos_android_app/src/main/java/com/dspread/pos/utils/PosParameters.java b/pos_android_app/src/main/java/com/dspread/pos/utils/PosParameters.java index 44a21c5..ae8a3da 100644 --- a/pos_android_app/src/main/java/com/dspread/pos/utils/PosParameters.java +++ b/pos_android_app/src/main/java/com/dspread/pos/utils/PosParameters.java @@ -276,7 +276,7 @@ public class PosParameters { map.put("scan", R.drawable.ax_scaner_grey); map.put("printer", R.drawable.ax_receipt_grey); map.put("settings", R.drawable.ax_settings_grey); - map.put("pinpad", R.drawable.ax_menu_grey); + map.put("pinpad", R.drawable.ax_pinpad_grey); map.put("cashier", R.drawable.ax_cashier_grey); map.put("mulberry", R.drawable.am_mulberry_logo_wide_color); map.put("overtec", R.drawable.am_overtec_logo_wide_color); diff --git a/pos_android_app/src/main/res/drawable/ax_pinpad_grey.xml b/pos_android_app/src/main/res/drawable/ax_pinpad_grey.xml new file mode 100644 index 0000000..32cf0e8 --- /dev/null +++ b/pos_android_app/src/main/res/drawable/ax_pinpad_grey.xml @@ -0,0 +1,179 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/pos_android_app/src/main/res/layout/fragment_mulberry.xml b/pos_android_app/src/main/res/layout/fragment_mulberry.xml index 904e15e..db3bd69 100644 --- a/pos_android_app/src/main/res/layout/fragment_mulberry.xml +++ b/pos_android_app/src/main/res/layout/fragment_mulberry.xml @@ -5,6 +5,10 @@ xmlns:binding="http://schemas.android.com/apk/res-auto"> + + @@ -33,11 +37,18 @@ android:layout_height="wrap_content" android:gravity="center" android:orientation="vertical" - android:paddingTop="10dp" - android:paddingBottom="10dp" + + + + app:layout_constraintBottom_toTopOf="@id/gridLayout" + + + app:layout_constraintVertical_bias="0.5" + app:layout_constraintTop_toTopOf="parent" app:layout_constraintStart_toStartOf="parent" - app:layout_constraintEnd_toEndOf="parent"> + app:layout_constraintEnd_toEndOf="parent" + > + android:padding="14dp">