forked from upstream-mirrors/quik
Move packages to com.moez.QKSMS
This commit is contained in:
@@ -0,0 +1,131 @@
|
||||
/*
|
||||
* 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.common.widget
|
||||
|
||||
import android.content.Context
|
||||
import android.net.Uri
|
||||
import android.provider.ContactsContract
|
||||
import android.telephony.PhoneNumberUtils
|
||||
import android.util.AttributeSet
|
||||
import android.view.View
|
||||
import android.widget.FrameLayout
|
||||
import com.moez.QKSMS.R
|
||||
import com.moez.QKSMS.common.Navigator
|
||||
import com.moez.QKSMS.common.util.Colors
|
||||
import com.moez.QKSMS.common.util.GlideApp
|
||||
import com.moez.QKSMS.common.util.extensions.setBackgroundTint
|
||||
import com.moez.QKSMS.common.util.extensions.setTint
|
||||
import com.moez.QKSMS.injection.appComponent
|
||||
import com.moez.QKSMS.model.Contact
|
||||
import com.moez.QKSMS.model.Recipient
|
||||
import kotlinx.android.synthetic.main.avatar_view.view.*
|
||||
import javax.inject.Inject
|
||||
|
||||
class AvatarView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : FrameLayout(context, attrs) {
|
||||
|
||||
@Inject lateinit var colors: Colors
|
||||
@Inject lateinit var navigator: Navigator
|
||||
|
||||
/**
|
||||
* This value can be changes if we should use the theme from a particular conversation
|
||||
*/
|
||||
var threadId: Long = 0
|
||||
set(value) {
|
||||
if (field == value) return
|
||||
field = value
|
||||
applyTheme(value)
|
||||
}
|
||||
|
||||
private var lookupKey: String? = null
|
||||
private var name: String? = null
|
||||
private var address: String? = null
|
||||
|
||||
init {
|
||||
if (!isInEditMode) {
|
||||
appComponent.inject(this)
|
||||
}
|
||||
|
||||
View.inflate(context, R.layout.avatar_view, this)
|
||||
|
||||
setBackgroundResource(R.drawable.circle)
|
||||
clipToOutline = true
|
||||
|
||||
setOnClickListener {
|
||||
if (lookupKey.isNullOrEmpty()) {
|
||||
address?.let { address -> navigator.addContact(address) }
|
||||
} else {
|
||||
val uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_LOOKUP_URI, lookupKey)
|
||||
ContactsContract.QuickContact.showQuickContact(context, this@AvatarView, uri,
|
||||
ContactsContract.QuickContact.MODE_MEDIUM, null)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun setContact(recipient: Recipient?) {
|
||||
// If the recipient has a contact, just use that and return
|
||||
recipient?.contact?.let { contact ->
|
||||
setContact(contact)
|
||||
return
|
||||
}
|
||||
|
||||
lookupKey = null
|
||||
name = null
|
||||
address = recipient?.address
|
||||
updateView()
|
||||
}
|
||||
|
||||
fun setContact(contact: Contact?) {
|
||||
lookupKey = contact?.lookupKey
|
||||
name = contact?.name
|
||||
address = contact?.numbers?.firstOrNull()?.address
|
||||
updateView()
|
||||
}
|
||||
|
||||
override fun onFinishInflate() {
|
||||
super.onFinishInflate()
|
||||
|
||||
if (!isInEditMode) {
|
||||
applyTheme(threadId)
|
||||
updateView()
|
||||
}
|
||||
}
|
||||
|
||||
fun applyTheme(threadId: Long) {
|
||||
colors.theme(threadId).run {
|
||||
setBackgroundTint(theme)
|
||||
initial.setTextColor(textPrimary)
|
||||
icon.setTint(textPrimary)
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateView() {
|
||||
if (name?.isNotEmpty() == true) {
|
||||
initial.text = name?.substring(0, 1)
|
||||
icon.visibility = GONE
|
||||
} else {
|
||||
initial.text = null
|
||||
icon.visibility = VISIBLE
|
||||
}
|
||||
|
||||
photo.setImageDrawable(null)
|
||||
address?.let { address ->
|
||||
GlideApp.with(photo).load(PhoneNumberUtils.stripSeparators(address)).into(photo)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
* 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.common.widget
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.Path
|
||||
import android.graphics.RectF
|
||||
import android.util.AttributeSet
|
||||
import android.widget.ImageView
|
||||
import com.moez.QKSMS.common.util.extensions.dpToPx
|
||||
|
||||
class BubbleImageView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : ImageView(context, attrs) {
|
||||
|
||||
enum class Style(val topLeft: Boolean, val topRight: Boolean, val bottomRight: Boolean, val bottomLeft: Boolean) {
|
||||
|
||||
ONLY(true, true, true, true),
|
||||
IN_FIRST(true, true, true, false),
|
||||
IN_MIDDLE(false, true, true, false),
|
||||
IN_LAST(false, true, true, true),
|
||||
OUT_FIRST(true, true, false, true),
|
||||
OUT_MIDDLE(true, false, false, true),
|
||||
OUT_LAST(true, false, true, true)
|
||||
}
|
||||
|
||||
var bubbleStyle = Style.ONLY
|
||||
set(value) {
|
||||
field = value
|
||||
setPath()
|
||||
invalidate()
|
||||
}
|
||||
|
||||
private val path = Path()
|
||||
private val radiusSmall = 4.dpToPx(context).toFloat()
|
||||
private val radiusLarge = 18.dpToPx(context).toFloat()
|
||||
|
||||
override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
|
||||
super.onSizeChanged(w, h, oldw, oldh)
|
||||
setPath()
|
||||
}
|
||||
|
||||
override fun onDraw(canvas: Canvas) {
|
||||
if (!path.isEmpty) {
|
||||
canvas.clipPath(path)
|
||||
}
|
||||
|
||||
super.onDraw(canvas)
|
||||
}
|
||||
|
||||
private fun setPath() {
|
||||
path.rewind()
|
||||
|
||||
val width = width.toFloat()
|
||||
val height = height.toFloat()
|
||||
|
||||
val cornerRectSmall = RectF().apply { set(-radiusSmall, -radiusSmall, radiusSmall, radiusSmall) }
|
||||
val cornerRectLarge = RectF().apply { set(-radiusLarge, -radiusLarge, radiusLarge, radiusLarge) }
|
||||
|
||||
if (bubbleStyle.topLeft) {
|
||||
cornerRectLarge.offsetTo(0f, 0f)
|
||||
path.arcTo(cornerRectLarge, 180f, 90f)
|
||||
} else {
|
||||
cornerRectSmall.offsetTo(0f, 0f)
|
||||
path.arcTo(cornerRectSmall, 180f, 90f)
|
||||
}
|
||||
|
||||
if (bubbleStyle.topRight) {
|
||||
cornerRectLarge.offsetTo(width - radiusLarge * 2, 0f)
|
||||
path.arcTo(cornerRectLarge, 270f, 90f)
|
||||
} else {
|
||||
cornerRectSmall.offsetTo(width - radiusSmall * 2, 0f)
|
||||
path.arcTo(cornerRectSmall, 270f, 90f)
|
||||
}
|
||||
|
||||
if (bubbleStyle.bottomRight) {
|
||||
cornerRectLarge.offsetTo(width - radiusLarge * 2, height - radiusLarge * 2)
|
||||
path.arcTo(cornerRectLarge, 0f, 90f)
|
||||
} else {
|
||||
cornerRectSmall.offsetTo(width - radiusSmall * 2, height - radiusSmall * 2)
|
||||
path.arcTo(cornerRectSmall, 0f, 90f)
|
||||
}
|
||||
|
||||
if (bubbleStyle.bottomLeft) {
|
||||
cornerRectLarge.offsetTo(0f, height - radiusLarge * 2)
|
||||
path.arcTo(cornerRectLarge, 90f, 90f)
|
||||
} else {
|
||||
cornerRectSmall.offsetTo(0f, height - radiusSmall * 2)
|
||||
path.arcTo(cornerRectSmall, 90f, 90f)
|
||||
}
|
||||
|
||||
path.close()
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* 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.common.widget
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Build
|
||||
import android.support.constraint.ConstraintLayout
|
||||
import android.util.AttributeSet
|
||||
import android.view.View
|
||||
import com.moez.QKSMS.R
|
||||
import com.moez.QKSMS.model.Recipient
|
||||
import kotlinx.android.synthetic.main.group_avatar_view.view.*
|
||||
|
||||
class GroupAvatarView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : ConstraintLayout(context, attrs) {
|
||||
|
||||
var contacts: List<Recipient> = ArrayList()
|
||||
set(value) {
|
||||
field = value
|
||||
updateView()
|
||||
}
|
||||
|
||||
private val avatars by lazy { listOf(avatar1, avatar2, avatar3) }
|
||||
|
||||
init {
|
||||
View.inflate(context, R.layout.group_avatar_view, this)
|
||||
setBackgroundResource(R.drawable.circle)
|
||||
clipToOutline = true
|
||||
}
|
||||
|
||||
override fun onFinishInflate() {
|
||||
super.onFinishInflate()
|
||||
|
||||
avatars.forEach { avatar ->
|
||||
avatar.setBackgroundResource(R.drawable.rectangle)
|
||||
|
||||
// If we're on API 21 we need to reapply the tint after changing the background
|
||||
if (Build.VERSION.SDK_INT < 22) {
|
||||
avatar.applyTheme(0)
|
||||
}
|
||||
}
|
||||
|
||||
if (!isInEditMode) {
|
||||
updateView()
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateView() {
|
||||
avatars.forEachIndexed { index, avatar ->
|
||||
avatar.visibility = if (contacts.size > index) View.VISIBLE else View.GONE
|
||||
avatar.setContact(contacts.getOrNull(index))
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* 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.common.widget
|
||||
|
||||
import android.content.Context
|
||||
import android.content.res.ColorStateList
|
||||
import android.support.v4.view.ViewPager
|
||||
import android.util.AttributeSet
|
||||
import android.view.LayoutInflater
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.TextView
|
||||
import com.moez.QKSMS.R
|
||||
import com.moez.QKSMS.common.util.Colors
|
||||
import com.moez.QKSMS.common.util.extensions.forEach
|
||||
import com.moez.QKSMS.common.util.extensions.resolveThemeColor
|
||||
import com.moez.QKSMS.injection.appComponent
|
||||
import com.uber.autodispose.android.scope
|
||||
import com.uber.autodispose.kotlin.autoDisposable
|
||||
import io.reactivex.subjects.BehaviorSubject
|
||||
import io.reactivex.subjects.Subject
|
||||
import kotlinx.android.synthetic.main.tab_view.view.*
|
||||
import javax.inject.Inject
|
||||
|
||||
class PagerTitleView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : LinearLayout(context, attrs) {
|
||||
|
||||
@Inject lateinit var colors: Colors
|
||||
|
||||
private val threadId: Subject<Long> = BehaviorSubject.create()
|
||||
|
||||
var pager: ViewPager? = null
|
||||
set(value) {
|
||||
if (field !== value) {
|
||||
field = value
|
||||
recreate()
|
||||
}
|
||||
}
|
||||
|
||||
init {
|
||||
if (!isInEditMode) appComponent.inject(this)
|
||||
}
|
||||
|
||||
fun setThreadId(id: Long) {
|
||||
threadId.onNext(id)
|
||||
}
|
||||
|
||||
private fun recreate() {
|
||||
removeAllViews()
|
||||
|
||||
pager?.adapter?.count?.forEach { position ->
|
||||
val view = LayoutInflater.from(context).inflate(R.layout.tab_view, this, false)
|
||||
view.label.text = pager?.adapter?.getPageTitle(position)
|
||||
view.setOnClickListener { pager?.currentItem = position }
|
||||
|
||||
addView(view)
|
||||
}
|
||||
|
||||
childCount.forEach { index ->
|
||||
getChildAt(index).isSelected = index == pager?.currentItem
|
||||
}
|
||||
|
||||
pager?.addOnPageChangeListener(object : ViewPager.SimpleOnPageChangeListener() {
|
||||
override fun onPageSelected(position: Int) {
|
||||
childCount.forEach { index ->
|
||||
getChildAt(index).isSelected = index == position
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
override fun onAttachedToWindow() {
|
||||
super.onAttachedToWindow()
|
||||
|
||||
val states = arrayOf(
|
||||
intArrayOf(android.R.attr.state_selected),
|
||||
intArrayOf(-android.R.attr.state_selected))
|
||||
|
||||
threadId
|
||||
.distinctUntilChanged()
|
||||
.switchMap { threadId -> colors.themeObservable(threadId) }
|
||||
.map { theme ->
|
||||
val textSecondary = context.resolveThemeColor(android.R.attr.textColorSecondary)
|
||||
ColorStateList(states, intArrayOf(theme.theme, textSecondary))
|
||||
}
|
||||
.autoDisposable(scope())
|
||||
.subscribe { colorStateList ->
|
||||
childCount.forEach { index ->
|
||||
(getChildAt(index) as? TextView)?.setTextColor(colorStateList)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* 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.common.widget
|
||||
|
||||
import android.content.Context
|
||||
import android.support.v7.widget.LinearLayoutCompat
|
||||
import android.util.AttributeSet
|
||||
import android.view.Gravity
|
||||
import android.view.View
|
||||
import android.widget.TextView
|
||||
import com.moez.QKSMS.R
|
||||
import com.moez.QKSMS.common.util.extensions.resolveThemeAttribute
|
||||
import com.moez.QKSMS.common.util.extensions.resolveThemeColor
|
||||
import com.moez.QKSMS.common.util.extensions.setTint
|
||||
import com.moez.QKSMS.common.util.extensions.setVisible
|
||||
import com.moez.QKSMS.injection.appComponent
|
||||
import kotlinx.android.synthetic.main.preference_view.view.*
|
||||
|
||||
class PreferenceView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : LinearLayoutCompat(context, attrs) {
|
||||
|
||||
var title: String? = null
|
||||
set(value) {
|
||||
field = value
|
||||
|
||||
if (isInEditMode) {
|
||||
findViewById<TextView>(R.id.titleView).text = value
|
||||
} else {
|
||||
titleView.text = value
|
||||
}
|
||||
}
|
||||
|
||||
var summary: String? = null
|
||||
set(value) {
|
||||
field = value
|
||||
|
||||
|
||||
if (isInEditMode) {
|
||||
findViewById<TextView>(R.id.summaryView).run {
|
||||
text = value
|
||||
setVisible(value?.isNotEmpty() == true)
|
||||
}
|
||||
} else {
|
||||
summaryView.text = value
|
||||
summaryView.setVisible(value?.isNotEmpty() == true)
|
||||
}
|
||||
}
|
||||
|
||||
init {
|
||||
if (!isInEditMode) {
|
||||
appComponent.inject(this)
|
||||
}
|
||||
|
||||
View.inflate(context, R.layout.preference_view, this)
|
||||
setBackgroundResource(context.resolveThemeAttribute(R.attr.selectableItemBackground))
|
||||
orientation = HORIZONTAL
|
||||
gravity = Gravity.CENTER_VERTICAL
|
||||
|
||||
val textSecondary = context.resolveThemeColor(android.R.attr.textColorSecondary)
|
||||
icon.setTint(textSecondary)
|
||||
|
||||
context.obtainStyledAttributes(attrs, R.styleable.PreferenceView)?.run {
|
||||
title = getString(R.styleable.PreferenceView_title)
|
||||
summary = getString(R.styleable.PreferenceView_summary)
|
||||
|
||||
// If there's a custom view used for the preference's widget, inflate it
|
||||
getResourceId(R.styleable.PreferenceView_widget, -1).takeIf { it != -1 }?.let { id ->
|
||||
View.inflate(context, id, widgetFrame)
|
||||
}
|
||||
|
||||
// If an icon is being used, set up the icon view
|
||||
getResourceId(R.styleable.PreferenceView_icon, -1).takeIf { it != -1 }?.let { id ->
|
||||
icon.setVisible(true)
|
||||
icon.setImageResource(id)
|
||||
}
|
||||
|
||||
recycle()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* 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.common.widget
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Build
|
||||
import android.support.v13.view.inputmethod.EditorInfoCompat
|
||||
import android.support.v13.view.inputmethod.InputConnectionCompat
|
||||
import android.support.v13.view.inputmethod.InputContentInfoCompat
|
||||
import android.util.AttributeSet
|
||||
import android.view.KeyEvent
|
||||
import android.view.inputmethod.EditorInfo
|
||||
import android.view.inputmethod.InputConnection
|
||||
import android.view.inputmethod.InputConnectionWrapper
|
||||
import android.widget.EditText
|
||||
import com.google.android.mms.ContentType
|
||||
import com.moez.QKSMS.common.util.TextViewStyler
|
||||
import com.moez.QKSMS.injection.appComponent
|
||||
import com.moez.QKSMS.util.tryOrNull
|
||||
import io.reactivex.subjects.PublishSubject
|
||||
import io.reactivex.subjects.Subject
|
||||
import javax.inject.Inject
|
||||
|
||||
|
||||
/**
|
||||
* Custom implementation of EditText to allow for dynamic text colors
|
||||
*
|
||||
* Beware of updating to extend AppCompatTextView, as this inexplicably breaks the view in
|
||||
* the contacts chip view
|
||||
*/
|
||||
class QkEditText @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : EditText(context, attrs) {
|
||||
|
||||
@Inject lateinit var textViewStyler: TextViewStyler
|
||||
|
||||
val backspaces: Subject<Unit> = PublishSubject.create()
|
||||
val inputContentSelected: Subject<InputContentInfoCompat> = PublishSubject.create()
|
||||
var supportsInputContent: Boolean = false
|
||||
|
||||
init {
|
||||
if (!isInEditMode) {
|
||||
appComponent.inject(this)
|
||||
textViewStyler.applyAttributes(this, attrs)
|
||||
} else {
|
||||
TextViewStyler.applyEditModeAttributes(this, attrs)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateInputConnection(editorInfo: EditorInfo): InputConnection {
|
||||
|
||||
val inputConnection = object : InputConnectionWrapper(super.onCreateInputConnection(editorInfo), true) {
|
||||
override fun sendKeyEvent(event: KeyEvent): Boolean {
|
||||
if (event.action == KeyEvent.ACTION_DOWN && event.keyCode == KeyEvent.KEYCODE_DEL) {
|
||||
backspaces.onNext(Unit)
|
||||
}
|
||||
return super.sendKeyEvent(event)
|
||||
}
|
||||
|
||||
|
||||
override fun deleteSurroundingText(beforeLength: Int, afterLength: Int): Boolean {
|
||||
if (beforeLength == 1 && afterLength == 0) {
|
||||
backspaces.onNext(Unit)
|
||||
}
|
||||
return super.deleteSurroundingText(beforeLength, afterLength)
|
||||
}
|
||||
}
|
||||
|
||||
if (supportsInputContent) {
|
||||
EditorInfoCompat.setContentMimeTypes(editorInfo, arrayOf(
|
||||
ContentType.IMAGE_JPEG,
|
||||
ContentType.IMAGE_JPG,
|
||||
ContentType.IMAGE_PNG,
|
||||
ContentType.IMAGE_GIF))
|
||||
}
|
||||
|
||||
val callback = InputConnectionCompat.OnCommitContentListener { inputContentInfo, flags, opts ->
|
||||
val grantReadPermission = flags and InputConnectionCompat.INPUT_CONTENT_GRANT_READ_URI_PERMISSION != 0
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1 && grantReadPermission) {
|
||||
return@OnCommitContentListener tryOrNull {
|
||||
inputContentInfo.requestPermission()
|
||||
inputContentSelected.onNext(inputContentInfo)
|
||||
true
|
||||
} ?: false
|
||||
|
||||
}
|
||||
|
||||
true
|
||||
}
|
||||
|
||||
return InputConnectionCompat.createWrapper(inputConnection, editorInfo, callback)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* 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.common.widget
|
||||
|
||||
import android.content.Context
|
||||
import android.content.res.ColorStateList
|
||||
import android.support.v7.widget.SwitchCompat
|
||||
import android.util.AttributeSet
|
||||
import com.moez.QKSMS.R
|
||||
import com.moez.QKSMS.common.util.Colors
|
||||
import com.moez.QKSMS.common.util.extensions.getColorCompat
|
||||
import com.moez.QKSMS.common.util.extensions.withAlpha
|
||||
import com.moez.QKSMS.injection.appComponent
|
||||
import com.moez.QKSMS.util.Preferences
|
||||
import javax.inject.Inject
|
||||
|
||||
class QkSwitch @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : SwitchCompat(context, attrs) {
|
||||
|
||||
@Inject lateinit var colors: Colors
|
||||
@Inject lateinit var prefs: Preferences
|
||||
|
||||
init {
|
||||
if (!isInEditMode) {
|
||||
appComponent.inject(this)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onAttachedToWindow() {
|
||||
super.onAttachedToWindow()
|
||||
|
||||
if (!isInEditMode) {
|
||||
val states = arrayOf(
|
||||
intArrayOf(-android.R.attr.state_enabled),
|
||||
intArrayOf(android.R.attr.state_checked),
|
||||
intArrayOf())
|
||||
|
||||
val themeColor = colors.theme().theme
|
||||
|
||||
val switchThumbEnabled: Int = prefs.night.get()
|
||||
.let { night -> if (night) R.color.switchThumbEnabledDark else R.color.switchThumbEnabledLight }
|
||||
.let { res -> context.getColorCompat(res) }
|
||||
|
||||
val switchThumbDisabled: Int = prefs.night.get()
|
||||
.let { night -> if (night) R.color.switchThumbDisabledDark else R.color.switchThumbDisabledLight }
|
||||
.let { res -> context.getColorCompat(res) }
|
||||
|
||||
val switchTrackEnabled: Int = prefs.night.get()
|
||||
.let { night -> if (night) R.color.switchTrackEnabledDark else R.color.switchTrackEnabledLight }
|
||||
.let { res -> context.getColorCompat(res) }
|
||||
|
||||
val switchTrackDisabled: Int = prefs.night.get()
|
||||
.let { night -> if (night) R.color.switchTrackDisabledDark else R.color.switchTrackDisabledLight }
|
||||
.let { res -> context.getColorCompat(res) }
|
||||
|
||||
thumbTintList = ColorStateList(states, intArrayOf(switchThumbDisabled, themeColor, switchThumbEnabled))
|
||||
trackTintList = ColorStateList(states, intArrayOf(switchTrackDisabled, themeColor.withAlpha(0x4D), switchTrackEnabled))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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.common.widget
|
||||
|
||||
import android.content.Context
|
||||
import android.support.text.emoji.widget.EmojiAppCompatTextView
|
||||
import android.util.AttributeSet
|
||||
import com.moez.QKSMS.common.util.TextViewStyler
|
||||
import com.moez.QKSMS.injection.appComponent
|
||||
import javax.inject.Inject
|
||||
|
||||
open class QkTextView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null)
|
||||
: EmojiAppCompatTextView(context, attrs) {
|
||||
|
||||
@Inject lateinit var textViewStyler: TextViewStyler
|
||||
|
||||
init {
|
||||
if (!isInEditMode) {
|
||||
appComponent.inject(this)
|
||||
textViewStyler.applyAttributes(this, attrs)
|
||||
} else {
|
||||
TextViewStyler.applyEditModeAttributes(this, attrs)
|
||||
}
|
||||
}
|
||||
|
||||
override fun setTextColor(color: Int) {
|
||||
super.setTextColor(color)
|
||||
setLinkTextColor(color)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* 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.common.widget
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.widget.ImageView
|
||||
|
||||
class SquareImageView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : ImageView(context, attrs) {
|
||||
|
||||
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
|
||||
super.onMeasure(widthMeasureSpec, widthMeasureSpec)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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.common.widget
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
|
||||
class TightTextView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : QkTextView(context, attrs) {
|
||||
|
||||
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec)
|
||||
|
||||
layout?.let {
|
||||
val maxLineWidth = (0 until layout.lineCount)
|
||||
.asSequence()
|
||||
.map { layout.getLineMax(it) }
|
||||
.max() ?: 0f
|
||||
|
||||
val width = (Math.ceil(maxLineWidth.toDouble()).toInt() + compoundPaddingLeft + compoundPaddingRight)
|
||||
val height = measuredHeight
|
||||
setMeasuredDimension(width, height)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user