Add labs flag for polls.

This commit is contained in:
Onuray Sahin 2021-12-07 11:53:52 +03:00
parent 23ad4e5a27
commit 1df6b33981
8 changed files with 42 additions and 0 deletions

View File

@ -48,4 +48,8 @@ class UserPreferencesProvider @Inject constructor(private val vectorPreferences:
fun shouldShowAvatarDisplayNameChanges(): Boolean {
return vectorPreferences.showAvatarDisplayNameChangeMessages()
}
fun shouldShowPolls(): Boolean {
return vectorPreferences.labsEnablePolls()
}
}

View File

@ -34,9 +34,11 @@ import android.widget.ImageButton
import android.widget.LinearLayout
import android.widget.PopupWindow
import androidx.core.view.doOnNextLayout
import androidx.core.view.isVisible
import com.amulyakhare.textdrawable.TextDrawable
import com.amulyakhare.textdrawable.util.ColorGenerator
import im.vector.app.R
import im.vector.app.core.extensions.exhaustive
import im.vector.app.core.extensions.getMeasurements
import im.vector.app.core.utils.PERMISSIONS_EMPTY
import im.vector.app.core.utils.PERMISSIONS_FOR_PICKING_CONTACT
@ -121,6 +123,20 @@ class AttachmentTypeSelectorView(context: Context,
}
}
fun setAttachmentVisibility(type: Type, isVisible: Boolean) {
when (type) {
Type.CAMERA -> views.attachmentCameraButtonContainer
Type.GALLERY -> views.attachmentGalleryButtonContainer
Type.FILE -> views.attachmentFileButtonContainer
Type.STICKER -> views.attachmentStickersButtonContainer
Type.AUDIO -> views.attachmentAudioButtonContainer
Type.CONTACT -> views.attachmentContactButtonContainer
Type.POLL -> views.attachmentPollButtonContainer
}.exhaustive.let {
it.isVisible = isVisible
}
}
private fun animateButtonIn(button: View, delay: Int) {
val animation = AnimationSet(true)
val scale = ScaleAnimation(0.0f, 1.0f, 0.0f, 1.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.0f)

View File

@ -1322,6 +1322,7 @@ class RoomDetailFragment @Inject constructor(
override fun onAddAttachment() {
if (!::attachmentTypeSelector.isInitialized) {
attachmentTypeSelector = AttachmentTypeSelectorView(vectorBaseActivity, vectorBaseActivity.layoutInflater, this@RoomDetailFragment)
attachmentTypeSelector.setAttachmentVisibility(AttachmentTypeSelectorView.Type.POLL, vectorPreferences.labsEnablePolls())
}
attachmentTypeSelector.show(views.composerLayout.views.attachmentButton, keyboardStateUtils.isKeyboardShowing)
}

View File

@ -119,6 +119,8 @@ class TimelineEventVisibilityHelper @Inject constructor(private val userPreferen
val diff = computeMembershipDiff()
if ((diff.isJoin || diff.isPart) && !userPreferencesProvider.shouldShowJoinLeaves()) return true
if ((diff.isAvatarChange || diff.isDisplaynameChange) && !userPreferencesProvider.shouldShowAvatarDisplayNameChanges()) return true
} else if (root.getClearType() == EventType.POLL_START && !userPreferencesProvider.shouldShowPolls()) {
return true
}
return false
}

View File

@ -202,6 +202,8 @@ class VectorPreferences @Inject constructor(private val context: Context) {
private const val TAKE_PHOTO_VIDEO_MODE = "TAKE_PHOTO_VIDEO_MODE"
private const val SETTINGS_LABS_ENABLE_POLLS = "SETTINGS_LABS_ENABLE_POLLS"
// Possible values for TAKE_PHOTO_VIDEO_MODE
const val TAKE_PHOTO_VIDEO_MODE_ALWAYS_ASK = 0
const val TAKE_PHOTO_VIDEO_MODE_PHOTO = 1
@ -1012,4 +1014,8 @@ class VectorPreferences @Inject constructor(private val context: Context) {
putInt(TAKE_PHOTO_VIDEO_MODE, mode)
}
}
fun labsEnablePolls(): Boolean {
return defaultPrefs.getBoolean(SETTINGS_LABS_ENABLE_POLLS, false)
}
}

View File

@ -24,6 +24,7 @@
android:weightSum="3">
<LinearLayout
android:id="@+id/attachmentCameraButtonContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
@ -46,6 +47,7 @@
<LinearLayout
android:id="@+id/attachmentGalleryButtonContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
@ -68,6 +70,7 @@
<LinearLayout
android:id="@+id/attachmentFileButtonContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
@ -99,6 +102,7 @@
android:weightSum="3">
<LinearLayout
android:id="@+id/attachmentAudioButtonContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
@ -121,6 +125,7 @@
<LinearLayout
android:id="@+id/attachmentContactButtonContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
@ -143,6 +148,7 @@
<LinearLayout
android:id="@+id/attachmentStickersButtonContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
@ -174,6 +180,7 @@
android:weightSum="3">
<LinearLayout
android:id="@+id/attachmentPollButtonContainer"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"

View File

@ -3670,4 +3670,5 @@
<string name="end_poll_confirmation_title">End poll</string>
<string name="end_poll_confirmation_description">Are you sure you want to end this poll? This will stop people from being able to vote and will display the final results of the poll.</string>
<string name="end_poll_confirmation_approve_button">End poll</string>
<string name="labs_enable_polls">Enable Polls</string>
</resources>

View File

@ -52,5 +52,10 @@
android:summary="@string/labs_use_restricted_join_rule_desc"/>
<!--</im.vector.app.core.preference.VectorPreferenceCategory>-->
<im.vector.app.core.preference.VectorSwitchPreference
android:defaultValue="false"
android:key="SETTINGS_LABS_ENABLE_POLLS"
android:title="@string/labs_enable_polls" />
</androidx.preference.PreferenceScreen>