Skip to content

Commit

Permalink
Merge pull request #404 from Chooloo/staging
Browse files Browse the repository at this point in the history
Staging
  • Loading branch information
roeiedri authored Apr 8, 2022
2 parents 30781aa + b9379d9 commit 3285544
Show file tree
Hide file tree
Showing 20 changed files with 104 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class PhonesAdapter @Inject constructor(
imageVisibility = false
titleText = item.number
isRightButtonVisible = true
captionText = strings.getString(Phone.getTypeLabelResource(item.type))
captionText = Phone.getTypeLabel(resources, item.type, item.label).toString()

setTitleBold(true)
setBackground(null)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.chooloo.www.chooloolib.adapter

import android.graphics.Color
import android.net.Uri
import android.provider.ContactsContract.CommonDataKinds.Phone
import com.chooloo.www.chooloolib.interactor.animation.AnimationsInteractor
import com.chooloo.www.chooloolib.interactor.phoneaccounts.PhonesInteractor
Expand All @@ -11,6 +12,7 @@ import com.chooloo.www.chooloolib.model.ListData
import com.chooloo.www.chooloolib.model.RecentAccount
import com.chooloo.www.chooloolib.ui.widgets.listitem.ListItem
import com.chooloo.www.chooloolib.util.getHoursString
import com.chooloo.www.chooloolib.util.initials
import javax.inject.Inject

class RecentsAdapter @Inject constructor(
Expand All @@ -28,14 +30,15 @@ class RecentsAdapter @Inject constructor(
phones.lookupAccount(item.number) {
titleText = it?.name ?: item.number
it?.let {
captionText = "$captionText · ${
strings.getString(Phone.getTypeLabelResource(it.type))
}"
captionText =
"$captionText · ${Phone.getTypeLabel(resources, it.type, it.label)} ·"
setImageInitials(it.name?.initials())
setImageUri(if (it.photoUri != null) Uri.parse(it.photoUri) else null)
}
}

setImageBackgroundColor(Color.TRANSPARENT)
setImageResource(recents.getCallTypeImage(item.type))
setCaptionImageRes(recents.getCallTypeImage(item.type))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class PhoneLookupContentResolver(context: Context, number: String?) :
override val uri: Uri = PhoneLookup.CONTENT_FILTER_URI.buildUpon().appendPath(number).build()
override val projection: Array<String> = arrayOf(
PhoneLookup.TYPE,
PhoneLookup.LABEL,
PhoneLookup.NUMBER,
PhoneLookup.STARRED,
PhoneLookup.PHOTO_URI,
Expand All @@ -26,6 +27,7 @@ class PhoneLookupContentResolver(context: Context, number: String?) :

@SuppressLint("Range")
override fun convertCursorToItem(cursor: Cursor) = PhoneLookupAccount(
label = cursor.getString(cursor.getColumnIndex(PhoneLookup.LABEL)),
number = cursor.getString(cursor.getColumnIndex(PhoneLookup.NUMBER)),
name = cursor.getString(cursor.getColumnIndex(PhoneLookup.DISPLAY_NAME)),
contactId = cursor.getLong(cursor.getColumnIndex(PhoneLookup.CONTACT_ID)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class PhonesContentResolver(context: Context, contactId: Long? = null) :
override val selection = SelectionBuilder().addSelection(Phone.CONTACT_ID, contactId).build()
override val projection: Array<String> = arrayOf(
Phone.TYPE,
Phone.LABEL,
Phone.NUMBER,
Phone.CONTACT_ID,
Phone.NORMALIZED_NUMBER,
Expand All @@ -27,6 +28,7 @@ class PhonesContentResolver(context: Context, contactId: Long? = null) :
@SuppressLint("Range")
override fun convertCursorToItem(cursor: Cursor) = PhoneAccount(
type = cursor.getInt(cursor.getColumnIndex(Phone.TYPE)),
label = cursor.getString(cursor.getColumnIndex(Phone.LABEL)),
number = cursor.getString(cursor.getColumnIndex(Phone.NUMBER)),
contactId = cursor.getLong(cursor.getColumnIndex(Phone.CONTACT_ID)),
displayName = cursor.getString(cursor.getColumnIndex(Phone.DISPLAY_NAME_PRIMARY)),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.chooloo.www.chooloolib.interactor.color

import android.content.Context
import android.content.res.Configuration
import android.util.TypedValue
import androidx.appcompat.app.AppCompatDelegate
import androidx.core.content.ContextCompat
import com.chooloo.www.chooloolib.util.baseobservable.BaseObservable
import dagger.hilt.android.qualifiers.ApplicationContext
Expand All @@ -13,7 +15,18 @@ class ColorsInteractorImpl @Inject constructor(
@ApplicationContext private val context: Context
) : BaseObservable<ColorsInteractor.Listener>(), ColorsInteractor {

override fun getColor(colorRes: Int) = ContextCompat.getColor(context, colorRes)
private fun getThemedContext(): Context {
val configuration = Configuration(context.resources.configuration)
configuration.uiMode = when (AppCompatDelegate.getDefaultNightMode()) {
AppCompatDelegate.MODE_NIGHT_NO -> Configuration.UI_MODE_NIGHT_NO
AppCompatDelegate.MODE_NIGHT_YES -> Configuration.UI_MODE_NIGHT_YES
else -> configuration.uiMode
}
return context.createConfigurationContext(configuration)
}

override fun getColor(colorRes: Int) = ContextCompat.getColor(getThemedContext(), colorRes)

override fun getAttrColor(colorRes: Int) =
TypedValue().also { context.theme.resolveAttribute(colorRes, it, true) }.data
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ data class PhoneAccount(
val number: String,
val contactId: Long,
val displayName: String,
val label: String? = null,
val normalizedNumber: String?,
val type: Int = Phone.TYPE_OTHER
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.provider.ContactsContract.CommonDataKinds.Phone

data class PhoneLookupAccount(
val name: String?,
val label: String? = null,
val number: String? = null,
val contactId: Long? = null,
val photoUri: String? = null,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.chooloo.www.chooloolib.ui.dialer

import android.content.ClipboardManager
import androidx.lifecycle.MutableLiveData
import com.chooloo.www.chooloolib.interactor.audio.AudiosInteractor
import com.chooloo.www.chooloolib.interactor.navigation.NavigationsInteractor
Expand All @@ -17,9 +18,10 @@ class DialerViewState @Inject constructor(
audios: AudiosInteractor,
preferences: PreferencesInteractor,
private val recents: RecentsInteractor,
private val clipboardManager: ClipboardManager,
private val navigations: NavigationsInteractor
) :
DialpadViewState(audios, preferences) {
DialpadViewState(audios, clipboardManager, preferences) {

val callVoicemailEvent = LiveEvent()
val callNumberEvent = DataLiveEvent<String>()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.chooloo.www.chooloolib.ui.dialpad

import android.content.ClipboardManager
import android.content.Context
import android.view.View
import androidx.core.view.isVisible
import androidx.fragment.app.activityViewModels
Expand Down Expand Up @@ -77,9 +75,6 @@ open class DialpadFragment @Inject constructor() : BaseFragment<DialpadViewState
}

override fun onPaste() {
val clipboard = activity?.getSystemService(Context.CLIPBOARD_SERVICE) as? ClipboardManager
val item = clipboard?.primaryClip?.getItemAt(0)
val text = item?.text.toString().replace(Regex("[^+#*0-9]"), "")
viewState.onTextPasted(text)
viewState.onTextPasted()
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.chooloo.www.chooloolib.ui.dialpad

import android.content.ClipboardManager
import androidx.lifecycle.MutableLiveData
import com.chooloo.www.chooloolib.interactor.audio.AudiosInteractor
import com.chooloo.www.chooloolib.interactor.preferences.PreferencesInteractor
Expand All @@ -10,6 +11,7 @@ import javax.inject.Inject
@HiltViewModel
open class DialpadViewState @Inject constructor(
private val audios: AudiosInteractor,
private val clipboardManager: ClipboardManager,
private val preferences: PreferencesInteractor
) :
BaseViewState() {
Expand All @@ -27,7 +29,9 @@ open class DialpadViewState @Inject constructor(

open fun onLongKeyClick(char: Char) = true

open fun onTextPasted(text: String) {
open fun onTextPasted() {
val item = clipboardManager.primaryClip?.getItemAt(0)
val text = item?.text.toString().replace(Regex("[^+#*0-9]"), "")
onTextChanged(text)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ class RecentFragment @Inject constructor() : BaseFragment<RecentViewState>() {

viewState.apply {
recentId.value = args.getLong(ARG_RECENT_ID)
image.observe(this@RecentFragment, binding.recentTypeImage::setImageDrawable)
imageUri.observe(this@RecentFragment, binding.recentContactImage::setImageURI)
typeImage.observe(this@RecentFragment, binding.recentTypeImage::setImageDrawable)

name.observe(this@RecentFragment) {
binding.recentTextName.text = it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.chooloo.www.chooloolib.ui.recent

import android.Manifest.permission.WRITE_CALL_LOG
import android.graphics.drawable.Drawable
import android.net.Uri
import androidx.lifecycle.MutableLiveData
import com.chooloo.www.chooloolib.R
import com.chooloo.www.chooloolib.interactor.blocked.BlockedInteractor
Expand Down Expand Up @@ -31,9 +32,10 @@ class RecentViewState @Inject constructor(
BaseViewState() {

val name = MutableLiveData<String?>()
val imageUri = MutableLiveData<Uri>()
val recentId = MutableLiveData(0L)
val image = MutableLiveData<Drawable?>()
val timeString = MutableLiveData<String?>()
val typeImage = MutableLiveData<Drawable?>()
val durationString = MutableLiveData<String?>()
val isContactVisible = MutableLiveData(false)
val isAddContactVisible = MutableLiveData(false)
Expand All @@ -56,12 +58,13 @@ class RecentViewState @Inject constructor(
timeString.value = _recent!!.relativeTime
durationString.value =
if (_recent!!.duration > 0L) getElapsedTimeString(_recent!!.duration) else null
image.value =
drawables.getDrawable(recents.getCallTypeImage(_recent!!.type))
name.value =
if (_recent!!.cachedName?.isNotEmpty() == true) _recent!!.cachedName else _recent!!.number
typeImage.value =
drawables.getDrawable(recents.getCallTypeImage(_recent!!.type))

phones.lookupAccount(_recent!!.number) {
it?.photoUri?.let { imageUri.value = Uri.parse(it) }
isContactVisible.value = it?.name != null
isAddContactVisible.value = it?.name == null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ class DialpadEditText : AppCompatEditText {
textAlignment = TEXT_ALIGNMENT_CENTER
inputType = InputType.TYPE_CLASS_PHONE
background = ContextCompat.getDrawable(context, R.drawable.round_outline)
backgroundTintList = ColorStateList.valueOf(context.getAttrColor(R.attr.colorSurface))
filters = arrayOf(InputFilter { source, _, _, _, _, _ ->
source.filter { char -> char.isDigit() || char in arrayOf('*', '#', '+') }
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ class DialpadKey : LinearLayout {
_lettersTextView = TextView(context, attrs, defStyleRes).apply {
layoutParams = LayoutParams(WRAP_CONTENT, WRAP_CONTENT)

setPadding(0, context.getSizeInDp(5), 0, 0)
setTextAppearance(R.style.Chooloo_Text_Caption)
setPadding(0, context.getSizeInDp(2), 0, 0)
typeface = ResourcesCompat.getFont(context, R.font.google_sans_medium)
}.also {
addView(it)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class SearchBar : TextInputLayout {

private val colorBackground by lazy { context.getAttrColor(R.attr.colorLightBackground) }
private val colorForeground by lazy { context.getAttrColor(R.attr.colorLightForeground) }
private val spacing by lazy { resources.getDimensionPixelSize(R.dimen.default_spacing) }
private val spacingSmall by lazy { resources.getDimensionPixelSize(R.dimen.default_spacing_small) }


Expand All @@ -50,18 +51,17 @@ class SearchBar : TextInputLayout {
hint = resources.getString(R.string.hint_search)
layoutParams = LayoutParams(MATCH_PARENT, WRAP_CONTENT)
compoundDrawableTintList = ColorStateList.valueOf(colorForeground)
filters =
arrayOf(InputFilter { source, _, _, _, _, _ ->
source.forEach { char ->
if (!(char.isLetterOrDigit() || char == ' ')) {
return@InputFilter ""
}
filters = arrayOf(InputFilter { source, _, _, _, _, _ ->
source.forEach { char ->
if (!(char.isLetterOrDigit() || char == ' ')) {
return@InputFilter ""
}
return@InputFilter null
})
}
return@InputFilter null
})

setTextAppearance(R.style.Chooloo_Text_Subtitle1)
setPadding(spacingSmall, 0, spacingSmall, 0)
setPadding(spacing, 0, spacingSmall, 0)
setHintTextColor(ColorStateList.valueOf(colorForeground))
setTextColor(context.getAttrColor(R.attr.colorOnSurface))

Expand All @@ -82,6 +82,7 @@ class SearchBar : TextInputLayout {
endIconDrawable = ContextCompat.getDrawable(context, R.drawable.round_close_24)
startIconDrawable = ContextCompat.getDrawable(context, R.drawable.round_search_24)

setPadding(spacingSmall, 0, 0, 0)
setEndIconTintList(ColorStateList.valueOf(colorForeground))
setStartIconTintList(ColorStateList.valueOf(colorForeground))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import android.util.AttributeSet
import android.view.View
import android.view.ViewGroup.LayoutParams.MATCH_PARENT
import android.view.ViewGroup.LayoutParams.WRAP_CONTENT
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import androidx.annotation.ColorInt
Expand Down Expand Up @@ -52,6 +53,7 @@ open class ListItem : LinearLayout {
protected val image: AvatarImageView
protected val buttonLeft: IconButton
protected val buttonRight: IconButton
protected val captionImage: ImageView
protected val personLayout: ConstraintLayout

protected val dimenSpacing by lazy { resources.getDimensionPixelSize(R.dimen.default_spacing) }
Expand Down Expand Up @@ -201,6 +203,13 @@ open class ListItem : LinearLayout {
setPadding(0, context.getSizeInDp(2), 0, 0)
}

captionImage = ImageView(context, attrs, defStyleRes).apply {
id = View.generateViewId()
layoutParams = ConstraintLayout.LayoutParams(WRAP_CONTENT, 0).apply {
setMargins(2, 0, 0, 0)
}
}

image = AvatarImageView(context, attrs).apply {
state = SHOW_INITIAL
id = generateViewId()
Expand Down Expand Up @@ -266,6 +275,7 @@ open class ListItem : LinearLayout {
addView(caption)
addView(buttonLeft)
addView(buttonRight)
addView(captionImage)
}

ConstraintSet().apply {
Expand All @@ -291,6 +301,12 @@ open class ListItem : LinearLayout {
connect(it, BOTTOM, PARENT_ID, BOTTOM)
}

captionImage.id.also {
connect(it, TOP, caption.id, TOP)
connect(it, START, caption.id, END)
connect(it, BOTTOM, caption.id, BOTTOM)
}

buttonRight.id.also {
connect(it, END, PARENT_ID, END)
connect(it, TOP, PARENT_ID, TOP)
Expand Down Expand Up @@ -421,10 +437,15 @@ open class ListItem : LinearLayout {
title.setTextColor(color)
}


fun setImageResource(@DrawableRes res: Int) {
image.setImageResource(res)
}

fun setCaptionImageRes(@DrawableRes res: Int) {
captionImage.setImageResource(res)
}

fun setTitleTextAppearance(@StyleRes resId: Int) {
title.setTextAppearance(resId)
}
Expand Down
3 changes: 2 additions & 1 deletion chooloolib/src/main/res/layout/dialpad.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/default_spacing_big"
android:layout_marginEnd="@dimen/default_spacing_big"
android:layout_marginBottom="@dimen/default_spacing_big"
android:layout_marginBottom="@dimen/default_spacing_small"
android:minWidth="200dp"
app:layout_constraintBottom_toTopOf="@id/dialpad_keys_layout"
app:layout_constraintEnd_toEndOf="parent"
Expand All @@ -38,6 +38,7 @@

<TableLayout
android:id="@+id/dialpad_keys_layout"
android:layoutDirection="ltr"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/default_spacing_big"
Expand Down
Loading

0 comments on commit 3285544

Please sign in to comment.