Skip to content

Commit

Permalink
fix 主页bottombar长按时出现toast问题
Browse files Browse the repository at this point in the history
  • Loading branch information
hegaojian committed Oct 12, 2020
1 parent ba4abf2 commit b8b614b
Show file tree
Hide file tree
Showing 51 changed files with 827 additions and 3,237 deletions.
21 changes: 11 additions & 10 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ android {
applicationId "me.hgj.jetpackmvvm.demo"
minSdkVersion 21
targetSdkVersion 29
versionCode 18
versionName "1.1.8"
versionCode 19
versionName "1.1.9"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
/* ndk {
// 设置支持的SO库架构 一般只设置这个就阔以设配所有的设备了,还可以减少apk的大小
Expand Down Expand Up @@ -69,17 +69,17 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.1'
implementation 'androidx.core:core-ktx:1.3.2'
//test
testImplementation 'junit:junit:4.13'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation 'com.android.support:multidex:1.0.3'
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.4'
//androidx UI
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.material:material:1.3.0-alpha02'
implementation 'androidx.constraintlayout:constraintlayout:2.0.2'
implementation 'com.google.android.material:material:1.3.0-alpha03'
implementation 'androidx.cardview:cardview:1.0.0'
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0"
implementation 'androidx.preference:preference:1.1.1'
Expand All @@ -98,16 +98,16 @@ dependencies {
//微信开源项目,替代SP
implementation 'com.tencent:mmkv:1.0.22'
//项目核心框架
implementation project(path: ':JetpackMvvm')
// implementation 'me.hegj:JetpackMvvm:1.1.8'
// implementation project(path: ':JetpackMvvm')
implementation 'me.hegj:JetpackMvvm:1.1.9'
//轮播图
implementation 'com.github.zhpanvip:BannerViewPager:3.1.5'
//BaseAdapter
implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:3.0.4'
//第三方recyclerview
implementation 'com.yanzhenjie.recyclerview:x:1.3.2'
//管理界面状态库
implementation 'com.kingja.loadsir:loadsir:1.3.6'
implementation 'com.kingja.loadsir:loadsir:1.3.8'
//指示器库
implementation 'com.github.hackware1993:MagicIndicator:1.6.0'
//官方的
Expand All @@ -129,5 +129,6 @@ dependencies {
implementation("com.liulishuo.filedownloader:library:1.7.7") {
exclude group: "com.android.support"
}
implementation 'com.louiscad.splitties:splitties-collections:2.1.1'

}
3,617 changes: 531 additions & 3,086 deletions app/priguardMapping.txt

Large diffs are not rendered by default.

Binary file modified app/release/app-release.apk
Binary file not shown.
2 changes: 1 addition & 1 deletion app/release/output.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":16,"versionName":"1.1.6","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release","dirName":""},"path":"app-release.apk","properties":{}}]
[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":18,"versionName":"1.1.8","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release","dirName":""},"path":"app-release.apk","properties":{}}]
4 changes: 4 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
android:label="错误界面"
android:launchMode="singleTask"
android:screenOrientation="portrait" />
<activity
android:name=".ui.activity.TestActivity"
android:launchMode="singleTask"
android:screenOrientation="portrait" />
<activity
android:name="com.tencent.bugly.beta.ui.BetaActivity"
android:configChanges="keyboardHidden|orientation|screenSize|locale"
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/java/me/hgj/jetpackmvvm/demo/app/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class App : BaseApp() {
strategy.isUploadProcess = processName == null || processName == packageName
// 初始化Bugly
Bugly.init(context, if (BuildConfig.DEBUG) "xxx" else "a52f2b5ebb", BuildConfig.DEBUG)

jetpackMvvmLog = BuildConfig.DEBUG

//防止项目崩溃,崩溃后打开错误界面
Expand All @@ -66,7 +66,6 @@ class App : BaseApp() {
.minTimeBetweenCrashesMs(2000) //应用程序崩溃之间必须经过的时间 default: 3000
.restartActivity(WelcomeActivity::class.java) // 重启的activity
.errorActivity(ErrorActivity::class.java) //发生错误跳转的activity
.eventListener(null) //允许你指定事件侦听器,以便在库显示错误活动 default: null
.apply()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,13 @@ package me.hgj.jetpackmvvm.demo.app.base

import android.content.res.Resources
import android.os.Bundle
import android.view.View
import android.widget.ProgressBar
import android.widget.TextView
import androidx.databinding.ViewDataBinding
import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.customview.customView
import com.afollestad.materialdialogs.customview.getCustomView
import com.afollestad.materialdialogs.lifecycle.lifecycleOwner
import me.hgj.jetpackmvvm.base.viewmodel.BaseViewModel
import me.hgj.jetpackmvvm.base.activity.BaseVmDbActivity
import me.hgj.jetpackmvvm.demo.R
import me.hgj.jetpackmvvm.base.viewmodel.BaseViewModel
import me.hgj.jetpackmvvm.demo.app.event.AppViewModel
import me.hgj.jetpackmvvm.demo.app.event.EventViewModel
import me.hgj.jetpackmvvm.demo.app.ext.dismissLoadingExt
import me.hgj.jetpackmvvm.demo.app.ext.showLoadingExt
import me.hgj.jetpackmvvm.demo.app.util.SettingUtil
import me.hgj.jetpackmvvm.ext.getAppViewModel
import me.jessyan.autosize.AutoSizeCompat

Expand Down
29 changes: 29 additions & 0 deletions app/src/main/java/me/hgj/jetpackmvvm/demo/app/ext/AppExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,32 @@ fun NavController.jumpByLogin(
}


fun List<*>?.isNull(): Boolean {
return this?.isEmpty() ?: true
}

fun List<*>?.isNotNull(): Boolean {
return this != null && this.isNotEmpty()
}

/**
* 根据索引获取集合的child值
* @receiver List<T>?
* @param position Int
* @return T?
*/
inline fun <reified T> List<T>?.getChild(position: Int): T? {
//如果List为null 返回null
return if (this == null) {
null
} else {
//如果position大于集合的size 返回null
if (position + 1 > this.size) {
null
} else {
//返回正常数据
this[position]
}
}
}

28 changes: 20 additions & 8 deletions app/src/main/java/me/hgj/jetpackmvvm/demo/app/ext/CustomViewExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.app.Activity
import android.content.Context
import android.graphics.Color
import android.view.View
import android.view.ViewGroup
import android.view.animation.AccelerateInterpolator
import android.view.animation.DecelerateInterpolator
import android.view.inputmethod.InputMethodManager
Expand All @@ -17,7 +18,6 @@ import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import androidx.viewpager.widget.ViewPager
import androidx.viewpager2.adapter.FragmentStateAdapter
import androidx.viewpager2.widget.ViewPager2
import com.chad.library.adapter.base.BaseQuickAdapter
Expand All @@ -26,10 +26,8 @@ import com.ittianyu.bottomnavigationviewex.BottomNavigationViewEx
import com.kingja.loadsir.core.LoadService
import com.kingja.loadsir.core.LoadSir
import com.yanzhenjie.recyclerview.SwipeRecyclerView
import com.zhpan.bannerview.BannerViewPager
import me.hgj.jetpackmvvm.base.Ktx
import me.hgj.jetpackmvvm.demo.R
import me.hgj.jetpackmvvm.base.appContext
import me.hgj.jetpackmvvm.demo.R
import me.hgj.jetpackmvvm.demo.app.network.stateCallback.ListDataUiState
import me.hgj.jetpackmvvm.demo.app.util.SettingUtil
import me.hgj.jetpackmvvm.demo.app.weight.loadCallBack.EmptyCallback
Expand Down Expand Up @@ -246,8 +244,7 @@ fun MagicIndicator.bindViewPager2(
viewPager: ViewPager2,
mDataList: ArrayList<ClassifyResponse> = arrayListOf(),
mStringList: ArrayList<String> = arrayListOf(),
action: (index: Int) -> Unit = {}
) {
action: (index: Int) -> Unit = {}) {
val commonNavigator = CommonNavigator(appContext)
commonNavigator.adapter = object : CommonNavigatorAdapter() {
override fun getCount(): Int {
Expand All @@ -257,7 +254,6 @@ fun MagicIndicator.bindViewPager2(
mStringList.size
}
}

override fun getTitleView(context: Context, index: Int): IPagerTitleView {
return ScaleTransitionPagerTitleView(appContext).apply {
text = if (mDataList.size != 0) {
Expand All @@ -274,7 +270,6 @@ fun MagicIndicator.bindViewPager2(
}
}
}

override fun getIndicator(context: Context): IPagerIndicator {
return LinePagerIndicator(context).apply {
mode = LinePagerIndicator.MODE_EXACTLY
Expand Down Expand Up @@ -377,6 +372,21 @@ fun BottomNavigationViewEx.init(navigationItemSelectedAction: (Int) -> Unit): Bo
return this
}


/**
* 拦截BottomNavigation长按事件 防止长按时出现Toast ---- 追求完美的大屌群友提的bug
* @receiver BottomNavigationViewEx
* @param ids IntArray
*/
fun BottomNavigationViewEx.interceptLongClick(vararg ids:Int) {
val bottomNavigationMenuView: ViewGroup = (this.getChildAt(0) as ViewGroup)
for (index in ids.indices){
bottomNavigationMenuView.getChildAt(index).findViewById<View>(ids[index]).setOnLongClickListener {
true
}
}
}

/**
* 隐藏软键盘
*/
Expand Down Expand Up @@ -405,7 +415,9 @@ fun <T> loadListData(
swipeRefreshLayout: SwipeRefreshLayout
) {
swipeRefreshLayout.isRefreshing = false

recyclerView.loadMoreFinish(data.isEmpty, data.hasMore)

if (data.isSuccess) {
//成功
when {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import java.util.concurrent.TimeUnit
val apiService: ApiService by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) {
NetworkApi.INSTANCE.getApi(ApiService::class.java, ApiService.SERVER_URL)
}

//测试的
val apiService1: ApiService by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) {
NetworkApi.INSTANCE.getApi(ApiService::class.java, ApiService.SERVER_URL1)
}
Expand All @@ -47,7 +47,6 @@ class NetworkApi : BaseNetworkApi() {
* 在这里可以添加拦截器,可以对 OkHttpClient.Builder 做任意操作
*/
override fun setHttpClientBuilder(builder: OkHttpClient.Builder): OkHttpClient.Builder {
"setHttpClientBuilder".logi("hgj")
builder.apply {
//设置缓存配置 缓存最大10M
cache(Cache(File(appContext.cacheDir, "cxk_cache"), 10 * 1024 * 1024))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ import android.widget.ImageView
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
import com.zhpan.bannerview.BaseViewHolder
import me.hgj.jetpackmvvm.base.appContext
import me.hgj.jetpackmvvm.demo.R
import me.hgj.jetpackmvvm.demo.data.model.bean.BannerResponse

class HomeBannerViewHolder(view: View) : BaseViewHolder<BannerResponse>(view) {
override fun bindData(data: BannerResponse?, position: Int, pageSize: Int) {
val img = itemView.findViewById<ImageView>(R.id.bannerhome_img)
data?.let {
Glide.with(img.context.applicationContext)
Glide.with(appContext)
.load(it.imagePath)
.transition(DrawableTransitionOptions.withCrossFade(500))
.into(img)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,19 @@ data class ApiPagerResponse<T>(
var pageCount: Int,
var size: Int,
var total: Int
) :Serializable{
) : Serializable {
/**
* 数据是否为空
*/
fun isEmpty(): Boolean {
fun isEmpty() = (datas as List<*>).size == 0

return (datas as List<*>).size==0
}
/**
* 是否为刷新
*/
fun isRefresh(): Boolean {
//wanandroid 第一页该字段都为0
return offset==0
}
fun isRefresh() = offset == 0

/**
* 是否还有更多数据
*/
fun hasMore(): Boolean {
return !over
}
fun hasMore() = !over
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package me.hgj.jetpackmvvm.demo.ui.activity

import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.view.WindowManager
import android.widget.Toast
import androidx.activity.OnBackPressedCallback
import androidx.lifecycle.Observer
Expand All @@ -26,6 +27,7 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
override fun initView(savedInstanceState: Bundle?) {
//进入首页检查更新
Beta.checkUpgrade(false, true)

onBackPressedDispatcher.addCallback(this, object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
val nav = Navigation.findNavController(this@MainActivity, R.id.host_fragment)
Expand All @@ -42,8 +44,10 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
}
}
}
})
appViewModel.appColor.value?.let { supportActionBar?.setBackgroundDrawable(ColorDrawable(it))
})
appViewModel.appColor.value?.let {
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN)
supportActionBar?.setBackgroundDrawable(ColorDrawable(it))
StatusBarUtil.setColor(this, it, 0) }
}

Expand All @@ -65,4 +69,5 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
Toast.makeText(applicationContext, "我特么怎么断网了!", Toast.LENGTH_SHORT).show()
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package me.hgj.jetpackmvvm.demo.ui.activity

import android.os.Bundle
import androidx.activity.viewModels
import androidx.lifecycle.Observer
import kotlinx.android.synthetic.main.activity_test.*
import me.hgj.jetpackmvvm.base.viewmodel.BaseViewModel
import me.hgj.jetpackmvvm.demo.R
import me.hgj.jetpackmvvm.demo.app.base.BaseActivity
import me.hgj.jetpackmvvm.demo.app.ext.showMessage
import me.hgj.jetpackmvvm.demo.databinding.ActivityTestBinding
import me.hgj.jetpackmvvm.demo.ui.adapter.TestAdapter
import me.hgj.jetpackmvvm.demo.viewmodel.request.RequestLoginRegisterViewModel
import me.hgj.jetpackmvvm.ext.parseState
import me.hgj.jetpackmvvm.ext.util.logd

/**
* @author : hgj
* @date : 2020/8/26
*/

class TestActivity : BaseActivity<BaseViewModel, ActivityTestBinding>() {

val viewModel: RequestLoginRegisterViewModel by viewModels()

val adapter: TestAdapter by lazy { TestAdapter(arrayListOf()) }

override fun layoutId() = R.layout.activity_test


override fun initView(savedInstanceState: Bundle?) {

//强烈注意:使用addLoadingObserve 将非绑定当前activity的viewmodel绑定loading回调 防止出现请求时不显示 loading 弹窗bug
addLoadingObserve(viewModel)

adapter.run {
clickAction = { position, item, state ->
"海王收到了点击事件,并准备发一个红包".logd()
}
}
button.setOnClickListener {
viewModel.loginReq("123", "123456")
}
}

override fun createObserver() {
//测试在activity中 loading弹窗是否正确
viewModel.loginResult.observe(this, Observer {
parseState(it, {
showMessage(it.nickname)
}, {
showMessage(it.errorMsg)
})
})
}
}

Loading

0 comments on commit b8b614b

Please sign in to comment.