Skip to content

Commit

Permalink
Disabled more stuff
Browse files Browse the repository at this point in the history
Signed-off-by: rapterjet2004 <[email protected]>
  • Loading branch information
rapterjet2004 committed Nov 5, 2024
1 parent 6ff7f74 commit 09afb91
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 41 deletions.
14 changes: 13 additions & 1 deletion app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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<View?>(R.id.conversation_voice_call)?.setOnLongClickListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<AbstractFlexibleItem<*>>) {
Expand Down Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());

Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 09afb91

Please sign in to comment.