Skip to content

Commit

Permalink
fix #6: Select first row of notifications after refresh on tablet
Browse files Browse the repository at this point in the history
  • Loading branch information
maxme committed Sep 23, 2013
1 parent 105d47a commit 1702e8b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
1 change: 1 addition & 0 deletions res/layout-sw600dp/notifications.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<fragment
android:name="org.wordpress.android.ui.notifications.NotificationsListFragment"
android:id="@+id/notes_list"
android:tag="tablet-view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
Expand Down
1 change: 1 addition & 0 deletions res/layout-sw720dp/notifications.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<fragment
android:name="org.wordpress.android.ui.notifications.NotificationsListFragment"
android:id="@+id/notes_list"
android:tag="tablet-view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ public void onCreate(Bundle savedInstanceState){
mNotesList.setNoteProvider(new NoteProvider());
mNotesList.setOnNoteClickListener(new NoteClickListener());

// Load notes
notes = WordPress.wpDB.loadNotes();

fragmentDetectors.add(new FragmentDetector(){
@Override
public Fragment getFragment(Note note){
Expand All @@ -85,15 +88,15 @@ public Fragment getFragment(Note note){
return null;
}
});
fragmentDetectors.add(new FragmentDetector(){
@Override
public Fragment getFragment(Note note){
if (note.isSingleLineListTemplate()) {
Fragment fragment = new SingleLineListFragment();
return fragment;
}
return null;
}
fragmentDetectors.add(new FragmentDetector() {
@Override
public Fragment getFragment(Note note) {
if (note.isSingleLineListTemplate()) {
Fragment fragment = new SingleLineListFragment();
return fragment;
}
return null;
}
});
fragmentDetectors.add(new FragmentDetector(){
@Override
Expand All @@ -112,8 +115,6 @@ public Fragment getFragment(Note note){
if (savedInstanceState == null)
launchWithNoteId();

// Load notes
notes = WordPress.wpDB.loadNotes();
refreshNotificationsListFragment(notes);

if (savedInstanceState != null)
Expand Down Expand Up @@ -160,7 +161,6 @@ private void launchWithNoteId(){
openNote(note);
}
} else if (intent.hasExtra(NOTE_ID_EXTRA)) {
// FIXME: check if in DB and not placeholder...
// find it/load it etc
Map<String, String> params = new HashMap<String, String>();
params.put("ids", intent.getStringExtra(NOTE_ID_EXTRA));
Expand All @@ -176,9 +176,20 @@ public void onNotes(List<Note> notes){
};
restClient.getNotifications(params, handler, handler);
} else {
// on a tablet: open first note if none selected
String fragmentTag = mNotesList.getTag();
if (fragmentTag != null && fragmentTag.equals("tablet-view")) {
if (notes != null && notes.size() > 0) {
Note note = notes.get(0);
if (note != null) {
openNote(note);
}
}
}
refreshNotes();
}
}

@Override
public boolean onOptionsItemSelected(final MenuItem item) {
if (item.equals(mRefreshMenuItem)) {
Expand Down

0 comments on commit 1702e8b

Please sign in to comment.