mirror of
https://github.com/SimpleMobileTools/Simple-SMS-Messenger.git
synced 2025-02-19 21:20:39 +01:00
Merge branch 'SimpleMobileTools:master' into rewrite_sms
This commit is contained in:
commit
d31feca559
@ -33,6 +33,7 @@ import com.simplemobiletools.smsmessenger.models.Events
|
|||||||
import com.simplemobiletools.smsmessenger.models.Message
|
import com.simplemobiletools.smsmessenger.models.Message
|
||||||
import com.simplemobiletools.smsmessenger.models.SearchResult
|
import com.simplemobiletools.smsmessenger.models.SearchResult
|
||||||
import kotlinx.android.synthetic.main.activity_main.*
|
import kotlinx.android.synthetic.main.activity_main.*
|
||||||
|
import kotlinx.android.synthetic.main.menu_search.view.*
|
||||||
import org.greenrobot.eventbus.EventBus
|
import org.greenrobot.eventbus.EventBus
|
||||||
import org.greenrobot.eventbus.Subscribe
|
import org.greenrobot.eventbus.Subscribe
|
||||||
import org.greenrobot.eventbus.ThreadMode
|
import org.greenrobot.eventbus.ThreadMode
|
||||||
@ -93,7 +94,6 @@ class MainActivity : SimpleActivity() {
|
|||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
setupToolbar(main_toolbar)
|
|
||||||
updateMenuColors()
|
updateMenuColors()
|
||||||
|
|
||||||
getOrCreateConversationsAdapter().apply {
|
getOrCreateConversationsAdapter().apply {
|
||||||
@ -131,35 +131,35 @@ class MainActivity : SimpleActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onBackPressed() {
|
override fun onBackPressed() {
|
||||||
if (search_holder.isVisible()) {
|
if (main_menu.isSearchOpen) {
|
||||||
closeSearch()
|
main_menu.closeSearch()
|
||||||
} else {
|
} else {
|
||||||
super.onBackPressed()
|
super.onBackPressed()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupOptionsMenu() {
|
private fun setupOptionsMenu() {
|
||||||
updateMenuColors()
|
main_menu.top_toolbar.inflateMenu(R.menu.menu_main)
|
||||||
|
main_menu.setupMenu()
|
||||||
main_toolbar_search_icon.setOnClickListener {
|
main_menu.onSearchOpenListener = {
|
||||||
if (search_holder.isVisible()) {
|
search_holder.fadeIn()
|
||||||
closeSearch()
|
conversations_fab.beGone()
|
||||||
} else {
|
|
||||||
main_toolbar_search.requestFocus()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
main_toolbar_search.setOnFocusChangeListener { v, hasFocus ->
|
main_menu.onSearchClosedListener = {
|
||||||
if (hasFocus) {
|
search_holder.animate().alpha(0f).setDuration(SHORT_ANIMATION_DURATION).withEndAction {
|
||||||
openSearch()
|
search_holder.beGone()
|
||||||
}
|
searchTextChanged("", true)
|
||||||
|
}.start()
|
||||||
|
|
||||||
|
conversations_fab.beVisible()
|
||||||
}
|
}
|
||||||
|
|
||||||
main_toolbar_search.onTextChangeListener {
|
main_menu.onSearchTextChangedListener = { text ->
|
||||||
searchTextChanged(it)
|
searchTextChanged(text)
|
||||||
}
|
}
|
||||||
|
|
||||||
main_toolbar.setOnMenuItemClickListener { menuItem ->
|
main_menu.top_toolbar.setOnMenuItemClickListener { menuItem ->
|
||||||
when (menuItem.itemId) {
|
when (menuItem.itemId) {
|
||||||
R.id.import_messages -> tryImportMessages()
|
R.id.import_messages -> tryImportMessages()
|
||||||
R.id.export_messages -> tryToExportMessages()
|
R.id.export_messages -> tryToExportMessages()
|
||||||
@ -173,7 +173,7 @@ class MainActivity : SimpleActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun refreshMenuItems() {
|
private fun refreshMenuItems() {
|
||||||
main_toolbar.menu.apply {
|
main_menu.top_toolbar.menu.apply {
|
||||||
findItem(R.id.more_apps_from_us).isVisible = !resources.getBoolean(R.bool.hide_google_relations)
|
findItem(R.id.more_apps_from_us).isVisible = !resources.getBoolean(R.bool.hide_google_relations)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -200,15 +200,8 @@ class MainActivity : SimpleActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun updateMenuColors() {
|
private fun updateMenuColors() {
|
||||||
val backgroundColor = getProperBackgroundColor()
|
updateStatusbarColor(getProperBackgroundColor())
|
||||||
val contrastColor = backgroundColor.getContrastColor()
|
main_menu.updateColors()
|
||||||
|
|
||||||
updateStatusbarColor(backgroundColor)
|
|
||||||
main_app_bar_layout.setBackgroundColor(backgroundColor)
|
|
||||||
main_toolbar_search_icon.applyColorFilter(contrastColor)
|
|
||||||
main_toolbar_holder.background?.applyColorFilter(getProperPrimaryColor().adjustAlpha(LOWER_ALPHA))
|
|
||||||
main_toolbar_search.setTextColor(contrastColor)
|
|
||||||
main_toolbar_search.setHintTextColor(contrastColor.adjustAlpha(MEDIUM_ALPHA))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// while SEND_SMS and READ_SMS permissions are mandatory, READ_CONTACTS is optional. If we don't have it, we just won't be able to show the contact name in some cases
|
// while SEND_SMS and READ_SMS permissions are mandatory, READ_CONTACTS is optional. If we don't have it, we just won't be able to show the contact name in some cases
|
||||||
@ -440,19 +433,11 @@ class MainActivity : SimpleActivity() {
|
|||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun openSearch() {
|
private fun searchTextChanged(text: String, forceUpdate: Boolean = false) {
|
||||||
search_holder.beVisible()
|
if (!main_menu.isSearchOpen && !forceUpdate) {
|
||||||
main_toolbar_search_icon.setImageResource(R.drawable.ic_arrow_left_vector)
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun closeSearch() {
|
|
||||||
hideKeyboard()
|
|
||||||
main_toolbar_search.setText("")
|
|
||||||
search_holder.beGone()
|
|
||||||
main_toolbar_search_icon.setImageResource(R.drawable.ic_search_vector)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun searchTextChanged(text: String) {
|
|
||||||
lastSearchedText = text
|
lastSearchedText = text
|
||||||
search_placeholder_2.beGoneIf(text.length >= 2)
|
search_placeholder_2.beGoneIf(text.length >= 2)
|
||||||
if (text.length >= 2) {
|
if (text.length >= 2) {
|
||||||
|
@ -0,0 +1,71 @@
|
|||||||
|
package com.simplemobiletools.smsmessenger.views
|
||||||
|
|
||||||
|
import android.app.Activity
|
||||||
|
import android.content.Context
|
||||||
|
import android.util.AttributeSet
|
||||||
|
import com.google.android.material.appbar.AppBarLayout
|
||||||
|
import com.simplemobiletools.commons.extensions.*
|
||||||
|
import com.simplemobiletools.commons.helpers.LOWER_ALPHA
|
||||||
|
import com.simplemobiletools.commons.helpers.MEDIUM_ALPHA
|
||||||
|
import com.simplemobiletools.smsmessenger.R
|
||||||
|
import com.simplemobiletools.smsmessenger.activities.SimpleActivity
|
||||||
|
import kotlinx.android.synthetic.main.menu_search.view.*
|
||||||
|
|
||||||
|
class MySearchMenu(context: Context, attrs: AttributeSet) : AppBarLayout(context, attrs) {
|
||||||
|
var isSearchOpen = false
|
||||||
|
var onSearchOpenListener: (() -> Unit)? = null
|
||||||
|
var onSearchClosedListener: (() -> Unit)? = null
|
||||||
|
var onSearchTextChangedListener: ((text: String) -> Unit)? = null
|
||||||
|
|
||||||
|
init {
|
||||||
|
inflate(context, R.layout.menu_search, this)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setupMenu() {
|
||||||
|
top_toolbar_search_icon.setOnClickListener {
|
||||||
|
if (isSearchOpen) {
|
||||||
|
closeSearch()
|
||||||
|
} else {
|
||||||
|
top_toolbar_search.requestFocus()
|
||||||
|
(context as? Activity)?.showKeyboard(top_toolbar_search)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
top_toolbar_search.setOnFocusChangeListener { v, hasFocus ->
|
||||||
|
if (hasFocus) {
|
||||||
|
openSearch()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
top_toolbar_search.onTextChangeListener {
|
||||||
|
onSearchTextChangedListener?.invoke(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun openSearch() {
|
||||||
|
isSearchOpen = true
|
||||||
|
onSearchOpenListener?.invoke()
|
||||||
|
top_toolbar_search_icon.setImageResource(R.drawable.ic_arrow_left_vector)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun closeSearch() {
|
||||||
|
isSearchOpen = false
|
||||||
|
onSearchClosedListener?.invoke()
|
||||||
|
top_toolbar_search.setText("")
|
||||||
|
top_toolbar_search_icon.setImageResource(R.drawable.ic_search_vector)
|
||||||
|
(context as? Activity)?.hideKeyboard()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun updateColors() {
|
||||||
|
val backgroundColor = context.getProperBackgroundColor()
|
||||||
|
val contrastColor = backgroundColor.getContrastColor()
|
||||||
|
|
||||||
|
setBackgroundColor(backgroundColor)
|
||||||
|
top_app_bar_layout.setBackgroundColor(backgroundColor)
|
||||||
|
top_toolbar_search_icon.applyColorFilter(contrastColor)
|
||||||
|
top_toolbar_holder.background?.applyColorFilter(context.getProperPrimaryColor().adjustAlpha(LOWER_ALPHA))
|
||||||
|
top_toolbar_search.setTextColor(contrastColor)
|
||||||
|
top_toolbar_search.setHintTextColor(contrastColor.adjustAlpha(MEDIUM_ALPHA))
|
||||||
|
(context as? SimpleActivity)?.updateTopBarColors(top_toolbar, backgroundColor)
|
||||||
|
}
|
||||||
|
}
|
@ -5,61 +5,18 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
<com.google.android.material.appbar.AppBarLayout
|
<com.simplemobiletools.smsmessenger.views.MySearchMenu
|
||||||
android:id="@+id/main_app_bar_layout"
|
android:id="@+id/main_menu"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="?attr/actionBarSize"
|
android:layout_height="wrap_content" />
|
||||||
android:layout_marginStart="@dimen/activity_margin"
|
|
||||||
android:layout_marginEnd="@dimen/activity_margin">
|
|
||||||
|
|
||||||
<RelativeLayout
|
|
||||||
android:id="@+id/main_toolbar_holder"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginTop="@dimen/small_margin"
|
|
||||||
android:layout_marginBottom="@dimen/small_margin"
|
|
||||||
android:background="@drawable/search_menu_background">
|
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:id="@+id/main_toolbar_search_icon"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:layout_centerVertical="true"
|
|
||||||
android:paddingStart="@dimen/activity_margin"
|
|
||||||
android:src="@drawable/ic_search_vector" />
|
|
||||||
|
|
||||||
<EditText
|
|
||||||
android:id="@+id/main_toolbar_search"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:layout_centerVertical="true"
|
|
||||||
android:layout_toStartOf="@+id/main_toolbar"
|
|
||||||
android:layout_toEndOf="@+id/main_toolbar_search_icon"
|
|
||||||
android:background="@null"
|
|
||||||
android:gravity="start|center_vertical"
|
|
||||||
android:hint="@string/search"
|
|
||||||
android:paddingStart="@dimen/activity_margin"
|
|
||||||
android:textSize="@dimen/big_text_size" />
|
|
||||||
|
|
||||||
<com.google.android.material.appbar.MaterialToolbar
|
|
||||||
android:id="@+id/main_toolbar"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:layout_alignParentEnd="true"
|
|
||||||
android:layout_marginEnd="@dimen/small_margin"
|
|
||||||
app:menu="@menu/menu_main"
|
|
||||||
app:titleTextAppearance="@style/AppTheme.ActionBar.TitleTextStyle" />
|
|
||||||
|
|
||||||
</RelativeLayout>
|
|
||||||
</com.google.android.material.appbar.AppBarLayout>
|
|
||||||
|
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
android:id="@+id/main_nested_scrollview"
|
android:id="@+id/main_nested_scrollview"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="?attr/actionBarSize"
|
|
||||||
android:fillViewport="true"
|
android:fillViewport="true"
|
||||||
android:scrollbars="none">
|
android:scrollbars="none"
|
||||||
|
app:layout_behavior="@string/appbar_scrolling_view_behavior">
|
||||||
|
|
||||||
<androidx.coordinatorlayout.widget.CoordinatorLayout
|
<androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||||
android:id="@+id/main_coordinator_wrapper"
|
android:id="@+id/main_coordinator_wrapper"
|
||||||
@ -116,21 +73,13 @@
|
|||||||
|
|
||||||
</com.qtalk.recyclerviewfastscroller.RecyclerViewFastScroller>
|
</com.qtalk.recyclerviewfastscroller.RecyclerViewFastScroller>
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
||||||
<com.simplemobiletools.commons.views.MyFloatingActionButton
|
|
||||||
android:id="@+id/conversations_fab"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_gravity="bottom|end"
|
|
||||||
android:layout_margin="@dimen/activity_margin"
|
|
||||||
android:src="@drawable/ic_plus_vector" />
|
|
||||||
|
|
||||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||||
|
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
android:id="@+id/search_holder"
|
android:id="@+id/search_holder"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
|
android:alpha="0"
|
||||||
android:visibility="gone">
|
android:visibility="gone">
|
||||||
|
|
||||||
<com.simplemobiletools.commons.views.MyTextView
|
<com.simplemobiletools.commons.views.MyTextView
|
||||||
@ -173,4 +122,13 @@
|
|||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
||||||
|
<com.simplemobiletools.commons.views.MyFloatingActionButton
|
||||||
|
android:id="@+id/conversations_fab"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="bottom|end"
|
||||||
|
android:layout_margin="@dimen/activity_margin"
|
||||||
|
android:src="@drawable/ic_plus_vector" />
|
||||||
|
|
||||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||||
|
49
app/src/main/res/layout/menu_search.xml
Normal file
49
app/src/main/res/layout/menu_search.xml
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<com.google.android.material.appbar.AppBarLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:id="@+id/top_app_bar_layout"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="?attr/actionBarSize"
|
||||||
|
android:layout_marginStart="@dimen/activity_margin"
|
||||||
|
android:layout_marginEnd="@dimen/activity_margin"
|
||||||
|
app:layout_scrollFlags="enterAlways|scroll">
|
||||||
|
|
||||||
|
<RelativeLayout
|
||||||
|
android:id="@+id/top_toolbar_holder"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="@dimen/medium_margin"
|
||||||
|
android:layout_marginBottom="@dimen/medium_margin"
|
||||||
|
android:background="@drawable/search_menu_background">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/top_toolbar_search_icon"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_centerVertical="true"
|
||||||
|
android:paddingStart="@dimen/activity_margin"
|
||||||
|
android:src="@drawable/ic_search_vector" />
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/top_toolbar_search"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_centerVertical="true"
|
||||||
|
android:layout_toStartOf="@+id/top_toolbar"
|
||||||
|
android:layout_toEndOf="@+id/top_toolbar_search_icon"
|
||||||
|
android:background="@null"
|
||||||
|
android:gravity="start|center_vertical"
|
||||||
|
android:hint="@string/search"
|
||||||
|
android:paddingStart="@dimen/activity_margin"
|
||||||
|
android:textSize="@dimen/big_text_size" />
|
||||||
|
|
||||||
|
<com.google.android.material.appbar.MaterialToolbar
|
||||||
|
android:id="@+id/top_toolbar"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_alignParentEnd="true"
|
||||||
|
android:layout_marginEnd="@dimen/small_margin"
|
||||||
|
app:titleTextAppearance="@style/AppTheme.ActionBar.TitleTextStyle" />
|
||||||
|
|
||||||
|
</RelativeLayout>
|
||||||
|
</com.google.android.material.appbar.AppBarLayout>
|
@ -17,7 +17,7 @@
|
|||||||
android:id="@+id/more_apps_from_us"
|
android:id="@+id/more_apps_from_us"
|
||||||
android:icon="@drawable/ic_google_play_vector"
|
android:icon="@drawable/ic_google_play_vector"
|
||||||
android:title="@string/more_apps_from_us"
|
android:title="@string/more_apps_from_us"
|
||||||
app:showAsAction="always" />
|
app:showAsAction="ifRoom" />
|
||||||
<item
|
<item
|
||||||
android:id="@+id/settings"
|
android:id="@+id/settings"
|
||||||
android:icon="@drawable/ic_settings_cog_vector"
|
android:icon="@drawable/ic_settings_cog_vector"
|
||||||
@ -27,5 +27,5 @@
|
|||||||
android:id="@+id/about"
|
android:id="@+id/about"
|
||||||
android:icon="@drawable/ic_info_vector"
|
android:icon="@drawable/ic_info_vector"
|
||||||
android:title="@string/about"
|
android:title="@string/about"
|
||||||
app:showAsAction="ifRoom" />
|
app:showAsAction="always" />
|
||||||
</menu>
|
</menu>
|
||||||
|
@ -1 +1 @@
|
|||||||
Jednostavan SMS slatelj
|
Jednostavan SMS messenger
|
||||||
|
Loading…
x
Reference in New Issue
Block a user