From 7e1fd4ff0b1146d4a3a6902647a9009dde86c1ae Mon Sep 17 00:00:00 2001 From: Martin Zeitler Date: Fri, 12 Jul 2024 20:37:35 +0200 Subject: [PATCH] some code cleanup. --- .../syslogic/github/fragment/PreferencesFragment.java | 4 ++-- .../syslogic/github/network/AccountAuthenticator.java | 2 +- .../java/io/syslogic/github/network/TokenHelper.java | 10 ++++++---- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/mobile/src/main/java/io/syslogic/github/fragment/PreferencesFragment.java b/mobile/src/main/java/io/syslogic/github/fragment/PreferencesFragment.java index c833ff5e..d627ca98 100644 --- a/mobile/src/main/java/io/syslogic/github/fragment/PreferencesFragment.java +++ b/mobile/src/main/java/io/syslogic/github/fragment/PreferencesFragment.java @@ -112,7 +112,7 @@ public void onCreatePreferences(@Nullable Bundle savedInstanceState, @Nullable S requireActivity().startActivityFromFragment(this, intent, 100); return true; } catch (ActivityNotFoundException e) { - if (mDebug) {Log.e(LOG_TAG, "" + e.getMessage());} + if (mDebug) {Log.e(LOG_TAG, "ActivityNotFoundException: " + e.getMessage());} return false; } }); @@ -182,7 +182,7 @@ private void chooseDirectory() { try { requestFileChooserResult.launch(intent); } catch (ActivityNotFoundException e) { - Log.e(LOG_TAG, "" + e.getMessage()); + Log.e(LOG_TAG, "ActivityNotFoundException: " + e.getMessage()); } } diff --git a/mobile/src/main/java/io/syslogic/github/network/AccountAuthenticator.java b/mobile/src/main/java/io/syslogic/github/network/AccountAuthenticator.java index 19985568..ff5fa28e 100644 --- a/mobile/src/main/java/io/syslogic/github/network/AccountAuthenticator.java +++ b/mobile/src/main/java/io/syslogic/github/network/AccountAuthenticator.java @@ -99,7 +99,7 @@ public Bundle addAccount( * The result will contain either: * diff --git a/mobile/src/main/java/io/syslogic/github/network/TokenHelper.java b/mobile/src/main/java/io/syslogic/github/network/TokenHelper.java index 178410fa..bdc3b3a8 100644 --- a/mobile/src/main/java/io/syslogic/github/network/TokenHelper.java +++ b/mobile/src/main/java/io/syslogic/github/network/TokenHelper.java @@ -19,14 +19,15 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; + import io.syslogic.github.BuildConfig; import io.syslogic.github.Constants; +import io.syslogic.github.R; import io.syslogic.github.activity.AuthenticatorActivity; import io.syslogic.github.activity.NavHostActivity; import io.syslogic.github.api.GithubClient; import io.syslogic.github.api.model.User; import io.syslogic.github.fragment.HomeScreenFragment; -import io.syslogic.github.fragment.HomeScreenFragmentDirections; import retrofit2.Call; import retrofit2.Callback; @@ -89,6 +90,7 @@ public static String getUsername(@NonNull Context context) { } } + @Nullable private static String loadTokenFromPackageMeta(@NonNull Activity activity, AccountManager accountManager) { String token = null; try { @@ -137,8 +139,7 @@ public void onResponse(@NonNull Call call, @NonNull Response respons if (activity instanceof NavHostActivity activity2) { if (activity2.getCurrentFragment() instanceof HomeScreenFragment) { activity2.getNavController().navigate( - HomeScreenFragmentDirections - .actionHomeScreenFragmentToPreferencesFragment() + R.id.action_homeScreenFragment_to_preferencesFragment ); } } @@ -156,7 +157,8 @@ public void onFailure(@NonNull Call call, @NonNull Throwable t) { } } } catch (NullPointerException | PackageManager.NameNotFoundException e) { - e.printStackTrace(); + Log.e(LOG_TAG, e.getClass().getSimpleName() + ": " + e.getMessage()); + return null; } return token; }