From 2e348a76b7c6134a45f671e6d501caebaa3e362e Mon Sep 17 00:00:00 2001 From: Thomas Date: Sun, 29 May 2022 11:03:28 +0200 Subject: [PATCH] Fix a db issue --- .../android/activities/LoginActivity.java | 36 ++++++++++++------- .../app/fedilab/android/sqlite/Sqlite.java | 2 +- .../ui/fragment/login/FragmentLoginMain.java | 3 ++ 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/app/fedilab/android/activities/LoginActivity.java b/app/src/main/java/app/fedilab/android/activities/LoginActivity.java index 0d9226c8..dcf933e6 100644 --- a/app/src/main/java/app/fedilab/android/activities/LoginActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/LoginActivity.java @@ -54,19 +54,10 @@ public class LoginActivity extends BaseActivity { private final int PICK_IMPORT = 5557; private boolean requestedAdmin; - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - ThemeHelper.applyTheme(this); - SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(LoginActivity.this); - setContentView(new FrameLayout(this)); - Helper.addFragment(getSupportFragmentManager(), android.R.id.content, new FragmentLoginMain(), null, null, null); - requestedAdmin = false; - //The activity handles a redirect URI, it will extract token code and will proceed to authentication - //That happens when the user wants to use an external browser - if (getIntent() != null && getIntent().getData() != null && getIntent().getData().toString().contains(REDIRECT_CONTENT_WEB + "?code=")) { - String url = getIntent().getData().toString(); + private void manageItent(Intent intent) { + if (intent != null && intent.getData() != null && intent.getData().toString().contains(REDIRECT_CONTENT_WEB + "?code=")) { + String url = intent.getData().toString(); Matcher matcher = Helper.codePattern.matcher(url); if (!matcher.find()) { Toasty.error(LoginActivity.this, getString(R.string.toast_code_error), Toast.LENGTH_LONG).show(); @@ -108,6 +99,27 @@ public class LoginActivity extends BaseActivity { } } + + @Override + protected void onNewIntent(Intent intent) { + super.onNewIntent(intent); + manageItent(intent); + } + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + ThemeHelper.applyTheme(this); + SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(LoginActivity.this); + setContentView(new FrameLayout(this)); + + Helper.addFragment(getSupportFragmentManager(), android.R.id.content, new FragmentLoginMain(), null, null, null); + requestedAdmin = false; + //The activity handles a redirect URI, it will extract token code and will proceed to authentication + //That happens when the user wants to use an external browser + manageItent(getIntent()); + } + public boolean requestedAdmin() { return requestedAdmin; } diff --git a/app/src/main/java/app/fedilab/android/sqlite/Sqlite.java b/app/src/main/java/app/fedilab/android/sqlite/Sqlite.java index 895184dc..d1142d4e 100644 --- a/app/src/main/java/app/fedilab/android/sqlite/Sqlite.java +++ b/app/src/main/java/app/fedilab/android/sqlite/Sqlite.java @@ -95,7 +95,7 @@ public class Sqlite extends SQLiteOpenHelper { + COL_APP_CLIENT_ID + " TEXT NOT NULL, " + COL_APP_CLIENT_SECRET + " TEXT NOT NULL, " + COL_CREATED_AT + " TEXT NOT NULL," - + COL_ADMIN + "INTEGER NOT NULL DEFAULT 0," + + COL_ADMIN + " INTEGER NOT NULL DEFAULT 0," + COL_UPDATED_AT + " TEXT)"; private static final String CREATE_TABLE_TIMELINES = "CREATE TABLE IF NOT EXISTS " + TABLE_TIMELINES + " (" + COL_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " diff --git a/app/src/main/java/app/fedilab/android/ui/fragment/login/FragmentLoginMain.java b/app/src/main/java/app/fedilab/android/ui/fragment/login/FragmentLoginMain.java index c879b8db..f8e54f0c 100644 --- a/app/src/main/java/app/fedilab/android/ui/fragment/login/FragmentLoginMain.java +++ b/app/src/main/java/app/fedilab/android/ui/fragment/login/FragmentLoginMain.java @@ -142,6 +142,9 @@ public class FragmentLoginMain extends Fragment { binding.continueButton.setEnabled(false); NodeInfoVM nodeInfoVM = new ViewModelProvider(requireActivity()).get(NodeInfoVM.class); nodeInfoVM.getNodeInfo(binding.loginInstance.getText().toString()).observe(requireActivity(), nodeInfo -> { + if (nodeInfo == null) { + return; + } binding.continueButton.setEnabled(true); BaseMainActivity.software = nodeInfo.software.name.toUpperCase(); switch (nodeInfo.software.name.toUpperCase().trim()) {