Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
karasevm committed Jun 27, 2024
1 parent 17f62ac commit 08a6015
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 18 deletions.
11 changes: 6 additions & 5 deletions app/src/main/java/ru/karasevm/privatednstoggle/DnsTileService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -76,6 +76,7 @@ class DnsTileService : TileService() {
null
)
}

DNS_MODE_AUTO -> {
changeTileState(
qsTile,
Expand All @@ -86,6 +87,7 @@ class DnsTileService : TileService() {
dnsProvider
)
}

DNS_MODE_PRIVATE -> {
changeTileState(
qsTile,
Expand Down Expand Up @@ -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])
Expand All @@ -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(
Expand Down Expand Up @@ -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])
Expand Down
19 changes: 12 additions & 7 deletions app/src/main/java/ru/karasevm/privatednstoggle/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 {
Expand All @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,17 @@ class RecyclerAdapter(private val items: MutableList<String>, 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)
}
Expand Down

0 comments on commit 08a6015

Please sign in to comment.