Add collapsing toolbar and upgrade link on Scheduled screen

This commit is contained in:
Moez Bhatti
2018-07-16 01:33:51 -04:00
parent 9077a92053
commit 7140df66a1
11 changed files with 182 additions and 59 deletions
@@ -33,6 +33,7 @@ import com.moez.QKSMS.common.util.extensions.setBackgroundTint
import com.moez.QKSMS.common.util.extensions.setTint
import com.moez.QKSMS.common.util.extensions.setVisible
import dagger.android.AndroidInjection
import kotlinx.android.synthetic.main.collapsing_toolbar.*
import kotlinx.android.synthetic.main.qksms_plus_activity.*
import javax.inject.Inject
@@ -1,23 +1,33 @@
package com.moez.QKSMS.feature.scheduled
import android.graphics.Typeface
import android.os.Bundle
import androidx.core.view.isVisible
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.ViewModelProviders
import com.jakewharton.rxbinding2.view.clicks
import com.moez.QKSMS.R
import com.moez.QKSMS.common.QkDialog
import com.moez.QKSMS.common.base.QkThemedActivity
import com.moez.QKSMS.common.util.FontProvider
import com.moez.QKSMS.common.util.extensions.setBackgroundTint
import com.moez.QKSMS.common.util.extensions.setTint
import dagger.android.AndroidInjection
import kotlinx.android.synthetic.main.collapsing_toolbar.*
import kotlinx.android.synthetic.main.scheduled_activity.*
import javax.inject.Inject
class ScheduledActivity : QkThemedActivity(), ScheduledView {
@Inject lateinit var dialog: QkDialog
@Inject lateinit var fontProvider: FontProvider
@Inject lateinit var messageAdapter: ScheduledMessageAdapter
@Inject lateinit var viewModelFactory: ViewModelProvider.Factory
override val messageClickIntent by lazy { messageAdapter.clicks }
override val messageMenuIntent by lazy { dialog.adapter.menuItemClicks }
override val upgradeIntent by lazy { upgrade.clicks() }
private val viewModel by lazy { ViewModelProviders.of(this, viewModelFactory)[ScheduledViewModel::class.java] }
@@ -29,15 +39,31 @@ class ScheduledActivity : QkThemedActivity(), ScheduledView {
showBackButton(true)
viewModel.bindView(this)
if (!prefs.systemFont.get()) {
fontProvider.getLato { lato ->
val typeface = Typeface.create(lato, Typeface.BOLD)
collapsingToolbar.setCollapsedTitleTypeface(typeface)
collapsingToolbar.setExpandedTitleTypeface(typeface)
}
}
dialog.title = getString(R.string.scheduled_options_title)
dialog.adapter.setData(R.array.scheduled_options)
messageAdapter.emptyView = empty
messages.adapter = messageAdapter
colors.theme().let { theme ->
upgrade.setBackgroundTint(theme.theme)
upgradeIcon.setTint(theme.textPrimary)
upgradeLabel.setTextColor(theme.textPrimary)
}
}
override fun render(state: ScheduledState) {
messageAdapter.updateData(state.scheduledMessages)
upgrade.isVisible = !state.upgraded
}
override fun showMessageOptions() {
@@ -4,5 +4,6 @@ import com.moez.QKSMS.model.ScheduledMessage
import io.realm.RealmResults
data class ScheduledState(
val scheduledMessages: RealmResults<ScheduledMessage>? = null
val scheduledMessages: RealmResults<ScheduledMessage>? = null,
val upgraded: Boolean = false
)
@@ -7,6 +7,7 @@ interface ScheduledView : QkView<ScheduledState> {
val messageClickIntent: Observable<Long>
val messageMenuIntent: Observable<Int>
val upgradeIntent: Observable<*>
fun showMessageOptions()
@@ -1,20 +1,30 @@
package com.moez.QKSMS.feature.scheduled
import com.moez.QKSMS.common.Navigator
import com.moez.QKSMS.common.androidxcompat.scope
import com.moez.QKSMS.common.base.QkViewModel
import com.moez.QKSMS.common.util.BillingManager
import com.moez.QKSMS.interactor.SendScheduledMessage
import com.moez.QKSMS.repository.ScheduledMessageRepository
import com.uber.autodispose.kotlin.autoDisposable
import io.reactivex.rxkotlin.plusAssign
import io.reactivex.rxkotlin.withLatestFrom
import javax.inject.Inject
class ScheduledViewModel @Inject constructor(
billingManager: BillingManager,
private val navigator: Navigator,
private val scheduledMessageRepo: ScheduledMessageRepository,
private val sendScheduledMessage: SendScheduledMessage
) : QkViewModel<ScheduledView, ScheduledState>(ScheduledState(
scheduledMessages = scheduledMessageRepo.getScheduledMessages()
)) {
init {
disposables += billingManager.upgradeStatus
.subscribe { upgraded -> newState { copy(upgraded = upgraded) } }
}
override fun bindView(view: ScheduledView) {
super.bindView(view)
@@ -31,6 +41,10 @@ class ScheduledViewModel @Inject constructor(
}
.autoDisposable(view.scope())
.subscribe()
view.upgradeIntent
.autoDisposable(view.scope())
.subscribe { navigator.showQksmsPlusActivity("schedule_fab") }
}
}
@@ -0,0 +1,27 @@
<?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/>.
-->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/white" />
<corners android:radius="24dp" />
</shape>
@@ -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/>.
-->
<com.google.android.material.appbar.AppBarLayout android:id="@+id/appBarLayout"
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="108dp"
android:fitsSystemWindows="true">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:id="@+id/collapsingToolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:collapsedTitleTextAppearance="@style/CollapsingToolbarCollapsedText"
app:expandedTitleMarginBottom="8dp"
app:expandedTitleTextAppearance="@style/CollapsingToolbarExpandedText"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
tools:title="Title" />
</com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>
@@ -23,28 +23,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="160dp"
android:fitsSystemWindows="true">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:id="@+id/collapsingToolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:collapsedTitleTextAppearance="@style/CollapsingToolbarCollapsedText"
app:expandedTitleTextAppearance="@style/CollapsingToolbarExpandedText"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin" />
</com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>
<include layout="@layout/collapsing_toolbar" />
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
@@ -54,7 +33,8 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
android:orientation="vertical"
android:paddingTop="8dp">
<LinearLayout
android:id="@+id/toUpgrade"
@@ -271,4 +251,10 @@
</androidx.core.widget.NestedScrollView>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_gravity="bottom"
android:background="?android:attr/divider" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
@@ -17,55 +17,73 @@
~ 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"
<androidx.coordinatorlayout.widget.CoordinatorLayout 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="match_parent">
<include
android:id="@+id/toolbar"
layout="@layout/toolbar"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/messages"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="8dp"
android:paddingTop="8dp"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:listitem="@layout/scheduled_message_list_item" />
<com.moez.QKSMS.common.widget.QkTextView
android:id="@+id/empty"
style="@style/TextSecondary"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:focusable="true"
android:gravity="center"
android:padding="56dp"
android:text="@string/scheduled_empty_text"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/toolbar" />
android:text="@string/scheduled_empty_text" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/messages"
android:layout_width="match_parent"
android:layout_height="0dp"
android:paddingBottom="8dp"
android:paddingTop="8dp"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@id/toolbar"
tools:listitem="@layout/scheduled_message_list_item" />
<LinearLayout
android:id="@+id/upgrade"
android:layout_width="wrap_content"
android:layout_height="48dp"
android:layout_gravity="bottom|end"
android:layout_margin="16dp"
android:background="@drawable/rounded_rectangle_24dp"
android:elevation="4dp"
android:gravity="center"
android:visibility="gone"
tools:backgroundTint="@color/tools_theme"
tools:visibility="visible">
<View
android:layout_width="match_parent"
android:layout_height="8dp"
android:background="@drawable/ab_shadow"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/toolbar" />
<ImageView
android:id="@+id/upgradeIcon"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginStart="12dp"
android:src="@drawable/ic_star_black_24dp"
tools:tint="@color/textPrimaryDark" />
<com.moez.QKSMS.common.widget.QkTextView
android:id="@+id/upgradeLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:text="@string/title_qksms_plus"
android:textColor="@color/textPrimaryDark"
android:textStyle="bold"
app:textSize="primary" />
</LinearLayout>
<include layout="@layout/collapsing_toolbar" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?android:attr/divider"
app:layout_constraintBottom_toBottomOf="parent" />
android:layout_gravity="bottom"
android:background="?android:attr/divider" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
@@ -136,6 +136,7 @@
<string name="gallery_toast_saved">Saved to gallery</string>
<string name="scheduled_title">Scheduled</string>
<string name="scheduled_empty_description">Automatically send a message, at the exact moment you\'d like</string>
<string name="scheduled_empty_text">Your scheduled messages will appear here</string>
<string name="scheduled_options_title">Scheduled message</string>
<string-array name="scheduled_options">
+3 -1
View File
@@ -79,10 +79,12 @@
<style name="CollapsingToolbarCollapsedText">
<item name="textSize">toolbar</item>
<item name="android:textStyle">bold</item>
</style>
<style name="CollapsingToolbarExpandedText">
<item name="android:textSize">48sp</item>
<item name="android:textSize">44dp</item>
<item name="android:textStyle">bold</item>
</style>
<style name="DrawerRow">