host config view
This commit is contained in:
parent
20417eb811
commit
eed7dd4680
@ -1,46 +0,0 @@
|
||||
package com.utsmm.kbz.ui.settings;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.utsmm.kbz.databinding.ItemHostConfigBinding;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class HostConfigAdapter extends RecyclerView.Adapter<HostConfigAdapter.Holder> {
|
||||
private List<HostConfigItem> list = new ArrayList<>();
|
||||
|
||||
public void setList(List<HostConfigItem> newList){
|
||||
this.list = newList;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public HostConfigAdapter.Holder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
ItemHostConfigBinding binding = ItemHostConfigBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false);
|
||||
return new Holder(binding);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull HostConfigAdapter.Holder holder, int position) {
|
||||
holder.binding.setItem(list.get(position));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return list.size();
|
||||
}
|
||||
|
||||
static class Holder extends RecyclerView.ViewHolder {
|
||||
ItemHostConfigBinding binding;
|
||||
Holder(ItemHostConfigBinding bind){
|
||||
super(bind.getRoot());
|
||||
binding = bind;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2,6 +2,11 @@ package com.utsmm.kbz.ui.settings;
|
||||
|
||||
import static androidx.databinding.DataBindingUtil.getBinding;
|
||||
|
||||
import static com.utsmyanmar.baselib.BaseApplication.sunmiPrinterService;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Typeface;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
@ -10,6 +15,7 @@ import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
|
||||
import android.os.RemoteException;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
@ -21,6 +27,7 @@ import com.nexgo.oaf.apiv3.DeviceEngine;
|
||||
import com.nexgo.oaf.apiv3.DeviceInfo;
|
||||
import com.nexgo.oaf.apiv3.SdkResult;
|
||||
import com.nexgo.oaf.apiv3.device.printer.AlignEnum;
|
||||
import com.nexgo.oaf.apiv3.device.printer.GrayLevelEnum;
|
||||
import com.nexgo.oaf.apiv3.device.printer.Printer;
|
||||
import com.utsmm.kbz.BR;
|
||||
import com.utsmm.kbz.R;
|
||||
@ -28,11 +35,22 @@ import com.utsmm.kbz.config.Constants;
|
||||
import com.utsmm.kbz.databinding.FragmentHostConfigBinding;
|
||||
import com.utsmyanmar.baselib.fragment.DataBindingFragment;
|
||||
import com.utsmyanmar.baselib.util.DataBindingConfig;
|
||||
import com.utsmyanmar.baselib.util.DialogCallback;
|
||||
import com.utsmyanmar.paylibs.PayLibsUtils;
|
||||
import com.utsmyanmar.paylibs.print.PaperRollStatusCallback;
|
||||
import com.utsmyanmar.paylibs.print.PrintHelper;
|
||||
import com.utsmyanmar.paylibs.utils.LogUtil;
|
||||
import com.utsmyanmar.paylibs.utils.core_utils.SystemParamsOperation;
|
||||
import com.utsmyanmar.paylibs.utils.print_utils.BitmapUtils;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class HostConfigFragment extends DataBindingFragment {
|
||||
|
||||
private HostConfigViewModel viewModel;
|
||||
protected Printer printer;
|
||||
int FONT_NORMAL = 20;
|
||||
int FONT_HEADER = 28;
|
||||
|
||||
@Override
|
||||
protected void initViewModel() {
|
||||
@ -50,6 +68,7 @@ public class HostConfigFragment extends DataBindingFragment {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
|
||||
FragmentHostConfigBinding binding = (FragmentHostConfigBinding) this.binding;
|
||||
viewModel.loadConfig();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -80,118 +99,146 @@ public class HostConfigFragment extends DataBindingFragment {
|
||||
}
|
||||
|
||||
public void onPrint(){
|
||||
|
||||
startPrintProcess();
|
||||
}
|
||||
}
|
||||
private void startPrintProcess() {
|
||||
|
||||
DeviceEngine engine = APIProxy.getDeviceEngine(requireContext());
|
||||
printer = engine.getPrinter();
|
||||
int printerStatus = printer.getStatus();
|
||||
if(printerStatus != SdkResult.Success){
|
||||
Log.e("Print Config", "Printer Error: " + printerStatus);
|
||||
return;
|
||||
}
|
||||
printer.setGray(GrayLevelEnum.LEVEL_2);
|
||||
printer.setTypeface(Typeface.SANS_SERIF);
|
||||
SystemParamsOperation sp = SystemParamsOperation.getInstance();
|
||||
|
||||
|
||||
Bitmap bitmap = BitmapFactory.decodeResource(requireContext().getResources(), com.utsmyanmar.paylibs.R.drawable.print_kbz_logo);
|
||||
printLogo(bitmap);
|
||||
printer.appendPrnStr("\n", FONT_NORMAL, AlignEnum.CENTER, false);
|
||||
printer.appendPrnStr("TERMINAL CONFIGURATION", FONT_HEADER, AlignEnum.CENTER, true);
|
||||
printer.appendPrnStr("\n", FONT_NORMAL, AlignEnum.CENTER, false);
|
||||
printer.appendPrnStr(sp.getMerchantName(), FONT_NORMAL, AlignEnum.LEFT, false);
|
||||
printer.appendPrnStr(sp.getMerchantPhoneNo(), FONT_NORMAL, AlignEnum.LEFT, false);
|
||||
printer.appendPrnStr(sp.getMerchantAddress(), FONT_NORMAL, AlignEnum.CENTER, false);
|
||||
printer.appendPrnStr(sp.getMerchantAddress2(), FONT_NORMAL, AlignEnum.CENTER, false);
|
||||
printer.appendPrnStr("\n--------------------------------\n", FONT_NORMAL, AlignEnum.LEFT, false);
|
||||
printer.appendPrnStr("PRIMARY HOST", FONT_NORMAL, AlignEnum.LEFT, true);
|
||||
printer.appendPrnStr("Name : " + sp.getHostName(), FONT_NORMAL, AlignEnum.LEFT, false);
|
||||
printer.appendPrnStr("TID : " + sp.getTerminalId(), FONT_NORMAL, AlignEnum.LEFT, false);
|
||||
printer.appendPrnStr("MID : " + sp.getMerchantId(), FONT_NORMAL, AlignEnum.LEFT, false);
|
||||
String ipAddress = sp.getIpAddress();
|
||||
String[] ipAndPort = splitIpAndPort(ipAddress);
|
||||
String ip = ipAndPort[0];
|
||||
String port = ipAndPort[1];
|
||||
printer.appendPrnStr("Primary Ip : " + ip, FONT_NORMAL, AlignEnum.LEFT, true);
|
||||
printer.appendPrnStr("Primary Port : " + port, FONT_NORMAL, AlignEnum.LEFT, true);
|
||||
String secIpAddress = sp.getSecIpAddress();
|
||||
String[] secIpAndPort = splitIpAndPort(secIpAddress);
|
||||
String secIp = secIpAndPort[0];
|
||||
String secPort = secIpAndPort[1];
|
||||
printer.appendPrnStr("Secondary Ip : " + secIp, FONT_NORMAL, AlignEnum.LEFT, true);
|
||||
printer.appendPrnStr("Secondary Port : " + secPort, FONT_NORMAL, AlignEnum.LEFT, true);
|
||||
printer.appendPrnStr("Currency Code : " + sp.getCurrencyType(), FONT_NORMAL, AlignEnum.LEFT, true);
|
||||
printer.appendPrnStr("\n--------------------------------\n", FONT_NORMAL, AlignEnum.LEFT, false);
|
||||
|
||||
if (!TextUtils.isEmpty(sp.getSecHostName())) {
|
||||
printer.appendPrnStr("SECONDARY HOST", FONT_NORMAL, AlignEnum.LEFT, true);
|
||||
printer.appendPrnStr("Name : " + sp.getSecHostName(), FONT_NORMAL, AlignEnum.LEFT, false);
|
||||
printer.appendPrnStr("TID : " + sp.getSecHostTerminalId(), FONT_NORMAL, AlignEnum.LEFT, false);
|
||||
printer.appendPrnStr("MID : " + sp.getSecHostMerchantId(), FONT_NORMAL, AlignEnum.LEFT, false);
|
||||
String secHostIpAddress = sp.getSecHostIpAddress();
|
||||
String[] secHostIpAndPort = splitIpAndPort(secHostIpAddress);
|
||||
String secHostIp = secHostIpAndPort[0];
|
||||
String secHostPort = secHostIpAndPort[1];
|
||||
printer.appendPrnStr("Primary Ip : " + secHostIp, FONT_NORMAL, AlignEnum.LEFT, true);
|
||||
printer.appendPrnStr("Primary Port : " + secHostPort, FONT_NORMAL, AlignEnum.LEFT, true);
|
||||
String secHostSecIpAddress = sp.getSecHostSecIpAddress();
|
||||
String[] SecHostSecIpAndPort = splitIpAndPort(secHostSecIpAddress);
|
||||
String secHostSecIp = SecHostSecIpAndPort[0];
|
||||
String secHostSecPort = SecHostSecIpAndPort[1];
|
||||
printer.appendPrnStr("Secondary Ip : " + secHostSecIp, FONT_NORMAL, AlignEnum.LEFT, true);
|
||||
printer.appendPrnStr("Secondary Port : " + secHostSecPort, FONT_NORMAL, AlignEnum.LEFT, true);
|
||||
printer.appendPrnStr("Currency Code : " + sp.getCurrencyType(), FONT_NORMAL, AlignEnum.LEFT, true);
|
||||
printer.appendPrnStr("\n--------------------------------\n", FONT_NORMAL, AlignEnum.LEFT, false);
|
||||
}
|
||||
|
||||
printer.startPrint(true, ret -> {
|
||||
Log.d("Print", "Print result = " + ret);
|
||||
});
|
||||
}
|
||||
|
||||
private String[] splitIpAndPort(String raw) {
|
||||
if (raw == null || raw.trim().isEmpty()) {
|
||||
return new String[]{"", ""};
|
||||
}
|
||||
|
||||
raw = raw.trim();
|
||||
|
||||
// If starts with http/https
|
||||
if (raw.startsWith("http://") || raw.startsWith("https://")) {
|
||||
|
||||
// Attempt to extract host + port via URL
|
||||
try {
|
||||
java.net.URL url = new java.net.URL(raw);
|
||||
|
||||
String host = url.getHost(); // hostname or IP
|
||||
int port = url.getPort(); // -1 if no port
|
||||
String path = url.getPath(); // /api or /
|
||||
|
||||
// If port exists → split normally
|
||||
if (port != -1) {
|
||||
return new String[]{
|
||||
host, // e.g. 10.10.10.10
|
||||
String.valueOf(port) // e.g. 5000
|
||||
};
|
||||
}
|
||||
|
||||
// No port → do NOT split
|
||||
return new String[]{ raw, "" };
|
||||
|
||||
} catch (Exception e) {
|
||||
// fail-safe: do not split
|
||||
return new String[]{ raw, "" };
|
||||
}
|
||||
}
|
||||
|
||||
//public void onClickPrintConfig() {
|
||||
//
|
||||
// DeviceEngine deviceEngine = APIProxy.getDeviceEngine(requireContext());
|
||||
// Printer printer = deviceEngine.getPrinter();
|
||||
// DeviceInfo deviceInfo = deviceEngine.getDeviceInfo();
|
||||
//
|
||||
// int FONT_NORMAL = 24;
|
||||
// int FONT_HEADER = 32;
|
||||
//
|
||||
// int status = printer.getStatus();
|
||||
// if (status != SdkResult.Success) {
|
||||
// Log.d("Printer", "Printer error: " + status);
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// SystemParamsOperation sp = SystemParamsOperation.getInstance();
|
||||
//
|
||||
// String addr1 = sp.getMerchantAddress();
|
||||
// String addr2 = sp.getMerchantAddress2();
|
||||
// String phone = sp.getMerchantPhoneNo();
|
||||
// if (addr2 == null) addr2 = "";
|
||||
// if (phone == null || phone.trim().isEmpty()) phone = "";
|
||||
//
|
||||
// printer.setGray(getGrayLevel());
|
||||
//
|
||||
// // ================== Header ==================
|
||||
// printer.appendPrnStr("==== Device Configs ====", FONT_HEADER, AlignEnum.CENTER, true);
|
||||
// printer.appendPrnStr(" ", FONT_NORMAL, AlignEnum.CENTER, false);
|
||||
//
|
||||
// if(!TextUtils.isEmpty(addr1))
|
||||
// printer.appendPrnStr(addr1, FONT_NORMAL, AlignEnum.CENTER, true);
|
||||
// if(!TextUtils.isEmpty(addr2))
|
||||
// printer.appendPrnStr(addr2, FONT_NORMAL, AlignEnum.CENTER, true);
|
||||
// if(!TextUtils.isEmpty(phone))
|
||||
// printer.appendPrnStr(phone, FONT_NORMAL, AlignEnum.CENTER, true);
|
||||
//
|
||||
// printer.appendPrnStr(" ", FONT_NORMAL, AlignEnum.CENTER, false);
|
||||
//
|
||||
//
|
||||
// // ================== Device Info ==================
|
||||
// printer.appendPrnStr("Device S/N", deviceInfo.getSn(), FONT_NORMAL, true);
|
||||
// printer.appendPrnStr(" ", FONT_NORMAL, AlignEnum.CENTER, false);
|
||||
//
|
||||
//
|
||||
// // ================== Host Section ==================
|
||||
// printer.appendPrnStr("HOSTS", FONT_HEADER, AlignEnum.LEFT, true);
|
||||
// printer.appendPrnStr(" ", FONT_NORMAL, AlignEnum.CENTER, false);
|
||||
//
|
||||
// // ---- Primary Host ----
|
||||
// printer.appendPrnStr("Name :", sp.getHostName(), FONT_NORMAL, false);
|
||||
// printTwoColWrapped(printer, "IP :", sp.getIpAddress(), FONT_NORMAL, false);
|
||||
// printTwoColWrapped(printer, "Sec IP :", sp.getSecIpAddress(), FONT_NORMAL, false);
|
||||
// printer.appendPrnStr("MID :", sp.getMerchantId(), FONT_NORMAL, false);
|
||||
// printer.appendPrnStr("TID :", sp.getTerminalId(), FONT_NORMAL, false);
|
||||
//
|
||||
// printer.appendPrnStr("--------------------------------", FONT_NORMAL, AlignEnum.LEFT, false);
|
||||
//
|
||||
// // ---- Secondary Host ----
|
||||
// if (!TextUtils.isEmpty(sp.getSecHostName())) {
|
||||
//
|
||||
// printer.appendPrnStr("Name :", sp.getSecHostName(), FONT_NORMAL, false);
|
||||
// printTwoColWrapped(printer, "IP :", sp.getSecHostIpAddress(), FONT_NORMAL, false);
|
||||
// printTwoColWrapped(printer, "Sec IP :", sp.getSecHostSecIpAddress(), FONT_NORMAL, false);
|
||||
// printer.appendPrnStr("MID :", sp.getSecHostMerchantId(), FONT_NORMAL, false);
|
||||
// printer.appendPrnStr("TID :", sp.getSecHostTerminalId(), FONT_NORMAL, false);
|
||||
//
|
||||
// printer.appendPrnStr("--------------------------------", FONT_NORMAL, AlignEnum.LEFT, false);
|
||||
// }
|
||||
//
|
||||
// // ================== Start Printing ==================
|
||||
// printer.startPrint(true, ret -> {
|
||||
// if(ret == SdkResult.Success){
|
||||
// Log.d("Printer", "Print success");
|
||||
// } else {
|
||||
// Log.d("Printer", "Print failed: " + ret);
|
||||
// }
|
||||
// });
|
||||
//}
|
||||
//
|
||||
//private void printTwoColWrapped(Printer p, String left, String right, int font, Boolean isBold) {
|
||||
//
|
||||
// if (right == null) right = "";
|
||||
//
|
||||
// int maxRight = 24; // recommended width for right column
|
||||
//
|
||||
// // If right text fits → print normally
|
||||
// if (right.length() <= maxRight) {
|
||||
// p.appendPrnStr(left, right, font, isBold);
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// // Otherwise wrap it
|
||||
// int start = 0;
|
||||
// boolean firstLine = true;
|
||||
//
|
||||
// while (start < right.length()) {
|
||||
// int end = Math.min(start + maxRight, right.length());
|
||||
// String part = right.substring(start, end);
|
||||
//
|
||||
// if (firstLine) {
|
||||
// p.appendPrnStr(left, part, font, isBold);
|
||||
// firstLine = false;
|
||||
// } else {
|
||||
// // subsequent lines: blank left column
|
||||
// p.appendPrnStr(" ", part, font, isBold);
|
||||
// }
|
||||
//
|
||||
// start += maxRight;
|
||||
// }
|
||||
//}
|
||||
// Normal "IP:Port" split
|
||||
int idx = raw.lastIndexOf(":");
|
||||
|
||||
if (idx == -1) {
|
||||
return new String[]{ raw, "" };
|
||||
}
|
||||
|
||||
return new String[]{
|
||||
raw.substring(0, idx),
|
||||
raw.substring(idx + 1)
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
private void printLogo(Bitmap logoBitmap) {
|
||||
try {
|
||||
if (logoBitmap == null || printer == null) return;
|
||||
|
||||
Bitmap bmp = logoBitmap;
|
||||
|
||||
// Max printable width = 384px
|
||||
if (bmp.getWidth() > 384) {
|
||||
int newHeight = (int) (bmp.getHeight() * (384f / bmp.getWidth()));
|
||||
bmp = Bitmap.createScaledBitmap(bmp, 384, newHeight, true);
|
||||
}
|
||||
|
||||
printer.appendPrnStr("\n", FONT_NORMAL, AlignEnum.CENTER, false);
|
||||
printer.appendImage(bmp, AlignEnum.CENTER);
|
||||
printer.appendPrnStr("\n", FONT_NORMAL, AlignEnum.CENTER, false);
|
||||
|
||||
} catch (Exception e) {
|
||||
Log.e("PRINT", "Logo error: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,26 +1,123 @@
|
||||
package com.utsmm.kbz.ui.settings;
|
||||
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
import androidx.lifecycle.ViewModel;
|
||||
import com.utsmyanmar.paylibs.utils.core_utils.SystemParamsOperation;
|
||||
|
||||
public class HostConfigViewModel extends ViewModel {
|
||||
|
||||
public String merchantAddress1;
|
||||
public String merchantAddress2;
|
||||
public String merchantPhoneNumber;
|
||||
public String merchantName;
|
||||
public String merchantPhone;
|
||||
public MutableLiveData<String> merchantName = new MutableLiveData<>();
|
||||
public MutableLiveData<String> merchantPhone = new MutableLiveData<>();
|
||||
public MutableLiveData<String> merchantAddress1 = new MutableLiveData<>();
|
||||
public MutableLiveData<String> merchantAddress2 = new MutableLiveData<>();
|
||||
|
||||
// Primary Host
|
||||
public MutableLiveData<String> hostName = new MutableLiveData<>();
|
||||
public MutableLiveData<String> tid = new MutableLiveData<>();
|
||||
public MutableLiveData<String> mid = new MutableLiveData<>();
|
||||
public MutableLiveData<String> primaryIp = new MutableLiveData<>();
|
||||
public MutableLiveData<String> primaryPort = new MutableLiveData<>();
|
||||
public MutableLiveData<String> secondaryIp = new MutableLiveData<>();
|
||||
public MutableLiveData<String> secondaryPort = new MutableLiveData<>();
|
||||
public MutableLiveData<String> currencyCode = new MutableLiveData<>();
|
||||
|
||||
// Secondary Host
|
||||
public MutableLiveData<String> secHostName = new MutableLiveData<>();
|
||||
public MutableLiveData<String> secHostTid = new MutableLiveData<>();
|
||||
public MutableLiveData<String> secHostMid = new MutableLiveData<>();
|
||||
public MutableLiveData<String> secHostPrimaryIp = new MutableLiveData<>();
|
||||
public MutableLiveData<String> secHostPrimaryPort = new MutableLiveData<>();
|
||||
public MutableLiveData<String> secHostSecondaryIp = new MutableLiveData<>();
|
||||
public MutableLiveData<String> secHostSecondaryPort = new MutableLiveData<>();
|
||||
|
||||
|
||||
public void loadConfig() {
|
||||
|
||||
public HostConfigViewModel(){
|
||||
SystemParamsOperation sp = SystemParamsOperation.getInstance();
|
||||
merchantAddress1 = sp.getMerchantAddress();
|
||||
merchantAddress2 = sp.getMerchantAddress2();
|
||||
merchantPhoneNumber = sp.getMerchantPhoneNo();
|
||||
merchantName = sp.getMerchantName();
|
||||
merchantPhone = sp.getMerchantPhoneNo();
|
||||
|
||||
// Merchant Info
|
||||
merchantName.setValue(sp.getMerchantName());
|
||||
merchantPhone.setValue(sp.getMerchantPhoneNo());
|
||||
merchantAddress1.setValue(sp.getMerchantAddress());
|
||||
merchantAddress2.setValue(sp.getMerchantAddress2());
|
||||
|
||||
// PRIMARY HOST
|
||||
hostName.setValue(sp.getHostName());
|
||||
tid.setValue(sp.getTerminalId());
|
||||
mid.setValue(sp.getMerchantId());
|
||||
|
||||
String[] pri = split(sp.getIpAddress());
|
||||
primaryIp.setValue(pri[0]);
|
||||
primaryPort.setValue(pri[1]);
|
||||
|
||||
String[] sec = split(sp.getSecIpAddress());
|
||||
secondaryIp.setValue(sec[0]);
|
||||
secondaryPort.setValue(sec[1]);
|
||||
|
||||
currencyCode.setValue(sp.getCurrencyType() != null ? sp.getCurrencyType().toString() : "");
|
||||
|
||||
|
||||
if (sp.getSecHostName() != null && !sp.getSecHostName().isEmpty()) {
|
||||
|
||||
secHostName.setValue(sp.getSecHostName());
|
||||
secHostTid.setValue(sp.getSecHostTerminalId());
|
||||
secHostMid.setValue(sp.getSecHostMerchantId());
|
||||
|
||||
String[] shp = split(sp.getSecHostIpAddress());
|
||||
secHostPrimaryIp.setValue(shp[0]);
|
||||
secHostPrimaryPort.setValue(shp[1]);
|
||||
|
||||
String[] shs = split(sp.getSecHostSecIpAddress());
|
||||
secHostSecondaryIp.setValue(shs[0]);
|
||||
secHostSecondaryPort.setValue(shs[1]);
|
||||
}
|
||||
}
|
||||
|
||||
private String saftString(String s){
|
||||
return s == null ? "" : s;
|
||||
private String[] split(String raw) {
|
||||
if (raw == null || raw.trim().isEmpty()) {
|
||||
return new String[]{"", ""};
|
||||
}
|
||||
|
||||
raw = raw.trim();
|
||||
|
||||
// If starts with http/https
|
||||
if (raw.startsWith("http://") || raw.startsWith("https://")) {
|
||||
|
||||
// Attempt to extract host + port via URL
|
||||
try {
|
||||
java.net.URL url = new java.net.URL(raw);
|
||||
|
||||
String host = url.getHost(); // hostname or IP
|
||||
int port = url.getPort(); // -1 if no port
|
||||
String path = url.getPath(); // /api or /
|
||||
|
||||
// If port exists → split normally
|
||||
if (port != -1) {
|
||||
return new String[]{
|
||||
host, // e.g. 10.10.10.10
|
||||
String.valueOf(port) // e.g. 5000
|
||||
};
|
||||
}
|
||||
|
||||
// No port → do NOT split
|
||||
return new String[]{ raw, "" };
|
||||
|
||||
} catch (Exception e) {
|
||||
// fail-safe: do not split
|
||||
return new String[]{ raw, "" };
|
||||
}
|
||||
}
|
||||
|
||||
// Normal "IP:Port" split
|
||||
int idx = raw.lastIndexOf(":");
|
||||
|
||||
if (idx == -1) {
|
||||
return new String[]{ raw, "" };
|
||||
}
|
||||
|
||||
return new String[]{
|
||||
raw.substring(0, idx),
|
||||
raw.substring(idx + 1)
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
|
||||
<data>
|
||||
<import type="android.view.View"/>
|
||||
<import type="android.text.TextUtils" />
|
||||
<variable
|
||||
name="viewModel"
|
||||
type="com.utsmm.kbz.ui.settings.HostConfigViewModel" />
|
||||
@ -48,38 +49,119 @@
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
<!-- HEADER -->
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
tools:text="TERMINAL CONFIGURATION"
|
||||
android:gravity="center"
|
||||
android:text="TERMINAL CONFIGURATION"
|
||||
/>
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
tools:text="Merchant Name"
|
||||
android:text='@{viewModel.merchantName}'
|
||||
/>
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
tools:text="Phone"
|
||||
android:text='@{viewModel.merchantPhone}'
|
||||
/>
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
tools:text="Address1"
|
||||
android:text="@{viewModel.merchantAddress1}"
|
||||
/>
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
tools:text="Address2"
|
||||
android:text="@{viewModel.merchantAddress2}"
|
||||
/>
|
||||
android:gravity="center"
|
||||
android:textStyle="bold"
|
||||
android:textSize="18sp"
|
||||
android:paddingBottom="12dp"/>
|
||||
|
||||
<!-- Merchant Info -->
|
||||
<TextView android:layout_width="match_parent" android:layout_height="wrap_content"
|
||||
android:text="@{viewModel.merchantName}" />
|
||||
|
||||
<TextView android:layout_width="match_parent" android:layout_height="wrap_content"
|
||||
android:text="@{viewModel.merchantPhone}" />
|
||||
|
||||
<TextView android:layout_width="match_parent" android:layout_height="wrap_content"
|
||||
android:text="@{viewModel.merchantAddress1}" />
|
||||
|
||||
<TextView android:layout_width="match_parent" android:layout_height="wrap_content"
|
||||
android:text="@{viewModel.merchantAddress2}" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="--------------------------------"
|
||||
android:paddingTop="8dp"
|
||||
android:paddingBottom="8dp"/>
|
||||
|
||||
<!-- PRIMARY HOST -->
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="PRIMARY HOST"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView android:layout_width="match_parent" android:layout_height="wrap_content"
|
||||
android:text='@{"Name : " + viewModel.hostName}' />
|
||||
|
||||
<TextView android:layout_width="match_parent" android:layout_height="wrap_content"
|
||||
android:text='@{"TID : " + viewModel.tid}' />
|
||||
|
||||
<TextView android:layout_width="match_parent" android:layout_height="wrap_content"
|
||||
android:text='@{"MID : " + viewModel.mid}' />
|
||||
|
||||
<TextView android:layout_width="match_parent" android:layout_height="wrap_content"
|
||||
android:text='@{"Primary Ip : " + viewModel.primaryIp}' />
|
||||
|
||||
<TextView android:layout_width="match_parent" android:layout_height="wrap_content"
|
||||
android:text='@{"Primary Port : " + viewModel.primaryPort}' />
|
||||
|
||||
<TextView android:layout_width="match_parent" android:layout_height="wrap_content"
|
||||
android:text='@{"Secondary Ip : " + viewModel.secondaryIp}' />
|
||||
|
||||
<TextView android:layout_width="match_parent" android:layout_height="wrap_content"
|
||||
android:text='@{"Secondary Port : " + viewModel.secondaryPort}' />
|
||||
|
||||
<TextView android:layout_width="match_parent" android:layout_height="wrap_content"
|
||||
android:text='@{"Currency Code : " + viewModel.currencyCode}' />
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="--------------------------------"
|
||||
android:paddingTop="8dp"
|
||||
android:paddingBottom="8dp"/>
|
||||
|
||||
<!-- SECONDARY HOST (only if exists) -->
|
||||
<LinearLayout
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:visibility='@{!viewModel.secHostName.isEmpty() ? View.VISIBLE : View.GONE}'>
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="SECONDARY HOST"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView android:layout_width="match_parent" android:layout_height="wrap_content"
|
||||
android:text='@{"Name : " + viewModel.secHostName}' />
|
||||
|
||||
<TextView android:layout_width="match_parent" android:layout_height="wrap_content"
|
||||
android:text='@{"TID : " + viewModel.secHostTid}' />
|
||||
|
||||
<TextView android:layout_width="match_parent" android:layout_height="wrap_content"
|
||||
android:text='@{"MID : " + viewModel.secHostMid}' />
|
||||
|
||||
<TextView android:layout_width="match_parent" android:layout_height="wrap_content"
|
||||
android:text='@{"Primary Ip : " + viewModel.secHostPrimaryIp}' />
|
||||
|
||||
<TextView android:layout_width="match_parent" android:layout_height="wrap_content"
|
||||
android:text='@{"Primary Port : " + viewModel.secHostPrimaryPort}' />
|
||||
|
||||
<TextView android:layout_width="match_parent" android:layout_height="wrap_content"
|
||||
android:text='@{"Secondary Ip : " + viewModel.secHostSecondaryIp}' />
|
||||
|
||||
<TextView android:layout_width="match_parent" android:layout_height="wrap_content"
|
||||
android:text='@{"Secondary Port : " + viewModel.secHostSecondaryPort}' />
|
||||
|
||||
<TextView android:layout_width="match_parent" android:layout_height="wrap_content"
|
||||
android:text='@{"Currency Code : " + viewModel.currencyCode}' />
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="--------------------------------"
|
||||
android:paddingTop="8dp"
|
||||
android:paddingBottom="8dp"/>
|
||||
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user