Commit 242c34f2 authored by jiangjiantao's avatar jiangjiantao

dev

parent c4e87076
......@@ -37,7 +37,6 @@ android {
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
// implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.1'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
......@@ -59,4 +58,5 @@ dependencies {
implementation 'com.alibaba:fastjson:1.2.8'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation files('libs/miya-print-1.0.22.aar')
}
\ No newline at end of file
......@@ -12,6 +12,7 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:name=".BaseApplication"
android:theme="@style/Theme.MiYaFastCashier">
<activity
......
package com.miya.fastcashier
import android.app.Application
import com.miya.print.PrinterManager
class BaseApplication : Application() {
override fun onCreate() {
super.onCreate()
PrinterManager.instance.init(this)
}
}
\ No newline at end of file
package com.miya.fastcashier.dialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.constraintlayout.widget.Group;
import com.miya.fastcashier.R;
import com.miya.fastcashier.utils.ScanGunKeyEventHelper;
public class CodeScanDialog extends Dialog implements DialogInterface.OnDismissListener {
private final ScanGunKeyEventHelper scanGunKeyEventHelper;
private OnScanListener listener;
public CodeScanDialog(Context context) {
super(context);
initWindow();
setContentView(R.layout.dialog_code_scan);
setCanceledOnTouchOutside(false);
setOnDismissListener(this);
scanGunKeyEventHelper = new ScanGunKeyEventHelper();
scanGunKeyEventHelper.setOnBarCodeCatchListener(barcode -> {
if (listener != null) {
listener.onScan(barcode);
}
});
}
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
scanGunKeyEventHelper.analysisKeyEvent(event);
return true;
}
private void initWindow() {
Window win = this.getWindow();
win.getDecorView().setPadding(0, 0, 0, 0);
WindowManager.LayoutParams lp = win.getAttributes();
lp.width = WindowManager.LayoutParams.MATCH_PARENT;
lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
lp.gravity = Gravity.BOTTOM;
lp.windowAnimations = R.style.BottomInAndOutStyle;
win.setAttributes(lp);
win.setBackgroundDrawableResource(android.R.color.transparent);
}
public void setOnScanListener(OnScanListener listener) {
this.listener = listener;
}
@Override
public void onDismiss(DialogInterface dialogInterface) {
if (scanGunKeyEventHelper != null) {
scanGunKeyEventHelper.onDestroy();
}
}
public interface OnScanListener {
void onScan(String result);
}
}
......@@ -12,7 +12,7 @@ import java.util.HashMap
/**
* 提供支付、退款的功能
*/
class PayRepository {
object PayRepository {
/**
* 支付功能
......
package com.miya.fastcashier.service
import com.miya.fastcashier.beans.SelfCashierAccountInfo
import com.sdy.miya.moblie.component.pay.platform.bean.MiyaOrderRefundResponse
object AccountService{
private var selfCashierAccountInfo : SelfCashierAccountInfo? = null;
fun setAccountInfo(selfCashierAccountInfo : SelfCashierAccountInfo){
this.selfCashierAccountInfo = selfCashierAccountInfo
}
fun getAccountInfo(): SelfCashierAccountInfo? {
return selfCashierAccountInfo;
}
}
\ No newline at end of file
package com.miya.fastcashier.service
import com.miya.fastcashier.beans.SelfCashierAccountInfo
import com.sdy.miya.moblie.component.pay.platform.bean.MiyaOrderRefundResponse
import com.sdy.miya.moblie.component.pay.platform.bean.PayServiceResponse
object PrintService{
/**
* 退款
*/
fun refundPrint(selfCashierAccountInfo: SelfCashierAccountInfo,payServiceResponse: PayServiceResponse){
if(true){
throw RuntimeException("退款异常");
}
}
}
\ No newline at end of file
......@@ -4,22 +4,15 @@ import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.lifecycle.ViewModelProvider
import com.miya.fastcashier.R
import com.miya.fastcashier.dialog.CodeScanDialog
import com.miya.fastcashier.viewmodel.PayViewModel
import com.miya.fastcashier.viewmodel.MainViewModel
class MainActivity : AppCompatActivity() {
private lateinit var viewModel: PayViewModel
private lateinit var scanDialog: CodeScanDialog
private lateinit var viewModel: MainViewModel
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
viewModel = ViewModelProvider(this).get(PayViewModel::class.java)
scanDialog = CodeScanDialog(this);
scanDialog.setOnScanListener {
viewModel.
}
viewModel = ViewModelProvider(this).get(MainViewModel::class.java)
}
}
\ No newline at end of file
package com.miya.fastcashier.viewmodel
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.miya.fastcashier.beans.LoginRequest
import com.miya.fastcashier.beans.SelfCashierAccountInfo
import com.miya.fastcashier.repository.PayRepository
import com.miya.fastcashier.service.AccountService
import com.miya.fastcashier.service.LoginService
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import com.miya.fastcashier.service.PrintService
import com.sdy.miya.moblie.component.pay.platform.bean.MiyaOrderRefundResponse
import kotlinx.coroutines.*
class PayViewModel : ViewModel() {
fun refund(userName:String,passWord:String) {
viewModelScope.launch {
val refundResult = async(Dispatchers.IO) {
booksRepository.getAllBooks()
}
class MainViewModel : ViewModel() {
refundResult,
val refundLiveData: MutableLiveData<Result<PayRepository>> = MutableLiveData()
/**
* oriOrderNo 原订单号
* refundOrderNo 退款订单号
* refundPrice 退款金额
*/
fun refund(oriOrderNo: String, refundOrderNo: String, refundPrice: String) = runBlocking {
val refundParams = HashMap<String, String>()
refundParams["oriOrderNo"] = oriOrderNo;
refundParams["refundOrderNo"] = refundOrderNo;
refundParams["refundPrice"] = refundPrice;
val refundResult = async(Dispatchers.IO) {
PayRepository.refundByOrderNo(refundParams)
}
}
val printResult = async(Dispatchers.IO) {
AccountService.getAccountInfo()
?.let { PrintService.refundPrint(it, refundResult.await()) }
}
printResult.await()
refundLiveData.value = Result.success()
}
}
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/tvRefund"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="请扫码退款"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.258" />
</androidx.constraintlayout.widget.ConstraintLayout>
\ 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