From 5cdc3fef897f359a72008bd966032b178b915aab Mon Sep 17 00:00:00 2001 From: Vlad Golubev Date: Sun, 25 Jan 2015 01:43:47 +0200 Subject: [PATCH] Resolve #10 - Crash on orientation change --- app/src/main/AndroidManifest.xml | 1 - .../java/ua/samosfator/moduleok/Auth.java | 3 +- .../ua/samosfator/moduleok/MainActivity.java | 3 ++ .../fragment/NavigationDrawerFragment.java | 30 ++++++++++--------- .../moduleok/fragment/SemesterSpinner.java | 3 +- .../modules_fragment/ModuleFragment.java | 14 +++++---- .../SubjectsFragment.java | 2 ++ 7 files changed, 33 insertions(+), 23 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index de58a42..0d36228 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -13,7 +13,6 @@ android:theme="@style/AppTheme"> diff --git a/app/src/main/java/ua/samosfator/moduleok/Auth.java b/app/src/main/java/ua/samosfator/moduleok/Auth.java index c106187..4d44942 100644 --- a/app/src/main/java/ua/samosfator/moduleok/Auth.java +++ b/app/src/main/java/ua/samosfator/moduleok/Auth.java @@ -21,7 +21,7 @@ public void signIn(String login, String password) { } private void downloadSessionId(String login, String password) { - Connection.Response loginResponse = null; + Connection.Response loginResponse; try { loginResponse = downloadLoginResponse(login, password); Document loginDocument = loginResponse.parse(); @@ -61,6 +61,7 @@ public boolean isSuccess() { return success; } + @SuppressWarnings("UnusedDeclaration") public void onEvent(LoginEvent event) { StudentKeeper.initStudent(); } diff --git a/app/src/main/java/ua/samosfator/moduleok/MainActivity.java b/app/src/main/java/ua/samosfator/moduleok/MainActivity.java index 03eab09..59edaa4 100644 --- a/app/src/main/java/ua/samosfator/moduleok/MainActivity.java +++ b/app/src/main/java/ua/samosfator/moduleok/MainActivity.java @@ -43,6 +43,7 @@ protected void onCreate(Bundle savedInstanceState) { @Override protected void onResume() { registerClassForEventBus(); + initNavigationDrawer(); super.onResume(); } @@ -139,10 +140,12 @@ public boolean onOptionsItemSelected(MenuItem item) { return super.onOptionsItemSelected(item); } + @SuppressWarnings("UnusedDeclaration") public void onEvent(LoginEvent event) { setAccountInfo(); } + @SuppressWarnings("UnusedDeclaration") public void onEvent(LogoutEvent event) { eraseAccountInfo(); } diff --git a/app/src/main/java/ua/samosfator/moduleok/fragment/NavigationDrawerFragment.java b/app/src/main/java/ua/samosfator/moduleok/fragment/NavigationDrawerFragment.java index 823cd87..c2f07e4 100644 --- a/app/src/main/java/ua/samosfator/moduleok/fragment/NavigationDrawerFragment.java +++ b/app/src/main/java/ua/samosfator/moduleok/fragment/NavigationDrawerFragment.java @@ -112,19 +112,6 @@ public void addLoginSection() { } } - public void onEvent(LoginEvent event) { - getActivity().runOnUiThread(new Runnable() { - @Override - public void run() { - addLoginOrLogoutSection(); - } - }); - } - - public void onEvent(LogoutEvent event) { - addLoginOrLogoutSection(); - } - @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { @@ -165,7 +152,7 @@ public void onDrawerOpened(View drawerView) { private void saveUserSawDrawerState() { mUserSawDrawer = true; - Preferences.save(KEY_USER_SAW_DRAWER, String.valueOf(mUserSawDrawer)); + Preferences.save(KEY_USER_SAW_DRAWER, String.valueOf(true)); } @Override @@ -188,6 +175,21 @@ public void run() { }); } + @SuppressWarnings("UnusedDeclaration") + public void onEvent(LoginEvent event) { + getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + addLoginOrLogoutSection(); + } + }); + } + + @SuppressWarnings("UnusedDeclaration") + public void onEvent(LogoutEvent event) { + addLoginOrLogoutSection(); + } + @Override public void onStop() { EventBus.getDefault().unregister(this); diff --git a/app/src/main/java/ua/samosfator/moduleok/fragment/SemesterSpinner.java b/app/src/main/java/ua/samosfator/moduleok/fragment/SemesterSpinner.java index 434862b..78a5e89 100644 --- a/app/src/main/java/ua/samosfator/moduleok/fragment/SemesterSpinner.java +++ b/app/src/main/java/ua/samosfator/moduleok/fragment/SemesterSpinner.java @@ -48,7 +48,8 @@ public void onItemSelected(AdapterView parent, View view, int position, long } private void setItemColorLight(AdapterView parent) { - ((TextView) parent.getChildAt(0)).setTextColor(App.getContext().getResources().getColor(R.color.textColorPrimary)); + int textColorPrimary = App.getContext().getResources().getColor(R.color.textColorPrimary); + ((TextView) parent.getChildAt(0)).setTextColor(textColorPrimary); } @Override diff --git a/app/src/main/java/ua/samosfator/moduleok/fragment/modules_fragment/ModuleFragment.java b/app/src/main/java/ua/samosfator/moduleok/fragment/modules_fragment/ModuleFragment.java index d7e97f7..b14ac4a 100644 --- a/app/src/main/java/ua/samosfator/moduleok/fragment/modules_fragment/ModuleFragment.java +++ b/app/src/main/java/ua/samosfator/moduleok/fragment/modules_fragment/ModuleFragment.java @@ -43,12 +43,11 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa return rootView; } - public void onEvent(RefreshEvent event) { - StudentKeeper.refreshStudent(); - ModulesFragment.initSubjects(); - reRenderModuleSubjectsList(); + private void reRenderModuleSubjectsList() { + moduleSubjectItemAdapter.notifyItemRangeChanged(0, moduleSubjectItemAdapter.getItemCount()); } + @SuppressWarnings("UnusedDeclaration") public void onEvent(SemesterChangedEvent event) { Log.d("SEMESTER_CHANGED_EVENT", "SemesterIndex:" + StudentKeeper.getCurrentSemesterIndex()); @@ -56,8 +55,11 @@ public void onEvent(SemesterChangedEvent event) { reRenderModuleSubjectsList(); } - private void reRenderModuleSubjectsList() { - moduleSubjectItemAdapter.notifyItemRangeChanged(0, moduleSubjectItemAdapter.getItemCount()); + @SuppressWarnings("UnusedDeclaration") + public void onEvent(RefreshEvent event) { + StudentKeeper.refreshStudent(); + ModulesFragment.initSubjects(); + reRenderModuleSubjectsList(); } @Override diff --git a/app/src/main/java/ua/samosfator/moduleok/fragment/semesters_subjects_fragment/SubjectsFragment.java b/app/src/main/java/ua/samosfator/moduleok/fragment/semesters_subjects_fragment/SubjectsFragment.java index 2d49af6..9ebbbc1 100644 --- a/app/src/main/java/ua/samosfator/moduleok/fragment/semesters_subjects_fragment/SubjectsFragment.java +++ b/app/src/main/java/ua/samosfator/moduleok/fragment/semesters_subjects_fragment/SubjectsFragment.java @@ -103,12 +103,14 @@ private void openLoginFragment() { .commit(); } + @SuppressWarnings("UnusedDeclaration") public void onEvent(RefreshEvent event) { StudentKeeper.refreshStudent(); initSubjects(); reRenderSubjectsList(); } + @SuppressWarnings("UnusedDeclaration") public void onEvent(SemesterChangedEvent event) { Log.d("SEMESTER_CHANGED_EVENT", "SemesterIndex:" + StudentKeeper.getCurrentSemesterIndex());