feat(settings): add reset settings - #69
Merged
Merged
Conversation
Reviewer's GuideAdds a "Reset Settings" action to NekoSettingsActivity that clears multiple shared preference stores and restarts the app, and introduces localized strings for the new action across supported languages along with an AppRestartHelper activity to handle process rebirth. Sequence diagram for resetting settings and restarting the appsequenceDiagram
actor User
participant NekoSettingsActivity
participant AlertUtil
participant ApplicationLoader
participant NekoConfig
participant AppRestartHelper
participant LaunchActivity
participant Process
participant Runtime
User ->> NekoSettingsActivity: onItemClick(resetSettingsRow)
NekoSettingsActivity ->> AlertUtil: showConfirm(getParentActivity, ResetSettingsAlert, msg_reset, Reset, true, callback)
alt [user confirms]
AlertUtil -->> NekoSettingsActivity: callback()
NekoSettingsActivity ->> ApplicationLoader: applicationContext.getSharedPreferences("nekocloud", MODE_PRIVATE)
NekoSettingsActivity ->> ApplicationLoader: applicationContext.getSharedPreferences("nekox_config", MODE_PRIVATE)
ApplicationLoader ->> ApplicationLoader: edit().clear().commit()
NekoSettingsActivity ->> NekoConfig: getPreferences().edit().clear().commit()
NekoSettingsActivity ->> AppRestartHelper: triggerRebirth(getParentActivity, Intent(LaunchActivity))
AppRestartHelper ->> AppRestartHelper: onCreate(savedInstanceState)
AppRestartHelper ->> Process: killProcess(main_process_pid)
AppRestartHelper ->> AppRestartHelper: getParcelableArrayListExtra(KEY_RESTART_INTENTS)
AppRestartHelper ->> LaunchActivity: startActivities(intents)
AppRestartHelper ->> Runtime: getRuntime().exit(0)
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 2 issues, and left some high level feedback:
- AppRestartHelper.triggerRebirth assumes at least one intent and directly accesses nextIntents[0]; add a guard or require a non-empty vararg to avoid potential ArrayIndexOutOfBoundsException.
- The restart helper uses extra keys prefixed with "nagram" in KEY_RESTART_INTENTS and KEY_MAIN_PROCESS_PID; consider renaming these to match the current app naming (e.g., "nekogram") for consistency.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- AppRestartHelper.triggerRebirth assumes at least one intent and directly accesses nextIntents[0]; add a guard or require a non-empty vararg to avoid potential ArrayIndexOutOfBoundsException.
- The restart helper uses extra keys prefixed with "nagram" in KEY_RESTART_INTENTS and KEY_MAIN_PROCESS_PID; consider renaming these to match the current app naming (e.g., "nekogram") for consistency.
## Individual Comments
### Comment 1
<location path="TMessagesProj/src/main/java/tw/nekomimi/nekogram/helpers/AppRestartHelper.java" line_range="19-20" />
<code_context>
+ private static final String KEY_RESTART_INTENTS = "nagram_restart_intents";
+ private static final String KEY_MAIN_PROCESS_PID = "nagram_main_process_pid";
+
+ public static void triggerRebirth(Context context, Intent... nextIntents) {
+ nextIntents[0].addFlags(FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TASK);
+ Intent intent = new Intent(context, AppRestartHelper.class);
+ intent.addFlags(FLAG_ACTIVITY_NEW_TASK);
</code_context>
<issue_to_address>
**suggestion:** Varargs use assumes at least one intent is provided, which is fragile for future callers.
Indexing `nextIntents[0]` will crash if `triggerRebirth(context)` is ever called without intents. To make this safer, either explicitly validate `nextIntents` (null/empty check with a clear exception) or change the method signature so at least one intent is required and any others are optional, letting the compiler enforce correct usage.
Suggested implementation:
```java
public static void triggerRebirth(Context context, Intent firstIntent, Intent... additionalIntents) {
if (firstIntent == null) {
throw new IllegalArgumentException("firstIntent must not be null");
}
firstIntent.addFlags(FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TASK);
Intent intent = new Intent(context, AppRestartHelper.class);
intent.addFlags(FLAG_ACTIVITY_NEW_TASK);
ArrayList<Intent> intents = new ArrayList<>();
intents.add(firstIntent);
if (additionalIntents != null && additionalIntents.length > 0) {
intents.addAll(Arrays.asList(additionalIntents));
}
intent.putParcelableArrayListExtra(KEY_RESTART_INTENTS, intents);
intent.putExtra(KEY_MAIN_PROCESS_PID, Process.myPid());
context.startActivity(intent);
}
```
Any existing calls to `triggerRebirth` must be updated to pass at least one `Intent` explicitly.
For example:
- `triggerRebirth(context, intent)` continues to work as-is.
- `triggerRebirth(context, intent1, intent2, ...)` continues to work as-is.
- Any call like `triggerRebirth(context)` (with no intents) will now fail to compile and must be adjusted to provide a first restart `Intent`.
</issue_to_address>
### Comment 2
<location path="TMessagesProj/src/main/java/tw/nekomimi/nekogram/helpers/AppRestartHelper.java" line_range="32" />
<code_context>
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ Process.killProcess(getIntent().getIntExtra(KEY_MAIN_PROCESS_PID, -1));
+ ArrayList<Intent> intents = getIntent().getParcelableArrayListExtra(KEY_RESTART_INTENTS);
+ if (intents != null) {
+ startActivities(intents.toArray(new Intent[0]));
</code_context>
<issue_to_address>
**suggestion:** Handle the case where the restart intents extra is missing to avoid leaving a blank helper activity.
If `KEY_RESTART_INTENTS` is missing or deserialization fails, `intents` will be `null` and this block is skipped, leaving the helper activity running with no UI. Consider calling `finish()` (and potentially terminating the process) in the `null` case so users can’t get stuck on a blank screen if the extras are malformed or absent.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Parsa307
force-pushed
the
reset-settings
branch
7 times, most recently
from
July 22, 2026 19:33
01964fe to
6edb203
Compare
thanks to @NagramX Co-authored-by: risin42 <5331402+risin42@users.noreply.github.com>
omg-xtao
approved these changes
Jul 23, 2026
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
thanks to @NagramX
files and codes borrowed from:
https://github.com/risin42/NagramX/blob/beaec62055fdab95aab31c55d7a809c6f2289bb8/TMessagesProj/src/main/java/tw/nekomimi/nekogram/helpers/AppRestartHelper.java
https://github.com/risin42/NagramX/blob/beaec62055fdab95aab31c55d7a809c6f2289bb8/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoSettingsActivity.java#L81
https://github.com/risin42/NagramX/blob/beaec62055fdab95aab31c55d7a809c6f2289bb8/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoSettingsActivity.java#L105
https://github.com/risin42/NagramX/blob/beaec62055fdab95aab31c55d7a809c6f2289bb8/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoSettingsActivity.java#L355-L366
https://github.com/risin42/NagramX/blob/6dc11748b1bb8347532b5926ac0349106e2e37f9/TMessagesProj/src/main/res/values
Summary by Sourcery
Add a settings option to reset all Neko-related preferences and restart the app to apply a clean configuration state.
New Features: