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,86 @@
/*
* 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.conversations
import android.content.Context
import android.graphics.Bitmap
import android.graphics.Canvas
import android.graphics.Paint
import android.support.v7.widget.RecyclerView
import android.support.v7.widget.helper.ItemTouchHelper
import androidx.graphics.drawable.toBitmap
import com.moez.QKSMS.R
import com.moez.QKSMS.common.util.extensions.dpToPx
import io.reactivex.subjects.PublishSubject
import io.reactivex.subjects.Subject
import javax.inject.Inject
class ConversationItemTouchCallback @Inject constructor(private val context: Context) : ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT or ItemTouchHelper.RIGHT) {
val swipes: Subject<Long> = PublishSubject.create()
private var paint = Paint()
private lateinit var icon: Bitmap
private var iconLength = 24.dpToPx(context)
var color: Int = 0
set(value) {
field = value
paint.color = value
}
var iconColor: Int = 0
set(value) {
field = value
icon = context.resources.getDrawable(R.drawable.ic_archive_black_24dp)
.apply { setTint(value) }
.toBitmap(iconLength, iconLength)
}
override fun onMove(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder, target: RecyclerView.ViewHolder): Boolean {
return false
}
override fun onChildDraw(c: Canvas, recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder, dX: Float, dY: Float, actionState: Int, isCurrentlyActive: Boolean) {
if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE) {
val itemView = viewHolder.itemView
if (dX > 0) {
c.drawRect(itemView.left.toFloat(), itemView.top.toFloat(), dX, itemView.bottom.toFloat(), paint)
c.drawBitmap(icon, itemView.left.toFloat() + iconLength,
itemView.top.toFloat() + (itemView.bottom.toFloat() - itemView.top.toFloat() - icon.height) / 2,
paint)
} else if (dX < 0) {
c.drawRect(itemView.right.toFloat() + dX, itemView.top.toFloat(), itemView.right.toFloat(), itemView.bottom.toFloat(), paint)
c.drawBitmap(icon, itemView.right.toFloat() - iconLength - icon.width,
itemView.top.toFloat() + (itemView.bottom.toFloat() - itemView.top.toFloat() - icon.height) / 2,
paint)
}
super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive)
}
}
override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) {
swipes.onNext(viewHolder.itemId)
}
}
@@ -0,0 +1,99 @@
/*
* 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.conversations
import android.content.Context
import android.graphics.Typeface
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.DateFormatter
import com.moez.QKSMS.common.util.extensions.resolveThemeColor
import com.moez.QKSMS.model.Conversation
import kotlinx.android.synthetic.main.conversation_list_item.view.*
import javax.inject.Inject
class ConversationsAdapter @Inject constructor(
private val context: Context,
private val dateFormatter: DateFormatter,
private val navigator: Navigator
) : QkRealmAdapter<Conversation>() {
init {
setHasStableIds(true)
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QkViewHolder {
val layoutInflater = LayoutInflater.from(parent.context)
val view = layoutInflater.inflate(R.layout.conversation_list_item, parent, false)
if (viewType == 1) {
val textColorPrimary = parent.context.resolveThemeColor(android.R.attr.textColorPrimary)
view.title.setTypeface(view.title.typeface, Typeface.BOLD)
view.snippet.setTypeface(view.snippet.typeface, Typeface.BOLD)
view.snippet.setTextColor(textColorPrimary)
view.snippet.maxLines = 5
view.date.setTypeface(view.date.typeface, Typeface.BOLD)
view.date.setTextColor(textColorPrimary)
}
return QkViewHolder(view)
}
override fun onBindViewHolder(viewHolder: QkViewHolder, position: Int) {
val conversation = getItem(position)!!
val view = viewHolder.itemView
view.setOnClickListener {
when (toggleSelection(conversation.id, false)) {
true -> view.isSelected = isSelected(conversation.id)
false -> navigator.showConversation(conversation.id)
}
}
view.setOnLongClickListener {
toggleSelection(conversation.id)
view.isSelected = isSelected(conversation.id)
true
}
view.isSelected = isSelected(conversation.id)
view.avatars.contacts = conversation.recipients
view.title.text = conversation.getTitle()
view.date.text = dateFormatter.getConversationTimestamp(conversation.date)
view.snippet.text = when (conversation.me) {
true -> context.getString(R.string.main_sender_you, conversation.snippet)
false -> conversation.snippet
}
}
override fun getItemId(index: Int): Long {
return getItem(index)!!.id
}
override fun getItemViewType(position: Int): Int {
return if (getItem(position)!!.read) 0 else 1
}
}