Skip to content

Commit

Permalink
1.升级kotlin版本号
Browse files Browse the repository at this point in the history
2.让core comp utilities 之间 不会相互依赖
  • Loading branch information
keep2iron committed Apr 2, 2019
1 parent fd4d6e9 commit 2454e59
Show file tree
Hide file tree
Showing 15 changed files with 68 additions and 194 deletions.
6 changes: 3 additions & 3 deletions comp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ dependencies {
transitive = true
}
api 'com.scwang.smartrefresh:SmartRefreshLayout:1.0.5.1'
implementation 'com.github.keep2iron:pomelo:0.1.4'
api project(":utilities")
api project(":core")
implementation deps.fast4android.pomelo
// api project(":utilities")
// api project(":core")

implementation deps.rxjava2
implementation deps.rx_android
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.github.keep2iron.android.adapter

import android.content.Context
import android.support.v7.widget.GridLayoutManager
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
Expand All @@ -9,7 +8,6 @@ import android.view.View
import com.alibaba.android.vlayout.LayoutHelper
import com.alibaba.android.vlayout.layout.LinearLayoutHelper
import io.github.keep2iron.android.comp.R
import io.github.keep2iron.android.utilities.WeakHandler

/**
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.github.keep2iron.android.adapter

import android.content.Context
import android.databinding.DataBindingUtil
import android.databinding.ViewDataBinding
import android.support.annotation.IdRes
Expand All @@ -12,18 +11,13 @@ import android.view.ViewGroup
import com.alibaba.android.vlayout.DelegateAdapter
import com.alibaba.android.vlayout.LayoutHelper
import com.alibaba.android.vlayout.layout.LinearLayoutHelper
import io.github.keep2iron.android.Fast4Android

/**
* @author keep2iron [Contract me.](http://keep2iron.github.io)
* @version 1.0
* @since 2017/11/17 16:30
*/
abstract class AbstractSubAdapter : DelegateAdapter.Adapter<RecyclerViewHolder> {
protected var context: Context = Fast4Android.CONTEXT

protected lateinit var layoutHelper: LayoutHelper

private var listenerMap = ArrayMap<@IdRes Int, (Int) -> Unit>()

private var viewType: Int = 0
Expand All @@ -35,7 +29,6 @@ abstract class AbstractSubAdapter : DelegateAdapter.Adapter<RecyclerViewHolder>
private constructor()

constructor(viewType: Int = 0) : this() {
this.layoutHelper = this.onCreateLayoutHelper()
this.viewType = viewType
}

Expand All @@ -59,7 +52,7 @@ abstract class AbstractSubAdapter : DelegateAdapter.Adapter<RecyclerViewHolder>
abstract fun render(holder: RecyclerViewHolder, position: Int)

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerViewHolder {
val view = LayoutInflater.from(context).inflate(getLayoutId(), parent, false)
val view = LayoutInflater.from(parent.context.applicationContext).inflate(getLayoutId(), parent, false)
var binding: ViewDataBinding? = null
try {
binding = DataBindingUtil.bind(view)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.keep2iron.android.comp

import android.annotation.SuppressLint
import android.arch.lifecycle.Lifecycle
import android.arch.lifecycle.LifecycleObserver
import android.arch.lifecycle.LifecycleOwner
Expand All @@ -12,7 +13,6 @@ import android.os.Bundle
import android.os.Parcelable
import android.support.v4.content.LocalBroadcastManager
import android.support.v4.util.ArrayMap
import io.github.keep2iron.android.Fast4Android
import java.io.Serializable

/**
Expand All @@ -28,19 +28,23 @@ class EventManager {
companion object {
const val DEFAULT_KEY = "Default_Key"

@SuppressLint("StaticFieldLeak")
lateinit var CONTEXT: Context

private val INSTANCE: EventManager by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) {
EventManager()
}

fun getInstance(): EventManager {
fun getInstance(context: Context): EventManager {
this.CONTEXT = context.applicationContext
return EventManager.INSTANCE
}
}

fun register(lifecycleOwner: LifecycleOwner, action: String, handler: (Context, Intent) -> Unit) {
val broadcastReceiver = InnerBroadcastReceiver(handler)
val intentFilter = IntentFilter(action)
LocalBroadcastManager.getInstance(Fast4Android.CONTEXT).registerReceiver(broadcastReceiver, intentFilter)
LocalBroadcastManager.getInstance(CONTEXT).registerReceiver(broadcastReceiver, intentFilter)

lifeCycleBroadcastMap[lifecycleOwner.hashCode().toString() + "#$action"] = broadcastReceiver

Expand All @@ -57,7 +61,7 @@ class EventManager {
if (it.startsWith(lifecycleOwner.hashCode().toString())) {
val broadcastReceiver = lifeCycleBroadcastMap[it]
if (broadcastReceiver != null) {
LocalBroadcastManager.getInstance(Fast4Android.CONTEXT).unregisterReceiver(broadcastReceiver)
LocalBroadcastManager.getInstance(CONTEXT).unregisterReceiver(broadcastReceiver)
lifeCycleBroadcastMap[it] = null
lifeCycleBroadcastMap.remove(it)
}
Expand All @@ -68,19 +72,19 @@ class EventManager {
fun sendEvent(action: String, data: Serializable) {
val intent = Intent(action)
intent.putExtra(DEFAULT_KEY, data)
LocalBroadcastManager.getInstance(Fast4Android.CONTEXT).sendBroadcast(intent)
LocalBroadcastManager.getInstance(CONTEXT).sendBroadcast(intent)
}

fun sendEvent(action: String, data: Parcelable) {
val intent = Intent(action)
intent.putExtra(DEFAULT_KEY, data)
LocalBroadcastManager.getInstance(Fast4Android.CONTEXT).sendBroadcast(intent)
LocalBroadcastManager.getInstance(CONTEXT).sendBroadcast(intent)
}

fun sendEvent(action: String, bundle: Bundle) {
val intent = Intent(action)
intent.putExtras(bundle)
LocalBroadcastManager.getInstance(Fast4Android.CONTEXT).sendBroadcast(intent)
LocalBroadcastManager.getInstance(CONTEXT).sendBroadcast(intent)
}

private class InnerBroadcastReceiver(val handler: (Context, Intent) -> Unit) : BroadcastReceiver() {
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package io.github.keep2iron.android.databinding

import android.databinding.ObservableList
import android.util.Log
import com.orhanobut.logger.Logger

import java.lang.ref.WeakReference

Expand All @@ -9,22 +11,30 @@ open class WeakOnListChangedCallback<T : ObservableList<*>>(delegate: Observable
private val ref: WeakReference<ObservableList.OnListChangedCallback<T>> = WeakReference(delegate)

override fun onChanged(sender: T) {
ref.get()!!.onChanged(sender)
getListener()?.onChanged(sender)
}

override fun onItemRangeChanged(sender: T, positionStart: Int, itemCount: Int) {
ref.get()!!.onItemRangeChanged(sender, positionStart, itemCount)
getListener()?.onItemRangeChanged(sender, positionStart, itemCount)
}

override fun onItemRangeInserted(sender: T, positionStart: Int, itemCount: Int) {
ref.get()!!.onItemRangeInserted(sender, positionStart, itemCount)
getListener()?.onItemRangeInserted(sender, positionStart, itemCount)
}

override fun onItemRangeMoved(sender: T, fromPosition: Int, toPosition: Int, itemCount: Int) {
ref.get()!!.onItemRangeMoved(sender, fromPosition, toPosition, itemCount)
getListener()?.onItemRangeMoved(sender, fromPosition, toPosition, itemCount)
}

override fun onItemRangeRemoved(sender: T, positionStart: Int, itemCount: Int) {
ref.get()!!.onItemRangeRemoved(sender, positionStart, itemCount)
getListener()?.onItemRangeRemoved(sender, positionStart, itemCount)
}

private fun getListener(): ObservableList.OnListChangedCallback<T>? {
val listener = ref.get()
if (listener == null) {
Log.d(WeakOnListChangedCallback::class.java.simpleName, "ref.get() is null!")
}
return listener
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ import android.os.Build
import android.support.v4.view.ViewCompat
import android.util.AttributeSet
import android.util.Log
import android.util.TypedValue
import android.view.Gravity
import android.view.LayoutInflater
import android.view.MotionEvent
import android.view.View
import android.view.View.OnTouchListener
import android.view.ViewGroup
import android.view.WindowManager
import java.lang.reflect.TypeVariable

/**
* copy from qmui
Expand Down Expand Up @@ -170,11 +172,11 @@ abstract class BasePopupWindow(private var mContext: Context) {
}

protected fun makeWidthMeasureSpec(): Int {
return View.MeasureSpec.makeMeasureSpec(io.github.keep2iron.android.utilities.DisplayUtil.getScreenWidth(mContext), View.MeasureSpec.AT_MOST)
return View.MeasureSpec.makeMeasureSpec(mContext.resources.displayMetrics.widthPixels, View.MeasureSpec.AT_MOST)
}

protected fun makeHeightMeasureSpec(): Int {
return View.MeasureSpec.makeMeasureSpec(io.github.keep2iron.android.utilities.DisplayUtil.getScreenHeight(mContext), View.MeasureSpec.AT_MOST)
return View.MeasureSpec.makeMeasureSpec(mContext.resources.displayMetrics.widthPixels, View.MeasureSpec.AT_MOST)
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import android.view.Gravity
import android.view.View
import android.widget.TextView
import io.github.keep2iron.android.comp.R
import io.github.keep2iron.android.utilities.DisplayUtil.dp2px

/**
* @author keep2iron [Contract me.](http://keep2iron.github.io)
Expand All @@ -38,16 +37,16 @@ class BottomTabAdapter(context: Context, val tabs: ArrayList<TabHolder>) {

internal fun provideDefaultTextView(context: Context,
tab: TabHolder,
tabIconWidth: Int,
tabIconHeight: Int,
tabIconWidth: Float,
tabIconHeight: Float,
tabTextSize: Int,
tabLayoutHeight: Float,
drawablePadding: Int,
isSelect: Boolean = false): TextView {
return BadgeTextView(context).apply {
val drawable = ContextCompat.getDrawable(context, if (isSelect) tab.selIconResId else tab.iconResId)
if (drawable != null) {
drawable.setBounds(0, 0, tabIconWidth, tabIconHeight)
drawable.setBounds(0, 0, tabIconWidth.toInt(), tabIconHeight.toInt())
setCompoundDrawables(null, drawable, null, null)
}

Expand Down Expand Up @@ -127,8 +126,8 @@ class BottomTabAdapter(context: Context, val tabs: ArrayList<TabHolder>) {
lateinit var customView: View

var isCustom: Boolean = false
var tabIconWidth: Int = 0
var tabIconHeight: Int = 0
var tabIconWidth: Float = 0f
var tabIconHeight: Float = 0f
var badgeSize: Int = 0
var isEnable = true

Expand Down Expand Up @@ -176,7 +175,7 @@ class BottomTabAdapter(context: Context, val tabs: ArrayList<TabHolder>) {
(customView as TextView).apply {
val drawable = ContextCompat.getDrawable(context, if (isSelect) selIconResId else iconResId)
if (drawable != null) {
drawable.setBounds(0, 0, tabIconWidth, tabIconHeight)
drawable.setBounds(0, 0, tabIconWidth.toInt(), tabIconHeight.toInt())
setCompoundDrawables(null, drawable, null, null)
}
if (!TextUtils.isEmpty(title)) {
Expand Down
Loading

0 comments on commit 2454e59

Please sign in to comment.