Commit 480f0737 by 王宇航

打印,结账

parent 92720ce0
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
package com.jess.arms.http.log; package com.jess.arms.http.log;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log;
import com.jess.arms.di.module.GlobalConfigModule; import com.jess.arms.di.module.GlobalConfigModule;
import com.jess.arms.utils.CharacterHandler; import com.jess.arms.utils.CharacterHandler;
...@@ -172,6 +173,7 @@ public class DefaultFormatPrinter implements FormatPrinter { ...@@ -172,6 +173,7 @@ public class DefaultFormatPrinter implements FormatPrinter {
int end = (i + 1) * MAX_LONG_SIZE; int end = (i + 1) * MAX_LONG_SIZE;
end = end > line.length() ? line.length() : end; end = end > line.length() ? line.length() : end;
Timber.tag(tag).i(DEFAULT_LINE + line.substring(start, end)); Timber.tag(tag).i(DEFAULT_LINE + line.substring(start, end));
Log.e("aaa", "" + DEFAULT_LINE + line.substring(start, end));
} }
} }
} }
......
...@@ -115,7 +115,8 @@ ext { ...@@ -115,7 +115,8 @@ ext {
"arms" : "me.jessyan:arms:2.5.2", "arms" : "me.jessyan:arms:2.5.2",
"fastjson" : "com.alibaba:fastjson:1.2.46", "fastjson" : "com.alibaba:fastjson:1.2.46",
"zxing" : "cn.yipianfengye.android:zxing-library:2.2", "zxing" : "cn.yipianfengye.android:zxing-library:2.2",
"BaseRecyclerViewAdapter" : "com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.46" "BaseRecyclerViewAdapter" : "com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.46",
"yzjRecyclerView" : "com.yanzhenjie.recyclerview:x:1.3.2"
] ]
} }
ext.alwaysLib = true //虽然apply了cc-settings-2.gradle,但一直作为library编译,否则别的组件依赖此module时会报错
apply from: rootProject.file('cc-settings.gradle')
android {
compileSdkVersion rootProject.ext.android["compileSdkVersion"]
buildToolsVersion rootProject.ext.android["buildToolsVersion"]
defaultConfig {
minSdkVersion rootProject.ext.android["minSdkVersion"]
targetSdkVersion rootProject.ext.android["targetSdkVersion"]
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
<manifest package="com.billy.cc.demo.interceptors" />
package com.billy.cc.demo.interceptors;
import android.util.Log;
import com.billy.cc.core.component.CCResult;
import com.billy.cc.core.component.Chain;
import com.billy.cc.core.component.IGlobalCCInterceptor;
/**
* 示例全局拦截器:日志打印
* @author billy.qi
* @since 18/5/26 11:42
*/
public class LogInterceptor implements IGlobalCCInterceptor {
private static final String TAG = "LogInterceptor";
@Override
public int priority() {
return 1;
}
@Override
public CCResult intercept(Chain chain) {
Log.i(TAG, "============log before:" + chain.getCC());
CCResult result = chain.proceed();
Log.i(TAG, "============log after:" + result);
return result;
}
}
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
android:icon="@mipmap/ic_launcher" android:icon="@mipmap/ic_launcher"
android:label="@string/download_data_app_name" android:label="@string/download_data_app_name"
android:roundIcon="@mipmap/ic_launcher_round" android:roundIcon="@mipmap/ic_launcher_round"
android:networkSecurityConfig="@xml/network_android"
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/AppTheme"> android:theme="@style/AppTheme">
......
package debug; package debug;
import android.app.Application;
import com.billy.cc.core.component.CC; import com.billy.cc.core.component.CC;
import com.jess.arms.base.BaseApplication;
/** /**
* @author billy.qi * @author billy.qi
* @since 17/11/20 20:02 * @since 17/11/20 20:02
*/ */
public class MyApp extends Application { public class MyApp extends BaseApplication {
@Override @Override
public void onCreate() { public void onCreate() {
super.onCreate(); super.onCreate();
......
package debug.di.component;
import com.gingersoft.gsa.cloud.download.mvp.contract.DownloadContract;
import com.gingersoft.gsa.cloud.download.mvp.ui.activity.DownloadActivity;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.di.scope.ActivityScope;
import dagger.BindsInstance;
import dagger.Component;
import debug.di.module.DownloadModule;
/**
* ================================================
* Description:
* <p>
* Created by MVPArmsTemplate on 12/26/2019 17:59
* <a href="mailto:jess.yan.effort@gmail.com">Contact me</a>
* <a href="https://github.com/JessYanCoding">Follow me</a>
* <a href="https://github.com/JessYanCoding/MVPArms">Star me</a>
* <a href="https://github.com/JessYanCoding/MVPArms/wiki">See me</a>
* <a href="https://github.com/JessYanCoding/MVPArmsTemplate">模版请保持更新</a>
* ================================================
*/
@ActivityScope
@Component(modules = DownloadModule.class, dependencies = AppComponent.class)
public interface DownloadComponent {
void inject(DownloadActivity activity);
@Component.Builder
interface Builder {
@BindsInstance
DownloadComponent.Builder view(DownloadContract.View view);
DownloadComponent.Builder appComponent(AppComponent appComponent);
DownloadComponent build();
}
}
\ No newline at end of file
package debug.di.module;
import com.gingersoft.gsa.cloud.download.mvp.contract.DownloadContract;
import com.gingersoft.gsa.cloud.download.mvp.model.DownloadModel;
import dagger.Binds;
import dagger.Module;
/**
* ================================================
* Description:
* <p>
* Created by MVPArmsTemplate on 12/26/2019 17:59
* <a href="mailto:jess.yan.effort@gmail.com">Contact me</a>
* <a href="https://github.com/JessYanCoding">Follow me</a>
* <a href="https://github.com/JessYanCoding/MVPArms">Star me</a>
* <a href="https://github.com/JessYanCoding/MVPArms/wiki">See me</a>
* <a href="https://github.com/JessYanCoding/MVPArmsTemplate">模版请保持更新</a>
* ================================================
*/
@Module
public abstract class DownloadModule {
@Binds
abstract DownloadContract.Model bindDownloadModel(DownloadModel model);
}
\ No newline at end of file
...@@ -2,7 +2,7 @@ package com.gingersoft.gsa.cloud.download.mvp.contract; ...@@ -2,7 +2,7 @@ package com.gingersoft.gsa.cloud.download.mvp.contract;
import android.content.Context; import android.content.Context;
import com.gingersoft.gsa.cloud.base.bean.FoodBean; import com.gingersoft.gsa.cloud.base.common.bean.FoodBean;
import com.gingersoft.gsa.cloud.database.bean.Food; import com.gingersoft.gsa.cloud.database.bean.Food;
import com.gingersoft.gsa.cloud.download.mvp.model.bean.FunctionBean; import com.gingersoft.gsa.cloud.download.mvp.model.bean.FunctionBean;
import com.jess.arms.base.DefaultAdapter; import com.jess.arms.base.DefaultAdapter;
......
...@@ -3,7 +3,7 @@ package com.gingersoft.gsa.cloud.download.mvp.model; ...@@ -3,7 +3,7 @@ package com.gingersoft.gsa.cloud.download.mvp.model;
import android.app.Application; import android.app.Application;
import android.content.Context; import android.content.Context;
import com.gingersoft.gsa.cloud.base.bean.FoodBean; import com.gingersoft.gsa.cloud.base.common.bean.FoodBean;
import com.gingersoft.gsa.cloud.database.bean.Food; import com.gingersoft.gsa.cloud.database.bean.Food;
import com.gingersoft.gsa.cloud.database.utils.FoodDaoUtils; import com.gingersoft.gsa.cloud.database.utils.FoodDaoUtils;
import com.gingersoft.gsa.cloud.download.mvp.model.bean.FunctionBean; import com.gingersoft.gsa.cloud.download.mvp.model.bean.FunctionBean;
......
package com.gingersoft.gsa.cloud.download.mvp.model.service; package com.gingersoft.gsa.cloud.download.mvp.model.service;
import com.gingersoft.gsa.cloud.base.bean.FoodBean; import com.gingersoft.gsa.cloud.base.common.bean.FoodBean;
import com.gingersoft.gsa.cloud.download.mvp.model.bean.FunctionBean; import com.gingersoft.gsa.cloud.download.mvp.model.bean.FunctionBean;
import io.reactivex.Observable; import io.reactivex.Observable;
......
...@@ -4,7 +4,7 @@ import android.app.Application; ...@@ -4,7 +4,7 @@ import android.app.Application;
import com.billy.cc.core.component.CC; import com.billy.cc.core.component.CC;
import com.gingersoft.gsa.cloud.base.Api; import com.gingersoft.gsa.cloud.base.Api;
import com.gingersoft.gsa.cloud.base.bean.FoodBean; import com.gingersoft.gsa.cloud.base.common.bean.FoodBean;
import com.gingersoft.gsa.cloud.base.utils.constans.HttpsConstans; import com.gingersoft.gsa.cloud.base.utils.constans.HttpsConstans;
import com.gingersoft.gsa.cloud.database.bean.Food; import com.gingersoft.gsa.cloud.database.bean.Food;
import com.gingersoft.gsa.cloud.database.utils.FoodDaoUtils; import com.gingersoft.gsa.cloud.database.utils.FoodDaoUtils;
...@@ -31,8 +31,6 @@ import com.gingersoft.gsa.cloud.download.mvp.contract.DownloadContract; ...@@ -31,8 +31,6 @@ import com.gingersoft.gsa.cloud.download.mvp.contract.DownloadContract;
import com.jess.arms.utils.DeviceUtils; import com.jess.arms.utils.DeviceUtils;
import com.jess.arms.utils.RxLifecycleUtils; import com.jess.arms.utils.RxLifecycleUtils;
import org.simple.eventbus.EventBus;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
...@@ -114,7 +112,6 @@ public class DownloadPresenter extends BasePresenter<DownloadContract.Model, Dow ...@@ -114,7 +112,6 @@ public class DownloadPresenter extends BasePresenter<DownloadContract.Model, Dow
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.compose(RxLifecycleUtils.bindToLifecycle(mRootView)) .compose(RxLifecycleUtils.bindToLifecycle(mRootView))
.subscribe(new ErrorHandleSubscriber<Object>(mErrorHandler) { .subscribe(new ErrorHandleSubscriber<Object>(mErrorHandler) {
@Override @Override
public void onSubscribe(Disposable d) { public void onSubscribe(Disposable d) {
//订阅前先清空正在执行的订阅 //订阅前先清空正在执行的订阅
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
android:allowBackup="true" android:allowBackup="true"
android:icon="@mipmap/ic_launcher" android:icon="@mipmap/ic_launcher"
android:label="@string/app_name" android:label="@string/app_name"
android:networkSecurityConfig="@xml/network_android"
android:roundIcon="@mipmap/ic_launcher_round" android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/AppTheme"> android:theme="@style/AppTheme">
......
...@@ -104,8 +104,6 @@ public class MainActivity extends BaseFragmentActivity<MainPresenter> implements ...@@ -104,8 +104,6 @@ public class MainActivity extends BaseFragmentActivity<MainPresenter> implements
}; };
mViewPager.setAdapter(pagerAdapter); mViewPager.setAdapter(pagerAdapter);
mTabSegment.setupWithViewPager(mViewPager, false); mTabSegment.setupWithViewPager(mViewPager, false);
} }
private void initTabs() { private void initTabs() {
......
...@@ -50,7 +50,7 @@ public class HomeFunctionAdapter extends QMUIDefaultStickySectionAdapter<Section ...@@ -50,7 +50,7 @@ public class HomeFunctionAdapter extends QMUIDefaultStickySectionAdapter<Section
viewHolder.tvFun.setText(section.getItemAt(itemIndex).getText()); viewHolder.tvFun.setText(section.getItemAt(itemIndex).getText());
} }
class ViewHolder extends QMUIStickySectionAdapter.ViewHolder { public class ViewHolder extends QMUIStickySectionAdapter.ViewHolder {
@BindView(R2.id.iv_main_home_item_function_icon) @BindView(R2.id.iv_main_home_item_function_icon)
ImageView ivFun;//功能圖標 ImageView ivFun;//功能圖標
@BindView(R2.id.tv_main_home_item_function_name) @BindView(R2.id.tv_main_home_item_function_name)
...@@ -59,5 +59,9 @@ public class HomeFunctionAdapter extends QMUIDefaultStickySectionAdapter<Section ...@@ -59,5 +59,9 @@ public class HomeFunctionAdapter extends QMUIDefaultStickySectionAdapter<Section
super(itemView); super(itemView);
ButterKnife.bind(this, itemView); ButterKnife.bind(this, itemView);
} }
public TextView getTvFun() {
return tvFun;
}
} }
} }
...@@ -4,6 +4,7 @@ import android.content.Intent; ...@@ -4,6 +4,7 @@ import android.content.Intent;
import android.media.Image; import android.media.Image;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log; import android.util.Log;
import android.util.SparseArray;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
...@@ -12,6 +13,7 @@ import android.widget.ImageView; ...@@ -12,6 +13,7 @@ import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import com.billy.cc.core.component.CC; import com.billy.cc.core.component.CC;
import com.gingersoft.gsa.cloud.base.application.GsaCloudApplication;
import com.gingersoft.gsa.cloud.base.utils.time.TimeUtils; import com.gingersoft.gsa.cloud.base.utils.time.TimeUtils;
import com.gingersoft.gsa.cloud.main.R; import com.gingersoft.gsa.cloud.main.R;
import com.gingersoft.gsa.cloud.main.R2; import com.gingersoft.gsa.cloud.main.R2;
...@@ -32,7 +34,9 @@ import com.qmuiteam.qmui.widget.section.QMUIStickySectionLayout; ...@@ -32,7 +34,9 @@ import com.qmuiteam.qmui.widget.section.QMUIStickySectionLayout;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
...@@ -78,13 +82,10 @@ public class HomeFragment extends BaseFragment<HomePresenter> implements HomeCon ...@@ -78,13 +82,10 @@ public class HomeFragment extends BaseFragment<HomePresenter> implements HomeCon
private RecyclerView.LayoutManager mLayoutManager; private RecyclerView.LayoutManager mLayoutManager;
private HomeFunctionAdapter mAdapter; private HomeFunctionAdapter mAdapter;
private String[] title = new String[]{"點餐", "管理", "員工"};
private String[] functionTitles = { private Map<String, String[]> function = new HashMap<>();
"餐檯模式", "外送模式", "外賣模式", "預點餐模式", private ArrayList<QMUISection<SectionHeader, SectionItem>> list;
"快速收款", "餐牌管理", "選項管理", "餐桌管理",
"時段管理", "支付管理", "折扣管理", "員工管理",
"權限管理", "操作記錄"
};
public static HomeFragment newInstance() { public static HomeFragment newInstance() {
HomeFragment fragment = new HomeFragment(); HomeFragment fragment = new HomeFragment();
...@@ -108,7 +109,7 @@ public class HomeFragment extends BaseFragment<HomePresenter> implements HomeCon ...@@ -108,7 +109,7 @@ public class HomeFragment extends BaseFragment<HomePresenter> implements HomeCon
@Override @Override
public void initData(@Nullable Bundle savedInstanceState) { public void initData(@Nullable Bundle savedInstanceState) {
mPresenter.getRestaurantReport("26"); mPresenter.getRestaurantReport(GsaCloudApplication.getRestaurantId(mContext) + "");
// mPresenter.getRestaurantFunList("26"); // mPresenter.getRestaurantFunList("26");
initTopBar(); initTopBar();
initStickyLayout(); initStickyLayout();
...@@ -147,13 +148,26 @@ public class HomeFragment extends BaseFragment<HomePresenter> implements HomeCon ...@@ -147,13 +148,26 @@ public class HomeFragment extends BaseFragment<HomePresenter> implements HomeCon
@Override @Override
public void onItemClick(QMUIStickySectionAdapter.ViewHolder holder, int position) { public void onItemClick(QMUIStickySectionAdapter.ViewHolder holder, int position) {
switch (position) { if (holder instanceof HomeFunctionAdapter.ViewHolder) {
case 1: HomeFunctionAdapter.ViewHolder viewHolder = (HomeFunctionAdapter.ViewHolder) holder;
CC.obtainBuilder("Component.Table") if (viewHolder.getTvFun().getText() != null) {
.setActionName("showTableActivity") switch (viewHolder.getTvFun().getText().toString()) {
.build() case "餐檯模式":
.call(); CC.obtainBuilder("Component.Table")
break; .setActionName("showTableActivity")
.build()
.call();
break;
case "打印管理":
CC.obtainBuilder("Component.Print")
.setActionName("showPrintActivity")
.build()
.call();
break;
}
}
} else {
//點擊的頭部,折疊
} }
} }
...@@ -162,26 +176,30 @@ public class HomeFragment extends BaseFragment<HomePresenter> implements HomeCon ...@@ -162,26 +176,30 @@ public class HomeFragment extends BaseFragment<HomePresenter> implements HomeCon
return false; return false;
} }
}); });
String[] title = new String[]{"點餐", "管理", "員工"}; function.put(title[0], new String[]{"餐檯模式", "外送模式", "外賣模式", "預點餐模式", "快速收款"});
function.put(title[1], new String[]{"餐牌管理", "選項管理", "餐桌管理", "打印管理", "時段管理", "支付管理", "折扣管理", "員工管理"});
function.put(title[2], new String[]{"權限管理", "操作記錄"});
mSectionLayout.setAdapter(mAdapter, true); mSectionLayout.setAdapter(mAdapter, true);
ArrayList<QMUISection<SectionHeader, SectionItem>> list = new ArrayList<>(); list = new ArrayList<>();
for (String s : title) {
list.add(createSection(s)); for (int i = 0; i < function.size(); i++) {
list.add(createSection(title[i]));
} }
mAdapter.setData(list); mAdapter.setData(list);
} }
private QMUISection<SectionHeader, SectionItem> createSection(String headerText) { private QMUISection<SectionHeader, SectionItem> createSection(String title) {
SectionHeader header = new SectionHeader(headerText); SectionHeader header = new SectionHeader(title);
ArrayList<SectionItem> contents = new ArrayList<>(); ArrayList<SectionItem> contents = new ArrayList<>();
for (int i = 0; i < 5; i++) { for (int i = 0; i < Objects.requireNonNull(function.get(title)).length; i++) {
contents.add(new SectionItem(R.drawable.ic_dining_table, functionTitles[i])); contents.add(new SectionItem(R.drawable.ic_dining_table, Objects.requireNonNull(function.get(title))[i]));
} }
QMUISection<SectionHeader, SectionItem> section = new QMUISection<>(header, contents, false); // QMUISection<SectionHeader, SectionItem> section = new QMUISection<>(header, contents, false);
// if test load more, you can open the code // if test load more, you can open the code
// section.setExistAfterDataToLoad(true); // section.setExistAfterDataToLoad(true);
// section.setExistBeforeDataToLoad(true); // section.setExistBeforeDataToLoad(true);
return section; return new QMUISection<>(header, contents, false);
} }
private RecyclerView.LayoutManager createLayoutManager() { private RecyclerView.LayoutManager createLayoutManager() {
......
apply from: rootProject.file('cc-settings.gradle')
apply plugin: 'com.jakewharton.butterknife'
android {
compileSdkVersion rootProject.ext.android["compileSdkVersion"]
compileOptions {
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_1_8
}
// 避免 lint 检测出错时停止构建
lintOptions {
abortOnError false
}
defaultConfig {
if (project.ext.runAsApp) {
applicationId "com.gingersoft.gsa.cloud.mealstand"
}
minSdkVersion rootProject.ext.android["minSdkVersion"]
targetSdkVersion rootProject.ext.android["targetSdkVersion"]
versionCode rootProject.ext.android["versionCode"]
versionName rootProject.ext.android["versionName"]
javaCompileOptions {
annotationProcessorOptions {
arguments = [AROUTER_MODULE_NAME: project.getName()]
includeCompileClasspath true
}
}
}
resourcePrefix "meal"
buildTypes {
release {
postprocessing {
removeUnusedCode false
removeUnusedResources false
obfuscate false
optimizeCode false
proguardFiles 'proguard.cfg'
}
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
// if (project.ext.runAsApp) {
annotationProcessor rootProject.ext.dependencies["dagger2-compiler"]
debugImplementation rootProject.ext.dependencies["canary-debug"]
releaseImplementation rootProject.ext.dependencies["canary-release"]
testImplementation rootProject.ext.dependencies["canary-release"]
// }else {
// compileOnly rootProject.ext.dependencies["dagger2-compiler"]
// compileOnly rootProject.ext.dependencies["canary-debug"]
// compileOnly rootProject.ext.dependencies["canary-release"]
// compileOnly rootProject.ext.dependencies["canary-release"]
// }
// test
testImplementation rootProject.ext.dependencies["junit"]
// debugImplementation rootProject.ext.dependencies["canary-debug"]
// releaseImplementation rootProject.ext.dependencies["canary-release"]
// testImplementation rootProject.ext.dependencies["canary-release"]
}
package com.gingersoft.cloud.gsa;
import android.content.Context;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.*;
/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
assertEquals("com.gingersoft.cloud.gsa", appContext.getPackageName());
}
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.gingersoft.gsa.cloud.meal">
<application>
<activity android:name=".mvp.ui.activity.MealStandActivity"/>
<activity android:name=".mvp.ui.activity.OrderPayActivity"/>
<activity android:name=".mvp.ui.activity.OrderContentActivity" />
</application>
</manifest>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.gingersoft.gsa.cloud.meal">
<application
android:name="com.gingersoft.gsa.cloud.base.application.GsaCloudApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/meal_app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".mvp.ui.activity.OrderPayActivity"></activity>
<activity android:name=".mvp.ui.activity.OrderContentActivity" />
<activity
android:name=".mvp.ui.activity.MealStandActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden|adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="network.config.GlobalConfiguration"
android:value="ConfigModule" />
<meta-data
android:name="design_width_in_dp"
android:value="360" />
<meta-data
android:name="design_height_in_dp"
android:value="540" />
</application>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECEIVE_USER_PRESENT" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
</manifest>
\ No newline at end of file
package debug;
import android.app.Application;
import com.billy.cc.core.component.CC;
/**
* @author billy.qi
* @since 17/11/20 20:02
*/
public class MyApp extends Application {
@Override
public void onCreate() {
super.onCreate();
CC.enableVerboseLog(true);
CC.enableDebug(true);
CC.enableRemoteCC(true);
}
}
package com.gingersoft.gsa.cloud.meal;
import com.billy.cc.core.component.CC;
import com.billy.cc.core.component.CCResult;
import com.billy.cc.core.component.CCUtil;
import com.billy.cc.core.component.IComponent;
import com.gingersoft.gsa.cloud.base.mealManage.MyOrderManage;
import com.gingersoft.gsa.cloud.meal.mvp.ui.activity.MealStandActivity;
public class ComponentMealStand implements IComponent {
@Override
public String getName() {
//组件的名称,调用此组件的方式:
// CC.obtainBuilder("ComponentA")...build().callAsync()
return "Component.Meal";
}
/**
* 组件被调用时的入口
* 要确保每个逻辑分支都会调用到CC.sendCCResult,
* 包括try-catch,if-else,switch-case-default,startActivity
*
* @param cc 组件调用对象,可从此对象中获取相关信息
* @return true:将异步调用CC.sendCCResult(...),用于异步实现相关功能,例如:文件加载、网络请求等
* false:会同步调用CC.sendCCResult(...),即在onCall方法return之前调用,否则将被视为不合法的实现
*/
@Override
public boolean onCall(CC cc) {
String actionName = cc.getActionName();
switch (actionName) {
case "showMealStandActivity":
openActivity(cc);
break;
case "clearOrderList":
clearOrderList(cc);
break;
case "getLifecycleFragment":
//demo for provide fragment object to other component
getLifecycleFragment(cc);
break;
case "lifecycleFragment.addText":
lifecycleFragmentDoubleText(cc);
break;
case "getInfo":
getInfo(cc);
break;
default:
//这个逻辑分支上没有调用CC.sendCCResult(...),是一种错误的示例
//并且方法的返回值为false,代表不会异步调用CC.sendCCResult(...)
//在LocalCCInterceptor中将会返回错误码为-10的CCResult
break;
}
return false;
}
private void clearOrderList(CC cc) {
MyOrderManage.getInstance().clear();
}
private void lifecycleFragmentDoubleText(CC cc) {
// LifecycleFragment lifecycleFragment = cc.getParamItem("fragment");
// if (lifecycleFragment != null) {
// String text = cc.getParamItem("text", "");
// lifecycleFragment.addText(text);
// CC.sendCCResult(cc.getCallId(), CCResult.success());
// } else {
// CC.sendCCResult(cc.getCallId(), CCResult.error("no fragment params"));
// }
}
private void getLifecycleFragment(CC cc) {
// CC.sendCCResult(cc.getCallId(), CCResult.successWithNoKey(new LifecycleFragment()));
}
private void getInfo(CC cc) {
String userName = "billy";
CC.sendCCResult(cc.getCallId(), CCResult.success("userName", userName));
}
private void openActivity(CC cc) {
CCUtil.navigateTo(cc, MealStandActivity.class);
CC.sendCCResult(cc.getCallId(), CCResult.success());
}
}
package com.gingersoft.gsa.cloud.meal;
import com.billy.cc.core.component.CC;
import com.billy.cc.core.component.CCResult;
import com.billy.cc.core.component.CCUtil;
import com.billy.cc.core.component.IComponent;
import com.gingersoft.gsa.cloud.meal.mvp.ui.activity.MealStandActivity;
public class ComponentOrderContent implements IComponent {
@Override
public String getName() {
//组件的名称,调用此组件的方式:
// CC.obtainBuilder("ComponentA")...build().callAsync()
return "Component.OrderContent";
}
/**
* 组件被调用时的入口
* 要确保每个逻辑分支都会调用到CC.sendCCResult,
* 包括try-catch,if-else,switch-case-default,startActivity
*
* @param cc 组件调用对象,可从此对象中获取相关信息
* @return true:将异步调用CC.sendCCResult(...),用于异步实现相关功能,例如:文件加载、网络请求等
* false:会同步调用CC.sendCCResult(...),即在onCall方法return之前调用,否则将被视为不合法的实现
*/
@Override
public boolean onCall(CC cc) {
String actionName = cc.getActionName();
switch (actionName) {
case "showOrderContentActivity":
openActivity(cc);
break;
case "getLifecycleFragment":
//demo for provide fragment object to other component
getLifecycleFragment(cc);
break;
case "lifecycleFragment.addText":
lifecycleFragmentDoubleText(cc);
break;
case "getInfo":
getInfo(cc);
break;
default:
//这个逻辑分支上没有调用CC.sendCCResult(...),是一种错误的示例
//并且方法的返回值为false,代表不会异步调用CC.sendCCResult(...)
//在LocalCCInterceptor中将会返回错误码为-10的CCResult
break;
}
return false;
}
private void lifecycleFragmentDoubleText(CC cc) {
// LifecycleFragment lifecycleFragment = cc.getParamItem("fragment");
// if (lifecycleFragment != null) {
// String text = cc.getParamItem("text", "");
// lifecycleFragment.addText(text);
// CC.sendCCResult(cc.getCallId(), CCResult.success());
// } else {
// CC.sendCCResult(cc.getCallId(), CCResult.error("no fragment params"));
// }
}
private void getLifecycleFragment(CC cc) {
// CC.sendCCResult(cc.getCallId(), CCResult.successWithNoKey(new LifecycleFragment()));
}
private void getInfo(CC cc) {
String userName = "billy";
CC.sendCCResult(cc.getCallId(), CCResult.success("userName", userName));
}
private void openActivity(CC cc) {
CCUtil.navigateTo(cc, MealStandActivity.class);
CC.sendCCResult(cc.getCallId(), CCResult.success());
}
}
package com.gingersoft.gsa.cloud.meal.app;
/**
* 作者:ELEGANT_BIN
* 版本:1.6.0
* 创建日期:2020-01-08
* 修订历史:2020-01-08
* 描述:
*/
public interface GoldConstants {
int DetailColCount = 5;
}
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt"
android:width="108dp"
android:height="108dp"
android:viewportHeight="108"
android:viewportWidth="108">
<path
android:fillType="evenOdd"
android:pathData="M32,64C32,64 38.39,52.99 44.13,50.95C51.37,48.37 70.14,49.57 70.14,49.57L108.26,87.69L108,109.01L75.97,107.97L32,64Z"
android:strokeColor="#00000000"
android:strokeWidth="1">
<aapt:attr name="android:fillColor">
<gradient
android:endX="78.5885"
android:endY="90.9159"
android:startX="48.7653"
android:startY="61.0927"
android:type="linear">
<item
android:color="#44000000"
android:offset="0.0" />
<item
android:color="#00000000"
android:offset="1.0" />
</gradient>
</aapt:attr>
</path>
<path
android:fillColor="#FFFFFF"
android:fillType="nonZero"
android:pathData="M6.94,46.02L66.94,46.02C72.44,50.07 76,56.61 76,64L32,64C32,56.61 35.56,50.11 40.98,46.06L36.18,41.19C35.45,40.45 35.45,39.3 36.18,38.56C36.91,37.81 38.05,37.81 38.78,38.56L44.25,44.05C47.18,42.57 50.48,41.71 54,41.71C57.48,41.71 60.78,42.57 63.68,44.05L69.11,38.56C69.84,37.81 70.98,37.81 71.71,38.56C72.44,39.3 72.44,40.45 71.71,41.19L66.94,46.02ZM62.94,56.92C64.08,56.92 65,56.01 65,54.88C65,53.76 64.08,52.85 62.94,52.85C61.8,52.85 60.88,53.76 60.88,54.88C60.88,56.01 61.8,56.92 62.94,56.92ZM45.06,56.92C46.2,56.92 47.13,56.01 47.13,54.88C47.13,53.76 46.2,52.85 45.06,52.85C43.92,52.85 43,53.76 43,54.88C43,56.01 43.92,56.92 45.06,56.92Z"
android:strokeColor="#00000000"
android:strokeWidth="1" />
</vector>
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="108dp"
android:height="108dp"
android:viewportHeight="108"
android:viewportWidth="108">
<path
android:fillColor="#008577"
android:pathData="M0,0h108v108h-108z" />
<path
android:fillColor="#00000000"
android:pathData="M9,0L9,108"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M19,0L19,108"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M29,0L29,108"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M39,0L39,108"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M49,0L49,108"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M59,0L59,108"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M69,0L69,108"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M79,0L79,108"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M89,0L89,108"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M99,0L99,108"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M0,9L108,9"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M0,19L108,19"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M0,29L108,29"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M0,39L108,39"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M0,49L108,49"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M0,59L108,59"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M0,69L108,69"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M0,79L108,79"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M0,89L108,89"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M0,99L108,99"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M19,29L89,29"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M19,39L89,39"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M19,49L89,49"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M19,59L89,59"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M19,69L89,69"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M19,79L89,79"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M29,19L29,89"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M39,19L39,89"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M49,19L49,89"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M59,19L59,89"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M69,19L69,89"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M79,19L79,89"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
</vector>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="meal_colorPrimary">#008577</color>
<color name="meal_colorPrimaryDark">#00574B</color>
<color name="meal_colorAccent">#D81B60</color>
</resources>
<resources>
<dimen name="meal_fab_margin">16dp</dimen>
</resources>
<resources>
<string name="meal_app_name">GSA-Mealstand</string>
<string name="meal_send_order">送單</string>
<string name="meal_print_order">印單</string>
<string name="meal_pay_order">結賬</string>
</resources>
<resources>
<!-- Base application theme. -->
<style name="meal_AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/meal_colorPrimary</item>
<item name="colorPrimaryDark">@color/meal_colorPrimaryDark</item>
<item name="colorAccent">@color/meal_colorAccent</item>
</style>
</resources>
package com.gingersoft.cloud.gsa;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* Example local unit test, which will execute on the development machine (host).
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() {
assertEquals(4, 2 + 2);
}
}
\ No newline at end of file
apply from: rootProject.file("cc-settings.gradle") apply from: rootProject.file("cc-settings.gradle")
apply plugin: 'com.jakewharton.butterknife'
android { android {
compileSdkVersion rootProject.ext.android["compileSdkVersion"] compileSdkVersion rootProject.ext.android["compileSdkVersion"]
...@@ -38,11 +38,17 @@ dependencies { ...@@ -38,11 +38,17 @@ dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar']) implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0' implementation 'androidx.appcompat:appcompat:1.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0' androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation rootProject.ext.dependencies["zxing"] annotationProcessor rootProject.ext.dependencies["dagger2-compiler"]
implementation 'am.util:printer:2.1.0' implementation 'am.util:printer:2.1.0'
implementation rootProject.ext.dependencies["BaseRecyclerViewAdapter"] implementation rootProject.ext.dependencies["BaseRecyclerViewAdapter"]
implementation rootProject.ext.dependencies["yzjRecyclerView"]
// implementation rootProject.ext.dependencies["fastjson"]
debugImplementation rootProject.ext.dependencies["canary-debug"]
releaseImplementation rootProject.ext.dependencies["canary-release"]
testImplementation rootProject.ext.dependencies["canary-release"]
testImplementation rootProject.ext.dependencies["junit"]
} }
package com.joe.print;
import android.content.Context;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.*;
/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
assertEquals("com.joe.print.test", appContext.getPackageName());
}
}
...@@ -2,7 +2,9 @@ ...@@ -2,7 +2,9 @@
package="com.joe.print"> package="com.joe.print">
<application> <application>
<activity android:name=".PrintActivity"/> <activity android:name=".mvp.ui.activity.PrintActivity" android:theme="@style/print_TranslucentTheme"/>
<activity android:name=".mvp.ui.activity.PrinterListActivity"/>
<activity android:name=".mvp.ui.activity.PrinterAddActivity"/>
</application> </application>
</manifest> </manifest>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.joe.print" > package="com.joe.print">
<uses-permission android:name="android.permission.BLUETOOTH" /> <uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application <application
android:name=".MyApp"
android:allowBackup="true" android:allowBackup="true"
android:icon="@mipmap/ic_launcher" android:icon="@mipmap/ic_launcher"
android:label="@string/app_name" android:label="@string/app_name"
android:name=".MyApp"
android:roundIcon="@mipmap/ic_launcher_round" android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/user_register_AppTheme"> android:theme="@style/AppTheme">
<activity android:name=".mvp.ui.activity.PrinterAddActivity"/>
<activity android:name=".PrintActivity"> <activity android:name=".mvp.ui.activity.PrintActivity" android:theme="@style/print_TranslucentTheme"/> <!-- android:theme="@style/print_TranslucentTheme" -->
<activity android:name=".mvp.ui.activity.PrinterListActivity">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.VIEW" /> <action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter> </intent-filter>
</activity> </activity>
</application> </application>
</manifest> </manifest>
\ No newline at end of file
...@@ -2,22 +2,6 @@ ...@@ -2,22 +2,6 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="#000"
android:orientation="vertical"> android:orientation="vertical">
<Button
android:id="@+id/btn_print"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="打印"
android:layout_marginTop="50dp"
android:textColor="#333"
android:textSize="16sp" />
<ImageView
android:id="@+id/iv_print"
android:layout_width="match_parent"
android:layout_gravity="center"
android:layout_height="wrap_content"/>
</LinearLayout> </LinearLayout>
\ No newline at end of file
package com.joe.print;
import android.app.Activity;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;
import com.billy.cc.core.component.CCUtil;
import com.gingersoft.gsa.cloud.base.bean.TableBean;
import com.gingersoft.gsa.cloud.base.mealManage.MyOrderManage;
import com.gingersoft.gsa.cloud.base.mealManage.OpenTableContract;
import com.gingersoft.gsa.cloud.database.bean.Food;
import com.gingersoft.gsa.cloud.ui.dialog.LoadingDialog;
import com.joe.print.adapter.BillAdapter;
import com.joe.print.adapter.FoodAdapter;
import com.joe.print.bean.BillingBean;
import com.joe.print.bean.FoodBean;
import com.joe.print.print.SendPrint;
import java.util.ArrayList;
import java.util.List;
import am.util.printer.PrintExecutor;
import am.util.printer.PrintSocketHolder;
import am.util.printer.PrinterWriter58mm;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
/**
* Created by Wyh on 2020/1/7.
*/
public class PrintActivity extends Activity implements PrintSocketHolder.OnStateChangedListener, PrintExecutor.OnPrintResultListener {
private ImageView view;
private PrintExecutor executor;
private SendPrint maker;
private TextView tv_dining_table_number;
private TextView tv_people;
private TextView tv_order_num;
private TextView tv_date;
private RecyclerView rvFood;
private RecyclerView rvBill;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.activity_print);
setContentView(R.layout.print_layout_print);
tv_dining_table_number= findViewById(R.id.tv_dining_table_number);
tv_people= findViewById(R.id.tv_people);
tv_order_num= findViewById(R.id.tv_order_num);
tv_date= findViewById(R.id.tv_date);
rvFood = findViewById(R.id.rv_food);
rvBill = findViewById(R.id.rv_bill_amount);
List<Food> foodList = MyOrderManage.getInstance().getOrderFoodList();
TableBean.DataBean tableBean = OpenTableContract.getDefault().getTableBean();
tv_dining_table_number.setText(tableBean.getTableName());
tv_people.setText(tableBean.getPeopleNumber()+"");
// tv_order_num.setText();
tv_date.setText(tableBean.getCreateTime());
// List<FoodBean> data = new ArrayList<>();
// data.add(new FoodBean("包子(主項)", 1, 13.54));
// data.add(new FoodBean("番薯爸爸", 2, 8.0));
// data.add(new FoodBean("包子(主項)", 3, 37.34));
// data.add(new FoodBean("測卡很快就酸辣粉十大減肥和思考", 33, 1334.2254));
FoodAdapter foodAdapter = new FoodAdapter(foodList);
rvFood.setLayoutManager(new LinearLayoutManager(this));
rvFood.setAdapter(foodAdapter);
List<BillingBean> billingBeans = new ArrayList<>();
billingBeans.add(new BillingBean("合計", 58.88));
billingBeans.add(new BillingBean("10%服務費", 5.08));
billingBeans.add(new BillingBean("賬單小數", -0.06));
billingBeans.add(new BillingBean("上課交電話費扣水電費可接受的咖啡機", 837248.8829372));
BillAdapter billAdapter = new BillAdapter(billingBeans);
rvBill.setLayoutManager(new LinearLayoutManager(this));
rvBill.setAdapter(billAdapter);
// view = findViewById(R.id.iv_print);
LoadingDialog.showDialogForLoading(this,"打印中...",false);
// findViewById(R.id.btn_print).setOnClickListener(v -> {
if (executor == null) {
executor = new PrintExecutor("192.168.1.217", 9100, PrinterWriter58mm.TYPE_58);
executor.setOnStateChangedListener(PrintActivity.this::onResult);
executor.setOnPrintResultListener(PrintActivity.this);
}
executor.setIp("192.168.1.217", 9100);
executor.doPrinterRequestAsync(maker);
// });
}
public void loadImage(Bitmap bitmap) {
runOnUiThread(() -> view.setImageBitmap(bitmap));
}
@Override
public void onResult(int errorCode) {
switch (errorCode) {
case PrintSocketHolder.ERROR_0:
break;
case PrintSocketHolder.ERROR_1:
break;
case PrintSocketHolder.ERROR_2:
break;
case PrintSocketHolder.ERROR_3:
break;
case PrintSocketHolder.ERROR_4:
break;
case PrintSocketHolder.ERROR_5:
break;
}
LoadingDialog.cancelDialogForLoading();
finish();
}
@Override
public void onStateChanged(int state) {
switch (state) {
case PrintSocketHolder.STATE_0:
break;
case PrintSocketHolder.STATE_1:
break;
case PrintSocketHolder.STATE_2:
break;
case PrintSocketHolder.STATE_3:
break;
case PrintSocketHolder.STATE_4:
break;
}
}
}
package com.joe.print; package com.joe.print;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import com.billy.cc.core.component.CC; import com.billy.cc.core.component.CC;
import com.billy.cc.core.component.CCResult; import com.billy.cc.core.component.CCResult;
import com.billy.cc.core.component.CCUtil; import com.billy.cc.core.component.CCUtil;
import com.billy.cc.core.component.IComponent; import com.billy.cc.core.component.IComponent;
import com.joe.print.mvp.ui.activity.PrintActivity;
import com.joe.print.mvp.ui.activity.PrinterListActivity;
public class PrintComponent implements IComponent { public class PrintComponent implements IComponent {
...@@ -41,7 +47,15 @@ public class PrintComponent implements IComponent { ...@@ -41,7 +47,15 @@ public class PrintComponent implements IComponent {
case "getInfo": case "getInfo":
getInfo(cc); getInfo(cc);
break; break;
case "print_order":
return printOrderInfo(cc);
default: default:
// cc.callAsync(new IComponentCallback() {
// @Override
// public void onResult(CC cc, CCResult result) {
//
// }
// });
//这个逻辑分支上没有调用CC.sendCCResult(...),是一种错误的示例 //这个逻辑分支上没有调用CC.sendCCResult(...),是一种错误的示例
//并且方法的返回值为false,代表不会异步调用CC.sendCCResult(...) //并且方法的返回值为false,代表不会异步调用CC.sendCCResult(...)
//在LocalCCInterceptor中将会返回错误码为-10的CCResult //在LocalCCInterceptor中将会返回错误码为-10的CCResult
...@@ -71,8 +85,28 @@ public class PrintComponent implements IComponent { ...@@ -71,8 +85,28 @@ public class PrintComponent implements IComponent {
} }
private void openActivity(CC cc) { private void openActivity(CC cc) {
CCUtil.navigateTo(cc, PrintActivity.class); CCUtil.navigateTo(cc, PrinterListActivity.class);
CC.sendCCResult(cc.getCallId(), CCResult.success()); CC.sendCCResult(cc.getCallId(), CCResult.success());
} }
private boolean printOrderInfo(CC cc){
// Print.getInstance().printOrder(cc.getContext());
Context context = cc.getContext();
Intent intent = new Intent(context, PrintActivity.class);
if (!(context instanceof Activity)) {
//调用方没有设置context或app间组件跳转,context为application
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
}
//将cc的callId传给Activity,登录完成后通过这个callId来回传结果
intent.putExtra("callId", cc.getCallId());
context.startActivity(intent);
// CCUtil.navigateTo(cc, PrintActivity.class);
// CC.sendCCResult(cc.getCallId(), CCResult.success());
//返回true,不立即调用CC.sendCCResult
return true;
}
} }
package com.joe.print.di.component;
import dagger.BindsInstance;
import dagger.Component;
import com.jess.arms.di.component.AppComponent;
import com.joe.print.di.module.PrintListModule;
import com.joe.print.mvp.contract.PrintListContract;
import com.jess.arms.di.scope.ActivityScope;
import com.joe.print.mvp.ui.activity.PrinterListActivity;
/**
* ================================================
* Description:
* <p>
* Created by MVPArmsTemplate on 01/16/2020 10:24
* <a href="mailto:jess.yan.effort@gmail.com">Contact me</a>
* <a href="https://github.com/JessYanCoding">Follow me</a>
* <a href="https://github.com/JessYanCoding/MVPArms">Star me</a>
* <a href="https://github.com/JessYanCoding/MVPArms/wiki">See me</a>
* <a href="https://github.com/JessYanCoding/MVPArmsTemplate">模版请保持更新</a>
* ================================================
*/
@ActivityScope
@Component(modules = PrintListModule.class, dependencies = AppComponent.class)
public interface PrintListComponent {
void inject(PrinterListActivity activity);
@Component.Builder
interface Builder {
@BindsInstance
PrintListComponent.Builder view(PrintListContract.View view);
PrintListComponent.Builder appComponent(AppComponent appComponent);
PrintListComponent build();
}
}
\ No newline at end of file
package com.joe.print.di.component;
import dagger.BindsInstance;
import dagger.Component;
import com.jess.arms.di.component.AppComponent;
import com.joe.print.di.module.PrinterAddModule;
import com.joe.print.mvp.contract.PrinterAddContract;
import com.jess.arms.di.scope.ActivityScope;
import com.joe.print.mvp.ui.activity.PrinterAddActivity;
/**
* ================================================
* Description:
* <p>
* Created by MVPArmsTemplate on 01/16/2020 16:23
* <a href="mailto:jess.yan.effort@gmail.com">Contact me</a>
* <a href="https://github.com/JessYanCoding">Follow me</a>
* <a href="https://github.com/JessYanCoding/MVPArms">Star me</a>
* <a href="https://github.com/JessYanCoding/MVPArms/wiki">See me</a>
* <a href="https://github.com/JessYanCoding/MVPArmsTemplate">模版请保持更新</a>
* ================================================
*/
@ActivityScope
@Component(modules = PrinterAddModule.class, dependencies = AppComponent.class)
public interface PrinterAddComponent {
void inject(PrinterAddActivity activity);
@Component.Builder
interface Builder {
@BindsInstance
PrinterAddComponent.Builder view(PrinterAddContract.View view);
PrinterAddComponent.Builder appComponent(AppComponent appComponent);
PrinterAddComponent build();
}
}
\ No newline at end of file
package com.joe.print.di.module;
import com.jess.arms.di.scope.ActivityScope;
import dagger.Binds;
import dagger.Module;
import dagger.Provides;
import com.joe.print.mvp.contract.PrintListContract;
import com.joe.print.mvp.model.PrintListModel;
/**
* ================================================
* Description:
* <p>
* Created by MVPArmsTemplate on 01/16/2020 10:24
* <a href="mailto:jess.yan.effort@gmail.com">Contact me</a>
* <a href="https://github.com/JessYanCoding">Follow me</a>
* <a href="https://github.com/JessYanCoding/MVPArms">Star me</a>
* <a href="https://github.com/JessYanCoding/MVPArms/wiki">See me</a>
* <a href="https://github.com/JessYanCoding/MVPArmsTemplate">模版请保持更新</a>
* ================================================
*/
@Module
public abstract class PrintListModule {
@Binds
abstract PrintListContract.Model bindPrintListModel(PrintListModel model);
}
\ No newline at end of file
package com.joe.print.di.module;
import com.jess.arms.di.scope.ActivityScope;
import dagger.Binds;
import dagger.Module;
import dagger.Provides;
import com.joe.print.mvp.contract.PrinterAddContract;
import com.joe.print.mvp.model.PrinterAddModel;
/**
* ================================================
* Description:
* <p>
* Created by MVPArmsTemplate on 01/16/2020 16:23
* <a href="mailto:jess.yan.effort@gmail.com">Contact me</a>
* <a href="https://github.com/JessYanCoding">Follow me</a>
* <a href="https://github.com/JessYanCoding/MVPArms">Star me</a>
* <a href="https://github.com/JessYanCoding/MVPArms/wiki">See me</a>
* <a href="https://github.com/JessYanCoding/MVPArmsTemplate">模版请保持更新</a>
* ================================================
*/
@Module
public abstract class PrinterAddModule {
@Binds
abstract PrinterAddContract.Model bindPrinterAddModel(PrinterAddModel model);
}
\ No newline at end of file
package com.joe.print.mvp.contract;
import com.gingersoft.gsa.cloud.base.common.bean.BaseResult;
import com.gingersoft.gsa.cloud.database.bean.PrinterDeviceBean;
import com.jess.arms.mvp.IModel;
import com.jess.arms.mvp.IView;
import java.util.List;
import io.reactivex.Observable;
import okhttp3.RequestBody;
/**
* ================================================
* Description:
* <p>
* Created by MVPArmsTemplate on 01/16/2020 10:24
* <a href="mailto:jess.yan.effort@gmail.com">Contact me</a>
* <a href="https://github.com/JessYanCoding">Follow me</a>
* <a href="https://github.com/JessYanCoding/MVPArms">Star me</a>
* <a href="https://github.com/JessYanCoding/MVPArms/wiki">See me</a>
* <a href="https://github.com/JessYanCoding/MVPArmsTemplate">模版请保持更新</a>
* ================================================
*/
public interface PrintListContract {
//对于经常使用的关于UI的方法可以定义到IView中,如显示隐藏进度条,和显示文字消息
interface View extends IView {
void loadPrinterList(List<PrinterDeviceBean> deviceBeans);
}
//Model层定义接口,外部只需关心Model返回的数据,无需关心内部细节,即是否使用缓存
interface Model extends IModel {
Observable<BaseResult> getPrinterList(int restaurantId);
Observable<BaseResult> deletePrinter(RequestBody requestBody);
}
}
package com.joe.print.mvp.contract;
import com.gingersoft.gsa.cloud.base.common.bean.BaseResult;
import com.jess.arms.mvp.IView;
import com.jess.arms.mvp.IModel;
import io.reactivex.Observable;
import okhttp3.RequestBody;
/**
* ================================================
* Description:
* <p>
* Created by MVPArmsTemplate on 01/16/2020 16:23
* <a href="mailto:jess.yan.effort@gmail.com">Contact me</a>
* <a href="https://github.com/JessYanCoding">Follow me</a>
* <a href="https://github.com/JessYanCoding/MVPArms">Star me</a>
* <a href="https://github.com/JessYanCoding/MVPArms/wiki">See me</a>
* <a href="https://github.com/JessYanCoding/MVPArmsTemplate">模版请保持更新</a>
* ================================================
*/
public interface PrinterAddContract {
//对于经常使用的关于UI的方法可以定义到IView中,如显示隐藏进度条,和显示文字消息
interface View extends IView {
void addPrinterSuccess();
}
//Model层定义接口,外部只需关心Model返回的数据,无需关心内部细节,即是否使用缓存
interface Model extends IModel {
Observable<BaseResult> addPrinter(RequestBody requestBody);
Observable<BaseResult> updatePrinter(RequestBody requestBody);
}
}
package com.joe.print.mvp.model;
import android.app.Application;
import com.gingersoft.gsa.cloud.base.common.bean.BaseResult;
import com.google.gson.Gson;
import com.jess.arms.integration.IRepositoryManager;
import com.jess.arms.mvp.BaseModel;
import com.jess.arms.di.scope.ActivityScope;
import javax.inject.Inject;
import com.joe.print.mvp.contract.PrintListContract;
import com.joe.print.mvp.model.server.PrinterService;
import io.reactivex.Observable;
import okhttp3.RequestBody;
/**
* ================================================
* Description:
* <p>
* Created by MVPArmsTemplate on 01/16/2020 10:24
* <a href="mailto:jess.yan.effort@gmail.com">Contact me</a>
* <a href="https://github.com/JessYanCoding">Follow me</a>
* <a href="https://github.com/JessYanCoding/MVPArms">Star me</a>
* <a href="https://github.com/JessYanCoding/MVPArms/wiki">See me</a>
* <a href="https://github.com/JessYanCoding/MVPArmsTemplate">模版请保持更新</a>
* ================================================
*/
@ActivityScope
public class PrintListModel extends BaseModel implements PrintListContract.Model {
@Inject
Gson mGson;
@Inject
Application mApplication;
@Inject
public PrintListModel(IRepositoryManager repositoryManager) {
super(repositoryManager);
}
@Override
public void onDestroy() {
super.onDestroy();
this.mGson = null;
this.mApplication = null;
}
@Override
public Observable<BaseResult> getPrinterList(int restaurantId) {
return mRepositoryManager.obtainRetrofitService(PrinterService.class)
.getPrinterList(restaurantId);
}
@Override
public Observable<BaseResult> deletePrinter(RequestBody requestBody) {
return mRepositoryManager.obtainRetrofitService(PrinterService.class)
.deletePrinterList(requestBody);
}
}
\ No newline at end of file
package com.joe.print.mvp.model;
import android.app.Application;
import com.gingersoft.gsa.cloud.base.common.bean.BaseResult;
import com.google.gson.Gson;
import com.jess.arms.integration.IRepositoryManager;
import com.jess.arms.mvp.BaseModel;
import com.jess.arms.di.scope.ActivityScope;
import javax.inject.Inject;
import com.joe.print.mvp.contract.PrinterAddContract;
import com.joe.print.mvp.model.server.PrinterService;
import io.reactivex.Observable;
import okhttp3.RequestBody;
/**
* ================================================
* Description:
* <p>
* Created by MVPArmsTemplate on 01/16/2020 16:23
* <a href="mailto:jess.yan.effort@gmail.com">Contact me</a>
* <a href="https://github.com/JessYanCoding">Follow me</a>
* <a href="https://github.com/JessYanCoding/MVPArms">Star me</a>
* <a href="https://github.com/JessYanCoding/MVPArms/wiki">See me</a>
* <a href="https://github.com/JessYanCoding/MVPArmsTemplate">模版请保持更新</a>
* ================================================
*/
@ActivityScope
public class PrinterAddModel extends BaseModel implements PrinterAddContract.Model {
@Inject
Gson mGson;
@Inject
Application mApplication;
@Inject
public PrinterAddModel(IRepositoryManager repositoryManager) {
super(repositoryManager);
}
@Override
public void onDestroy() {
super.onDestroy();
this.mGson = null;
this.mApplication = null;
}
@Override
public Observable<BaseResult> addPrinter(RequestBody requestBody) {
return mRepositoryManager.obtainRetrofitService(PrinterService.class)
.addPrinter(requestBody);
}
@Override
public Observable<BaseResult> updatePrinter(RequestBody requestBody) {
return mRepositoryManager.obtainRetrofitService(PrinterService.class)
.updatePrinter(requestBody);
}
}
\ No newline at end of file
package com.joe.print.mvp.model;
import com.gingersoft.gsa.cloud.database.bean.PrinterDeviceBean;
import java.util.List;
/**
* Created by Wyh on 2020/1/17.
*/
public class PrinterManager {
private static PrinterManager printerManager;
public static PrinterManager getPrinterManager() {
if (printerManager == null) {
printerManager = new PrinterManager();
}
return printerManager;
}
public List<PrinterDeviceBean> deviceBeans;
public List<PrinterDeviceBean> getDeviceBeans() {
return deviceBeans;
}
public void setDeviceBeans(List<PrinterDeviceBean> deviceBeans) {
this.deviceBeans = deviceBeans;
}
}
package com.joe.print.bean; package com.joe.print.mvp.model.bean;
/** /**
* Created by Wyh on 2020/1/9. * Created by Wyh on 2020/1/9.
......
package com.joe.print.bean; package com.joe.print.mvp.model.bean;
/** /**
* Created by Wyh on 2020/1/9. * Created by Wyh on 2020/1/9.
......
//package com.joe.print.mvp.model.bean;
//
//import java.io.Serializable;
//
///**
// * Created by Wyh on 2020/1/16.
// * 打印機實體類
// */
//public class PrinterDeviceBean implements Serializable {
// private int id; //這個類是用來“新增”打印機的,不能有id。解析打印機列表用另一個類
//// private int uid;
// private int restaurantId;
// private String ip;
// private int port;
// private int type;
//// private long createTime;
//
// public PrinterDeviceBean() {
// }
//
// public PrinterDeviceBean(int id, int restaurantId, String ip, int port, int type) {
// this.id = id;
// this.restaurantId = restaurantId;
// this.ip = ip;
// this.port = port;
// this.type = type;
// }
//
// public PrinterDeviceBean(int restaurantId, String ip, int port, int type) {
// this.restaurantId = restaurantId;
// this.ip = ip;
// this.port = port;
// this.type = type;
// }
//
// public int getRestaurantId() {
// return restaurantId;
// }
//
// public void setRestaurantId(int restaurantId) {
// this.restaurantId = restaurantId;
// }
//
// public String getIp() {
// return ip;
// }
//
// public void setIp(String ip) {
// this.ip = ip;
// }
//
// public int getPort() {
// return port;
// }
//
// public void setPort(int port) {
// this.port = port;
// }
//
// public int getType() {
// return type;
// }
//
// public void setType(int type) {
// this.type = type;
// }
//
// public int getId() {
// return id;
// }
//
// public void setId(int id) {
// this.id = id;
// }
//
//// public int getUid() {
//// return uid;
//// }
////
//// public void setUid(int uid) {
//// this.uid = uid;
//// }
////
//// public long getCreateTime() {
//// return createTime;
//// }
////
//// public void setCreateTime(long createTime) {
//// this.createTime = createTime;
//// }
//}
package com.joe.print.mvp.model.server;
import com.gingersoft.gsa.cloud.base.common.bean.BaseResult;
import com.gingersoft.gsa.cloud.base.common.bean.TableBean;
import io.reactivex.Observable;
import me.jessyan.retrofiturlmanager.RetrofitUrlManager;
import okhttp3.RequestBody;
import retrofit2.http.Body;
import retrofit2.http.Field;
import retrofit2.http.GET;
import retrofit2.http.POST;
import retrofit2.http.Query;
/**
* Created by Wyh on 2019/12/20.
*/
public interface PrinterService {
@POST("PrinterDevice/add" + RetrofitUrlManager.IDENTIFICATION_PATH_SIZE + 2)
Observable<BaseResult> addPrinter(@Body RequestBody requestBody);
@GET("PrinterDevice/list?" + RetrofitUrlManager.IDENTIFICATION_PATH_SIZE + 2)
Observable<BaseResult> getPrinterList(@Query("restaurantId") int restaurantId);
@POST("PrinterDevice/deletes" + RetrofitUrlManager.IDENTIFICATION_PATH_SIZE + 2)
Observable<BaseResult> deletePrinterList(@Body RequestBody requestBody);
@POST("PrinterDevice/update" + RetrofitUrlManager.IDENTIFICATION_PATH_SIZE + 2)
Observable<BaseResult> updatePrinter(@Body RequestBody requestBody);
}
package com.joe.print.mvp.presenter;
import android.app.Application;
import com.gingersoft.gsa.cloud.base.common.bean.BaseResult;
import com.gingersoft.gsa.cloud.base.utils.JsonUtils;
import com.gingersoft.gsa.cloud.database.bean.PrinterDeviceBean;
import com.jess.arms.di.scope.ActivityScope;
import com.jess.arms.http.imageloader.ImageLoader;
import com.jess.arms.integration.AppManager;
import com.jess.arms.mvp.BasePresenter;
import com.jess.arms.utils.RxLifecycleUtils;
import com.joe.print.mvp.contract.PrintListContract;
import java.util.List;
import javax.inject.Inject;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import me.jessyan.rxerrorhandler.core.RxErrorHandler;
import me.jessyan.rxerrorhandler.handler.ErrorHandleSubscriber;
import okhttp3.FormBody;
import okhttp3.RequestBody;
/**
* ================================================
* Description:
* <p>
* Created by MVPArmsTemplate on 01/16/2020 10:24
* <a href="mailto:jess.yan.effort@gmail.com">Contact me</a>
* <a href="https://github.com/JessYanCoding">Follow me</a>
* <a href="https://github.com/JessYanCoding/MVPArms">Star me</a>
* <a href="https://github.com/JessYanCoding/MVPArms/wiki">See me</a>
* <a href="https://github.com/JessYanCoding/MVPArmsTemplate">模版请保持更新</a>
* ================================================
*/
@ActivityScope
public class PrintListPresenter extends BasePresenter<PrintListContract.Model, PrintListContract.View> {
@Inject
RxErrorHandler mErrorHandler;
@Inject
Application mApplication;
@Inject
ImageLoader mImageLoader;
@Inject
AppManager mAppManager;
@Inject
public PrintListPresenter(PrintListContract.Model model, PrintListContract.View rootView) {
super(model, rootView);
}
@Override
public void onDestroy() {
super.onDestroy();
this.mErrorHandler = null;
this.mAppManager = null;
this.mImageLoader = null;
this.mApplication = null;
}
/**
* 獲取打印機列表
*
* @param restaurantId 餐廳id
*/
public void getPrinterList(int restaurantId) {
mModel.getPrinterList(restaurantId)
.subscribeOn(Schedulers.io())
.doOnSubscribe(disposable -> mRootView.showLoading(""))
.subscribeOn(AndroidSchedulers.mainThread())
.observeOn(AndroidSchedulers.mainThread())
.doAfterTerminate(() -> mRootView.hideLoading())
.compose(RxLifecycleUtils.bindToLifecycle(mRootView))
.subscribe(new ErrorHandleSubscriber<BaseResult>(mErrorHandler) {
@Override
public void onNext(BaseResult baseResult) {
if(baseResult.isSuccess()){
List<PrinterDeviceBean> deviceBeans = JsonUtils.parseArray(baseResult.getData(), PrinterDeviceBean.class);
if(deviceBeans != null && deviceBeans.size() > 0){
mRootView.loadPrinterList(deviceBeans);
}
}
}
});
}
/**
* 刪除打印機
* @param ids 打印機id,可以傳多個 例如:1,2,3
*/
public void deletePrinter(String ids){
RequestBody requestBody = new FormBody.Builder()
.add("ids", ids)
.build();
mModel.deletePrinter(requestBody)
.subscribeOn(Schedulers.io())
.doOnSubscribe(disposable -> mRootView.showLoading(""))
.subscribeOn(AndroidSchedulers.mainThread())
.observeOn(AndroidSchedulers.mainThread())
.doAfterTerminate(() -> mRootView.hideLoading())
.compose(RxLifecycleUtils.bindToLifecycle(mRootView))
.subscribe(new ErrorHandleSubscriber<BaseResult>(mErrorHandler) {
@Override
public void onNext(BaseResult baseResult) {
}
});
}
}
package com.joe.print.mvp.presenter;
import android.app.Application;
import com.gingersoft.gsa.cloud.base.common.bean.BaseResult;
import com.gingersoft.gsa.cloud.base.utils.JsonUtils;
import com.gingersoft.gsa.cloud.database.bean.PrinterDeviceBean;
import com.jess.arms.di.scope.ActivityScope;
import com.jess.arms.http.imageloader.ImageLoader;
import com.jess.arms.integration.AppManager;
import com.jess.arms.mvp.BasePresenter;
import com.jess.arms.utils.RxLifecycleUtils;
import com.joe.print.mvp.contract.PrinterAddContract;
import javax.inject.Inject;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import me.jessyan.rxerrorhandler.core.RxErrorHandler;
import me.jessyan.rxerrorhandler.handler.ErrorHandleSubscriber;
import okhttp3.MediaType;
import okhttp3.RequestBody;
/**
* ================================================
* Description:
* <p>
* Created by MVPArmsTemplate on 01/16/2020 16:23
* <a href="mailto:jess.yan.effort@gmail.com">Contact me</a>
* <a href="https://github.com/JessYanCoding">Follow me</a>
* <a href="https://github.com/JessYanCoding/MVPArms">Star me</a>
* <a href="https://github.com/JessYanCoding/MVPArms/wiki">See me</a>
* <a href="https://github.com/JessYanCoding/MVPArmsTemplate">模版请保持更新</a>
* ================================================
*/
@ActivityScope
public class PrinterAddPresenter extends BasePresenter<PrinterAddContract.Model, PrinterAddContract.View> {
@Inject
RxErrorHandler mErrorHandler;
@Inject
Application mApplication;
@Inject
ImageLoader mImageLoader;
@Inject
AppManager mAppManager;
@Inject
public PrinterAddPresenter(PrinterAddContract.Model model, PrinterAddContract.View rootView) {
super(model, rootView);
}
@Override
public void onDestroy() {
super.onDestroy();
this.mErrorHandler = null;
this.mAppManager = null;
this.mImageLoader = null;
this.mApplication = null;
}
/**
* 添加打印機
*
* @param restaurantId 餐廳id
* @param ip 打印機ip
* @param port 打印機端口號
* @param type 類型1 :55mm, 2:88mm
*/
public void addPrinter(int restaurantId, String ip, String port, int type) {
PrinterDeviceBean printerDeviceBean = new PrinterDeviceBean(restaurantId, ip, Integer.parseInt(port), type);
RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), JsonUtils.toJson(printerDeviceBean));
mModel.addPrinter(requestBody)
.subscribeOn(Schedulers.io())
.doOnSubscribe(disposable -> mRootView.showLoading(""))
.subscribeOn(AndroidSchedulers.mainThread())
.observeOn(AndroidSchedulers.mainThread())
.doAfterTerminate(() -> mRootView.hideLoading())
.compose(RxLifecycleUtils.bindToLifecycle(mRootView))
.subscribe(new ErrorHandleSubscriber<BaseResult>(mErrorHandler) {
@Override
public void onNext(BaseResult baseResult) {
if (baseResult.isSuccess()) {
mRootView.addPrinterSuccess();
} else {
mRootView.showMessage("保存失敗");
}
}
});
}
/**
* 更新打印機信息
*
* @param id 打印機id
* @param restaurantId 餐廳id
* @param ip 打印機ip地址
* @param port 打印機端口號
* @param type 打印機類型 1 :55mm, 2:88mm
*/
public void updatePrinterInfo(int id, int restaurantId, String ip, String port, int type) {
PrinterDeviceBean printerDeviceBean = new PrinterDeviceBean(id, restaurantId, ip, Integer.parseInt(port), type);
RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), JsonUtils.toJson(printerDeviceBean));
mModel.updatePrinter(requestBody)
.subscribeOn(Schedulers.io())
.doOnSubscribe(disposable -> mRootView.showLoading(""))
.subscribeOn(AndroidSchedulers.mainThread())
.observeOn(AndroidSchedulers.mainThread())
.doAfterTerminate(() -> mRootView.hideLoading())
.compose(RxLifecycleUtils.bindToLifecycle(mRootView))
.subscribe(new ErrorHandleSubscriber<BaseResult>(mErrorHandler) {
@Override
public void onNext(BaseResult baseResult) {
if (baseResult.isSuccess()) {
}
}
});
}
}
package com.joe.print.mvp.print;
import android.content.Context;
import com.gingersoft.gsa.cloud.base.application.GsaCloudApplication;
import com.gingersoft.gsa.cloud.ui.dialog.LoadingDialog;
import am.util.printer.PrintExecutor;
import am.util.printer.PrintSocketHolder;
import am.util.printer.PrinterWriter58mm;
/**
* Created by Wyh on 2020/1/15.
*/
public class Print implements PrintSocketHolder.OnStateChangedListener, PrintExecutor.OnPrintResultListener {
private PrintExecutor executor;
private SendPrint maker;
private static Print print;
private Context mContext;
public static Print getInstance() {
synchronized (Print.class) {
if (print == null) {
print = new Print();
}
}
return print;
}
public void printOrder(Context context) {
this.mContext = context;
LoadingDialog.showNewDialogForLoading(GsaCloudApplication.getAppContext(),"初始化...",false);
if (executor == null) {
executor = new PrintExecutor("192.168.1.217", 9100, PrinterWriter58mm.TYPE_58);
executor.setOnStateChangedListener(this);
executor.setOnPrintResultListener(this);
}
if (maker == null) {
maker = new SendPrint(context, 255, 580);
}
executor.setIp("192.168.1.218", 9100);
executor.doPrinterRequestAsync(maker);
}
@Override
public void onResult(int errorCode) {
String msg;
switch (errorCode) {
case PrintSocketHolder.ERROR_0:
//打印成功
msg = "打印成功";
break;
case PrintSocketHolder.ERROR_2:
//创建Socket失败
msg = "連接打印機失敗";
break;
case PrintSocketHolder.ERROR_1:
case PrintSocketHolder.ERROR_3:
case PrintSocketHolder.ERROR_4:
case PrintSocketHolder.ERROR_5:
default:
//打印失敗
msg = "打印失敗";
// LoadingDialog.cancelDialogForLoading();
break;
}
LoadingDialog.setText(msg);
}
@Override
public void onStateChanged(int state) {
String msg = "";
switch (state) {
case PrintSocketHolder.STATE_0:
case PrintSocketHolder.STATE_1:
//创建Socket连接
msg = "連接打印機...";
break;
case PrintSocketHolder.STATE_2:
case PrintSocketHolder.STATE_3:
//写入测试页面数据
msg = "正在打印...";
break;
case PrintSocketHolder.STATE_4:
msg = "正在關閉...";
// LoadingDialog.cancelDialogForLoading();
break;
}
LoadingDialog.setText(msg);
}
}
package com.joe.print.print; package com.joe.print.mvp.print;
import android.content.Context; import android.content.Context;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.view.View; import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView;
import com.gingersoft.gsa.cloud.base.common.bean.TableBean;
import com.gingersoft.gsa.cloud.base.common.bean.mealManage.MyOrderManage;
import com.gingersoft.gsa.cloud.base.common.bean.mealManage.OpenTableContract;
import com.gingersoft.gsa.cloud.base.utils.MoneyUtil;
import com.gingersoft.gsa.cloud.base.utils.time.TimeUtils;
import com.gingersoft.gsa.cloud.database.bean.Food; import com.gingersoft.gsa.cloud.database.bean.Food;
import com.joe.print.LayoutToBitmapUtils; import com.gingersoft.gsa.cloud.base.utils.view.LayoutToBitmapUtils;
import com.joe.print.R; import com.joe.print.R;
import com.joe.print.adapter.BillAdapter; import com.joe.print.mvp.ui.adapter.BillAdapter;
import com.joe.print.adapter.FoodAdapter; import com.joe.print.mvp.ui.adapter.FoodAdapter;
import com.joe.print.bean.BillingBean; import com.joe.print.mvp.model.bean.BillingBean;
import com.joe.print.bean.FoodBean; import com.gingersoft.gsa.cloud.base.utils.view.ImageUtils;
import com.joe.print.utils.BitmapUtil;
import com.joe.print.utils.ImageUtils;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.math.BigDecimal;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
...@@ -59,8 +63,9 @@ public class SendPrint implements PrintDataMaker { ...@@ -59,8 +63,9 @@ public class SendPrint implements PrintDataMaker {
LayoutToBitmapUtils.layoutView(context, view);//先测量view LayoutToBitmapUtils.layoutView(context, view);//先测量view
Bitmap bitmap = LayoutToBitmapUtils.loadBitmapFromView(view);//将view轉bitmap Bitmap bitmap = LayoutToBitmapUtils.loadBitmapFromView(view);//将view轉bitmap
//壓縮bitmap到指定大小 //壓縮bitmap到指定大小
bitmap = ImageUtils.scalingBitmap(bitmap, width); bitmap = ImageUtils.zoomDrawable(bitmap, width, bitmap.getHeight());
ArrayList<byte[]> image1 = PrinterUtils.decodeBitmapToDataList(bitmap, parting);//bitmap转字节码 ArrayList<byte[]> image1 = PrinterUtils.decodeBitmapToDataList(bitmap, parting);//bitmap转字节码
data.addAll(image1); data.addAll(image1);
...@@ -86,32 +91,74 @@ public class SendPrint implements PrintDataMaker { ...@@ -86,32 +91,74 @@ public class SendPrint implements PrintDataMaker {
} }
} }
private View view;
private TextView brandName;
private TextView restaurantName;
private TextView tableNum;//台號
private TextView people;//人數
private TextView orderNum;//單號
private TextView orderData;
private RecyclerView rvFood;
private RecyclerView rvBillAmount;
private TextView mTvTotalAmount;//總金額
private TextView checkOutTime;
private TextView line_food_info;
@NotNull @NotNull
private View initView() { private View initView() {
View view = LinearLayout.inflate(context, R.layout.print_layout_print, null); if (view == null) {
RecyclerView rvFood = view.findViewById(R.id.rv_food); view = LinearLayout.inflate(context, R.layout.print_layout_print, null);
RecyclerView rvBill = view.findViewById(R.id.rv_bill_amount); brandName = view.findViewById(R.id.tv_brand_name);
restaurantName = view.findViewById(R.id.tv_restaurant_name);
tableNum = view.findViewById(R.id.tv_dining_table_number);
people = view.findViewById(R.id.tv_people);
orderNum = view.findViewById(R.id.tv_order_num);
orderData = view.findViewById(R.id.tv_date);
rvFood = view.findViewById(R.id.rv_food);
rvBillAmount = view.findViewById(R.id.rv_bill_amount);
mTvTotalAmount = view.findViewById(R.id.tv_total_amount);
checkOutTime = view.findViewById(R.id.tv_checkout_time);
line_food_info = view.findViewById(R.id.line_food_info);
}
List<Food> foodList = MyOrderManage.getInstance().getOrderFoodList();
TableBean.DataBean tableBean = OpenTableContract.getDefault().getTableBean();
// List<Food> foodBeans = new ArrayList<>(); tableNum.setText(tableBean.getTableName());
// foodBeans.add(new FoodBean("包子(主項)", 1, 13.54)); people.setText(tableBean.getPeopleNumber() + "");
// foodBeans.add(new FoodBean("番薯爸爸", 2, 8.0)); orderData.setText(tableBean.getCreateTime());
// foodBeans.add(new FoodBean("包子(主項)", 3, 37.34));
// foodBeans.add(new FoodBean("測卡很快就酸辣粉十大減肥和思考", 33, 1334.2254));
// FoodAdapter foodAdapter = new FoodAdapter(foodBeans); checkOutTime.setText(TimeUtils.getCurrentTimeInString(TimeUtils.DEFAULT_DATE_FORMAT));
// rvFood.setLayoutManager(new LinearLayoutManager(context));
// rvFood.setAdapter(foodAdapter);
FoodAdapter foodAdapter = new FoodAdapter(foodList);
rvFood.setLayoutManager(new LinearLayoutManager(context));
rvFood.setAdapter(foodAdapter);
List<BillingBean> billingBeans = new ArrayList<>(); List<BillingBean> billingBeans = new ArrayList<>();
billingBeans.add(new BillingBean("合計", 58.88)); // billingBeans.add(new BillingBean("合計", 58.88));
billingBeans.add(new BillingBean("10%服務費", 5.08)); // billingBeans.add(new BillingBean("10%服務費", 5.08));
billingBeans.add(new BillingBean("賬單小數", -0.06)); // billingBeans.add(new BillingBean("賬單小數", -0.06));
billingBeans.add(new BillingBean("上課交電話費扣水電費可接受的咖啡機", 837248.8829372)); if (billingBeans.size() <= 0) {
line_food_info.setVisibility(View.GONE);
BillAdapter billAdapter = new BillAdapter(billingBeans); } else {
rvBill.setLayoutManager(new LinearLayoutManager(context)); BillAdapter billAdapter = new BillAdapter(billingBeans);
rvBill.setAdapter(billAdapter); rvBillAmount.setLayoutManager(new LinearLayoutManager(context));
rvBillAmount.setAdapter(billAdapter);
}
if(OpenTableContract.getDefault().getTableBean() != null) {
tableNum.setText(OpenTableContract.getDefault().getTableBean().getTableName());
people.setText(OpenTableContract.getDefault().getTableBean().getPeopleNumber() + "");
}
if(MyOrderManage.getInstance().getOrderId() != -1){
orderNum.setText(MyOrderManage.getInstance().getOrderId() + "");
}
BigDecimal totalAmount = new BigDecimal(0);
for (Food food : MyOrderManage.getInstance().getOrderFoodList()) {
totalAmount = MoneyUtil.sum(totalAmount, MoneyUtil.priceCalculation(food.getPrice(), food.getNumber()));
}
//總金額
mTvTotalAmount.setText(totalAmount +"");
//加载条形码 //加载条形码
// ImageView ivBarCode = view.findViewById(R.id.iv_bar_code); // ImageView ivBarCode = view.findViewById(R.id.iv_bar_code);
// ivBarCode.setImageBitmap(BitmapUtil.generateBitmap("12312112131", 2, 450, 150)); // ivBarCode.setImageBitmap(BitmapUtil.generateBitmap("12312112131", 2, 450, 150));
......
package com.joe.print.mvp.ui.activity;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.WindowManager;
import com.billy.cc.core.component.CC;
import com.billy.cc.core.component.CCResult;
import com.gingersoft.gsa.cloud.base.utils.toast.ToastUtils;
import com.gingersoft.gsa.cloud.database.DaoManager;
import com.gingersoft.gsa.cloud.database.greendao.PrinterDeviceBeanDao;
import com.gingersoft.gsa.cloud.ui.dialog.LoadingDialog;
import com.joe.print.mvp.print.SendPrint;
import am.util.printer.PrintExecutor;
import am.util.printer.PrintSocketHolder;
import am.util.printer.PrinterWriter58mm;
import androidx.annotation.Nullable;
import static com.gingersoft.gsa.cloud.database.DaoManager.getInstance;
/**
* Created by Wyh on 2020/1/7.
*/
public class PrintActivity extends Activity implements PrintSocketHolder.OnStateChangedListener, PrintExecutor.OnPrintResultListener, DialogInterface.OnDismissListener {
private PrintExecutor executor;
private SendPrint maker;
private Dialog dialog;
private String callId;
/**
* 是否打印成功 true:成功
*/
private boolean printStatus = false;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setBackgroundDrawable(null);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
callId = getIntent().getStringExtra("callId");
// if(callId != null){
// PrinterDeviceBeanDao deviceBeanDao = getInstance().getDaoSession().getPrinterDeviceBeanDao();
// }
printOrder(this);
}
public void printOrder(Context context) {
if (dialog != null) {
dialog.dismiss();
}
dialog = LoadingDialog.showNewDialogForLoading(this, "初始化...", false);
dialog.setOnDismissListener(this);
if (executor == null) {
executor = new PrintExecutor("192.168.1.217", 9100, PrinterWriter58mm.TYPE_58);
executor.setOnStateChangedListener(this);
executor.setOnPrintResultListener(this);
}
if (maker == null) {
maker = new SendPrint(context, 255, 560);
}
executor.setIp("192.168.1.217", 9100);
executor.doPrinterRequestAsync(maker);
}
@Override
public void onResult(int errorCode) {
String msg = "";
switch (errorCode) {
case PrintSocketHolder.ERROR_0:
//打印成功
msg = "打印成功";
printStatus = true;
dismiss(msg);
break;
case PrintSocketHolder.ERROR_2:
//创建Socket失败
msg = "連接打印機失敗";
printStatus = false;
dismiss(msg);
break;
case PrintSocketHolder.ERROR_1:
case PrintSocketHolder.ERROR_3:
case PrintSocketHolder.ERROR_4:
case PrintSocketHolder.ERROR_5:
//打印失敗
msg = "打印失敗";
dismiss(msg);
printStatus = false;
break;
default:
break;
}
LoadingDialog.setText(msg);
}
@Override
public void onStateChanged(int state) {
String msg = "";
switch (state) {
case PrintSocketHolder.STATE_0:
case PrintSocketHolder.STATE_1:
//创建Socket连接
msg = "連接打印機...";
break;
case PrintSocketHolder.STATE_2:
case PrintSocketHolder.STATE_3:
//写入测试页面数据
msg = "正在打印...";
break;
case PrintSocketHolder.STATE_4:
msg = "正在關閉...";
dismiss(msg);
break;
}
LoadingDialog.setText(msg);
}
private void dismiss(String msg) {
ToastUtils.show(this, msg);
dialog.dismiss();
//判断是否为CC调用打开本页面
if (callId != null) {
CCResult result;
if (printStatus) {
result = CCResult.success();
} else {
result = CCResult.error("print error");
}
//为确保不管登录成功与否都会调用CC.sendCCResult,在onDestroy方法中调用
CC.sendCCResult(callId, result);
}
finish();
}
@Override
public void onDismiss(DialogInterface dialog) {
finish();
}
}
package com.joe.print.mvp.ui.activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.TextView;
import com.gingersoft.gsa.cloud.base.application.GsaCloudApplication;
import com.gingersoft.gsa.cloud.database.bean.PrinterDeviceBean;
import com.gingersoft.gsa.cloud.ui.view.MyEditText;
import com.jess.arms.base.BaseActivity;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.utils.ArmsUtils;
import com.joe.print.R;
import com.joe.print.R2;
import com.joe.print.di.component.DaggerPrinterAddComponent;
import com.joe.print.mvp.contract.PrinterAddContract;
import com.joe.print.mvp.presenter.PrinterAddPresenter;
import com.qmuiteam.qmui.widget.QMUITopBar;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import butterknife.BindView;
import butterknife.BindViews;
import butterknife.OnClick;
import static com.jess.arms.utils.Preconditions.checkNotNull;
/**
* 新增或編輯打印機
*/
public class PrinterAddActivity extends BaseActivity<PrinterAddPresenter> implements PrinterAddContract.View, View.OnClickListener {
// EditText ipEdit1, ipEdit2, ipEdit3, ipEdit4;
@BindViews({R2.id.ip_edit_1, R2.id.ip_edit_2, R2.id.ip_edit_3, R2.id.ip_edit_4})
EditText[] ipEdits = new EditText[4];
@BindView(R2.id.add_printer_topbar)
QMUITopBar topBar;
@BindView(R2.id.add_printer_ed_port)
MyEditText etPort;
@BindView(R2.id.print_test)
TextView printTest;
@BindView(R2.id.printer_type)
RadioGroup rgPaperType;
private PrinterDeviceBean printerDeviceBean;
private boolean isEditPrinter = false;//是否是編輯打印機
@Override
public void setupActivityComponent(@NonNull AppComponent appComponent) {
DaggerPrinterAddComponent //如找不到该类,请编译一下项目
.builder()
.appComponent(appComponent)
.view(this)
.build()
.inject(this);
}
@Override
public int initView(@Nullable Bundle savedInstanceState) {
return R.layout.printer_activity_add; //如果你不需要框架帮你设置 setContentView(id) 需要自行设置,请返回 0
}
@Override
public void initData(@Nullable Bundle savedInstanceState) {
etPort.getEditText().setInputType(EditorInfo.TYPE_CLASS_NUMBER);
String[] ips = new String[4];
//如果不為空,則是編輯打印機,初始化信息
if (printerDeviceBean != null) {
ips = printerDeviceBean.getIp().split("[.]");
etPort.setText(printerDeviceBean.getPort() + "");
if (printerDeviceBean.getType() == 1) {
rgPaperType.check(R.id.print_paper_size_58);
} else {
rgPaperType.check(R.id.print_paper_size_88);
}
}
//添加監聽
for (int i = 0; i < ipEdits.length; i++) {
MyTextWatcher myTextWatchers = new MyTextWatcher(ipEdits[i]);
ipEdits[i].addTextChangedListener(myTextWatchers);
if (ips.length > i) {
ipEdits[i].setText(ips[i]);
}
}
}
@Override
public void initIntent() {
printerDeviceBean = (PrinterDeviceBean) getIntent().getSerializableExtra("printerInfo");
isEditPrinter = printerDeviceBean != null;
}
@Override
public void initTopBar() {
String title = "添加打印機";
if (isEditPrinter) {
title = "編輯打印機";
}
topBar.setTitle(title);
topBar.addLeftImageButton(R.drawable.icon_back, R.id.iv_left_back).setOnClickListener(v -> finish());
topBar.addRightTextButton("保存", R.id.printer_add).setOnClickListener(this);
}
@Override
public void initLanguage() {
}
@Override
public void initLayoutParams() {
}
@Override
public void initLayoutVisible() {
}
@Override
public void showLoading(String message) {
}
@Override
public void hideLoading() {
}
@Override
public void showMessage(@NonNull String message) {
checkNotNull(message);
ArmsUtils.snackbarText(message);
}
@Override
public void launchActivity(@NonNull Intent intent) {
checkNotNull(intent);
ArmsUtils.startActivity(intent);
}
@Override
public void killMyself() {
finish();
}
@OnClick({R2.id.print_test})
@Override
public void onClick(View v) {
if (v.getId() == R.id.print_test) {
//打印測試
startActivity(new Intent(mContext, PrintActivity.class));
} else if (v.getId() == R.id.printer_add) {
//保存打印機信息
StringBuilder ipAddress = new StringBuilder();
for (EditText editText : ipEdits) {
if (editText.getText() == null || editText.getText().toString().equals("")) {
showMessage("請輸入完整的IP地址");
return;
}
ipAddress.append(editText.getText());
ipAddress.append(".");
}
if (etPort.getText() == null || etPort.getText().toString().equals("")) {
showMessage("請輸入端口號");
return;
}
hideKeyBoard();
int paperType = 1;
if (rgPaperType.getCheckedRadioButtonId() != R.id.print_paper_size_58) {
paperType = 2;
}
if (isEditPrinter && printerDeviceBean != null) {
mPresenter.updatePrinterInfo(printerDeviceBean.getId(), GsaCloudApplication.getRestaurantId(mContext), ipAddress.substring(0, ipAddress.lastIndexOf(".")), etPort.getText().toString(), paperType);
} else {
mPresenter.addPrinter(GsaCloudApplication.getRestaurantId(mContext), ipAddress.substring(0, ipAddress.lastIndexOf(".")), etPort.getText().toString(), paperType);
}
}
}
private void hideKeyBoard() {
//收起鍵盤
InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
// 隐藏软键盘
imm.hideSoftInputFromWindow(getWindow().getDecorView().getWindowToken(), 0);
}
@Override
public void addPrinterSuccess() {
//添加或編輯打印機成功
showMessage("保存成功");
finish();
}
class MyTextWatcher implements TextWatcher {
public EditText mEditText;
public MyTextWatcher(EditText mEditText) {
super();
this.mEditText = mEditText;
}
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
if (s.length() == 3) {
if (Integer.parseInt(mEditText.getEditableText().toString()) > 255) {
mEditText.setText("255");
}
if (this.mEditText == ipEdits[0]) {
ipEdits[1].requestFocus();
} else if (this.mEditText == ipEdits[1]) {
ipEdits[2].requestFocus();
} else if (this.mEditText == ipEdits[2]) {
ipEdits[3].requestFocus();
}
if (this.mEditText == ipEdits[3]) {
ipEdits[3].setSelection(3);
}
}
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
}
}
package com.joe.print.mvp.ui.activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.ViewGroup;
import com.gingersoft.gsa.cloud.base.application.GsaCloudApplication;
import com.gingersoft.gsa.cloud.database.bean.PrinterDeviceBean;
import com.jess.arms.base.BaseActivity;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.utils.ArmsUtils;
import com.joe.print.R;
import com.joe.print.R2;
import com.joe.print.di.component.DaggerPrintListComponent;
import com.joe.print.mvp.contract.PrintListContract;
import com.joe.print.mvp.model.PrinterManager;
import com.joe.print.mvp.presenter.PrintListPresenter;
import com.joe.print.mvp.ui.adapter.PrinterListAdapter;
import com.qmuiteam.qmui.widget.QMUITopBar;
import com.yanzhenjie.recyclerview.SwipeMenuCreator;
import com.yanzhenjie.recyclerview.SwipeMenuItem;
import com.yanzhenjie.recyclerview.SwipeRecyclerView;
import com.yanzhenjie.recyclerview.touch.OnItemMoveListener;
import com.yanzhenjie.recyclerview.touch.OnItemStateChangedListener;
import com.yanzhenjie.recyclerview.widget.DefaultItemDecoration;
import java.util.Collections;
import java.util.List;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import androidx.core.view.ViewCompat;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import static com.jess.arms.utils.Preconditions.checkNotNull;
/**
* ================================================
* Description:
* <p>
* Created by MVPArmsTemplate on 01/16/2020 10:24
* <a href="mailto:jess.yan.effort@gmail.com">Contact me</a>
* <a href="https://github.com/JessYanCoding">Follow me</a>
* <a href="https://github.com/JessYanCoding/MVPArms">Star me</a>
* <a href="https://github.com/JessYanCoding/MVPArms/wiki">See me</a>
* <a href="https://github.com/JessYanCoding/MVPArmsTemplate">模版请保持更新</a>
* ================================================
*/
public class PrinterListActivity extends BaseActivity<PrintListPresenter> implements PrintListContract.View {
@BindView(R2.id.rc_print_list)
SwipeRecyclerView mRvPrintList;
@BindView(R2.id.printer_home_bar)
QMUITopBar topBar;
private PrinterListAdapter printListAdapter;
@Override
public void setupActivityComponent(@NonNull AppComponent appComponent) {
DaggerPrintListComponent //如找不到该类,请编译一下项目
.builder()
.appComponent(appComponent)
.view(this)
.build()
.inject(this);
}
@Override
public int initView(@Nullable Bundle savedInstanceState) {
return R.layout.printer_activity_list; //如果你不需要框架帮你设置 setContentView(id) 需要自行设置,请返回 0
}
@Override
public void initData(@Nullable Bundle savedInstanceState) {
// mPresenter.getPrinterList(GsaCloudApplication.getRestaurantId(mContext));
}
@Override
protected void onResume() {
super.onResume();
mPresenter.getPrinterList(GsaCloudApplication.getRestaurantId(mContext));
}
/**
* 創建右側刪除按鈕
*/
private SwipeMenuCreator mSwipeMenuCreator = (swipeLeftMenu, swipeRightMenu, position) -> {
int width = getResources().getDimensionPixelSize(R.dimen.dp_70);
// 1. MATCH_PARENT 自适应高度,保持和Item一样高;
// 2. 指定具体的高,比如80;
// 3. WRAP_CONTENT,自身高度,不推荐;
int height = ViewGroup.LayoutParams.MATCH_PARENT;
// 添加右侧的按鈕。
SwipeMenuItem deleteItem = new SwipeMenuItem(mContext).setBackground(
R.color.theme_color)
// .setImage(R.drawable.ic_action_delete)
.setText("刪除")
.setTextColor(Color.WHITE)
.setWidth(width)
.setHeight(height);
swipeRightMenu.addMenuItem(deleteItem);// 添加一个按钮到右侧侧菜单。
};
/**
* Item的拖拽/侧滑删除时,手指状态发生变化监听。
*/
private OnItemStateChangedListener mOnItemStateChangedListener = (viewHolder, actionState) -> {
if (actionState == OnItemStateChangedListener.ACTION_STATE_DRAG) {
// mActionBar.setSubtitle("状态:拖拽");
// // 拖拽的时候背景就透明了,这里我们可以添加一个特殊背景。
viewHolder.itemView.setBackgroundColor(ContextCompat.getColor(mContext, R.color.color_ccc));
} else if (actionState == OnItemStateChangedListener.ACTION_STATE_SWIPE) {
// mActionBar.setSubtitle("状态:滑动删除");
} else if (actionState == OnItemStateChangedListener.ACTION_STATE_IDLE) {
// mActionBar.setSubtitle("状态:手指松开");
// 在手松开的时候还原背景。
ViewCompat.setBackground(viewHolder.itemView,
ContextCompat.getDrawable(mContext, R.color.white));
}
};
@Override
public void initIntent() {
}
@Override
public void initTopBar() {
topBar.setTitle("打印機列表");
topBar.addLeftImageButton(R.drawable.icon_back, R.id.iv_left_back).setOnClickListener(v -> finish());
topBar.addRightTextButton("新增", R.id.printer_add).setOnClickListener(v -> startActivity(new Intent(mContext, PrinterAddActivity.class)));
}
@Override
public void initLanguage() {
}
@Override
public void initLayoutParams() {
}
@Override
public void initLayoutVisible() {
}
@Override
public void showLoading(String message) {
}
@Override
public void hideLoading() {
}
@Override
public void showMessage(@NonNull String message) {
checkNotNull(message);
ArmsUtils.snackbarText(message);
}
@Override
public void launchActivity(@NonNull Intent intent) {
checkNotNull(intent);
ArmsUtils.startActivity(intent);
}
@Override
public void killMyself() {
finish();
}
@Override
public void loadPrinterList(List<PrinterDeviceBean> deviceBeans) {
PrinterManager.getPrinterManager().setDeviceBeans(deviceBeans);
printListAdapter = new PrinterListAdapter(deviceBeans);
mRvPrintList.setLayoutManager(new LinearLayoutManager(this));
//分割线
mRvPrintList.addItemDecoration(new DefaultItemDecoration(ContextCompat.getColor(this, R.color.line_color)));
mRvPrintList.setOnItemClickListener((view, adapterPosition) -> {
//打開打印機詳情
Intent intent = new Intent(mContext, PrinterAddActivity.class);
intent.putExtra("printerInfo", deviceBeans.get(adapterPosition));
startActivity(intent);
});
//menu 右侧菜單點擊事件
mRvPrintList.setOnItemMenuClickListener((menuBridge, position) -> {
menuBridge.closeMenu();
// mPresenter.deletePrinter(deviceBeans.get(position).getId() + "");
deviceBeans.remove(position);
printListAdapter.notifyItemRemoved(position);
}); // Item的Menu点击。
mRvPrintList.setSwipeMenuCreator(mSwipeMenuCreator); // 菜单创建器。
mRvPrintList.setOnItemStateChangedListener(mOnItemStateChangedListener); // 监听Item的手指状态,拖拽、侧滑、松开。
mRvPrintList.setLongPressDragEnabled(true); // 长按拖拽,默认关闭。
mRvPrintList.setOnItemMoveListener(new OnItemMoveListener() {
@Override
public boolean onItemMove(RecyclerView.ViewHolder srcHolder, RecyclerView.ViewHolder targetHolder) {
// 不同的ViewType不能拖拽换位置。
if (srcHolder.getItemViewType() != targetHolder.getItemViewType()) return false;
// 真实的Position:通过ViewHolder拿到的position都需要减掉HeadView的数量。
int fromPosition = srcHolder.getAdapterPosition() - mRvPrintList.getHeaderCount();
int toPosition = targetHolder.getAdapterPosition() - mRvPrintList.getHeaderCount();
if (fromPosition < toPosition) {
for (int i = fromPosition; i < toPosition; i++) {
Collections.swap(deviceBeans, i, i + 1);
}
} else {
for (int i = fromPosition; i > toPosition; i--) {
Collections.swap(deviceBeans, i, i - 1);
}
}
printListAdapter.notifyItemMoved(fromPosition, toPosition);
return true;// 返回true表示处理了,返回false表示你没有处理。
}
@Override
public void onItemDismiss(RecyclerView.ViewHolder srcHolder) {
// int adapterPosition = srcHolder.getAdapterPosition();
// int position = adapterPosition - mRvPrintList.getHeaderCount();
}
});// 监听拖拽和侧滑删除,更新UI和数据源。
mRvPrintList.setAdapter(printListAdapter);
}
}
package com.joe.print.adapter; package com.joe.print.mvp.ui.adapter;
import com.chad.library.adapter.base.BaseQuickAdapter; import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder; import com.chad.library.adapter.base.BaseViewHolder;
import com.joe.print.R; import com.joe.print.R;
import com.joe.print.bean.BillingBean; import com.joe.print.mvp.model.bean.BillingBean;
import java.util.List; import java.util.List;
......
package com.joe.print.adapter; package com.joe.print.mvp.ui.adapter;
import com.chad.library.adapter.base.BaseQuickAdapter; import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder; import com.chad.library.adapter.base.BaseViewHolder;
import com.gingersoft.gsa.cloud.database.bean.Food; import com.gingersoft.gsa.cloud.database.bean.Food;
import com.joe.print.R; import com.joe.print.R;
import com.joe.print.bean.FoodBean;
import java.util.List; import java.util.List;
......
package com.joe.print.mvp.ui.adapter;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.gingersoft.gsa.cloud.database.bean.PrinterDeviceBean;
import com.joe.print.R;
import java.util.List;
import androidx.annotation.Nullable;
/**
* Created by Wyh on 2020/1/16.
*/
public class PrinterListAdapter extends BaseQuickAdapter<PrinterDeviceBean, BaseViewHolder> {
public PrinterListAdapter(@Nullable List<PrinterDeviceBean> data) {
super(R.layout.printer_item, data);
}
@Override
protected void convert(BaseViewHolder helper, PrinterDeviceBean item) {
helper.setText(R.id.tv_printer_name, item.getIp() +"");
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.qmuiteam.qmui.widget.QMUITopBar
android:id="@+id/add_printer_topbar"
android:layout_width="match_parent"
android:layout_height="@dimen/head_height" />
<LinearLayout
style="@style/print_add_printer_input_style"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.3"
android:text="打印機IP"
android:textColor="@color/normal_color"
android:textSize="@dimen/sp_14"
android:textStyle="bold" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.7"
android:orientation="horizontal">
<EditText
android:id="@+id/ip_edit_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="bottom"
android:hint="0"
android:text="192"
android:inputType="number"
android:maxLength="3"
android:minWidth="@dimen/dp_30"
android:singleLine="true"
android:textColor="@color/normal_color"
android:textCursorDrawable="@null"
android:textSize="15sp">
<requestFocus />
</EditText>
<TextView
android:id="@+id/dot_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:text="."
android:textColor="#000"
android:textSize="20sp"
android:textStyle="bold" />
<EditText
android:id="@+id/ip_edit_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="bottom"
android:hint="0"
android:text="168"
android:inputType="number"
android:maxLength="3"
android:minWidth="@dimen/dp_30"
android:singleLine="true"
android:textColor="@color/normal_color"
android:textCursorDrawable="@null"
android:textSize="15sp" />
<TextView
android:id="@+id/dot_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:text="."
android:textColor="#000"
android:textSize="20sp"
android:textStyle="bold" />
<EditText
android:id="@+id/ip_edit_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="bottom"
android:hint="0"
android:text="125"
android:inputType="number"
android:maxLength="3"
android:minWidth="@dimen/dp_30"
android:singleLine="true"
android:textColor="@color/normal_color"
android:textCursorDrawable="@null"
android:textSize="15sp" />
<TextView
android:id="@+id/dot_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:text="."
android:textColor="#000"
android:textSize="20sp"
android:textStyle="bold" />
<EditText
android:id="@+id/ip_edit_4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="bottom"
android:hint="0"
android:text="075"
android:inputType="number"
android:maxLength="3"
android:minWidth="@dimen/dp_30"
android:singleLine="true"
android:textColor="@color/normal_color"
android:textCursorDrawable="@null"
android:textSize="15sp" />
</LinearLayout>
</LinearLayout>
<include layout="@layout/include_dividing_line" />
<LinearLayout
style="@style/print_add_printer_input_style"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.3"
android:text="端口號"
android:textColor="@color/normal_color"
android:textSize="@dimen/sp_14"
android:textStyle="bold" />
<com.gingersoft.gsa.cloud.ui.view.MyEditText
android:id="@+id/add_printer_ed_port"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.7"
android:gravity="center_vertical"
app:ed_MaxLength="6"
app:ed_text="8856"
app:ed_hint="請輸入端口號"
app:ed_hintColor="@color/hint_color"
app:ed_textColor="@color/normal_color"
app:ed_textSize="@dimen/sp_14" />
</LinearLayout>
<include layout="@layout/include_dividing_line" />
<LinearLayout
style="@style/print_add_printer_input_style"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.3"
android:text="紙張規格"
android:textColor="@color/normal_color"
android:textSize="@dimen/sp_14"
android:textStyle="bold" />
<RadioGroup
android:id="@+id/printer_type"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.7"
android:checkedButton="@id/print_paper_size_58"
android:orientation="horizontal">
<RadioButton
android:id="@+id/print_paper_size_58"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="58mm"
android:textColor="@color/normal_color"
android:textSize="@dimen/sp_14" />
<RadioButton
android:id="@+id/print_paper_size_88"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/dp_10"
android:text="88mm"
android:textColor="@color/normal_color"
android:textSize="@dimen/sp_14" />
</RadioGroup>
</LinearLayout>
<include layout="@layout/include_dividing_line" />
<TextView
android:id="@+id/print_test"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/printer_add_input_paddingLeft"
android:layout_marginRight="@dimen/printer_add_input_paddingLeft"
android:gravity="center"
android:layout_marginTop="@dimen/dp_30"
android:paddingTop="@dimen/dp_10"
android:paddingBottom="@dimen/dp_10"
android:background="@drawable/shape_app_btn"
android:text="打印測試"
android:textColor="@color/white"
android:textSize="@dimen/sp_16" />
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.qmuiteam.qmui.widget.QMUITopBar
android:id="@+id/printer_home_bar"
android:layout_width="match_parent"
android:layout_height="@dimen/head_height"
android:fitsSystemWindows="true" />
<com.yanzhenjie.recyclerview.SwipeRecyclerView
android:id="@+id/rc_print_list"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
\ No newline at end of file
<?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="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/tv_printer_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="center"
android:padding="@dimen/dp_10"
android:textColor="@color/normal_color"
android:textSize="@dimen/dp_16" />
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="print_TranslucentTheme">
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:colorBackgroundCacheHint">@null</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowAnimationStyle">@android:style/Animation</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:navigationBarColor">@android:color/transparent</item>
</style>
</resources>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- 添加打印機 輸入信息的間距-->
<dimen name="printer_add_input_paddingLeft">@dimen/dp_10</dimen>
<dimen name="printer_add_input_paddingTop">@dimen/dp_20</dimen>
<dimen name="printer_add_input_paddingBottom">@dimen/dp_10</dimen>
</resources>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
</resources>
<item name="printer_add" type="id"/>
</resources>
\ No newline at end of file
...@@ -4,5 +4,19 @@ ...@@ -4,5 +4,19 @@
<item name="android:textColor">#333</item> <item name="android:textColor">#333</item>
<item name="android:textSize">16sp</item> <item name="android:textSize">16sp</item>
</style> </style>
<style name="print_TranslucentTheme" parent="Theme.AppCompat">
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:colorBackgroundCacheHint">@null</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowAnimationStyle">@android:style/Animation</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowContentOverlay">@null</item>
</style>
<style name="print_add_printer_input_style">
<item name="android:gravity">center_vertical</item>
<item name="android:paddingLeft">@dimen/printer_add_input_paddingLeft</item>
<item name="android:paddingTop">@dimen/printer_add_input_paddingTop</item>
<item name="android:paddingBottom">@dimen/printer_add_input_paddingBottom</item>
</style>
</resources> </resources>
\ No newline at end of file
package com.joe.print;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* Example local unit test, which will execute on the development machine (host).
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() {
assertEquals(4, 2 + 2);
}
}
\ No newline at end of file
...@@ -39,7 +39,8 @@ dependencies { ...@@ -39,7 +39,8 @@ dependencies {
testImplementation 'junit:junit:4.12' testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0' androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation rootProject.ext.dependencies["fastjson"]
//日誌管理 //日誌管理
implementation 'com.elvishew:xlog:1.6.1' implementation 'com.elvishew:xlog:1.6.1'
implementation rootProject.ext.dependencies["zxing"]
} }
package com.gingersoft.gsa.cloud.base.bean; package com.gingersoft.gsa.cloud.base.common.bean;
/** /**
* 作者:ELEGANT_BIN * Created by Wyh on 2020/1/15.
* 版本:1.6.0
* 创建日期:2020-01-02
* 修订历史:2020-01-02
* 描述:
*/ */
public class BaseRespose { public class BaseResult {
/** /**
* success : true * success : true
* sysTime : 1577960831043 * sysTime : 1579079565872
* data : 40560
*/ */
private boolean success; private boolean success;
private String errMsg;
private long sysTime; private long sysTime;
private Object data;
public boolean isSuccess() { public boolean isSuccess() {
return success; return success;
...@@ -27,14 +23,6 @@ public class BaseRespose { ...@@ -27,14 +23,6 @@ public class BaseRespose {
this.success = success; this.success = success;
} }
public String getErrMsg() {
return errMsg;
}
public void setErrMsg(String errMsg) {
this.errMsg = errMsg;
}
public long getSysTime() { public long getSysTime() {
return sysTime; return sysTime;
} }
...@@ -42,4 +30,12 @@ public class BaseRespose { ...@@ -42,4 +30,12 @@ public class BaseRespose {
public void setSysTime(long sysTime) { public void setSysTime(long sysTime) {
this.sysTime = sysTime; this.sysTime = sysTime;
} }
public Object getData() {
return data;
}
public void setData(Object data) {
this.data = data;
}
} }
package com.gingersoft.gsa.cloud.base.bean; package com.gingersoft.gsa.cloud.base.common.bean;
import com.gingersoft.gsa.cloud.database.bean.Food; import com.gingersoft.gsa.cloud.database.bean.Food;
......
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