forked from upstream-mirrors/quik
Merge pull request #406 from gavine99/no-auto-keyboard-show-on-compose-activity
no keyboard auto-show on compose activity
This commit is contained in:
@@ -57,7 +57,8 @@
|
|||||||
<activity
|
<activity
|
||||||
android:name=".feature.main.MainActivity"
|
android:name=".feature.main.MainActivity"
|
||||||
android:exported="true"
|
android:exported="true"
|
||||||
android:launchMode="singleTask">
|
android:launchMode="singleTask"
|
||||||
|
android:windowSoftInputMode="stateAlwaysHidden">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
<category android:name="android.intent.category.LAUNCHER" />
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
@@ -70,7 +71,8 @@
|
|||||||
<activity
|
<activity
|
||||||
android:name=".feature.compose.ComposeActivity"
|
android:name=".feature.compose.ComposeActivity"
|
||||||
android:exported="true"
|
android:exported="true"
|
||||||
android:parentActivityName=".feature.main.MainActivity">
|
android:parentActivityName=".feature.main.MainActivity"
|
||||||
|
android:windowSoftInputMode="stateHidden">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.VIEW" />
|
<action android:name="android.intent.action.VIEW" />
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
|||||||
@@ -839,10 +839,6 @@ class ComposeActivity : QkThemedActivity(), ComposeView {
|
|||||||
override fun onBackPressed() = backPressedIntent.onNext(Unit)
|
override fun onBackPressed() = backPressedIntent.onNext(Unit)
|
||||||
|
|
||||||
override fun focusMessage() {
|
override fun focusMessage() {
|
||||||
runOnUiThread {
|
message.requestFocus()
|
||||||
val message = findViewById<QkEditText>(R.id.message)
|
|
||||||
if (message !== null) message.requestFocus()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -113,5 +113,4 @@ interface ComposeView : QkView<ComposeState> {
|
|||||||
fun showClearCurrentMessageDialog()
|
fun showClearCurrentMessageDialog()
|
||||||
fun startSpeechRecognition()
|
fun startSpeechRecognition()
|
||||||
fun focusMessage()
|
fun focusMessage()
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -30,7 +30,6 @@ import android.view.Menu
|
|||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewStub
|
import android.view.ViewStub
|
||||||
import android.widget.LinearLayout
|
|
||||||
import androidx.appcompat.app.ActionBarDrawerToggle
|
import androidx.appcompat.app.ActionBarDrawerToggle
|
||||||
import androidx.core.app.ActivityCompat
|
import androidx.core.app.ActivityCompat
|
||||||
import androidx.core.view.GravityCompat
|
import androidx.core.view.GravityCompat
|
||||||
@@ -88,13 +87,8 @@ class MainActivity : QkThemedActivity(), MainView {
|
|||||||
override val activityResumedIntent: Subject<Boolean> = PublishSubject.create()
|
override val activityResumedIntent: Subject<Boolean> = PublishSubject.create()
|
||||||
override val queryChangedIntent by lazy { toolbarSearch.textChanges() }
|
override val queryChangedIntent by lazy { toolbarSearch.textChanges() }
|
||||||
override val composeIntent by lazy { compose.clicks() }
|
override val composeIntent by lazy { compose.clicks() }
|
||||||
override val drawerOpenIntent: Observable<Boolean> by lazy {
|
override val drawerToggledIntent: Observable<Boolean> by lazy {
|
||||||
drawerLayout
|
drawerLayout.drawerOpen(Gravity.START)
|
||||||
.drawerOpen(Gravity.START)
|
|
||||||
.doOnNext {
|
|
||||||
dismissKeyboard()
|
|
||||||
inbox.requestFocus();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
override val homeIntent: Subject<Unit> = PublishSubject.create()
|
override val homeIntent: Subject<Unit> = PublishSubject.create()
|
||||||
override val navigationIntent: Observable<NavItem> by lazy {
|
override val navigationIntent: Observable<NavItem> by lazy {
|
||||||
@@ -122,10 +116,22 @@ class MainActivity : QkThemedActivity(), MainView {
|
|||||||
override val undoArchiveIntent: Subject<Unit> = PublishSubject.create()
|
override val undoArchiveIntent: Subject<Unit> = PublishSubject.create()
|
||||||
override val snackbarButtonIntent: Subject<Unit> = PublishSubject.create()
|
override val snackbarButtonIntent: Subject<Unit> = PublishSubject.create()
|
||||||
|
|
||||||
private val viewModel by lazy { ViewModelProviders.of(this, viewModelFactory)[MainViewModel::class.java] }
|
private val viewModel by lazy {
|
||||||
private val toggle by lazy { ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.main_drawer_open_cd, 0) }
|
ViewModelProviders.of(this, viewModelFactory)[MainViewModel::class.java]
|
||||||
|
}
|
||||||
|
private val toggle by lazy {
|
||||||
|
ActionBarDrawerToggle(
|
||||||
|
this,
|
||||||
|
drawerLayout,
|
||||||
|
toolbar,
|
||||||
|
R.string.main_drawer_open_cd,
|
||||||
|
0
|
||||||
|
)
|
||||||
|
}
|
||||||
private val itemTouchHelper by lazy { ItemTouchHelper(itemTouchCallback) }
|
private val itemTouchHelper by lazy { ItemTouchHelper(itemTouchCallback) }
|
||||||
private val progressAnimator by lazy { ObjectAnimator.ofInt(syncingProgress, "progress", 0, 0) }
|
private val progressAnimator by lazy {
|
||||||
|
ObjectAnimator.ofInt(syncingProgress, "progress", 0, 0)
|
||||||
|
}
|
||||||
private val changelogDialog by lazy { ChangelogDialog(this) }
|
private val changelogDialog by lazy { ChangelogDialog(this) }
|
||||||
private val snackbar by lazy { findViewById<View>(R.id.snackbar) }
|
private val snackbar by lazy { findViewById<View>(R.id.snackbar) }
|
||||||
private val syncing by lazy { findViewById<View>(R.id.syncing) }
|
private val syncing by lazy { findViewById<View>(R.id.syncing) }
|
||||||
@@ -145,8 +151,10 @@ class MainActivity : QkThemedActivity(), MainView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
(syncing as? ViewStub)?.setOnInflateListener { _, _ ->
|
(syncing as? ViewStub)?.setOnInflateListener { _, _ ->
|
||||||
syncingProgress?.progressTintList = ColorStateList.valueOf(theme.blockingFirst().theme)
|
syncingProgress?.let {
|
||||||
syncingProgress?.indeterminateTintList = ColorStateList.valueOf(theme.blockingFirst().theme)
|
it.progressTintList = ColorStateList.valueOf(theme.blockingFirst().theme)
|
||||||
|
it.indeterminateTintList = ColorStateList.valueOf(theme.blockingFirst().theme)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
toggle.syncState()
|
toggle.syncState()
|
||||||
@@ -170,12 +178,13 @@ class MainActivity : QkThemedActivity(), MainView {
|
|||||||
intArrayOf(android.R.attr.state_activated),
|
intArrayOf(android.R.attr.state_activated),
|
||||||
intArrayOf(-android.R.attr.state_activated))
|
intArrayOf(-android.R.attr.state_activated))
|
||||||
|
|
||||||
resolveThemeColor(android.R.attr.textColorSecondary)
|
ColorStateList(states, intArrayOf(theme.theme,
|
||||||
.let { textSecondary -> ColorStateList(states, intArrayOf(theme.theme, textSecondary)) }
|
resolveThemeColor(android.R.attr.textColorSecondary)
|
||||||
.let { tintList ->
|
))
|
||||||
inboxIcon.imageTintList = tintList
|
.let { tintList ->
|
||||||
archivedIcon.imageTintList = tintList
|
inboxIcon.imageTintList = tintList
|
||||||
}
|
archivedIcon.imageTintList = tintList
|
||||||
|
}
|
||||||
|
|
||||||
// Miscellaneous views
|
// Miscellaneous views
|
||||||
listOf(plusBadge1, plusBadge2).forEach { badge ->
|
listOf(plusBadge1, plusBadge2).forEach { badge ->
|
||||||
@@ -193,10 +202,11 @@ class MainActivity : QkThemedActivity(), MainView {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onNewIntent(intent: Intent?) {
|
override fun onNewIntent(intent: Intent?) =
|
||||||
super.onNewIntent(intent)
|
intent?.let {
|
||||||
intent?.run(onNewIntentIntent::onNext)
|
super.onNewIntent(intent)
|
||||||
}
|
it.run(onNewIntentIntent::onNext)
|
||||||
|
} ?: Unit
|
||||||
|
|
||||||
override fun render(state: MainState) {
|
override fun render(state: MainState) {
|
||||||
if (state.hasError) {
|
if (state.hasError) {
|
||||||
@@ -228,20 +238,28 @@ class MainActivity : QkThemedActivity(), MainView {
|
|||||||
else -> 0
|
else -> 0
|
||||||
}
|
}
|
||||||
|
|
||||||
toolbarSearch.setVisible(state.page is Inbox && state.page.selected == 0 || state.page is Searching)
|
toolbarSearch.setVisible(state.page is Inbox &&
|
||||||
|
state.page.selected == 0 ||
|
||||||
|
state.page is Searching
|
||||||
|
)
|
||||||
toolbarTitle.setVisible(toolbarSearch.visibility != View.VISIBLE)
|
toolbarTitle.setVisible(toolbarSearch.visibility != View.VISIBLE)
|
||||||
|
|
||||||
toolbar.menu.findItem(R.id.select_all)?.isVisible = (conversationsAdapter.itemCount > 1) && selectedConversations != 0
|
toolbar.menu.apply {
|
||||||
toolbar.menu.findItem(R.id.archive)?.isVisible = state.page is Inbox && selectedConversations != 0
|
findItem(R.id.select_all)?.isVisible =
|
||||||
toolbar.menu.findItem(R.id.unarchive)?.isVisible = state.page is Archived && selectedConversations != 0
|
(conversationsAdapter.itemCount > 1) && selectedConversations != 0
|
||||||
toolbar.menu.findItem(R.id.delete)?.isVisible = selectedConversations != 0
|
findItem(R.id.archive)?.isVisible =
|
||||||
toolbar.menu.findItem(R.id.add)?.isVisible = addContact && selectedConversations != 0
|
state.page is Inbox && selectedConversations != 0
|
||||||
toolbar.menu.findItem(R.id.pin)?.isVisible = markPinned && selectedConversations != 0
|
findItem(R.id.unarchive)?.isVisible =
|
||||||
toolbar.menu.findItem(R.id.unpin)?.isVisible = !markPinned && selectedConversations != 0
|
state.page is Archived && selectedConversations != 0
|
||||||
toolbar.menu.findItem(R.id.read)?.isVisible = markRead && selectedConversations != 0
|
findItem(R.id.delete)?.isVisible = selectedConversations != 0
|
||||||
toolbar.menu.findItem(R.id.unread)?.isVisible = !markRead && selectedConversations != 0
|
findItem(R.id.add)?.isVisible = addContact && selectedConversations != 0
|
||||||
toolbar.menu.findItem(R.id.block)?.isVisible = selectedConversations != 0
|
findItem(R.id.pin)?.isVisible = markPinned && selectedConversations != 0
|
||||||
toolbar.menu.findItem(R.id.rename)?.isVisible = selectedConversations == 1
|
findItem(R.id.unpin)?.isVisible = !markPinned && selectedConversations != 0
|
||||||
|
findItem(R.id.read)?.isVisible = markRead && selectedConversations != 0
|
||||||
|
findItem(R.id.unread)?.isVisible = !markRead && selectedConversations != 0
|
||||||
|
findItem(R.id.block)?.isVisible = selectedConversations != 0
|
||||||
|
findItem(R.id.rename)?.isVisible = selectedConversations == 1
|
||||||
|
}
|
||||||
|
|
||||||
listOf(plusBadge1, plusBadge2).forEach { badge ->
|
listOf(plusBadge1, plusBadge2).forEach { badge ->
|
||||||
badge.isVisible = drawerBadgesExperiment.variant && !state.upgraded
|
badge.isVisible = drawerBadgesExperiment.variant && !state.upgraded
|
||||||
@@ -251,14 +269,17 @@ class MainActivity : QkThemedActivity(), MainView {
|
|||||||
rateLayout.setVisible(state.showRating)
|
rateLayout.setVisible(state.showRating)
|
||||||
|
|
||||||
compose.setVisible(state.page is Inbox || state.page is Archived)
|
compose.setVisible(state.page is Inbox || state.page is Archived)
|
||||||
conversationsAdapter.emptyView = empty.takeIf { state.page is Inbox || state.page is Archived }
|
conversationsAdapter.emptyView = empty.takeIf {
|
||||||
|
state.page is Inbox || state.page is Archived
|
||||||
|
}
|
||||||
searchAdapter.emptyView = empty.takeIf { state.page is Searching }
|
searchAdapter.emptyView = empty.takeIf { state.page is Searching }
|
||||||
|
|
||||||
when (state.page) {
|
when (state.page) {
|
||||||
is Inbox -> {
|
is Inbox -> {
|
||||||
showBackButton(state.page.selected > 0)
|
showBackButton(state.page.selected > 0)
|
||||||
title = getString(R.string.main_title_selected, state.page.selected)
|
title = getString(R.string.main_title_selected, state.page.selected)
|
||||||
if (recyclerView.adapter !== conversationsAdapter) recyclerView.adapter = conversationsAdapter
|
if (recyclerView.adapter !== conversationsAdapter)
|
||||||
|
recyclerView.adapter = conversationsAdapter
|
||||||
conversationsAdapter.updateData(state.page.data)
|
conversationsAdapter.updateData(state.page.data)
|
||||||
itemTouchHelper.attachToRecyclerView(recyclerView)
|
itemTouchHelper.attachToRecyclerView(recyclerView)
|
||||||
empty.setText(R.string.inbox_empty_text)
|
empty.setText(R.string.inbox_empty_text)
|
||||||
@@ -278,7 +299,8 @@ class MainActivity : QkThemedActivity(), MainView {
|
|||||||
true -> getString(R.string.main_title_selected, state.page.selected)
|
true -> getString(R.string.main_title_selected, state.page.selected)
|
||||||
false -> getString(R.string.title_archived)
|
false -> getString(R.string.title_archived)
|
||||||
}
|
}
|
||||||
if (recyclerView.adapter !== conversationsAdapter) recyclerView.adapter = conversationsAdapter
|
if (recyclerView.adapter !== conversationsAdapter)
|
||||||
|
recyclerView.adapter = conversationsAdapter
|
||||||
conversationsAdapter.updateData(state.page.data)
|
conversationsAdapter.updateData(state.page.data)
|
||||||
itemTouchHelper.attachToRecyclerView(null)
|
itemTouchHelper.attachToRecyclerView(null)
|
||||||
empty.setText(R.string.archived_empty_text)
|
empty.setText(R.string.archived_empty_text)
|
||||||
@@ -290,22 +312,26 @@ class MainActivity : QkThemedActivity(), MainView {
|
|||||||
inbox.isActivated = state.page is Inbox
|
inbox.isActivated = state.page is Inbox
|
||||||
archived.isActivated = state.page is Archived
|
archived.isActivated = state.page is Archived
|
||||||
|
|
||||||
if (drawerLayout.isDrawerOpen(GravityCompat.START) && !state.drawerOpen) {
|
if (drawerLayout.isDrawerOpen(GravityCompat.START) && !state.drawerOpen)
|
||||||
drawerLayout.closeDrawer(GravityCompat.START)
|
drawerLayout.closeDrawer(GravityCompat.START)
|
||||||
} else if (!drawerLayout.isDrawerVisible(GravityCompat.START) && state.drawerOpen) {
|
else if (!drawerLayout.isDrawerVisible(GravityCompat.START) && state.drawerOpen)
|
||||||
drawerLayout.openDrawer(GravityCompat.START)
|
drawerLayout.openDrawer(GravityCompat.START)
|
||||||
}
|
|
||||||
|
|
||||||
when (state.syncing) {
|
when (state.syncing) {
|
||||||
is SyncRepository.SyncProgress.Idle -> {
|
is SyncRepository.SyncProgress.Idle -> {
|
||||||
syncing.isVisible = false
|
syncing.isVisible = false
|
||||||
snackbar.isVisible = !state.defaultSms || !state.smsPermission || !state.contactPermission || !state.notificationPermission
|
snackbar.isVisible = (!state.defaultSms ||
|
||||||
|
!state.smsPermission ||
|
||||||
|
!state.contactPermission ||
|
||||||
|
!state.notificationPermission)
|
||||||
}
|
}
|
||||||
|
|
||||||
is SyncRepository.SyncProgress.Running -> {
|
is SyncRepository.SyncProgress.Running -> {
|
||||||
syncing.isVisible = true
|
syncing.isVisible = true
|
||||||
syncingProgress.max = state.syncing.max
|
syncingProgress.max = state.syncing.max
|
||||||
progressAnimator.apply { setIntValues(syncingProgress.progress, state.syncing.progress) }.start()
|
progressAnimator.apply {
|
||||||
|
setIntValues(syncingProgress.progress, state.syncing.progress)
|
||||||
|
}.start()
|
||||||
syncingProgress.isIndeterminate = state.syncing.indeterminate
|
syncingProgress.isIndeterminate = state.syncing.indeterminate
|
||||||
snackbar.isVisible = false
|
snackbar.isVisible = false
|
||||||
}
|
}
|
||||||
@@ -338,32 +364,26 @@ class MainActivity : QkThemedActivity(), MainView {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() =
|
||||||
super.onResume()
|
super.onResume().also { activityResumedIntent.onNext(true) }
|
||||||
activityResumedIntent.onNext(true)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onPause() {
|
override fun onPause() =
|
||||||
super.onPause()
|
super.onPause().also { activityResumedIntent.onNext(false) }
|
||||||
activityResumedIntent.onNext(false)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() =
|
||||||
super.onDestroy()
|
super.onDestroy().also { disposables.dispose() }
|
||||||
disposables.dispose()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun showBackButton(show: Boolean) {
|
override fun showBackButton(show: Boolean) =
|
||||||
toggle.onDrawerSlide(drawer, if (show) 1f else 0f)
|
toggle.let {
|
||||||
toggle.drawerArrowDrawable.color = when (show) {
|
it.onDrawerSlide(drawer, if (show) 1f else 0f)
|
||||||
true -> resolveThemeColor(android.R.attr.textColorSecondary)
|
it.drawerArrowDrawable.color = when (show) {
|
||||||
false -> resolveThemeColor(android.R.attr.textColorPrimary)
|
true -> resolveThemeColor(android.R.attr.textColorSecondary)
|
||||||
|
false -> resolveThemeColor(android.R.attr.textColorPrimary)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
override fun requestDefaultSms() {
|
override fun requestDefaultSms() =
|
||||||
navigator.showDefaultSmsDialog(this)
|
navigator.showDefaultSmsDialog(this)
|
||||||
}
|
|
||||||
|
|
||||||
override fun requestPermissions() {
|
override fun requestPermissions() {
|
||||||
val permissions = mutableListOf(
|
val permissions = mutableListOf(
|
||||||
@@ -372,9 +392,8 @@ class MainActivity : QkThemedActivity(), MainView {
|
|||||||
Manifest.permission.READ_CONTACTS
|
Manifest.permission.READ_CONTACTS
|
||||||
)
|
)
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU)
|
||||||
permissions += Manifest.permission.POST_NOTIFICATIONS
|
permissions += Manifest.permission.POST_NOTIFICATIONS
|
||||||
}
|
|
||||||
|
|
||||||
ActivityCompat.requestPermissions(this, permissions.toTypedArray(), 0)
|
ActivityCompat.requestPermissions(this, permissions.toTypedArray(), 0)
|
||||||
}
|
}
|
||||||
@@ -384,68 +403,72 @@ class MainActivity : QkThemedActivity(), MainView {
|
|||||||
toolbarSearch.text = null
|
toolbarSearch.text = null
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun clearSelection() {
|
override fun clearSelection() = conversationsAdapter.clearSelection()
|
||||||
conversationsAdapter.clearSelection()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun toggleSelectAll() {
|
override fun toggleSelectAll() = conversationsAdapter.toggleSelectAll()
|
||||||
conversationsAdapter.toggleSelectAll()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun themeChanged() {
|
override fun themeChanged() = recyclerView.scrapViews()
|
||||||
recyclerView.scrapViews()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun showBlockingDialog(conversations: List<Long>, block: Boolean) {
|
override fun showBlockingDialog(conversations: List<Long>, block: Boolean) {
|
||||||
blockingDialog.show(this, conversations, block)
|
blockingDialog.show(this, conversations, block)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun showDeleteDialog(conversations: List<Long>) {
|
override fun showDeleteDialog(conversations: List<Long>) {
|
||||||
val count = conversations.size
|
|
||||||
AlertDialog.Builder(this)
|
AlertDialog.Builder(this)
|
||||||
.setTitle(R.string.dialog_delete_title)
|
.setTitle(R.string.dialog_delete_title)
|
||||||
.setMessage(resources.getQuantityString(R.plurals.dialog_delete_message, count, count))
|
.setMessage(
|
||||||
.setPositiveButton(R.string.button_delete) { _, _ -> confirmDeleteIntent.onNext(conversations) }
|
resources.getQuantityString(
|
||||||
.setNegativeButton(R.string.button_cancel, null)
|
R.plurals.dialog_delete_message,
|
||||||
.show()
|
conversations.size,
|
||||||
|
conversations.size
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.setPositiveButton(R.string.button_delete) { _, _ -> confirmDeleteIntent.onNext(conversations) }
|
||||||
|
.setNegativeButton(R.string.button_cancel, null)
|
||||||
|
.show()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun showRenameDialog(conversationName: String) {
|
override fun showRenameDialog(conversationName: String) =
|
||||||
TextInputDialog(
|
TextInputDialog(
|
||||||
this,
|
this,
|
||||||
getString(R.string.info_name),
|
getString(R.string.info_name),
|
||||||
renameConversationIntent::onNext
|
renameConversationIntent::onNext
|
||||||
).setText(conversationName).show()
|
)
|
||||||
}
|
.setText(conversationName)
|
||||||
|
.show()
|
||||||
|
|
||||||
override fun showChangelog(changelog: ChangelogManager.CumulativeChangelog) {
|
override fun showChangelog(changelog: ChangelogManager.CumulativeChangelog) =
|
||||||
changelogDialog.show(changelog)
|
changelogDialog.show(changelog)
|
||||||
}
|
|
||||||
|
|
||||||
override fun showArchivedSnackbar(countConversationsArchived: Int) {
|
override fun showArchivedSnackbar(countConversationsArchived: Int) =
|
||||||
Snackbar.make(
|
Snackbar.make(
|
||||||
drawerLayout,
|
drawerLayout,
|
||||||
resources.getQuantityString(R.plurals.toast_archived, countConversationsArchived, countConversationsArchived),
|
resources.getQuantityString(R.plurals.toast_archived, countConversationsArchived, countConversationsArchived),
|
||||||
if (countConversationsArchived < 10) Snackbar.LENGTH_LONG else Snackbar.LENGTH_INDEFINITE
|
if (countConversationsArchived < 10) Snackbar.LENGTH_LONG
|
||||||
).apply {
|
else Snackbar.LENGTH_INDEFINITE
|
||||||
setAction(R.string.button_undo) { undoArchiveIntent.onNext(Unit) }
|
).let {
|
||||||
setActionTextColor(colors.theme().theme)
|
it.setAction(R.string.button_undo) { undoArchiveIntent.onNext(Unit) }
|
||||||
show()
|
it.setActionTextColor(colors.theme().theme)
|
||||||
|
it.show()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
|
override fun onCreateOptionsMenu(menu: Menu?) =
|
||||||
menuInflater.inflate(R.menu.main, menu)
|
menu?.let {
|
||||||
return super.onCreateOptionsMenu(menu)
|
menuInflater.inflate(R.menu.main, it)
|
||||||
}
|
super.onCreateOptionsMenu(it)
|
||||||
|
} ?: false
|
||||||
|
|
||||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
override fun onOptionsItemSelected(item: MenuItem) =
|
||||||
optionsItemIntent.onNext(item.itemId)
|
optionsItemIntent.onNext(item.itemId).let { true }
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onBackPressed() {
|
override fun onBackPressed() = backPressedSubject.onNext(NavItem.BACK)
|
||||||
backPressedSubject.onNext(NavItem.BACK)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
override fun drawerToggled(opened: Boolean) {
|
||||||
|
if (opened) {
|
||||||
|
dismissKeyboard()
|
||||||
|
if (!inbox.isInTouchMode)
|
||||||
|
inbox.requestFocus()
|
||||||
|
} else
|
||||||
|
toolbarSearch.requestFocus()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ interface MainView : QkView<MainState> {
|
|||||||
val activityResumedIntent: Observable<Boolean>
|
val activityResumedIntent: Observable<Boolean>
|
||||||
val queryChangedIntent: Observable<CharSequence>
|
val queryChangedIntent: Observable<CharSequence>
|
||||||
val composeIntent: Observable<Unit>
|
val composeIntent: Observable<Unit>
|
||||||
val drawerOpenIntent: Observable<Boolean>
|
val drawerToggledIntent: Observable<Boolean>
|
||||||
val homeIntent: Observable<*>
|
val homeIntent: Observable<*>
|
||||||
val navigationIntent: Observable<NavItem>
|
val navigationIntent: Observable<NavItem>
|
||||||
val optionsItemIntent: Observable<Int>
|
val optionsItemIntent: Observable<Int>
|
||||||
@@ -55,7 +55,7 @@ interface MainView : QkView<MainState> {
|
|||||||
fun showRenameDialog(conversationName: String)
|
fun showRenameDialog(conversationName: String)
|
||||||
fun showChangelog(changelog: ChangelogManager.CumulativeChangelog)
|
fun showChangelog(changelog: ChangelogManager.CumulativeChangelog)
|
||||||
fun showArchivedSnackbar(countConversationsArchived: Int)
|
fun showArchivedSnackbar(countConversationsArchived: Int)
|
||||||
|
fun drawerToggled(opened: Boolean)
|
||||||
}
|
}
|
||||||
|
|
||||||
enum class NavItem { BACK, INBOX, ARCHIVED, BACKUP, SCHEDULED, BLOCKING, SETTINGS, PLUS, HELP, INVITE }
|
enum class NavItem { BACK, INBOX, ARCHIVED, BACKUP, SCHEDULED, BLOCKING, SETTINGS, PLUS, HELP, INVITE }
|
||||||
|
|||||||
@@ -82,8 +82,10 @@ class MainViewModel @Inject constructor(
|
|||||||
private val ratingManager: RatingManager,
|
private val ratingManager: RatingManager,
|
||||||
private val syncContacts: SyncContacts,
|
private val syncContacts: SyncContacts,
|
||||||
private val syncMessages: SyncMessages
|
private val syncMessages: SyncMessages
|
||||||
) : QkViewModel<MainView, MainState>(MainState(page = Inbox(data = conversationRepo.getConversations(prefs.unreadAtTop.get())))) {
|
) : QkViewModel<MainView, MainState>(
|
||||||
private val lastArchivedThreadIds = ArrayList<Long>()
|
MainState(page = Inbox(data = conversationRepo.getConversations(prefs.unreadAtTop.get())))
|
||||||
|
) {
|
||||||
|
private var lastArchivedThreadIds = listOf<Long>(0)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
disposables += deleteConversations
|
disposables += deleteConversations
|
||||||
@@ -293,9 +295,13 @@ class MainViewModel @Inject constructor(
|
|||||||
.autoDisposable(view.scope())
|
.autoDisposable(view.scope())
|
||||||
.subscribe()
|
.subscribe()
|
||||||
|
|
||||||
view.drawerOpenIntent
|
view.drawerToggledIntent
|
||||||
.autoDisposable(view.scope())
|
.doOnNext {
|
||||||
.subscribe { open -> newState { copy(drawerOpen = open) } }
|
newState { copy(drawerOpen = it) }
|
||||||
|
view.drawerToggled(it)
|
||||||
|
}
|
||||||
|
.autoDisposable(view.scope())
|
||||||
|
.subscribe { open -> newState { copy(drawerOpen = open) } }
|
||||||
|
|
||||||
view.navigationIntent
|
view.navigationIntent
|
||||||
.withLatestFrom(state) { drawerItem, state ->
|
.withLatestFrom(state) { drawerItem, state ->
|
||||||
@@ -342,9 +348,8 @@ class MainViewModel @Inject constructor(
|
|||||||
.filter { itemId -> itemId == R.id.archive }
|
.filter { itemId -> itemId == R.id.archive }
|
||||||
.withLatestFrom(view.conversationsSelectedIntent) { _, conversations ->
|
.withLatestFrom(view.conversationsSelectedIntent) { _, conversations ->
|
||||||
markArchived.execute(conversations)
|
markArchived.execute(conversations)
|
||||||
lastArchivedThreadIds.clear()
|
lastArchivedThreadIds = conversations.toList()
|
||||||
conversations.forEach { conversation -> lastArchivedThreadIds.add(conversation) }
|
view.showArchivedSnackbar(lastArchivedThreadIds.count())
|
||||||
view.showArchivedSnackbar(conversations.count())
|
|
||||||
view.clearSelection()
|
view.clearSelection()
|
||||||
}
|
}
|
||||||
.autoDisposable(view.scope())
|
.autoDisposable(view.scope())
|
||||||
@@ -518,8 +523,7 @@ class MainViewModel @Inject constructor(
|
|||||||
when (action) {
|
when (action) {
|
||||||
Preferences.SWIPE_ACTION_ARCHIVE ->
|
Preferences.SWIPE_ACTION_ARCHIVE ->
|
||||||
markArchived.execute(listOf(threadId)) {
|
markArchived.execute(listOf(threadId)) {
|
||||||
lastArchivedThreadIds.clear()
|
lastArchivedThreadIds = listOf(threadId)
|
||||||
lastArchivedThreadIds.add(threadId)
|
|
||||||
view.showArchivedSnackbar(1)
|
view.showArchivedSnackbar(1)
|
||||||
}
|
}
|
||||||
Preferences.SWIPE_ACTION_DELETE ->
|
Preferences.SWIPE_ACTION_DELETE ->
|
||||||
@@ -543,8 +547,8 @@ class MainViewModel @Inject constructor(
|
|||||||
view.undoArchiveIntent
|
view.undoArchiveIntent
|
||||||
.autoDisposable(view.scope())
|
.autoDisposable(view.scope())
|
||||||
.subscribe {
|
.subscribe {
|
||||||
markUnarchived.execute(lastArchivedThreadIds)
|
markUnarchived.execute(lastArchivedThreadIds.toList())
|
||||||
lastArchivedThreadIds.clear()
|
lastArchivedThreadIds = listOf()
|
||||||
}
|
}
|
||||||
|
|
||||||
view.snackbarButtonIntent
|
view.snackbarButtonIntent
|
||||||
|
|||||||
@@ -62,9 +62,7 @@
|
|||||||
app:textSize="primary"
|
app:textSize="primary"
|
||||||
tools:textSize="16sp"
|
tools:textSize="16sp"
|
||||||
android:focusable="true"
|
android:focusable="true"
|
||||||
android:focusableInTouchMode="true"
|
|
||||||
android:nextFocusRight="@+id/compose" />
|
android:nextFocusRight="@+id/compose" />
|
||||||
|
|
||||||
</androidx.appcompat.widget.Toolbar>
|
</androidx.appcompat.widget.Toolbar>
|
||||||
|
|
||||||
<dev.octoshrimpy.quik.common.widget.QkTextView
|
<dev.octoshrimpy.quik.common.widget.QkTextView
|
||||||
|
|||||||
Reference in New Issue
Block a user