Skip to content

feat(settings): add reset settings - #69

Merged
omg-xtao merged 2 commits into
NextAlone:devfrom
Parsa307:reset-settings
Jul 23, 2026
Merged

feat(settings): add reset settings#69
omg-xtao merged 2 commits into
NextAlone:devfrom
Parsa307:reset-settings

Conversation

@Parsa307

@Parsa307 Parsa307 commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

@sourcery-ai

sourcery-ai Bot commented Jul 22, 2026

Copy link
Copy Markdown

Reviewer's Guide

Adds 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 app

sequenceDiagram
    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
Loading

File-Level Changes

Change Details Files
Introduce a reset-settings list item in the settings UI that clears local configuration and restarts the app via a helper activity.
  • Import NekoConfig and AppRestartHelper dependencies into NekoSettingsActivity.
  • Add resetSettingsRow field and register it when building the settings rows.
  • Handle clicks on the reset settings row by showing a confirmation dialog.
  • On confirmation, clear relevant SharedPreferences (nekocloud, nekox_config, NekoConfig) and restart using AppRestartHelper.triggerRebirth.
TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoSettingsActivity.java
Add localized strings for the reset-settings label and confirmation message across multiple locales.
  • Define ResetSettings and ResetSettingsAlert strings in the base strings_na resource file.
  • Provide translations for ResetSettings and ResetSettingsAlert in es, in, it, ja, pl, pt-BR, ru, tr, uk, zh-CN, zh-TW resource variants.
TMessagesProj/src/main/res/values/strings_na.xml
TMessagesProj/src/main/res/values-es-rES/strings_na.xml
TMessagesProj/src/main/res/values-in-rID/strings_na.xml
TMessagesProj/src/main/res/values-it-rIT/strings_na.xml
TMessagesProj/src/main/res/values-ja-rJP/strings_na.xml
TMessagesProj/src/main/res/values-pl-rPL/strings_na.xml
TMessagesProj/src/main/res/values-pt-rBR/strings_na.xml
TMessagesProj/src/main/res/values-ru-rRU/strings_na.xml
TMessagesProj/src/main/res/values-tr-rTR/strings_na.xml
TMessagesProj/src/main/res/values-uk-rUA/strings_na.xml
TMessagesProj/src/main/res/values-zh-rCN/strings_na.xml
TMessagesProj/src/main/res/values-zh-rTW/strings_na.xml
Create an AppRestartHelper activity that can restart the application by killing the current process and launching a new task stack.
  • Define AppRestartHelper as an Activity with static keys for restart intents and main process PID.
  • Implement triggerRebirth to wrap one or more target intents, add appropriate NEW_TASK/CLEAR_TASK flags, and start AppRestartHelper.
  • Implement onCreate to kill the recorded main process, start the provided intents as a new task stack, finish the helper activity, and exit the runtime.
TMessagesProj/src/main/java/tw/nekomimi/nekogram/helpers/AppRestartHelper.java

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@Parsa307
Parsa307 force-pushed the reset-settings branch 7 times, most recently from 01964fe to 6edb203 Compare July 22, 2026 19:33
@Parsa307 Parsa307 changed the title feat(settings): reset settings feat(settings): add reset settings Jul 22, 2026
thanks to @NagramX

Co-authored-by: risin42 <5331402+risin42@users.noreply.github.com>
@omg-xtao omg-xtao added the enhancement New feature or request label Jul 23, 2026
@omg-xtao
omg-xtao merged commit a13cb9b into NextAlone:dev Jul 23, 2026
4 of 5 checks passed
@Parsa307
Parsa307 deleted the reset-settings branch July 23, 2026 09:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants