Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
Ccixyj committed Mar 2, 2018
2 parents 6d04d3a + de801ab commit 1110afe
Show file tree
Hide file tree
Showing 63 changed files with 841 additions and 423 deletions.
10 changes: 6 additions & 4 deletions api/announce.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
"versionCode": 188,
"versionName": "1.2.1",
"url": "http://git.oschina.net/751762476/jbusfile/raw/master/JubsDriver_v1.2.1build302.apk",
"desc": "JBusDriver 1.2.1 已更新!
1.移除失效的磁力链接,添加了两个新的磁力解析站点.
2.修复收藏收据路径的问题.
3.修复了已知的bug.
"desc": "JBusDriver 1.2.2 已更新!
1.BTSO.PW磁力站点已经恢复,现已重新加入.
2.跳页模式下,添加跳页菜单,跳页选择模式优化.
3.现在抽屉菜单与配置项属性一致.
4.优化样本图片放大后,图片与换页的冲突.添加样本图片加载进度.
5.优化屏幕旋转/分屏的加载.
"
},
"notice": {
Expand Down
11 changes: 8 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,14 @@ dependencies {
implementation "com.github.CymChad:BaseRecyclerViewAdapterHelper:${versions.BaseRecyclerViewAdapterHelper}"
implementation "org.jsoup:jsoup:${versions.jsoup}"
//group: "org.jsoup", name: "jsoup", version: "1.11.1"
compile "com.xw.repo:bubbleseekbar:${versions.bubbleseekbar}-lite"

implementation "com.squareup.okhttp3:okhttp:${versions.okhttp}"
implementation "com.squareup.retrofit2:retrofit:${versions.retrofit}"
// implementation "com.squareup.retrofit2:converter-gson:${versions.retrofit}"
implementation "com.squareup.retrofit2:adapter-rxjava2:${versions.retrofit}"

implementation ("com.github.bumptech.glide:glide:${versions.glide}"){
implementation("com.github.bumptech.glide:glide:${versions.glide}") {
exclude group: "com.android.support"
}
kapt "com.github.bumptech.glide:compiler:${versions.glide}"
Expand All @@ -167,9 +168,13 @@ dependencies {
//https://github.com/xiaofeng-han/AndroidLibs/tree/master/flowlayoutmanager
implementation "com.umeng.analytics:analytics:${versions.analytics}"

//stetho
implementation "com.facebook.stetho:stetho:${versions.stetho}"
implementation "com.facebook.stetho:stetho-okhttp3:${versions.stetho}"

//leak
debugCompile "com.squareup.leakcanary:leakcanary-android:${versions.leakcanary}"
releaseCompile "com.squareup.leakcanary:leakcanary-android-no-op:${versions.leakcanary}"
debugImplementation "com.squareup.leakcanary:leakcanary-android:${versions.leakcanary}"
releaseImplementation "com.squareup.leakcanary:leakcanary-android-no-op:${versions.leakcanary}"

}

Expand Down
25 changes: 20 additions & 5 deletions app/src/main/java/me/jbusdriver/common/AppBaseActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import java.util.concurrent.atomic.AtomicInteger
/**
* Created by Administrator on 2016/7/21 0021.
*/
abstract class AppBaseActivity<P : BasePresenter<V>, V : BaseView> : BaseActivity(), LoaderManager.LoaderCallbacks<P>, PresenterFactory<P>, BaseView {
abstract class AppBaseActivity<P : BasePresenter<V>, in V : BaseView> : BaseActivity(), LoaderManager.LoaderCallbacks<P>, PresenterFactory<P>, BaseView {
/**
* Do we need to call [.doStart] from the [.onLoadFinished] method.
* Will be true if SPresenter wasn't loaded when [.onStart] is reached
Expand All @@ -35,6 +35,9 @@ abstract class AppBaseActivity<P : BasePresenter<V>, V : BaseView> : BaseActivit
mUniqueLoaderIdentifier = savedInstanceState?.getInt(C.SavedInstanceState.LOADER_ID_SAVED_STATE) ?: AppBaseActivity.sViewCounter.incrementAndGet()
setContentView(this.inflate(layoutId))
supportLoaderManager.initLoader(mUniqueLoaderIdentifier, savedInstanceState, this@AppBaseActivity)
if (savedInstanceState != null) {
intent.putExtra(C.SavedInstanceState.LOADER_SAVED_STATES + mUniqueLoaderIdentifier, savedInstanceState)
}
}

override fun onStart() {
Expand All @@ -51,6 +54,14 @@ abstract class AppBaseActivity<P : BasePresenter<V>, V : BaseView> : BaseActivit
requireNotNull(mBasePresenter)
mBasePresenter?.onViewAttached(this as V)
mBasePresenter?.onStart(mFirstStart)
/**
* 恢复状态 @see onSaveInstanceState
*/
val bundleKey = C.SavedInstanceState.LOADER_SAVED_STATES + mUniqueLoaderIdentifier
intent.getBundleExtra(bundleKey)?.let {
restoreState(it)
intent.removeExtra(bundleKey)
}
mFirstStart = false
}

Expand All @@ -77,10 +88,10 @@ abstract class AppBaseActivity<P : BasePresenter<V>, V : BaseView> : BaseActivit
}

override fun onSaveInstanceState(outState: Bundle?) {
KLog.d("onSaveInstanceState $outState")
super.onSaveInstanceState(outState)
outState?.putBoolean(C.SavedInstanceState.RECREATION_SAVED_STATE, true)
outState?.putBoolean(C.SavedInstanceState.RECREATION_SAVED_STATE, mFirstStart)
outState?.putInt(C.SavedInstanceState.LOADER_ID_SAVED_STATE, mUniqueLoaderIdentifier)
KLog.d("$TAG onSaveInstanceState $outState")
}

protected abstract val layoutId: Int
Expand Down Expand Up @@ -108,8 +119,7 @@ abstract class AppBaseActivity<P : BasePresenter<V>, V : BaseView> : BaseActivit
}



override fun showLoading() {
override fun showLoading() {
if (viewContext is AppContext) return
placeDialogHolder = MaterialDialog.Builder(viewContext).content("正在加载...").progress(true, 0).show()
}
Expand All @@ -119,6 +129,11 @@ abstract class AppBaseActivity<P : BasePresenter<V>, V : BaseView> : BaseActivit
placeDialogHolder = null
}

protected open fun restoreState(bundle: Bundle) {
KLog.d("$TAG restoreState : $bundle")
mBasePresenter?.restoreFromState()
}

companion object {
val sViewCounter = AtomicInteger(Integer.MIN_VALUE)
}
Expand Down
28 changes: 19 additions & 9 deletions app/src/main/java/me/jbusdriver/common/AppBaseFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,16 @@ abstract class AppBaseFragment<P : BasePresenter<V>, V> : BaseFragment(), Loader

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
KLog.t(TAG).d("onCreate : $savedInstanceState")
mFirstStart = savedInstanceState == null || savedInstanceState.getBoolean(C.SavedInstanceState.RECREATION_SAVED_STATE)
mUniqueLoaderIdentifier = savedInstanceState?.getInt(C.SavedInstanceState.LOADER_ID_SAVED_STATE) ?: AppBaseActivity.sViewCounter.incrementAndGet()

}

override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
KLog.t(TAG).d("onActivityCreated :$savedInstanceState")
require(activity != null)
activity!!.intent.putExtra(C.SavedInstanceState.LOADER_SAVED_STATES + mUniqueLoaderIdentifier, savedInstanceState)
loaderManager.initLoader(mUniqueLoaderIdentifier, null, this).startLoading()
}

Expand All @@ -60,17 +63,13 @@ abstract class AppBaseFragment<P : BasePresenter<V>, V> : BaseFragment(), Loader
}
}
KLog.t(TAG).d("onCreateView ok: ${rootViewWeakRef?.get()}")
if (savedInstanceState != null)
onRestartInstance(savedInstanceState)
return rootViewWeakRef?.get()
}

protected abstract val layoutId: Int

protected abstract fun initWidget(rootView: View)

protected open fun onRestartInstance(bundle: Bundle) {}


override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
Expand All @@ -80,17 +79,18 @@ abstract class AppBaseFragment<P : BasePresenter<V>, V> : BaseFragment(), Loader
}

private fun doStart() {
KLog.t(TAG).d("doStart : mFirstStart :" + mFirstStart, "mUniqueLoaderIdentifier :" + mUniqueLoaderIdentifier, "instance = " + this)
KLog.t(TAG).d("doStart : mFirstStart :" + mFirstStart +" mUniqueLoaderIdentifier :" + mUniqueLoaderIdentifier+ " instance = " + this)
requireNotNull(mBasePresenter)
mBasePresenter?.onViewAttached(this as V)
mBasePresenter?.onStart(mFirstStart)
if (mFirstStart || mViewReCreate) {
initData()
}
KLog.d("doStart lazyLoad $TAG $mFirstStart $isLazyLoaded $userVisibleHint")
if (mFirstStart && !isLazyLoaded && userVisibleHint) {
if ((mFirstStart || mViewReCreate) && !isLazyLoaded && userVisibleHint) {
lazyLoad()
}

mFirstStart = false
mViewReCreate = false
}
Expand Down Expand Up @@ -145,7 +145,6 @@ abstract class AppBaseFragment<P : BasePresenter<V>, V> : BaseFragment(), Loader
if (isLazyLoaded) {
return
}
KLog.w("lazyLoad :$TAG")
if (mBasePresenter is BasePresenter.LazyLoaderPresenter) (mBasePresenter as? BasePresenter.LazyLoaderPresenter)?.lazyLoad()
isLazyLoaded = true
}
Expand Down Expand Up @@ -178,8 +177,9 @@ abstract class AppBaseFragment<P : BasePresenter<V>, V> : BaseFragment(), Loader

