Skip to content
Snippets Groups Projects
Commit 39863518 authored by Vitalii Nikitchyn's avatar Vitalii Nikitchyn
Browse files

navigation clean up

Change-Id: I1ff25fea326c06a8ee85c91b9a41e1fa807eb68b
parent 2b0924a0
No related branches found
No related tags found
No related merge requests found
Showing
with 230 additions and 382 deletions
......@@ -72,4 +72,8 @@ class AboutFragment : Fragment() {
}
}
}
companion object {
val TAG = AboutFragment::class.simpleName!!
}
}
\ No newline at end of file
......@@ -18,15 +18,12 @@ package cx.ring.account
import android.os.Bundle
import android.view.*
import android.view.ViewTreeObserver.OnScrollChangedListener
import android.widget.FrameLayout
import android.widget.LinearLayout
import androidx.annotation.StringRes
import androidx.fragment.app.*
import androidx.recyclerview.widget.RecyclerView
import androidx.viewpager2.adapter.FragmentStateAdapter
import androidx.viewpager2.widget.ViewPager2
import com.google.android.material.tabs.TabLayout
import com.google.android.material.tabs.TabLayoutMediator
import cx.ring.R
import cx.ring.contactrequests.BlockListFragment
......@@ -47,7 +44,6 @@ import net.jami.utils.DonationUtils
class AccountEditionFragment : BaseSupportFragment<AccountEditionPresenter, AccountEditionView>(),
AccountEditionView {
private var mBinding: FragAccountSettingsBinding? = null
private var mAccountId: String? = null
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View =
FragAccountSettingsBinding.inflate(inflater, container, false).apply {
......@@ -69,54 +65,26 @@ class AccountEditionFragment : BaseSupportFragment<AccountEditionPresenter, Acco
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
setHasOptionsMenu(true)
super.onViewCreated(view, savedInstanceState)
mAccountId = requireArguments().getString(ACCOUNT_ID_KEY)
initViewPager(mAccountId!!, false)
//presenter.init(requireArguments().getString(ACCOUNT_ID_KEY)!!)
initViewPager(requireArguments().getString(ACCOUNT_ID_KEY)!!)
mBinding?.fragmentContainer?.viewTreeObserver?.addOnScrollChangedListener {
setupElevation()
}
}
private fun updateAdapter(tabLayout: TabLayout, viewPager: ViewPager2, accountId: String, isJami: Boolean) {
viewPager.adapter = PreferencesPagerAdapter(this@AccountEditionFragment, accountId, isJami)
TabLayoutMediator(tabLayout, viewPager){ tab, position ->
tab.text = context?.getString(getSIPPanelTitle(position))
}.attach()
}
override fun displaySummary(accountId: String) {
//toggleView(accountId, true)
val fragmentManager = childFragmentManager
val existingFragment = fragmentManager.findFragmentByTag(JamiAccountSummaryFragment.TAG)
val args = Bundle().apply { putString(ACCOUNT_ID_KEY, accountId) }
if (existingFragment == null) {
val fragment = JamiAccountSummaryFragment().apply {
arguments = args
}
fragmentManager.beginTransaction()
.add(R.id.fragment_container, fragment, JamiAccountSummaryFragment.TAG)
.commitAllowingStateLoss()
} else {
if (existingFragment is JamiAccountSummaryFragment) {
if (!existingFragment.isStateSaved) existingFragment.arguments = args
existingFragment.setAccount(accountId)
}
}
}
override fun displaySIPView(accountId: String) {
//toggleView(accountId, false)
}
override fun initViewPager(accountId: String, isJami: Boolean) {
override fun initViewPager(accountId: String) {
mBinding?.apply {
pager.offscreenPageLimit = 4
updateAdapter(slidingTabs, pager, accountId, isJami)
pager.adapter = PreferencesPagerAdapter(this@AccountEditionFragment, accountId)
TabLayoutMediator(slidingTabs, pager) { tab, position ->
tab.text = context?.getString(getSIPPanelTitle(position))
}.attach()
}
val existingFragment = childFragmentManager.findFragmentByTag(BlockListFragment.TAG) as BlockListFragment?
val existingFragment = childFragmentManager.findFragmentByTag(BlockListFragment.TAG) as? BlockListFragment
if (existingFragment != null) {
if (!existingFragment.isStateSaved)
existingFragment.arguments = Bundle().apply { putString(ACCOUNT_ID_KEY, accountId) }
......@@ -139,39 +107,13 @@ class AccountEditionFragment : BaseSupportFragment<AccountEditionPresenter, Acco
}
}
// private fun toggleView(accountId: String?, isJami: Boolean) {
// mAccountId = accountId
// mAccountIsJami = isJami
// mBinding?.apply {
// slidingTabs.visibility = if (isJami) View.GONE else View.VISIBLE
// pager.visibility = if (isJami) View.GONE else View.VISIBLE
// fragmentContainer.visibility = if (isJami) View.VISIBLE else View.GONE
// }
// }
override fun exit() {
activity?.onBackPressedDispatcher?.onBackPressed()
}
private class PreferencesPagerAdapter(
f: Fragment,
private val accountId: String,
private val isJamiAccount: Boolean
private val accountId: String
) : FragmentStateAdapter(f) {
override fun getItemCount(): Int = if (isJamiAccount) 3 else 4
override fun createFragment(position: Int): Fragment =
if (isJamiAccount) getJamiPanel(position) else getSIPPanel(position)
private fun getJamiPanel(position: Int): Fragment = when (position) {
0 -> fragmentWithBundle(GeneralAccountFragment())
1 -> fragmentWithBundle(MediaPreferenceFragment())
2 -> fragmentWithBundle(AdvancedAccountFragment())
3 -> fragmentWithBundle(PluginsListSettingsFragment())
else -> throw IllegalArgumentException()
}
override fun getItemCount(): Int = 4
private fun getSIPPanel(position: Int): Fragment = when (position) {
override fun createFragment(position: Int): Fragment = when (position) {
0 -> GeneralAccountFragment.newInstance(accountId)
1 -> MediaPreferenceFragment.newInstance(accountId)
2 -> fragmentWithBundle(AdvancedAccountFragment())
......@@ -197,7 +139,7 @@ class AccountEditionFragment : BaseSupportFragment<AccountEditionPresenter, Acco
}
companion object {
private val TAG = AccountEditionFragment::class.simpleName
val TAG = AccountEditionFragment::class.simpleName!!
val ACCOUNT_ID_KEY = AccountEditionFragment::class.qualifiedName + "accountId"
val ACCOUNT_HAS_PASSWORD_KEY = AccountEditionFragment::class.qualifiedName + "hasPassword"
private const val SCROLL_DIRECTION_UP = -1
......
......@@ -93,6 +93,6 @@ class JamiAccountConnectFragment : BaseSupportFragment<JamiAccountConnectPresent
}
companion object {
val TAG = HomeAccountCreationFragment::class.simpleName!!
val TAG = JamiAccountConnectFragment::class.simpleName!!
}
}
\ No newline at end of file
/*
* Copyright (C) 2004-2024 Savoir-faire Linux Inc.
*
* 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 <https://www.gnu.org/licenses/>.
*/
package cx.ring.account
import androidx.annotation.StringRes
import androidx.annotation.DrawableRes
class SettingItem(
@StringRes val titleRes: Int,
@DrawableRes val imageId: Int,
private val mOnClick: Runnable
) {
fun onClick() {
mOnClick.run()
}
}
\ No newline at end of file
......@@ -429,30 +429,25 @@ class HomeActivity : AppCompatActivity(), ContactPickerFragment.OnContactedPicke
// else we add it
conversationBackPressedCallback.isEnabled = true
supportFragmentManager.beginTransaction()
.replace(R.id.conversation, conversation, ConversationFragment::class.java.simpleName)
.replace(R.id.conversation, conversation, ConversationFragment.TAG)
.runOnCommit {
intent?.let { conversation.handleShareIntent(it) }
}
.commit()
}.commit()
fConversation = conversation
mBinding!!.panel.openPane()
}
private fun presentTrustRequestFragment(accountId: String) {
mNotificationService.cancelTrustRequestNotification(accountId)
}
fun goToAdvancedSettings() {
if (frameContent is SettingsFragment) {
return
}
val content = SettingsFragment()
frameContent = content
val fragment = SettingsFragment()
frameContent = fragment
supportFragmentManager
.beginTransaction()
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
.replace(R.id.frame, content, SETTINGS_TAG)
.addToBackStack(SETTINGS_TAG)
.replace(R.id.frame, fragment, SettingsFragment.TAG)
.addToBackStack(SettingsFragment.TAG)
.commit()
mBinding!!.frame.isVisible = true
}
......@@ -461,25 +456,21 @@ class HomeActivity : AppCompatActivity(), ContactPickerFragment.OnContactedPicke
if (frameContent is AboutFragment) {
return
}
val content = AboutFragment()
frameContent = content
val fragment = AboutFragment()
frameContent = fragment
mBinding!!.frame.isVisible = true
supportFragmentManager
.beginTransaction()
//.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out, android.R.animator.fade_in, android.R.animator.fade_out)
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
.replace(R.id.frame, content, ABOUT_TAG)
.addToBackStack(ABOUT_TAG)
.replace(R.id.frame, fragment, AboutFragment.TAG)
.addToBackStack(AboutFragment.TAG)
.commit()
}
/**
* Go to "account settings" parameters.
* Should be called only if an account is loaded.
*/
/** Go to "account settings" parameters. Should be called only if an account is loaded. */
fun goToAccountSettings() {
val account = mAccountService.currentAccount
if (account == null) {
Log.e(TAG, "No account loaded, cannot open \"Account settings\"")
return
......@@ -487,8 +478,7 @@ class HomeActivity : AppCompatActivity(), ContactPickerFragment.OnContactedPicke
if (account.needsMigration()) {
Log.d(TAG, "launchAccountMigrationActivity: Launch account migration activity")
val intent = Intent()
.setClass(this, AccountWizardActivity::class.java)
val intent = Intent(this, AccountWizardActivity::class.java)
.setData(
android.net.Uri.withAppendedPath(
ContentUri.ACCOUNTS_CONTENT_URI, account.accountId
......@@ -509,8 +499,8 @@ class HomeActivity : AppCompatActivity(), ContactPickerFragment.OnContactedPicke
frameContent = fragment
supportFragmentManager.beginTransaction()
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
.replace(R.id.frame, fragment, ACCOUNT_JAMI_TAG)
.addToBackStack(ACCOUNT_JAMI_TAG)
.replace(R.id.frame, fragment, JamiAccountSummaryFragment.TAG)
.addToBackStack(JamiAccountSummaryFragment.TAG)
.commit()
} else { //is SIP account --> display SIPView
......@@ -528,8 +518,8 @@ class HomeActivity : AppCompatActivity(), ContactPickerFragment.OnContactedPicke
frameContent = fragment
supportFragmentManager.beginTransaction()
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
.replace(R.id.frame, fragment, ACCOUNT_SIP_TAG)
.addToBackStack(ACCOUNT_SIP_TAG)
.replace(R.id.frame, fragment, AccountEditionFragment.TAG)
.addToBackStack(AccountEditionFragment.TAG)
.commit()
}
......@@ -587,11 +577,7 @@ class HomeActivity : AppCompatActivity(), ContactPickerFragment.OnContactedPicke
const val REQUEST_CODE_QR_CONVERSATION = 7
const val REQUEST_PERMISSION_CAMERA = 113
const val REQUEST_PERMISSION_READ_STORAGE = 114
const val ACCOUNT_JAMI_TAG = "Account_jami"
const val ACCOUNT_SIP_TAG = "Account_sip"
const val ABOUT_TAG = "About"
const val SETTINGS_TAG = "Prefs"
private const val CONVERSATIONS_CATEGORY = "conversations"
}
}
}
\ No newline at end of file
......@@ -1307,13 +1307,11 @@ class ConversationFragment : BaseSupportFragment<ConversationPresenter, Conversa
}
companion object {
private val TAG = ConversationFragment::class.simpleName
val TAG = ConversationFragment::class.simpleName
const val REQ_ADD_CONTACT = 42
const val KEY_PREFERENCE_PENDING_MESSAGE = "pendingMessage"
const val KEY_PREFERENCE_CONVERSATION_COLOR = "color"
@Deprecated("Use daemon feature")
const val KEY_PREFERENCE_CONVERSATION_LAST_READ = "lastRead"
const val KEY_PREFERENCE_CONVERSATION_SYMBOL = "symbol"
const val EXTRA_SHOW_MAP = "showMap"
private const val REQUEST_CODE_FILE_PICKER = 1000
private const val REQUEST_PERMISSION_CAMERA = 1001
......
......@@ -17,18 +17,14 @@
package cx.ring.fragments
import android.app.Activity
import android.content.Context
import android.content.DialogInterface
import android.content.Intent
import android.os.Bundle
import android.util.Log
import android.view.*
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.DefaultItemAnimator
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.snackbar.Snackbar
import cx.ring.R
import cx.ring.adapters.SmartListAdapter
import cx.ring.client.CallActivity
......@@ -41,23 +37,18 @@ import cx.ring.utils.TextUtils
import cx.ring.viewholders.SmartListViewHolder.SmartListListeners
import dagger.hilt.android.AndroidEntryPoint
import io.reactivex.rxjava3.disposables.CompositeDisposable
import io.reactivex.rxjava3.subjects.BehaviorSubject
import net.jami.model.Conversation
import net.jami.model.Conversation.ConversationActionCallback
import net.jami.model.Uri
import net.jami.services.AccountService
import net.jami.services.ConversationFacade
import net.jami.smartlist.SmartListPresenter
import net.jami.smartlist.SmartListView
import javax.inject.Inject
@AndroidEntryPoint
class SmartListFragment : BaseSupportFragment<SmartListPresenter, SmartListView>(),
SmartListListeners, ConversationActionCallback, SmartListView {
private var mSmartListAdapter: SmartListAdapter? = null
private var binding: FragSmartlistBinding? = null
private var mHomeFragment: HomeFragment? = null
override fun onSaveInstanceState(outState: Bundle) {
binding?.apply { outState.putBoolean(STATE_LOADING, loadingIndicator.isShown) }
......@@ -66,7 +57,7 @@ class SmartListFragment : BaseSupportFragment<SmartListPresenter, SmartListView>
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View =
FragSmartlistBinding.inflate(inflater, container, false).apply {
(confsList.itemAnimator as DefaultItemAnimator?)?.supportsChangeAnimations = false
(confsList.itemAnimator as? DefaultItemAnimator)?.supportsChangeAnimations = false
binding = this
}.root
......@@ -77,13 +68,6 @@ class SmartListFragment : BaseSupportFragment<SmartListPresenter, SmartListView>
binding = null
}
override fun onStart() {
super.onStart()
if (mHomeFragment == null)
mHomeFragment =
requireActivity().supportFragmentManager.findFragmentById(R.id.home_fragment) as HomeFragment?
}
override fun setLoading(loading: Boolean) {
binding!!.loadingIndicator.visibility = if (loading) View.VISIBLE else View.GONE
}
......@@ -110,18 +94,15 @@ class SmartListFragment : BaseSupportFragment<SmartListPresenter, SmartListView>
.setClass(context, CallActivity::class.java)
.setData(android.net.Uri.parse(selected.toString()))
startActivityForResult(intent, HomeActivity.REQUEST_CODE_CALL)
}
.show()
}.show()
}
override fun displayNoConversationMessage() {
binding!!.placeholder.visibility = View.VISIBLE
//(activity as HomeActivity).toggleConversationVisibility(false)
}
override fun hideNoConversationMessage() {
binding!!.placeholder.visibility = View.GONE
//(activity as HomeActivity).toggleConversationVisibility(true)
}
override fun displayConversationDialog(conversationItemViewModel: Conversation) {
......@@ -166,17 +147,18 @@ class SmartListFragment : BaseSupportFragment<SmartListPresenter, SmartListView>
mSmartListAdapter?.update(ConversationFacade.ConversationList())
}
override fun updateList(conversations: ConversationFacade.ConversationList, conversationFacade: ConversationFacade, parentDisposable: CompositeDisposable) {
//Log.w(TAG, "updateList ${conversations.publicDirectory.size} ${conversations.conversations.size}")
override fun updateList(
conversations: ConversationFacade.ConversationList,
conversationFacade: ConversationFacade,
parentDisposable: CompositeDisposable
) {
binding?.apply {
if (confsList.adapter == null) {
confsList.adapter = SmartListAdapter(conversations, this@SmartListFragment, conversationFacade, parentDisposable).apply {
mSmartListAdapter = this
}
confsList.adapter = SmartListAdapter(
conversations, this@SmartListFragment, conversationFacade, parentDisposable
).apply { mSmartListAdapter = this }
confsList.setHasFixedSize(true)
confsList.layoutManager = LinearLayoutManager(requireContext()).apply {
orientation = RecyclerView.VERTICAL
}
} else {
mSmartListAdapter?.update(conversations)
}
......@@ -204,7 +186,7 @@ class SmartListFragment : BaseSupportFragment<SmartListPresenter, SmartListView>
override fun goToConversation(accountId: String, conversationUri: Uri) {
Log.w(TAG, "goToConversation $accountId $conversationUri")
(mHomeFragment as HomeFragment).collapseSearchActionView()
(parentFragment as? HomeFragment)?.collapseSearchActionView()
(requireActivity() as HomeActivity).startConversation(accountId, conversationUri)
}
......@@ -218,7 +200,7 @@ class SmartListFragment : BaseSupportFragment<SmartListPresenter, SmartListView>
}
override fun scrollToTop() {
binding?.apply { confsList.scrollToPosition(0) }
binding?.confsList?.scrollToPosition(0)
}
override fun onItemClick(item: Conversation) {
......@@ -232,7 +214,6 @@ class SmartListFragment : BaseSupportFragment<SmartListPresenter, SmartListView>
companion object {
val TAG = SmartListFragment::class.simpleName!!
private val STATE_LOADING = "$TAG.STATE_LOADING"
private const val SCROLL_DIRECTION_UP = -1
}
}
\ No newline at end of file
......@@ -304,6 +304,7 @@ class SettingsFragment :
//=============== AppBar management end ===================
companion object {
val TAG = SettingsFragment::class.simpleName!!
const val NOTIFICATION_PRIVATE = 0
const val NOTIFICATION_PUBLIC = 1
const val NOTIFICATION_SECRET = 2
......
......@@ -156,6 +156,8 @@ along with this program; if not, write to the Free Software
android:id="@+id/searchResult"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
android:orientation="vertical"
android:clipToPadding="false"
android:divider="@null"
android:paddingBottom="8dp"
......
......@@ -22,8 +22,7 @@ along with this program; if not, write to the Free Software
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:fitsSystemWindows="true"
>
android:fitsSystemWindows="true">
<!-- Will be displayed when no accounts are available -->
<LinearLayout
......@@ -41,7 +40,8 @@ along with this program; if not, write to the Free Software
android:layout_width="128dp"
android:layout_height="128dp"
android:src="@drawable/baseline_forum_24"
app:tint="@color/darker_gray" />
app:tint="@color/darker_gray"
android:contentDescription="@string/conversation_placeholder" />
<TextView
android:layout_width="wrap_content"
......@@ -60,7 +60,7 @@ along with this program; if not, write to the Free Software
android:indeterminate="true"
tools:visibility="gone" />
<!-- Will display loaded accounts -->
<!-- Display loaded accounts -->
<!-- paddingTop allows to have list items under searchbar and invitation received toolbar -->
<!-- TODO: Determine if layout_constraintTop_toBottomOf is still needed -->
<androidx.recyclerview.widget.RecyclerView
......@@ -69,6 +69,8 @@ along with this program; if not, write to the Free Software
android:layout_height="match_parent"
android:layout_marginStart="0dp"
android:clipToPadding="false"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
android:orientation="vertical"
android:divider="@null"
android:elevation="2dp"
android:paddingBottom="8dp"
......@@ -76,4 +78,4 @@ along with this program; if not, write to the Free Software
tools:listitem="@layout/item_smartlist"
tools:visibility="visible" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
\ No newline at end of file
......@@ -31,6 +31,7 @@ class AccountEditionPresenter @Inject constructor(
fun init(accountId: String) {
val account = mAccountService.getAccount(accountId)
account?.let { init(it) }
mCompositeDisposable.add(mAccountService
.currentAccountSubject
.observeOn(mUiScheduler)
......@@ -43,12 +44,6 @@ class AccountEditionPresenter @Inject constructor(
fun init(account: Account) {
mAccount = account
val view = view ?: return
if (account.isJami) {
view.displaySummary(account.accountId)
} else {
view.displaySIPView(account.accountId)
}
view.initViewPager(account.accountId, account.isJami)
view?.initViewPager(account.accountId)
}
}
\ No newline at end of file
......@@ -17,9 +17,6 @@
package net.jami.account
interface AccountEditionView {
fun exit()
fun displaySummary(accountId: String)
fun initViewPager(accountId: String, isJami: Boolean)
fun initViewPager(accountId: String)
fun goToBlackList(accountId: String)
fun displaySIPView(accountId: String)
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment