Skip to content

Commit

Permalink
添加BaseMvvmFragment、升级CameraX与RxJava
Browse files Browse the repository at this point in the history
  • Loading branch information
sdwfqin committed Jun 9, 2020
1 parent 120c46b commit 657ae80
Show file tree
Hide file tree
Showing 20 changed files with 93 additions and 75 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,11 @@
# 导入指南
``` groovy
def quicklib = "4.0.5"
def quicklib = "4.1.0"
// quicklib(Base)
implementation "com.sdwfqin.quicklib:quicklib:$quicklib"
annotationProcessor "com.qmuiteam:arch-compiler:2.0.0-alpha09"
annotationProcessor "com.qmuiteam:arch-compiler:2.0.0-alpha10"
annotationProcessor "com.alibaba:arouter-compiler:1.2.2"
// 支付模块
implementation "com.sdwfqin.quicklib:paylib:$quicklib"
Expand Down Expand Up @@ -151,6 +151,7 @@ implementation "com.sdwfqin.quicklib:widget:$quicklib"
| BaseMvpFragment | 支持MVP的基类Fragment |
| RxPresenter | Presenter层封装 |
| BaseMvvmActivity | 支持MVVM的基类Activity |
| BaseMvvmFragment | 支持MVVM的基类Fragment |
| BaseViewModel | ViewModel基类 |
| WechatShareTools | 微信分享工具类 |
| ImagePreviewActivity | 图片预览Activity(多图/单图) |
Expand Down
Binary file modified app/release/app-release.apk
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.adapter.rxjava3.RxJava3CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

/**
Expand Down Expand Up @@ -50,7 +50,7 @@ private Retrofit createRetrofit() {
// 设置OkHttpclient
.client(initOkhttpClient())
// RxJava2
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.addCallAdapterFactory(RxJava3CallAdapterFactory.create())
// Gson
.addConverterFactory(GsonConverterFactory.create())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

import java.lang.ref.WeakReference;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;
import io.reactivex.rxjava3.core.Observer;
import io.reactivex.rxjava3.disposables.Disposable;

/**
* 描述:Retrofit Subscriber 封装
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import java.util.Map;

import io.reactivex.Observable;
import io.reactivex.rxjava3.core.Observable;
import retrofit2.http.GET;
import retrofit2.http.QueryMap;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.adapter.rxjava3.RxJava3CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
import retrofit2.converter.scalars.ScalarsConverterFactory;

Expand Down Expand Up @@ -49,7 +49,7 @@ private Retrofit createRetrofit() {
// 设置OkHttpclient
.client(initOkhttpClient())
// RxJava2
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.addCallAdapterFactory(RxJava3CallAdapterFactory.create())
// 字符串
.addConverterFactory(ScalarsConverterFactory.create())
// Gson
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

import java.lang.ref.WeakReference;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;
import io.reactivex.rxjava3.core.Observer;
import io.reactivex.rxjava3.disposables.Disposable;

/**
* 描述:Retrofit Subscriber 封装
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,12 @@ private void initCamera() {

private void bindPreview(@NonNull ProcessCameraProvider cameraProvider) {

mPreview.setSurfaceProvider(mBinding.viewFinder.createSurfaceProvider());
Camera camera = cameraProvider.bindToLifecycle(this, mCameraSelector, mImageCapture, mImageAnalysis, mPreview);

mCameraInfo = camera.getCameraInfo();
mCameraControl = camera.getCameraControl();

mPreview.setSurfaceProvider(mBinding.viewFinder.createSurfaceProvider(mCameraInfo));
initCameraListener();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,38 +37,10 @@ public class ShowSvgActivity extends SampleBaseActivity<ActivityShowSvgBinding>
"<g fill=\"#000000\">\n" +
"\t<rect x=\"21.6\" y=\"29.3\" class=\"st0\" width=\"126.9\" height=\"53.8\"/>\n" +
"\t<rect x=\"148.4\" y=\"29.3\" class=\"st1\" width=\"126.9\" height=\"53.8\"/>\n" +
"\t<rect x=\"274.5\" y=\"29.3\" class=\"st1\" width=\"126.9\" height=\"53.8\"/>\n" +
"\t<rect x=\"480.6\" y=\"29.3\" class=\"st1\" width=\"126.9\" height=\"53.8\"/>\n" +
"\t<rect x=\"633.9\" y=\"29.3\" class=\"st1\" width=\"126.9\" height=\"53.8\"/>\n" +
"\t<rect x=\"21.6\" y=\"112.5\" class=\"st1\" width=\"199.2\" height=\"53.8\"/>\n" +
"\t<rect x=\"21.6\" y=\"166.3\" class=\"st1\" width=\"199.2\" height=\"53.8\"/>\n" +
"\t<rect x=\"21.6\" y=\"220.1\" class=\"st1\" width=\"199.2\" height=\"53.7\"/>\n" +
"\t<rect x=\"21.6\" y=\"273.8\" class=\"st1\" width=\"199.2\" height=\"53.8\"/>\n" +
"\t<rect x=\"244.3\" y=\"112.5\" class=\"st1\" width=\"141.2\" height=\"215\"/>\n" +
"\t<rect x=\"409.1\" y=\"112.5\" class=\"st1\" width=\"199.2\" height=\"96.3\"/>\n" +
"\t<rect x=\"409.1\" y=\"231.3\" class=\"st1\" width=\"199.2\" height=\"96.3\"/>\n" +
"\t<rect x=\"633.1\" y=\"112.9\" class=\"st1\" width=\"126.9\" height=\"95.9\"/>\n" +
"\t<rect x=\"633.1\" y=\"231.7\" class=\"st1\" width=\"126.9\" height=\"95.9\"/>\n" +
"\t<rect x=\"21.6\" y=\"359.5\" class=\"st1\" width=\"199.2\" height=\"53.8\"/>\n" +
"\t<rect x=\"244.4\" y=\"359.5\" class=\"st1\" width=\"343.7\" height=\"53.8\"/>\n" +
"</g>\n" +
"<g id=\"文字图层\">\n" +
"\t<text transform=\"matrix(1 0 0 1 653.7477 62.8554)\" class=\"st2 st3\">危险化学品仓库</text>\n" +
"\t<text transform=\"matrix(1 0 0 1 86.2301 148.7154)\" class=\"st2 st3\">生产车间一</text>\n" +
"\t<text transform=\"matrix(1 0 0 1 86.2301 201.7154)\" class=\"st2 st3\">生产车间二</text>\n" +
"\t<text transform=\"matrix(1 0 0 1 86.2301 254.7154)\" class=\"st2 st3\">生产车间三</text>\n" +
"\t<text transform=\"matrix(1 0 0 1 86.2301 308.7154)\" class=\"st2 st3\">生产车间四</text>\n" +
"\t<text transform=\"matrix(1 0 0 1 279.8901 221.3546)\" class=\"st2 st3\">物料存放区</text>\n" +
"\t<text transform=\"matrix(1 0 0 1 100.2301 391.7154)\" class=\"st2 st3\">门卫室</text>\n" +
"\t<text transform=\"matrix(1 0 0 1 402.1901 391.715)\" class=\"st2 st3\">花坛</text>\n" +
"\t<text transform=\"matrix(1 0 0 1 480.6501 166.2996)\" class=\"st2 st3\">研发大楼</text>\n" +
"\t<text transform=\"matrix(1 0 0 1 487.6502 279.6246)\" class=\"st2 st3\">办公楼</text>\n" +
"\t<text transform=\"matrix(1 0 0 1 675.5451 166.2996)\" class=\"st2 st3\">停车场</text>\n" +
"\t<text transform=\"matrix(1 0 0 1 682.5451 284.7154)\" class=\"st2 st3\">食堂</text>\n" +
"\t<text transform=\"matrix(1 0 0 1 65.7729 63.0264)\" class=\"st2 st3\">配电房</text>\n" +
"\t<text transform=\"matrix(1 0 0 1 188.7477 63.4633)\" class=\"st2 st3\">空压机房</text>\n" +
"\t<text transform=\"matrix(1 0 0 1 307.7477 65.4304)\" class=\"st2 st3\">维修车间</text>\n" +
"\t<text transform=\"matrix(1 0 0 1 518.7477 63.7154)\" class=\"st2 st3\">成品仓库</text>\n" +
"\t<text transform=\"matrix(1 0 0 1 65.7729 63.0264)\" class=\"st2 st3\">测试1</text>\n" +
"\t<text transform=\"matrix(1 0 0 1 188.7477 63.4633)\" class=\"st2 st3\">测试2</text>\n" +
"</g>\n" +
"</svg>";

Expand All @@ -80,7 +52,7 @@ protected ActivityShowSvgBinding getViewBinding() {
@Override
protected void initEventAndData() {

mTopBar.setTitle("展示SVG图片");
mTopBar.setTitle("展示原生SVG图片");
mTopBar.addLeftBackImageButton()
.setOnClickListener(v -> finish());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
import java.util.ArrayList;
import java.util.List;

import io.reactivex.Observable;
import io.reactivex.ObservableOnSubscribe;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.core.ObservableOnSubscribe;

/**
* 仿京东分类列表
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class MainFragment extends BaseFragment<FragmentMainBinding> {
"跑马灯Demo",
"Camerax(支持二维码识别)",
"VLayoutDemo",
"展示SVG图片",
"展示原生SVG图片",
"WebView",
"悬浮窗与截图",
"支持换肤的弹窗",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
import java.io.FileOutputStream;
import java.nio.ByteBuffer;

import io.reactivex.Observable;
import io.reactivex.ObservableOnSubscribe;
import io.reactivex.disposables.Disposable;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.core.ObservableOnSubscribe;
import io.reactivex.rxjava3.disposables.Disposable;

/**
* 悬浮窗View Demo
Expand Down
26 changes: 12 additions & 14 deletions config.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
ext {

versionCode = 40095
versionName = "4.0.5"
versionCode = 41000
versionName = "4.1.0"

qmui = "2.0.0-alpha09"
okhttp = "4.6.0"
retrofit = "2.8.1"
qmui = "2.0.0-alpha10"
okhttp = "4.7.2"
retrofit = "2.9.0"
glide = "4.11.0"
vlayout = "1.2.36"
camerax_version = "1.0.0-beta03"
camerax_version = "1.0.0-beta04"
smartrefresh = "2.0.0"

androidVersion = [
Expand All @@ -31,10 +31,8 @@ ext {

eventDependencies = [
// rxjava
"rxjava" : "io.reactivex.rxjava2:rxjava:2.2.19",
"rxandroid": "io.reactivex.rxjava2:rxandroid:2.1.1",
// "rxandroid": "io.reactivex.rxjava3:rxandroid:3.0.0",
// "rxjava" : "io.reactivex.rxjava3:rxjava:3.0.1",
"rxandroid": "io.reactivex.rxjava3:rxandroid:3.0.0",
"rxjava" : "io.reactivex.rxjava3:rxjava:3.0.4",
// eventbus
"eventbus" : "org.greenrobot:eventbus:3.2.0",
]
Expand All @@ -43,7 +41,7 @@ ext {
"retrofit" : "com.squareup.retrofit2:retrofit:$retrofit",
"converter-gson" : "com.squareup.retrofit2:converter-gson:$retrofit",
"converter-scalars" : "com.squareup.retrofit2:converter-scalars:$retrofit",
"adapter-rxjava2" : "com.squareup.retrofit2:adapter-rxjava2:$retrofit",
"adapter-rxjava2" : "com.squareup.retrofit2:adapter-rxjava3:$retrofit",
"okhttp" : "com.squareup.okhttp3:okhttp:$okhttp",
"logging-interceptor": "com.squareup.okhttp3:logging-interceptor:$okhttp",
]
Expand All @@ -53,7 +51,7 @@ ext {
"qmui" : "com.qmuiteam:qmui:$qmui",
"arch" : "com.qmuiteam:arch:$qmui",
// brvah
"brvah" : "com.github.CymChad:BaseRecyclerViewAdapterHelper:3.0.3",
"brvah" : "com.github.CymChad:BaseRecyclerViewAdapterHelper:3.0.4",
// smartrefresh
"smartrefresh" : "com.scwang.smart:refresh-layout-kernel:$smartrefresh",
"smartrefresh-classics": "com.scwang.smart:refresh-header-classics:$smartrefresh",
Expand All @@ -70,15 +68,15 @@ ext {
"matisse" : "com.zhihu.android:matisse:0.5.3-beta3",
"androidsvg" : "com.caverock:androidsvg-aar:1.4",
"camera-camera2" : "androidx.camera:camera-camera2:${camerax_version}",
"camera-view" : "androidx.camera:camera-view:1.0.0-alpha10",
"camera-view" : "androidx.camera:camera-view:1.0.0-alpha11",
"camera-lifecycle" : "androidx.camera:camera-lifecycle:${camerax_version}",
]

utilsDependencies = [
// easypermissions
"easypermissions": "pub.devrel:easypermissions:3.0.0",
// utils
"utilcodex" : "com.blankj:utilcodex:1.28.4",
"utilcodex" : "com.blankj:utilcodex:1.29.0",
// agentweb
"agentweb" : "com.just.agentweb:agentweb:4.1.3",
// arouter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@

import java.util.List;

import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.disposables.Disposable;
import io.reactivex.rxjava3.disposables.CompositeDisposable;
import io.reactivex.rxjava3.disposables.Disposable;
import pub.devrel.easypermissions.AfterPermissionGranted;
import pub.devrel.easypermissions.AppSettingsDialog;
import pub.devrel.easypermissions.EasyPermissions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.disposables.Disposable;
import io.reactivex.rxjava3.disposables.CompositeDisposable;
import io.reactivex.rxjava3.disposables.Disposable;

/**
* 描述:Fragment基类
Expand Down Expand Up @@ -92,6 +92,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
mInflater = onGetLayoutInflater(savedInstanceState);
initPresenter();
initViewModel();
initEventAndData();
initClickListener();
// 界面加载完成
Expand Down Expand Up @@ -272,6 +273,10 @@ public void unSubscribe() {
}
}

protected void initViewModel() {

}

protected void initPresenter() {

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.qmuiteam.qmui.widget.dialog.QMUITipDialog;

import io.reactivex.disposables.Disposable;
import io.reactivex.rxjava3.disposables.Disposable;

/**
* 描述:View的基类
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.sdwfqin.quicklib.base.BaseActivity;

/**
* 描述:Mvp Activity基类
* 描述:Mvvm Activity基类
*
* @author 张钦
*/
Expand Down Expand Up @@ -36,6 +36,6 @@ protected void initViewModel() {
* 通用网络异常回掉
*/
protected void commonNetworkErrorListener(Throwable throwable) {
// 其实这里可以写一下默认处理方式
// TODO 其实这里可以写一下默认处理方式,可以在业务模块写网络异常处理
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.sdwfqin.quicklib.mvvm;

import androidx.viewbinding.ViewBinding;

import com.sdwfqin.quicklib.base.BaseActivity;
import com.sdwfqin.quicklib.base.BaseFragment;

/**
* 描述:Mvvm Fragment基类
*
* @author 张钦
*/
public abstract class BaseMvvmFragment<V extends ViewBinding, VM extends BaseViewModel> extends BaseFragment<V> {

protected VM mVm;

@Override
protected void initViewModel() {
mVm = getViewModel();

mVm.isLoading.observe(getViewLifecycleOwner(), isLoading -> {
if (isLoading) {
showProgress();
} else {
hideProgress();
}
});
mVm.networkError.observe(this, this::commonNetworkErrorListener);
}

/**
* 获取ViewModel
*/
protected abstract VM getViewModel();

/**
* 通用网络异常回掉
*/
protected void commonNetworkErrorListener(Throwable throwable) {
// TODO 其实这里可以写一下默认处理方式,可以在业务模块写网络异常处理
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.sdwfqin.quicklib.utils.rx;

import io.reactivex.FlowableTransformer;
import io.reactivex.ObservableTransformer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
import io.reactivex.rxjava3.core.FlowableTransformer;
import io.reactivex.rxjava3.core.ObservableTransformer;
import io.reactivex.rxjava3.schedulers.Schedulers;

/**
* 描述:RxJava线程切换工具类
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.util.concurrent.TimeUnit;

import io.reactivex.Observable;
import io.reactivex.rxjava3.core.Observable;

/**
* 描述:RxJava定时任务
Expand Down

0 comments on commit 657ae80

Please sign in to comment.