Fixed tab indicator missing upon device rotation

This commit is contained in:
Sylvain Berfini 2020-04-02 09:52:14 +02:00
parent baf2c10755
commit c70114c45d
17 changed files with 27 additions and 72 deletions

View file

@ -19,9 +19,7 @@
*/
package org.linphone.activities.main.fragments
import android.content.Context
import android.os.Bundle
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
@ -36,38 +34,15 @@ class TabsFragment : Fragment() {
private lateinit var binding: TabsFragmentBinding
private lateinit var viewModel: TabsViewModel
private var dialerSelected: Boolean = false
private var contactsSelected: Boolean = false
private var chatSelected: Boolean = false
private var historySelected: Boolean = false
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
binding = TabsFragmentBinding.inflate(inflater, container, false)
binding.historySelect.visibility = if (historySelected) View.VISIBLE else View.GONE
binding.contactsSelect.visibility = if (contactsSelected) View.VISIBLE else View.GONE
binding.dialerSelect.visibility = if (dialerSelected) View.VISIBLE else View.GONE
binding.chatSelect.visibility = if (chatSelected) View.VISIBLE else View.GONE
return binding.root
}
override fun onInflate(context: Context, attrs: AttributeSet, savedInstanceState: Bundle?) {
super.onInflate(context, attrs, savedInstanceState)
val attributes = context.obtainStyledAttributes(attrs, R.styleable.TabsFragment)
historySelected = attributes.getBoolean(R.styleable.TabsFragment_history_selected, false)
contactsSelected = attributes.getBoolean(R.styleable.TabsFragment_contacts_selected, false)
dialerSelected = attributes.getBoolean(R.styleable.TabsFragment_dialer_selected, false)
chatSelected = attributes.getBoolean(R.styleable.TabsFragment_chat_selected, false)
attributes.recycle()
}
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
@ -78,6 +53,17 @@ class TabsFragment : Fragment() {
} ?: throw Exception("Invalid Activity")
binding.viewModel = viewModel
viewModel.historySelected.value = false
viewModel.contactsSelected.value = false
viewModel.dialerSelected.value = false
viewModel.chatSelected.value = false
when (findNavController().currentDestination?.id) {
R.id.masterCallLogsFragment -> viewModel.historySelected.value = true
R.id.masterContactsFragment -> viewModel.contactsSelected.value = true
R.id.dialerFragment -> viewModel.dialerSelected.value = true
R.id.masterChatRoomsFragment -> viewModel.chatSelected.value = true
}
binding.setHistoryClickListener {
when (findNavController().currentDestination?.id) {
R.id.masterContactsFragment -> findNavController().navigate(R.id.action_masterContactsFragment_to_masterCallLogsFragment)

View file

@ -25,6 +25,11 @@ import org.linphone.LinphoneApplication.Companion.coreContext
import org.linphone.core.*
class TabsViewModel : ViewModel() {
val historySelected = MutableLiveData<Boolean>()
val contactsSelected = MutableLiveData<Boolean>()
val dialerSelected = MutableLiveData<Boolean>()
val chatSelected = MutableLiveData<Boolean>()
val unreadMessagesCount = MutableLiveData<Int>()
val missedCallsCount = MutableLiveData<Int>()

View file

@ -29,7 +29,6 @@
android:layout_width="60dp"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
app:chat_selected="true"
tools:layout="@layout/tabs_fragment" />
<LinearLayout

View file

@ -32,7 +32,6 @@
android:layout_width="60dp"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
app:contacts_selected="true"
tools:layout="@layout/tabs_fragment" />
<LinearLayout

View file

@ -40,7 +40,6 @@
android:layout_width="60dp"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
app:dialer_selected="true"
tools:layout="@layout/tabs_fragment" />
<RelativeLayout

View file

@ -29,7 +29,6 @@
android:layout_width="60dp"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
app:history_selected="true"
tools:layout="@layout/tabs_fragment" />
<LinearLayout

View file

@ -28,7 +28,6 @@
android:orientation="vertical">
<RelativeLayout
android:id="@+id/history"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
@ -44,15 +43,13 @@
android:src="@drawable/footer_history" />
<View
android:id="@+id/history_select"
android:layout_width="5dp"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:background="?attr/accentColor"
android:visibility="gone" />
android:visibility="@{viewModel.historySelected ? View.VISIBLE : View.GONE, default=gone}" />
<TextView
android:id="@+id/missed_calls"
style="@style/unread_count_font"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
@ -67,7 +64,6 @@
</RelativeLayout>
<RelativeLayout
android:id="@+id/contacts"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
@ -83,17 +79,15 @@
android:src="@drawable/footer_contacts" />
<View
android:id="@+id/contacts_select"
android:layout_width="5dp"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:background="?attr/accentColor"
android:visibility="gone" />
android:visibility="@{viewModel.contactsSelected ? View.VISIBLE : View.GONE, default=gone}" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/dialer"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
@ -109,16 +103,15 @@
android:src="@drawable/footer_dialer" />
<View
android:id="@+id/dialer_select"
android:layout_width="5dp"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:background="?attr/accentColor" />
android:background="?attr/accentColor"
android:visibility="@{viewModel.dialerSelected ? View.VISIBLE : View.GONE, default=visible}" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/chat"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
@ -134,15 +127,13 @@
android:src="@drawable/footer_chat" />
<View
android:id="@+id/chat_select"
android:layout_width="5dp"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:background="?attr/accentColor"
android:visibility="gone" />
android:visibility="@{viewModel.chatSelected ? View.VISIBLE : View.GONE, default=gone}" />
<TextView
android:id="@+id/missed_chats"
style="@style/unread_count_font"
android:layout_width="wrap_content"
android:layout_height="wrap_content"

View file

@ -29,7 +29,6 @@
android:layout_width="60dp"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
app:chat_selected="true"
tools:layout="@layout/tabs_fragment" />
<LinearLayout

View file

@ -32,7 +32,6 @@
android:layout_width="60dp"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
app:contacts_selected="true"
tools:layout="@layout/tabs_fragment" />
<LinearLayout

View file

@ -29,7 +29,6 @@
android:layout_width="60dp"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
app:history_selected="true"
tools:layout="@layout/tabs_fragment" />
<LinearLayout

View file

@ -29,7 +29,6 @@
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_alignParentBottom="true"
app:chat_selected="true"
tools:layout="@layout/tabs_fragment" />
<LinearLayout

View file

@ -32,7 +32,6 @@
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_alignParentBottom="true"
app:contacts_selected="true"
tools:layout="@layout/tabs_fragment" />
<LinearLayout

View file

@ -38,7 +38,6 @@
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_alignParentBottom="true"
app:dialer_selected="true"
tools:layout="@layout/tabs_fragment" />
<RelativeLayout

View file

@ -29,7 +29,6 @@
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_alignParentBottom="true"
app:history_selected="true"
tools:layout="@layout/tabs_fragment" />
<LinearLayout

View file

@ -28,7 +28,6 @@
android:orientation="horizontal">
<RelativeLayout
android:id="@+id/history"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
@ -44,15 +43,13 @@
android:src="@drawable/footer_history" />
<View
android:id="@+id/history_select"
android:layout_width="match_parent"
android:layout_height="5dp"
android:layout_alignParentBottom="true"
android:background="?attr/accentColor"
android:visibility="gone" />
android:visibility="@{viewModel.historySelected ? View.VISIBLE : View.GONE, default=gone}" />
<TextView
android:id="@+id/missed_calls"
style="@style/unread_count_font"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
@ -65,7 +62,6 @@
</RelativeLayout>
<RelativeLayout
android:id="@+id/contacts"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
@ -81,17 +77,15 @@
android:src="@drawable/footer_contacts" />
<View
android:id="@+id/contacts_select"
android:layout_width="match_parent"
android:layout_height="5dp"
android:layout_alignParentBottom="true"
android:background="?attr/accentColor"
android:visibility="gone" />
android:visibility="@{viewModel.contactsSelected ? View.VISIBLE : View.GONE, default=gone}" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/dialer"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
@ -107,16 +101,15 @@
android:src="@drawable/footer_dialer" />
<View
android:id="@+id/dialer_select"
android:layout_width="match_parent"
android:layout_height="5dp"
android:layout_alignParentBottom="true"
android:background="?attr/accentColor" />
android:background="?attr/accentColor"
android:visibility="@{viewModel.dialerSelected ? View.VISIBLE : View.GONE, default=visible}" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/chat"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
@ -132,15 +125,13 @@
android:src="@drawable/footer_chat" />
<View
android:id="@+id/chat_select"
android:layout_width="match_parent"
android:layout_height="5dp"
android:layout_alignParentBottom="true"
android:background="?attr/accentColor"
android:visibility="gone" />
android:visibility="@{viewModel.chatSelected ? View.VISIBLE : View.GONE, default=gone}" />
<TextView
android:id="@+id/missed_chats"
style="@style/unread_count_font"
android:layout_width="wrap_content"
android:layout_height="wrap_content"

View file

@ -28,13 +28,6 @@
<attr name="button_background_drawable" format="reference" />
</declare-styleable>
<declare-styleable name="TabsFragment">
<attr name="history_selected" format="boolean"/>
<attr name="contacts_selected" format="boolean"/>
<attr name="dialer_selected" format="boolean"/>
<attr name="chat_selected" format="boolean"/>
</declare-styleable>
<declare-styleable name="Settings">
<attr name="title" format="string" />
<attr name="subtitle" format="string" />

View file

@ -12,7 +12,7 @@ buildscript {
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.1'
classpath 'com.android.tools.build:gradle:3.6.2'
classpath 'com.google.gms:google-services:4.3.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jlleitschuh.gradle:ktlint-gradle:9.1.1"