forked from dovecoteescapee/ByeDPIAndroid
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add shortcut toggle and refactoring quicktile
- Loading branch information
Showing
9 changed files
with
113 additions
and
68 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
app/src/main/java/io/github/dovecoteescapee/byedpi/activities/ToggleActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package io.github.dovecoteescapee.byedpi.activities | ||
|
||
import android.net.VpnService | ||
import android.os.Bundle | ||
import android.util.Log | ||
import androidx.appcompat.app.AppCompatActivity | ||
import io.github.dovecoteescapee.byedpi.data.AppStatus | ||
import io.github.dovecoteescapee.byedpi.data.Mode | ||
import io.github.dovecoteescapee.byedpi.services.ServiceManager | ||
import io.github.dovecoteescapee.byedpi.services.appStatus | ||
import io.github.dovecoteescapee.byedpi.utility.getPreferences | ||
import io.github.dovecoteescapee.byedpi.utility.mode | ||
|
||
class ToggleActivity : AppCompatActivity() { | ||
|
||
companion object { | ||
private const val TAG = "ToggleServiceActivity" | ||
} | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
toggleService() | ||
finish() | ||
} | ||
|
||
private fun toggleService() { | ||
val (status) = appStatus | ||
when (status) { | ||
AppStatus.Halted -> { | ||
val mode = getPreferences().mode() | ||
|
||
if (mode == Mode.VPN && VpnService.prepare(this) != null) { | ||
return | ||
} | ||
|
||
ServiceManager.start(this, mode) | ||
Log.i(TAG, "Toggle start") | ||
} | ||
AppStatus.Running -> { | ||
ServiceManager.stop(this) | ||
Log.i(TAG, "Toggle stop") | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="#000000" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp"> | ||
|
||
<path android:fillColor="@android:color/white" android:pathData="M13,3h-2v10h2L13,3zM17.83,5.17l-1.42,1.42C17.99,7.86 19,9.81 19,12c0,3.87 -3.13,7 -7,7s-7,-3.13 -7,-7c0,-2.19 1.01,-4.14 2.58,-5.42L6.17,5.17C4.23,6.82 3,9.26 3,12c0,4.97 4.03,9 9,9s9,-4.03 9,-9c0,-2.74 -1.23,-5.18 -3.17,-6.83z"/> | ||
|
||
</vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<shortcuts xmlns:tools="http://schemas.android.com/tools" | ||
xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<shortcut | ||
android:shortcutId="toggle_connect" | ||
android:enabled="true" | ||
android:icon="@drawable/ic_toggle" | ||
android:shortcutShortLabel="@string/toggle_connect" | ||
android:shortcutLongLabel="@string/toggle_connect" | ||
tools:ignore="UnusedAttribute"> | ||
<intent | ||
android:action="io.github.romanvht.byedpi.TOGGLE_SERVICE" /> | ||
</shortcut> | ||
</shortcuts> |