forked from upstream-mirrors/quik
Reduce number of errors in gradle build
This commit is contained in:
@@ -22,6 +22,7 @@ import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.graphics.Color
|
||||
import android.os.Build
|
||||
import android.support.annotation.ColorRes
|
||||
import android.view.View
|
||||
import com.moez.QKSMS.R
|
||||
import io.reactivex.Observable
|
||||
@@ -29,16 +30,16 @@ import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Singleton
|
||||
class Colors @Inject constructor(context: Context, prefs: Preferences) {
|
||||
class Colors @Inject constructor(private val context: Context, prefs: Preferences) {
|
||||
|
||||
companion object {
|
||||
private val MINIMUM_CONTRAST_RATIO = 2
|
||||
private const val MINIMUM_CONTRAST_RATIO = 2
|
||||
}
|
||||
|
||||
// Cache these values so they don't need to be recalculated
|
||||
private val primaryTextLuminance = measureLuminance(context.resources.getColor(R.color.textPrimaryDark))
|
||||
private val secondaryTextLuminance = measureLuminance(context.resources.getColor(R.color.textSecondaryDark))
|
||||
private val tertiaryTextLuminance = measureLuminance(context.resources.getColor(R.color.textTertiaryDark))
|
||||
private val primaryTextLuminance = measureLuminance(getColor(R.color.textPrimaryDark))
|
||||
private val secondaryTextLuminance = measureLuminance(getColor(R.color.textSecondaryDark))
|
||||
private val tertiaryTextLuminance = measureLuminance(getColor(R.color.textTertiaryDark))
|
||||
|
||||
val theme: Observable<Int> = prefs.theme.asObservable()
|
||||
.distinctUntilChanged()
|
||||
@@ -57,47 +58,47 @@ class Colors @Inject constructor(context: Context, prefs: Preferences) {
|
||||
|
||||
val statusBar: Observable<Int> = prefs.dark.asObservable()
|
||||
.map { dark -> if (dark) R.color.statusBarDark else R.color.statusBarLight }
|
||||
.map { res -> context.resources.getColor(res) }
|
||||
.map { res -> getColor(res) }
|
||||
.distinctUntilChanged()
|
||||
|
||||
val toolbarColor: Observable<Int> = prefs.dark.asObservable()
|
||||
.map { dark -> if (dark) R.color.toolbarDark else R.color.toolbarLight }
|
||||
.map { res -> context.resources.getColor(res) }
|
||||
.map { res -> getColor(res) }
|
||||
.distinctUntilChanged()
|
||||
|
||||
val background: Observable<Int> = prefs.dark.asObservable()
|
||||
.map { dark -> if (dark) R.color.backgroundDark else R.color.white }
|
||||
.map { res -> context.resources.getColor(res) }
|
||||
.map { res -> getColor(res) }
|
||||
.distinctUntilChanged()
|
||||
|
||||
val field: Observable<Int> = prefs.dark.asObservable()
|
||||
.map { dark -> if (dark) R.color.fieldDark else R.color.fieldLight }
|
||||
.map { res -> context.resources.getColor(res) }
|
||||
.map { res -> getColor(res) }
|
||||
.distinctUntilChanged()
|
||||
|
||||
val composeBackground: Observable<Int> = prefs.dark.asObservable()
|
||||
.map { dark -> if (dark) R.color.backgroundDark else R.color.backgroundLight }
|
||||
.map { res -> context.resources.getColor(res) }
|
||||
.map { res -> getColor(res) }
|
||||
.distinctUntilChanged()
|
||||
|
||||
val separator: Observable<Int> = prefs.dark.asObservable()
|
||||
.map { dark -> if (dark) R.color.separatorDark else R.color.separatorLight }
|
||||
.map { res -> context.resources.getColor(res) }
|
||||
.map { res -> getColor(res) }
|
||||
.distinctUntilChanged()
|
||||
|
||||
val textPrimary: Observable<Int> = prefs.dark.asObservable()
|
||||
.map { dark -> if (dark) R.color.textPrimaryDark else R.color.textPrimary }
|
||||
.map { res -> context.resources.getColor(res) }
|
||||
.map { res -> getColor(res) }
|
||||
.distinctUntilChanged()
|
||||
|
||||
val textSecondary: Observable<Int> = prefs.dark.asObservable()
|
||||
.map { dark -> if (dark) R.color.textSecondaryDark else R.color.textSecondary }
|
||||
.map { res -> context.resources.getColor(res) }
|
||||
.map { res -> getColor(res) }
|
||||
.distinctUntilChanged()
|
||||
|
||||
val textTertiary: Observable<Int> = prefs.dark.asObservable()
|
||||
.map { dark -> if (dark) R.color.textTertiaryDark else R.color.textTertiary }
|
||||
.map { res -> context.resources.getColor(res) }
|
||||
.map { res -> getColor(res) }
|
||||
.distinctUntilChanged()
|
||||
|
||||
val textPrimaryOnTheme: Observable<Int> = prefs.theme.asObservable()
|
||||
@@ -105,7 +106,7 @@ class Colors @Inject constructor(context: Context, prefs: Preferences) {
|
||||
.map { themeLuminance -> primaryTextLuminance / themeLuminance }
|
||||
.map { contrastRatio -> contrastRatio < MINIMUM_CONTRAST_RATIO }
|
||||
.map { contrastRatio -> if (contrastRatio) R.color.textPrimary else R.color.textPrimaryDark }
|
||||
.map { res -> context.resources.getColor(res) }
|
||||
.map { res -> getColor(res) }
|
||||
.distinctUntilChanged()
|
||||
|
||||
val textSecondaryOnTheme: Observable<Int> = prefs.theme.asObservable()
|
||||
@@ -113,7 +114,7 @@ class Colors @Inject constructor(context: Context, prefs: Preferences) {
|
||||
.map { themeLuminance -> secondaryTextLuminance / themeLuminance }
|
||||
.map { contrastRatio -> contrastRatio < MINIMUM_CONTRAST_RATIO }
|
||||
.map { contrastRatio -> if (contrastRatio) R.color.textSecondary else R.color.textSecondaryDark }
|
||||
.map { res -> context.resources.getColor(res) }
|
||||
.map { res -> getColor(res) }
|
||||
.distinctUntilChanged()
|
||||
|
||||
val textTertiaryOnTheme: Observable<Int> = prefs.theme.asObservable()
|
||||
@@ -121,34 +122,38 @@ class Colors @Inject constructor(context: Context, prefs: Preferences) {
|
||||
.map { themeLuminance -> tertiaryTextLuminance / themeLuminance }
|
||||
.map { contrastRatio -> contrastRatio < MINIMUM_CONTRAST_RATIO }
|
||||
.map { contrastRatio -> if (contrastRatio) R.color.textTertiary else R.color.textTertiaryDark }
|
||||
.map { res -> context.resources.getColor(res) }
|
||||
.map { res -> getColor(res) }
|
||||
.distinctUntilChanged()
|
||||
|
||||
val bubble: Observable<Int> = prefs.dark.asObservable()
|
||||
.map { dark -> if (dark) R.color.bubbleDark else R.color.bubbleLight }
|
||||
.map { res -> context.resources.getColor(res) }
|
||||
.map { res -> getColor(res) }
|
||||
.distinctUntilChanged()
|
||||
|
||||
val switchThumbEnabled: Observable<Int> = prefs.dark.asObservable()
|
||||
.map { dark -> if (dark) R.color.switchThumbEnabledDark else R.color.switchThumbEnabledLight }
|
||||
.map { res -> context.resources.getColor(res) }
|
||||
.map { res -> getColor(res) }
|
||||
.distinctUntilChanged()
|
||||
|
||||
val switchThumbDisabled: Observable<Int> = prefs.dark.asObservable()
|
||||
.map { dark -> if (dark) R.color.switchThumbDisabledDark else R.color.switchThumbDisabledLight }
|
||||
.map { res -> context.resources.getColor(res) }
|
||||
.map { res -> getColor(res) }
|
||||
.distinctUntilChanged()
|
||||
|
||||
val switchTrackEnabled: Observable<Int> = prefs.dark.asObservable()
|
||||
.map { dark -> if (dark) R.color.switchTrackEnabledDark else R.color.switchTrackEnabledLight }
|
||||
.map { res -> context.resources.getColor(res) }
|
||||
.map { res -> getColor(res) }
|
||||
.distinctUntilChanged()
|
||||
|
||||
val switchTrackDisabled: Observable<Int> = prefs.dark.asObservable()
|
||||
.map { dark -> if (dark) R.color.switchTrackDisabledDark else R.color.switchTrackDisabledLight }
|
||||
.map { res -> context.resources.getColor(res) }
|
||||
.map { res -> getColor(res) }
|
||||
.distinctUntilChanged()
|
||||
|
||||
private fun getColor(@ColorRes res: Int): Int {
|
||||
return context.resources.getColor(res)
|
||||
}
|
||||
|
||||
/**
|
||||
* Measures the luminance value of a color to be able to measure the contrast ratio between two colors
|
||||
* Based on https://stackoverflow.com/a/9733420
|
||||
|
||||
@@ -27,5 +27,5 @@ fun Int.dpToPx(context: Context): Int {
|
||||
}
|
||||
|
||||
fun Int.withAlpha(alpha: Int): Int {
|
||||
return Color.argb(0x4D, Color.red(this), Color.green(this), Color.blue(this))
|
||||
return Color.argb(alpha, Color.red(this), Color.green(this), Color.blue(this))
|
||||
}
|
||||
@@ -36,7 +36,7 @@ class ContactRepository @Inject constructor(val context: Context) {
|
||||
|
||||
fun findContactUri(address: String): Single<Uri> {
|
||||
return Flowable.just(address)
|
||||
.map { address -> Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(address)) }
|
||||
.map { Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(address)) }
|
||||
.flatMap { uri -> context.contentResolver.query(uri, arrayOf(ContactsContract.PhoneLookup._ID), null, null, null).asFlowable() }
|
||||
.firstOrError()
|
||||
.map { cursor -> cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.PhoneLookup._ID)) }
|
||||
|
||||
@@ -138,7 +138,8 @@ class MessageRepository @Inject constructor(
|
||||
return Realm.getDefaultInstance()
|
||||
.where(Message::class.java)
|
||||
.equalTo("threadId", threadId)
|
||||
.findAllSorted("date")
|
||||
.sort("date")
|
||||
.findAll()
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -151,7 +152,8 @@ class MessageRepository @Inject constructor(
|
||||
.equalTo("seen", false)
|
||||
.equalTo("read", false)
|
||||
.equalTo("threadId", threadId)
|
||||
.findAllSorted("date")
|
||||
.sort("date")
|
||||
.findAll()
|
||||
}
|
||||
|
||||
fun markArchived(threadId: Long) {
|
||||
|
||||
@@ -38,6 +38,7 @@ import io.reactivex.disposables.CompositeDisposable
|
||||
import io.reactivex.rxkotlin.plusAssign
|
||||
import io.reactivex.subjects.PublishSubject
|
||||
import io.reactivex.subjects.Subject
|
||||
import io.realm.RealmList
|
||||
import io.realm.RealmRecyclerViewAdapter
|
||||
import kotlinx.android.synthetic.main.message_list_item_in.view.*
|
||||
import presentation.common.base.QkViewHolder
|
||||
@@ -47,8 +48,8 @@ import javax.inject.Inject
|
||||
class MessagesAdapter @Inject constructor(
|
||||
private val context: Context,
|
||||
private val colors: Colors,
|
||||
private val dateFormatter: DateFormatter)
|
||||
: RealmRecyclerViewAdapter<Message, QkViewHolder>(null, true) {
|
||||
private val dateFormatter: DateFormatter
|
||||
) : RealmRecyclerViewAdapter<Message, QkViewHolder>(null, true) {
|
||||
|
||||
companion object {
|
||||
private val VIEWTYPE_ME = 1
|
||||
@@ -92,9 +93,8 @@ class MessagesAdapter @Inject constructor(
|
||||
}
|
||||
|
||||
if (absViewType != VIEWTYPE_ME) {
|
||||
view.avatar.contact = Contact().apply {
|
||||
numbers.add(PhoneNumber().apply { address = people[absViewType - 2] })
|
||||
}
|
||||
val number = PhoneNumber(address = people[absViewType - 2])
|
||||
view.avatar.contact = Contact(numbers = RealmList(number))
|
||||
}
|
||||
|
||||
return QkViewHolder(view)
|
||||
|
||||
@@ -139,6 +139,7 @@ class MainViewModel : QkViewModel<MainView, MainState>(MainState()) {
|
||||
DrawerItem.ARCHIVED -> newState { it.copy(page = Archived(messageRepo.getConversations(true))) }
|
||||
DrawerItem.SCHEDULED -> newState { it.copy(page = Scheduled()) }
|
||||
DrawerItem.BLOCKED -> newState { it.copy(page = Blocked()) }
|
||||
else -> {} // Do nothing
|
||||
}
|
||||
}
|
||||
.autoDisposable(view.scope())
|
||||
@@ -151,7 +152,7 @@ class MainViewModel : QkViewModel<MainView, MainState>(MainState()) {
|
||||
.subscribe()
|
||||
|
||||
view.conversationLongClickIntent
|
||||
.withLatestFrom(state, { l, mainState ->
|
||||
.withLatestFrom(state, { _, mainState ->
|
||||
when (mainState.page) {
|
||||
is Inbox -> {
|
||||
val page = mainState.page.copy(menu = listOf(menuArchive, menuDelete))
|
||||
|
||||
Reference in New Issue
Block a user