diff --git a/app/src/main/java/com/utsmm/kbz/ui/settings/HostConfigViewModel.java b/app/src/main/java/com/utsmm/kbz/ui/settings/HostConfigViewModel.java index 3766ecd..67bf4ab 100644 --- a/app/src/main/java/com/utsmm/kbz/ui/settings/HostConfigViewModel.java +++ b/app/src/main/java/com/utsmm/kbz/ui/settings/HostConfigViewModel.java @@ -1,11 +1,18 @@ package com.utsmm.kbz.ui.settings; +import static com.utsmyanmar.paylibs.print.printx.BaseXPrint.wrapAddressText; + +import android.text.TextUtils; + import androidx.lifecycle.MutableLiveData; import androidx.lifecycle.ViewModel; import com.utsmm.kbz.BuildConfig; import com.utsmyanmar.paylibs.utils.core_utils.SystemParamsOperation; +import java.util.ArrayList; +import java.util.List; + public class HostConfigViewModel extends ViewModel { public String appVersion = BuildConfig.VERSION_NAME; @@ -38,13 +45,11 @@ public class HostConfigViewModel extends ViewModel { public void loadConfig() { - SystemParamsOperation sp = SystemParamsOperation.getInstance(); - // Merchant Info merchantName.setValue(sp.getMerchantName()); merchantPhone.setValue(sp.getMerchantPhoneNo()); - merchantAddress1.setValue(sp.getMerchantAddress()); + merchantAddress1.setValue(wrapForUi(sp.getMerchantAddress())); merchantAddress2.setValue(sp.getMerchantAddress2()); terminalName.setValue(sp.getTerminalName()); @@ -81,6 +86,22 @@ public class HostConfigViewModel extends ViewModel { } } + public static String wrapForUi(String text) { + if (text == null || text.isEmpty()) return ""; + + List result = new ArrayList<>(); + + String[] paragraphs = text.split("\\n"); + + for (String paragraph : paragraphs) { + List wrappedLines = wrapAddressText(paragraph.trim(), 29); + + result.addAll(wrappedLines); + } + + return TextUtils.join("\n", result); + } + private String[] split(String raw) { if (raw == null || raw.trim().isEmpty()) { return new String[]{"", ""}; diff --git a/app/src/main/res/layout/fragment_host_config.xml b/app/src/main/res/layout/fragment_host_config.xml index 7e65bb9..b35542e 100644 --- a/app/src/main/res/layout/fragment_host_config.xml +++ b/app/src/main/res/layout/fragment_host_config.xml @@ -1,21 +1,23 @@ - + xmlns:tools="http://schemas.android.com/tools"> + + type="com.utsmm.kbz.ui.settings.HostConfigViewModel"/> + + type="com.utsmm.kbz.ui.core_viewmodel.SharedViewModel"/> + + type="com.utsmm.kbz.ui.settings.HostConfigFragment.ClickHandler"/> - + - - - - - - - - - - - - - + + android:gravity="center" + style="@style/HostLabelStyle" + android:fontFamily="@font/rubik_regular" + tools:text="Terminal Name" + android:layout_height="wrap_content" + android:layout_width="match_parent"/> - - - - - - - - - - + tools:text="Merchant Address Line 1" + android:layout_height="wrap_content" + android:layout_width="match_parent"/> + android:layout_width="match_parent"/> - - - + + + + android:paddingBottom="4dp" + style="@style/HostLabelStyle" + android:layout_height="wrap_content" + android:layout_width="match_parent"/> - + android:stretchColumns="1"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + android:layout_width="match_parent"/> - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + android:layout_height="wrap_content" + android:layout_width="match_parent"/> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + - + style="@style/HostLabelStyle" + android:fontFamily="@font/rubik_regular" + android:layout_height="wrap_content" + android:layout_width="match_parent"/> - + + android:textStyle="bold"/>