Added settings to show/hide some parts of the UI

This commit is contained in:
Sylvain Berfini 2020-07-10 16:11:28 +02:00
parent 8e9aa6117c
commit c496126281
15 changed files with 196 additions and 8 deletions

View file

@ -24,12 +24,15 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider
import androidx.navigation.fragment.findNavController
import org.linphone.R
import org.linphone.activities.assistant.viewmodels.WelcomeViewModel
import org.linphone.databinding.AssistantWelcomeFragmentBinding
class WelcomeFragment : Fragment() {
private lateinit var binding: AssistantWelcomeFragmentBinding
private lateinit var viewModel: WelcomeViewModel
override fun onCreateView(
inflater: LayoutInflater,
@ -45,6 +48,9 @@ class WelcomeFragment : Fragment() {
binding.lifecycleOwner = this
viewModel = ViewModelProvider(this).get(WelcomeViewModel::class.java)
binding.viewModel = viewModel
binding.setCreateAccountClickListener {
if (findNavController().currentDestination?.id == R.id.welcomeFragment) {
if (resources.getBoolean(R.bool.isTablet)) {

View file

@ -21,6 +21,7 @@ package org.linphone.activities.assistant.viewmodels
import androidx.lifecycle.*
import org.linphone.LinphoneApplication.Companion.coreContext
import org.linphone.R
import org.linphone.core.*
import org.linphone.core.tools.Log
import org.linphone.utils.Event
@ -100,7 +101,7 @@ class AccountLoginViewModel(accountCreator: AccountCreator) : AbstractPhoneViewM
init {
accountCreator.addListener(listener)
loginWithUsernamePassword.value = false
loginWithUsernamePassword.value = coreContext.context.resources.getBoolean(R.bool.isTablet)
loginEnabled.value = false
loginEnabled.addSource(prefix) {

View file

@ -0,0 +1,30 @@
/*
* Copyright (c) 2010-2020 Belledonne Communications SARL.
*
* This file is part of linphone-android
* (see https://www.linphone.org).
*
* This program 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.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.linphone.activities.assistant.viewmodels
import androidx.lifecycle.ViewModel
import org.linphone.LinphoneApplication.Companion.corePreferences
class WelcomeViewModel : ViewModel() {
val showCreateAccount: Boolean = corePreferences.showCreateAccount
val showLinphoneLogin: Boolean = corePreferences.showLinphoneLogin
val showGenericLogin: Boolean = corePreferences.showGenericLogin
val showRemoteProvisioning: Boolean = corePreferences.showRemoteProvisioning
}

View file

@ -22,11 +22,22 @@ package org.linphone.activities.main.settings.viewmodels
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import org.linphone.LinphoneApplication.Companion.coreContext
import org.linphone.LinphoneApplication.Companion.corePreferences
import org.linphone.activities.main.settings.SettingListenerStub
class SettingsViewModel : ViewModel() {
val tunnelAvailable: Boolean = coreContext.core.tunnelAvailable()
val showAccountSettings: Boolean = corePreferences.showAccountSettings
val showTunnelSettings: Boolean = tunnelAvailable && corePreferences.showTunnelSettings
val showAudioSettings: Boolean = corePreferences.showAudioSettings
val showVideoSettings: Boolean = corePreferences.showVideoSettings
val showCallSettings: Boolean = corePreferences.showCallSettings
val showChatSettings: Boolean = corePreferences.showChatSettings
val showNetworkSettings: Boolean = corePreferences.showNetworkSettings
val showContactsSettings: Boolean = corePreferences.showContactsSettings
val showAdvancedSettings: Boolean = corePreferences.showAdvancedSettings
val accounts = MutableLiveData<ArrayList<AccountSettingsViewModel>>()
private var accountClickListener = object : SettingListenerStub() {

View file

@ -22,15 +22,18 @@ package org.linphone.activities.main.sidemenu.viewmodels
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import org.linphone.LinphoneApplication.Companion.coreContext
import org.linphone.LinphoneApplication.Companion.corePreferences
import org.linphone.activities.main.settings.SettingListenerStub
import org.linphone.activities.main.settings.viewmodels.AccountSettingsViewModel
import org.linphone.core.*
class SideMenuViewModel : ViewModel() {
val showAssistant: Boolean = true
val showSettings: Boolean = true
val showRecordings: Boolean = true
val showAbout: Boolean = true
val showAccounts: Boolean = corePreferences.showAccountsInSideMenu
val showAssistant: Boolean = corePreferences.showAssistantInSideMenu
val showSettings: Boolean = corePreferences.showSettingsInSideMenu
val showRecordings: Boolean = corePreferences.showRecordingsInSideMenu
val showAbout: Boolean = corePreferences.showAboutInSideMenu
val showQuit: Boolean = corePreferences.showQuitInSideMenu
val defaultAccount = MutableLiveData<AccountSettingsViewModel>()
val defaultAccountFound = MutableLiveData<Boolean>()

View file

@ -22,9 +22,15 @@ package org.linphone.activities.main.viewmodels
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import org.linphone.LinphoneApplication.Companion.coreContext
import org.linphone.LinphoneApplication.Companion.corePreferences
import org.linphone.core.*
class TabsViewModel : ViewModel() {
val showHistory: Boolean = corePreferences.showHistory
val showContacts: Boolean = corePreferences.showContacts
val showDialer: Boolean = corePreferences.showDialer
val showChat: Boolean = corePreferences.showChat
val historySelected = MutableLiveData<Boolean>()
val contactsSelected = MutableLiveData<Boolean>()
val dialerSelected = MutableLiveData<Boolean>()

View file

@ -239,6 +239,85 @@ class CorePreferences constructor(private val context: Context) {
val checkUpdateAvailableInterval: Int
get() = config.getInt("app", "version_check_interval", 86400000)
/* Tabs */
val showHistory: Boolean
get() = config.getBool("app", "tabs_history", true)
val showContacts: Boolean
get() = config.getBool("app", "tabs_contacts", true)
val showDialer: Boolean
get() = config.getBool("app", "tabs_dialer", true)
val showChat: Boolean
get() = config.getBool("app", "tabs_chat", true)
/* Assistant */
val showCreateAccount: Boolean
get() = config.getBool("app", "assistant_create_account", true)
val showLinphoneLogin: Boolean
get() = config.getBool("app", "assistant_linphone_login", true)
val showGenericLogin: Boolean
get() = config.getBool("app", "assistant_generic_login", true)
val showRemoteProvisioning: Boolean
get() = config.getBool("app", "assistant_remote_provisioning", true)
/* Side Menu */
val showAccountsInSideMenu: Boolean
get() = config.getBool("app", "side_menu_accounts", true)
val showAssistantInSideMenu: Boolean
get() = config.getBool("app", "side_menu_assistant", true)
val showSettingsInSideMenu: Boolean
get() = config.getBool("app", "side_menu_settings", true)
val showRecordingsInSideMenu: Boolean
get() = config.getBool("app", "side_menu_recordings", true)
val showAboutInSideMenu: Boolean
get() = config.getBool("app", "side_menu_about", true)
val showQuitInSideMenu: Boolean
get() = config.getBool("app", "side_menu_quit", true)
/* Settings */
val showAccountSettings: Boolean
get() = config.getBool("app", "settings_accounts", true)
val showTunnelSettings: Boolean
get() = config.getBool("app", "settings_tunnel", true)
val showAudioSettings: Boolean
get() = config.getBool("app", "settings_audio", true)
val showVideoSettings: Boolean
get() = config.getBool("app", "settings_video", true)
val showCallSettings: Boolean
get() = config.getBool("app", "settings_call", true)
val showChatSettings: Boolean
get() = config.getBool("app", "settings_chat", true)
val showNetworkSettings: Boolean
get() = config.getBool("app", "settings_network", true)
val showContactsSettings: Boolean
get() = config.getBool("app", "settings_contacts", true)
val showAdvancedSettings: Boolean
get() = config.getBool("app", "settings_advanced", true)
/* Other stuff */
private val darkModeAllowed: Boolean
get() = config.getBool("app", "dark_mode_allowed", true)

View file

@ -16,6 +16,9 @@
<variable
name="remoteProvisioningClickListener"
type="android.view.View.OnClickListener"/>
<variable
name="viewModel"
type="org.linphone.activities.assistant.viewmodels.WelcomeViewModel" />
</data>
<RelativeLayout
@ -65,6 +68,7 @@
<TextView
android:id="@+id/account_creation"
android:visibility="@{viewModel.showCreateAccount ? View.VISIBLE : View.GONE}"
android:onClick="@{createAccountClickListener}"
style="@style/button_font"
android:gravity="center"
@ -80,6 +84,7 @@
<TextView
android:id="@+id/account_connection"
android:visibility="@{viewModel.showLinphoneLogin ? View.VISIBLE : View.GONE}"
android:onClick="@{accountLoginClickListener}"
style="@style/button_font"
android:gravity="center"
@ -95,6 +100,7 @@
<TextView
android:id="@+id/generic_connection"
android:visibility="@{viewModel.showGenericLogin ? View.VISIBLE : View.GONE}"
android:onClick="@{genericAccountLoginClickListener}"
style="@style/button_font"
android:gravity="center"
@ -110,6 +116,7 @@
<TextView
android:id="@+id/remote_configuration"
android:visibility="@{viewModel.showRemoteProvisioning ? View.VISIBLE : View.GONE}"
android:onClick="@{remoteProvisioningClickListener}"
style="@style/button_font"
android:gravity="center"

View file

@ -32,6 +32,7 @@
android:layout_height="0dp"
android:layout_weight="1"
android:onClick="@{historyClickListener}"
android:visibility="@{viewModel.showHistory ? View.VISIBLE : View.GONE}"
android:background="@drawable/footer_button">
<ImageView
@ -68,6 +69,7 @@
android:layout_height="0dp"
android:layout_weight="1"
android:onClick="@{contactsClickListener}"
android:visibility="@{viewModel.showContacts ? View.VISIBLE : View.GONE}"
android:background="@drawable/footer_button">
<ImageView
@ -92,6 +94,7 @@
android:layout_height="0dp"
android:layout_weight="1"
android:onClick="@{dialerClickListener}"
android:visibility="@{viewModel.showDialer ? View.VISIBLE : View.GONE}"
android:background="@drawable/footer_button">
<ImageView
@ -116,6 +119,7 @@
android:layout_height="0dp"
android:layout_weight="1"
android:onClick="@{chatClickListener}"
android:visibility="@{viewModel.showChat ? View.VISIBLE : View.GONE}"
android:background="@drawable/footer_button">
<ImageView

View file

@ -75,6 +75,7 @@
<TextView
style="@style/settings_category_font"
android:text="@string/settings_accounts_title"
android:visibility="@{viewModel.showAccountSettings ? View.VISIBLE : View.GONE}"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_width="wrap_content"
@ -84,6 +85,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="@{viewModel.showAccountSettings ? View.VISIBLE : View.GONE}"
linphone:entries="@{viewModel.accounts}"
linphone:layout="@{@layout/settings_account_cell}"/>
@ -99,42 +101,49 @@
<include
layout="@layout/settings_widget_basic"
linphone:listener="@{viewModel.tunnelSettingsListener}"
android:visibility="@{viewModel.tunnelAvailable ? View.VISIBLE : View.GONE}"
android:visibility="@{viewModel.showTunnelSettings ? View.VISIBLE : View.GONE}"
linphone:title="@{@string/settings_tunnel_title}" />
<include
layout="@layout/settings_widget_basic"
linphone:listener="@{viewModel.audioSettingsListener}"
android:visibility="@{viewModel.showAudioSettings ? View.VISIBLE : View.GONE}"
linphone:title="@{@string/settings_audio_title}" />
<include
layout="@layout/settings_widget_basic"
linphone:listener="@{viewModel.videoSettingsListener}"
android:visibility="@{viewModel.showVideoSettings ? View.VISIBLE : View.GONE}"
linphone:title="@{@string/settings_video_title}" />
<include
layout="@layout/settings_widget_basic"
linphone:listener="@{viewModel.callSettingsListener}"
android:visibility="@{viewModel.showCallSettings ? View.VISIBLE : View.GONE}"
linphone:title="@{@string/settings_call_title}" />
<include
layout="@layout/settings_widget_basic"
linphone:listener="@{viewModel.chatSettingsListener}"
android:visibility="@{viewModel.showChatSettings ? View.VISIBLE : View.GONE}"
linphone:title="@{@string/settings_chat_title}" />
<include
layout="@layout/settings_widget_basic"
linphone:listener="@{viewModel.networkSettingsListener}"
android:visibility="@{viewModel.showNetworkSettings ? View.VISIBLE : View.GONE}"
linphone:title="@{@string/settings_network_title}" />
<include
layout="@layout/settings_widget_basic"
linphone:listener="@{viewModel.contactsSettingsListener}"
android:visibility="@{viewModel.showContactsSettings ? View.VISIBLE : View.GONE}"
linphone:title="@{@string/settings_contacts_title}" />
<include
layout="@layout/settings_widget_basic"
linphone:listener="@{viewModel.advancedSettingsListener}"
android:visibility="@{viewModel.showAdvancedSettings ? View.VISIBLE : View.GONE}"
linphone:title="@{@string/settings_advanced_title}" />
</LinearLayout>

View file

@ -75,6 +75,7 @@
<TextView
style="@style/settings_category_font"
android:text="@string/settings_accounts_title"
android:visibility="@{viewModel.showAccountSettings ? View.VISIBLE : View.GONE}"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_width="wrap_content"
@ -84,6 +85,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="@{viewModel.showAccountSettings ? View.VISIBLE : View.GONE}"
linphone:entries="@{viewModel.accounts}"
linphone:layout="@{@layout/settings_account_cell}"/>
@ -99,42 +101,49 @@
<include
layout="@layout/settings_widget_basic"
linphone:listener="@{viewModel.tunnelSettingsListener}"
android:visibility="@{viewModel.tunnelAvailable ? View.VISIBLE : View.GONE}"
android:visibility="@{viewModel.showTunnelSettings ? View.VISIBLE : View.GONE}"
linphone:title="@{@string/settings_tunnel_title}" />
<include
layout="@layout/settings_widget_basic"
linphone:listener="@{viewModel.audioSettingsListener}"
android:visibility="@{viewModel.showAudioSettings ? View.VISIBLE : View.GONE}"
linphone:title="@{@string/settings_audio_title}" />
<include
layout="@layout/settings_widget_basic"
linphone:listener="@{viewModel.videoSettingsListener}"
android:visibility="@{viewModel.showVideoSettings ? View.VISIBLE : View.GONE}"
linphone:title="@{@string/settings_video_title}" />
<include
layout="@layout/settings_widget_basic"
linphone:listener="@{viewModel.callSettingsListener}"
android:visibility="@{viewModel.showCallSettings ? View.VISIBLE : View.GONE}"
linphone:title="@{@string/settings_call_title}" />
<include
layout="@layout/settings_widget_basic"
linphone:listener="@{viewModel.chatSettingsListener}"
android:visibility="@{viewModel.showChatSettings ? View.VISIBLE : View.GONE}"
linphone:title="@{@string/settings_chat_title}" />
<include
layout="@layout/settings_widget_basic"
linphone:listener="@{viewModel.networkSettingsListener}"
android:visibility="@{viewModel.showNetworkSettings ? View.VISIBLE : View.GONE}"
linphone:title="@{@string/settings_network_title}" />
<include
layout="@layout/settings_widget_basic"
linphone:listener="@{viewModel.contactsSettingsListener}"
android:visibility="@{viewModel.showContactsSettings ? View.VISIBLE : View.GONE}"
linphone:title="@{@string/settings_contacts_title}" />
<include
layout="@layout/settings_widget_basic"
linphone:listener="@{viewModel.advancedSettingsListener}"
android:visibility="@{viewModel.showAdvancedSettings ? View.VISIBLE : View.GONE}"
linphone:title="@{@string/settings_advanced_title}" />
</LinearLayout>

View file

@ -16,6 +16,9 @@
<variable
name="remoteProvisioningClickListener"
type="android.view.View.OnClickListener"/>
<variable
name="viewModel"
type="org.linphone.activities.assistant.viewmodels.WelcomeViewModel" />
</data>
<RelativeLayout
@ -65,6 +68,7 @@
<TextView
android:id="@+id/account_creation"
android:visibility="@{viewModel.showCreateAccount ? View.VISIBLE : View.GONE}"
android:onClick="@{createAccountClickListener}"
style="@style/button_font"
android:gravity="center"
@ -80,6 +84,7 @@
<TextView
android:id="@+id/account_connection"
android:visibility="@{viewModel.showLinphoneLogin ? View.VISIBLE : View.GONE}"
android:onClick="@{accountLoginClickListener}"
style="@style/button_font"
android:gravity="center"
@ -95,6 +100,7 @@
<TextView
android:id="@+id/generic_connection"
android:visibility="@{viewModel.showGenericLogin ? View.VISIBLE : View.GONE}"
android:onClick="@{genericAccountLoginClickListener}"
style="@style/button_font"
android:gravity="center"
@ -110,6 +116,7 @@
<TextView
android:id="@+id/remote_configuration"
android:visibility="@{viewModel.showRemoteProvisioning ? View.VISIBLE : View.GONE}"
android:onClick="@{remoteProvisioningClickListener}"
style="@style/button_font"
android:gravity="center"

View file

@ -69,6 +69,7 @@
<TextView
style="@style/settings_category_font"
android:text="@string/settings_accounts_title"
android:visibility="@{viewModel.showAccountSettings ? View.VISIBLE : View.GONE}"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_width="wrap_content"
@ -78,6 +79,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="@{viewModel.showAccountSettings ? View.VISIBLE : View.GONE}"
linphone:entries="@{viewModel.accounts}"
linphone:layout="@{@layout/settings_account_cell}"/>
@ -93,41 +95,48 @@
<include
layout="@layout/settings_widget_basic"
linphone:listener="@{viewModel.tunnelSettingsListener}"
android:visibility="@{viewModel.tunnelAvailable ? View.VISIBLE : View.GONE}"
android:visibility="@{viewModel.showTunnelSettings ? View.VISIBLE : View.GONE}"
linphone:title="@{@string/settings_tunnel_title}" />
<include
layout="@layout/settings_widget_basic"
android:visibility="@{viewModel.showAudioSettings ? View.VISIBLE : View.GONE}"
linphone:listener="@{viewModel.audioSettingsListener}"
linphone:title="@{@string/settings_audio_title}" />
<include
layout="@layout/settings_widget_basic"
android:visibility="@{viewModel.showVideoSettings ? View.VISIBLE : View.GONE}"
linphone:listener="@{viewModel.videoSettingsListener}"
linphone:title="@{@string/settings_video_title}" />
<include
layout="@layout/settings_widget_basic"
android:visibility="@{viewModel.showCallSettings ? View.VISIBLE : View.GONE}"
linphone:listener="@{viewModel.callSettingsListener}"
linphone:title="@{@string/settings_call_title}" />
<include
layout="@layout/settings_widget_basic"
android:visibility="@{viewModel.showChatSettings ? View.VISIBLE : View.GONE}"
linphone:listener="@{viewModel.chatSettingsListener}"
linphone:title="@{@string/settings_chat_title}" />
<include
layout="@layout/settings_widget_basic"
android:visibility="@{viewModel.showNetworkSettings ? View.VISIBLE : View.GONE}"
linphone:listener="@{viewModel.networkSettingsListener}"
linphone:title="@{@string/settings_network_title}" />
<include
layout="@layout/settings_widget_basic"
android:visibility="@{viewModel.showContactsSettings ? View.VISIBLE : View.GONE}"
linphone:listener="@{viewModel.contactsSettingsListener}"
linphone:title="@{@string/settings_contacts_title}" />
<include
layout="@layout/settings_widget_basic"
android:visibility="@{viewModel.showAdvancedSettings ? View.VISIBLE : View.GONE}"
linphone:listener="@{viewModel.advancedSettingsListener}"
linphone:title="@{@string/settings_advanced_title}" />

View file

@ -34,6 +34,7 @@
android:id="@+id/main_account"
android:onClick="@{() -> viewModel.defaultAccount.accountsSettingsListener.onAccountClicked(viewModel.defaultAccount.identity)}"
android:enabled="@{viewModel.defaultAccountFound}"
android:visibility="@{viewModel.showAccounts ? View.VISIBLE : View.GONE}"
android:layout_width="match_parent"
android:layout_height="70dp"
android:background="?attr/lightToolbarBackgroundColor">
@ -91,6 +92,7 @@
</RelativeLayout>
<LinearLayout
android:visibility="@{viewModel.showAccounts ? View.VISIBLE : View.GONE}"
android:id="@+id/additional_accounts"
android:layout_below="@id/main_account"
android:layout_width="match_parent"
@ -226,6 +228,7 @@
<LinearLayout
android:id="@+id/side_menu_quit"
android:onClick="@{quitClickListener}"
android:visibility="@{viewModel.showQuit ? View.VISIBLE : View.GONE}"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"

View file

@ -32,6 +32,7 @@
android:layout_height="match_parent"
android:layout_weight="1"
android:onClick="@{historyClickListener}"
android:visibility="@{viewModel.showHistory ? View.VISIBLE : View.GONE}"
android:background="@drawable/footer_button">
<ImageView
@ -66,6 +67,7 @@
android:layout_height="match_parent"
android:layout_weight="1"
android:onClick="@{contactsClickListener}"
android:visibility="@{viewModel.showContacts ? View.VISIBLE : View.GONE}"
android:background="@drawable/footer_button">
<ImageView
@ -90,6 +92,7 @@
android:layout_height="match_parent"
android:layout_weight="1"
android:onClick="@{dialerClickListener}"
android:visibility="@{viewModel.showDialer ? View.VISIBLE : View.GONE}"
android:background="@drawable/footer_button">
<ImageView
@ -114,6 +117,7 @@
android:layout_height="match_parent"
android:layout_weight="1"
android:onClick="@{chatClickListener}"
android:visibility="@{viewModel.showChat ? View.VISIBLE : View.GONE}"
android:background="@drawable/footer_button">
<ImageView