-
-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
lucky
committed
Jul 14, 2022
1 parent
ebf2a59
commit 712ef42
Showing
77 changed files
with
532 additions
and
10 deletions.
There are no files selected for viewing
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
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
95 changes: 95 additions & 0 deletions
95
app/src/main/java/me/lucky/wasted/fragment/ApplicationFragment.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,95 @@ | ||
package me.lucky.wasted.fragment | ||
|
||
import android.content.Context | ||
import android.content.SharedPreferences | ||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.fragment.app.Fragment | ||
|
||
import me.lucky.wasted.ApplicationOption | ||
import me.lucky.wasted.Preferences | ||
import me.lucky.wasted.Utils | ||
import me.lucky.wasted.databinding.FragmentApplicationBinding | ||
|
||
class ApplicationFragment : Fragment() { | ||
private lateinit var binding: FragmentApplicationBinding | ||
private lateinit var ctx: Context | ||
private lateinit var prefs: Preferences | ||
private lateinit var prefsdb: Preferences | ||
private val utils by lazy { Utils(ctx) } | ||
|
||
private val prefsListener = SharedPreferences.OnSharedPreferenceChangeListener { _, key -> | ||
prefs.copyTo(prefsdb, key) | ||
} | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, | ||
container: ViewGroup?, | ||
savedInstanceState: Bundle?, | ||
): View { | ||
binding = FragmentApplicationBinding.inflate(inflater, container, false) | ||
init() | ||
setup() | ||
return binding.root | ||
} | ||
|
||
override fun onStart() { | ||
super.onStart() | ||
prefs.registerListener(prefsListener) | ||
} | ||
|
||
override fun onStop() { | ||
super.onStop() | ||
prefs.unregisterListener(prefsListener) | ||
} | ||
|
||
private fun init() { | ||
ctx = requireContext() | ||
prefs = Preferences(ctx) | ||
prefsdb = Preferences(ctx, encrypted = false) | ||
binding.apply { | ||
val options = prefs.triggerApplicationOptions | ||
signal.isChecked = options.and(ApplicationOption.SIGNAL.value) != 0 | ||
telegram.isChecked = options.and(ApplicationOption.TELEGRAM.value) != 0 | ||
threema.isChecked = options.and(ApplicationOption.THREEMA.value) != 0 | ||
session.isChecked = options.and(ApplicationOption.SESSION.value) != 0 | ||
} | ||
} | ||
|
||
private fun setup() = binding.apply { | ||
signal.setOnCheckedChangeListener { _, isChecked -> | ||
prefs.triggerApplicationOptions = Utils.setFlag( | ||
prefs.triggerApplicationOptions, | ||
ApplicationOption.SIGNAL.value, | ||
isChecked, | ||
) | ||
utils.updateApplicationEnabled() | ||
} | ||
telegram.setOnCheckedChangeListener { _, isChecked -> | ||
prefs.triggerApplicationOptions = Utils.setFlag( | ||
prefs.triggerApplicationOptions, | ||
ApplicationOption.TELEGRAM.value, | ||
isChecked, | ||
) | ||
utils.updateApplicationEnabled() | ||
} | ||
threema.setOnCheckedChangeListener { _, isChecked -> | ||
prefs.triggerApplicationOptions = Utils.setFlag( | ||
prefs.triggerApplicationOptions, | ||
ApplicationOption.THREEMA.value, | ||
isChecked, | ||
) | ||
utils.updateApplicationEnabled() | ||
} | ||
session.setOnCheckedChangeListener { _, isChecked -> | ||
prefs.triggerApplicationOptions = Utils.setFlag( | ||
prefs.triggerApplicationOptions, | ||
ApplicationOption.SESSION.value, | ||
isChecked, | ||
) | ||
utils.updateApplicationEnabled() | ||
} | ||
} | ||
} |
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
26 changes: 26 additions & 0 deletions
26
app/src/main/java/me/lucky/wasted/trigger/application/ApplicationActivity.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,26 @@ | ||
package me.lucky.wasted.trigger.application | ||
|
||
import android.os.Bundle | ||
import androidx.appcompat.app.AppCompatActivity | ||
|
||
import me.lucky.wasted.Preferences | ||
import me.lucky.wasted.Trigger | ||
import me.lucky.wasted.admin.DeviceAdminManager | ||
|
||
class ApplicationActivity : AppCompatActivity() { | ||
private val prefs by lazy { Preferences(this) } | ||
private val admin by lazy { DeviceAdminManager(this) } | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
if (!prefs.isEnabled || prefs.triggers.and(Trigger.APPLICATION.value) == 0) { | ||
finishAndRemoveTask() | ||
return | ||
} | ||
try { | ||
admin.lockNow() | ||
if (prefs.isWipeData) admin.wipeData() | ||
} catch (exc: SecurityException) {} | ||
finishAndRemoveTask() | ||
} | ||
} |
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,35 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:aapt="http://schemas.android.com/aapt" | ||
android:width="108dp" | ||
android:height="108dp" | ||
android:viewportWidth="108" | ||
android:viewportHeight="108"> | ||
<group android:scaleX="0.07452" | ||
android:scaleY="0.07452" | ||
android:translateX="16.74" | ||
android:translateY="16.74"> | ||
<path | ||
android:pathData="M500,500m-500,0a500,500 0,1 1,1000 0a500,500 0,1 1,-1000 0" | ||
android:strokeWidth="1" | ||
android:fillType="evenOdd" | ||
android:strokeColor="#00000000"> | ||
<aapt:attr name="android:fillColor"> | ||
<gradient | ||
android:startX="500" | ||
android:startY="-0" | ||
android:endX="500" | ||
android:endY="992.6" | ||
android:type="linear"> | ||
<item android:offset="0" android:color="#FF2AABEE"/> | ||
<item android:offset="1" android:color="#FF229ED9"/> | ||
</gradient> | ||
</aapt:attr> | ||
</path> | ||
<path | ||
android:pathData="M226.3,494.7C372.1,431.2 469.3,389.4 517.9,369.1C656.8,311.4 685.6,301.3 704.4,301C708.6,300.9 717.8,302 723.8,306.8C728.9,310.9 730.3,316.5 730.9,320.4C731.6,324.2 732.4,333.1 731.8,340C724.2,419.1 691.7,611 675.1,699.5C668.1,737 654.3,749.5 640.9,750.8C611.9,753.4 589.9,731.6 561.7,713.2C517.7,684.3 492.9,666.3 450.2,638.2C400.8,605.7 432.8,587.8 460.9,558.6C468.3,550.9 596.2,434.6 598.7,424C599,422.7 599.3,417.8 596.4,415.2C593.4,412.6 589.1,413.5 586,414.2C581.6,415.2 511.3,461.6 375.1,553.6C355.2,567.3 337.1,573.9 320.9,573.6C303,573.2 268.7,563.5 243.2,555.2C211.9,545 187,539.6 189.1,522.3C190.3,513.3 202.7,504.1 226.3,494.7Z" | ||
android:strokeWidth="1" | ||
android:fillColor="#FFFFFF" | ||
android:fillType="evenOdd" | ||
android:strokeColor="#00000000"/> | ||
</group> | ||
</vector> |
Oops, something went wrong.