Skip to content

Commit

Permalink
1.增加了腾讯 Bugly;
Browse files Browse the repository at this point in the history
2.LeakCanary 检测内存泄漏工具;
3.打开 APP 时增加统一权限处理。
  • Loading branch information
git-xuhao committed Dec 8, 2017
1 parent 8aad113 commit 98d17d2
Show file tree
Hide file tree
Showing 29 changed files with 319 additions and 128 deletions.
14 changes: 14 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ android {
}
}
signingConfig signingConfigs.config
// 实现毛玻璃那种透明的效果需要添加的库
renderscriptTargetApi 19
renderscriptSupportModeEnabled true // Enable RS support
}
buildTypes {
debug {
Expand Down Expand Up @@ -68,6 +71,7 @@ dependencies {
implementation rootProject.ext.otherLibs
// APT dependencies(Kotlin内置的注解处理器)
kapt rootProject.ext.annotationProcessorLibs

implementation 'com.android.support.constraint:constraint-layout:1.0.2'
// 底部菜单
implementation('com.flyco.tablayout:FlycoTabLayout_Lib:2.1.0@aar') {
Expand All @@ -91,4 +95,14 @@ dependencies {
//Google开源的一个布局控件
implementation 'com.google.android:flexbox:0.3.1'
implementation project(':multiple-status-view')
//模糊透明 View
implementation 'com.github.mmin18:realtimeblurview:1.1.0'
//leakCanary
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.5.4'
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.4'
//腾讯 bugly
compile 'com.tencent.bugly:crashreport:2.6.6.1'
//运行时权限
compile 'me.weyye.hipermission:library:1.0.7'

}
6 changes: 6 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<!-- 访问网络 -->
<uses-permission android:name="android.permission.INTERNET" />
<!-- 读取手机状态 -->
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.READ_LOGS" />
<!-- SD 卡读写权限 -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

<application
android:name=".MyApplication"
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/java/com/hazz/kotlinmvp/Constants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,8 @@ class Constants private constructor(){

val BUNDLE_VIDEO_DATA = "video_data"
val BUNDLE_CATEGORY_DATA = "category_data"

//腾讯 Bugly APP id
val BUGLY_APPID="176aad0d9e"
}
}
50 changes: 21 additions & 29 deletions app/src/main/java/com/hazz/kotlinmvp/MyApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,14 @@ import android.util.Log
import com.hazz.kotlinmvp.utils.DisplayManager
import com.orhanobut.logger.AndroidLogAdapter
import com.orhanobut.logger.Logger
import kotlin.properties.Delegates
import com.scwang.smartrefresh.layout.constant.SpinnerStyle
import com.scwang.smartrefresh.layout.footer.ClassicsFooter
import com.scwang.smartrefresh.layout.api.RefreshLayout
import com.scwang.smartrefresh.layout.api.RefreshFooter
import com.scwang.smartrefresh.layout.api.DefaultRefreshFooterCreater
import com.scwang.smartrefresh.layout.SmartRefreshLayout
import com.scwang.smartrefresh.layout.header.ClassicsHeader
import com.scwang.smartrefresh.layout.api.RefreshHeader
import com.scwang.smartrefresh.layout.api.DefaultRefreshHeaderCreater
import com.orhanobut.logger.PrettyFormatStrategy
import com.orhanobut.logger.FormatStrategy
import com.scwang.smartrefresh.header.MaterialHeader
import com.scwang.smartrefresh.layout.SmartRefreshLayout
import com.squareup.leakcanary.LeakCanary
import com.squareup.leakcanary.RefWatcher
import com.tencent.bugly.crashreport.CrashReport
import kotlinx.android.synthetic.main.fragment_home.*
import kotlin.properties.Delegates


/**
Expand All @@ -29,7 +24,7 @@ import com.scwang.smartrefresh.header.MaterialHeader

class MyApplication : Application(){


private var refWatcher: RefWatcher? = null

companion object {

Expand All @@ -39,35 +34,31 @@ class MyApplication : Application(){
var context: Context by Delegates.notNull()
private set


}
init {
//static 代码段可以防止内存泄露 (全局的下拉刷新,上拉加载样式)
//设置全局的Header构建器
SmartRefreshLayout.setDefaultRefreshHeaderCreater { context, layout ->
layout?.setPrimaryColorsId(R.color.colorPrimary, android.R.color.white) //全局设置主题颜色
MaterialHeader(context)
fun getRefWatcher(context: Context): RefWatcher? {
val myApplication = context.applicationContext as MyApplication
return myApplication.refWatcher
}
//设置全局的Footer构建器
// SmartRefreshLayout.setDefaultRefreshFooterCreater { context, _ ->
// //指定为经典Footer,默认是 BallPulseFooter
// ClassicsFooter(context).setSpinnerStyle(SpinnerStyle.Scale)
// }
}


}

override fun onCreate() {
super.onCreate()

context = applicationContext
refWatcher = setupLeakCanary()
initConfig()
DisplayManager.init(this)
registerActivityLifecycleCallbacks(mActivityLifecycleCallbacks)


}

private fun setupLeakCanary(): RefWatcher {
return if (LeakCanary.isInAnalyzerProcess(this)) {
RefWatcher.DISABLED
} else LeakCanary.install(this)
}


/**
* 初始化配置
*/
Expand All @@ -84,7 +75,8 @@ class MyApplication : Application(){
return BuildConfig.DEBUG
}
})

//测试阶段建议设置成true,发布时设置为false。
CrashReport.initCrashReport(applicationContext, Constants.BUGLY_APPID, false)
}


