Skip to content

Commit

Permalink
Add option to change update check frequency.
Browse files Browse the repository at this point in the history
Add basis for loading only supported features on older builds.
  • Loading branch information
rodit committed May 10, 2022
1 parent 2564757 commit 08bb2b1
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 16 deletions.
22 changes: 22 additions & 0 deletions app/src/main/java/xyz/rodit/snapmod/SettingsActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import android.widget.EditText
import androidx.appcompat.app.AlertDialog
import androidx.preference.EditTextPreference
import androidx.preference.Preference
import androidx.preference.PreferenceManager
import xyz.rodit.xposed.SettingsActivity
import xyz.rodit.xposed.utils.PathUtils
import java.io.File
Expand All @@ -24,6 +25,20 @@ class SettingsActivity : SettingsActivity(R.xml.root_preferences) {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

val minUpdateDelta = PreferenceManager.getDefaultSharedPreferences(this)
.getString("update_frequency", "0")!!.toLong()
if (minUpdateDelta >= 0) {
val updateCheckFile = File(filesDir, ".update")
val lastUpdateCheck =
if (updateCheckFile.exists()) updateCheckFile.lastModified() else 0
if (System.currentTimeMillis() - lastUpdateCheck >= minUpdateDelta) {
performUpdateCheck()
}
}
}

private fun performUpdateCheck() {
updates.checkForUpdates("rodit", "SnapMod")
}

Expand All @@ -49,6 +64,13 @@ class SettingsActivity : SettingsActivity(R.xml.root_preferences) {
}
}

fragment.findPreference<Preference>("check_for_updates")?.apply {
onPreferenceClickListener = Preference.OnPreferenceClickListener {
performUpdateCheck()
true
}
}

setNumericInput(fragment, "override_snap_timer")
setNumericInput(fragment, "public_dp_resolution")
setNumericInput(fragment, "location_share_lat")
Expand Down
10 changes: 7 additions & 3 deletions app/src/main/java/xyz/rodit/snapmod/SnapHooks.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import xyz.rodit.snapmod.features.InstanceManager
import xyz.rodit.snapmod.logging.XLog
import xyz.rodit.snapmod.logging.log
import xyz.rodit.snapmod.mappings.MainActivity
import xyz.rodit.snapmod.util.versionCode
import xyz.rodit.xposed.HooksBase
import xyz.rodit.xposed.mappings.LoadScheme
import java.util.*
Expand Down Expand Up @@ -85,8 +86,10 @@ class SnapHooks : HooksBase(

MainActivity.attachBaseContext.hook(object : XC_MethodHook() {
override fun beforeHookedMethod(param: MethodHookParam) {
featureContext!!.activity = param.thisObject as Activity
mainActivity = featureContext!!.activity
featureContext?.let {
it.activity = param.thisObject as Activity
mainActivity = it.activity
}
}
})

Expand All @@ -97,7 +100,8 @@ class SnapHooks : HooksBase(
config,
files,
server,
InstanceManager()
InstanceManager(),
appContext.versionCode
)

(appContext as Application).registerActivityLifecycleCallbacks(
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/java/xyz/rodit/snapmod/features/Feature.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package xyz.rodit.snapmod.features

abstract class Feature(context: FeatureContext) : Contextual(context) {
abstract class Feature(
context: FeatureContext, val support: LongRange = LongRange(0, Long.MAX_VALUE)
) : Contextual(context) {

open fun init() {}
open fun onConfigLoaded(first: Boolean) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ class FeatureContext(
val config: ConfigurationClient,
val files: FileClient,
val server: StreamServer,
val instances: InstanceManager
val instances: InstanceManager,
val appVersion: Long
) {
val callbacks: CallbackManager = CallbackManager()
val pinned: ConversationManager = ConversationManager(appContext.filesDir, PINNED_CONVERSATIONS_FILE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import xyz.rodit.snapmod.features.saving.ChatSaving
import xyz.rodit.snapmod.features.saving.PublicProfileSaving
import xyz.rodit.snapmod.features.saving.StoriesSaving
import xyz.rodit.snapmod.features.tweaks.*
import java.util.function.Function

class FeatureManager(context: FeatureContext) : Contextual(context) {

Expand Down Expand Up @@ -71,7 +70,10 @@ class FeatureManager(context: FeatureContext) : Contextual(context) {
features.forEach { it.performHooks() }
}

fun add(supplier: Function<FeatureContext, Feature>) {
features.add(supplier.apply(context))
fun add(supplier: (FeatureContext) -> Feature) {
val feature = supplier(context)
if (feature.support.contains(context.appVersion)) {
features.add(feature)
}
}
}
11 changes: 11 additions & 0 deletions app/src/main/java/xyz/rodit/snapmod/util/BuildUtils.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package xyz.rodit.snapmod.util

import android.content.Context
import android.os.Build

val Context.versionCode: Long
get() {
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
this.packageManager.getPackageInfo(this.packageName, 0).longVersionCode else
this.packageManager.getPackageInfo(this.packageName, 0).versionCode.toLong()
}
16 changes: 16 additions & 0 deletions app/src/main/res/values/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,22 @@
<item>4</item>
</string-array>

<string-array name="update_frequencies">
<item>Every Launch</item>
<item>Every 6 Hours</item>
<item>Every 12 Hours</item>
<item>Every Day</item>
<item>Never</item>
</string-array>

<string-array name="update_frequencies_values">
<item>0</item>
<item>21600000</item>
<item>43200000</item>
<item>86400000</item>
<item>-1</item>
</string-array>

<string-array name="sc_scope">
<item>com.snapchat.android</item>
</string-array>
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,10 @@
<string name="donations_title">Donations</string>
<string name="donations_summary">If you would like to support SnapMod, you can donate by tapping here.</string>
<string name="donations_link">https://github.com/rodit/SnapMod#donations</string>

<string name="updates_header">Updates</string>
<string name="update_frequency_title">Update Check Frequency</string>
<string name="update_frequency_description">Sets the minimum amount of time between SnapMod update checks. Note: SnapMod still only checks for updates when you launch it (never in the background).</string>
<string name="check_for_updates_title">Check For Updates</string>
<string name="check_for_updates_description">Checks for updates now.</string>
</resources>
32 changes: 24 additions & 8 deletions app/src/main/res/xml/root_preferences.xml
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
<PreferenceScreen xmlns:app="http://schemas.android.com/apk/res-auto">

<Preference app:key="installation_status"
<Preference
app:key="installation_status"
app:title="@string/installation_status_title"
app:summary="@string/installation_status_summary"
app:iconSpaceReserved="false">

</Preference>
app:iconSpaceReserved="false" />

<Preference app:key="donations"
<Preference
app:key="donations"
app:title="@string/donations_title"
app:summary="@string/donations_summary"
app:iconSpaceReserved="false">

</Preference>
app:iconSpaceReserved="false" />

<PreferenceCategory app:title="@string/privacy_header"
app:iconSpaceReserved="false">
Expand Down Expand Up @@ -306,4 +304,22 @@
app:iconSpaceReserved="false" />

</PreferenceCategory>

<PreferenceCategory app:title="@string/updates_header"
app:iconSpaceReserved="false">

<ListPreference
app:key="update_frequency"
app:title="@string/update_frequency_title"
app:summary="@string/update_frequency_description"
app:entries="@array/update_frequencies"
app:entryValues="@array/update_frequencies_values"
app:defaultValue="0"
app:iconSpaceReserved="false" />

<Preference app:key="check_for_updates"
app:title="@string/check_for_updates_title"
app:summary="@string/check_for_updates_description"
app:iconSpaceReserved="false" />
</PreferenceCategory>
</PreferenceScreen>

0 comments on commit 08bb2b1

Please sign in to comment.