Commit 970ba942 authored by 赵鹏翔's avatar 赵鹏翔

系统参数弹窗相关 java code 2 kotlin

parent 20cf5615
package com.miya.fastcashier.log;
package com.miya.fastcashier.log
import java.io.File;
import java.util.Comparator;
import java.io.File
import java.util.Comparator
/**
* Created by Dimorinny on 24.10.15.
*/
public class FileComparator implements Comparator<File> {
@Override
public int compare(File f1, File f2) {
if(f1 == f2) {
return 0;
class FileComparator : Comparator<File> {
override fun compare(f1: File, f2: File): Int {
if (f1 === f2) {
return 0
}
if(f1.isDirectory() && f2.isFile()) {
if (f1.isDirectory && f2.isFile) {
// Show directories above files
return -1;
return -1
}
if(f1.isFile() && f2.isDirectory()) {
return if (f1.isFile && f2.isDirectory) {
// Show files below directories
return 1;
}
1
} else f1.name.compareTo(f2.name, ignoreCase = true)
// Sort the directories alphabetically
return f1.getName().compareToIgnoreCase(f2.getName());
}
}
}
\ No newline at end of file
package com.miya.fastcashier.log;
import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;
import com.miya.fastcashier.BuildConfig;
import com.miya.fastcashier.R;
import com.miya.fastcashier.beans.SelfCashierAccountInfo;
import com.miya.fastcashier.databinding.DialogSystemParameterBinding;
import com.miya.fastcashier.net.ApiConfig;
import com.miya.fastcashier.service.AccountService;
import com.miya.fastcashier.utils.BaseFunctionKt;
import com.miya.print.PrinterManager;
import androidx.annotation.NonNull;
public class SystemParameterDialog extends Dialog {
private DialogSystemParameterBinding viewBinding;
public SystemParameterDialog(@NonNull Context context) {
super(context, R.style.CommonDialog);
viewBinding = DialogSystemParameterBinding.inflate(getLayoutInflater());
setContentView(viewBinding.getRoot());
setCanceledOnTouchOutside(false);
setCancelable(true);
init();
}
private void init() {
SelfCashierAccountInfo accountInfo = AccountService.INSTANCE.getAccountInfo();
setInfo(viewBinding.tvVersion, BaseFunctionKt.getVersion(getContext()));
setInfo(viewBinding.tvStoreName, accountInfo.getShopInfo().getStoreName());
setInfo(viewBinding.tvStoreNum, accountInfo.getShopInfo().getStoreId());
setInfo(viewBinding.tvMerchantNum, accountInfo.getShopInfo().getHhMerchant());
setInfo(viewBinding.tvPos, accountInfo.getShopInfo().getPosId());
setInfo(viewBinding.tvCashier, accountInfo.getShopInfo().getOperatorId());
setInfo(viewBinding.tvVersionType, "fastCashier_" + BuildConfig.appType);
setInfo(viewBinding.tvEquipment, "sunmi_v2pro");
setInfo(viewBinding.tvServerUrl, ApiConfig.getBaseUrl());
setInfo(viewBinding.tvWifiName, BaseFunctionKt.getWifyName(getContext()));
setInfo(viewBinding.tvNetIp, BaseFunctionKt.getNetIp(getContext()) == null ? "未知" : BaseFunctionKt.getNetIp(getContext()));
setInfo(viewBinding.tvPrintType, PrinterManager.getInstance().getPrinter() == null ?
getContext().getResources().getString(R.string.app_unkown) :
PrinterManager.getInstance().getPrinter().getPrinterName());
setInfo(viewBinding.tvChannel, BuildConfig.CHANNEL);
viewBinding.ivClose.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
dismiss();
}
});
resize();
}
private void setInfo(View view, String info) {
((TextView) view).setText(info);
}
/**
* 设置对话框大小
*
* @param width 宽度,传0表示走默认宽度
* @param height 高度,传0表示走默认高度
*/
public SystemParameterDialog setSize(int width, int height) {
if (width < 0 || height < 0) {
return this;
}
WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
if (width != 0 && height != 0) {
layoutParams.width = width;
layoutParams.height = height;
} else if (width == 0 && height != 0) {
layoutParams.height = height;
} else if (width != 0 && height == 0) {
layoutParams.width = width;
}
getWindow().setGravity(Gravity.CENTER);
getWindow().setAttributes(layoutParams);
return this;
}
private void resize() {
this.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.MATCH_PARENT);
}
}
\ No newline at end of file
package com.miya.fastcashier.log
import android.app.Dialog
import android.content.Context
import com.miya.fastcashier.service.AccountService.getAccountInfo
import com.miya.fastcashier.utils.getVersion
import com.miya.fastcashier.net.ApiConfig.baseUrl
import com.miya.fastcashier.utils.getWifyName
import com.miya.fastcashier.utils.getNetIp
import com.miya.fastcashier.R
import com.miya.fastcashier.beans.SelfCashierAccountInfo
import com.miya.fastcashier.service.AccountService
import com.miya.fastcashier.net.ApiConfig
import com.miya.print.PrinterManager
import android.widget.TextView
import com.miya.fastcashier.log.SystemParameterDialog
import android.view.WindowManager
import android.view.Gravity
import android.view.View
import com.miya.fastcashier.BuildConfig
import com.miya.fastcashier.databinding.DialogSystemParameterBinding
class SystemParameterDialog(context: Context) : Dialog(context, R.style.CommonDialog) {
private val viewBinding: DialogSystemParameterBinding
init {
viewBinding = DialogSystemParameterBinding.inflate(
layoutInflater
)
setContentView(viewBinding.root)
setCanceledOnTouchOutside(false)
setCancelable(true)
init()
}
private fun init() {
val accountInfo = getAccountInfo()
setInfo(viewBinding.tvVersion, getVersion(context))
setInfo(viewBinding.tvStoreName, accountInfo!!.shopInfo.storeName)
setInfo(viewBinding.tvStoreNum, accountInfo.shopInfo.storeId)
setInfo(viewBinding.tvMerchantNum, accountInfo.shopInfo.hhMerchant)
setInfo(viewBinding.tvPos, accountInfo.shopInfo.posId)
setInfo(viewBinding.tvCashier, accountInfo.shopInfo.operatorId)
setInfo(viewBinding.tvVersionType, "fastCashier_" + BuildConfig.appType)
setInfo(viewBinding.tvEquipment, "sunmi_v2pro")
setInfo(viewBinding.tvServerUrl, baseUrl)
setInfo(viewBinding.tvWifiName, getWifyName(context))
setInfo(viewBinding.tvNetIp, if (getNetIp(context) == null) "未知" else getNetIp(context))
setInfo(
viewBinding.tvPrintType,
if (PrinterManager.getInstance().printer == null) context.resources.getString(R.string.app_unkown) else PrinterManager.getInstance().printer.printerName
)
setInfo(viewBinding.tvChannel, BuildConfig.CHANNEL)
viewBinding.ivClose.setOnClickListener(View.OnClickListener { dismiss() })
resize()
}
private fun setInfo(view: View, info: String?) {
(view as TextView).text = info
}
/**
* 设置对话框大小
*
* @param width 宽度,传0表示走默认宽度
* @param height 高度,传0表示走默认高度
*/
fun setSize(width: Int, height: Int): SystemParameterDialog {
if (width < 0 || height < 0) {
return this
}
val layoutParams = window!!.attributes
if (width != 0 && height != 0) {
layoutParams.width = width
layoutParams.height = height
} else if (width == 0 && height != 0) {
layoutParams.height = height
} else if (width != 0 && height == 0) {
layoutParams.width = width
}
window!!.setGravity(Gravity.CENTER)
window!!.attributes = layoutParams
return this
}
private fun resize() {
this.window!!.setLayout(
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.MATCH_PARENT
)
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment