diff --git a/app/src/main/java/ru/karasevm/privatednstoggle/DnsTileService.kt b/app/src/main/java/ru/karasevm/privatednstoggle/DnsTileService.kt index caf5c8e..ddf34ab 100644 --- a/app/src/main/java/ru/karasevm/privatednstoggle/DnsTileService.kt +++ b/app/src/main/java/ru/karasevm/privatednstoggle/DnsTileService.kt @@ -53,7 +53,7 @@ class DnsTileService : TileService() { changeDNSServer(DNS_MODE_PRIVATE, null) } else { if (sharedPrefs.autoMode == AUTO_MODE_OPTION_AUTO) { - changeDNSServer(DNS_MODE_AUTO,dnsProvider) + changeDNSServer(DNS_MODE_AUTO, dnsProvider) } else { changeDNSServer(DNS_MODE_OFF, dnsProvider) } @@ -76,6 +76,7 @@ class DnsTileService : TileService() { null ) } + DNS_MODE_AUTO -> { changeTileState( qsTile, @@ -86,6 +87,7 @@ class DnsTileService : TileService() { dnsProvider ) } + DNS_MODE_PRIVATE -> { changeTileState( qsTile, @@ -153,7 +155,7 @@ class DnsTileService : TileService() { val sharedPrefs = PreferenceHelper.defaultPreference(this) val items = sharedPrefs.dns_servers.map { val parts = it.split(" : ") - if(parts.size == 2) + if (parts.size == 2) DnsServer(parts[0], parts[1]) else DnsServer(parts[0], parts[0]) @@ -166,8 +168,7 @@ class DnsTileService : TileService() { "Google", R.drawable.ic_private_black_24dp ) - } - else { + } else { val index = items.indexOfFirst { it.server == dnsProvider } if (index == -1) { refreshTile( @@ -242,7 +243,7 @@ class DnsTileService : TileService() { val items = sharedPrefs.dns_servers.map { val parts = it.split(" : ") // Assuming string is in the format "$label : $server" - if(parts.size == 2) + if (parts.size == 2) DnsServer(parts[0], parts[1]) else DnsServer(parts[0], parts[0]) diff --git a/app/src/main/java/ru/karasevm/privatednstoggle/MainActivity.kt b/app/src/main/java/ru/karasevm/privatednstoggle/MainActivity.kt index cb25cfb..f19a122 100644 --- a/app/src/main/java/ru/karasevm/privatednstoggle/MainActivity.kt +++ b/app/src/main/java/ru/karasevm/privatednstoggle/MainActivity.kt @@ -41,8 +41,7 @@ class MainActivity : AppCompatActivity(), AddServerDialogFragment.NoticeDialogLi private val itemTouchHelper by lazy { val simpleItemTouchCallback = - object : ItemTouchHelper.SimpleCallback(UP or - DOWN, 0) { + object : ItemTouchHelper.SimpleCallback(UP or DOWN, 0) { override fun onMove( recyclerView: RecyclerView, @@ -55,7 +54,10 @@ class MainActivity : AppCompatActivity(), AddServerDialogFragment.NoticeDialogLi override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) {} - override fun onSelectedChanged(viewHolder: RecyclerView.ViewHolder?, actionState: Int) { + override fun onSelectedChanged( + viewHolder: RecyclerView.ViewHolder?, + actionState: Int + ) { super.onSelectedChanged(viewHolder, actionState) if (actionState == ItemTouchHelper.ACTION_STATE_DRAG) { viewHolder?.itemView?.apply { @@ -67,7 +69,10 @@ class MainActivity : AppCompatActivity(), AddServerDialogFragment.NoticeDialogLi } } - override fun clearView(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder) { + override fun clearView( + recyclerView: RecyclerView, + viewHolder: RecyclerView.ViewHolder + ) { super.clearView(recyclerView, viewHolder) viewHolder.itemView.apply { // Reset the appearance @@ -108,14 +113,14 @@ class MainActivity : AppCompatActivity(), AddServerDialogFragment.NoticeDialogLi sharedPrefs.dns_servers = swapedItems } adapter.onDragStart = { viewHolder -> - itemTouchHelper.startDrag(viewHolder); + itemTouchHelper.startDrag(viewHolder) } binding.floatingActionButton.setOnClickListener { val newFragment = AddServerDialogFragment() newFragment.show(supportFragmentManager, "add_server") } binding.recyclerView.adapter = adapter - itemTouchHelper.attachToRecyclerView(binding.recyclerView); + itemTouchHelper.attachToRecyclerView(binding.recyclerView) binding.topAppBar.setOnMenuItemClickListener { item -> when (item.itemId) { @@ -189,7 +194,7 @@ class MainActivity : AppCompatActivity(), AddServerDialogFragment.NoticeDialogLi Toast.makeText(this, R.string.server_length_error, Toast.LENGTH_SHORT).show() return } - if(label.isNullOrEmpty()) { + if (label.isNullOrEmpty()) { items.add(server) } else { items.add("$label : $server") diff --git a/app/src/main/java/ru/karasevm/privatednstoggle/OptionsDialogFragment.kt b/app/src/main/java/ru/karasevm/privatednstoggle/OptionsDialogFragment.kt index 2a074ea..e4b9cb4 100644 --- a/app/src/main/java/ru/karasevm/privatednstoggle/OptionsDialogFragment.kt +++ b/app/src/main/java/ru/karasevm/privatednstoggle/OptionsDialogFragment.kt @@ -46,7 +46,9 @@ class OptionsDialogFragment : DialogFragment() { R.id.autoOptionAuto -> sharedPrefs.autoMode = PrivateDNSUtils.AUTO_MODE_OPTION_AUTO R.id.autoOptionOffAuto -> sharedPrefs.autoMode = PrivateDNSUtils.AUTO_MODE_OPTION_OFF_AUTO - R.id.autoOptionPrivate -> sharedPrefs.autoMode = PrivateDNSUtils.AUTO_MODE_OPTION_PRIVATE + + R.id.autoOptionPrivate -> sharedPrefs.autoMode = + PrivateDNSUtils.AUTO_MODE_OPTION_PRIVATE } } diff --git a/app/src/main/java/ru/karasevm/privatednstoggle/RecyclerAdapter.kt b/app/src/main/java/ru/karasevm/privatednstoggle/RecyclerAdapter.kt index 48865a8..6c9e648 100644 --- a/app/src/main/java/ru/karasevm/privatednstoggle/RecyclerAdapter.kt +++ b/app/src/main/java/ru/karasevm/privatednstoggle/RecyclerAdapter.kt @@ -28,18 +28,17 @@ class RecyclerAdapter(private val items: MutableList, private val showDr override fun onBindViewHolder(holder: RecyclerAdapter.ViewHolder, position: Int) { val item = items[position] val parts = item.split(" : ") - if(parts.size == 2){ + if (parts.size == 2) { holder.labelTextView.text = parts[0] holder.textView.text = parts[1] - } else{ + } else { holder.labelTextView.visibility = View.GONE holder.textView.text = parts[0] } - if(showDragHandle) { + if (showDragHandle) { holder.dragHandle.visibility = View.VISIBLE - holder.dragHandle.setOnTouchListener { - _, event -> + holder.dragHandle.setOnTouchListener { _, event -> if (event.actionMasked == MotionEvent.ACTION_DOWN) { onDragStart?.invoke(holder) }