Expand Down
5 changes: 4 additions & 1 deletion app/src/main/java/com/hazz/kotlinmvp/api/api
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@

//热门搜索词
http://baobab.kaiyanapp.com/api/v3/queries/hot
["阅后即瞎","日食记","复仇者联盟","励志","谷阿莫","复仇者联盟3","美食","广告","爱情","舞蹈","搞笑","漫威","动画","日本","电影相关","健身","VR","滑板","脱口秀","寻梦环游记"]
["阅后即瞎","日食记","复仇者联盟","励志","谷阿莫","复仇者联盟3","美食","广告","爱情","舞蹈","搞笑","漫威","动画","日本","电影相关","健身","VR","滑板","脱口秀","寻梦环游记"]

作者信息
http://baobab.kaiyanapp.com/api/v4/pgcs/detail/tab?id=571
14 changes: 13 additions & 1 deletion app/src/main/java/com/hazz/kotlinmvp/base/BaseActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import android.view.View
import android.view.inputmethod.InputMethodManager
import android.widget.EditText
import com.classic.common.MultipleStatusView
import com.hazz.kotlinmvp.MyApplication
import com.hazz.kotlinmvp.showToast


Expand All @@ -27,9 +28,15 @@ abstract class BaseActivity : AppCompatActivity() {
initData()
initView()
start()
mLayoutStatusView?.setOnClickListener(mRetryClickListener)
initListener()


}

private fun initListener() {
mLayoutStatusView?.setOnClickListener(mRetryClickListener)
}

open val mRetryClickListener: View.OnClickListener = View.OnClickListener {
start()
}
Expand Down Expand Up @@ -74,6 +81,11 @@ abstract class BaseActivity : AppCompatActivity() {
}


override fun onDestroy() {
super.onDestroy()
MyApplication.getRefWatcher(this)?.watch(this)
}

}


6 changes: 6 additions & 0 deletions app/src/main/java/com/hazz/kotlinmvp/base/BaseFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.classic.common.MultipleStatusView
import com.hazz.kotlinmvp.MyApplication
import com.hazz.kotlinmvp.showToast

/**
Expand Down Expand Up @@ -79,4 +80,9 @@ import com.hazz.kotlinmvp.showToast
* 懒加载
*/
abstract fun lazyLoad()

