Skip to content

Commit

Permalink
Resolve #10 - Crash on orientation change
Browse files Browse the repository at this point in the history
  • Loading branch information
vladholubiev committed Jan 24, 2015
1 parent 26f7283 commit 5cdc3fe
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 23 deletions.
1 change: 0 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:screenOrientation="portrait"
android:label="@string/title_activity_main">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/ua/samosfator/moduleok/Auth.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -61,6 +61,7 @@ public boolean isSuccess() {
return success;
}

@SuppressWarnings("UnusedDeclaration")
public void onEvent(LoginEvent event) {
StudentKeeper.initStudent();
}
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/java/ua/samosfator/moduleok/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ protected void onCreate(Bundle savedInstanceState) {
@Override
protected void onResume() {
registerClassForEventBus();
initNavigationDrawer();
super.onResume();
}

Expand Down Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,23 @@ 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());

ModulesFragment.initSubjects();
reRenderModuleSubjectsList();
}

private void reRenderModuleSubjectsList() {
moduleSubjectItemAdapter.notifyItemRangeChanged(0, moduleSubjectItemAdapter.getItemCount());
@SuppressWarnings("UnusedDeclaration")
public void onEvent(RefreshEvent event) {
StudentKeeper.refreshStudent();
ModulesFragment.initSubjects();
reRenderModuleSubjectsList();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down

0 comments on commit 5cdc3fe

Please sign in to comment.