From b3eb1e96420b0703b95524c9631e6bacd3811398 Mon Sep 17 00:00:00 2001 From: zengxianze <603883033@qq.com> Date: Thu, 14 Nov 2019 15:58:39 +0800 Subject: [PATCH 01/11] Migrate AndroidX Migrate AndroidX --- app/build.gradle | 5 +- app/src/main/AndroidManifest.xml | 19 ++-- .../mvvmhabit/app/AppViewModelFactory.java | 9 +- .../twinklingrefreshlayout/ViewAdapter.java | 4 +- .../goldze/mvvmhabit/data/DemoRepository.java | 5 +- .../source/local/LocalDataSourceImpl.java | 1 - .../goldze/mvvmhabit/entity/FormEntity.java | 3 +- .../adapter/BaseFragmentPagerAdapter.java | 8 +- .../ui/base/fragment/BasePagerFragment.java | 9 +- .../ui/base/viewmodel/ToolbarViewModel.java | 6 +- .../mvvmhabit/ui/form/FormFragment.java | 8 +- .../mvvmhabit/ui/form/FormViewModel.java | 4 +- .../mvvmhabit/ui/login/LoginActivity.java | 6 +- .../mvvmhabit/ui/login/LoginViewModel.java | 6 +- .../mvvmhabit/ui/main/DemoActivity.java | 7 +- .../mvvmhabit/ui/main/DemoViewModel.java | 6 +- .../mvvmhabit/ui/network/NetWorkFragment.java | 8 +- .../ui/network/NetWorkItemViewModel.java | 6 +- .../ui/network/NetWorkViewModel.java | 6 +- .../ui/network/detail/DetailViewModel.java | 4 +- .../rv_multi/MultiRecycleHeadViewModel.java | 3 +- .../MultiRecycleLeftItemViewModel.java | 5 +- .../MultiRecycleRightItemViewModel.java | 5 +- .../ui/rv_multi/MultiRecycleViewFragment.java | 2 +- .../ui/rv_multi/MultiRecycleViewModel.java | 7 +- .../ui/tab_bar/activity/TabBarActivity.java | 6 +- .../ui/tab_bar/fragment/TabBar1Fragment.java | 2 +- .../ui/tab_bar/fragment/TabBar2Fragment.java | 2 +- .../ui/tab_bar/fragment/TabBar3Fragment.java | 2 +- .../ui/tab_bar/fragment/TabBar4Fragment.java | 2 +- .../viewpager/activity/ViewPagerActivity.java | 6 +- .../adapter/ViewPagerBindingAdapter.java | 2 +- .../viewpager/vm/ViewPagerItemViewModel.java | 3 +- .../ui/viewpager/vm/ViewPagerViewModel.java | 7 +- .../ui/vp_frg/ViewPagerGroupFragment.java | 5 +- .../goldze/mvvmhabit/utils/HttpsUtils.java | 3 - .../main/res/layout/fragment_base_pager.xml | 4 +- app/src/main/res/layout/fragment_multi_rv.xml | 4 +- app/src/main/res/layout/fragment_network.xml | 4 +- .../main/res/layout/fragment_viewpager.xml | 12 +-- app/src/main/res/layout/layout_toolbar.xml | 4 +- .../main/res/xml/network_security_config.xml | 4 + config.gradle | 25 +++--- gradle.properties | 5 +- .../me/goldze/mvvmhabit/base/AppManager.java | 3 +- .../goldze/mvvmhabit/base/BaseActivity.java | 14 +-- .../mvvmhabit/base/BaseApplication.java | 2 +- .../goldze/mvvmhabit/base/BaseFragment.java | 14 +-- .../goldze/mvvmhabit/base/BaseViewModel.java | 10 +-- .../mvvmhabit/base/ContainerActivity.java | 12 +-- .../goldze/mvvmhabit/base/IBaseViewModel.java | 9 +- .../goldze/mvvmhabit/base/ItemViewModel.java | 3 +- .../mvvmhabit/base/MultiItemViewModel.java | 3 +- .../mvvmhabit/base/ViewModelFactory.java | 7 +- .../binding/command/BindingCommand.java | 2 - .../binding/command/BindingFunction.java | 2 - .../binding/command/ResponseCommand.java | 2 - .../viewadapter/checkbox/ViewAdapter.java | 2 +- .../viewadapter/edittext/ViewAdapter.java | 2 +- .../viewadapter/image/ViewAdapter.java | 4 +- .../viewadapter/listview/ViewAdapter.java | 2 +- .../viewadapter/mswitch/ViewAdapter.java | 6 +- .../viewadapter/radiogroup/ViewAdapter.java | 6 +- .../viewadapter/recyclerview/DividerLine.java | 3 +- .../recyclerview/LayoutManagers.java | 88 +++++++++++++++++++ .../recyclerview/LineManagers.java | 2 +- .../viewadapter/recyclerview/ViewAdapter.java | 11 ++- .../viewadapter/scrollview/ViewAdapter.java | 4 +- .../viewadapter/spinner/ViewAdapter.java | 3 +- .../viewadapter/swiperefresh/ViewAdapter.java | 5 +- .../binding/viewadapter/view/ViewAdapter.java | 2 +- .../viewgroup/IBindingItemViewModel.java | 5 +- .../viewadapter/viewgroup/ViewAdapter.java | 10 +-- .../viewadapter/viewpager/ViewAdapter.java | 7 +- .../viewadapter/webview/ViewAdapter.java | 3 +- .../me/goldze/mvvmhabit/bus/Messenger.java | 1 - .../java/me/goldze/mvvmhabit/bus/RxBus.java | 1 - .../goldze/mvvmhabit/bus/RxBusSubscriber.java | 1 - .../goldze/mvvmhabit/bus/RxSubscriptions.java | 2 - .../mvvmhabit/bus/event/SingleLiveEvent.java | 15 ++-- .../mvvmhabit/bus/event/SnackbarMessage.java | 8 +- .../me/goldze/mvvmhabit/crash/CaocConfig.java | 9 +- .../mvvmhabit/crash/CaocInitProvider.java | 5 +- .../crash/CustomActivityOnCrash.java | 7 +- .../mvvmhabit/crash/DefaultErrorActivity.java | 6 +- .../mvvmhabit/http/ApiDisposableObserver.java | 1 - .../me/goldze/mvvmhabit/http/NetworkUtil.java | 1 - .../http/interceptor/CacheInterceptor.java | 2 - .../me/goldze/mvvmhabit/utils/ImageUtils.java | 2 - .../mvvmhabit/utils/MaterialDialogUtils.java | 3 +- .../me/goldze/mvvmhabit/utils/RxUtils.java | 2 +- .../me/goldze/mvvmhabit/utils/SPUtils.java | 3 +- .../me/goldze/mvvmhabit/utils/ToastUtils.java | 12 +-- .../java/me/goldze/mvvmhabit/utils/Utils.java | 3 +- .../mvvmhabit/utils/compression/Luban.java | 2 +- .../utils/compression/Preconditions.java | 2 +- .../utils/constant/MemoryConstants.java | 4 +- .../utils/constant/TimeConstants.java | 4 +- 98 files changed, 325 insertions(+), 273 deletions(-) create mode 100644 app/src/main/res/xml/network_security_config.xml create mode 100644 mvvmhabit/src/main/java/me/goldze/mvvmhabit/binding/viewadapter/recyclerview/LayoutManagers.java diff --git a/app/build.gradle b/app/build.gradle index 4c371cbb..ed4eed5b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -8,7 +8,6 @@ android { targetSdkVersion rootProject.ext.android.targetSdkVersion versionCode rootProject.ext.android.versionCode versionName rootProject.ext.android.versionName - testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { release { @@ -39,6 +38,6 @@ dependencies { implementation project(':mvvmhabit') // implementation rootProject.ext.dependencies.MVVMHabit //内存泄漏测试 - debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.6.2' - debugImplementation 'com.squareup.leakcanary:leakcanary-support-fragment:1.6.2' + debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.6.3' + debugImplementation 'com.squareup.leakcanary:leakcanary-support-fragment:1.6.3' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index f717cdda..70c160aa 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,9 +1,9 @@ + package="com.goldze.mvvmhabit"> - + @@ -11,13 +11,14 @@ + android:name=".app.AppApplication" + android:allowBackup="true" + android:icon="@mipmap/ic_launcher" + android:label="@string/app_name" + android:networkSecurityConfig="@xml/network_security_config" + android:roundIcon="@mipmap/ic_launcher_round" + android:supportsRtl="true" + android:theme="@style/AppTheme"> diff --git a/app/src/main/java/com/goldze/mvvmhabit/app/AppViewModelFactory.java b/app/src/main/java/com/goldze/mvvmhabit/app/AppViewModelFactory.java index 01cdf05f..e59ed8fb 100644 --- a/app/src/main/java/com/goldze/mvvmhabit/app/AppViewModelFactory.java +++ b/app/src/main/java/com/goldze/mvvmhabit/app/AppViewModelFactory.java @@ -2,15 +2,16 @@ import android.annotation.SuppressLint; import android.app.Application; -import android.arch.lifecycle.ViewModel; -import android.arch.lifecycle.ViewModelProvider; -import android.support.annotation.NonNull; -import android.support.annotation.VisibleForTesting; import com.goldze.mvvmhabit.data.DemoRepository; import com.goldze.mvvmhabit.ui.login.LoginViewModel; import com.goldze.mvvmhabit.ui.network.NetWorkViewModel; +import androidx.annotation.NonNull; +import androidx.annotation.VisibleForTesting; +import androidx.lifecycle.ViewModel; +import androidx.lifecycle.ViewModelProvider; + /** * Created by goldze on 2019/3/26. */ diff --git a/app/src/main/java/com/goldze/mvvmhabit/binding/twinklingrefreshlayout/ViewAdapter.java b/app/src/main/java/com/goldze/mvvmhabit/binding/twinklingrefreshlayout/ViewAdapter.java index 1351122c..fa28a221 100644 --- a/app/src/main/java/com/goldze/mvvmhabit/binding/twinklingrefreshlayout/ViewAdapter.java +++ b/app/src/main/java/com/goldze/mvvmhabit/binding/twinklingrefreshlayout/ViewAdapter.java @@ -1,11 +1,9 @@ package com.goldze.mvvmhabit.binding.twinklingrefreshlayout; - -import android.databinding.BindingAdapter; - import com.lcodecore.tkrefreshlayout.RefreshListenerAdapter; import com.lcodecore.tkrefreshlayout.TwinklingRefreshLayout; +import androidx.databinding.BindingAdapter; import me.goldze.mvvmhabit.binding.command.BindingCommand; diff --git a/app/src/main/java/com/goldze/mvvmhabit/data/DemoRepository.java b/app/src/main/java/com/goldze/mvvmhabit/data/DemoRepository.java index 98d6970b..b0f25a8d 100644 --- a/app/src/main/java/com/goldze/mvvmhabit/data/DemoRepository.java +++ b/app/src/main/java/com/goldze/mvvmhabit/data/DemoRepository.java @@ -1,12 +1,11 @@ package com.goldze.mvvmhabit.data; -import android.support.annotation.NonNull; -import android.support.annotation.VisibleForTesting; - import com.goldze.mvvmhabit.data.source.HttpDataSource; import com.goldze.mvvmhabit.data.source.LocalDataSource; import com.goldze.mvvmhabit.entity.DemoEntity; +import androidx.annotation.NonNull; +import androidx.annotation.VisibleForTesting; import io.reactivex.Observable; import me.goldze.mvvmhabit.base.BaseModel; import me.goldze.mvvmhabit.http.BaseResponse; diff --git a/app/src/main/java/com/goldze/mvvmhabit/data/source/local/LocalDataSourceImpl.java b/app/src/main/java/com/goldze/mvvmhabit/data/source/local/LocalDataSourceImpl.java index a306b78c..2037e1ef 100644 --- a/app/src/main/java/com/goldze/mvvmhabit/data/source/local/LocalDataSourceImpl.java +++ b/app/src/main/java/com/goldze/mvvmhabit/data/source/local/LocalDataSourceImpl.java @@ -1,7 +1,6 @@ package com.goldze.mvvmhabit.data.source.local; import com.goldze.mvvmhabit.data.source.LocalDataSource; -import com.goldze.mvvmhabit.data.source.http.service.DemoApiService; import me.goldze.mvvmhabit.utils.SPUtils; diff --git a/app/src/main/java/com/goldze/mvvmhabit/entity/FormEntity.java b/app/src/main/java/com/goldze/mvvmhabit/entity/FormEntity.java index 7ac53432..70a9fb21 100644 --- a/app/src/main/java/com/goldze/mvvmhabit/entity/FormEntity.java +++ b/app/src/main/java/com/goldze/mvvmhabit/entity/FormEntity.java @@ -1,9 +1,10 @@ package com.goldze.mvvmhabit.entity; -import android.databinding.BaseObservable; import android.os.Parcel; import android.os.Parcelable; +import androidx.databinding.BaseObservable; + /** * Created by goldze on 2017/7/17. */ diff --git a/app/src/main/java/com/goldze/mvvmhabit/ui/base/adapter/BaseFragmentPagerAdapter.java b/app/src/main/java/com/goldze/mvvmhabit/ui/base/adapter/BaseFragmentPagerAdapter.java index 132e074d..2ee0da05 100644 --- a/app/src/main/java/com/goldze/mvvmhabit/ui/base/adapter/BaseFragmentPagerAdapter.java +++ b/app/src/main/java/com/goldze/mvvmhabit/ui/base/adapter/BaseFragmentPagerAdapter.java @@ -1,11 +1,11 @@ package com.goldze.mvvmhabit.ui.base.adapter; -import android.support.v4.app.Fragment; -import android.support.v4.app.FragmentManager; -import android.support.v4.app.FragmentPagerAdapter; - import java.util.List; +import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentManager; +import androidx.fragment.app.FragmentPagerAdapter; + /** * Created by goldze on 2017/7/17. * FragmentPager适配器 diff --git a/app/src/main/java/com/goldze/mvvmhabit/ui/base/fragment/BasePagerFragment.java b/app/src/main/java/com/goldze/mvvmhabit/ui/base/fragment/BasePagerFragment.java index beac1847..ee4a631d 100644 --- a/app/src/main/java/com/goldze/mvvmhabit/ui/base/fragment/BasePagerFragment.java +++ b/app/src/main/java/com/goldze/mvvmhabit/ui/base/fragment/BasePagerFragment.java @@ -1,20 +1,19 @@ package com.goldze.mvvmhabit.ui.base.fragment; - import android.os.Bundle; -import android.support.annotation.Nullable; -import android.support.design.widget.TabLayout; -import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.ViewGroup; -import com.goldze.mvvmhabit.R; import com.goldze.mvvmhabit.BR; +import com.goldze.mvvmhabit.R; import com.goldze.mvvmhabit.databinding.FragmentBasePagerBinding; import com.goldze.mvvmhabit.ui.base.adapter.BaseFragmentPagerAdapter; +import com.google.android.material.tabs.TabLayout; import java.util.List; +import androidx.annotation.Nullable; +import androidx.fragment.app.Fragment; import me.goldze.mvvmhabit.base.BaseFragment; import me.goldze.mvvmhabit.base.BaseViewModel; diff --git a/app/src/main/java/com/goldze/mvvmhabit/ui/base/viewmodel/ToolbarViewModel.java b/app/src/main/java/com/goldze/mvvmhabit/ui/base/viewmodel/ToolbarViewModel.java index a9c02f68..681be4e5 100644 --- a/app/src/main/java/com/goldze/mvvmhabit/ui/base/viewmodel/ToolbarViewModel.java +++ b/app/src/main/java/com/goldze/mvvmhabit/ui/base/viewmodel/ToolbarViewModel.java @@ -1,11 +1,11 @@ package com.goldze.mvvmhabit.ui.base.viewmodel; import android.app.Application; -import android.databinding.ObservableField; -import android.databinding.ObservableInt; -import android.support.annotation.NonNull; import android.view.View; +import androidx.annotation.NonNull; +import androidx.databinding.ObservableField; +import androidx.databinding.ObservableInt; import me.goldze.mvvmhabit.base.BaseModel; import me.goldze.mvvmhabit.base.BaseViewModel; import me.goldze.mvvmhabit.binding.command.BindingAction; diff --git a/app/src/main/java/com/goldze/mvvmhabit/ui/form/FormFragment.java b/app/src/main/java/com/goldze/mvvmhabit/ui/form/FormFragment.java index 8de8b15d..f1be9df1 100644 --- a/app/src/main/java/com/goldze/mvvmhabit/ui/form/FormFragment.java +++ b/app/src/main/java/com/goldze/mvvmhabit/ui/form/FormFragment.java @@ -1,11 +1,7 @@ package com.goldze.mvvmhabit.ui.form; import android.app.DatePickerDialog; -import android.arch.lifecycle.Observer; -import android.databinding.Observable; import android.os.Bundle; -import android.support.annotation.Nullable; -import android.support.v7.app.AppCompatActivity; import android.view.LayoutInflater; import android.view.ViewGroup; import android.widget.DatePicker; @@ -17,6 +13,10 @@ import java.util.Calendar; +import androidx.annotation.Nullable; +import androidx.appcompat.app.AppCompatActivity; +import androidx.databinding.Observable; +import androidx.lifecycle.Observer; import me.goldze.mvvmhabit.base.BaseFragment; import me.goldze.mvvmhabit.utils.MaterialDialogUtils; diff --git a/app/src/main/java/com/goldze/mvvmhabit/ui/form/FormViewModel.java b/app/src/main/java/com/goldze/mvvmhabit/ui/form/FormViewModel.java index 0f22bcaa..326d9270 100644 --- a/app/src/main/java/com/goldze/mvvmhabit/ui/form/FormViewModel.java +++ b/app/src/main/java/com/goldze/mvvmhabit/ui/form/FormViewModel.java @@ -1,8 +1,6 @@ package com.goldze.mvvmhabit.ui.form; import android.app.Application; -import android.databinding.ObservableBoolean; -import android.support.annotation.NonNull; import android.text.TextUtils; import android.view.View; @@ -14,6 +12,8 @@ import java.util.ArrayList; import java.util.List; +import androidx.annotation.NonNull; +import androidx.databinding.ObservableBoolean; import me.goldze.mvvmhabit.binding.command.BindingAction; import me.goldze.mvvmhabit.binding.command.BindingCommand; import me.goldze.mvvmhabit.binding.command.BindingConsumer; diff --git a/app/src/main/java/com/goldze/mvvmhabit/ui/login/LoginActivity.java b/app/src/main/java/com/goldze/mvvmhabit/ui/login/LoginActivity.java index 79d96bec..47b68009 100644 --- a/app/src/main/java/com/goldze/mvvmhabit/ui/login/LoginActivity.java +++ b/app/src/main/java/com/goldze/mvvmhabit/ui/login/LoginActivity.java @@ -1,9 +1,6 @@ package com.goldze.mvvmhabit.ui.login; -import android.arch.lifecycle.Observer; -import android.arch.lifecycle.ViewModelProviders; import android.os.Bundle; -import android.support.annotation.Nullable; import android.text.method.HideReturnsTransformationMethod; import android.text.method.PasswordTransformationMethod; @@ -12,6 +9,9 @@ import com.goldze.mvvmhabit.app.AppViewModelFactory; import com.goldze.mvvmhabit.databinding.ActivityLoginBinding; +import androidx.annotation.Nullable; +import androidx.lifecycle.Observer; +import androidx.lifecycle.ViewModelProviders; import me.goldze.mvvmhabit.base.BaseActivity; /** diff --git a/app/src/main/java/com/goldze/mvvmhabit/ui/login/LoginViewModel.java b/app/src/main/java/com/goldze/mvvmhabit/ui/login/LoginViewModel.java index 8b80d2a7..a377c6fc 100644 --- a/app/src/main/java/com/goldze/mvvmhabit/ui/login/LoginViewModel.java +++ b/app/src/main/java/com/goldze/mvvmhabit/ui/login/LoginViewModel.java @@ -1,15 +1,15 @@ package com.goldze.mvvmhabit.ui.login; import android.app.Application; -import android.databinding.ObservableField; -import android.databinding.ObservableInt; -import android.support.annotation.NonNull; import android.text.TextUtils; import android.view.View; import com.goldze.mvvmhabit.data.DemoRepository; import com.goldze.mvvmhabit.ui.main.DemoActivity; +import androidx.annotation.NonNull; +import androidx.databinding.ObservableField; +import androidx.databinding.ObservableInt; import io.reactivex.disposables.Disposable; import io.reactivex.functions.Consumer; import me.goldze.mvvmhabit.base.BaseViewModel; diff --git a/app/src/main/java/com/goldze/mvvmhabit/ui/main/DemoActivity.java b/app/src/main/java/com/goldze/mvvmhabit/ui/main/DemoActivity.java index 68dc0dbb..41a38328 100644 --- a/app/src/main/java/com/goldze/mvvmhabit/ui/main/DemoActivity.java +++ b/app/src/main/java/com/goldze/mvvmhabit/ui/main/DemoActivity.java @@ -2,23 +2,20 @@ import android.Manifest; import android.app.ProgressDialog; -import android.arch.lifecycle.Observer; -import android.content.Context; import android.content.pm.ActivityInfo; -import android.databinding.Observable; import android.os.Bundle; -import android.support.annotation.Nullable; import com.goldze.mvvmhabit.BR; import com.goldze.mvvmhabit.R; import com.goldze.mvvmhabit.databinding.ActivityDemoBinding; import com.tbruyelle.rxpermissions2.RxPermissions; +import androidx.annotation.Nullable; +import androidx.lifecycle.Observer; import io.reactivex.functions.Consumer; import me.goldze.mvvmhabit.base.BaseActivity; import me.goldze.mvvmhabit.http.DownLoadManager; import me.goldze.mvvmhabit.http.download.ProgressCallBack; -import me.goldze.mvvmhabit.utils.KLog; import me.goldze.mvvmhabit.utils.ToastUtils; import okhttp3.ResponseBody; diff --git a/app/src/main/java/com/goldze/mvvmhabit/ui/main/DemoViewModel.java b/app/src/main/java/com/goldze/mvvmhabit/ui/main/DemoViewModel.java index 8e102bb7..7983c86f 100644 --- a/app/src/main/java/com/goldze/mvvmhabit/ui/main/DemoViewModel.java +++ b/app/src/main/java/com/goldze/mvvmhabit/ui/main/DemoViewModel.java @@ -1,10 +1,7 @@ package com.goldze.mvvmhabit.ui.main; import android.app.Application; -import android.arch.lifecycle.MutableLiveData; -import android.databinding.ObservableBoolean; import android.os.Bundle; -import android.support.annotation.NonNull; import com.goldze.mvvmhabit.entity.FormEntity; import com.goldze.mvvmhabit.ui.form.FormFragment; @@ -14,6 +11,7 @@ import com.goldze.mvvmhabit.ui.viewpager.activity.ViewPagerActivity; import com.goldze.mvvmhabit.ui.vp_frg.ViewPagerGroupFragment; +import androidx.annotation.NonNull; import me.goldze.mvvmhabit.base.BaseViewModel; import me.goldze.mvvmhabit.binding.command.BindingAction; import me.goldze.mvvmhabit.binding.command.BindingCommand; @@ -112,7 +110,7 @@ public void call() { public BindingCommand fileDownLoadClick = new BindingCommand(new BindingAction() { @Override public void call() { - loadUrlEvent.setValue("http://gdown.baidu.com/data/wisegame/a2cd8828b227b9f9/neihanduanzi_692.apk"); + loadUrlEvent.setValue("http://gdown.baidu.com/data/wisegame/dc8a46540c7960a2/baidushoujizhushou_16798087.apk"); } }); } diff --git a/app/src/main/java/com/goldze/mvvmhabit/ui/network/NetWorkFragment.java b/app/src/main/java/com/goldze/mvvmhabit/ui/network/NetWorkFragment.java index f4ec0dd8..40c7327c 100644 --- a/app/src/main/java/com/goldze/mvvmhabit/ui/network/NetWorkFragment.java +++ b/app/src/main/java/com/goldze/mvvmhabit/ui/network/NetWorkFragment.java @@ -1,11 +1,7 @@ package com.goldze.mvvmhabit.ui.network; -import android.arch.lifecycle.Observer; -import android.arch.lifecycle.ViewModelProviders; import android.content.pm.ActivityInfo; import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; import android.view.LayoutInflater; import android.view.ViewGroup; @@ -16,6 +12,10 @@ import com.goldze.mvvmhabit.app.AppViewModelFactory; import com.goldze.mvvmhabit.databinding.FragmentNetworkBinding; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.lifecycle.Observer; +import androidx.lifecycle.ViewModelProviders; import me.goldze.mvvmhabit.base.BaseFragment; import me.goldze.mvvmhabit.utils.MaterialDialogUtils; import me.goldze.mvvmhabit.utils.ToastUtils; diff --git a/app/src/main/java/com/goldze/mvvmhabit/ui/network/NetWorkItemViewModel.java b/app/src/main/java/com/goldze/mvvmhabit/ui/network/NetWorkItemViewModel.java index 02928165..140b05e3 100644 --- a/app/src/main/java/com/goldze/mvvmhabit/ui/network/NetWorkItemViewModel.java +++ b/app/src/main/java/com/goldze/mvvmhabit/ui/network/NetWorkItemViewModel.java @@ -1,15 +1,15 @@ package com.goldze.mvvmhabit.ui.network; -import android.databinding.ObservableField; import android.graphics.drawable.Drawable; import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.v4.content.ContextCompat; import com.goldze.mvvmhabit.R; import com.goldze.mvvmhabit.entity.DemoEntity; import com.goldze.mvvmhabit.ui.network.detail.DetailFragment; +import androidx.annotation.NonNull; +import androidx.core.content.ContextCompat; +import androidx.databinding.ObservableField; import me.goldze.mvvmhabit.base.ItemViewModel; import me.goldze.mvvmhabit.binding.command.BindingAction; import me.goldze.mvvmhabit.binding.command.BindingCommand; diff --git a/app/src/main/java/com/goldze/mvvmhabit/ui/network/NetWorkViewModel.java b/app/src/main/java/com/goldze/mvvmhabit/ui/network/NetWorkViewModel.java index d32c9133..4d0652e8 100644 --- a/app/src/main/java/com/goldze/mvvmhabit/ui/network/NetWorkViewModel.java +++ b/app/src/main/java/com/goldze/mvvmhabit/ui/network/NetWorkViewModel.java @@ -1,15 +1,15 @@ package com.goldze.mvvmhabit.ui.network; import android.app.Application; -import android.databinding.ObservableArrayList; -import android.databinding.ObservableList; -import android.support.annotation.NonNull; import com.goldze.mvvmhabit.BR; import com.goldze.mvvmhabit.R; import com.goldze.mvvmhabit.data.DemoRepository; import com.goldze.mvvmhabit.entity.DemoEntity; +import androidx.annotation.NonNull; +import androidx.databinding.ObservableArrayList; +import androidx.databinding.ObservableList; import io.reactivex.disposables.Disposable; import io.reactivex.functions.Action; import io.reactivex.functions.Consumer; diff --git a/app/src/main/java/com/goldze/mvvmhabit/ui/network/detail/DetailViewModel.java b/app/src/main/java/com/goldze/mvvmhabit/ui/network/detail/DetailViewModel.java index 9faf3b22..6dfda5af 100644 --- a/app/src/main/java/com/goldze/mvvmhabit/ui/network/detail/DetailViewModel.java +++ b/app/src/main/java/com/goldze/mvvmhabit/ui/network/detail/DetailViewModel.java @@ -1,11 +1,11 @@ package com.goldze.mvvmhabit.ui.network.detail; import android.app.Application; -import android.databinding.ObservableField; -import android.support.annotation.NonNull; import com.goldze.mvvmhabit.entity.DemoEntity; +import androidx.annotation.NonNull; +import androidx.databinding.ObservableField; import me.goldze.mvvmhabit.base.BaseViewModel; /** diff --git a/app/src/main/java/com/goldze/mvvmhabit/ui/rv_multi/MultiRecycleHeadViewModel.java b/app/src/main/java/com/goldze/mvvmhabit/ui/rv_multi/MultiRecycleHeadViewModel.java index 72b5b705..60543869 100644 --- a/app/src/main/java/com/goldze/mvvmhabit/ui/rv_multi/MultiRecycleHeadViewModel.java +++ b/app/src/main/java/com/goldze/mvvmhabit/ui/rv_multi/MultiRecycleHeadViewModel.java @@ -1,7 +1,6 @@ package com.goldze.mvvmhabit.ui.rv_multi; -import android.support.annotation.NonNull; - +import androidx.annotation.NonNull; import me.goldze.mvvmhabit.base.BaseViewModel; import me.goldze.mvvmhabit.base.MultiItemViewModel; import me.goldze.mvvmhabit.binding.command.BindingAction; diff --git a/app/src/main/java/com/goldze/mvvmhabit/ui/rv_multi/MultiRecycleLeftItemViewModel.java b/app/src/main/java/com/goldze/mvvmhabit/ui/rv_multi/MultiRecycleLeftItemViewModel.java index fb13a855..5ac9e4aa 100644 --- a/app/src/main/java/com/goldze/mvvmhabit/ui/rv_multi/MultiRecycleLeftItemViewModel.java +++ b/app/src/main/java/com/goldze/mvvmhabit/ui/rv_multi/MultiRecycleLeftItemViewModel.java @@ -1,8 +1,7 @@ package com.goldze.mvvmhabit.ui.rv_multi; -import android.databinding.ObservableField; -import android.support.annotation.NonNull; - +import androidx.annotation.NonNull; +import androidx.databinding.ObservableField; import me.goldze.mvvmhabit.base.MultiItemViewModel; import me.goldze.mvvmhabit.binding.command.BindingAction; diff --git a/app/src/main/java/com/goldze/mvvmhabit/ui/rv_multi/MultiRecycleRightItemViewModel.java b/app/src/main/java/com/goldze/mvvmhabit/ui/rv_multi/MultiRecycleRightItemViewModel.java index 4a373f61..66008771 100644 --- a/app/src/main/java/com/goldze/mvvmhabit/ui/rv_multi/MultiRecycleRightItemViewModel.java +++ b/app/src/main/java/com/goldze/mvvmhabit/ui/rv_multi/MultiRecycleRightItemViewModel.java @@ -1,8 +1,7 @@ package com.goldze.mvvmhabit.ui.rv_multi; -import android.databinding.ObservableField; -import android.support.annotation.NonNull; - +import androidx.annotation.NonNull; +import androidx.databinding.ObservableField; import me.goldze.mvvmhabit.base.MultiItemViewModel; import me.goldze.mvvmhabit.binding.command.BindingAction; diff --git a/app/src/main/java/com/goldze/mvvmhabit/ui/rv_multi/MultiRecycleViewFragment.java b/app/src/main/java/com/goldze/mvvmhabit/ui/rv_multi/MultiRecycleViewFragment.java index 09bbc572..670d8c1c 100644 --- a/app/src/main/java/com/goldze/mvvmhabit/ui/rv_multi/MultiRecycleViewFragment.java +++ b/app/src/main/java/com/goldze/mvvmhabit/ui/rv_multi/MultiRecycleViewFragment.java @@ -1,7 +1,6 @@ package com.goldze.mvvmhabit.ui.rv_multi; import android.os.Bundle; -import android.support.annotation.Nullable; import android.view.LayoutInflater; import android.view.ViewGroup; @@ -9,6 +8,7 @@ import com.goldze.mvvmhabit.R; import com.goldze.mvvmhabit.databinding.FragmentMultiRvBinding; +import androidx.annotation.Nullable; import me.goldze.mvvmhabit.base.BaseFragment; import me.tatarka.bindingcollectionadapter2.BindingRecyclerViewAdapter; diff --git a/app/src/main/java/com/goldze/mvvmhabit/ui/rv_multi/MultiRecycleViewModel.java b/app/src/main/java/com/goldze/mvvmhabit/ui/rv_multi/MultiRecycleViewModel.java index a59bbb3e..92e690c2 100644 --- a/app/src/main/java/com/goldze/mvvmhabit/ui/rv_multi/MultiRecycleViewModel.java +++ b/app/src/main/java/com/goldze/mvvmhabit/ui/rv_multi/MultiRecycleViewModel.java @@ -1,16 +1,15 @@ package com.goldze.mvvmhabit.ui.rv_multi; import android.app.Application; -import android.databinding.ObservableArrayList; -import android.databinding.ObservableList; -import android.support.annotation.NonNull; import com.goldze.mvvmhabit.BR; import com.goldze.mvvmhabit.R; +import androidx.annotation.NonNull; +import androidx.databinding.ObservableArrayList; +import androidx.databinding.ObservableList; import me.goldze.mvvmhabit.base.BaseViewModel; import me.goldze.mvvmhabit.base.MultiItemViewModel; -import me.tatarka.bindingcollectionadapter2.BindingRecyclerViewAdapter; import me.tatarka.bindingcollectionadapter2.ItemBinding; import me.tatarka.bindingcollectionadapter2.OnItemBind; diff --git a/app/src/main/java/com/goldze/mvvmhabit/ui/tab_bar/activity/TabBarActivity.java b/app/src/main/java/com/goldze/mvvmhabit/ui/tab_bar/activity/TabBarActivity.java index 76271458..c64e93e0 100644 --- a/app/src/main/java/com/goldze/mvvmhabit/ui/tab_bar/activity/TabBarActivity.java +++ b/app/src/main/java/com/goldze/mvvmhabit/ui/tab_bar/activity/TabBarActivity.java @@ -1,9 +1,6 @@ package com.goldze.mvvmhabit.ui.tab_bar.activity; import android.os.Bundle; -import android.support.v4.app.Fragment; -import android.support.v4.app.FragmentTransaction; -import android.support.v4.content.ContextCompat; import com.goldze.mvvmhabit.BR; import com.goldze.mvvmhabit.R; @@ -16,6 +13,9 @@ import java.util.ArrayList; import java.util.List; +import androidx.core.content.ContextCompat; +import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentTransaction; import me.goldze.mvvmhabit.base.BaseActivity; import me.goldze.mvvmhabit.base.BaseViewModel; import me.majiajie.pagerbottomtabstrip.NavigationController; diff --git a/app/src/main/java/com/goldze/mvvmhabit/ui/tab_bar/fragment/TabBar1Fragment.java b/app/src/main/java/com/goldze/mvvmhabit/ui/tab_bar/fragment/TabBar1Fragment.java index 1d279dda..7f053dc6 100644 --- a/app/src/main/java/com/goldze/mvvmhabit/ui/tab_bar/fragment/TabBar1Fragment.java +++ b/app/src/main/java/com/goldze/mvvmhabit/ui/tab_bar/fragment/TabBar1Fragment.java @@ -1,13 +1,13 @@ package com.goldze.mvvmhabit.ui.tab_bar.fragment; import android.os.Bundle; -import android.support.annotation.Nullable; import android.view.LayoutInflater; import android.view.ViewGroup; import com.goldze.mvvmhabit.BR; import com.goldze.mvvmhabit.R; +import androidx.annotation.Nullable; import me.goldze.mvvmhabit.base.BaseFragment; /** diff --git a/app/src/main/java/com/goldze/mvvmhabit/ui/tab_bar/fragment/TabBar2Fragment.java b/app/src/main/java/com/goldze/mvvmhabit/ui/tab_bar/fragment/TabBar2Fragment.java index d94d97a9..681a319d 100644 --- a/app/src/main/java/com/goldze/mvvmhabit/ui/tab_bar/fragment/TabBar2Fragment.java +++ b/app/src/main/java/com/goldze/mvvmhabit/ui/tab_bar/fragment/TabBar2Fragment.java @@ -1,13 +1,13 @@ package com.goldze.mvvmhabit.ui.tab_bar.fragment; import android.os.Bundle; -import android.support.annotation.Nullable; import android.view.LayoutInflater; import android.view.ViewGroup; import com.goldze.mvvmhabit.BR; import com.goldze.mvvmhabit.R; +import androidx.annotation.Nullable; import me.goldze.mvvmhabit.base.BaseFragment; /** diff --git a/app/src/main/java/com/goldze/mvvmhabit/ui/tab_bar/fragment/TabBar3Fragment.java b/app/src/main/java/com/goldze/mvvmhabit/ui/tab_bar/fragment/TabBar3Fragment.java index 83b44077..4636e4f7 100644 --- a/app/src/main/java/com/goldze/mvvmhabit/ui/tab_bar/fragment/TabBar3Fragment.java +++ b/app/src/main/java/com/goldze/mvvmhabit/ui/tab_bar/fragment/TabBar3Fragment.java @@ -1,13 +1,13 @@ package com.goldze.mvvmhabit.ui.tab_bar.fragment; import android.os.Bundle; -import android.support.annotation.Nullable; import android.view.LayoutInflater; import android.view.ViewGroup; import com.goldze.mvvmhabit.BR; import com.goldze.mvvmhabit.R; +import androidx.annotation.Nullable; import me.goldze.mvvmhabit.base.BaseFragment; /** diff --git a/app/src/main/java/com/goldze/mvvmhabit/ui/tab_bar/fragment/TabBar4Fragment.java b/app/src/main/java/com/goldze/mvvmhabit/ui/tab_bar/fragment/TabBar4Fragment.java index e4835eba..67889c57 100644 --- a/app/src/main/java/com/goldze/mvvmhabit/ui/tab_bar/fragment/TabBar4Fragment.java +++ b/app/src/main/java/com/goldze/mvvmhabit/ui/tab_bar/fragment/TabBar4Fragment.java @@ -1,13 +1,13 @@ package com.goldze.mvvmhabit.ui.tab_bar.fragment; import android.os.Bundle; -import android.support.annotation.Nullable; import android.view.LayoutInflater; import android.view.ViewGroup; import com.goldze.mvvmhabit.BR; import com.goldze.mvvmhabit.R; +import androidx.annotation.Nullable; import me.goldze.mvvmhabit.base.BaseFragment; /** diff --git a/app/src/main/java/com/goldze/mvvmhabit/ui/viewpager/activity/ViewPagerActivity.java b/app/src/main/java/com/goldze/mvvmhabit/ui/viewpager/activity/ViewPagerActivity.java index 3d4d5466..0d31775b 100644 --- a/app/src/main/java/com/goldze/mvvmhabit/ui/viewpager/activity/ViewPagerActivity.java +++ b/app/src/main/java/com/goldze/mvvmhabit/ui/viewpager/activity/ViewPagerActivity.java @@ -1,16 +1,16 @@ package com.goldze.mvvmhabit.ui.viewpager.activity; -import android.arch.lifecycle.Observer; import android.os.Bundle; -import android.support.annotation.Nullable; -import android.support.design.widget.TabLayout; import com.goldze.mvvmhabit.BR; import com.goldze.mvvmhabit.R; import com.goldze.mvvmhabit.databinding.FragmentViewpagerBinding; import com.goldze.mvvmhabit.ui.viewpager.adapter.ViewPagerBindingAdapter; import com.goldze.mvvmhabit.ui.viewpager.vm.ViewPagerViewModel; +import com.google.android.material.tabs.TabLayout; +import androidx.annotation.Nullable; +import androidx.lifecycle.Observer; import me.goldze.mvvmhabit.base.BaseActivity; import me.goldze.mvvmhabit.utils.ToastUtils; diff --git a/app/src/main/java/com/goldze/mvvmhabit/ui/viewpager/adapter/ViewPagerBindingAdapter.java b/app/src/main/java/com/goldze/mvvmhabit/ui/viewpager/adapter/ViewPagerBindingAdapter.java index a2b9970c..b492992f 100644 --- a/app/src/main/java/com/goldze/mvvmhabit/ui/viewpager/adapter/ViewPagerBindingAdapter.java +++ b/app/src/main/java/com/goldze/mvvmhabit/ui/viewpager/adapter/ViewPagerBindingAdapter.java @@ -1,11 +1,11 @@ package com.goldze.mvvmhabit.ui.viewpager.adapter; -import android.databinding.ViewDataBinding; import android.view.ViewGroup; import com.goldze.mvvmhabit.databinding.ItemViewpagerBinding; import com.goldze.mvvmhabit.ui.viewpager.vm.ViewPagerItemViewModel; +import androidx.databinding.ViewDataBinding; import me.tatarka.bindingcollectionadapter2.BindingViewPagerAdapter; /** diff --git a/app/src/main/java/com/goldze/mvvmhabit/ui/viewpager/vm/ViewPagerItemViewModel.java b/app/src/main/java/com/goldze/mvvmhabit/ui/viewpager/vm/ViewPagerItemViewModel.java index 1d175ecb..349e48ba 100644 --- a/app/src/main/java/com/goldze/mvvmhabit/ui/viewpager/vm/ViewPagerItemViewModel.java +++ b/app/src/main/java/com/goldze/mvvmhabit/ui/viewpager/vm/ViewPagerItemViewModel.java @@ -1,7 +1,6 @@ package com.goldze.mvvmhabit.ui.viewpager.vm; -import android.support.annotation.NonNull; - +import androidx.annotation.NonNull; import me.goldze.mvvmhabit.base.ItemViewModel; import me.goldze.mvvmhabit.binding.command.BindingAction; import me.goldze.mvvmhabit.binding.command.BindingCommand; diff --git a/app/src/main/java/com/goldze/mvvmhabit/ui/viewpager/vm/ViewPagerViewModel.java b/app/src/main/java/com/goldze/mvvmhabit/ui/viewpager/vm/ViewPagerViewModel.java index 3a50393f..168a916b 100644 --- a/app/src/main/java/com/goldze/mvvmhabit/ui/viewpager/vm/ViewPagerViewModel.java +++ b/app/src/main/java/com/goldze/mvvmhabit/ui/viewpager/vm/ViewPagerViewModel.java @@ -1,14 +1,13 @@ package com.goldze.mvvmhabit.ui.viewpager.vm; import android.app.Application; -import android.databinding.ObservableArrayList; -import android.databinding.ObservableList; -import android.support.annotation.NonNull; import com.goldze.mvvmhabit.BR; import com.goldze.mvvmhabit.R; -import com.goldze.mvvmhabit.ui.viewpager.adapter.ViewPagerBindingAdapter; +import androidx.annotation.NonNull; +import androidx.databinding.ObservableArrayList; +import androidx.databinding.ObservableList; import me.goldze.mvvmhabit.base.BaseViewModel; import me.goldze.mvvmhabit.binding.command.BindingCommand; import me.goldze.mvvmhabit.binding.command.BindingConsumer; diff --git a/app/src/main/java/com/goldze/mvvmhabit/ui/vp_frg/ViewPagerGroupFragment.java b/app/src/main/java/com/goldze/mvvmhabit/ui/vp_frg/ViewPagerGroupFragment.java index bb2783e1..56c2315e 100644 --- a/app/src/main/java/com/goldze/mvvmhabit/ui/vp_frg/ViewPagerGroupFragment.java +++ b/app/src/main/java/com/goldze/mvvmhabit/ui/vp_frg/ViewPagerGroupFragment.java @@ -1,8 +1,5 @@ package com.goldze.mvvmhabit.ui.vp_frg; -import android.support.v4.app.Fragment; - - import com.goldze.mvvmhabit.ui.base.fragment.BasePagerFragment; import com.goldze.mvvmhabit.ui.tab_bar.fragment.TabBar1Fragment; import com.goldze.mvvmhabit.ui.tab_bar.fragment.TabBar2Fragment; @@ -12,6 +9,8 @@ import java.util.ArrayList; import java.util.List; +import androidx.fragment.app.Fragment; + /** * Create Author:goldze * Create Date:2019/01/25 diff --git a/app/src/main/java/com/goldze/mvvmhabit/utils/HttpsUtils.java b/app/src/main/java/com/goldze/mvvmhabit/utils/HttpsUtils.java index ef769645..8c612946 100644 --- a/app/src/main/java/com/goldze/mvvmhabit/utils/HttpsUtils.java +++ b/app/src/main/java/com/goldze/mvvmhabit/utils/HttpsUtils.java @@ -35,9 +35,6 @@ import javax.net.ssl.TrustManagerFactory; import javax.net.ssl.X509TrustManager; -import me.goldze.mvvmhabit.utils.KLog; - - public class HttpsUtils { public static class SSLParams { diff --git a/app/src/main/res/layout/fragment_base_pager.xml b/app/src/main/res/layout/fragment_base_pager.xml index d23670cd..bd9f3fe7 100644 --- a/app/src/main/res/layout/fragment_base_pager.xml +++ b/app/src/main/res/layout/fragment_base_pager.xml @@ -18,7 +18,7 @@ android:background="@color/white" android:orientation="vertical"> - - - + @@ -26,7 +26,7 @@ android:layout_height="match_parent" android:orientation="vertical"> - - + @@ -35,7 +35,7 @@ binding:tr_head_height="80dp" binding:tr_wave_height="80dp"> - - + binding:tabGravity="fill" + binding:tabIndicatorColor="@color/colorPrimary" + binding:tabSelectedTextColor="@color/colorPrimary" + binding:tabTextColor="@android:color/black" /> - - - + diff --git a/app/src/main/res/xml/network_security_config.xml b/app/src/main/res/xml/network_security_config.xml new file mode 100644 index 00000000..2439f15c --- /dev/null +++ b/app/src/main/res/xml/network_security_config.xml @@ -0,0 +1,4 @@ + + + + diff --git a/config.gradle b/config.gradle index 9e2a0209..a29a05f4 100644 --- a/config.gradle +++ b/config.gradle @@ -11,19 +11,18 @@ ext { ] //version配置 versions = [ - "support-version": "28.0.0", + "support-version": "1.0.0", "junit-version" : "4.12", ] //support配置 support = [ - "constraint-layout" : "1.0.0-beta2", - 'support-v4' : "com.android.support:support-v4:${versions["support-version"]}", - 'appcompat-v7' : "com.android.support:appcompat-v7:${versions["support-version"]}", - 'recyclerview-v7' : "com.android.support:recyclerview-v7:${versions["support-version"]}", - 'support-v13' : "com.android.support:support-v13:${versions["support-version"]}", - 'support-fragment' : "com.android.support:support-fragment:${versions["support-version"]}", - 'design' : "com.android.support:design:${versions["support-version"]}", - 'animated-vector-drawable': "com.android.support:animated-vector-drawable:${versions["support-version"]}", + 'support-v4' : "androidx.legacy:legacy-support-v4:${versions["support-version"]}", + 'appcompat-v7' : "androidx.appcompat:appcompat:${versions["support-version"]}", + 'recyclerview-v7' : "androidx.recyclerview:recyclerview:${versions["support-version"]}", + 'support-v13' : "androidx.legacy:legacy-support-v13:${versions["support-version"]}", + 'support-fragment' : "androidx.fragment:fragment:${versions["support-version"]}", + 'design' : "com.google.android.material:material:${versions["support-version"]}", + 'animated-vector-drawable': "androidx.vectordrawable:vectordrawable-animated:${versions["support-version"]}", 'junit' : "junit:junit:${versions["junit-version"]}", ] //依赖第三方配置 @@ -52,11 +51,11 @@ ext { "material-dialogs-core" : "com.afollestad.material-dialogs:core:0.9.4.5", "material-dialogs-commons" : "com.afollestad.material-dialogs:commons:0.9.4.5", //recyclerview的databinding套装 - "bindingcollectionadapter" : "me.tatarka.bindingcollectionadapter2:bindingcollectionadapter:2.2.0", - "bindingcollectionadapter-recyclerview": "me.tatarka.bindingcollectionadapter2:bindingcollectionadapter-recyclerview:2.2.0", + "bindingcollectionadapter" : "me.tatarka.bindingcollectionadapter2:bindingcollectionadapter:3.1.1", + "bindingcollectionadapter-recyclerview": "me.tatarka.bindingcollectionadapter2:bindingcollectionadapter-recyclerview:3.1.1", //Google AAC - "lifecycle-extensions" : "android.arch.lifecycle:extensions:1.1.1", - "lifecycle-compiler" : "android.arch.lifecycle:compiler:1.1.1", + "lifecycle-extensions" : "androidx.lifecycle:lifecycle-extensions:2.0.0", + "lifecycle-compiler" : "androidx.lifecycle:lifecycle-compiler:2.0.0", //MVVMHabit "MVVMHabit" : "com.github.goldze:MVVMHabit:3.1.3", ] diff --git a/gradle.properties b/gradle.properties index f8dd8775..901c7f82 100644 --- a/gradle.properties +++ b/gradle.properties @@ -15,4 +15,7 @@ org.gradle.jvmargs=-Xmx1536m # This option should only be used with decoupled projects. More details, visit # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects # org.gradle.parallel=true -# android.databinding.enableV2=true \ No newline at end of file +# android.databinding.enableV2=true + +android.useAndroidX=true +android.enableJetifier=true \ No newline at end of file diff --git a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/base/AppManager.java b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/base/AppManager.java index 07f13c41..2d1eff59 100644 --- a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/base/AppManager.java +++ b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/base/AppManager.java @@ -1,10 +1,11 @@ package me.goldze.mvvmhabit.base; import android.app.Activity; -import android.support.v4.app.Fragment; import java.util.Stack; +import androidx.fragment.app.Fragment; + /** * Created by goldze on 2017/6/15. * activity堆栈式管理 diff --git a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/base/BaseActivity.java b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/base/BaseActivity.java index 012dee9c..19bfb07c 100644 --- a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/base/BaseActivity.java +++ b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/base/BaseActivity.java @@ -1,14 +1,7 @@ package me.goldze.mvvmhabit.base; -import android.arch.lifecycle.Observer; -import android.arch.lifecycle.ViewModel; -import android.arch.lifecycle.ViewModelProviders; import android.content.Intent; -import android.databinding.DataBindingUtil; -import android.databinding.ViewDataBinding; import android.os.Bundle; -import android.support.annotation.Nullable; -import android.support.v4.app.FragmentActivity; import com.afollestad.materialdialogs.MaterialDialog; import com.trello.rxlifecycle2.components.support.RxAppCompatActivity; @@ -17,6 +10,13 @@ import java.lang.reflect.Type; import java.util.Map; +import androidx.annotation.Nullable; +import androidx.databinding.DataBindingUtil; +import androidx.databinding.ViewDataBinding; +import androidx.fragment.app.FragmentActivity; +import androidx.lifecycle.Observer; +import androidx.lifecycle.ViewModel; +import androidx.lifecycle.ViewModelProviders; import me.goldze.mvvmhabit.base.BaseViewModel.ParameterField; import me.goldze.mvvmhabit.bus.Messenger; import me.goldze.mvvmhabit.utils.MaterialDialogUtils; diff --git a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/base/BaseApplication.java b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/base/BaseApplication.java index b9b12999..5899a9ab 100644 --- a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/base/BaseApplication.java +++ b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/base/BaseApplication.java @@ -3,8 +3,8 @@ import android.app.Activity; import android.app.Application; import android.os.Bundle; -import android.support.annotation.NonNull; +import androidx.annotation.NonNull; import me.goldze.mvvmhabit.utils.Utils; /** diff --git a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/base/BaseFragment.java b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/base/BaseFragment.java index cfedd8e9..cd245597 100644 --- a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/base/BaseFragment.java +++ b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/base/BaseFragment.java @@ -1,14 +1,7 @@ package me.goldze.mvvmhabit.base; -import android.arch.lifecycle.Observer; -import android.arch.lifecycle.ViewModel; -import android.arch.lifecycle.ViewModelProviders; import android.content.Intent; -import android.databinding.DataBindingUtil; -import android.databinding.ViewDataBinding; import android.os.Bundle; -import android.support.annotation.Nullable; -import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -20,6 +13,13 @@ import java.lang.reflect.Type; import java.util.Map; +import androidx.annotation.Nullable; +import androidx.databinding.DataBindingUtil; +import androidx.databinding.ViewDataBinding; +import androidx.fragment.app.Fragment; +import androidx.lifecycle.Observer; +import androidx.lifecycle.ViewModel; +import androidx.lifecycle.ViewModelProviders; import me.goldze.mvvmhabit.base.BaseViewModel.ParameterField; import me.goldze.mvvmhabit.bus.Messenger; import me.goldze.mvvmhabit.utils.MaterialDialogUtils; diff --git a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/base/BaseViewModel.java b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/base/BaseViewModel.java index cb46eeda..8d4be18a 100644 --- a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/base/BaseViewModel.java +++ b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/base/BaseViewModel.java @@ -1,12 +1,7 @@ package me.goldze.mvvmhabit.base; import android.app.Application; -import android.arch.lifecycle.AndroidViewModel; -import android.arch.lifecycle.Lifecycle; -import android.arch.lifecycle.LifecycleOwner; -import android.arch.lifecycle.Observer; import android.os.Bundle; -import android.support.annotation.NonNull; import com.trello.rxlifecycle2.LifecycleProvider; @@ -14,6 +9,11 @@ import java.util.HashMap; import java.util.Map; +import androidx.annotation.NonNull; +import androidx.lifecycle.AndroidViewModel; +import androidx.lifecycle.Lifecycle; +import androidx.lifecycle.LifecycleOwner; +import androidx.lifecycle.Observer; import io.reactivex.disposables.CompositeDisposable; import io.reactivex.disposables.Disposable; import io.reactivex.functions.Consumer; diff --git a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/base/ContainerActivity.java b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/base/ContainerActivity.java index 7a136237..58127c79 100644 --- a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/base/ContainerActivity.java +++ b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/base/ContainerActivity.java @@ -2,23 +2,17 @@ import android.content.Intent; import android.os.Bundle; -import android.os.PersistableBundle; -import android.support.v4.app.Fragment; -import android.support.v4.app.FragmentManager; -import android.support.v4.app.FragmentTransaction; -import android.view.View; -import android.view.ViewGroup; import android.view.WindowManager; -import android.widget.LinearLayout; import com.trello.rxlifecycle2.components.support.RxAppCompatActivity; import java.lang.ref.WeakReference; +import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentManager; +import androidx.fragment.app.FragmentTransaction; import me.goldze.mvvmhabit.R; -import static android.view.View.generateViewId; - /** * 盛装Fragment的一个容器(代理)Activity diff --git a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/base/IBaseViewModel.java b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/base/IBaseViewModel.java index 1f5382ba..0ad257dc 100644 --- a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/base/IBaseViewModel.java +++ b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/base/IBaseViewModel.java @@ -1,9 +1,10 @@ package me.goldze.mvvmhabit.base; -import android.arch.lifecycle.Lifecycle; -import android.arch.lifecycle.LifecycleObserver; -import android.arch.lifecycle.LifecycleOwner; -import android.arch.lifecycle.OnLifecycleEvent; + +import androidx.lifecycle.Lifecycle; +import androidx.lifecycle.LifecycleObserver; +import androidx.lifecycle.LifecycleOwner; +import androidx.lifecycle.OnLifecycleEvent; /** * Created by goldze on 2017/6/15. diff --git a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/base/ItemViewModel.java b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/base/ItemViewModel.java index 45ac04e0..8b673231 100644 --- a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/base/ItemViewModel.java +++ b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/base/ItemViewModel.java @@ -1,6 +1,7 @@ package me.goldze.mvvmhabit.base; -import android.support.annotation.NonNull; + +import androidx.annotation.NonNull; /** * ItemViewModel diff --git a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/base/MultiItemViewModel.java b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/base/MultiItemViewModel.java index 0e04d9a3..e300c520 100644 --- a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/base/MultiItemViewModel.java +++ b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/base/MultiItemViewModel.java @@ -1,6 +1,7 @@ package me.goldze.mvvmhabit.base; -import android.support.annotation.NonNull; + +import androidx.annotation.NonNull; /** * Create Author:goldze diff --git a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/base/ViewModelFactory.java b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/base/ViewModelFactory.java index 6d104cb7..86b26591 100644 --- a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/base/ViewModelFactory.java +++ b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/base/ViewModelFactory.java @@ -2,14 +2,13 @@ import android.annotation.SuppressLint; import android.app.Application; -import android.arch.lifecycle.ViewModel; -import android.arch.lifecycle.ViewModelProvider; -import android.arch.lifecycle.ViewModelProviders; -import android.support.v4.app.FragmentActivity; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; +import androidx.lifecycle.ViewModel; +import androidx.lifecycle.ViewModelProvider; + /** * Created by goldze on 2018/9/30. */ diff --git a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/binding/command/BindingCommand.java b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/binding/command/BindingCommand.java index 6a27b40d..4b6b1f81 100644 --- a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/binding/command/BindingCommand.java +++ b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/binding/command/BindingCommand.java @@ -1,8 +1,6 @@ package me.goldze.mvvmhabit.binding.command; -import io.reactivex.exceptions.Exceptions; - /** * About : kelin的ReplyCommand * 执行的命令回调, 用于ViewModel与xml之间的数据绑定 diff --git a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/binding/command/BindingFunction.java b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/binding/command/BindingFunction.java index 2d0cbe0b..34210115 100644 --- a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/binding/command/BindingFunction.java +++ b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/binding/command/BindingFunction.java @@ -1,7 +1,5 @@ package me.goldze.mvvmhabit.binding.command; -import me.goldze.mvvmhabit.R; - /** * Represents a function with zero arguments. * diff --git a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/binding/command/ResponseCommand.java b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/binding/command/ResponseCommand.java index 45522d2d..c02bb3ad 100644 --- a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/binding/command/ResponseCommand.java +++ b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/binding/command/ResponseCommand.java @@ -1,7 +1,5 @@ package me.goldze.mvvmhabit.binding.command; - -import io.reactivex.exceptions.Exceptions; import io.reactivex.functions.Function; /** diff --git a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/binding/viewadapter/checkbox/ViewAdapter.java b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/binding/viewadapter/checkbox/ViewAdapter.java index 1ffc3add..3305ef2c 100644 --- a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/binding/viewadapter/checkbox/ViewAdapter.java +++ b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/binding/viewadapter/checkbox/ViewAdapter.java @@ -1,9 +1,9 @@ package me.goldze.mvvmhabit.binding.viewadapter.checkbox; -import android.databinding.BindingAdapter; import android.widget.CheckBox; import android.widget.CompoundButton; +import androidx.databinding.BindingAdapter; import me.goldze.mvvmhabit.binding.command.BindingCommand; /** diff --git a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/binding/viewadapter/edittext/ViewAdapter.java b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/binding/viewadapter/edittext/ViewAdapter.java index 45861741..fdc742d4 100644 --- a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/binding/viewadapter/edittext/ViewAdapter.java +++ b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/binding/viewadapter/edittext/ViewAdapter.java @@ -1,12 +1,12 @@ package me.goldze.mvvmhabit.binding.viewadapter.edittext; import android.content.Context; -import android.databinding.BindingAdapter; import android.text.Editable; import android.text.TextWatcher; import android.view.inputmethod.InputMethodManager; import android.widget.EditText; +import androidx.databinding.BindingAdapter; import me.goldze.mvvmhabit.binding.command.BindingCommand; /** diff --git a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/binding/viewadapter/image/ViewAdapter.java b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/binding/viewadapter/image/ViewAdapter.java index 88202f82..5871393c 100644 --- a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/binding/viewadapter/image/ViewAdapter.java +++ b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/binding/viewadapter/image/ViewAdapter.java @@ -1,14 +1,12 @@ package me.goldze.mvvmhabit.binding.viewadapter.image; - -import android.databinding.BindingAdapter; import android.text.TextUtils; import android.widget.ImageView; import com.bumptech.glide.Glide; import com.bumptech.glide.request.RequestOptions; -import me.goldze.mvvmhabit.R; +import androidx.databinding.BindingAdapter; /** * Created by goldze on 2017/6/18. diff --git a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/binding/viewadapter/listview/ViewAdapter.java b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/binding/viewadapter/listview/ViewAdapter.java index aea8f0ac..d467e52d 100644 --- a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/binding/viewadapter/listview/ViewAdapter.java +++ b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/binding/viewadapter/listview/ViewAdapter.java @@ -1,6 +1,5 @@ package me.goldze.mvvmhabit.binding.viewadapter.listview; -import android.databinding.BindingAdapter; import android.view.View; import android.widget.AbsListView; import android.widget.AdapterView; @@ -8,6 +7,7 @@ import java.util.concurrent.TimeUnit; +import androidx.databinding.BindingAdapter; import io.reactivex.functions.Consumer; import io.reactivex.subjects.PublishSubject; import me.goldze.mvvmhabit.binding.command.BindingCommand; diff --git a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/binding/viewadapter/mswitch/ViewAdapter.java b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/binding/viewadapter/mswitch/ViewAdapter.java index 577f4adb..2e584824 100644 --- a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/binding/viewadapter/mswitch/ViewAdapter.java +++ b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/binding/viewadapter/mswitch/ViewAdapter.java @@ -1,15 +1,11 @@ package me.goldze.mvvmhabit.binding.viewadapter.mswitch; -import android.databinding.BindingAdapter; -import android.text.TextUtils; import android.widget.CompoundButton; import android.widget.Switch; +import androidx.databinding.BindingAdapter; import me.goldze.mvvmhabit.binding.command.BindingCommand; -import static android.R.attr.checked; -import static me.goldze.mvvmhabit.R.attr.switchState; - /** * Created by goldze on 2017/6/18. */ diff --git a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/binding/viewadapter/radiogroup/ViewAdapter.java b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/binding/viewadapter/radiogroup/ViewAdapter.java index 9792d8e7..fe0c38cb 100644 --- a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/binding/viewadapter/radiogroup/ViewAdapter.java +++ b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/binding/viewadapter/radiogroup/ViewAdapter.java @@ -1,12 +1,10 @@ package me.goldze.mvvmhabit.binding.viewadapter.radiogroup; -import android.databinding.BindingAdapter; -import android.support.annotation.IdRes; -import android.text.TextUtils; -import android.webkit.WebView; import android.widget.RadioButton; import android.widget.RadioGroup; +import androidx.annotation.IdRes; +import androidx.databinding.BindingAdapter; import me.goldze.mvvmhabit.binding.command.BindingCommand; /** diff --git a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/binding/viewadapter/recyclerview/DividerLine.java b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/binding/viewadapter/recyclerview/DividerLine.java index 894b0f8f..eb3fe0a7 100644 --- a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/binding/viewadapter/recyclerview/DividerLine.java +++ b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/binding/viewadapter/recyclerview/DividerLine.java @@ -5,9 +5,10 @@ import android.graphics.Canvas; import android.graphics.Rect; import android.graphics.drawable.Drawable; -import android.support.v7.widget.RecyclerView; import android.view.View; +import androidx.recyclerview.widget.RecyclerView; + /** * Created by goldze on 2017/6/16. */ diff --git a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/binding/viewadapter/recyclerview/LayoutManagers.java b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/binding/viewadapter/recyclerview/LayoutManagers.java new file mode 100644 index 00000000..6dc84272 --- /dev/null +++ b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/binding/viewadapter/recyclerview/LayoutManagers.java @@ -0,0 +1,88 @@ +package me.goldze.mvvmhabit.binding.viewadapter.recyclerview; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +import androidx.annotation.IntDef; +import androidx.recyclerview.widget.GridLayoutManager; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; +import androidx.recyclerview.widget.StaggeredGridLayoutManager; + +/** + * A collection of factories to create RecyclerView LayoutManagers so that you can easily set them + * in your layout. + */ +public class LayoutManagers { + protected LayoutManagers() { + } + + public interface LayoutManagerFactory { + RecyclerView.LayoutManager create(RecyclerView recyclerView); + } + + /** + * A {@link LinearLayoutManager}. + */ + public static LayoutManagerFactory linear() { + return new LayoutManagerFactory() { + @Override + public RecyclerView.LayoutManager create(RecyclerView recyclerView) { + return new LinearLayoutManager(recyclerView.getContext()); + } + }; + } + + /** + * A {@link LinearLayoutManager} with the given orientation and reverseLayout. + */ + public static LayoutManagerFactory linear(@Orientation final int orientation, final boolean reverseLayout) { + return new LayoutManagerFactory() { + @Override + public RecyclerView.LayoutManager create(RecyclerView recyclerView) { + return new LinearLayoutManager(recyclerView.getContext(), orientation, reverseLayout); + } + }; + } + + /** + * A {@link GridLayoutManager} with the given spanCount. + */ + public static LayoutManagerFactory grid(final int spanCount) { + return new LayoutManagerFactory() { + @Override + public RecyclerView.LayoutManager create(RecyclerView recyclerView) { + return new GridLayoutManager(recyclerView.getContext(), spanCount); + } + }; + } + + /** + * A {@link GridLayoutManager} with the given spanCount, orientation and reverseLayout. + **/ + public static LayoutManagerFactory grid(final int spanCount, @Orientation final int orientation, final boolean reverseLayout) { + return new LayoutManagerFactory() { + @Override + public RecyclerView.LayoutManager create(RecyclerView recyclerView) { + return new GridLayoutManager(recyclerView.getContext(), spanCount, orientation, reverseLayout); + } + }; + } + + /** + * A {@link StaggeredGridLayoutManager} with the given spanCount and orientation. + */ + public static LayoutManagerFactory staggeredGrid(final int spanCount, @Orientation final int orientation) { + return new LayoutManagerFactory() { + @Override + public RecyclerView.LayoutManager create(RecyclerView recyclerView) { + return new StaggeredGridLayoutManager(spanCount, orientation); + } + }; + } + + @IntDef({LinearLayoutManager.HORIZONTAL, LinearLayoutManager.VERTICAL}) + @Retention(RetentionPolicy.SOURCE) + public @interface Orientation { + } +} \ No newline at end of file diff --git a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/binding/viewadapter/recyclerview/LineManagers.java b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/binding/viewadapter/recyclerview/LineManagers.java index 5697c68d..a3f65e3d 100644 --- a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/binding/viewadapter/recyclerview/LineManagers.java +++ b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/binding/viewadapter/recyclerview/LineManagers.java @@ -1,6 +1,6 @@ package me.goldze.mvvmhabit.binding.viewadapter.recyclerview; -import android.support.v7.widget.RecyclerView; +import androidx.recyclerview.widget.RecyclerView; /** * Created by goldze on 2017/6/16. diff --git a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/binding/viewadapter/recyclerview/ViewAdapter.java b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/binding/viewadapter/recyclerview/ViewAdapter.java index 50d46ba3..604a90bc 100644 --- a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/binding/viewadapter/recyclerview/ViewAdapter.java +++ b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/binding/viewadapter/recyclerview/ViewAdapter.java @@ -1,11 +1,10 @@ package me.goldze.mvvmhabit.binding.viewadapter.recyclerview; -import android.databinding.BindingAdapter; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; - import java.util.concurrent.TimeUnit; +import androidx.databinding.BindingAdapter; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; import io.reactivex.functions.Consumer; import io.reactivex.subjects.PublishSubject; import me.goldze.mvvmhabit.binding.command.BindingCommand; @@ -20,6 +19,10 @@ public static void setLineManager(RecyclerView recyclerView, LineManagers.LineMa recyclerView.addItemDecoration(lineManagerFactory.create(recyclerView)); } + @BindingAdapter("layoutManager") + public static void setLayoutManager(RecyclerView recyclerView, LayoutManagers.LayoutManagerFactory layoutManagerFactory) { + recyclerView.setLayoutManager(layoutManagerFactory.create(recyclerView)); + } @BindingAdapter(value = {"onScrollChangeCommand", "onScrollStateChangedCommand"}, requireAll = false) public static void onScrollChangeCommand(final RecyclerView recyclerView, diff --git a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/binding/viewadapter/scrollview/ViewAdapter.java b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/binding/viewadapter/scrollview/ViewAdapter.java index 63f6978d..20b0ade0 100644 --- a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/binding/viewadapter/scrollview/ViewAdapter.java +++ b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/binding/viewadapter/scrollview/ViewAdapter.java @@ -1,10 +1,10 @@ package me.goldze.mvvmhabit.binding.viewadapter.scrollview; -import android.databinding.BindingAdapter; -import android.support.v4.widget.NestedScrollView; import android.view.ViewTreeObserver; import android.widget.ScrollView; +import androidx.core.widget.NestedScrollView; +import androidx.databinding.BindingAdapter; import me.goldze.mvvmhabit.binding.command.BindingCommand; /** diff --git a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/binding/viewadapter/spinner/ViewAdapter.java b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/binding/viewadapter/spinner/ViewAdapter.java index b1be3ede..34806180 100644 --- a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/binding/viewadapter/spinner/ViewAdapter.java +++ b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/binding/viewadapter/spinner/ViewAdapter.java @@ -1,16 +1,15 @@ package me.goldze.mvvmhabit.binding.viewadapter.spinner; -import android.databinding.BindingAdapter; import android.text.TextUtils; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.Spinner; -import android.widget.SpinnerAdapter; import java.util.ArrayList; import java.util.List; +import androidx.databinding.BindingAdapter; import me.goldze.mvvmhabit.binding.command.BindingCommand; /** diff --git a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/binding/viewadapter/swiperefresh/ViewAdapter.java b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/binding/viewadapter/swiperefresh/ViewAdapter.java index 13b6ff80..a6ece792 100644 --- a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/binding/viewadapter/swiperefresh/ViewAdapter.java +++ b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/binding/viewadapter/swiperefresh/ViewAdapter.java @@ -1,8 +1,7 @@ package me.goldze.mvvmhabit.binding.viewadapter.swiperefresh; -import android.databinding.BindingAdapter; -import android.support.v4.widget.SwipeRefreshLayout; - +import androidx.databinding.BindingAdapter; +import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; import me.goldze.mvvmhabit.binding.command.BindingCommand; diff --git a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/binding/viewadapter/view/ViewAdapter.java b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/binding/viewadapter/view/ViewAdapter.java index 56cc9600..878083d3 100644 --- a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/binding/viewadapter/view/ViewAdapter.java +++ b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/binding/viewadapter/view/ViewAdapter.java @@ -1,12 +1,12 @@ package me.goldze.mvvmhabit.binding.viewadapter.view; -import android.databinding.BindingAdapter; import android.view.View; import com.jakewharton.rxbinding2.view.RxView; import java.util.concurrent.TimeUnit; +import androidx.databinding.BindingAdapter; import io.reactivex.functions.Consumer; import me.goldze.mvvmhabit.binding.command.BindingCommand; diff --git a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/binding/viewadapter/viewgroup/IBindingItemViewModel.java b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/binding/viewadapter/viewgroup/IBindingItemViewModel.java index 5489b226..98fe8353 100644 --- a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/binding/viewadapter/viewgroup/IBindingItemViewModel.java +++ b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/binding/viewadapter/viewgroup/IBindingItemViewModel.java @@ -1,11 +1,10 @@ package me.goldze.mvvmhabit.binding.viewadapter.viewgroup; +import androidx.databinding.ViewDataBinding; + /** * Created by goldze on 2017/6/15. */ - -import android.databinding.ViewDataBinding; - public interface IBindingItemViewModel { void injecDataBinding(V binding); } diff --git a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/binding/viewadapter/viewgroup/ViewAdapter.java b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/binding/viewadapter/viewgroup/ViewAdapter.java index 32d18833..847114e4 100644 --- a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/binding/viewadapter/viewgroup/ViewAdapter.java +++ b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/binding/viewadapter/viewgroup/ViewAdapter.java @@ -1,16 +1,14 @@ package me.goldze.mvvmhabit.binding.viewadapter.viewgroup; -import android.databinding.BindingAdapter; -import android.databinding.DataBindingUtil; -import android.databinding.ObservableList; -import android.databinding.ViewDataBinding; import android.view.LayoutInflater; import android.view.ViewGroup; +import androidx.databinding.BindingAdapter; +import androidx.databinding.DataBindingUtil; +import androidx.databinding.ObservableList; +import androidx.databinding.ViewDataBinding; import me.tatarka.bindingcollectionadapter2.ItemBinding; -import static me.goldze.mvvmhabit.R.attr.itemView; - /** * Created by goldze on 2017/6/18. */ diff --git a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/binding/viewadapter/viewpager/ViewAdapter.java b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/binding/viewadapter/viewpager/ViewAdapter.java index 2b290317..d3e9d54e 100644 --- a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/binding/viewadapter/viewpager/ViewAdapter.java +++ b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/binding/viewadapter/viewpager/ViewAdapter.java @@ -1,10 +1,7 @@ package me.goldze.mvvmhabit.binding.viewadapter.viewpager; -import android.databinding.BindingAdapter; -import android.support.v4.view.ViewPager; -import android.text.TextUtils; -import android.webkit.WebView; - +import androidx.databinding.BindingAdapter; +import androidx.viewpager.widget.ViewPager; import me.goldze.mvvmhabit.binding.command.BindingCommand; /** diff --git a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/binding/viewadapter/webview/ViewAdapter.java b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/binding/viewadapter/webview/ViewAdapter.java index cbabc54d..9ea65be4 100644 --- a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/binding/viewadapter/webview/ViewAdapter.java +++ b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/binding/viewadapter/webview/ViewAdapter.java @@ -1,9 +1,10 @@ package me.goldze.mvvmhabit.binding.viewadapter.webview; -import android.databinding.BindingAdapter; import android.text.TextUtils; import android.webkit.WebView; +import androidx.databinding.BindingAdapter; + /** * Created by goldze on 2017/6/18. */ diff --git a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/bus/Messenger.java b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/bus/Messenger.java index fd7f0d4e..1b1dcd36 100644 --- a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/bus/Messenger.java +++ b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/bus/Messenger.java @@ -1,6 +1,5 @@ package me.goldze.mvvmhabit.bus; - import java.lang.reflect.Type; import java.util.ArrayList; import java.util.Collection; diff --git a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/bus/RxBus.java b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/bus/RxBus.java index 43564d44..bd327758 100644 --- a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/bus/RxBus.java +++ b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/bus/RxBus.java @@ -1,6 +1,5 @@ package me.goldze.mvvmhabit.bus; - import java.util.Map; import java.util.concurrent.ConcurrentHashMap; diff --git a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/bus/RxBusSubscriber.java b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/bus/RxBusSubscriber.java index 936137b0..5748b531 100644 --- a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/bus/RxBusSubscriber.java +++ b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/bus/RxBusSubscriber.java @@ -1,6 +1,5 @@ package me.goldze.mvvmhabit.bus; - import io.reactivex.observers.DisposableObserver; /** diff --git a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/bus/RxSubscriptions.java b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/bus/RxSubscriptions.java index 89c297bc..41ebf5a1 100644 --- a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/bus/RxSubscriptions.java +++ b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/bus/RxSubscriptions.java @@ -1,7 +1,5 @@ package me.goldze.mvvmhabit.bus; -import org.reactivestreams.Subscription; - import io.reactivex.disposables.CompositeDisposable; import io.reactivex.disposables.Disposable; diff --git a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/bus/event/SingleLiveEvent.java b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/bus/event/SingleLiveEvent.java index 37c814fd..6f53309d 100644 --- a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/bus/event/SingleLiveEvent.java +++ b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/bus/event/SingleLiveEvent.java @@ -16,15 +16,17 @@ package me.goldze.mvvmhabit.bus.event; -import android.arch.lifecycle.LifecycleOwner; -import android.arch.lifecycle.MutableLiveData; -import android.arch.lifecycle.Observer; -import android.support.annotation.MainThread; -import android.support.annotation.Nullable; import android.util.Log; import java.util.concurrent.atomic.AtomicBoolean; +import androidx.annotation.MainThread; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.lifecycle.LifecycleOwner; +import androidx.lifecycle.MutableLiveData; +import androidx.lifecycle.Observer; + /** * A lifecycle-aware observable that sends only new updates after subscription, used for events like * navigation and Snackbar messages. @@ -36,13 +38,12 @@ * Note that only one observer is going to be notified of changes. */ public class SingleLiveEvent extends MutableLiveData { - private static final String TAG = "SingleLiveEvent"; private final AtomicBoolean mPending = new AtomicBoolean(false); @MainThread - public void observe(LifecycleOwner owner, final Observer observer) { + public void observe(@NonNull LifecycleOwner owner, @NonNull final Observer observer) { if (hasActiveObservers()) { Log.w(TAG, "Multiple observers registered but only one will be notified of changes."); diff --git a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/bus/event/SnackbarMessage.java b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/bus/event/SnackbarMessage.java index 66a1df82..dd2b9752 100644 --- a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/bus/event/SnackbarMessage.java +++ b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/bus/event/SnackbarMessage.java @@ -16,10 +16,10 @@ package me.goldze.mvvmhabit.bus.event; -import android.arch.lifecycle.LifecycleOwner; -import android.arch.lifecycle.Observer; -import android.support.annotation.Nullable; -import android.support.annotation.StringRes; +import androidx.annotation.Nullable; +import androidx.annotation.StringRes; +import androidx.lifecycle.LifecycleOwner; +import androidx.lifecycle.Observer; /** * A SingleLiveEvent used for Snackbar messages. Like a {@link SingleLiveEvent} but also prevents diff --git a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/crash/CaocConfig.java b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/crash/CaocConfig.java index 5175bab4..fe2d23ea 100644 --- a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/crash/CaocConfig.java +++ b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/crash/CaocConfig.java @@ -17,16 +17,17 @@ package me.goldze.mvvmhabit.crash; import android.app.Activity; -import android.support.annotation.DrawableRes; -import android.support.annotation.IntDef; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; import java.io.Serializable; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.reflect.Modifier; +import androidx.annotation.DrawableRes; +import androidx.annotation.IntDef; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + public class CaocConfig implements Serializable { diff --git a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/crash/CaocInitProvider.java b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/crash/CaocInitProvider.java index b0cd50e5..27a4a937 100644 --- a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/crash/CaocInitProvider.java +++ b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/crash/CaocInitProvider.java @@ -20,8 +20,9 @@ import android.content.ContentValues; import android.database.Cursor; import android.net.Uri; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; public class CaocInitProvider extends ContentProvider { diff --git a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/crash/CustomActivityOnCrash.java b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/crash/CustomActivityOnCrash.java index c8dfb4d2..b081154a 100644 --- a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/crash/CustomActivityOnCrash.java +++ b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/crash/CustomActivityOnCrash.java @@ -27,9 +27,6 @@ import android.content.pm.ResolveInfo; import android.os.Build; import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.support.annotation.RestrictTo; import android.util.Log; import java.io.PrintWriter; @@ -46,6 +43,10 @@ import java.util.zip.ZipEntry; import java.util.zip.ZipFile; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.annotation.RestrictTo; + public final class CustomActivityOnCrash { diff --git a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/crash/DefaultErrorActivity.java b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/crash/DefaultErrorActivity.java index 1fbd7a56..240b6c1c 100644 --- a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/crash/DefaultErrorActivity.java +++ b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/crash/DefaultErrorActivity.java @@ -23,9 +23,6 @@ import android.content.DialogInterface; import android.content.res.TypedArray; import android.os.Bundle; -import android.support.annotation.Nullable; -import android.support.v4.content.res.ResourcesCompat; -import android.support.v7.app.AppCompatActivity; import android.util.TypedValue; import android.view.View; import android.widget.Button; @@ -33,6 +30,9 @@ import android.widget.TextView; import android.widget.Toast; +import androidx.annotation.Nullable; +import androidx.appcompat.app.AppCompatActivity; +import androidx.core.content.res.ResourcesCompat; import me.goldze.mvvmhabit.R; diff --git a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/http/ApiDisposableObserver.java b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/http/ApiDisposableObserver.java index ce2fbc00..26dbd076 100644 --- a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/http/ApiDisposableObserver.java +++ b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/http/ApiDisposableObserver.java @@ -1,6 +1,5 @@ package me.goldze.mvvmhabit.http; - import io.reactivex.observers.DisposableObserver; import me.goldze.mvvmhabit.base.AppManager; import me.goldze.mvvmhabit.utils.KLog; diff --git a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/http/NetworkUtil.java b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/http/NetworkUtil.java index 6b64313f..fb44a7f7 100644 --- a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/http/NetworkUtil.java +++ b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/http/NetworkUtil.java @@ -5,7 +5,6 @@ import android.net.NetworkInfo; import android.telephony.TelephonyManager; - import java.io.IOException; import java.net.HttpURLConnection; import java.net.InetAddress; diff --git a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/http/interceptor/CacheInterceptor.java b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/http/interceptor/CacheInterceptor.java index 7484d0eb..5867077b 100644 --- a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/http/interceptor/CacheInterceptor.java +++ b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/http/interceptor/CacheInterceptor.java @@ -1,8 +1,6 @@ package me.goldze.mvvmhabit.http.interceptor; -import android.app.Activity; import android.content.Context; -import android.widget.Toast; import java.io.IOException; diff --git a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/utils/ImageUtils.java b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/utils/ImageUtils.java index a9e9594d..85b35a3a 100644 --- a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/utils/ImageUtils.java +++ b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/utils/ImageUtils.java @@ -28,8 +28,6 @@ import android.text.TextUtils; import android.util.DisplayMetrics; -import org.reactivestreams.Subscriber; - import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.ByteArrayInputStream; diff --git a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/utils/MaterialDialogUtils.java b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/utils/MaterialDialogUtils.java index c3ab2dda..73e444e0 100644 --- a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/utils/MaterialDialogUtils.java +++ b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/utils/MaterialDialogUtils.java @@ -3,10 +3,8 @@ import android.content.Context; import android.content.DialogInterface; import android.graphics.Color; -import android.support.annotation.NonNull; import android.text.InputType; import android.text.TextUtils; -import android.util.TypedValue; import android.view.KeyEvent; import android.view.View; @@ -17,6 +15,7 @@ import java.util.List; +import androidx.annotation.NonNull; import me.goldze.mvvmhabit.R; diff --git a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/utils/RxUtils.java b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/utils/RxUtils.java index 30e5528b..19423b8b 100644 --- a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/utils/RxUtils.java +++ b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/utils/RxUtils.java @@ -1,11 +1,11 @@ package me.goldze.mvvmhabit.utils; import android.content.Context; -import android.support.v4.app.Fragment; import com.trello.rxlifecycle2.LifecycleProvider; import com.trello.rxlifecycle2.LifecycleTransformer; +import androidx.fragment.app.Fragment; import io.reactivex.Observable; import io.reactivex.ObservableSource; import io.reactivex.ObservableTransformer; diff --git a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/utils/SPUtils.java b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/utils/SPUtils.java index 2a88acf0..486aff49 100644 --- a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/utils/SPUtils.java +++ b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/utils/SPUtils.java @@ -2,13 +2,14 @@ import android.content.Context; import android.content.SharedPreferences; -import android.support.annotation.NonNull; import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.Set; +import androidx.annotation.NonNull; + /** * Created by goldze on 2017/5/14. * SharedPreferences工具类 diff --git a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/utils/ToastUtils.java b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/utils/ToastUtils.java index a7097d5b..6ab540e2 100644 --- a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/utils/ToastUtils.java +++ b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/utils/ToastUtils.java @@ -1,12 +1,8 @@ package me.goldze.mvvmhabit.utils; + import android.content.Context; import android.os.Handler; import android.os.Looper; -import android.support.annotation.ColorInt; -import android.support.annotation.DrawableRes; -import android.support.annotation.LayoutRes; -import android.support.annotation.Nullable; -import android.support.annotation.StringRes; import android.text.SpannableString; import android.text.Spanned; import android.text.style.ForegroundColorSpan; @@ -17,6 +13,12 @@ import java.lang.ref.WeakReference; +import androidx.annotation.ColorInt; +import androidx.annotation.DrawableRes; +import androidx.annotation.LayoutRes; +import androidx.annotation.Nullable; +import androidx.annotation.StringRes; + /** * Created by goldze on 2017/5/14. * 吐司工具类 diff --git a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/utils/Utils.java b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/utils/Utils.java index affc9ecc..4d3996ad 100644 --- a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/utils/Utils.java +++ b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/utils/Utils.java @@ -2,7 +2,8 @@ import android.annotation.SuppressLint; import android.content.Context; -import android.support.annotation.NonNull; + +import androidx.annotation.NonNull; /** * Created by goldze on 2017/5/14. diff --git a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/utils/compression/Luban.java b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/utils/compression/Luban.java index a3d45487..548a43b8 100644 --- a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/utils/compression/Luban.java +++ b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/utils/compression/Luban.java @@ -5,7 +5,6 @@ import android.graphics.BitmapFactory; import android.graphics.Matrix; import android.media.ExifInterface; -import android.support.annotation.NonNull; import android.text.TextUtils; import android.util.Log; @@ -16,6 +15,7 @@ import java.util.ArrayList; import java.util.List; +import androidx.annotation.NonNull; import io.reactivex.Observable; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.functions.Consumer; diff --git a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/utils/compression/Preconditions.java b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/utils/compression/Preconditions.java index ffec2c26..590dfde0 100644 --- a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/utils/compression/Preconditions.java +++ b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/utils/compression/Preconditions.java @@ -1,6 +1,6 @@ package me.goldze.mvvmhabit.utils.compression; -import android.support.annotation.Nullable; +import androidx.annotation.Nullable; final class Preconditions { diff --git a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/utils/constant/MemoryConstants.java b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/utils/constant/MemoryConstants.java index 699e0370..639efd6d 100644 --- a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/utils/constant/MemoryConstants.java +++ b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/utils/constant/MemoryConstants.java @@ -1,10 +1,10 @@ package me.goldze.mvvmhabit.utils.constant; -import android.support.annotation.IntDef; - import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; +import androidx.annotation.IntDef; + /** * Created by goldze on 2017/5/14. * 存储相关常量 diff --git a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/utils/constant/TimeConstants.java b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/utils/constant/TimeConstants.java index 669cb180..6b6ef534 100644 --- a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/utils/constant/TimeConstants.java +++ b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/utils/constant/TimeConstants.java @@ -1,10 +1,10 @@ package me.goldze.mvvmhabit.utils.constant; -import android.support.annotation.IntDef; - import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; +import androidx.annotation.IntDef; + /** * Created by goldze on 2017/5/14. * 时间相关常量 From de2df4bb99b63ef6c3883ade1df1e70121b40d7a Mon Sep 17 00:00:00 2001 From: zengxianze <603883033@qq.com> Date: Fri, 15 Nov 2019 09:19:10 +0800 Subject: [PATCH 02/11] Migrate AndroidX Migrate AndroidX --- README.md | 2 ++ .../me/goldze/mvvmhabit/http/download/ProgressCallBack.java | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b83d80a0..e0beb17f 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,8 @@ - 升级第三方依赖库; - 修改文档说明。 #### [更多日志](./UpdateLog.md) + +#### [AndroidX分支](https://github.com/goldze/MVVMHabit/tree/androidx) *** **注:[1.x-废弃版(最后版本:1.2.6.1)](https://github.com/goldze/MVVMHabit/tree/1.2.6.1)、[2.x-顺手版(最后版本:2.0.10)](https://github.com/goldze/MVVMHabit/tree/2.0.10)已停止维护,建议使用当前[3.x-健壮版(最后版本:3.1.3)](https://github.com/goldze/MVVMHabit)。** diff --git a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/http/download/ProgressCallBack.java b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/http/download/ProgressCallBack.java index 12967cdd..e3aea755 100644 --- a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/http/download/ProgressCallBack.java +++ b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/http/download/ProgressCallBack.java @@ -60,7 +60,6 @@ public void saveFile(ResponseBody body) { fos.write(buf, 0, len); } fos.flush(); - unsubscribe(); //onCompleted(); } catch (FileNotFoundException e) { e.printStackTrace(); @@ -70,6 +69,7 @@ public void saveFile(ResponseBody body) { try { if (is != null) is.close(); if (fos != null) fos.close(); + unsubscribe(); } catch (IOException e) { Log.e("saveFile", e.getMessage()); } From 4e2bafa5f28e8d0148fb71d55c53e746b904e9a3 Mon Sep 17 00:00:00 2001 From: zengxianze <603883033@qq.com> Date: Wed, 27 Nov 2019 14:12:08 +0800 Subject: [PATCH 03/11] supplement supplement --- README.md | 770 +----------------------------------------------------- 1 file changed, 1 insertion(+), 769 deletions(-) diff --git a/README.md b/README.md index e0beb17f..18ec2a1f 100644 --- a/README.md +++ b/README.md @@ -1,773 +1,10 @@ ## 最新日志 -**v3.0.7:2019年1月25日** - -- 优化框架代码,解决已知Bug; -- 新增ViewPager+Fragment例子; -- 新增RecycleView多布局例子; -- 升级第三方依赖库; -- 修改文档说明。 +#### AndroidX分支目前还处于过度阶段,如果你的项目需要AndroidX的支持,那么请使用本地依赖的方式导入项目Library。 #### [更多日志](./UpdateLog.md) -#### [AndroidX分支](https://github.com/goldze/MVVMHabit/tree/androidx) -*** - -**注:[1.x-废弃版(最后版本:1.2.6.1)](https://github.com/goldze/MVVMHabit/tree/1.2.6.1)、[2.x-顺手版(最后版本:2.0.10)](https://github.com/goldze/MVVMHabit/tree/2.0.10)已停止维护,建议使用当前[3.x-健壮版(最后版本:3.1.3)](https://github.com/goldze/MVVMHabit)。** - > **原文地址:** [https://github.com/goldze/MVVMHabit](https://github.com/goldze/MVVMHabit) MVVMHabit-Family -# MVVMHabit -## -目前,android流行的MVC、MVP模式的开发框架很多,然而一款基于MVVM模式开发框架却很少。**MVVMHabit是以谷歌DataBinding+LiveData+ViewModel框架为基础,整合Okhttp+RxJava+Retrofit+Glide等流行模块,加上各种原生控件自定义的BindingAdapter,让事件与数据源完美绑定的一款容易上瘾的实用性MVVM快速开发框架**。从此告别findViewById(),告别setText(),告别setOnClickListener()... - -## 框架流程 -![](./img/fc.png) - -## 框架特点 -- **快速开发** - - 只需要写项目的业务逻辑,不用再去关心网络请求、权限申请、View的生命周期等问题,撸起袖子就是干。 - -- **维护方便** - - MVVM开发模式,低耦合,逻辑分明。Model层负责将请求的数据交给ViewModel;ViewModel层负责将请求到的数据做业务逻辑处理,最后交给View层去展示,与View一一对应;View层只负责界面绘制刷新,不处理业务逻辑,非常适合分配独立模块开发。 - -- **流行框架** - - [retrofit](https://github.com/square/retrofit)+[okhttp](https://github.com/square/okhttp)+[rxJava](https://github.com/ReactiveX/RxJava)负责网络请求;[gson](https://github.com/google/gson)负责解析json数据;[glide](https://github.com/bumptech/glide)负责加载图片;[rxlifecycle](https://github.com/trello/RxLifecycle)负责管理view的生命周期;与网络请求共存亡;[rxbinding](https://github.com/JakeWharton/RxBinding)结合databinding扩展UI事件;[rxpermissions](https://github.com/tbruyelle/RxPermissions)负责Android 6.0权限申请;[material-dialogs](https://github.com/afollestad/material-dialogs)一个漂亮的、流畅的、可定制的material design风格的对话框。 - -- **数据绑定** - - 满足google目前控件支持的databinding双向绑定,并扩展原控件一些不支持的数据绑定。例如将图片的url路径绑定到ImageView控件中,在BindingAdapter方法里面则使用Glide加载图片;View的OnClick事件在BindingAdapter中方法使用RxView防重复点击,再把事件回调到ViewModel层,实现xml与ViewModel之间数据和事件的绑定(框架里面部分扩展控件和回调命令使用的是@kelin原创的)。 - -- **基类封装** - - 专门针对MVVM模式打造的BaseActivity、BaseFragment、BaseViewModel,在View层中不再需要定义ViewDataBinding和ViewModel,直接在BaseActivity、BaseFragment上限定泛型即可使用。普通界面只需要编写Fragment,然后使用ContainerActivity盛装(代理),这样就不需要每个界面都在AndroidManifest中注册一遍。 - -- **全局操作** - 1. 全局的Activity堆栈式管理,在程序任何地方可以打开、结束指定的Activity,一键退出应用程序。 - 2. LoggingInterceptor全局拦截网络请求日志,打印Request和Response,格式化json、xml数据显示,方便与后台调试接口。 - 3. 全局Cookie,支持SharedPreferences和内存两种管理模式。 - 4. 通用的网络请求异常监听,根据不同的状态码或异常设置相应的message。 - 5. 全局的异常捕获,程序发生异常时不会崩溃,可跳入异常界面重启应用。 - 6. 全局事件回调,提供RxBus、Messenger两种回调方式。 - 7. 全局任意位置一行代码实现文件下载进度监听(暂不支持多文件进度监听)。 - 8. 全局点击事件防抖动处理,防止点击过快。 - - -## 1、准备工作 -> 网上的很多有关MVVM的资料,在此就不再阐述什么是MVVM了,不清楚的朋友可以先去了解一下。[todo-mvvm-live](https://github.com/googlesamples/android-architecture/tree/todo-mvvm-live) -### 1.1、启用databinding -在主工程app的build.gradle的android {}中加入: -```gradle -dataBinding { - enabled true -} -``` -### 1.2、依赖Library -从远程依赖: - -在根目录的build.gradle中加入 -```gradle -allprojects { - repositories { - ... - google() - jcenter() - maven { url 'https://jitpack.io' } - } -} -``` -在主项目app的build.gradle中依赖 -```gradle -dependencies { - ... - implementation 'com.github.goldze:MVVMHabit:3.1.3' -} -``` -或 - -下载例子程序,在主项目app的build.gradle中依赖例子程序中的**mvvmhabit**: -```gradle -dependencies { - ... - implementation project(':mvvmhabit') -} -``` - -### 1.3、配置config.gradle -如果不是远程依赖,而是下载的例子程序,那么还需要将例子程序中的config.gradle放入你的主项目根目录中,然后在根目录build.gradle的第一行加入: - -```gradle -apply from: "config.gradle" -``` - -**注意:** config.gradle中的 - -android = [] 是你的开发相关版本配置,可自行修改 - -support = [] 是你的support相关配置,可自行修改 - -dependencies = [] 是依赖第三方库的配置,可以加新库,但不要去修改原有第三方库的版本号,不然可能会编译不过 -### 1.4、配置AndroidManifest -添加权限: -```xml - - - - - - -``` -配置Application: - -继承**mvvmhabit**中的BaseApplication,或者调用 - -```java -BaseApplication.setApplication(this); -``` -来初始化你的Application - -可以在你的自己AppApplication中配置 - -```java -//是否开启日志打印 -KLog.init(true); -//配置全局异常崩溃操作 -CaocConfig.Builder.create() - .backgroundMode(CaocConfig.BACKGROUND_MODE_SILENT) //背景模式,开启沉浸式 - .enabled(true) //是否启动全局异常捕获 - .showErrorDetails(true) //是否显示错误详细信息 - .showRestartButton(true) //是否显示重启按钮 - .trackActivities(true) //是否跟踪Activity - .minTimeBetweenCrashesMs(2000) //崩溃的间隔时间(毫秒) - .errorDrawable(R.mipmap.ic_launcher) //错误图标 - .restartActivity(LoginActivity.class) //重新启动后的activity - //.errorActivity(YourCustomErrorActivity.class) //崩溃后的错误activity - //.eventListener(new YourCustomEventListener()) //崩溃后的错误监听 - .apply(); -``` - -## 2、快速上手 - -### 2.1、第一个Activity -> 以大家都熟悉的登录操作为例:三个文件**LoginActivty.java**、**LoginViewModel.java**、**activity_login.xml** - -##### 2.1.1、关联ViewModel -在activity_login.xml中关联LoginViewModel。 -```xml - - - - - ..... - - -``` - -> variable - type:类的全路径
variable - name:变量名 - -##### 2.1.2、继承BaseActivity - -LoginActivity继承BaseActivity -```java - -public class LoginActivity extends BaseActivity { - //ActivityLoginBinding类是databinding框架自定生成的,对activity_login.xml - @Override - public int initContentView(Bundle savedInstanceState) { - return R.layout.activity_login; - } - - @Override - public int initVariableId() { - return BR.viewModel; - } - - @Override - public LoginViewModel initViewModel() { - //View持有ViewModel的引用,如果没有特殊业务处理,这个方法可以不重写 - return ViewModelProviders.of(this).get(LoginViewModel.class); - } -} -``` -> 保存activity_login.xml后databinding会生成一个ActivityLoginBinding类。(如果没有生成,试着点击Build->Clean Project) - -BaseActivity是一个抽象类,有两个泛型参数,一个是ViewDataBinding,另一个是BaseViewModel,上面的ActivityLoginBinding则是继承的ViewDataBinding作为第一个泛型约束,LoginViewModel继承BaseViewModel作为第二个泛型约束。 - -重写BaseActivity的二个抽象方法 - -initContentView() 返回界面layout的id
-initVariableId() 返回变量的id,对应activity_login中name="viewModel",就像一个控件的id,可以使用R.id.xxx,这里的BR跟R文件一样,由系统生成,使用BR.xxx找到这个ViewModel的id。
- -选择性重写initViewModel()方法,返回ViewModel对象 -```java -@Override -public LoginViewModel initViewModel() { - //View持有ViewModel的引用,如果没有特殊业务处理,这个方法可以不重写 - return ViewModelProviders.of(this).get(LoginViewModel.class); -} -``` - -**注意:** 不重写initViewModel(),默认会创建LoginActivity中第二个泛型约束的LoginViewModel,如果没有指定第二个泛型,则会创建BaseViewModel - -##### 2.1.3、继承BaseViewModel - -LoginViewModel继承BaseViewModel -```java -public class LoginViewModel extends BaseViewModel { - public LoginViewModel(@NonNull Application application) { - super(application); - } - .... -} -``` -BaseViewModel与BaseActivity通过LiveData来处理常用UI逻辑,即可在ViewModel中使用父类的showDialog()、startActivity()等方法。在这个LoginViewModel中就可以尽情的写你的逻辑了! -> BaseFragment的使用和BaseActivity一样,详情参考Demo。 - -### 2.2、数据绑定 -> 拥有databinding框架自带的双向绑定,也有扩展 -##### 2.2.1、传统绑定 -绑定用户名: - -在LoginViewModel中定义 -```java -//用户名的绑定 -public ObservableField userName = new ObservableField<>(""); -``` -在用户名EditText标签中绑定 -```xml -android:text="@={viewModel.userName}" -``` -这样一来,输入框中输入了什么,userName.get()的内容就是什么,userName.set("")设置什么,输入框中就显示什么。 -**注意:** @符号后面需要加=号才能达到双向绑定效果;userName需要是public的,不然viewModel无法找到它。 - -点击事件绑定: - -在LoginViewModel中定义 -```java -//登录按钮的点击事件 -public View.OnClickListener loginOnClick = new View.OnClickListener() { - @Override - public void onClick(View v) { - - } -}; -``` -在登录按钮标签中绑定 -```xml -android:onClick="@{viewModel.loginOnClick}" -``` -这样一来,用户的点击事件直接被回调到ViewModel层了,更好的维护了业务逻辑 - -这就是强大的databinding框架双向绑定的特性,不用再给控件定义id,setText(),setOnClickListener()。 - -**但是,光有这些,完全满足不了我们复杂业务的需求啊!MVVMHabit闪亮登场:它有一套自定义的绑定规则,可以满足大部分的场景需求,请继续往下看。** - -##### 2.2.2、自定义绑定 -还拿点击事件说吧,不用传统的绑定方式,使用自定义的点击事件绑定。 - -在LoginViewModel中定义 -```java -//登录按钮的点击事件 -public BindingCommand loginOnClickCommand = new BindingCommand(new BindingAction() { - @Override - public void call() { - - } -}); -``` -在activity_login中定义命名空间 -```xml -xmlns:binding="http://schemas.android.com/apk/res-auto" -``` -在登录按钮标签中绑定 -```xml -binding:onClickCommand="@{viewModel.loginOnClickCommand}" -``` -这和原本传统的绑定不是一样吗?不,这其实是有差别的。使用这种形式的绑定,在原本事件绑定的基础之上,带有防重复点击的功能,1秒内多次点击也只会执行一次操作。如果不需要防重复点击,可以加入这条属性 -```xml -binding:isThrottleFirst="@{Boolean.TRUE}" -``` -那这功能是在哪里做的呢?答案在下面的代码中。 -```java -//防重复点击间隔(秒) -public static final int CLICK_INTERVAL = 1; - -/** -* requireAll 是意思是是否需要绑定全部参数, false为否 -* View的onClick事件绑定 -* onClickCommand 绑定的命令, -* isThrottleFirst 是否开启防止过快点击 -*/ -@BindingAdapter(value = {"onClickCommand", "isThrottleFirst"}, requireAll = false) -public static void onClickCommand(View view, final BindingCommand clickCommand, final boolean isThrottleFirst) { - if (isThrottleFirst) { - RxView.clicks(view) - .subscribe(new Consumer() { - @Override - public void accept(Object object) throws Exception { - if (clickCommand != null) { - clickCommand.execute(); - } - } - }); - } else { - RxView.clicks(view) - .throttleFirst(CLICK_INTERVAL, TimeUnit.SECONDS)//1秒钟内只允许点击1次 - .subscribe(new Consumer() { - @Override - public void accept(Object object) throws Exception { - if (clickCommand != null) { - clickCommand.execute(); - } - } - }); - } -} -``` -onClickCommand方法是自定义的,使用@BindingAdapter注解来标明这是一个绑定方法。在方法中使用了RxView来增强view的clicks事件,.throttleFirst()限制订阅者在指定的时间内重复执行,最后通过BindingCommand将事件回调出去,就好比有一种拦截器,在点击时先做一下判断,然后再把事件沿着他原有的方向传递。 - -是不是觉得有点意思,好戏还在后头呢! -##### 2.2.3、自定义ImageView图片加载 -绑定图片路径: - -在ViewModel中定义 -```java -public String imgUrl = "http://img0.imgtn.bdimg.com/it/u=2183314203,562241301&fm=26&gp=0.jpg"; -``` -在ImageView标签中 -```xml -binding:url="@{viewModel.imgUrl}" -``` -url是图片路径,这样绑定后,这个ImageView就会去显示这张图片,不限网络图片还是本地图片。 - -如果需要给一个默认加载中的图片,可以加这一句 -```xml -binding:placeholderRes="@{R.mipmap.ic_launcher_round}" -``` -> R文件需要在data标签中导入使用,如:`` - -BindingAdapter中的实现 -```java -@BindingAdapter(value = {"url", "placeholderRes"}, requireAll = false) -public static void setImageUri(ImageView imageView, String url, int placeholderRes) { - if (!TextUtils.isEmpty(url)) { - //使用Glide框架加载图片 - Glide.with(imageView.getContext()) - .load(url) - .placeholder(placeholderRes) - .into(imageView); - } -} -``` -很简单就自定义了一个ImageView图片加载的绑定,学会这种方式,可自定义扩展。 -> 如果你对这些感兴趣,可以下载源码,在binding包中可以看到各类控件的绑定实现方式 - -##### 2.2.4、RecyclerView绑定 -> RecyclerView也是很常用的一种控件,传统的方式需要针对各种业务要写各种Adapter,如果你使用了mvvmhabit,则可大大简化这种工作量,从此告别setAdapter()。 - -在ViewModel中定义: -```java -//给RecyclerView添加items -public final ObservableList observableList = new ObservableArrayList<>(); -//给RecyclerView添加ItemBinding -public final ItemBinding itemBinding = ItemBinding.of(BR.viewModel, R.layout.item_network); -``` -ObservableList<>和ItemBinding<>的泛型是Item布局所对应的ItemViewModel - -在xml中绑定 -```xml - -``` -layoutManager控制是线性(包含水平和垂直)排列还是网格排列,lineManager是设置分割线 - -网格布局的写法:`binding:layoutManager="@{LayoutManagers.grid(3)}`
-水平布局的写法:`binding:layoutManager="@{LayoutManagers.linear(LinearLayoutManager.HORIZONTAL,Boolean.FALSE)}"`
- -使用到相关类,则需要导入该类才能使用,和导入Java类相似 - -> ``
-> ``
-> `` - - -这样绑定后,在ViewModel中调用ObservableList的add()方法,添加一个ItemViewModel,界面上就会实时绘制出一个Item。在Item对应的ViewModel中,同样可以以绑定的形式完成逻辑 -> 可以在请求到数据后,循环添加`observableList.add(new NetWorkItemViewModel(NetWorkViewModel.this, entity));`详细可以参考例子程序中NetWorkViewModel类。 - -**注意:** 在以前的版本中,ItemViewModel是继承BaseViewModel,传入Context,新版本3.x中可继承ItemViewModel,传入当前页面的ViewModel - -更多RecyclerView、ListView、ViewPager等绑定方式,请参考 [https://github.com/evant/binding-collection-adapter](https://github.com/evant/binding-collection-adapter) - -### 2.3、网络请求 -> 网络请求一直都是一个项目的核心,现在的项目基本都离不开网络,一个好用网络请求框架可以让开发事半功倍。 -#### 2.3.1、Retrofit+Okhttp+RxJava -> 现今,这三个组合基本是网络请求的标配,如果你对这三个框架不了解,建议先去查阅相关资料。 - -square出品的框架,用起来确实非常方便。**MVVMHabit**中引入了 -```gradle -api "com.squareup.okhttp3:okhttp:3.10.0" -api "com.squareup.retrofit2:retrofit:2.4.0" -api "com.squareup.retrofit2:converter-gson:2.4.0" -api "com.squareup.retrofit2:adapter-rxjava2:2.4.0" -``` -构建Retrofit时加入 -```java -Retrofit retrofit = new Retrofit.Builder() - .addConverterFactory(GsonConverterFactory.create()) - .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) - .build(); -``` -或者直接使用例子程序中封装好的RetrofitClient -#### 2.3.2、网络拦截器 -**LoggingInterceptor:** 全局拦截请求信息,格式化打印Request、Response,可以清晰的看到与后台接口对接的数据, -```java -LoggingInterceptor mLoggingInterceptor = new LoggingInterceptor - .Builder()//构建者模式 - .loggable(true) //是否开启日志打印 - .setLevel(Level.BODY) //打印的等级 - .log(Platform.INFO) // 打印类型 - .request("Request") // request的Tag - .response("Response")// Response的Tag - .addHeader("version", BuildConfig.VERSION_NAME)//打印版本 - .build() -``` -构建okhttp时加入 -```java -OkHttpClient okHttpClient = new OkHttpClient.Builder() - .addInterceptor(mLoggingInterceptor) - .build(); -``` -**CacheInterceptor:** 缓存拦截器,当没有网络连接的时候自动读取缓存中的数据,缓存存放时间默认为3天。
-创建缓存对象 -```java -//缓存时间 -int CACHE_TIMEOUT = 10 * 1024 * 1024 -//缓存存放的文件 -File httpCacheDirectory = new File(mContext.getCacheDir(), "goldze_cache"); -//缓存对象 -Cache cache = new Cache(httpCacheDirectory, CACHE_TIMEOUT); -``` -构建okhttp时加入 -```java -OkHttpClient okHttpClient = new OkHttpClient.Builder() - .cache(cache) - .addInterceptor(new CacheInterceptor(mContext)) - .build(); -``` -#### 2.3.3、Cookie管理 -**MVVMHabit**提供两种CookieStore:**PersistentCookieStore** (SharedPreferences管理)和**MemoryCookieStore** (内存管理),可以根据自己的业务需求,在构建okhttp时加入相应的cookieJar -```java -OkHttpClient okHttpClient = new OkHttpClient.Builder() - .cookieJar(new CookieJarImpl(new PersistentCookieStore(mContext))) - .build(); -``` -或者 -```java -OkHttpClient okHttpClient = new OkHttpClient.Builder() - .cookieJar(new CookieJarImpl(new MemoryCookieStore())) - .build(); -``` -#### 2.3.4、绑定生命周期 -请求在ViewModel层。默认在BaseActivity中注入了LifecycleProvider对象到ViewModel,用于绑定请求的生命周期,View与请求共存亡。 -```java -RetrofitClient.getInstance().create(DemoApiService.class) - .demoGet() - .compose(RxUtils.bindToLifecycle(getLifecycleProvider())) // 请求与View周期同步 - .compose(RxUtils.schedulersTransformer()) // 线程调度 - .compose(RxUtils.exceptionTransformer()) // 网络错误的异常转换 - .subscribe(new Consumer>() { - @Override - public void accept(BaseResponse response) throws Exception { - - } - }, new Consumer() { - @Override - public void accept(ResponseThrowable throwable) throws Exception { - - } - }); - -``` -在请求时关键需要加入组合操作符`.compose(RxUtils.bindToLifecycle(getLifecycleProvider()))`
-**注意:** 由于BaseActivity/BaseFragment都实现了LifecycleProvider接口,并且默认注入到ViewModel中,所以在调用请求方法时可以直接调用getLifecycleProvider()拿到生命周期接口。如果你没有使用 **mvvmabit** 里面的BaseActivity或BaseFragment,使用自己定义的Base,那么需要让你自己的Activity继承RxAppCompatActivity、Fragment继承RxFragment才能用`RxUtils.bindToLifecycle(lifecycle)`方法。 -#### 2.3.5、网络异常处理 -网络异常在网络请求中非常常见,比如请求超时、解析错误、资源不存在、服务器内部错误等,在客户端则需要做相应的处理(当然,你可以把一部分异常甩锅给网络,比如当出现code 500时,提示:请求超时,请检查网络连接,此时偷偷将异常信息发送至后台(手动滑稽))。
- -在使用Retrofit请求时,加入组合操作符`.compose(RxUtils.exceptionTransformer())`,当发生网络异常时,回调onError(ResponseThrowable)方法,可以拿到异常的code和message,做相应处理。
- -> mvvmhabit中自定义了一个[ExceptionHandle](./mvvmhabit/src/main/java/me/goldze/mvvmhabit/http/ExceptionHandle.java),已为你完成了大部分网络异常的判断,也可自行根据项目的具体需求调整逻辑。
- -**注意:** 这里的网络异常code,并非是与服务端协议约定的code。网络异常可以分为两部分,一部分是协议异常,即出现code = 404、500等,属于HttpException,另一部分为请求异常,即出现:连接超时、解析错误、证书验证失等。而与服务端约定的code规则,它不属于网络异常,它是属于一种业务异常。在请求中可以使用RxJava的filter(过滤器),也可以自定义BaseSubscriber统一处理网络请求的业务逻辑异常。由于每个公司的业务协议不一样,所以具体需要你自己来处理该类异常。 -## 3、辅助功能 -> 一个完整的快速开发框架,当然也少不了常用的辅助类。下面来介绍一下**MVVMabit**中有哪些辅助功能。 -### 3.1、事件总线 -> 事件总线存在的优点想必大家都很清楚了,android自带的广播机制对于组件间的通信而言,使用非常繁琐,通信组件彼此之间的订阅和发布的耦合也比较严重,特别是对于事件的定义,广播机制局限于序列化的类(通过Intent传递),不够灵活。 -#### 3.3.1、RxBus -RxBus并不是一个库,而是一种模式。相信大多数开发者都使用过EventBus,对RxBus也是很熟悉。由于**MVVMabit**中已经加入RxJava,所以采用了RxBus代替EventBus作为事件总线通信,以减少库的依赖。 - -使用方法: - -在ViewModel中重写registerRxBus()方法来注册RxBus,重写removeRxBus()方法来移除RxBus -```java -//订阅者 -private Disposable mSubscription; -//注册RxBus -@Override -public void registerRxBus() { - super.registerRxBus(); - mSubscription = RxBus.getDefault().toObservable(String.class) - .subscribe(new Consumer() { - @Override - public void accept(String s) throws Exception { - - } - }); - //将订阅者加入管理站 - RxSubscriptions.add(mSubscription); -} - -//移除RxBus -@Override -public void removeRxBus() { - super.removeRxBus(); - //将订阅者从管理站中移除 - RxSubscriptions.remove(mSubscription); -} -``` -在需要执行回调的地方发送 -```java -RxBus.getDefault().post(object); -``` -#### 3.3.2、Messenger -Messenger是一个轻量级全局的消息通信工具,在我们的复杂业务中,难免会出现一些交叉的业务,比如ViewModel与ViewModel之间需要有数据交换,这时候可以轻松地使用Messenger发送一个实体或一个空消息,将事件从一个ViewModel回调到另一个ViewModel中。 - -使用方法: - -定义一个静态String类型的字符串token -```java -public static final String TOKEN_LOGINVIEWMODEL_REFRESH = "token_loginviewmodel_refresh"; -``` -在ViewModel中注册消息监听 -```java -//注册一个空消息监听 -//参数1:接受人(上下文) -//参数2:定义的token -//参数3:执行的回调监听 -Messenger.getDefault().register(this, LoginViewModel.TOKEN_LOGINVIEWMODEL_REFRESH, new BindingAction() { - @Override - public void call() { - - } -}); - -//注册一个带数据回调的消息监听 -//参数1:接受人(上下文) -//参数2:定义的token -//参数3:实体的泛型约束 -//参数4:执行的回调监听 -Messenger.getDefault().register(this, LoginViewModel.TOKEN_LOGINVIEWMODEL_REFRESH, String.class, new BindingConsumer() { - @Override - public void call(String s) { - - } -}); -``` -在需要回调的地方使用token发送消息 -```java -//发送一个空消息 -//参数1:定义的token -Messenger.getDefault().sendNoMsg(LoginViewModel.TOKEN_LOGINVIEWMODEL_REFRESH); - -//发送一个带数据回调消息 -//参数1:回调的实体 -//参数2:定义的token -Messenger.getDefault().send("refresh",LoginViewModel.TOKEN_LOGINVIEWMODEL_REFRESH); -``` -> token最好不要重名,不然可能就会出现逻辑上的bug,为了更好的维护和清晰逻辑,建议以`aa_bb_cc`的格式来定义token。aa:TOKEN,bb:ViewModel的类名,cc:动作名(功能名)。 - -> 为了避免大量使用Messenger,建议只在ViewModel与ViewModel之间使用,View与ViewModel之间采用ObservableField去监听UI上的逻辑,可在继承了Base的Activity或Fragment中重写initViewObservable()方法来初始化UI的监听 - - -注册了监听,当然也要解除它。在BaseActivity、BaseFragment的onDestroy()方法里已经调用`Messenger.getDefault().unregister(viewModel);`解除注册,所以不用担心忘记解除导致的逻辑错误和内存泄漏。 -### 3.2、文件下载 -文件下载几乎是每个app必备的功能,图文的下载,软件的升级等都要用到,mvvmhabit使用Retrofit+Okhttp+RxJava+RxBus实现一行代码监听带进度的文件下载。 - -下载文件 -```java -String loadUrl = "你的文件下载路径"; -String destFileDir = context.getCacheDir().getPath(); //文件存放的路径 -String destFileName = System.currentTimeMillis() + ".apk";//文件存放的名称 -DownLoadManager.getInstance().load(loadUrl, new ProgressCallBack(destFileDir, destFileName) { - @Override - public void onStart() { - //RxJava的onStart() - } - - @Override - public void onCompleted() { - //RxJava的onCompleted() - } - - @Override - public void onSuccess(ResponseBody responseBody) { - //下载成功的回调 - } - - @Override - public void progress(final long progress, final long total) { - //下载中的回调 progress:当前进度 ,total:文件总大小 - } - - @Override - public void onError(Throwable e) { - //下载错误回调 - } -}); -``` -> 在ProgressResponseBody中使用了RxBus,发送下载进度信息到ProgressCallBack中,继承ProgressCallBack就可以监听到下载状态。回调方法全部执行在主线程,方便UI的更新,详情请参考例子程序。 -### 3.3、ContainerActivity -一个盛装Fragment的一个容器(代理)Activity,普通界面只需要编写Fragment,使用此Activity盛装,这样就不需要每个界面都在AndroidManifest中注册一遍 - -使用方法: - -在ViewModel中调用BaseViewModel的方法开一个Fragment -```java -startContainerActivity(你的Fragment类名.class.getCanonicalName()) -``` -在ViewModel中调用BaseViewModel的方法,携带一个序列化实体打开一个Fragment -```java -Bundle mBundle = new Bundle(); -mBundle.putParcelable("entity", entity); -startContainerActivity(你的Fragment类名.class.getCanonicalName(), mBundle); -``` -在你的Fragment中取出实体 -```java -Bundle mBundle = getArguments(); -if (mBundle != null) { - entity = mBundle.getParcelable("entity"); -} -``` -### 3.4、6.0权限申请 -> 对RxPermissions已经熟悉的朋友可以跳过。 - -使用方法: - -例如请求相机权限,在ViewModel中调用 -```java -//请求打开相机权限 -RxPermissions rxPermissions = new RxPermissions((Activity) context); -rxPermissions.request(Manifest.permission.CAMERA) - .subscribe(new Consumer() { - @Override - public void accept(Boolean aBoolean) throws Exception { - if (aBoolean) { - ToastUtils.showShort("权限已经打开,直接跳入相机"); - } else { - ToastUtils.showShort("权限被拒绝"); - } - } - }); -``` -更多权限申请方式请参考[RxPermissions原项目地址](https://github.com/tbruyelle/RxPermissions) -### 3.5、图片压缩 -> 为了节约用户流量和加快图片上传的速度,某些场景将图片在本地压缩后再传给后台,所以特此提供一个图片压缩的辅助功能。 - -使用方法: - -RxJava的方式压缩单张图片,得到一个压缩后的图片文件对象 -```java -String filePath = "mnt/sdcard/1.png"; -ImageUtils.compressWithRx(filePath, new Consumer() { - @Override - public void accept(File file) throws Exception { - //将文件放入RequestBody - ... - } -}); -``` -RxJava的方式压缩多张图片,按集合顺序每压缩成功一张,都将在onNext方法中得到一个压缩后的图片文件对象 -```java -List filePaths = new ArrayList<>(); -filePaths.add("mnt/sdcard/1.png"); -filePaths.add("mnt/sdcard/2.png"); -ImageUtils.compressWithRx(filePaths, new Subscriber() { - @Override - public void onCompleted() { - - } - - @Override - public void onError(Throwable e) { - - } - - @Override - public void onNext(File file) { - - } -}); -``` -### 3.6、其他辅助类 -**ToastUtils:** 吐司工具类 - -**MaterialDialogUtils:** Material风格对话框工具类 - -**SPUtils:** SharedPreferences工具类 - -**SDCardUtils:** SD卡相关工具类 - -**ConvertUtils:** 转换相关工具类 - -**StringUtils:** 字符串相关工具类 - -**RegexUtils:** 正则相关工具类 - -**KLog:** 日志打印,含json格式打印 - -## 4、附加 - -### 4.1、编译错误解决方法 -> 使用databinding其实有个缺点,就是会遇到一些编译错误,而AS不能很好的定位到错误的位置,这对于刚开始使用databinding的开发者来说是一个比较郁闷的事。那么我在此把我自己在开发中遇到的各种编译问题的解决方法分享给大家,希望这对你会有所帮助。 - -##### 4.1.1、绑定错误 -绑定错误是一个很常见的错误,基本都会犯。比如TextView的 `android:text=""` ,本来要绑定的是一个String类型,结果你不小心,可能绑了一个Boolean上去,或者变量名写错了,这时候编辑器不会报红错,而是在点编译运行的时候,在AS的Messages中会出现错误提示,如下图: - - - -解决方法:把错误提示拉到最下面 (上面的提示找不到BR类这个不要管它),看最后一个错误 ,这里会提示是哪个xml出了错,并且会定位到行数,按照提示找到对应位置,即可解决该编译错误的问题。 - -**注意:** 行数要+1,意思是上面报出第33行错误,实际是第34行错误,AS定位的不准确 (这可能是它的一个bug) - -##### 4.1.2、xml导包错误 -在xml中需要导入ViewModel或者一些业务相关的类,假如在xml中导错了类,那一行则会报红,但是res/layout却没有错误提示,有一种场景,非常特殊,不容易找出错误位置。就是你写了一个xml,导入了一个类,比如XXXUtils,后来因为业务需求,把那个XXXUtils删了,这时候res/layout下不会出现任何错误,而你在编译运行的时候,才会出现错误日志。苦逼的是,不会像上面那样提示哪一个xml文件,哪一行出错了,最后一个错误只是一大片的报错报告。如下图: - - - -解决方法:同样找到最后一个错误提示,找到Cannot resolve type for **xxx**这一句 (xxx是类名),然后使用全局搜索 (Ctrl+H) ,搜索哪个xml引用了这个类,跟踪点击进去,在xml就会出现一个红错,看到错误你就会明白了,这样就可解决该编译错误的问题。 - -##### 4.1.3、build错误 -构建多module工程时,如出现【4.1.1、绑定错误】,且你能确定这个绑定是没有问题的,经过修改后出现下图错误: - - - -解决方法: -这种是databinding比较大的坑,清理、重构和删build都不起作用,网上很难找到方法。经过试验,解决办法是手动创建异常中提到的文件夹,或者拷贝上一个没有报错的版本中对应的文件夹,可以解决这个异常 - -##### 4.1.4、自动生成类错误 -有时候在写完xml时,databinding没有自动生成对应的Binding类及属性。比如新建了一个activity_login.xml,按照databinding的写法加入``` ```后,理论上会自动对应生成ActivityLoginBinding.java类和variable的属性,可能是as对databding的支持还不够吧,有时候偏偏就不生成,导致BR.xxx报红等一些莫名的错误。 - -解决方法:其实确保自己的写法没有问题,是可以直接运行的,报红不一定是你写的有问题,也有可能是编译器抽风了。或者使用下面的办法
-第一招:Build->Clean Project;
第二招:Build->Rebuild Project;
第三招:重启大法。 ## 混淆 例子程序中给出了最新的【MVVMHabit混淆规则】,包含MVVMHabit中依赖的所有第三方library,可以将规则直接拷贝到自己app的混淆规则中。在此基础上你只需要关注自己业务代码以及自己引入第三方的混淆,【MVVMHabit混淆规则】请参考app目录下的[proguard-rules.pro](./app/proguard-rules.pro)文件。 @@ -775,11 +12,6 @@ ImageUtils.compressWithRx(filePaths, new Subscriber() { ## 组件化 进阶Android组件化方案,请移步:[MVVMHabitComponent](https://github.com/goldze/MVVMHabitComponent) -## About -**goldze:** 本人喜欢尝试新的技术,以后发现有好用的东西,我将会在企业项目中实战,没有问题了就会把它引入到**MVVMHabit**中,一直维护着这套框架,谢谢各位朋友的支持。如果觉得这套框架不错的话,麻烦点个 **star**,你的支持则是我前进的动力! - -**QQ群**:84692105 - ## License Copyright 2017 goldze(曾宪泽) From 1094819b1935c99c5f7be13d64b035fc349a246f Mon Sep 17 00:00:00 2001 From: zengxianze <603883033@qq.com> Date: Fri, 6 Dec 2019 09:06:50 +0800 Subject: [PATCH 04/11] supplement supplement --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 18ec2a1f..42449762 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ ## 最新日志 -#### AndroidX分支目前还处于过度阶段,如果你的项目需要AndroidX的支持,那么请使用本地依赖的方式导入项目Library。 +#### AndroidX分支目前还处于过度阶段,如果你的项目需要AndroidX的支持,那么请使用本地依赖的方式导入该分支的Library。 #### [更多日志](./UpdateLog.md) > **原文地址:** [https://github.com/goldze/MVVMHabit](https://github.com/goldze/MVVMHabit) From 7ca47b73eabdacf0a4820bcdeddf7aefc4abff62 Mon Sep 17 00:00:00 2001 From: zengxianze <603883033@qq.com> Date: Wed, 25 Mar 2020 11:26:35 +0800 Subject: [PATCH 05/11] supplement --- .../src/main/java/me/goldze/mvvmhabit/base/BaseActivity.java | 2 ++ .../src/main/java/me/goldze/mvvmhabit/base/BaseFragment.java | 2 ++ 2 files changed, 4 insertions(+) diff --git a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/base/BaseActivity.java b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/base/BaseActivity.java index 19bfb07c..2953b5d1 100644 --- a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/base/BaseActivity.java +++ b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/base/BaseActivity.java @@ -84,6 +84,8 @@ private void initViewDataBinding(Bundle savedInstanceState) { } //关联ViewModel binding.setVariable(viewModelId, viewModel); + //支持LiveData绑定xml,数据改变,UI自动会更新 + binding.setLifecycleOwner(this); //让ViewModel拥有View的生命周期感应 getLifecycle().addObserver(viewModel); //注入RxLifecycle生命周期 diff --git a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/base/BaseFragment.java b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/base/BaseFragment.java index cd245597..ee34f831 100644 --- a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/base/BaseFragment.java +++ b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/base/BaseFragment.java @@ -97,6 +97,8 @@ private void initViewDataBinding() { viewModel = (VM) createViewModel(this, modelClass); } binding.setVariable(viewModelId, viewModel); + //支持LiveData绑定xml,数据改变,UI自动会更新 + binding.setLifecycleOwner(this); //让ViewModel拥有View的生命周期感应 getLifecycle().addObserver(viewModel); //注入RxLifecycle生命周期 From 953a3b48f9382af42e319720936442be8a2cc3a8 Mon Sep 17 00:00:00 2001 From: zengxianze <603883033@qq.com> Date: Fri, 5 Jun 2020 13:46:35 +0800 Subject: [PATCH 06/11] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E6=8B=A6=E6=88=AA=E5=99=A8=E7=BC=BA=E9=99=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mvvmhabit/http/interceptor/logging/LoggingInterceptor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/http/interceptor/logging/LoggingInterceptor.java b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/http/interceptor/logging/LoggingInterceptor.java index 9ecbacd2..c9dbf0ce 100644 --- a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/http/interceptor/logging/LoggingInterceptor.java +++ b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/http/interceptor/logging/LoggingInterceptor.java @@ -74,7 +74,7 @@ public Response intercept(Chain chain) throws IOException { long st = System.nanoTime(); Response response = chain.proceed(request); - List segmentList = ((Request) request.tag()).url().encodedPathSegments(); + List segmentList = request.url().encodedPathSegments(); long chainMs = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - st); String header = response.headers().toString(); int code = response.code(); From 3ad2d132a6bc9a428d43c43540bdfda2b82543ad Mon Sep 17 00:00:00 2001 From: zengxianze <603883033@qq.com> Date: Fri, 5 Jun 2020 13:47:43 +0800 Subject: [PATCH 07/11] =?UTF-8?q?=E4=BC=98=E5=8C=96demo=E7=BD=91=E7=BB=9C?= =?UTF-8?q?=E8=AF=B7=E6=B1=82=E5=9B=9E=E8=B0=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mvvmhabit/ui/network/NetWorkViewModel.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/goldze/mvvmhabit/ui/network/NetWorkViewModel.java b/app/src/main/java/com/goldze/mvvmhabit/ui/network/NetWorkViewModel.java index 4d0652e8..99de1c95 100644 --- a/app/src/main/java/com/goldze/mvvmhabit/ui/network/NetWorkViewModel.java +++ b/app/src/main/java/com/goldze/mvvmhabit/ui/network/NetWorkViewModel.java @@ -13,6 +13,7 @@ import io.reactivex.disposables.Disposable; import io.reactivex.functions.Action; import io.reactivex.functions.Consumer; +import io.reactivex.observers.DisposableObserver; import me.goldze.mvvmhabit.base.BaseViewModel; import me.goldze.mvvmhabit.binding.command.BindingAction; import me.goldze.mvvmhabit.binding.command.BindingCommand; @@ -104,9 +105,9 @@ public void accept(Disposable disposable) throws Exception { showDialog("正在请求..."); } }) - .subscribe(new Consumer>() { + .subscribe(new DisposableObserver>() { @Override - public void accept(BaseResponse response) throws Exception { + public void onNext(BaseResponse response) { //清除列表 observableList.clear(); //请求成功 @@ -121,9 +122,9 @@ public void accept(BaseResponse response) throws Exception { ToastUtils.showShort("数据错误"); } } - }, new Consumer() { + @Override - public void accept(Throwable throwable) throws Exception { + public void onError(Throwable throwable) { //关闭对话框 dismissDialog(); //请求刷新完成收回 @@ -132,9 +133,9 @@ public void accept(Throwable throwable) throws Exception { ToastUtils.showShort(((ResponseThrowable) throwable).message); } } - }, new Action() { + @Override - public void run() throws Exception { + public void onComplete() { //关闭对话框 dismissDialog(); //请求刷新完成收回 From d5a834601920b2a6b0e5cffde024d12ec9de0b76 Mon Sep 17 00:00:00 2001 From: goldze <603883033@qq.com> Date: Fri, 16 Jul 2021 09:32:54 +0800 Subject: [PATCH 08/11] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=8D=87=E7=BA=A7?= =?UTF-8?q?=E6=AD=A3=E5=88=99=E6=A0=A1=E9=AA=8C=E5=B7=A5=E5=85=B7=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (cherry picked from commit 1dda4d2e2438c8eeeb79ab1a9b88d4c4d0b5cf70) --- .../me/goldze/mvvmhabit/utils/RegexUtils.java | 236 +++++++++++++----- 1 file changed, 173 insertions(+), 63 deletions(-) diff --git a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/utils/RegexUtils.java b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/utils/RegexUtils.java index 1da5ac6a..c6f0e3eb 100644 --- a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/utils/RegexUtils.java +++ b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/utils/RegexUtils.java @@ -1,6 +1,9 @@ package me.goldze.mvvmhabit.utils; +import android.support.v4.util.SimpleArrayMap; + import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -13,6 +16,8 @@ */ public final class RegexUtils { + private final static SimpleArrayMap CITY_MAP = new SimpleArrayMap<>(); + private RegexUtils() { throw new UnsupportedOperationException("u can't instantiate me..."); } @@ -22,136 +27,231 @@ private RegexUtils() { /////////////////////////////////////////////////////////////////////////// /** - * 验证手机号(简单) + * Return whether input matches regex of simple mobile. * - * @param input 待验证文本 - * @return {@code true}: 匹配
{@code false}: 不匹配 + * @param input The input. + * @return {@code true}: yes
{@code false}: no */ public static boolean isMobileSimple(final CharSequence input) { return isMatch(RegexConstants.REGEX_MOBILE_SIMPLE, input); } /** - * 验证手机号(精确) + * Return whether input matches regex of exact mobile. * - * @param input 待验证文本 - * @return {@code true}: 匹配
{@code false}: 不匹配 + * @param input The input. + * @return {@code true}: yes
{@code false}: no */ public static boolean isMobileExact(final CharSequence input) { - return isMatch(RegexConstants.REGEX_MOBILE_EXACT, input); + return isMobileExact(input, null); } /** - * 验证电话号码 + * Return whether input matches regex of exact mobile. * - * @param input 待验证文本 - * @return {@code true}: 匹配
{@code false}: 不匹配 + * @param input The input. + * @param newSegments The new segments of mobile number. + * @return {@code true}: yes
{@code false}: no + */ + public static boolean isMobileExact(final CharSequence input, List newSegments) { + boolean match = isMatch(RegexConstants.REGEX_MOBILE_EXACT, input); + if (match) return true; + if (newSegments == null) return false; + if (input == null || input.length() != 11) return false; + String content = input.toString(); + for (char c : content.toCharArray()) { + if (!Character.isDigit(c)) { + return false; + } + } + for (String newSegment : newSegments) { + if (content.startsWith(newSegment)) { + return true; + } + } + return false; + } + + /** + * Return whether input matches regex of telephone number. + * + * @param input The input. + * @return {@code true}: yes
{@code false}: no */ public static boolean isTel(final CharSequence input) { return isMatch(RegexConstants.REGEX_TEL, input); } /** - * 验证身份证号码15位 + * Return whether input matches regex of id card number which length is 15. * - * @param input 待验证文本 - * @return {@code true}: 匹配
{@code false}: 不匹配 + * @param input The input. + * @return {@code true}: yes
{@code false}: no */ public static boolean isIDCard15(final CharSequence input) { return isMatch(RegexConstants.REGEX_ID_CARD15, input); } /** - * 验证身份证号码18位 + * Return whether input matches regex of id card number which length is 18. * - * @param input 待验证文本 - * @return {@code true}: 匹配
{@code false}: 不匹配 + * @param input The input. + * @return {@code true}: yes
{@code false}: no */ public static boolean isIDCard18(final CharSequence input) { return isMatch(RegexConstants.REGEX_ID_CARD18, input); } /** - * 验证邮箱 + * Return whether input matches regex of exact id card number which length is 18. + * + * @param input The input. + * @return {@code true}: yes
{@code false}: no + */ + public static boolean isIDCard18Exact(final CharSequence input) { + if (isIDCard18(input)) { + int[] factor = new int[]{7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2}; + char[] suffix = new char[]{'1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'}; + if (CITY_MAP.isEmpty()) { + CITY_MAP.put("11", "北京"); + CITY_MAP.put("12", "天津"); + CITY_MAP.put("13", "河北"); + CITY_MAP.put("14", "山西"); + CITY_MAP.put("15", "内蒙古"); + + CITY_MAP.put("21", "辽宁"); + CITY_MAP.put("22", "吉林"); + CITY_MAP.put("23", "黑龙江"); + + CITY_MAP.put("31", "上海"); + CITY_MAP.put("32", "江苏"); + CITY_MAP.put("33", "浙江"); + CITY_MAP.put("34", "安徽"); + CITY_MAP.put("35", "福建"); + CITY_MAP.put("36", "江西"); + CITY_MAP.put("37", "山东"); + + CITY_MAP.put("41", "河南"); + CITY_MAP.put("42", "湖北"); + CITY_MAP.put("43", "湖南"); + CITY_MAP.put("44", "广东"); + CITY_MAP.put("45", "广西"); + CITY_MAP.put("46", "海南"); + + CITY_MAP.put("50", "重庆"); + CITY_MAP.put("51", "四川"); + CITY_MAP.put("52", "贵州"); + CITY_MAP.put("53", "云南"); + CITY_MAP.put("54", "西藏"); + + CITY_MAP.put("61", "陕西"); + CITY_MAP.put("62", "甘肃"); + CITY_MAP.put("63", "青海"); + CITY_MAP.put("64", "宁夏"); + CITY_MAP.put("65", "新疆"); + + CITY_MAP.put("71", "台湾老"); + CITY_MAP.put("81", "香港"); + CITY_MAP.put("82", "澳门"); + CITY_MAP.put("83", "台湾新"); + CITY_MAP.put("91", "国外"); + } + if (CITY_MAP.get(input.subSequence(0, 2).toString()) != null) { + int weightSum = 0; + for (int i = 0; i < 17; ++i) { + weightSum += (input.charAt(i) - '0') * factor[i]; + } + int idCardMod = weightSum % 11; + char idCardLast = input.charAt(17); + return idCardLast == suffix[idCardMod]; + } + } + return false; + } + + /** + * Return whether input matches regex of email. * - * @param input 待验证文本 - * @return {@code true}: 匹配
{@code false}: 不匹配 + * @param input The input. + * @return {@code true}: yes
{@code false}: no */ public static boolean isEmail(final CharSequence input) { return isMatch(RegexConstants.REGEX_EMAIL, input); } /** - * 验证URL + * Return whether input matches regex of url. * - * @param input 待验证文本 - * @return {@code true}: 匹配
{@code false}: 不匹配 + * @param input The input. + * @return {@code true}: yes
{@code false}: no */ public static boolean isURL(final CharSequence input) { return isMatch(RegexConstants.REGEX_URL, input); } /** - * 验证汉字 + * Return whether input matches regex of Chinese character. * - * @param input 待验证文本 - * @return {@code true}: 匹配
{@code false}: 不匹配 + * @param input The input. + * @return {@code true}: yes
{@code false}: no */ public static boolean isZh(final CharSequence input) { return isMatch(RegexConstants.REGEX_ZH, input); } /** - * 验证用户名 - *

取值范围为a-z,A-Z,0-9,"_",汉字,不能以"_"结尾,用户名必须是6-20位

+ * Return whether input matches regex of username. + *

scope for "a-z", "A-Z", "0-9", "_", "Chinese character"

+ *

can't end with "_"

+ *

length is between 6 to 20

. * - * @param input 待验证文本 - * @return {@code true}: 匹配
{@code false}: 不匹配 + * @param input The input. + * @return {@code true}: yes
{@code false}: no */ public static boolean isUsername(final CharSequence input) { return isMatch(RegexConstants.REGEX_USERNAME, input); } /** - * 验证yyyy-MM-dd格式的日期校验,已考虑平闰年 + * Return whether input matches regex of date which pattern is "yyyy-MM-dd". * - * @param input 待验证文本 - * @return {@code true}: 匹配
{@code false}: 不匹配 + * @param input The input. + * @return {@code true}: yes
{@code false}: no */ public static boolean isDate(final CharSequence input) { return isMatch(RegexConstants.REGEX_DATE, input); } /** - * 验证IP地址 + * Return whether input matches regex of ip address. * - * @param input 待验证文本 - * @return {@code true}: 匹配
{@code false}: 不匹配 + * @param input The input. + * @return {@code true}: yes
{@code false}: no */ public static boolean isIP(final CharSequence input) { return isMatch(RegexConstants.REGEX_IP, input); } /** - * 判断是否匹配正则 + * Return whether input matches the regex. * - * @param regex 正则表达式 - * @param input 要匹配的字符串 - * @return {@code true}: 匹配
{@code false}: 不匹配 + * @param regex The regex. + * @param input The input. + * @return {@code true}: yes
{@code false}: no */ public static boolean isMatch(final String regex, final CharSequence input) { return input != null && input.length() > 0 && Pattern.matches(regex, input); } /** - * 获取正则匹配的部分 + * Return the list of input matches the regex. * - * @param regex 正则表达式 - * @param input 要匹配的字符串 - * @return 正则匹配的部分 + * @param regex The regex. + * @param input The input. + * @return the list of input matches the regex */ public static List getMatches(final String regex, final CharSequence input) { - if (input == null) return null; + if (input == null) return Collections.emptyList(); List matches = new ArrayList<>(); Pattern pattern = Pattern.compile(regex); Matcher matcher = pattern.matcher(input); @@ -162,40 +262,50 @@ public static List getMatches(final String regex, final CharSequence inp } /** - * 获取正则匹配分组 + * Splits input around matches of the regex. * - * @param input 要分组的字符串 - * @param regex 正则表达式 - * @return 正则匹配分组 + * @param input The input. + * @param regex The regex. + * @return the array of strings computed by splitting input around matches of regex */ public static String[] getSplits(final String input, final String regex) { - if (input == null) return null; + if (input == null) return new String[0]; return input.split(regex); } /** - * 替换正则匹配的第一部分 + * Replace the first subsequence of the input sequence that matches the + * regex with the given replacement string. * - * @param input 要替换的字符串 - * @param regex 正则表达式 - * @param replacement 代替者 - * @return 替换正则匹配的第一部分 + * @param input The input. + * @param regex The regex. + * @param replacement The replacement string. + * @return the string constructed by replacing the first matching + * subsequence by the replacement string, substituting captured + * subsequences as needed */ - public static String getReplaceFirst(final String input, final String regex, final String replacement) { - if (input == null) return null; + public static String getReplaceFirst(final String input, + final String regex, + final String replacement) { + if (input == null) return ""; return Pattern.compile(regex).matcher(input).replaceFirst(replacement); } /** - * 替换所有正则匹配的部分 + * Replace every subsequence of the input sequence that matches the + * pattern with the given replacement string. * - * @param input 要替换的字符串 - * @param regex 正则表达式 - * @param replacement 代替者 - * @return 替换所有正则匹配的部分 + * @param input The input. + * @param regex The regex. + * @param replacement The replacement string. + * @return the string constructed by replacing each matching subsequence + * by the replacement string, substituting captured subsequences + * as needed */ - public static String getReplaceAll(final String input, final String regex, final String replacement) { - if (input == null) return null; + public static String getReplaceAll(final String input, + final String regex, + final String replacement) { + if (input == null) return ""; return Pattern.compile(regex).matcher(input).replaceAll(replacement); } } From f90e665ca5dfe58b60a7002440e2dbb42c8259b8 Mon Sep 17 00:00:00 2001 From: goldze <603883033@qq.com> Date: Fri, 16 Jul 2021 10:12:33 +0800 Subject: [PATCH 09/11] =?UTF-8?q?=E5=8D=87=E7=BA=A7gradle=E8=87=B33.5.2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 2 +- gradle/wrapper/gradle-wrapper.properties | 2 +- .../src/main/java/me/goldze/mvvmhabit/utils/RegexUtils.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index e814da57..848cec1b 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.3.2' + classpath 'com.android.tools.build:gradle:3.5.2' // classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3' // classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5' // classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3' diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 6af21361..82c55c84 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip diff --git a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/utils/RegexUtils.java b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/utils/RegexUtils.java index c6f0e3eb..2fdc4f02 100644 --- a/mvvmhabit/src/main/java/me/goldze/mvvmhabit/utils/RegexUtils.java +++ b/mvvmhabit/src/main/java/me/goldze/mvvmhabit/utils/RegexUtils.java @@ -1,6 +1,5 @@ package me.goldze.mvvmhabit.utils; -import android.support.v4.util.SimpleArrayMap; import java.util.ArrayList; import java.util.Collections; @@ -8,6 +7,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; +import androidx.collection.SimpleArrayMap; import me.goldze.mvvmhabit.utils.constant.RegexConstants; /** From da06fdc730edeef98fd6c5a6e05d6eac479e47c3 Mon Sep 17 00:00:00 2001 From: goldze <603883033@qq.com> Date: Fri, 16 Jul 2021 10:13:18 +0800 Subject: [PATCH 10/11] =?UTF-8?q?=E5=8D=87=E7=BA=A7bindingcollectionadapte?= =?UTF-8?q?r=EF=BC=8C=E4=BC=98=E5=8C=96demo=E7=BB=91=E5=AE=9A=E6=96=B9?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/goldze/mvvmhabit/ui/network/NetWorkFragment.java | 3 --- .../mvvmhabit/ui/rv_multi/MultiRecycleViewFragment.java | 3 --- app/src/main/res/layout/fragment_multi_rv.xml | 7 ------- app/src/main/res/layout/fragment_network.xml | 7 ------- config.gradle | 5 +++-- mvvmhabit/build.gradle | 3 +++ 6 files changed, 6 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/com/goldze/mvvmhabit/ui/network/NetWorkFragment.java b/app/src/main/java/com/goldze/mvvmhabit/ui/network/NetWorkFragment.java index 40c7327c..28cad3f6 100644 --- a/app/src/main/java/com/goldze/mvvmhabit/ui/network/NetWorkFragment.java +++ b/app/src/main/java/com/goldze/mvvmhabit/ui/network/NetWorkFragment.java @@ -52,9 +52,6 @@ public NetWorkViewModel initViewModel() { @Override public void initData() { - //给RecyclerView添加Adpter,请使用自定义的Adapter继承BindingRecyclerViewAdapter,重写onBindBinding方法,里面有你要的Item对应的binding对象。 - // Adapter属于View层的东西, 不建议定义到ViewModel中绑定,以免内存泄漏 - binding.setAdapter(new BindingRecyclerViewAdapter()); //请求网络数据 viewModel.requestNetWork(); } diff --git a/app/src/main/java/com/goldze/mvvmhabit/ui/rv_multi/MultiRecycleViewFragment.java b/app/src/main/java/com/goldze/mvvmhabit/ui/rv_multi/MultiRecycleViewFragment.java index 670d8c1c..87955e6f 100644 --- a/app/src/main/java/com/goldze/mvvmhabit/ui/rv_multi/MultiRecycleViewFragment.java +++ b/app/src/main/java/com/goldze/mvvmhabit/ui/rv_multi/MultiRecycleViewFragment.java @@ -32,8 +32,5 @@ public int initVariableId() { @Override public void initData() { super.initData(); - //给RecyclerView添加Adpter,请使用自定义的Adapter继承BindingRecyclerViewAdapter,重写onBindBinding方法,里面有你要的Item对应的binding对象。 - // Adapter属于View层的东西, 不建议定义到ViewModel中绑定,以免内存泄漏 - binding.setAdapter(new BindingRecyclerViewAdapter()); } } diff --git a/app/src/main/res/layout/fragment_multi_rv.xml b/app/src/main/res/layout/fragment_multi_rv.xml index 449390c7..87ae300b 100644 --- a/app/src/main/res/layout/fragment_multi_rv.xml +++ b/app/src/main/res/layout/fragment_multi_rv.xml @@ -5,16 +5,10 @@ - - - - @@ -29,7 +23,6 @@ - - - - @@ -38,7 +32,6 @@ Date: Fri, 16 Jul 2021 11:12:25 +0800 Subject: [PATCH 11/11] =?UTF-8?q?=E5=8D=87=E7=BA=A7=E7=AC=AC=E4=B8=89?= =?UTF-8?q?=E6=96=B9=E6=A1=86=E6=9E=B6=E4=BE=9D=E8=B5=96=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.gradle | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/config.gradle b/config.gradle index 3b1030ed..d6aa1f9b 100644 --- a/config.gradle +++ b/config.gradle @@ -43,13 +43,13 @@ ext { "converter-gson" : "com.squareup.retrofit2:converter-gson:2.4.0", "adapter-rxjava" : "com.squareup.retrofit2:adapter-rxjava2:2.4.0", //glide图片加载 - "glide" : "com.github.bumptech.glide:glide:4.8.0", - "glide-compiler" : "com.github.bumptech.glide:compiler:4.8.0", + "glide" : "com.github.bumptech.glide:glide:4.11.0", + "glide-compiler" : "com.github.bumptech.glide:compiler:4.11.0", //json解析 - "gson" : "com.google.code.gson:gson:2.8.5", + "gson" : "com.google.code.gson:gson:2.8.6", //material-dialogs - "material-dialogs-core" : "com.afollestad.material-dialogs:core:0.9.4.5", - "material-dialogs-commons" : "com.afollestad.material-dialogs:commons:0.9.4.5", + "material-dialogs-core" : "com.afollestad.material-dialogs:core:0.9.6.0", + "material-dialogs-commons" : "com.afollestad.material-dialogs:commons:0.9.6.0", //recyclerview的databinding套装 "bindingcollectionadapter" : "me.tatarka.bindingcollectionadapter2:bindingcollectionadapter:4.0.0", "bindingcollectionadapter-recyclerview": "me.tatarka.bindingcollectionadapter2:bindingcollectionadapter-recyclerview:4.0.0",