Use swipe right both to enable and disable codec
This commit is contained in:
@ -68,16 +68,6 @@ class CodecsActivity : AppCompatActivity() {
|
||||
codecList.layoutManager = LinearLayoutManager(this)
|
||||
codecList.adapter = codecsAdapter
|
||||
|
||||
codecsAdapter.setOnItemClickListener(object : CodecsAdapter.OnItemClickListener {
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
override fun onItemClick(position: Int) {
|
||||
if (!newCodecs[position].enabled) {
|
||||
codecsAdapter.enableItem(position)
|
||||
codecsAdapter.notifyDataSetChanged()
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
itemTouchHelper.attachToRecyclerView(binding.CodecList)
|
||||
|
||||
codecsTitle.setOnClickListener {
|
||||
@ -93,9 +83,8 @@ class CodecsActivity : AppCompatActivity() {
|
||||
|
||||
private val itemTouchHelper by lazy {
|
||||
val simpleItemTouchCallback = object : ItemTouchHelper.SimpleCallback(
|
||||
UP or DOWN or START or END,
|
||||
RIGHT
|
||||
) {
|
||||
UP or DOWN or START or END, RIGHT) {
|
||||
|
||||
override fun onMove(
|
||||
recyclerView: RecyclerView,
|
||||
viewHolder: RecyclerView.ViewHolder,
|
||||
@ -108,9 +97,16 @@ class CodecsActivity : AppCompatActivity() {
|
||||
return true
|
||||
}
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) {
|
||||
codecsAdapter.removeItem(viewHolder.adapterPosition)
|
||||
codecsAdapter.notifyItemRemoved(viewHolder.adapterPosition)
|
||||
val position = viewHolder.adapterPosition
|
||||
if (newCodecs[position].enabled) {
|
||||
codecsAdapter.disableItem(position)
|
||||
codecsAdapter.notifyItemRemoved(position)
|
||||
} else {
|
||||
codecsAdapter.enableItem(position)
|
||||
codecsAdapter.notifyDataSetChanged()
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
|
||||
@ -11,19 +11,9 @@ import java.util.*
|
||||
class CodecsAdapter(private val codecs: ArrayList<Codec>):
|
||||
RecyclerView.Adapter<CodecsAdapter.CodecViewHolder>() {
|
||||
|
||||
private var codecListener: OnItemClickListener? = null
|
||||
|
||||
interface OnItemClickListener {
|
||||
fun onItemClick(position: Int)
|
||||
}
|
||||
|
||||
fun setOnItemClickListener(listener: OnItemClickListener) {
|
||||
codecListener = listener
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CodecViewHolder {
|
||||
val v = LayoutInflater.from(parent.context).inflate(R.layout.codec, parent, false)
|
||||
return CodecViewHolder(v, codecListener!!)
|
||||
return CodecViewHolder(v)
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
@ -37,7 +27,14 @@ class CodecsAdapter(private val codecs: ArrayList<Codec>):
|
||||
codecs.add(toPosition, codec)
|
||||
}
|
||||
|
||||
fun removeItem(position: Int) {
|
||||
fun enableItem(position: Int) {
|
||||
val codec: Codec = codecs[position]
|
||||
codec.enabled = true
|
||||
codecs.removeAt(position)
|
||||
codecs.add(0, codec)
|
||||
}
|
||||
|
||||
fun disableItem(position: Int) {
|
||||
val codec: Codec = codecs[position]
|
||||
if (codec.enabled) {
|
||||
codec.enabled = false
|
||||
@ -46,33 +43,17 @@ class CodecsAdapter(private val codecs: ArrayList<Codec>):
|
||||
}
|
||||
}
|
||||
|
||||
fun enableItem(position: Int) {
|
||||
val codec: Codec = codecs[position]
|
||||
codec.enabled = true
|
||||
codecs.removeAt(position)
|
||||
codecs.add(0, codec)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: CodecViewHolder, position: Int) {
|
||||
val codec = codecs[position]
|
||||
holder.codecName.text = codec.name
|
||||
holder.codecName.alpha = if (codec.enabled) 1.0f else 0.5f
|
||||
holder.actionImage.setImageResource(
|
||||
if (codec.enabled) R.drawable.reorder else R.drawable.add
|
||||
holder.reorderImage.setImageResource(
|
||||
if (codec.enabled) R.drawable.reorder else android.R.color.transparent
|
||||
)
|
||||
}
|
||||
|
||||
class CodecViewHolder(itemView: View, listener: OnItemClickListener):
|
||||
RecyclerView.ViewHolder(itemView) {
|
||||
class CodecViewHolder(itemView: View): RecyclerView.ViewHolder(itemView) {
|
||||
var codecName: TextView = itemView.findViewById(R.id.codecName)
|
||||
var actionImage: ImageView = itemView.findViewById(R.id.actionImage)
|
||||
init {
|
||||
itemView.setOnClickListener {
|
||||
val position = adapterPosition
|
||||
if (position != RecyclerView.NO_POSITION) {
|
||||
listener.onItemClick(position)
|
||||
}
|
||||
}
|
||||
}
|
||||
var reorderImage: ImageView = itemView.findViewById(R.id.reorderImage)
|
||||
}
|
||||
}
|
||||
|
||||
@ -240,6 +240,7 @@
|
||||
android:hint="@string/dtmf"
|
||||
android:importantForAutofill="no"
|
||||
android:inputType="phone"
|
||||
android:digits="0123456789#*"
|
||||
android:textSize="20sp" >
|
||||
</EditText>
|
||||
|
||||
|
||||
@ -22,7 +22,7 @@
|
||||
app:layout_constraintStart_toStartOf="parent" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/actionImage"
|
||||
android:id="@+id/reorderImage"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
|
||||
@ -287,15 +287,14 @@
|
||||
<string name="delete_chats_alert">Haluatko tyhjentää tilin \'%1$s\' viestihistorian\?</string>
|
||||
<!-- Codecs Activity -->
|
||||
<string name="audio_codecs">Audion koodausmenetelmät</string>
|
||||
<string name="audio_codecs_help">Luettelo käytössä olevista audion
|
||||
koodausmenetelmistä prioriteettijärjestyksessä. Ota käyttöön koskettamalla,
|
||||
järjestä vetämällä ja pudottamalla, poista käytöstä pyyhkäisemällä oikealle.</string>
|
||||
<string name="audio_codecs_help">Luettelo audion koodausmenetelmistä prioriteettijärjestyksessä.
|
||||
Järjestä raahaamalla ja pudottamalla, ota käyttöön tai poista käytöstä pyyhkäisemällä oikealle.
|
||||
</string>
|
||||
<string name="video_codecs">Videon koodausmenetelmät</string>
|
||||
<string name="video_codecs_help">Luettelo käytössä olevista videon
|
||||
koodausmenetelmistä prioriteettijärjestyksessä. Ota käyttöön koskettamalla,
|
||||
järjestä vetämällä ja pudottamalla, poista käytöstä pyyhkäisemällä oikealle.</string>
|
||||
<string name="codec_action">Koodausmenetelmä toiminto (ota käyttöön, järjestä, poista
|
||||
käytöstä)</string>
|
||||
<string name="video_codecs_help">Luettelo videon koodausmenetelmistä prioriteettijärjestyksessä.
|
||||
Järjestä raahaamalla ja pudottamalla, ota käyttöön tai poista käytöstä pyyhkäisemällä oikealle.
|
||||
</string>
|
||||
<string name="codec_action">Järjestä</string>
|
||||
<!-- Config Activity -->
|
||||
<string name="configuration">Asetukset</string>
|
||||
<string name="start_automatically">Käynnistä automaattisesti</string>
|
||||
|
||||
@ -279,12 +279,12 @@
|
||||
<string name="delete_chats_alert">Do you want to delete chat history of account \'%1$s\'\?</string>
|
||||
<!-- Codecs Activity -->
|
||||
<string name="audio_codecs">Audio Codecs</string>
|
||||
<string name="audio_codecs_help">List of enabled audio codecs in priority order. Click to enable,
|
||||
drag to reorder, swipe right to disable.</string>
|
||||
<string name="audio_codecs_help">List of audio codecs in priority order. Drag to reorder,
|
||||
swipe right to enable or disable.</string>
|
||||
<string name="video_codecs">Video Codecs</string>
|
||||
<string name="video_codecs_help">List of enabled video codecs in priority order. Click to enable,
|
||||
drag to reorder, swipe right to disable.</string>
|
||||
<string name="codec_action">Codec action (enable, reorder, disable)</string>
|
||||
<string name="video_codecs_help">List of video codecs in priority order. Drag to reorder,
|
||||
swipe right to enable or disable.</string>
|
||||
<string name="codec_action">Reorder</string>
|
||||
<!-- Config Activity -->
|
||||
<string name="configuration">Settings</string>
|
||||
<string name="start_automatically">Start Automatically</string>
|
||||
|
||||
Reference in New Issue
Block a user