host config address fix

This commit is contained in:
MooN 2026-01-29 13:29:50 +06:30
parent 3c77d4d9c7
commit f6067f8de6
4 changed files with 238 additions and 252 deletions

View File

@ -1,11 +1,18 @@
package com.utsmm.kbz.ui.settings; 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.MutableLiveData;
import androidx.lifecycle.ViewModel; import androidx.lifecycle.ViewModel;
import com.utsmm.kbz.BuildConfig; import com.utsmm.kbz.BuildConfig;
import com.utsmyanmar.paylibs.utils.core_utils.SystemParamsOperation; import com.utsmyanmar.paylibs.utils.core_utils.SystemParamsOperation;
import java.util.ArrayList;
import java.util.List;
public class HostConfigViewModel extends ViewModel { public class HostConfigViewModel extends ViewModel {
public String appVersion = BuildConfig.VERSION_NAME; public String appVersion = BuildConfig.VERSION_NAME;
@ -38,13 +45,11 @@ public class HostConfigViewModel extends ViewModel {
public void loadConfig() { public void loadConfig() {
SystemParamsOperation sp = SystemParamsOperation.getInstance(); SystemParamsOperation sp = SystemParamsOperation.getInstance();
// Merchant Info // Merchant Info
merchantName.setValue(sp.getMerchantName()); merchantName.setValue(sp.getMerchantName());
merchantPhone.setValue(sp.getMerchantPhoneNo()); merchantPhone.setValue(sp.getMerchantPhoneNo());
merchantAddress1.setValue(sp.getMerchantAddress()); merchantAddress1.setValue(wrapForUi(sp.getMerchantAddress()));
merchantAddress2.setValue(sp.getMerchantAddress2()); merchantAddress2.setValue(sp.getMerchantAddress2());
terminalName.setValue(sp.getTerminalName()); 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<String> result = new ArrayList<>();
String[] paragraphs = text.split("\\n");
for (String paragraph : paragraphs) {
List<String> wrappedLines = wrapAddressText(paragraph.trim(), 29);
result.addAll(wrappedLines);
}
return TextUtils.join("\n", result);
}
private String[] split(String raw) { private String[] split(String raw) {
if (raw == null || raw.trim().isEmpty()) { if (raw == null || raw.trim().isEmpty()) {
return new String[]{"", ""}; return new String[]{"", ""};

View File

@ -1,21 +1,23 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<layout xmlns:tools="http://schemas.android.com/tools" <layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:bind="http://schemas.android.com/tools"> xmlns:tools="http://schemas.android.com/tools">
<data> <data>
<import type="android.view.View"/> <import type="android.view.View"/>
<import type="android.text.TextUtils"/> <import type="android.text.TextUtils"/>
<variable <variable
name="viewModel" name="viewModel"
type="com.utsmm.kbz.ui.settings.HostConfigViewModel" /> type="com.utsmm.kbz.ui.settings.HostConfigViewModel"/>
<variable <variable
name="sharedViewModel" name="sharedViewModel"
type="com.utsmm.kbz.ui.core_viewmodel.SharedViewModel" /> type="com.utsmm.kbz.ui.core_viewmodel.SharedViewModel"/>
<variable <variable
name="click" name="click"
type="com.utsmm.kbz.ui.settings.HostConfigFragment.ClickHandler" /> type="com.utsmm.kbz.ui.settings.HostConfigFragment.ClickHandler"/>
</data> </data>
<androidx.constraintlayout.widget.ConstraintLayout <androidx.constraintlayout.widget.ConstraintLayout
@ -23,12 +25,11 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:padding="16dp"> android:padding="16dp">
<!-- CARD SECTION --> <!-- ================= CARD ================= -->
<androidx.cardview.widget.CardView <androidx.cardview.widget.CardView
android:id="@+id/hostCard" android:id="@+id/hostCard"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="0dp" android:layout_height="0dp"
android:layout_marginBottom="8dp"
app:cardCornerRadius="16dp" app:cardCornerRadius="16dp"
app:cardElevation="0dp" app:cardElevation="0dp"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
@ -53,292 +54,204 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical"> android:orientation="vertical">
<!-- HEADER --> <!-- ===== HEADER ===== -->
<!-- Merchant Info -->
<!-- <TextView-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:text="@{viewModel.merchantName}"-->
<!-- android:fontFamily="@font/rubik_regular"-->
<!-- android:textSize="16sp"-->
<!-- android:textStyle="bold"-->
<!-- android:textAlignment="center"-->
<!-- tools:text="Someone Mart"/>-->
<TextView <TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@{viewModel.terminalName}" android:text="@{viewModel.terminalName}"
android:fontFamily="@font/rubik_regular"
android:textSize="16sp" android:textSize="16sp"
android:textStyle="bold" android:textStyle="bold"
android:textAlignment="center" android:gravity="center"
tools:text="Terminal_Name"/> style="@style/HostLabelStyle"
android:fontFamily="@font/rubik_regular"
tools:text="Terminal Name"
android:layout_height="wrap_content"
android:layout_width="match_parent"/>
<TextView <TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@{viewModel.merchantAddress1}" android:text="@{viewModel.merchantAddress1}"
android:fontFamily="@font/rubik_regular" android:textSize="14sp"
android:textSize="16sp" style="@style/HostLabelStyle"
android:textStyle="bold" android:textStyle="bold"
android:textAlignment="center" android:gravity="center"
tools:text="Corner of Bogyoke and Botahtaung Pagoda Street"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@{viewModel.merchantAddress2}"
android:fontFamily="@font/rubik_regular" android:fontFamily="@font/rubik_regular"
android:textSize="16sp" tools:text="Merchant Address Line 1"
android:textStyle="bold" android:layout_height="wrap_content"
android:textAlignment="center" android:layout_width="match_parent"/>
tools:text="Yangon"/>
<!-- <TextView-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:text="@{viewModel.terminalName}"-->
<!-- android:fontFamily="@font/rubik_regular"-->
<!-- android:textSize="16sp"-->
<!-- android:textStyle="bold"-->
<!-- tools:text="Terminal_Name"/>-->
<TextView <TextView
android:layout_width="match_parent" android:text="--------------------------------------------------------------------------"
android:gravity="left"
android:paddingVertical="8dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="*************************************************" android:layout_width="match_parent"/>
android:paddingTop="8dp"
android:paddingBottom="8dp"
tools:text="*********************************************************"/>
<TextView <TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TERMINAL CONFIGURATION" android:text="TERMINAL CONFIGURATION"
android:fontFamily="@font/rubik_regular"
android:textSize="16sp" android:textSize="16sp"
android:textStyle="bold" android:textStyle="bold"
android:textAlignment="center" style="@style/HostLabelStyle"
android:gravity="center"
android:paddingBottom="12dp" android:paddingBottom="12dp"
tools:text="TERMINAL CONFIGURATION"/> android:fontFamily="@font/rubik_regular"
<!-- PRIMARY HOST -->
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_width="match_parent"/>
<!-- ===== PRIMARY HOST ===== -->
<TextView
android:text="PRIMARY HOST" android:text="PRIMARY HOST"
android:fontFamily="@font/rubik_regular" android:paddingBottom="4dp"
android:textSize="14sp" style="@style/HostLabelStyle"
android:textStyle="bold" android:layout_height="wrap_content"
tools:text="PRIMARY HOST"/> android:layout_width="match_parent"/>
<TextView <TableLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text='@{"Name : " + viewModel.hostName}' android:stretchColumns="1">
android:fontFamily="@font/rubik_regular"
android:textSize="14sp" <TableRow>
android:textStyle="bold" <TextView style="@style/HostLabelStyle" android:text="Name"/>
tools:text="Name : Card Host"/> <TextView style="@style/HostValueStyle"
android:text='@{": " + viewModel.hostName}'/>
</TableRow>
<TableRow>
<TextView style="@style/HostLabelStyle" android:text="TID"/>
<TextView style="@style/HostValueStyle"
android:text='@{": " + viewModel.tid}'/>
</TableRow>
<TableRow>
<TextView style="@style/HostLabelStyle" android:text="MID"/>
<TextView style="@style/HostValueStyle"
android:text='@{": " + viewModel.mid}'/>
</TableRow>
<TableRow>
<TextView style="@style/HostLabelStyle" android:text="Primary IP"/>
<TextView style="@style/HostValueStyle"
android:text='@{": " + viewModel.primaryIp}'/>
</TableRow>
<TableRow>
<TextView style="@style/HostLabelStyle" android:text="Primary Port"/>
<TextView style="@style/HostValueStyle"
android:text='@{": " + viewModel.primaryPort}'/>
</TableRow>
<TableRow>
<TextView style="@style/HostLabelStyle" android:text="Secondary IP"/>
<TextView style="@style/HostValueStyle"
android:text='@{": " + viewModel.secondaryIp}'/>
</TableRow>
<TableRow>
<TextView style="@style/HostLabelStyle" android:text="Secondary Port"/>
<TextView style="@style/HostValueStyle"
android:text='@{": " + viewModel.secondaryPort}'/>
</TableRow>
<TableRow>
<TextView style="@style/HostLabelStyle" android:text="Currency"/>
<TextView style="@style/HostValueStyle"
android:text='@{": " + viewModel.currencyCode}'/>
</TableRow>
</TableLayout>
<TextView <TextView
android:layout_width="match_parent" android:text="--------------------------------------------------------------------------"
android:gravity="left"
android:paddingVertical="8dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text='@{"TID : " + viewModel.tid}' android:layout_width="match_parent"/>
android:fontFamily="@font/rubik_regular"
android:textSize="14sp"
android:textStyle="bold"
tools:text="TID : 12345678"/>
<TextView <!-- ===== SECONDARY HOST ===== -->
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text='@{"MID : " + viewModel.mid}'
android:fontFamily="@font/rubik_regular"
android:textSize="14sp"
android:textStyle="bold"
tools:text="MID : 123456789876543"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text='@{"PRIMARY IP : " + viewModel.primaryIp}'
android:fontFamily="@font/rubik_regular"
android:textSize="14sp"
android:textStyle="bold"
tools:text="PRIMARY IP : primaryidport.com"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text='@{"PRIMARY PORT : " + viewModel.primaryPort}'
android:fontFamily="@font/rubik_regular"
android:textSize="14sp"
android:textStyle="bold"
tools:text="PRIMARY PORT : 8080"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text='@{"SECONDARY IP : " + viewModel.secondaryIp}'
android:fontFamily="@font/rubik_regular"
android:textSize="14sp"
android:textStyle="bold"
tools:text="SECONDARY IP : secondaryidport.com"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text='@{"SECONDARY PORT : " + viewModel.secondaryPort}'
android:fontFamily="@font/rubik_regular"
android:textSize="14sp"
android:textStyle="bold"
tools:text="SECONDARY PORT : 8080"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text='@{"CURRENCY CODE : " + viewModel.currencyCode}'
android:fontFamily="@font/rubik_regular"
android:textSize="14sp"
android:textStyle="bold"
tools:text="CURRENCY CODE : MMK"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="*************************************************"
android:paddingTop="8dp"
android:paddingBottom="8dp"
tools:text="********************************************************"/>
<!-- SECONDARY HOST -->
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical" android:orientation="vertical"
android:visibility='@{!viewModel.secHostName.isEmpty() ? View.VISIBLE : View.GONE}' android:visibility='@{!TextUtils.isEmpty(viewModel.secHostName) ? View.VISIBLE : View.GONE}'
tools:visibility="visible"> tools:visibility="visible">
<TextView <TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="SECONDARY HOST" android:text="SECONDARY HOST"
android:fontFamily="@font/rubik_regular"
android:textSize="14sp" android:textSize="14sp"
style="@style/HostLabelStyle"
android:textStyle="bold" android:textStyle="bold"
tools:text="SECONDARY HOST"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text='@{"Name : " + viewModel.secHostName}'
android:fontFamily="@font/rubik_regular" android:fontFamily="@font/rubik_regular"
android:textSize="14sp"
android:textStyle="bold"
tools:text="Name : QR Host"/>
<!-- <TextView-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:text='@{"TID : " + viewModel.secHostTid}'-->
<!-- android:fontFamily="@font/rubik_regular"-->
<!-- android:textSize="14sp"-->
<!-- android:textStyle="bold"-->
<!-- tools:text="TID : 87654321"/>-->
<!-- <TextView-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:text='@{"MID : " + viewModel.secHostMid}'-->
<!-- android:fontFamily="@font/rubik_regular"-->
<!-- android:textSize="14sp"-->
<!-- android:textStyle="bold"-->
<!-- tools:text="MID : 987654321012345"/>-->
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text='@{"SHORT CODE : " + viewModel.shortCode}'
android:fontFamily="@font/rubik_regular"
android:textSize="14sp"
android:textStyle="bold"
tools:text="SHORT CODE : 12345678987"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text='@{"Primary Ip : " + viewModel.secHostPrimaryIp}'
android:fontFamily="@font/rubik_regular"
android:textSize="14sp"
android:textStyle="bold"
tools:text="Primary Ip : 10.10.10.10"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text='@{"Primary Port : " + viewModel.secHostPrimaryPort}'
android:fontFamily="@font/rubik_regular"
android:textSize="14sp"
android:textStyle="bold"
tools:text="Primary Port : 5000"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text='@{"Secondary Ip : " + viewModel.secHostSecondaryIp}'
android:fontFamily="@font/rubik_regular"
android:textSize="14sp"
android:textStyle="bold"
tools:text="Secondary Ip : 10.10.10.11"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text='@{"Secondary Port : " + viewModel.secHostSecondaryPort}'
android:fontFamily="@font/rubik_regular"
android:textSize="14sp"
android:textStyle="bold"
tools:text="Secondary Port : 5001"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text='@{"Currency Code : " + viewModel.currencyCode}'
android:fontFamily="@font/rubik_regular"
android:textSize="14sp"
android:textStyle="bold"
tools:text="Currency Code : MMK"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="*************************************************"
android:paddingTop="8dp" android:paddingTop="8dp"
android:paddingBottom="8dp" android:layout_height="wrap_content"
tools:text="********************************************************"/> android:layout_width="match_parent"/>
</LinearLayout> <TableLayout
<LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical" android:stretchColumns="1">
tools:visibility="visible">
<TableRow>
<TextView style="@style/HostLabelStyle" android:text="Name"/>
<TextView style="@style/HostValueStyle"
android:text='@{": " + viewModel.secHostName}'/>
</TableRow>
<TableRow>
<TextView style="@style/HostLabelStyle" android:text="Short Code"/>
<TextView style="@style/HostValueStyle"
android:text='@{": " + viewModel.shortCode}'/>
</TableRow>
<TableRow>
<TextView style="@style/HostLabelStyle" android:text="Primary IP"/>
<TextView style="@style/HostValueStyle"
android:text='@{": " + viewModel.secHostPrimaryIp}'/>
</TableRow>
<TableRow>
<TextView style="@style/HostLabelStyle" android:text="Primary Port"/>
<TextView style="@style/HostValueStyle"
android:text='@{": " + viewModel.secHostPrimaryPort}'/>
</TableRow>
<TableRow>
<TextView style="@style/HostLabelStyle" android:text="Secondary IP"/>
<TextView style="@style/HostValueStyle"
android:text='@{": " + viewModel.secHostSecondaryIp}'/>
</TableRow>
<TableRow>
<TextView style="@style/HostLabelStyle" android:text="Secondary Port"/>
<TextView style="@style/HostValueStyle"
android:text='@{": " + viewModel.secHostSecondaryPort}'/>
</TableRow>
<TableRow>
<TextView style="@style/HostLabelStyle" android:text="Currency"/>
<TextView style="@style/HostValueStyle"
android:text='@{": " + viewModel.currencyCode}'/>
</TableRow>
</TableLayout>
<TextView <TextView
android:layout_width="match_parent" android:text="--------------------------------------------------------------------------"
android:gravity="left"
android:paddingVertical="8dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_width="match_parent"/>
</LinearLayout>
<!-- ===== APP VERSION ===== -->
<TextView
android:text='@{"App Version : " + viewModel.appVersion}' android:text='@{"App Version : " + viewModel.appVersion}'
android:fontFamily="@font/rubik_regular"
android:textSize="14sp" android:textSize="14sp"
android:textStyle="bold" android:textStyle="bold"
tools:text="App Version : 1.0"/> style="@style/HostLabelStyle"
</LinearLayout> android:fontFamily="@font/rubik_regular"
android:layout_height="wrap_content"
android:layout_width="match_parent"/>
</LinearLayout> </LinearLayout>
</ScrollView> </ScrollView>
</FrameLayout> </FrameLayout>
</androidx.cardview.widget.CardView> </androidx.cardview.widget.CardView>
<!-- ACTION BUTTONS --> <!-- ================= BUTTONS ================= -->
<LinearLayout <LinearLayout
android:id="@+id/actionButtons" android:id="@+id/actionButtons"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -356,8 +269,7 @@
android:onClick="@{()-> click.onCancel()}" android:onClick="@{()-> click.onCancel()}"
android:background="@drawable/bg_rounded_btn_cancel_cv" android:background="@drawable/bg_rounded_btn_cancel_cv"
android:textColor="@color/colorPrimary" android:textColor="@color/colorPrimary"
android:textStyle="bold" android:textStyle="bold"/>
tools:text="Cancel"/>
<Button <Button
android:layout_width="0dp" android:layout_width="0dp"
@ -368,8 +280,7 @@
android:onClick="@{()-> click.onPrint()}" android:onClick="@{()-> click.onPrint()}"
android:background="@drawable/bg_rounded_btn_cv" android:background="@drawable/bg_rounded_btn_cv"
android:textColor="@color/white" android:textColor="@color/white"
android:textStyle="bold" android:textStyle="bold"/>
tools:text="Print"/>
</LinearLayout> </LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingVertical="2dp">
<!-- LABEL -->
<TextView
android:id="@+id/tvLabel"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:text="Label"
android:textSize="14sp"
android:textStyle="bold"
android:fontFamily="@font/rubik_regular"/>
<!-- COLON -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" : "
android:textSize="14sp"
android:textStyle="bold"
android:fontFamily="@font/rubik_regular"/>
<!-- VALUE -->
<TextView
android:id="@+id/tvValue"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Value"
android:textSize="14sp"
android:textStyle="bold"
android:fontFamily="@font/rubik_regular"/>
</LinearLayout>

View File

@ -94,4 +94,21 @@
<item name="android:textColor">@color/colorPrimary</item> <item name="android:textColor">@color/colorPrimary</item>
</style> </style>
<style name="HostLabelStyle">
<item name="android:layout_width">110dp</item> <item name="android:layout_height">wrap_content</item>
<item name="android:fontFamily">@font/rubik_regular</item>
<item name="android:textSize">14sp</item>
<item name="android:textStyle">bold</item>
<item name="android:textColor">#000000</item>
</style>
<style name="HostValueStyle">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:fontFamily">@font/rubik_regular</item>
<item name="android:textSize">14sp</item>
<item name="android:textStyle">bold</item>
<item name="android:textColor">#000000</item>
</style>
</resources> </resources>