mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-22 21:58:53 +01:00
Use constructor injection for all adapters
This commit is contained in:
@@ -4,7 +4,6 @@ import com.moez.QKSMS.common.util.ContactImageLoader
|
|||||||
import com.moez.QKSMS.presentation.compose.ComposeActivity
|
import com.moez.QKSMS.presentation.compose.ComposeActivity
|
||||||
import com.moez.QKSMS.presentation.compose.ComposeViewModel
|
import com.moez.QKSMS.presentation.compose.ComposeViewModel
|
||||||
import com.moez.QKSMS.presentation.compose.DetailedChipView
|
import com.moez.QKSMS.presentation.compose.DetailedChipView
|
||||||
import com.moez.QKSMS.presentation.compose.MessagesAdapter
|
|
||||||
import com.moez.QKSMS.presentation.main.MainActivity
|
import com.moez.QKSMS.presentation.main.MainActivity
|
||||||
import com.moez.QKSMS.presentation.main.MainViewModel
|
import com.moez.QKSMS.presentation.main.MainViewModel
|
||||||
import com.moez.QKSMS.presentation.settings.SettingsActivity
|
import com.moez.QKSMS.presentation.settings.SettingsActivity
|
||||||
@@ -15,15 +14,13 @@ import dagger.Component
|
|||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
@Component(modules = arrayOf(AppModule::class))
|
@Component(modules = [(AppModule::class)])
|
||||||
interface AppComponent {
|
interface AppComponent {
|
||||||
|
|
||||||
fun inject(activity: MainActivity)
|
fun inject(activity: MainActivity)
|
||||||
fun inject(activity: ComposeActivity)
|
fun inject(activity: ComposeActivity)
|
||||||
fun inject(activity: SettingsActivity)
|
fun inject(activity: SettingsActivity)
|
||||||
|
|
||||||
fun inject(adapter: MessagesAdapter)
|
|
||||||
|
|
||||||
fun inject(receiver: DefaultSmsChangedReceiver)
|
fun inject(receiver: DefaultSmsChangedReceiver)
|
||||||
fun inject(receiver: SmsReceiver)
|
fun inject(receiver: SmsReceiver)
|
||||||
fun inject(receiver: MessageDeliveredReceiver)
|
fun inject(receiver: MessageDeliveredReceiver)
|
||||||
|
|||||||
@@ -21,11 +21,9 @@ import com.moez.QKSMS.presentation.base.QkAdapter
|
|||||||
import com.moez.QKSMS.presentation.base.QkViewHolder
|
import com.moez.QKSMS.presentation.base.QkViewHolder
|
||||||
import io.reactivex.subjects.PublishSubject
|
import io.reactivex.subjects.PublishSubject
|
||||||
import kotlinx.android.synthetic.main.contact_chip.view.*
|
import kotlinx.android.synthetic.main.contact_chip.view.*
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
class ChipsAdapter(
|
class ChipsAdapter @Inject constructor(private val context: Context) : QkAdapter<Contact>() {
|
||||||
private val context: Context,
|
|
||||||
private val view: RecyclerView)
|
|
||||||
: QkAdapter<Contact>() {
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private val TYPE_EDIT_TEXT = 0
|
private val TYPE_EDIT_TEXT = 0
|
||||||
@@ -35,6 +33,7 @@ class ChipsAdapter(
|
|||||||
private val hint: String = context.getString(R.string.title_compose)
|
private val hint: String = context.getString(R.string.title_compose)
|
||||||
private val editText = View.inflate(context, R.layout.chip_input_list_item, null) as EditText
|
private val editText = View.inflate(context, R.layout.chip_input_list_item, null) as EditText
|
||||||
|
|
||||||
|
var view: RecyclerView? = null
|
||||||
val chipDeleted: PublishSubject<Contact> = PublishSubject.create<Contact>()
|
val chipDeleted: PublishSubject<Contact> = PublishSubject.create<Contact>()
|
||||||
val textChanges = editText.textChanges()
|
val textChanges = editText.textChanges()
|
||||||
|
|
||||||
@@ -98,7 +97,7 @@ class ChipsAdapter(
|
|||||||
val detailedChipView = DetailedChipView(context)
|
val detailedChipView = DetailedChipView(context)
|
||||||
detailedChipView.setContact(contact)
|
detailedChipView.setContact(contact)
|
||||||
|
|
||||||
val rootView = view.rootView as ViewGroup
|
val rootView = view?.rootView as ViewGroup
|
||||||
|
|
||||||
val layoutParams = RelativeLayout.LayoutParams(
|
val layoutParams = RelativeLayout.LayoutParams(
|
||||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||||
|
|||||||
@@ -25,12 +25,11 @@ import io.reactivex.subjects.PublishSubject
|
|||||||
import io.reactivex.subjects.Subject
|
import io.reactivex.subjects.Subject
|
||||||
import kotlinx.android.synthetic.main.compose_activity.*
|
import kotlinx.android.synthetic.main.compose_activity.*
|
||||||
import kotlinx.android.synthetic.main.toolbar_chips.*
|
import kotlinx.android.synthetic.main.toolbar_chips.*
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
|
||||||
class ComposeActivity : QkActivity<ComposeViewModel>(), ComposeView {
|
class ComposeActivity : QkActivity<ComposeViewModel>(), ComposeView {
|
||||||
|
|
||||||
private lateinit var layoutManager: LinearLayoutManager
|
|
||||||
|
|
||||||
override val viewModelClass = ComposeViewModel::class
|
override val viewModelClass = ComposeViewModel::class
|
||||||
override val queryChangedIntent: Observable<CharSequence> by lazy { chipsAdapter.textChanges }
|
override val queryChangedIntent: Observable<CharSequence> by lazy { chipsAdapter.textChanges }
|
||||||
override val chipSelectedIntent: Subject<Contact> by lazy { contactsAdapter.contactSelected }
|
override val chipSelectedIntent: Subject<Contact> by lazy { contactsAdapter.contactSelected }
|
||||||
@@ -46,9 +45,11 @@ class ComposeActivity : QkActivity<ComposeViewModel>(), ComposeView {
|
|||||||
override val attachIntent by lazy { attach.clicks() }
|
override val attachIntent by lazy { attach.clicks() }
|
||||||
override val sendIntent by lazy { send.clicks() }
|
override val sendIntent by lazy { send.clicks() }
|
||||||
|
|
||||||
private val chipsAdapter by lazy { ChipsAdapter(this, chips) }
|
private val layoutManager by lazy { LinearLayoutManager(this).apply { stackFromEnd = true } }
|
||||||
private val contactsAdapter by lazy { ContactAdapter(this) }
|
|
||||||
private val messageAdapter by lazy { MessagesAdapter() }
|
@Inject lateinit var chipsAdapter: ChipsAdapter
|
||||||
|
@Inject lateinit var contactsAdapter: ContactAdapter
|
||||||
|
@Inject lateinit var messageAdapter: MessagesAdapter
|
||||||
|
|
||||||
init {
|
init {
|
||||||
appComponent.inject(this)
|
appComponent.inject(this)
|
||||||
@@ -60,6 +61,8 @@ class ComposeActivity : QkActivity<ComposeViewModel>(), ComposeView {
|
|||||||
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||||
viewModel.bindView(this)
|
viewModel.bindView(this)
|
||||||
|
|
||||||
|
chipsAdapter.view = chips
|
||||||
|
|
||||||
chips.itemAnimator = null
|
chips.itemAnimator = null
|
||||||
chips.layoutManager = FlexboxLayoutManager(this)
|
chips.layoutManager = FlexboxLayoutManager(this)
|
||||||
chips.adapter = chipsAdapter
|
chips.adapter = chipsAdapter
|
||||||
@@ -70,7 +73,6 @@ class ComposeActivity : QkActivity<ComposeViewModel>(), ComposeView {
|
|||||||
|
|
||||||
setupMessagesAdapter()
|
setupMessagesAdapter()
|
||||||
|
|
||||||
layoutManager = LinearLayoutManager(this).apply { stackFromEnd = true }
|
|
||||||
messageList.layoutManager = layoutManager
|
messageList.layoutManager = layoutManager
|
||||||
messageList.adapter = messageAdapter
|
messageList.adapter = messageAdapter
|
||||||
|
|
||||||
|
|||||||
@@ -11,8 +11,9 @@ import com.moez.QKSMS.presentation.base.QkViewHolder
|
|||||||
import io.reactivex.subjects.PublishSubject
|
import io.reactivex.subjects.PublishSubject
|
||||||
import io.reactivex.subjects.Subject
|
import io.reactivex.subjects.Subject
|
||||||
import kotlinx.android.synthetic.main.contact_list_item.view.*
|
import kotlinx.android.synthetic.main.contact_list_item.view.*
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
class ContactAdapter(private val context: Context) : QkAdapter<Contact>() {
|
class ContactAdapter @Inject constructor(private val context: Context) : QkAdapter<Contact>() {
|
||||||
|
|
||||||
val contactSelected: Subject<Contact> = PublishSubject.create()
|
val contactSelected: Subject<Contact> = PublishSubject.create()
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import android.view.View
|
|||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import com.jakewharton.rxbinding2.view.RxView
|
import com.jakewharton.rxbinding2.view.RxView
|
||||||
import com.moez.QKSMS.R
|
import com.moez.QKSMS.R
|
||||||
import com.moez.QKSMS.common.di.appComponent
|
|
||||||
import com.moez.QKSMS.common.util.Colors
|
import com.moez.QKSMS.common.util.Colors
|
||||||
import com.moez.QKSMS.common.util.DateFormatter
|
import com.moez.QKSMS.common.util.DateFormatter
|
||||||
import com.moez.QKSMS.common.util.extensions.dpToPx
|
import com.moez.QKSMS.common.util.extensions.dpToPx
|
||||||
@@ -26,26 +25,22 @@ import timber.log.Timber
|
|||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class MessagesAdapter : RealmRecyclerViewAdapter<Message, QkViewHolder>(null, true) {
|
class MessagesAdapter @Inject constructor(
|
||||||
|
private val context: Context,
|
||||||
|
private val colors: Colors,
|
||||||
|
private val dateFormatter: DateFormatter)
|
||||||
|
: RealmRecyclerViewAdapter<Message, QkViewHolder>(null, true) {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private val VIEWTYPE_ME = -1
|
private val VIEWTYPE_ME = -1
|
||||||
private val TIMESTAMP_THRESHOLD = 60
|
private val TIMESTAMP_THRESHOLD = 60
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject lateinit var context: Context
|
|
||||||
@Inject lateinit var colors: Colors
|
|
||||||
@Inject lateinit var dateFormatter: DateFormatter
|
|
||||||
|
|
||||||
val longClicks: Subject<Message> = PublishSubject.create<Message>()
|
val longClicks: Subject<Message> = PublishSubject.create<Message>()
|
||||||
|
|
||||||
private val people = ArrayList<String>()
|
private val people = ArrayList<String>()
|
||||||
private val disposables = CompositeDisposable()
|
private val disposables = CompositeDisposable()
|
||||||
|
|
||||||
init {
|
|
||||||
appComponent.inject(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): QkViewHolder {
|
override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): QkViewHolder {
|
||||||
|
|
||||||
val layoutInflater = LayoutInflater.from(context)
|
val layoutInflater = LayoutInflater.from(context)
|
||||||
|
|||||||
Reference in New Issue
Block a user