Skip to content

Commit

Permalink
Rename Profiles/Groups v2 (#1596)
Browse files Browse the repository at this point in the history
  • Loading branch information
gdlbo authored Mar 29, 2024
1 parent 46c4f1c commit 5de52ed
Show file tree
Hide file tree
Showing 5 changed files with 205 additions and 166 deletions.
45 changes: 28 additions & 17 deletions app/src/main/java/ru/vtosters/hooks/RenameHook.java
Original file line number Diff line number Diff line change
@@ -1,29 +1,40 @@
package ru.vtosters.hooks;

import androidx.core.util.Pair;
import org.json.JSONException;
import org.json.JSONObject;
import ru.vtosters.hooks.other.Preferences;
import ru.vtosters.lite.utils.RenameTool;

public class RenameHook {
public static void injectIntoJson(JSONObject obj) throws JSONException {
// int i = obj.getInt("id");
// if (RenameTool.updateRequested) {
// RenameTool.reloadDB();
// }
//
// Pair<String, String> user = RenameTool.renamedUsers.get(i);
// if (user == null) return;
// obj.put(RenameTool.COLUMN_FIRSTNAME, user.first).put(RenameTool.COLUMN_LASTNAME, user.second);
if (isEnabled()) {
int i = obj.getInt("id");
if (RenameTool.updateRequested) {
RenameTool.reloadDB();
}

Pair<String, String> user = RenameTool.renamedUsers.get(i);
if (user == null) return;
obj.put(RenameTool.COLUMN_FIRSTNAME, user.first).put(RenameTool.COLUMN_LASTNAME, user.second);
}
}

public static boolean isEnabled() {
return Preferences.getBoolValue("unstableNameChanger", true);
}

public static void injectIntoJsonGroup(JSONObject obj) throws JSONException {
// int i = obj.getInt("id");
//
// if (RenameTool.updateRequested) {
// RenameTool.reloadDB();
// }
//
// String user = RenameTool.renamedGroups.get(i);
// if (user == null) return;
// obj.put("name", user);
if (isEnabled()) {
int i = obj.getInt("id");

if (RenameTool.updateRequested) {
RenameTool.reloadDB();
}

String user = RenameTool.renamedGroups.get(i);
if (user == null) return;
obj.put("name", user);
}
}
}
11 changes: 11 additions & 0 deletions app/src/main/java/ru/vtosters/lite/ui/fragments/OtherFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,17 @@ private void prefs() {
return true;
});

findPreference("unstableNameChangerDrop").setOnPreferenceClickListener(preference -> {
RenameTool.clearDatabase();
LifecycleUtils.restartApplicationWithTimer();
return true;
});

findPreference("unstableNameChanger").setOnPreferenceChangeListener((preference, o) -> {
LifecycleUtils.restartApplicationWithTimer();
return true;
});

findPreference("copydebuginfo").setOnPreferenceClickListener(preference -> {
copyText(new DeviceInfoCollector().collect().forLogging());
Toast.makeText(requireContext(), AndroidUtils.getString("device_info_copied"), Toast.LENGTH_SHORT).show();
Expand Down
26 changes: 16 additions & 10 deletions app/src/main/java/ru/vtosters/lite/ui/vkui/MenuBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@
import com.vtosters.lite.api.ExtendedUserProfile;
import kotlin.Unit;
import kotlin.jvm.b.Functions;
import ru.vtosters.hooks.RenameHook;
import ru.vtosters.hooks.other.Preferences;
import ru.vtosters.lite.foaf.FoafBase;
import ru.vtosters.lite.utils.AccountManagerUtils;
import ru.vtosters.lite.utils.AndroidUtils;
import ru.vtosters.lite.utils.RenameTool;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
Expand Down Expand Up @@ -66,10 +68,12 @@ public static void injectAP(final ProfileFragmentActionsMenuBuilder mb, final Ac
return Unit.a;
});

// addItem(builder, AndroidUtils.getString(R.string.menu_change_name), () -> {
// RenameTool.createDialog(eup, ctx);
// return Unit.a;
// });
if (RenameHook.isEnabled()) {
addItem(builder, AndroidUtils.getString(R.string.menu_change_name), () -> {
RenameTool.createDialog(eup, ctx);
return Unit.a;
});
}

addItem(builder, AndroidUtils.getString(isPageWhitelistedFilter ? R.string.remove_from_filter_whitelist : R.string.add_to_filter_whitelist), () -> {
setWhitelistedFilter(eup, !isPageWhitelistedFilter);
Expand All @@ -83,7 +87,7 @@ public static void injectAP(final ProfileFragmentActionsMenuBuilder mb, final Ac
return Unit.a;
});
} catch (IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
e.fillInStackTrace();
}
}

Expand All @@ -100,10 +104,12 @@ public static void injectAP(final CommunityFragmentActionsMenuBuilder mb, final
return Unit.a;
});

// addItem(builder, AndroidUtils.getString(R.string.menu_change_name), () -> {
// RenameTool.createDialogGroup(ecp, ctx);
// return Unit.a;
// });
if (RenameHook.isEnabled()) {
addItem(builder, AndroidUtils.getString(R.string.menu_change_name), () -> {
RenameTool.createDialogGroup(ecp, ctx);
return Unit.a;
});
}

addItem(builder, AndroidUtils.getString(isPageWhitelistedFilter ? R.string.remove_from_filter_whitelist : R.string.add_to_filter_whitelist), () -> {
setWhitelistedFilter(ecp, !isPageWhitelistedFilter);
Expand All @@ -123,7 +129,7 @@ public static void injectAP(final CommunityFragmentActionsMenuBuilder mb, final
return Unit.a;
});
} catch (IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
e.fillInStackTrace();
}
}

Expand Down
Loading

0 comments on commit 5de52ed

Please sign in to comment.