override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
outState.putBoolean(C.SavedInstanceState.RECREATION_SAVED_STATE, true)
outState.putBoolean(C.SavedInstanceState.RECREATION_SAVED_STATE, mFirstStart)
outState.putInt(C.SavedInstanceState.LOADER_ID_SAVED_STATE, mUniqueLoaderIdentifier)
KLog.d("$TAG onSaveInstanceState $outState")
}


Expand All @@ -197,6 +197,11 @@ abstract class AppBaseFragment<P : BasePresenter<V>, V> : BaseFragment(), Loader
//fragment中会赋值两次,可以设置flag。
KLog.t(TAG).d("onLoadFinished")
mBasePresenter = data
val bundleKey = C.SavedInstanceState.LOADER_SAVED_STATES + mUniqueLoaderIdentifier
activity!!.intent.getBundleExtra(bundleKey)?.let {
restoreState(it)
activity!!.intent.removeExtra(bundleKey)
}
if (mNeedToCallStart.compareAndSet(true, false)) {
doStart()
}
Expand All @@ -216,4 +221,9 @@ abstract class AppBaseFragment<P : BasePresenter<V>, V> : BaseFragment(), Loader
placeDialogHolder = null
}

protected open fun restoreState(bundle: Bundle) {
KLog.d("$TAG restoreState : $bundle")
mBasePresenter?.restoreFromState()
}

}
55 changes: 39 additions & 16 deletions app/src/main/java/me/jbusdriver/common/AppBaseRecycleFragment.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package me.jbusdriver.common

