diff --git a/app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt b/app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt index df0adc0ecc..0185d27a66 100644 --- a/app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt @@ -91,13 +91,13 @@ import com.nextcloud.talk.adapters.messages.IncomingPreviewMessageViewHolder import com.nextcloud.talk.adapters.messages.IncomingTextMessageViewHolder import com.nextcloud.talk.adapters.messages.IncomingVoiceMessageViewHolder import com.nextcloud.talk.adapters.messages.MessagePayload +import com.nextcloud.talk.adapters.messages.OutcomingDeckCardViewHolder import com.nextcloud.talk.adapters.messages.OutcomingLinkPreviewMessageViewHolder import com.nextcloud.talk.adapters.messages.OutcomingLocationMessageViewHolder import com.nextcloud.talk.adapters.messages.OutcomingPollMessageViewHolder import com.nextcloud.talk.adapters.messages.OutcomingPreviewMessageViewHolder import com.nextcloud.talk.adapters.messages.OutcomingTextMessageViewHolder import com.nextcloud.talk.adapters.messages.OutcomingVoiceMessageViewHolder -import com.nextcloud.talk.adapters.messages.OutcomingDeckCardViewHolder import com.nextcloud.talk.adapters.messages.PreviewMessageInterface import com.nextcloud.talk.adapters.messages.PreviewMessageViewHolder import com.nextcloud.talk.adapters.messages.SystemMessageInterface @@ -114,6 +114,7 @@ import com.nextcloud.talk.chat.viewmodels.ChatViewModel import com.nextcloud.talk.chat.viewmodels.MessageInputViewModel import com.nextcloud.talk.conversationinfo.ConversationInfoActivity import com.nextcloud.talk.conversationlist.ConversationsListActivity +import com.nextcloud.talk.data.network.NetworkMonitor import com.nextcloud.talk.data.user.model.User import com.nextcloud.talk.databinding.ActivityChatBinding import com.nextcloud.talk.events.UserMentionClickEvent @@ -236,6 +237,9 @@ class ChatActivity : @Inject lateinit var viewModelFactory: ViewModelProvider.Factory + @Inject + lateinit var networkMonitor: NetworkMonitor + lateinit var chatViewModel: ChatViewModel lateinit var messageInputViewModel: MessageInputViewModel @@ -2930,6 +2934,14 @@ class ChatActivity : conversationVoiceCallMenuItem = menu.findItem(R.id.conversation_voice_call) conversationVideoMenuItem = menu.findItem(R.id.conversation_video_call) + this.lifecycleScope.launch { + networkMonitor.isOnline.onEach { isOnline -> + conversationVoiceCallMenuItem?.isVisible = isOnline + searchItem?.isVisible = isOnline + conversationVideoMenuItem?.isVisible = isOnline + }.collect() + } + if (CapabilitiesUtil.hasSpreedFeatureCapability(spreedCapabilities, SpreedFeatures.SILENT_CALL)) { Handler().post { findViewById(R.id.conversation_voice_call)?.setOnLongClickListener { diff --git a/app/src/main/java/com/nextcloud/talk/chat/MessageInputFragment.kt b/app/src/main/java/com/nextcloud/talk/chat/MessageInputFragment.kt index 79af0a4f53..4f7e811b51 100644 --- a/app/src/main/java/com/nextcloud/talk/chat/MessageInputFragment.kt +++ b/app/src/main/java/com/nextcloud/talk/chat/MessageInputFragment.kt @@ -227,17 +227,15 @@ class MessageInputFragment : Fragment() { }) } - binding.fragmentMessageInputView.attachmentButton.isEnabled = true - binding.fragmentMessageInputView.recordAudioButton.isEnabled = true - binding.fragmentMessageInputView.messageInput.isEnabled = true + binding.fragmentMessageInputView.attachmentButton.visibility = View.VISIBLE + binding.fragmentMessageInputView.recordAudioButton.visibility = View.VISIBLE } else { + binding.fragmentMessageInputView.attachmentButton.visibility = View.INVISIBLE + binding.fragmentMessageInputView.recordAudioButton.visibility = View.INVISIBLE binding.fragmentConnectionLost.clearAnimation() binding.fragmentConnectionLost.visibility = View.GONE binding.fragmentConnectionLost.setBackgroundColor(resources.getColor(R.color.hwSecurityRed)) - // binding.fragmentConnectionLost.text = getString(R.string.connection_lost_sent_messages_are_queued) binding.fragmentConnectionLost.visibility = View.VISIBLE - binding.fragmentMessageInputView.attachmentButton.isEnabled = false - binding.fragmentMessageInputView.recordAudioButton.isEnabled = false } } diff --git a/app/src/main/java/com/nextcloud/talk/conversationlist/ConversationsListActivity.kt b/app/src/main/java/com/nextcloud/talk/conversationlist/ConversationsListActivity.kt index b55729540e..98cadb2181 100644 --- a/app/src/main/java/com/nextcloud/talk/conversationlist/ConversationsListActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/conversationlist/ConversationsListActivity.kt @@ -21,8 +21,6 @@ import android.content.Intent import android.content.pm.PackageManager import android.graphics.drawable.ColorDrawable import android.graphics.drawable.Drawable -import android.net.ConnectivityManager -import android.net.NetworkCapabilities import android.net.Uri import android.os.Build import android.os.Bundle @@ -43,6 +41,7 @@ import androidx.annotation.OptIn import androidx.appcompat.app.AlertDialog import androidx.appcompat.widget.SearchView import androidx.core.view.MenuItemCompat +import androidx.core.view.isVisible import androidx.fragment.app.DialogFragment import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.lifecycleScope @@ -136,6 +135,7 @@ import io.reactivex.disposables.Disposable import io.reactivex.schedulers.Schedulers import io.reactivex.subjects.BehaviorSubject import kotlinx.coroutines.flow.collect +import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.launch import org.apache.commons.lang3.builder.CompareToBuilder @@ -893,26 +893,9 @@ class ConversationsListActivity : } private fun handleUI(show: Boolean) { - if (show) { - binding.floatingActionButton.isEnabled = true - binding.searchText.isEnabled = true - binding.searchText.hint = getString(R.string.appbar_search_in, getString(R.string.nc_app_product_name)) - } else { - binding.floatingActionButton.isEnabled = false - binding.searchText.isEnabled = false - binding.searchText.hint = getString(R.string.nc_common_disabled) - } - } - - @Suppress("ReturnCount") - private fun isNetworkAvailable(context: Context): Boolean { - val connectivityManager = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager - val network = connectivityManager.activeNetwork ?: return false - val capabilities = connectivityManager.getNetworkCapabilities(network) ?: return false - return capabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI) || - capabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR) || - capabilities.hasTransport(NetworkCapabilities.TRANSPORT_VPN) || - capabilities.hasTransport(NetworkCapabilities.TRANSPORT_ETHERNET) + binding.floatingActionButton.isEnabled = show + binding.searchText.isEnabled = show + binding.searchText.isVisible = show } private fun sortConversations(conversationItems: MutableList>) { @@ -1349,20 +1332,24 @@ class ConversationsListActivity : } override fun onItemLongClick(position: Int) { - if (showShareToScreen) { - Log.d(TAG, "sharing to multiple rooms not yet implemented. onItemLongClick is ignored.") - } else { - val clickedItem: Any? = adapter!!.getItem(position) - if (clickedItem != null && clickedItem is ConversationItem) { - val conversation = clickedItem.model - conversationsListBottomDialog = ConversationsListBottomDialog( - this, - userManager.currentUser.blockingGet(), - conversation - ) - conversationsListBottomDialog!!.show() + this.lifecycleScope.launch { + if (showShareToScreen || !networkMonitor.isOnline.first()) { + Log.d(TAG, "sharing to multiple rooms not yet implemented. onItemLongClick is ignored.") + } else { + val clickedItem: Any? = adapter!!.getItem(position) + if (clickedItem != null && clickedItem is ConversationItem) { + val conversation = clickedItem.model + conversationsListBottomDialog = ConversationsListBottomDialog( + this@ConversationsListActivity, + userManager.currentUser.blockingGet(), + conversation + ) + conversationsListBottomDialog!!.show() + } } + } + } @Suppress("Detekt.TooGenericExceptionCaught") diff --git a/app/src/main/java/com/nextcloud/talk/ui/dialog/ChooseAccountDialogFragment.java b/app/src/main/java/com/nextcloud/talk/ui/dialog/ChooseAccountDialogFragment.java index 8e53821479..86d02a0ca7 100644 --- a/app/src/main/java/com/nextcloud/talk/ui/dialog/ChooseAccountDialogFragment.java +++ b/app/src/main/java/com/nextcloud/talk/ui/dialog/ChooseAccountDialogFragment.java @@ -10,7 +10,11 @@ import android.annotation.SuppressLint; import android.app.Dialog; +import android.content.Context; import android.content.Intent; +import android.net.ConnectivityManager; +import android.net.Network; +import android.net.NetworkCapabilities; import android.net.Uri; import android.os.Bundle; import android.util.Log; @@ -261,6 +265,29 @@ private void themeViews() { viewThemeUtils.dialog.colorDialogMenuText(binding.manageSettings); } + // Would have preferred to use NetworkMonitor but java with kotlin flows is ugly + public static boolean isNetworkAvailable(Context context) { + ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); + if (connectivityManager == null) { + return false; + } + + Network network = connectivityManager.getActiveNetwork(); + if (network == null) { + return false; + } + + NetworkCapabilities capabilities = connectivityManager.getNetworkCapabilities(network); + if (capabilities == null) { + return false; + } + + return capabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI) || + capabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR) || + capabilities.hasTransport(NetworkCapabilities.TRANSPORT_VPN) || + capabilities.hasTransport(NetworkCapabilities.TRANSPORT_ETHERNET); + } + private void loadCurrentStatus(User user) { String credentials = ApiUtils.getCredentials(user.getUsername(), user.getToken()); @@ -316,6 +343,10 @@ private void prepareViews() { } binding.accountsList.setHasFixedSize(true); binding.accountsList.setAdapter(adapter); + + if (!isNetworkAvailable(getContext())) { + binding.addAccount.setVisibility(View.GONE); + } } public static ChooseAccountDialogFragment newInstance() {