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