Quellcode durchsuchen

feat: live password

tongmengxiao vor 5 Monaten
Ursprung
Commit
8f4342dbf9

+ 5 - 0
baseswago/src/main/java/com/swago/baseswago/cusview/CodeTextView.kt

@@ -89,4 +89,9 @@ class CodeTextView : RelativeLayout {
             false
         })
     }
+
+    fun getPasswordText() : String{
+        return stringBuffer.toString()
+    }
+
 }

+ 18 - 3
home/src/main/java/com/swago/home/dialog/EnterPasswordDialog.kt → baseswago/src/main/java/com/swago/baseswago/dialog/EnterPasswordDialog.kt

@@ -1,4 +1,4 @@
-package com.swago.home.dialog
+package com.swago.baseswago.dialog
 
 import android.os.Bundle
 import android.view.Gravity
@@ -9,7 +9,8 @@ import com.swago.baseswago.databinding.DialogInviteBindingBinding
 import com.swago.baseswago.dialog.BaseXDFragment
 
 class EnterPasswordDialog : BaseXDFragment<DialogEnterPasswordBinding>() {
-
+    var type = 0
+    var settingPassword:((password:String)->Unit)? = null
     init {
         setGravity(Gravity.CENTER)
         setDimAmount(0.5f)
@@ -17,8 +18,9 @@ class EnterPasswordDialog : BaseXDFragment<DialogEnterPasswordBinding>() {
     }
 
     companion object {
-        fun newInstance(): EnterPasswordDialog {
+        fun newInstance(type: Int): EnterPasswordDialog {
             val args = Bundle()
+            args.putInt("type", type)
             val fragment = EnterPasswordDialog()
             fragment.arguments = args
             return fragment
@@ -26,7 +28,20 @@ class EnterPasswordDialog : BaseXDFragment<DialogEnterPasswordBinding>() {
     }
 
     override fun initOther() {
+        arguments?.let {
+            type = it.getInt("type", 0)
+        }
+        binding.tvSetting.text = when (type) {
+            2 -> "Enter"
+            else -> {
+                "Setting"
+            }
+        }
         binding.tvSetting.setOnClickListener {
+            val password = binding.activationCode.getPasswordText()
+            if (password.isEmpty() || password.length <4)
+                return@setOnClickListener
+            settingPassword?.invoke(binding.activationCode.getPasswordText())
             dismissAllowingStateLoss()
         }
 

+ 1 - 1
home/src/main/java/com/swago/home/dialog/InviteBindingDialog.kt → baseswago/src/main/java/com/swago/baseswago/dialog/InviteBindingDialog.kt

@@ -1,4 +1,4 @@
-package com.swago.home.dialog
+package com.swago.baseswago.dialog
 
 import android.os.Bundle
 import android.view.Gravity

+ 3 - 2
baseswago/src/main/res/layout/dialog_enter_password.xml

@@ -72,11 +72,12 @@
 
     </androidx.constraintlayout.widget.ConstraintLayout>
 
-    <RelativeLayout
+    <ImageView
         android:id="@+id/iv_bg"
         android:layout_width="match_parent"
-        android:layout_height="match_parent"
+        android:layout_height="100dp"
         android:background="@mipmap/bg_invite"
+        app:layout_constraintTop_toTopOf="parent"
         android:layout_marginStart="40dp"
         android:layout_marginEnd="40dp"/>
 

+ 52 - 14
room/src/main/java/com/swago/room/anchor/AnchorRoomActivity.kt

@@ -22,6 +22,7 @@ import com.swago.baseswago.baseroom.SwagoRoomManager
 import com.swago.baseswago.baseroom.ui.AbsAnchorActivity
 import com.swago.baseswago.constant.ARouteConstant
 import com.swago.baseswago.dialog.ChoiceDialogFragment
+import com.swago.baseswago.dialog.EnterPasswordDialog
 import com.swago.baseswago.model.live.audio.AudioBg
 import com.swago.baseswago.model.live.audio.AudioSeatModel
 import com.swago.baseswago.model.live.audio.IMAudioModel
@@ -94,6 +95,7 @@ class AnchorRoomActivity : AbsAnchorActivity<ActivityAnchorRoomBinding, IRoomInf
     //语音房背景选中第几张
     private var selectedBgIndex = 0
     private var selectedBgUrl = ""
+    private var checkPassword = false
 
     override fun initLiveData() {
         PKStateManager.resetData()
@@ -181,14 +183,30 @@ class AnchorRoomActivity : AbsAnchorActivity<ActivityAnchorRoomBinding, IRoomInf
                         .permissions(Manifest.permission.POST_NOTIFICATIONS)
                         .request { allGranted, grantedList, deniedList ->
                             if (allGranted) {
-                                binding.tvStartLive.isEnabled = false
-                                val userModel = UserRoomModel()
-                                userModel.roomType = roomType
-                                userModel.selectedBgUrl = selectedBgUrl
-                                SwagoRoomManager.changeRoom(userModel)
-                                if (roomType == RoomType.VIDEO){
-                                    anchorRoomFragment?.setAudioRvState(false)
+                                if (checkPassword){
+                                    EnterPasswordDialog.newInstance(1).apply {
+                                        this.settingPassword = {password ->
+                                            val userModel = UserRoomModel()
+                                            userModel.roomType = roomType
+                                            userModel.selectedBgUrl = selectedBgUrl
+                                            userModel.password = password
+                                            SwagoRoomManager.changeRoom(userModel)
+                                            if (roomType == RoomType.VIDEO){
+                                                anchorRoomFragment?.setAudioRvState(false)
+                                            }
+                                        }
+                                    }.show(supportFragmentManager , "EnterPasswordDialog")
+                                } else {
+                                    binding.tvStartLive.isEnabled = false
+                                    val userModel = UserRoomModel()
+                                    userModel.roomType = roomType
+                                    userModel.selectedBgUrl = selectedBgUrl
+                                    SwagoRoomManager.changeRoom(userModel)
+                                    if (roomType == RoomType.VIDEO){
+                                        anchorRoomFragment?.setAudioRvState(false)
+                                    }
                                 }
+
                             } else {
                                 binding.tvStartLive.isEnabled = true
                                 Toast.makeText(
@@ -199,14 +217,30 @@ class AnchorRoomActivity : AbsAnchorActivity<ActivityAnchorRoomBinding, IRoomInf
                             }
                         }
                 }else{
-                    binding.tvStartLive.isEnabled = false
-                    val userModel = UserRoomModel()
-                    userModel.roomType = roomType
-                    userModel.selectedBgUrl = selectedBgUrl
-                    SwagoRoomManager.changeRoom(userModel)
-                    if (roomType == RoomType.VIDEO){
-                        anchorRoomFragment?.setAudioRvState(false)
+                    if (checkPassword){
+                        EnterPasswordDialog.newInstance(1).apply {
+                            this.settingPassword = {password ->
+                                val userModel = UserRoomModel()
+                                userModel.roomType = roomType
+                                userModel.selectedBgUrl = selectedBgUrl
+                                userModel.password = password
+                                SwagoRoomManager.changeRoom(userModel)
+                                if (roomType == RoomType.VIDEO){
+                                    anchorRoomFragment?.setAudioRvState(false)
+                                }
+                            }
+                        }.show(supportFragmentManager , "EnterPasswordDialog")
+                    } else {
+                        binding.tvStartLive.isEnabled = false
+                        val userModel = UserRoomModel()
+                        userModel.roomType = roomType
+                        userModel.selectedBgUrl = selectedBgUrl
+                        SwagoRoomManager.changeRoom(userModel)
+                        if (roomType == RoomType.VIDEO){
+                            anchorRoomFragment?.setAudioRvState(false)
+                        }
                     }
+
                 }
             }
         })
@@ -287,6 +321,10 @@ class AnchorRoomActivity : AbsAnchorActivity<ActivityAnchorRoomBinding, IRoomInf
                 }
             }
         })
+        binding.cbPassword.setOnCheckedChangeListener { _, isChecked ->
+            binding.cbPassword.text = if (isChecked)  "Password ·NO" else "Password ·OFF"
+            checkPassword = isChecked
+        }
 
     }
 

+ 2 - 0
room/src/main/java/com/swago/room/bean/UserRoomModel.kt

@@ -23,6 +23,8 @@ class UserRoomModel :  IRoomInfo{
 
     var selectedBgUrl = ""
 
+    var password = ""
+
     override fun getAnchorName(): String {
         return roomModel?.user_name?:""
     }

+ 6 - 0
room/src/main/res/drawable/live_password_check.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:drawable="@mipmap/ic_live_lock1" android:state_checked="true"/>
+ <item android:drawable="@mipmap/ic_live_unlock" android:state_checked="false"/>
+ <item android:drawable="@mipmap/ic_live_unlock"/>
+</selector>

+ 36 - 13
room/src/main/res/layout/activity_anchor_room.xml

@@ -88,20 +88,43 @@
             app:layout_constraintStart_toStartOf="parent"
             app:layout_constraintTop_toTopOf="parent" />
 
-
-        <TextView
-            android:id="@+id/tvWishGift"
+        <LinearLayout
+            android:id="@+id/ll_change"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
-            android:layout_marginBottom="24dp"
-            android:drawableTop="@mipmap/wish_gift"
-            android:drawablePadding="4dp"
-            android:text="Wish Gift"
-            android:textColor="#ffffff"
-            android:textSize="14dp"
+            android:orientation="horizontal"
             app:layout_constraintBottom_toTopOf="@+id/tvStartLive"
             app:layout_constraintEnd_toEndOf="parent"
-            app:layout_constraintStart_toStartOf="parent" />
+            app:layout_constraintStart_toStartOf="parent">
+
+            <CheckBox
+                android:id="@+id/cbPassword"
+                android:layout_width="120dp"
+                android:layout_height="wrap_content"
+                android:drawableTop="@drawable/live_password_check"
+                android:textColor="#ffffff"
+                android:textSize="14dp"
+                android:button="@null"
+                android:text="Password ·OFF"
+                android:drawablePadding="4dp"
+                android:gravity="center_horizontal"
+                android:background="@android:color/transparent"
+                android:layout_marginBottom="24dp"/>
+
+            <TextView
+                android:id="@+id/tvWishGift"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:layout_marginBottom="24dp"
+                android:drawableTop="@mipmap/wish_gift"
+                android:drawablePadding="4dp"
+                android:text="Wish Gift"
+                android:textColor="#ffffff"
+                android:textSize="14dp" />
+
+        </LinearLayout>
+
+
 
         <LinearLayout
             android:id="@+id/llChangeBg"
@@ -111,7 +134,7 @@
             android:visibility="gone"
             tools:visibility="visible"
             android:layout_marginBottom="10dp"
-            app:layout_constraintBottom_toTopOf="@+id/tvWishGift"
+            app:layout_constraintBottom_toTopOf="@+id/ll_change"
             app:layout_constraintEnd_toEndOf="parent"
             app:layout_constraintStart_toStartOf="parent">
 
@@ -152,8 +175,8 @@
             android:text="New"
             android:textColor="#ffffff"
             android:textSize="10dp"
-            app:layout_constraintEnd_toEndOf="@+id/tvWishGift"
-            app:layout_constraintTop_toTopOf="@+id/tvWishGift" />
+            app:layout_constraintEnd_toEndOf="@+id/ll_change"
+            app:layout_constraintTop_toTopOf="@+id/ll_change" />
 
 
         <com.swago.baseswago.cusview.BoldTextView

BIN
room/src/main/res/mipmap-xxhdpi/ic_live_lock1.png


BIN
room/src/main/res/mipmap-xxhdpi/ic_live_unlock.png