From a3a9ae4d3920501b09148dc1a9a5932df77f2f34 Mon Sep 17 00:00:00 2001 From: uykek Date: Sun, 30 Aug 2020 13:09:02 +0200 Subject: [PATCH] Adjust ImportBoardDialog: Use String.startsWith instead of String.contains when examining the whether or not the input contains the correct url schemes --- .../ui/CreateSudokuActivity.java | 4 ++-- .../privacyfriendlysudoku/ui/MainActivity.java | 12 ++++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/CreateSudokuActivity.java b/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/CreateSudokuActivity.java index f5061d5..b46171a 100644 --- a/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/CreateSudokuActivity.java +++ b/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/CreateSudokuActivity.java @@ -215,9 +215,9 @@ public class CreateSudokuActivity extends BaseActivity implements IFinalizeDialo remove the present prefix, or, if the input contains neither of the prefixes, notify the user that their input is not valid */ - if (input.contains(prefix1)) { + if (input.startsWith(prefix1)) { inputSudoku = input.replace(prefix1, ""); - } else if (input.contains(prefix2)) { + } else if (input.startsWith(prefix2)) { inputSudoku = input.replace(prefix2, ""); } else { Toast.makeText(CreateSudokuActivity.this, diff --git a/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/MainActivity.java b/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/MainActivity.java index 90896e4..50670a8 100644 --- a/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/MainActivity.java +++ b/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/MainActivity.java @@ -40,6 +40,8 @@ import androidx.viewpager.widget.ViewPager; import androidx.drawerlayout.widget.DrawerLayout; import androidx.appcompat.app.ActionBarDrawerToggle; import androidx.appcompat.widget.Toolbar; + +import android.util.Log; import android.view.LayoutInflater; import android.view.MenuItem; import android.view.View; @@ -442,9 +444,9 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig remove the present prefix, or, if the input contains neither of the prefixes, notify the user that their input is not valid */ - if (input.contains(prefix1)) { + if (input.startsWith(prefix1)) { inputSudoku = input.replace(prefix1, ""); - } else if (input.contains(prefix2)) { + } else if (input.startsWith(prefix2)) { inputSudoku = input.replace(prefix2, ""); } else { Toast.makeText(MainActivity.this, @@ -452,7 +454,7 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig return; } - int size = (int)Math.sqrt(inputSudoku.length()); + double size = Math.sqrt(inputSudoku.length()); boolean validSize = false; // check whether or not the size of the encoded sudoku is valid; if not, notify the user @@ -468,7 +470,9 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig return; } - GameType gameType = Enum.valueOf(GameType.class, "Default_" + size + "x" + size); + Log.i("Default_" + size + "x" + size, "SudokuTag"); + + GameType gameType = Enum.valueOf(GameType.class, "Default_" + (int)size + "x" + (int)size); //check whether or not the sudoku is valid and has a unique solution boolean solvable = CreateSudokuActivity.verify(gameType, inputSudoku);