From 1c17e6b7d271dddc12e2a180f82272dc5133b861 Mon Sep 17 00:00:00 2001 From: Balazs Toldi Date: Thu, 12 Oct 2023 08:26:50 +0200 Subject: [PATCH] Fix some issues with the "goto User" and "goto Community" options This commit allows the user to input the communities with their "!" prefix. Similarly, it also allows the "@" prefix for users when trying to navigate to them with their corresponding "go to" options. Also fixes issues with these options in the Community and User pages. --- .../activities/MainActivity.java | 25 ++++++++++++++++--- .../ViewSubredditDetailActivity.java | 24 +++++++++++++++--- .../activities/ViewUserDetailActivity.java | 24 +++++++++++++++--- 3 files changed, 61 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/eu/toldi/infinityforlemmy/activities/MainActivity.java b/app/src/main/java/eu/toldi/infinityforlemmy/activities/MainActivity.java index cd9504b5..26f4ccc5 100644 --- a/app/src/main/java/eu/toldi/infinityforlemmy/activities/MainActivity.java +++ b/app/src/main/java/eu/toldi/infinityforlemmy/activities/MainActivity.java @@ -1514,7 +1514,12 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb if (i == EditorInfo.IME_ACTION_DONE) { Utils.hideKeyboard(this); Intent subredditIntent = new Intent(this, ViewSubredditDetailActivity.class); - subredditIntent.putExtra(ViewSubredditDetailActivity.EXTRA_COMMUNITY_FULL_NAME_KEY, thingEditText.getText().toString()); + String communityName = thingEditText.getText().toString(); + if (communityName.startsWith("!")) { + communityName = communityName.substring(1); + } + subredditIntent.putExtra(ViewSubredditDetailActivity.EXTRA_COMMUNITY_FULL_NAME_KEY, communityName); + startActivity(subredditIntent); return true; } @@ -1572,7 +1577,11 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb -> { Utils.hideKeyboard(this); Intent subredditIntent = new Intent(this, ViewSubredditDetailActivity.class); - subredditIntent.putExtra(ViewSubredditDetailActivity.EXTRA_COMMUNITY_FULL_NAME_KEY, thingEditText.getText().toString()); + String communityName = thingEditText.getText().toString(); + if (communityName.startsWith("!")) { + communityName = communityName.substring(1); + } + subredditIntent.putExtra(ViewSubredditDetailActivity.EXTRA_COMMUNITY_FULL_NAME_KEY, communityName); startActivity(subredditIntent); }) .setNegativeButton(R.string.cancel, (dialogInterface, i) -> { @@ -1593,7 +1602,11 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb if (i == EditorInfo.IME_ACTION_DONE) { Utils.hideKeyboard(this); Intent userIntent = new Intent(this, ViewUserDetailActivity.class); - userIntent.putExtra(ViewUserDetailActivity.EXTRA_QUALIFIED_USER_NAME_KEY, thingEditText.getText().toString()); + String qualifiedName = thingEditText.getText().toString(); + if (qualifiedName.startsWith("@")) { + qualifiedName = qualifiedName.substring(1); + } + userIntent.putExtra(ViewUserDetailActivity.EXTRA_QUALIFIED_USER_NAME_KEY, qualifiedName); startActivity(userIntent); return true; } @@ -1606,7 +1619,11 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb -> { Utils.hideKeyboard(this); Intent userIntent = new Intent(this, ViewUserDetailActivity.class); - userIntent.putExtra(ViewUserDetailActivity.EXTRA_QUALIFIED_USER_NAME_KEY, thingEditText.getText().toString()); + String qualifiedName = thingEditText.getText().toString(); + if (qualifiedName.startsWith("@")) { + qualifiedName = qualifiedName.substring(1); + } + userIntent.putExtra(ViewUserDetailActivity.EXTRA_QUALIFIED_USER_NAME_KEY, qualifiedName); startActivity(userIntent); }) .setNegativeButton(R.string.cancel, (dialogInterface, i) -> { diff --git a/app/src/main/java/eu/toldi/infinityforlemmy/activities/ViewSubredditDetailActivity.java b/app/src/main/java/eu/toldi/infinityforlemmy/activities/ViewSubredditDetailActivity.java index 23239b43..6720f856 100644 --- a/app/src/main/java/eu/toldi/infinityforlemmy/activities/ViewSubredditDetailActivity.java +++ b/app/src/main/java/eu/toldi/infinityforlemmy/activities/ViewSubredditDetailActivity.java @@ -1518,7 +1518,11 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp if (i == EditorInfo.IME_ACTION_DONE) { Utils.hideKeyboard(this); Intent subredditIntent = new Intent(this, ViewSubredditDetailActivity.class); - subredditIntent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, thingEditText.getText().toString()); + String communityName = thingEditText.getText().toString(); + if (communityName.startsWith("!")) { + communityName = communityName.substring(1); + } + subredditIntent.putExtra(ViewSubredditDetailActivity.EXTRA_COMMUNITY_FULL_NAME_KEY, communityName); startActivity(subredditIntent); return true; } @@ -1576,7 +1580,11 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp -> { Utils.hideKeyboard(this); Intent subredditIntent = new Intent(this, ViewSubredditDetailActivity.class); - subredditIntent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, thingEditText.getText().toString()); + String communityName = thingEditText.getText().toString(); + if (communityName.startsWith("!")) { + communityName = communityName.substring(1); + } + subredditIntent.putExtra(ViewSubredditDetailActivity.EXTRA_COMMUNITY_FULL_NAME_KEY, communityName); startActivity(subredditIntent); }) .setNegativeButton(R.string.cancel, (dialogInterface, i) -> { @@ -1597,7 +1605,11 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp if (i == EditorInfo.IME_ACTION_DONE) { Utils.hideKeyboard(this); Intent userIntent = new Intent(this, ViewUserDetailActivity.class); - userIntent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, thingEditText.getText().toString()); + String qualifiedName = thingEditText.getText().toString(); + if (qualifiedName.startsWith("@")) { + qualifiedName = qualifiedName.substring(1); + } + userIntent.putExtra(ViewUserDetailActivity.EXTRA_QUALIFIED_USER_NAME_KEY, qualifiedName); startActivity(userIntent); return true; } @@ -1610,7 +1622,11 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp -> { Utils.hideKeyboard(this); Intent userIntent = new Intent(this, ViewUserDetailActivity.class); - userIntent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, thingEditText.getText().toString()); + String qualifiedName = thingEditText.getText().toString(); + if (qualifiedName.startsWith("@")) { + qualifiedName = qualifiedName.substring(1); + } + userIntent.putExtra(ViewUserDetailActivity.EXTRA_QUALIFIED_USER_NAME_KEY, qualifiedName); startActivity(userIntent); }) .setNegativeButton(R.string.cancel, (dialogInterface, i) -> { diff --git a/app/src/main/java/eu/toldi/infinityforlemmy/activities/ViewUserDetailActivity.java b/app/src/main/java/eu/toldi/infinityforlemmy/activities/ViewUserDetailActivity.java index 241a6021..c1676e62 100644 --- a/app/src/main/java/eu/toldi/infinityforlemmy/activities/ViewUserDetailActivity.java +++ b/app/src/main/java/eu/toldi/infinityforlemmy/activities/ViewUserDetailActivity.java @@ -1514,7 +1514,11 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele if (i == EditorInfo.IME_ACTION_DONE) { Utils.hideKeyboard(this); Intent subredditIntent = new Intent(this, ViewSubredditDetailActivity.class); - subredditIntent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, thingEditText.getText().toString()); + String communityName = thingEditText.getText().toString(); + if (communityName.startsWith("!")) { + communityName = communityName.substring(1); + } + subredditIntent.putExtra(ViewSubredditDetailActivity.EXTRA_COMMUNITY_FULL_NAME_KEY, communityName); startActivity(subredditIntent); return true; } @@ -1572,7 +1576,11 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele -> { Utils.hideKeyboard(this); Intent subredditIntent = new Intent(this, ViewSubredditDetailActivity.class); - subredditIntent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, thingEditText.getText().toString()); + String communityName = thingEditText.getText().toString(); + if (communityName.startsWith("!")) { + communityName = communityName.substring(1); + } + subredditIntent.putExtra(ViewSubredditDetailActivity.EXTRA_COMMUNITY_FULL_NAME_KEY, communityName); startActivity(subredditIntent); }) .setNegativeButton(R.string.cancel, (dialogInterface, i) -> { @@ -1593,7 +1601,11 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele if (i == EditorInfo.IME_ACTION_DONE) { Utils.hideKeyboard(this); Intent userIntent = new Intent(this, ViewUserDetailActivity.class); - userIntent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, thingEditText.getText().toString()); + String userName = thingEditText.getText().toString(); + if (userName.startsWith("@")) { + userName = userName.substring(1); + } + userIntent.putExtra(ViewUserDetailActivity.EXTRA_QUALIFIED_USER_NAME_KEY, userName); startActivity(userIntent); return true; } @@ -1606,7 +1618,11 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele -> { Utils.hideKeyboard(this); Intent userIntent = new Intent(this, ViewUserDetailActivity.class); - userIntent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, thingEditText.getText().toString()); + String userName = thingEditText.getText().toString(); + if (userName.startsWith("@")) { + userName = userName.substring(1); + } + userIntent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, userName); startActivity(userIntent); }) .setNegativeButton(R.string.cancel, (dialogInterface, i) -> {