Skip to content

Commit

Permalink
Fix mark as read being called when resuming from lock screen (fixes #19)
Browse files Browse the repository at this point in the history
Signed-off-by: Daniele Ricci <[email protected]>
  • Loading branch information
daniele-athome committed Jul 8, 2014
1 parent bbba67d commit 75dd5dc
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 4 deletions.
25 changes: 25 additions & 0 deletions src/org/kontalk/ui/ComposeMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ public class ComposeMessage extends ActionBarActivity {
private TextView mTitleView;
private TextView mSubtitleView;

/**
* True if the window has lost focus the last time
* {@link #onWindowFocusChanged} was called. */
private boolean mLostFocus;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down Expand Up @@ -409,6 +414,26 @@ protected void onSaveInstanceState(Bundle out) {
out.putParcelable(Uri.class.getName(), Threads.getUri(mFragment.getUserId()));
}

@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);

if (hasFocus) {
if (mLostFocus) {
mFragment.onFocus();
mLostFocus = false;
}
}
}

public void fragmentLostFocus() {
mLostFocus = true;
}

public boolean hasLostFocus() {
return mLostFocus;
}

public Intent getSendIntent() {
return sendIntent;
}
Expand Down
28 changes: 24 additions & 4 deletions src/org/kontalk/ui/ComposeMessageFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -2069,9 +2069,15 @@ public void onResume() {
return;
}

ComposeMessage activity = getParentActivity();
if (activity == null || !activity.hasLostFocus() || activity.hasWindowFocus()) {
onFocus();
}
}

public void onFocus() {
// resume content watcher
if (mListAdapter != null)
mListAdapter.setOnContentChangedListener(mContentChangedListener);
resumeContentListener();

// we are updating the status now
setActivityStatusUpdating();
Expand All @@ -2098,8 +2104,12 @@ public void onPause() {
super.onPause();

// pause content watcher
if (mListAdapter != null)
mListAdapter.setOnContentChangedListener(null);
pauseContentListener();

// notify parent of pausing
ComposeMessage parent = getParentActivity();
if (parent != null)
parent.fragmentLostFocus();

CharSequence text = mTextEntry.getText();
int len = text.length();
Expand Down Expand Up @@ -2188,6 +2198,16 @@ public void onDestroy() {
}
}

private void pauseContentListener() {
if (mListAdapter != null)
mListAdapter.setOnContentChangedListener(null);
}

private void resumeContentListener() {
if (mListAdapter != null)
mListAdapter.setOnContentChangedListener(mContentChangedListener);
}

public final boolean isFinishing() {
return (getActivity() == null || (getActivity() != null && getActivity()
.isFinishing())) || isRemoving();
Expand Down

0 comments on commit 75dd5dc

Please sign in to comment.