Move packages to com.moez.QKSMS

This commit is contained in:
Moez Bhatti
2018-06-20 14:29:07 -04:00
parent d8141737b3
commit a5f518042e
268 changed files with 1101 additions and 1116 deletions
@@ -0,0 +1,146 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package com.moez.QKSMS.feature.conversationinfo
import android.arch.lifecycle.ViewModelProvider
import android.arch.lifecycle.ViewModelProviders
import android.os.Bundle
import android.support.v7.app.AlertDialog
import android.text.InputFilter
import com.jakewharton.rxbinding2.view.clicks
import com.moez.QKSMS.R
import com.moez.QKSMS.common.Navigator
import com.moez.QKSMS.common.base.QkThemedActivity
import com.moez.QKSMS.common.util.extensions.animateLayoutChanges
import com.moez.QKSMS.common.util.extensions.dpToPx
import com.moez.QKSMS.common.util.extensions.resolveThemeColor
import com.moez.QKSMS.common.util.extensions.scrapViews
import com.moez.QKSMS.common.util.extensions.setVisible
import com.moez.QKSMS.common.widget.QkEditText
import com.uber.autodispose.android.lifecycle.scope
import com.uber.autodispose.kotlin.autoDisposable
import dagger.android.AndroidInjection
import io.reactivex.subjects.PublishSubject
import io.reactivex.subjects.Subject
import kotlinx.android.synthetic.main.conversation_info_activity.*
import javax.inject.Inject
class ConversationInfoActivity : QkThemedActivity(), ConversationInfoView {
@Inject lateinit var navigator: Navigator
@Inject lateinit var recipientAdapter: ConversationRecipientAdapter
@Inject lateinit var mediaAdapter: ConversationMediaAdapter
@Inject lateinit var itemDecoration: GridSpacingItemDecoration
@Inject lateinit var viewModelFactory: ViewModelProvider.Factory
override val nameIntent by lazy { name.clicks() }
override val nameChangedIntent: Subject<String> = PublishSubject.create()
override val notificationsIntent by lazy { notifications.clicks() }
override val themeIntent by lazy { themePrefs.clicks() }
override val archiveIntent by lazy { archive.clicks() }
override val blockIntent by lazy { block.clicks() }
override val deleteIntent by lazy { delete.clicks() }
override val confirmDeleteIntent: PublishSubject<Unit> = PublishSubject.create()
private val viewModel by lazy { ViewModelProviders.of(this, viewModelFactory)[ConversationInfoViewModel::class.java] }
override fun onCreate(savedInstanceState: Bundle?) {
AndroidInjection.inject(this)
super.onCreate(savedInstanceState)
setContentView(R.layout.conversation_info_activity)
showBackButton(true)
viewModel.bindView(this)
setTitle(R.string.info_title)
items.postDelayed({ items.animateLayoutChanges = true }, 100)
mediaAdapter.thumbnailClicks
.autoDisposable(scope())
.subscribe { view -> navigator.showImageAnimated(this, view) }
recipients.adapter = recipientAdapter
media.adapter = mediaAdapter
media.addItemDecoration(itemDecoration)
theme
.autoDisposable(scope())
.subscribe { recipients.scrapViews() }
}
override fun render(state: ConversationInfoState) {
if (state.hasError) {
finish()
return
}
threadId.onNext(state.threadId)
recipientAdapter.threadId = state.threadId
recipientAdapter.updateData(state.recipients)
name.setVisible(state.recipients?.size ?: 0 >= 2)
name.summary = state.name
notifications.setVisible(!state.blocked)
archive.setVisible(!state.blocked)
archive.title = getString(when (state.archived) {
true -> R.string.info_unarchive
false -> R.string.info_archive
})
block.title = getString(when (state.blocked) {
true -> R.string.info_unblock
false -> R.string.info_block
})
mediaAdapter.updateData(state.media)
}
override fun showNameDialog(name: String) {
val editText = QkEditText(this).apply {
val padding = 8.dpToPx(this@ConversationInfoActivity)
setPadding(padding * 3, padding, padding * 3, padding)
setSingleLine(true)
setHint(R.string.info_name_hint)
setText(name)
setHintTextColor(context.resolveThemeColor(android.R.attr.textColorTertiary))
setTextColor(context.resolveThemeColor(android.R.attr.textColorPrimary))
filters = arrayOf(InputFilter.LengthFilter(30))
background = null
}
AlertDialog.Builder(this)
.setTitle(R.string.info_name)
.setView(editText)
.setPositiveButton(R.string.button_save, { _, _ -> nameChangedIntent.onNext(editText.text.toString()) })
.setNegativeButton(R.string.button_cancel, null)
.show()
}
override fun showDeleteDialog() {
AlertDialog.Builder(this)
.setTitle(R.string.dialog_delete_title)
.setMessage(R.string.dialog_delete_message)
.setPositiveButton(R.string.button_delete, { _, _ -> confirmDeleteIntent.onNext(Unit) })
.setNegativeButton(R.string.button_cancel, null)
.show()
}
}
@@ -0,0 +1,22 @@
package com.moez.QKSMS.feature.conversationinfo
import android.arch.lifecycle.ViewModel
import com.moez.QKSMS.injection.ViewModelKey
import dagger.Module
import dagger.Provides
import dagger.multibindings.IntoMap
import javax.inject.Named
@Module
class ConversationInfoActivityModule {
@Provides
@Named("threadId")
fun provideIntent(activity: ConversationInfoActivity): Long = activity.intent.extras?.getLong("threadId") ?: 0L
@Provides
@IntoMap
@ViewModelKey(ConversationInfoViewModel::class)
fun provideConversationInfoViewModel(viewModel: ConversationInfoViewModel): ViewModel = viewModel
}
@@ -0,0 +1,34 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package com.moez.QKSMS.feature.conversationinfo
import com.moez.QKSMS.model.MmsPart
import com.moez.QKSMS.model.Recipient
import io.realm.RealmList
import io.realm.RealmResults
data class ConversationInfoState(
val name: String = "",
val recipients: RealmList<Recipient>? = null,
val threadId: Long = 0,
val archived: Boolean = false,
val blocked: Boolean = false,
val media: RealmResults<MmsPart>? = null,
val hasError: Boolean = false
)
@@ -0,0 +1,38 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package com.moez.QKSMS.feature.conversationinfo
import com.moez.QKSMS.common.base.QkView
import io.reactivex.Observable
interface ConversationInfoView : QkView<ConversationInfoState> {
val nameIntent: Observable<*>
val nameChangedIntent: Observable<String>
val notificationsIntent: Observable<Unit>
val themeIntent: Observable<Unit>
val archiveIntent: Observable<Unit>
val blockIntent: Observable<Unit>
val deleteIntent: Observable<Unit>
val confirmDeleteIntent: Observable<Unit>
fun showNameDialog(name: String)
fun showDeleteDialog()
}
@@ -0,0 +1,165 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package com.moez.QKSMS.feature.conversationinfo
import com.moez.QKSMS.common.Navigator
import com.moez.QKSMS.common.base.QkViewModel
import com.moez.QKSMS.extensions.asObservable
import com.moez.QKSMS.interactor.DeleteConversations
import com.moez.QKSMS.interactor.MarkArchived
import com.moez.QKSMS.interactor.MarkBlocked
import com.moez.QKSMS.interactor.MarkUnarchived
import com.moez.QKSMS.interactor.MarkUnblocked
import com.moez.QKSMS.model.Conversation
import com.moez.QKSMS.repository.ConversationRepository
import com.moez.QKSMS.repository.MessageRepository
import com.uber.autodispose.android.lifecycle.scope
import com.uber.autodispose.kotlin.autoDisposable
import io.reactivex.rxkotlin.plusAssign
import io.reactivex.rxkotlin.withLatestFrom
import io.reactivex.subjects.BehaviorSubject
import io.reactivex.subjects.Subject
import javax.inject.Inject
import javax.inject.Named
class ConversationInfoViewModel @Inject constructor(
@Named("threadId") threadId: Long,
private val conversationRepo: ConversationRepository,
private val markArchived: MarkArchived,
private val markUnarchived: MarkUnarchived,
private val markBlocked: MarkBlocked,
private val markUnblocked: MarkUnblocked,
private val messageRepo: MessageRepository,
private val navigator: Navigator,
private val deleteConversations: DeleteConversations
) : QkViewModel<ConversationInfoView, ConversationInfoState>(
ConversationInfoState(threadId = threadId, media = messageRepo.getPartsForConversation(threadId))
) {
private val conversation: Subject<Conversation> = BehaviorSubject.create()
init {
disposables += conversationRepo.getConversationAsync(threadId)
.asObservable<Conversation>()
.filter { conversation -> conversation.isLoaded }
.doOnNext { conversation ->
if (!conversation.isValid) {
newState { copy(hasError = true) }
}
}
.filter { conversation -> conversation.isValid }
.filter { conversation -> conversation.id != 0L }
.subscribe(conversation::onNext)
disposables += markArchived
disposables += markUnarchived
disposables += markBlocked
disposables += markUnblocked
disposables += deleteConversations
// Update the recipients whenever they change
disposables += conversation
.map { conversation -> conversation.recipients }
.distinctUntilChanged()
.subscribe { recipients -> newState { copy(recipients = recipients) } }
// Update conversation title whenever it changes
disposables += conversation
.map { conversation -> conversation.name }
.distinctUntilChanged()
.subscribe { name -> newState { copy(name = name) } }
// Update the view's archived state whenever it changes
disposables += conversation
.map { conversation -> conversation.archived }
.distinctUntilChanged()
.subscribe { archived -> newState { copy(archived = archived) } }
// Update the view's blocked state whenever it changes
disposables += conversation
.map { conversation -> conversation.blocked }
.distinctUntilChanged()
.subscribe { blocked -> newState { copy(blocked = blocked) } }
}
override fun bindView(view: ConversationInfoView) {
super.bindView(view)
// Show the conversation title dialog
view.nameIntent
.withLatestFrom(conversation) { _, conversation -> conversation }
.map { conversation -> conversation.name }
.autoDisposable(view.scope())
.subscribe(view::showNameDialog)
// Set the conversation title
view.nameChangedIntent
.withLatestFrom(conversation) { name, conversation ->
conversationRepo.setConversationName(conversation.id, name)
}
.autoDisposable(view.scope())
.subscribe()
// Show the notifications settings for the conversation
view.notificationsIntent
.withLatestFrom(conversation, { _, conversation -> conversation })
.autoDisposable(view.scope())
.subscribe { conversation -> navigator.showNotificationSettings(conversation.id) }
// Show the theme settings for the conversation
view.themeIntent
.withLatestFrom(conversation, { _, conversation -> conversation })
.autoDisposable(view.scope())
.subscribe { conversation -> navigator.showThemePicker(conversation.id) }
// Toggle the archived state of the conversation
view.archiveIntent
.withLatestFrom(conversation, { _, conversation -> conversation })
.autoDisposable(view.scope())
.subscribe { conversation ->
when (conversation.archived) {
true -> markUnarchived.execute(listOf(conversation.id))
false -> markArchived.execute(listOf(conversation.id))
}
}
// Toggle the blocked state of the conversation
view.blockIntent
.withLatestFrom(conversation, { _, conversation -> conversation })
.autoDisposable(view.scope())
.subscribe { conversation ->
when (conversation.blocked) {
true -> markUnblocked.execute(listOf(conversation.id))
false -> markBlocked.execute(listOf(conversation.id))
}
}
// Show the delete confirmation dialog
view.deleteIntent
.autoDisposable(view.scope())
.subscribe { view.showDeleteDialog() }
// Delete the conversation
view.confirmDeleteIntent
.withLatestFrom(conversation, { _, conversation -> conversation })
.autoDisposable(view.scope())
.subscribe { conversation -> deleteConversations.execute(listOf(conversation.id)) }
}
}
@@ -0,0 +1,74 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package com.moez.QKSMS.feature.conversationinfo
import android.content.Context
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.moez.QKSMS.R
import com.moez.QKSMS.common.Navigator
import com.moez.QKSMS.common.base.QkRealmAdapter
import com.moez.QKSMS.common.base.QkViewHolder
import com.moez.QKSMS.common.util.GlideApp
import com.moez.QKSMS.common.util.extensions.setVisible
import com.moez.QKSMS.extensions.isImage
import com.moez.QKSMS.extensions.isVideo
import com.moez.QKSMS.model.MmsPart
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.subjects.PublishSubject
import kotlinx.android.synthetic.main.conversation_media_list_item.view.*
import javax.inject.Inject
class ConversationMediaAdapter @Inject constructor(
private val context: Context,
private val navigator: Navigator
) : QkRealmAdapter<MmsPart>() {
val thumbnailClicks: PublishSubject<View> = PublishSubject.create()
private val disposables = CompositeDisposable()
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QkViewHolder {
val view = LayoutInflater.from(parent.context).inflate(R.layout.conversation_media_list_item, parent, false)
return QkViewHolder(view)
}
override fun onBindViewHolder(holder: QkViewHolder, position: Int) {
val part = getItem(position)!!
val view = holder.itemView
GlideApp.with(context)
.load(part.getUri())
.fitCenter()
.into(view.thumbnail)
view.video.setVisible(part.isVideo())
view.thumbnail.transitionName = part.id.toString()
view.thumbnail.setOnClickListener {
if (part.isImage()) thumbnailClicks.onNext(it) else navigator.showMedia(part.id)
}
}
override fun onDetachedFromRecyclerView(recyclerView: RecyclerView) {
disposables.clear()
}
}
@@ -0,0 +1,76 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package com.moez.QKSMS.feature.conversationinfo
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.ViewGroup
import com.moez.QKSMS.R
import com.moez.QKSMS.common.Navigator
import com.moez.QKSMS.common.base.QkRealmAdapter
import com.moez.QKSMS.common.base.QkViewHolder
import com.moez.QKSMS.common.util.extensions.setVisible
import com.moez.QKSMS.model.Recipient
import io.reactivex.disposables.CompositeDisposable
import kotlinx.android.synthetic.main.conversation_recipient_list_item.view.*
import javax.inject.Inject
class ConversationRecipientAdapter @Inject constructor(
private val navigator: Navigator
) : QkRealmAdapter<Recipient>() {
var threadId: Long = 0L
private val disposables = CompositeDisposable()
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QkViewHolder {
val layoutInflater = LayoutInflater.from(parent.context)
val view = layoutInflater.inflate(R.layout.conversation_recipient_list_item, parent, false)
return QkViewHolder(view)
}
override fun onBindViewHolder(holder: QkViewHolder, position: Int) {
val recipient = getItem(position)!!
val view = holder.itemView
view.setOnClickListener {
if (recipient.contact == null) {
navigator.addContact(recipient.address)
} else {
view.avatar.callOnClick()
}
}
view.avatar.threadId = threadId
view.avatar.setContact(recipient)
view.name.text = recipient.contact?.name ?: recipient.address
view.address.text = recipient.address
view.address.setVisible(recipient.contact != null)
view.add.setVisible(recipient.contact == null)
}
override fun onDetachedFromRecyclerView(recyclerView: RecyclerView) {
super.onDetachedFromRecyclerView(recyclerView)
disposables.clear()
}
}
@@ -0,0 +1,47 @@
/*
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
*
* This file is part of QKSMS.
*
* QKSMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QKSMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
*/
package com.moez.QKSMS.feature.conversationinfo
import android.content.Context
import android.graphics.Rect
import android.support.v7.widget.RecyclerView
import android.view.View
import com.moez.QKSMS.common.util.extensions.dpToPx
import javax.inject.Inject
class GridSpacingItemDecoration @Inject constructor(context: Context) : RecyclerView.ItemDecoration() {
private val spanCount = 3
private val spacing = 2.dpToPx(context)
override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State) {
super.getItemOffsets(outRect, view, parent, state)
val position = parent.getChildAdapterPosition(view)
val column = position % spanCount
outRect.left = column * spacing / spanCount
outRect.right = spacing - (column + 1) * spacing / spanCount
if (position >= spanCount) {
outRect.top = spacing
}
}
}