Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Migrating from the MaterialPreferences library to native #3063

Merged
merged 6 commits into from
Jun 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ configurations.all {
}

dependencies {
implementation 'androidx.preference:preference-ktx:1.2.0'
detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:1.23.0")

implementation fileTree(include: ['*'], dir: 'libs')
Expand Down Expand Up @@ -236,7 +237,6 @@ dependencies {
implementation 'net.orange-box.storebox:storebox-lib:1.4.0'
implementation 'eu.davidea:flexible-adapter:5.1.0'
implementation 'eu.davidea:flexible-adapter-ui:1.0.0'
implementation 'com.yarolegovich:mp:1.1.6'
implementation 'me.zhanghai.android.effortlesspermissions:library:1.1.0'
implementation 'org.apache.commons:commons-lang3:3.12.0'
implementation 'com.github.wooplr:Spotlight:1.3'
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package com.nextcloud.talk.conversationinfo

import android.annotation.SuppressLint
import android.content.Intent
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.widget.Toast
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.widget.SwitchCompat
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.nextcloud.talk.R
import com.nextcloud.talk.data.user.model.User
Expand All @@ -34,60 +32,55 @@ class GuestAccessHelper(
private val context = activity.context

fun setupGuestAccess() {
val guestAccessAllowSwitch = (
binding.guestAccessView.guestAccessAllowSwitch.findViewById<View>(R.id.mp_checkable)
as SwitchCompat
)
val guestAccessPasswordSwitch = (
binding.guestAccessView.guestAccessPasswordSwitch.findViewById<View>(R.id.mp_checkable)
as SwitchCompat
)

if (conversation.canModerate(conversationUser)) {
binding.guestAccessView.guestAccessSettings.visibility = View.VISIBLE
} else {
return
binding.guestAccessView.guestAccessSettings.visibility = View.GONE
}

if (conversation.type == Conversation.ConversationType.ROOM_PUBLIC_CALL) {
guestAccessAllowSwitch.isChecked = true
binding.guestAccessView.allowGuestsSwitch.isChecked = true
showAllOptions()
if (conversation.hasPassword) {
guestAccessPasswordSwitch.isChecked = true
binding.guestAccessView.passwordProtectionSwitch.isChecked = true
}
} else {
guestAccessAllowSwitch.isChecked = false
binding.guestAccessView.allowGuestsSwitch.isChecked = false
hideAllOptions()
}

binding.guestAccessView.guestAccessAllowSwitch.setOnClickListener {
binding.guestAccessView.guestAccessSettingsAllowGuest.setOnClickListener {
val isChecked = binding.guestAccessView.allowGuestsSwitch.isChecked
binding.guestAccessView.allowGuestsSwitch.isChecked = !isChecked
conversationsRepository.allowGuests(
conversation.token!!,
!guestAccessAllowSwitch.isChecked
!isChecked
).subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()).subscribe(AllowGuestsResultObserver())
}

binding.guestAccessView.guestAccessPasswordSwitch.setOnClickListener {
if (guestAccessPasswordSwitch.isChecked) {
binding.guestAccessView.guestAccessSettingsPasswordProtection.setOnClickListener {
val isChecked = binding.guestAccessView.passwordProtectionSwitch.isChecked
binding.guestAccessView.passwordProtectionSwitch.isChecked = !isChecked
if (isChecked) {
conversationsRepository.password("", conversation.token!!).subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()).subscribe(PasswordResultObserver(false))
} else {
showPasswordDialog(guestAccessPasswordSwitch)
showPasswordDialog()
}
}

binding.guestAccessView.guestAccessCopyUrl.setOnClickListener {
binding.guestAccessView.shareConversationButton.setOnClickListener {
shareUrl()
}

binding.guestAccessView.guestAccessResendInvitations.setOnClickListener {
binding.guestAccessView.resendInvitationsButton.setOnClickListener {
conversationsRepository.resendInvitations(conversation.token!!).subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()).subscribe(ResendInvitationsObserver())
}
}

@SuppressLint("InflateParams")
private fun showPasswordDialog(guestAccessPasswordSwitch: SwitchCompat) {
private fun showPasswordDialog() {
val builder = MaterialAlertDialogBuilder(activity)
builder.apply {
val dialogPassword = DialogPasswordBinding.inflate(LayoutInflater.from(context))
Expand All @@ -102,7 +95,7 @@ class GuestAccessHelper(
.subscribe(PasswordResultObserver(true))
}
setNegativeButton(R.string.nc_cancel) { _, _ ->
guestAccessPasswordSwitch.isChecked = false
binding.guestAccessView.passwordProtectionSwitch.isChecked = false
}
}
createDialog(builder)
Expand Down Expand Up @@ -179,10 +172,7 @@ class GuestAccessHelper(
}

override fun onComplete() {
(
binding.guestAccessView.guestAccessAllowSwitch.findViewById<View>(R.id.mp_checkable)
as SwitchCompat
).isChecked = allowGuestsResult.allow
binding.guestAccessView.allowGuestsSwitch.isChecked = allowGuestsResult.allow
if (allowGuestsResult.allow) {
showAllOptions()
} else {
Expand All @@ -194,17 +184,17 @@ class GuestAccessHelper(
}

private fun showAllOptions() {
binding.guestAccessView.guestAccessPasswordSwitch.visibility = View.VISIBLE
binding.guestAccessView.guestAccessCopyUrl.visibility = View.VISIBLE
binding.guestAccessView.guestAccessSettingsPasswordProtection.visibility = View.VISIBLE
binding.guestAccessView.shareConversationButton.visibility = View.VISIBLE
if (conversationUser.capabilities?.spreedCapability?.features?.contains("sip-support") == true) {
binding.guestAccessView.guestAccessResendInvitations.visibility = View.VISIBLE
binding.guestAccessView.resendInvitationsButton.visibility = View.VISIBLE
}
}

private fun hideAllOptions() {
binding.guestAccessView.guestAccessPasswordSwitch.visibility = View.GONE
binding.guestAccessView.guestAccessCopyUrl.visibility = View.GONE
binding.guestAccessView.guestAccessResendInvitations.visibility = View.GONE
binding.guestAccessView.guestAccessSettingsPasswordProtection.visibility = View.GONE
binding.guestAccessView.shareConversationButton.visibility = View.GONE
binding.guestAccessView.resendInvitationsButton.visibility = View.GONE
}

inner class PasswordResultObserver(private val setPassword: Boolean) :
Expand All @@ -225,12 +215,7 @@ class GuestAccessHelper(
}

override fun onComplete() {
val guestAccessPasswordSwitch = (
binding.guestAccessView.guestAccessPasswordSwitch.findViewById<View>(R.id.mp_checkable)
as SwitchCompat
)
guestAccessPasswordSwitch.isChecked = passwordResult.passwordSet && setPassword

binding.guestAccessView.passwordProtectionSwitch.isChecked = passwordResult.passwordSet && setPassword
if (passwordResult.passwordIsWeak) {
val builder = MaterialAlertDialogBuilder(activity)
builder.apply {
Expand Down
Loading