override fun onDestroy() {
super.onDestroy()
MyApplication.getRefWatcher(activity)?.watch(activity)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.hazz.kotlinmvp.dataFormat
import com.hazz.kotlinmvp.mvp.contract.VideoDetailContract
import com.hazz.kotlinmvp.mvp.model.VideoDetailModel
import com.hazz.kotlinmvp.mvp.model.bean.HomeBean
import com.hazz.kotlinmvp.net.exception.ExceptionHandle
import com.hazz.kotlinmvp.showToast
import com.hazz.kotlinmvp.utils.DisplayManager
import com.hazz.kotlinmvp.utils.NetworkUtil
Expand Down Expand Up @@ -73,13 +74,18 @@ class VideoDetailPresenter : BasePresenter<VideoDetailContract.View>(), VideoDet
* 请求相关的视频数据
*/
override fun requestRelatedVideo(id: Long) {

mRootView?.showLoading()
val disposable = videoDetailModel.requestRelatedData(id)
.subscribe({ issue ->
mRootView?.setRecentRelatedVideo(issue.itemList)
mRootView?.apply {
dismissLoading()
setRecentRelatedVideo(issue.itemList)
}
}, { t ->
mRootView?.setErrorMsg(t.toString())

mRootView?.apply {
dismissLoading()
setErrorMsg(ExceptionHandle.handleException(t))
}
})

addSubscription(disposable)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package com.hazz.kotlinmvp.ui.activity

import android.annotation.SuppressLint
import android.content.Intent
import android.net.Uri
import com.hazz.kotlinmvp.MyApplication
import com.hazz.kotlinmvp.R
import com.hazz.kotlinmvp.base.BaseActivity
import com.hazz.kotlinmvp.utils.AppUtils
import com.hazz.kotlinmvp.utils.StatusBarUtil
import kotlinx.android.synthetic.main.activity_about.*

Expand All @@ -17,9 +20,12 @@ class AboutActivity : BaseActivity() {
override fun initData() {
}

@SuppressLint("SetTextI18n")
override fun initView() {
StatusBarUtil.darkMode(this)
StatusBarUtil.setPaddingSmart(this, toolbar)

tv_version_name.text ="v${AppUtils.getVerName(MyApplication.context)}"
//返回
toolbar.setNavigationOnClickListener { finish() }
//访问 GitHub
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ class ProfileHomePageActivity : BaseActivity() {
private val h = DensityUtil.dp2px(170f)
private val color = ContextCompat.getColor(applicationContext, R.color.colorPrimary) and 0x00ffffff
override fun onScrollChange(v: NestedScrollView, scrollX: Int, scrollY: Int, oldScrollX: Int, oldScrollY: Int) {
var scrollY = scrollY
var tScrollY= scrollY
if (lastScrollY < h) {
scrollY = Math.min(h, scrollY)
mScrollY = if (scrollY > h) h else scrollY
tScrollY = Math.min(h, tScrollY)
mScrollY = if (tScrollY > h) h else tScrollY
buttonBarLayout.alpha = 1f * mScrollY / h
toolbar.setBackgroundColor(255 * mScrollY / h shl 24 or color)
parallax.translationY = (mOffset - mScrollY).toFloat()
}
lastScrollY = scrollY
lastScrollY = tScrollY
}
})
buttonBarLayout.alpha = 0f
Expand All @@ -73,22 +73,22 @@ class ProfileHomePageActivity : BaseActivity() {
toolbar.setNavigationOnClickListener { finish() }


refreshLayout.setOnRefreshListener { mWebView.loadUrl("http://xuhaoblog.com") }
refreshLayout.autoRefresh()

mWebView.settings.javaScriptEnabled = true
mWebView.webViewClient = object : WebViewClient() {
override fun shouldOverrideUrlLoading(view: WebView, url: String): Boolean {
view.loadUrl(url)
return true
}

override fun onPageFinished(view: WebView, url: String) {
super.onPageFinished(view, url)
refreshLayout.finishRefresh()
view.loadUrl(String.format(Locale.CHINA, "javascript:document.body.style.paddingTop='%fpx'; void 0", DensityUtil.px2dp(mWebView.paddingTop.toFloat())))
}
}
refreshLayout.setOnRefreshListener { }
// refreshLayout.autoRefresh()

// mWebView.settings.javaScriptEnabled = true
// mWebView.webViewClient = object : WebViewClient() {
// override fun shouldOverrideUrlLoading(view: WebView, url: String): Boolean {
// view.loadUrl(url)
// return true
// }
//
// override fun onPageFinished(view: WebView, url: String) {
// super.onPageFinished(view, url)
// refreshLayout.finishRefresh()
// view.loadUrl(String.format(Locale.CHINA, "javascript:document.body.style.paddingTop='%fpx'; void 0", DensityUtil.px2dp(mWebView.paddingTop.toFloat())))
// }
// }

}

Expand Down
Loading

0 comments on commit 98d17d2

Please sign in to comment.