import android.animation.ObjectAnimator
import android.content.Context
import android.os.Bundle
import android.support.v4.widget.SwipeRefreshLayout
import android.support.v7.widget.RecyclerView
Expand All @@ -10,6 +11,7 @@ import android.view.ViewGroup
import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.chad.library.adapter.base.loadmore.SimpleLoadMoreView
import io.reactivex.Flowable
import jbusdriver.me.jbusdriver.R
import me.jbusdriver.mvp.BaseView
Expand All @@ -18,23 +20,21 @@ import me.jbusdriver.mvp.presenter.BasePresenter
abstract class AppBaseRecycleFragment<P : BasePresenter.BaseRefreshLoadMorePresenter<V>, V : BaseView.BaseListWithRefreshView, M> : AppBaseFragment<P, V>(), BaseView.BaseListWithRefreshView {

/**
* view 销毁后获取时要从view中重新获取;
* view 销毁后获取时要从view中重新获取; ex : 切换横竖屏
* 重复使用fragment是不推荐lazy方式初始化.可能到时view引用的对象还是老对象.
*/
abstract val swipeView: SwipeRefreshLayout?
abstract val recycleView: RecyclerView
abstract val layoutManager: RecyclerView.LayoutManager
abstract val adapter: BaseQuickAdapter<M, in BaseViewHolder>


override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setHasOptionsMenu(true)
}

override fun initWidget(rootView: View) {
recycleView.layoutManager = layoutManager
recycleView.recycledViewPool

adapter.openLoadAnimation {
arrayOf(ObjectAnimator.ofFloat(it, "alpha", 0.0f, 1.0f),
Expand All @@ -44,6 +44,9 @@ abstract class AppBaseRecycleFragment<P : BasePresenter.BaseRefreshLoadMorePrese
swipeView?.setOnRefreshListener { mBasePresenter?.onRefresh() }
adapter.bindToRecyclerView(recycleView)
adapter.setOnLoadMoreListener({ mBasePresenter?.onLoadMore() }, recycleView)
adapter.setLoadMoreView(SimpleLoadMoreView())


}

override fun showLoading() {
Expand Down Expand Up @@ -78,26 +81,17 @@ abstract class AppBaseRecycleFragment<P : BasePresenter.BaseRefreshLoadMorePrese

override fun loadMoreEnd(clickable: Boolean) {
if (adapter.getEmptyView() == null && adapter.getData().isEmpty()) {
adapter.setEmptyView(getEmptyView())
adapter.setEmptyView(EmptyState.NoData(viewContext).getEmptyView())
}
adapter.loadMoreEnd()
adapter.enableLoadMoreEndClick(clickable)
}

protected open fun getEmptyView(): View = TextView(viewContext).apply {
text = "没有数据"
layoutParams = ViewGroup.MarginLayoutParams(ViewGroup.MarginLayoutParams.MATCH_PARENT, viewContext.dpToPx(36f)).apply {
gravity = Gravity.CENTER
}
}

override fun loadMoreFail() {
if (adapter.getData().isEmpty()){
adapter.setEmptyView(getEmptyView().apply {
(this as? TextView)?.text = "加载错误"
setOnClickListener {
mBasePresenter?.onRefresh()
}
if (adapter.getEmptyViewCount() <= 0 && adapter.getData().isEmpty()) {
adapter.setEmptyView(EmptyState.ErrorEmpty(viewContext).getEmptyView().apply {
setOnClickListener { mBasePresenter?.onRefresh() }
})
}
adapter.loadMoreFail()
Expand All @@ -116,12 +110,41 @@ abstract class AppBaseRecycleFragment<P : BasePresenter.BaseRefreshLoadMorePrese


override fun resetList() {
KLog.d("resetList")
adapter.setNewData(null)
}

override fun showError(e: Throwable?) {
adapter.loadMoreFail()
}

sealed class EmptyState(val tip: String) {
class NoData(val context: Context) : EmptyState("没有数据") {
override fun getEmptyView(): View {
return TextView(context).apply {
text = tip
layoutParams = ViewGroup.MarginLayoutParams(ViewGroup.MarginLayoutParams.MATCH_PARENT, context.dpToPx(36f)).apply {
gravity = Gravity.CENTER
}
}

}
}

class ErrorEmpty(val context: Context) : EmptyState("加载失败") {
override fun getEmptyView(): View {
return TextView(context).apply {
text = tip
layoutParams = ViewGroup.MarginLayoutParams(ViewGroup.MarginLayoutParams.MATCH_PARENT, context.dpToPx(36f)).apply {
gravity = Gravity.CENTER
}
}

}
}

abstract fun getEmptyView(): View
}
}


Loading

0 comments on commit 1110afe

Please sign in to comment.