forked from upstream-mirrors/quik
Cut down on static variable usage
This commit is contained in:
@@ -7,7 +7,6 @@ import android.graphics.Bitmap;
|
|||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import com.moez.QKSMS.R;
|
import com.moez.QKSMS.R;
|
||||||
import com.moez.QKSMS.transaction.SmsHelper;
|
import com.moez.QKSMS.transaction.SmsHelper;
|
||||||
import com.moez.QKSMS.ui.MainActivity;
|
|
||||||
import com.moez.QKSMS.ui.dialog.DefaultSmsHelper;
|
import com.moez.QKSMS.ui.dialog.DefaultSmsHelper;
|
||||||
|
|
||||||
public class Message {
|
public class Message {
|
||||||
@@ -151,12 +150,6 @@ public class Message {
|
|||||||
return photoBitmap;
|
return photoBitmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isVisible() {
|
|
||||||
return getThreadId() == MainActivity.sThreadId &&
|
|
||||||
MainActivity.sIsShowing &&
|
|
||||||
!MainActivity.sIsContentHidden;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void markSeen() {
|
public void markSeen() {
|
||||||
ContentValues cv = new ContentValues();
|
ContentValues cv = new ContentValues();
|
||||||
cv.put("seen", true);
|
cv.put("seen", true);
|
||||||
|
|||||||
@@ -52,10 +52,9 @@ public class NotificationService extends Service {
|
|||||||
conversationPrefs = new ConversationPrefsHelper(context, message.getThreadId());
|
conversationPrefs = new ConversationPrefsHelper(context, message.getThreadId());
|
||||||
|
|
||||||
if (conversationPrefs.getNotificationsEnabled()) {
|
if (conversationPrefs.getNotificationsEnabled()) {
|
||||||
// Only show QuickReply if we're outside of the app, and they have popups and
|
// Only show QuickReply if we're outside of the app, and they have popups and QuickReply enabled.
|
||||||
// QuickReply enabled.
|
if (!QKReplyActivity.sIsShowing && message.getThreadId() != MainActivity.sThreadShowing &&
|
||||||
if (!QKReplyActivity.sIsShowing && !MainActivity.sIsShowing && intent.getBooleanExtra(EXTRA_POPUP, false) &&
|
intent.getBooleanExtra(EXTRA_POPUP, false) && prefs.getBoolean(SettingsFragment.QUICKREPLY, true)) {
|
||||||
prefs.getBoolean(SettingsFragment.QUICKREPLY, true) && !MainActivity.sIsShowing) {
|
|
||||||
|
|
||||||
popupIntent = new Intent(context, QKReplyActivity.class);
|
popupIntent = new Intent(context, QKReplyActivity.class);
|
||||||
popupIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
popupIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
@@ -66,8 +65,7 @@ public class NotificationService extends Service {
|
|||||||
// Get the photo for the PushBullet notification.
|
// Get the photo for the PushBullet notification.
|
||||||
Bitmap photoBitmap = message.getPhotoBitmap();
|
Bitmap photoBitmap = message.getPhotoBitmap();
|
||||||
if (photoBitmap == null) {
|
if (photoBitmap == null) {
|
||||||
ContactHelper helper = new ContactHelper();
|
photoBitmap = ContactHelper.blankContact(context, message.getName());
|
||||||
photoBitmap = helper.blankContact(context, message.getName());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PushbulletService.mirrorMessage(context, "" + message.getThreadId(),
|
PushbulletService.mirrorMessage(context, "" + message.getThreadId(),
|
||||||
|
|||||||
@@ -156,7 +156,7 @@ public class NotificationManager {
|
|||||||
|
|
||||||
// If this message is in the foreground, mark it as read
|
// If this message is in the foreground, mark it as read
|
||||||
Message message = new Message(context, lastMessage.mMsgId);
|
Message message = new Message(context, lastMessage.mMsgId);
|
||||||
if (message.isVisible()) {
|
if (message.getThreadId() ==MainActivity.sThreadShowing) {
|
||||||
message.markRead();
|
message.markRead();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -243,7 +243,7 @@ public class NotificationManager {
|
|||||||
// If the message is visible (i.e. it is currently showing in the Main Activity),
|
// If the message is visible (i.e. it is currently showing in the Main Activity),
|
||||||
// don't show a notification; just mark it as read and return.
|
// don't show a notification; just mark it as read and return.
|
||||||
Message message = new Message(context, lastMessage.mMsgId);
|
Message message = new Message(context, lastMessage.mMsgId);
|
||||||
if (message.isVisible()) {
|
if (message.getThreadId() == MainActivity.sThreadShowing) {
|
||||||
message.markRead();
|
message.markRead();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,6 +63,8 @@ public class MainActivity extends QKActivity implements SlidingMenu.OnOpenListen
|
|||||||
|
|
||||||
public final static String EXTRA_THREAD_ID = "thread_id";
|
public final static String EXTRA_THREAD_ID = "thread_id";
|
||||||
|
|
||||||
|
public static long sThreadShowing;
|
||||||
|
|
||||||
private final String KEY_TYPE = "type";
|
private final String KEY_TYPE = "type";
|
||||||
private final String KEY_POSITION = "position";
|
private final String KEY_POSITION = "position";
|
||||||
private final String KEY_THREADID = "thread_id";
|
private final String KEY_THREADID = "thread_id";
|
||||||
@@ -81,10 +83,7 @@ public class MainActivity extends QKActivity implements SlidingMenu.OnOpenListen
|
|||||||
public static final String MMS_SETUP_DONT_ASK_AGAIN = "mmsSetupDontAskAgain";
|
public static final String MMS_SETUP_DONT_ASK_AGAIN = "mmsSetupDontAskAgain";
|
||||||
|
|
||||||
// thread IDs are always nonnegative
|
// thread IDs are always nonnegative
|
||||||
public static long sThreadId = 0;
|
private long mThreadId = 0;
|
||||||
|
|
||||||
public static boolean sIsShowing = false;
|
|
||||||
public static boolean sIsContentHidden = true;
|
|
||||||
|
|
||||||
private SlidingMenu mSlidingMenu;
|
private SlidingMenu mSlidingMenu;
|
||||||
private ConversationListFragment mConversationList;
|
private ConversationListFragment mConversationList;
|
||||||
@@ -126,12 +125,12 @@ public class MainActivity extends QKActivity implements SlidingMenu.OnOpenListen
|
|||||||
private void setupFragments(Bundle savedInstanceState) {
|
private void setupFragments(Bundle savedInstanceState) {
|
||||||
int type = 0;
|
int type = 0;
|
||||||
int position = 0;
|
int position = 0;
|
||||||
sThreadId = 0;
|
mThreadId = 0;
|
||||||
|
|
||||||
if (savedInstanceState != null) {
|
if (savedInstanceState != null) {
|
||||||
type = savedInstanceState.getInt(KEY_TYPE, 0);
|
type = savedInstanceState.getInt(KEY_TYPE, 0);
|
||||||
position = savedInstanceState.getInt(KEY_POSITION, 0);
|
position = savedInstanceState.getInt(KEY_POSITION, 0);
|
||||||
sThreadId = savedInstanceState.getLong(KEY_THREADID, 0);
|
mThreadId = savedInstanceState.getLong(KEY_THREADID, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
mConversationList = new ConversationListFragment();
|
mConversationList = new ConversationListFragment();
|
||||||
@@ -146,7 +145,7 @@ public class MainActivity extends QKActivity implements SlidingMenu.OnOpenListen
|
|||||||
break;
|
break;
|
||||||
case TYPE_CONVERSATION:
|
case TYPE_CONVERSATION:
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
args.putLong(MessageListFragment.ARG_THREAD_ID, sThreadId);
|
args.putLong(MessageListFragment.ARG_THREAD_ID, mThreadId);
|
||||||
mContent = MessageListFragment.getInstance(args);
|
mContent = MessageListFragment.getInstance(args);
|
||||||
break;
|
break;
|
||||||
case TYPE_SETTINGS:
|
case TYPE_SETTINGS:
|
||||||
@@ -278,7 +277,7 @@ public class MainActivity extends QKActivity implements SlidingMenu.OnOpenListen
|
|||||||
}
|
}
|
||||||
|
|
||||||
public long getThreadId() {
|
public long getThreadId() {
|
||||||
return sThreadId;
|
return mThreadId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -383,7 +382,7 @@ public class MainActivity extends QKActivity implements SlidingMenu.OnOpenListen
|
|||||||
@Override
|
@Override
|
||||||
protected void onPause() {
|
protected void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
sIsShowing = false;
|
sThreadShowing = 0;
|
||||||
if (!mSlidingMenu.isMenuShowing()) {
|
if (!mSlidingMenu.isMenuShowing()) {
|
||||||
mContent.onContentClosed();
|
mContent.onContentClosed();
|
||||||
}
|
}
|
||||||
@@ -405,13 +404,18 @@ public class MainActivity extends QKActivity implements SlidingMenu.OnOpenListen
|
|||||||
@Override
|
@Override
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
sIsShowing = true;
|
|
||||||
ThemeManager.loadThemeProperties(this);
|
ThemeManager.loadThemeProperties(this);
|
||||||
|
|
||||||
if (!mSlidingMenu.isMenuShowing()) {
|
if (!mSlidingMenu.isMenuShowing()) {
|
||||||
mContent.onContentOpened();
|
mContent.onContentOpened();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mContent != null && mContent instanceof MessageListFragment) {
|
||||||
|
sThreadShowing = ((MessageListFragment) mContent).getThreadId();
|
||||||
|
} else {
|
||||||
|
sThreadShowing = 0;
|
||||||
|
}
|
||||||
|
|
||||||
NotificationManager.initQuickCompose(this, false, false);
|
NotificationManager.initQuickCompose(this, false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -506,7 +510,7 @@ public class MainActivity extends QKActivity implements SlidingMenu.OnOpenListen
|
|||||||
mContent instanceof SettingsFragment ? TYPE_SETTINGS :
|
mContent instanceof SettingsFragment ? TYPE_SETTINGS :
|
||||||
mContent instanceof SearchFragment ? TYPE_SEARCH : TYPE_COMPOSE);
|
mContent instanceof SearchFragment ? TYPE_SEARCH : TYPE_COMPOSE);
|
||||||
outState.putInt(KEY_POSITION, mConversationList.getPosition());
|
outState.putInt(KEY_POSITION, mConversationList.getPosition());
|
||||||
outState.putLong(KEY_THREADID, sThreadId);
|
outState.putLong(KEY_THREADID, mThreadId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void switchContent(ContentFragment fragment, boolean animate) {
|
public void switchContent(ContentFragment fragment, boolean animate) {
|
||||||
@@ -557,14 +561,15 @@ public class MainActivity extends QKActivity implements SlidingMenu.OnOpenListen
|
|||||||
MessageListFragment fragment = MessageListFragment.getInstance(args);
|
MessageListFragment fragment = MessageListFragment.getInstance(args);
|
||||||
|
|
||||||
// Save the thread ID here and switch the content
|
// Save the thread ID here and switch the content
|
||||||
MainActivity.sThreadId = threadId;
|
mThreadId = threadId;
|
||||||
|
sThreadShowing = threadId;
|
||||||
switchContent(fragment, animate);
|
switchContent(fragment, animate);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onOpen() {
|
public void onOpen() {
|
||||||
invalidateOptionsMenu();
|
invalidateOptionsMenu();
|
||||||
sIsContentHidden = true;
|
sThreadShowing = 0;
|
||||||
|
|
||||||
// Notify the content that it is being closed, since the menu (i.e. conversation list) is being opened.
|
// Notify the content that it is being closed, since the menu (i.e. conversation list) is being opened.
|
||||||
if (mContent != null) mContent.onContentClosing();
|
if (mContent != null) mContent.onContentClosing();
|
||||||
@@ -578,10 +583,17 @@ public class MainActivity extends QKActivity implements SlidingMenu.OnOpenListen
|
|||||||
@Override
|
@Override
|
||||||
public void onClose() {
|
public void onClose() {
|
||||||
invalidateOptionsMenu();
|
invalidateOptionsMenu();
|
||||||
sIsContentHidden = false;
|
|
||||||
|
|
||||||
// Notify the content that it is being opened, since the menu (i.e. conversation list) is being closed.
|
// Notify the content that it is being opened, since the menu (i.e. conversation list) is being closed.
|
||||||
if (mContent != null) mContent.onContentOpening();
|
if (mContent != null) {
|
||||||
|
mContent.onContentOpening();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mContent != null && mContent instanceof MessageListFragment) {
|
||||||
|
sThreadShowing = ((MessageListFragment) mContent).getThreadId();
|
||||||
|
} else {
|
||||||
|
sThreadShowing = 0;
|
||||||
|
}
|
||||||
|
|
||||||
// Hide the soft keyboard
|
// Hide the soft keyboard
|
||||||
KeyboardUtils.hide(this, getCurrentFocus());
|
KeyboardUtils.hide(this, getCurrentFocus());
|
||||||
|
|||||||
Reference in New Issue
Block a user