mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-17 11:38:51 +01:00
Lazily load bottom info views in MainActivity
This commit is contained in:
@@ -27,6 +27,7 @@ import android.view.Gravity
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import android.view.ViewStub
|
||||
import androidx.appcompat.app.ActionBarDrawerToggle
|
||||
import androidx.core.app.ActivityCompat
|
||||
import androidx.core.view.GravityCompat
|
||||
@@ -62,6 +63,8 @@ import io.reactivex.subjects.PublishSubject
|
||||
import io.reactivex.subjects.Subject
|
||||
import kotlinx.android.synthetic.main.drawer_view.*
|
||||
import kotlinx.android.synthetic.main.main_activity.*
|
||||
import kotlinx.android.synthetic.main.main_permission_hint.*
|
||||
import kotlinx.android.synthetic.main.main_syncing.*
|
||||
import javax.inject.Inject
|
||||
|
||||
class MainActivity : QkThemedActivity(), MainView {
|
||||
@@ -103,7 +106,7 @@ class MainActivity : QkThemedActivity(), MainView {
|
||||
override val confirmDeleteIntent: Subject<List<Long>> = PublishSubject.create()
|
||||
override val swipeConversationIntent by lazy { itemTouchCallback.swipes }
|
||||
override val undoArchiveIntent: Subject<Unit> = PublishSubject.create()
|
||||
override val snackbarButtonIntent by lazy { snackbarButton.clicks() }
|
||||
override val snackbarButtonIntent: Subject<Unit> = PublishSubject.create()
|
||||
override val backPressedIntent: Subject<Unit> = PublishSubject.create()
|
||||
|
||||
private val viewModel by lazy { ViewModelProviders.of(this, viewModelFactory)[MainViewModel::class.java] }
|
||||
@@ -115,6 +118,8 @@ class MainActivity : QkThemedActivity(), MainView {
|
||||
setAction(R.string.button_undo) { undoArchiveIntent.onNext(Unit) }
|
||||
}
|
||||
}
|
||||
private val snackbar by lazy { findViewById<View>(R.id.snackbar) }
|
||||
private val syncing by lazy { findViewById<View>(R.id.syncing) }
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
AndroidInjection.inject(this)
|
||||
@@ -122,6 +127,15 @@ class MainActivity : QkThemedActivity(), MainView {
|
||||
setContentView(R.layout.main_activity)
|
||||
viewModel.bindView(this)
|
||||
|
||||
(snackbar as? ViewStub)?.setOnInflateListener { _, _ ->
|
||||
snackbarButton.clicks().subscribe(snackbarButtonIntent)
|
||||
}
|
||||
|
||||
(syncing as? ViewStub)?.setOnInflateListener { _, _ ->
|
||||
syncingProgress?.progressTintList = ColorStateList.valueOf(theme.blockingFirst().theme)
|
||||
syncingProgress?.indeterminateTintList = ColorStateList.valueOf(theme.blockingFirst().theme)
|
||||
}
|
||||
|
||||
toggle.syncState()
|
||||
toolbar.setNavigationOnClickListener {
|
||||
dismissKeyboard()
|
||||
@@ -135,7 +149,7 @@ class MainActivity : QkThemedActivity(), MainView {
|
||||
drawer.clicks().subscribe()
|
||||
|
||||
// Set the theme color tint to the recyclerView, progressbar, and FAB
|
||||
colors.themeObservable()
|
||||
theme
|
||||
.doOnNext { recyclerView.scrapViews() }
|
||||
.autoDisposable(scope())
|
||||
.subscribe { theme ->
|
||||
@@ -153,7 +167,8 @@ class MainActivity : QkThemedActivity(), MainView {
|
||||
badge.setBackgroundTint(theme.theme)
|
||||
badge.setTextColor(theme.textPrimary)
|
||||
}
|
||||
syncingProgress.indeterminateTintList = ColorStateList.valueOf(theme.theme)
|
||||
syncingProgress?.progressTintList = ColorStateList.valueOf(theme.theme)
|
||||
syncingProgress?.indeterminateTintList = ColorStateList.valueOf(theme.theme)
|
||||
plusIcon.setTint(theme.theme)
|
||||
rateIcon.setTint(theme.theme)
|
||||
compose.setBackgroundTint(theme.theme)
|
||||
@@ -269,21 +284,21 @@ class MainActivity : QkThemedActivity(), MainView {
|
||||
|
||||
when {
|
||||
!state.smsPermission -> {
|
||||
snackbarTitle.setText(R.string.main_permission_required)
|
||||
snackbarMessage.setText(R.string.main_permission_sms)
|
||||
snackbarButton.setText(R.string.main_permission_allow)
|
||||
snackbarTitle?.setText(R.string.main_permission_required)
|
||||
snackbarMessage?.setText(R.string.main_permission_sms)
|
||||
snackbarButton?.setText(R.string.main_permission_allow)
|
||||
}
|
||||
|
||||
!state.defaultSms -> {
|
||||
snackbarTitle.setText(R.string.main_default_sms_title)
|
||||
snackbarMessage.setText(R.string.main_default_sms_message)
|
||||
snackbarButton.setText(R.string.main_default_sms_change)
|
||||
snackbarTitle?.setText(R.string.main_default_sms_title)
|
||||
snackbarMessage?.setText(R.string.main_default_sms_message)
|
||||
snackbarButton?.setText(R.string.main_default_sms_change)
|
||||
}
|
||||
|
||||
!state.contactPermission -> {
|
||||
snackbarTitle.setText(R.string.main_permission_required)
|
||||
snackbarMessage.setText(R.string.main_permission_contacts)
|
||||
snackbarButton.setText(R.string.main_permission_allow)
|
||||
snackbarTitle?.setText(R.string.main_permission_required)
|
||||
snackbarMessage?.setText(R.string.main_permission_contacts)
|
||||
snackbarButton?.setText(R.string.main_permission_allow)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,9 +30,9 @@ data class MainState(
|
||||
val upgraded: Boolean = true,
|
||||
val showRating: Boolean = false,
|
||||
val syncing: SyncRepository.SyncProgress = SyncRepository.SyncProgress.Idle(),
|
||||
val defaultSms: Boolean = false,
|
||||
val smsPermission: Boolean = false,
|
||||
val contactPermission: Boolean = false
|
||||
val defaultSms: Boolean = true,
|
||||
val smsPermission: Boolean = true,
|
||||
val contactPermission: Boolean = true
|
||||
)
|
||||
|
||||
sealed class MainPage
|
||||
|
||||
@@ -107,99 +107,22 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:background="?android:attr/divider"
|
||||
app:layout_constraintBottom_toTopOf="@id/bottomDivider" />
|
||||
app:layout_constraintBottom_toTopOf="@id/snackbar" />
|
||||
|
||||
<androidx.constraintlayout.widget.Barrier
|
||||
android:id="@+id/bottomDivider"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:barrierDirection="top"
|
||||
app:constraint_referenced_ids="snackbarTitle, snackbarMessage, syncingLabel, syncingProgress" />
|
||||
|
||||
<androidx.constraintlayout.widget.Group
|
||||
<ViewStub
|
||||
android:id="@+id/snackbar"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:visibility="gone"
|
||||
app:constraint_referenced_ids="snackbarTitle, snackbarMessage, snackbarButton"
|
||||
tools:visibility="visible" />
|
||||
android:inflatedId="@id/snackbar"
|
||||
android:layout="@layout/main_permission_hint"
|
||||
app:layout_constraintBottom_toTopOf="@id/syncing" />
|
||||
|
||||
<androidx.constraintlayout.widget.Group
|
||||
<ViewStub
|
||||
android:id="@+id/syncing"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:visibility="gone"
|
||||
app:constraint_referenced_ids="syncingProgress,syncingLabel"
|
||||
tools:visibility="gone" />
|
||||
|
||||
<com.moez.QKSMS.common.widget.QkTextView
|
||||
android:id="@+id/snackbarTitle"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="16dp"
|
||||
android:paddingTop="16dp"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintBottom_toTopOf="@id/snackbarMessage"
|
||||
app:layout_constraintEnd_toStartOf="@id/snackbarButton"
|
||||
app:layout_constraintHorizontal_bias="0"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:textColor="primary"
|
||||
app:textSize="primary"
|
||||
tools:text="Love texting again" />
|
||||
|
||||
<com.moez.QKSMS.common.widget.QkTextView
|
||||
android:id="@+id/snackbarMessage"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginTop="2dp"
|
||||
android:paddingBottom="16dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@id/snackbarButton"
|
||||
app:layout_constraintHorizontal_bias="0"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:textColor="secondary"
|
||||
app:textSize="secondary"
|
||||
tools:text="Make QKSMS your default SMS app" />
|
||||
|
||||
<com.moez.QKSMS.common.widget.QkTextView
|
||||
android:id="@+id/snackbarButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:padding="16dp"
|
||||
android:textAllCaps="true"
|
||||
android:textColor="@color/tools_theme"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintBottom_toBottomOf="@id/snackbarMessage"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="@id/snackbarTitle"
|
||||
app:textColor="theme"
|
||||
app:textSize="secondary"
|
||||
tools:text="Change" />
|
||||
|
||||
<com.moez.QKSMS.common.widget.QkTextView
|
||||
android:id="@+id/syncingLabel"
|
||||
style="@style/TextPrimary"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:layout_marginStart="16dp"
|
||||
android:paddingTop="16dp"
|
||||
android:text="@string/main_syncing"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintBottom_toTopOf="@id/syncingProgress" />
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/syncingProgress"
|
||||
style="@style/Widget.AppCompat.ProgressBar.Horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:layout_marginStart="16dp"
|
||||
android:indeterminate="true"
|
||||
android:inflatedId="@id/syncing"
|
||||
android:layout="@layout/main_syncing"
|
||||
app:layout_constraintBottom_toBottomOf="parent" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ 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/>.
|
||||
-->
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<com.moez.QKSMS.common.widget.QkTextView
|
||||
android:id="@+id/snackbarTitle"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="16dp"
|
||||
android:paddingTop="16dp"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintBottom_toTopOf="@id/snackbarMessage"
|
||||
app:layout_constraintEnd_toStartOf="@id/snackbarButton"
|
||||
app:layout_constraintHorizontal_bias="0"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:textColor="primary"
|
||||
app:textSize="primary"
|
||||
tools:text="Love texting again" />
|
||||
|
||||
<com.moez.QKSMS.common.widget.QkTextView
|
||||
android:id="@+id/snackbarMessage"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginTop="2dp"
|
||||
android:paddingBottom="16dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@id/snackbarButton"
|
||||
app:layout_constraintHorizontal_bias="0"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:textColor="secondary"
|
||||
app:textSize="secondary"
|
||||
tools:text="Make QKSMS your default SMS app" />
|
||||
|
||||
<com.moez.QKSMS.common.widget.QkTextView
|
||||
android:id="@+id/snackbarButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:padding="16dp"
|
||||
android:textAllCaps="true"
|
||||
android:textColor="@color/tools_theme"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintBottom_toBottomOf="@id/snackbarMessage"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="@id/snackbarTitle"
|
||||
app:textColor="theme"
|
||||
app:textSize="secondary"
|
||||
tools:text="Change" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
@@ -0,0 +1,46 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ 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/>.
|
||||
-->
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<com.moez.QKSMS.common.widget.QkTextView
|
||||
android:id="@+id/syncingLabel"
|
||||
style="@style/TextPrimary"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:layout_marginStart="16dp"
|
||||
android:paddingTop="16dp"
|
||||
android:text="@string/main_syncing"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/syncingProgress"
|
||||
style="@style/Widget.AppCompat.ProgressBar.Horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:layout_marginStart="16dp"
|
||||
android:indeterminate="true" />
|
||||
|
||||
</LinearLayout>
|
||||
Reference in New Issue
Block a user