Remove unnecessary code

This commit is contained in:
Moez Bhatti
2015-09-18 13:47:59 -04:00
parent b008ea6b82
commit 047c753d63
8 changed files with 87 additions and 160 deletions
@@ -0,0 +1,30 @@
package com.moez.QKSMS.ui;
/**
* This interface is for fragments that must extend something other than a vanilla Fragment. It
* allows the fragment to get content animation callbacks without the developer having to
* rewrite the base class to extend BaseContentFragment.
*/
public interface ContentFragment {
/**
* Called when the content is being opened with an animation.
*/
void onContentOpening();
/**
* Called when the content has been opened, i.e. a opening animation has finished or it had
* been opened immediately.
*/
void onContentOpened();
/**
* Called when the content is being closed with an animation.
*/
void onContentClosing();
/**
* Called when the content has been closed, i.e. a closing animation has finished or it had
* been closed immediately.
*/
void onContentClosed();
}
@@ -6,10 +6,8 @@ import android.app.FragmentManager;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ComponentInfo; import android.content.pm.ComponentInfo;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.media.RingtoneManager; import android.media.RingtoneManager;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
@@ -24,6 +22,7 @@ import android.view.Menu;
import android.view.MenuInflater; import android.view.MenuInflater;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.widget.CheckBox;
import android.widget.ImageView; import android.widget.ImageView;
import com.google.android.mms.pdu_alt.PduHeaders; import com.google.android.mms.pdu_alt.PduHeaders;
import com.moez.QKSMS.R; import com.moez.QKSMS.R;
@@ -39,7 +38,6 @@ import com.moez.QKSMS.receiver.IconColorReceiver;
import com.moez.QKSMS.transaction.NotificationManager; import com.moez.QKSMS.transaction.NotificationManager;
import com.moez.QKSMS.transaction.SmsHelper; import com.moez.QKSMS.transaction.SmsHelper;
import com.moez.QKSMS.ui.base.QKActivity; import com.moez.QKSMS.ui.base.QKActivity;
import com.moez.QKSMS.ui.base.QKContentFragment;
import com.moez.QKSMS.ui.compose.ComposeFragment; import com.moez.QKSMS.ui.compose.ComposeFragment;
import com.moez.QKSMS.ui.conversationlist.ConversationListFragment; import com.moez.QKSMS.ui.conversationlist.ConversationListFragment;
import com.moez.QKSMS.ui.dialog.ConversationNotificationSettingsDialog; import com.moez.QKSMS.ui.dialog.ConversationNotificationSettingsDialog;
@@ -49,7 +47,6 @@ import com.moez.QKSMS.ui.dialog.mms.MMSSetupFragment;
import com.moez.QKSMS.ui.messagelist.MessageListFragment; import com.moez.QKSMS.ui.messagelist.MessageListFragment;
import com.moez.QKSMS.ui.search.SearchFragment; import com.moez.QKSMS.ui.search.SearchFragment;
import com.moez.QKSMS.ui.settings.SettingsFragment; import com.moez.QKSMS.ui.settings.SettingsFragment;
import com.moez.QKSMS.ui.view.QKCheckBox;
import com.moez.QKSMS.ui.view.slidingmenu.SlidingMenu; import com.moez.QKSMS.ui.view.slidingmenu.SlidingMenu;
import com.moez.QKSMS.ui.welcome.WelcomeActivity; import com.moez.QKSMS.ui.welcome.WelcomeActivity;
import com.nispok.snackbar.Snackbar; import com.nispok.snackbar.Snackbar;
@@ -90,7 +87,7 @@ public class MainActivity extends QKActivity implements SlidingMenu.OnOpenListen
private SlidingMenu mSlidingMenu; private SlidingMenu mSlidingMenu;
private ConversationListFragment mConversationList; private ConversationListFragment mConversationList;
private Fragment mContent; private ContentFragment mContent;
private long mWaitingForThreadId = -1; private long mWaitingForThreadId = -1;
private boolean mIsDestroyed = false; private boolean mIsDestroyed = false;
@@ -156,7 +153,7 @@ public class MainActivity extends QKActivity implements SlidingMenu.OnOpenListen
} }
getFragmentManager().beginTransaction() getFragmentManager().beginTransaction()
.replace(R.id.content_frame, mContent) .replace(R.id.content_frame, (Fragment) mContent)
.commit(); .commit();
} }
@@ -295,7 +292,7 @@ public class MainActivity extends QKActivity implements SlidingMenu.OnOpenListen
} }
public Fragment getContent() { public Fragment getContent() {
return mContent; return (Fragment) mContent;
} }
public long getThreadId() { public long getThreadId() {
@@ -406,7 +403,7 @@ public class MainActivity extends QKActivity implements SlidingMenu.OnOpenListen
super.onPause(); super.onPause();
sIsShowing = false; sIsShowing = false;
if (!mSlidingMenu.isMenuShowing()) { if (!mSlidingMenu.isMenuShowing()) {
QKContentFragment.notifyOnContentClosed(mContent); mContent.onContentClosed();
} }
} }
@@ -430,7 +427,7 @@ public class MainActivity extends QKActivity implements SlidingMenu.OnOpenListen
ThemeManager.loadThemeProperties(this); ThemeManager.loadThemeProperties(this);
if (!mSlidingMenu.isMenuShowing()) { if (!mSlidingMenu.isMenuShowing()) {
QKContentFragment.notifyOnContentOpened(mContent); mContent.onContentOpened();
} }
NotificationManager.initQuickCompose(this, false, false); NotificationManager.initQuickCompose(this, false, false);
@@ -530,7 +527,7 @@ public class MainActivity extends QKActivity implements SlidingMenu.OnOpenListen
outState.putLong(KEY_THREADID, sThreadId); outState.putLong(KEY_THREADID, sThreadId);
} }
public void switchContent(Fragment fragment, boolean animate) { public void switchContent(ContentFragment fragment, boolean animate) {
// Make sure that the activity isn't destroyed before making fragment transactions. // Make sure that the activity isn't destroyed before making fragment transactions.
if (fragment != null && !mIsDestroyed) { if (fragment != null && !mIsDestroyed) {
KeyboardUtils.hide(this); KeyboardUtils.hide(this);
@@ -542,7 +539,7 @@ public class MainActivity extends QKActivity implements SlidingMenu.OnOpenListen
if (fragment != m.findFragmentById(R.id.content_frame)) { if (fragment != m.findFragmentById(R.id.content_frame)) {
getFragmentManager() getFragmentManager()
.beginTransaction() .beginTransaction()
.replace(R.id.content_frame, fragment) .replace(R.id.content_frame, (Fragment) fragment)
.commitAllowingStateLoss(); .commitAllowingStateLoss();
} }
@@ -587,9 +584,8 @@ public class MainActivity extends QKActivity implements SlidingMenu.OnOpenListen
invalidateOptionsMenu(); invalidateOptionsMenu();
sIsContentHidden = true; sIsContentHidden = true;
// Notify the content that it is being closed, since the menu (i.e. conversation list) is // Notify the content that it is being closed, since the menu (i.e. conversation list) is being opened.
// being opened. if (mContent != null) mContent.onContentClosing();
QKContentFragment.notifyOnContentClosing(mContent);
// Hide the soft keyboard // Hide the soft keyboard
KeyboardUtils.hide(this, getCurrentFocus()); KeyboardUtils.hide(this, getCurrentFocus());
@@ -606,9 +602,8 @@ public class MainActivity extends QKActivity implements SlidingMenu.OnOpenListen
invalidateOptionsMenu(); invalidateOptionsMenu();
sIsContentHidden = false; sIsContentHidden = false;
// Notify the content that it is being opened, since the menu (i.e. conversation list) is // Notify the content that it is being opened, since the menu (i.e. conversation list) is being closed.
// being closed. if (mContent != null) mContent.onContentOpening();
QKContentFragment.notifyOnContentOpening(mContent);
// Hide the soft keyboard // Hide the soft keyboard
KeyboardUtils.hide(this, getCurrentFocus()); KeyboardUtils.hide(this, getCurrentFocus());
@@ -620,14 +615,14 @@ public class MainActivity extends QKActivity implements SlidingMenu.OnOpenListen
public void onOpened() { public void onOpened() {
// When the menu (i.e. the conversation list) has been opened, the content has been opened. // When the menu (i.e. the conversation list) has been opened, the content has been opened.
// So notify the content fragment. // So notify the content fragment.
QKContentFragment.notifyOnContentClosed(mContent); if (mContent != null) mContent.onContentClosed();
} }
@Override @Override
public void onClosed() { public void onClosed() {
// When the menu (i.e. the conversation list) has been closed, the content has been opened. // When the menu (i.e. the conversation list) has been closed, the content has been opened.
// So notify the content fragment. // So notify the content fragment.
QKContentFragment.notifyOnContentOpened(mContent); if (mContent != null) mContent.onContentOpened();
} }
/** /**
@@ -653,7 +648,7 @@ public class MainActivity extends QKActivity implements SlidingMenu.OnOpenListen
R.plurals.confirm_delete_conversation, cnt, cnt)); R.plurals.confirm_delete_conversation, cnt, cnt));
} }
final QKCheckBox checkbox = (QKCheckBox) contents.findViewById(R.id.delete_locked); final CheckBox checkbox = (CheckBox) contents.findViewById(R.id.delete_locked);
if (!hasLockedMessages) { if (!hasLockedMessages) {
checkbox.setVisibility(View.GONE); checkbox.setVisibility(View.GONE);
} else { } else {
@@ -1,10 +1,10 @@
package com.moez.QKSMS.ui.base; package com.moez.QKSMS.ui.base;
import android.app.Fragment;
import android.os.Bundle; import android.os.Bundle;
import android.view.View; import android.view.View;
import com.moez.QKSMS.common.LiveViewManager; import com.moez.QKSMS.common.LiveViewManager;
import com.moez.QKSMS.interfaces.LiveView; import com.moez.QKSMS.interfaces.LiveView;
import com.moez.QKSMS.ui.ContentFragment;
import com.moez.QKSMS.ui.ThemeManager; import com.moez.QKSMS.ui.ThemeManager;
import com.moez.QKSMS.ui.settings.SettingsFragment; import com.moez.QKSMS.ui.settings.SettingsFragment;
@@ -22,19 +22,7 @@ import com.moez.QKSMS.ui.settings.SettingsFragment;
* - Manages the current state of the fragment in terms of the animation, i.e. opening, fully * - Manages the current state of the fragment in terms of the animation, i.e. opening, fully
* opened, etc. * opened, etc.
*/ */
public class QKContentFragment extends QKFragment implements LiveView { public class QKContentFragment extends QKFragment implements LiveView, ContentFragment {
private static final boolean LOCAL_LOGV = false;
/**
* Holds the state of the content in the menu.
*/
private int mContentAnimationState = STATE_OPENED;
public static final int STATE_OPENING = 0;
public static final int STATE_OPENED = 1;
public static final int STATE_CLOSING = 2;
public static final int STATE_CLOSED = 3;
/** /**
* It's not strictly necessary, but subclasses should call through to super() in their * It's not strictly necessary, but subclasses should call through to super() in their
@@ -84,71 +72,30 @@ public class QKContentFragment extends QKFragment implements LiveView {
refresh(); refresh();
} }
/**
* @return The current state of the animation of the content.
*/
public int getContentAnimationState() {
return mContentAnimationState;
}
/**
* Call on a BaseContentFragment to notify it that it is opening.
*/
public final void performOnContentOpening() {
mContentAnimationState = STATE_OPENING;
onContentOpening();
}
/**
* Call on a BaseContentFragment to notify it that it has been opened fully, i.e. an opening
* animation has finished or the Fragment has been opened immediately.
*/
public final void performOnContentOpened() {
mContentAnimationState = STATE_OPENED;
onContentOpened();
}
/**
* Call on a BaseContentFragment to notify it that it is closing.
*/
public final void performOnContentClosing() {
mContentAnimationState = STATE_CLOSING;
onContentClosing();
}
/**
* Call on a BaseContentFragment to notify it that it has been closed fully, i.e. a closing
* animation has finished or the Fragment has been closed immediately.
*/
public final void performOnContentClosed() {
mContentAnimationState = STATE_CLOSED;
onContentClosed();
}
/** /**
* Called when the content is being opened with an animation. * Called when the content is being opened with an animation.
*/ */
protected void onContentOpening() { public void onContentOpening() {
} }
/** /**
* Called when the content has been opened, i.e. a opening animation has finished or it had * Called when the content has been opened, i.e. a opening animation has finished or it had
* been opened immediately. * been opened immediately.
*/ */
protected void onContentOpened() { public void onContentOpened() {
} }
/** /**
* Called when the content is being closed with an animation. * Called when the content is being closed with an animation.
*/ */
protected void onContentClosing() { public void onContentClosing() {
} }
/** /**
* Called when the content has been closed, i.e. a closing animation has finished or it had * Called when the content has been closed, i.e. a closing animation has finished or it had
* been closed immediately. * been closed immediately.
*/ */
protected void onContentClosed() { public void onContentClosed() {
} }
@Override @Override
@@ -158,67 +105,4 @@ public class QKContentFragment extends QKFragment implements LiveView {
view.setBackgroundColor(ThemeManager.getBackgroundColor()); view.setBackgroundColor(ThemeManager.getBackgroundColor());
} }
} }
/**
* This interface is for fragments that must extend something other than a vanilla Fragment. It
* allows the fragment to get content animation callbacks without the developer having to
* rewrite the base class to extend BaseContentFragment.
*/
public interface ContentFragment {
/**
* Called when the content is being opened with an animation.
*/
void onContentOpening();
/**
* Called when the content has been opened, i.e. a opening animation has finished or it had
* been opened immediately.
*/
void onContentOpened();
/**
* Called when the content is being closed with an animation.
*/
void onContentClosing();
/**
* Called when the content has been closed, i.e. a closing animation has finished or it had
* been closed immediately.
*/
void onContentClosed();
}
// The following static methods will notify a Fragment about their content animations if
// appropriate, or do nothing otherwise.
public static void notifyOnContentOpening(Fragment fragment) {
if (fragment instanceof QKContentFragment) {
((QKContentFragment) fragment).performOnContentOpening();
} else if (fragment instanceof ContentFragment) {
((ContentFragment) fragment).onContentOpening();
}
}
public static void notifyOnContentOpened(Fragment fragment) {
if (fragment instanceof QKContentFragment) {
((QKContentFragment) fragment).performOnContentOpened();
} else if (fragment instanceof ContentFragment) {
((ContentFragment) fragment).onContentOpened();
}
}
public static void notifyOnContentClosing(Fragment fragment) {
if (fragment instanceof QKContentFragment) {
((QKContentFragment) fragment).performOnContentClosing();
} else if (fragment instanceof ContentFragment) {
((ContentFragment) fragment).onContentClosing();
}
}
public static void notifyOnContentClosed(Fragment fragment) {
if (fragment instanceof QKContentFragment) {
((QKContentFragment) fragment).performOnContentClosed();
} else if (fragment instanceof ContentFragment) {
((ContentFragment) fragment).onContentClosed();
}
}
} }
@@ -142,7 +142,7 @@ public class ComposeFragment extends QKContentFragment implements ActivityLaunch
} }
@Override @Override
protected void onContentOpened() { public void onContentOpened() {
setupInput(); setupInput();
} }
@@ -167,7 +167,7 @@ public class ComposeFragment extends QKContentFragment implements ActivityLaunch
} }
@Override @Override
protected void onContentClosing() { public void onContentClosing() {
// Clear the focus from this fragment. // Clear the focus from this fragment.
if (getActivity() != null && getActivity().getCurrentFocus() != null) { if (getActivity() != null && getActivity().getCurrentFocus() != null) {
getActivity().getCurrentFocus().clearFocus(); getActivity().getCurrentFocus().clearFocus();
@@ -29,6 +29,7 @@ import com.moez.QKSMS.data.Conversation;
import com.moez.QKSMS.data.ConversationLegacy; import com.moez.QKSMS.data.ConversationLegacy;
import com.moez.QKSMS.interfaces.LiveView; import com.moez.QKSMS.interfaces.LiveView;
import com.moez.QKSMS.transaction.SmsHelper; import com.moez.QKSMS.transaction.SmsHelper;
import com.moez.QKSMS.ui.ContentFragment;
import com.moez.QKSMS.ui.MainActivity; import com.moez.QKSMS.ui.MainActivity;
import com.moez.QKSMS.ui.ThemeManager; import com.moez.QKSMS.ui.ThemeManager;
import com.moez.QKSMS.ui.base.QKFragment; import com.moez.QKSMS.ui.base.QKFragment;
@@ -262,11 +263,7 @@ public class ConversationListFragment extends QKFragment implements LoaderManage
getLoaderManager().initLoader(0, null, this); getLoaderManager().initLoader(0, null, this);
} }
private void switchFragment(Fragment fragment) { private void switchFragment(ContentFragment fragment) {
if (getActivity() == null) {
return;
}
// TODO
((MainActivity) getActivity()).switchContent(fragment, true); ((MainActivity) getActivity()).switchContent(fragment, true);
} }
@@ -724,13 +724,13 @@ public class MessageListFragment extends QKContentFragment implements ActivityLa
} }
@Override @Override
protected void onContentOpening() { public void onContentOpening() {
super.onContentOpening(); super.onContentOpening();
mOpened = false; // We're animating the fragment in, this flag warns us not to do anything heavy mOpened = false; // We're animating the fragment in, this flag warns us not to do anything heavy
} }
@Override @Override
protected void onContentOpened() { public void onContentOpened() {
super.onContentOpened(); super.onContentOpened();
mOpened = true; // The fragment has finished animating in mOpened = true; // The fragment has finished animating in
@@ -740,11 +740,11 @@ public class MessageListFragment extends QKContentFragment implements ActivityLa
} }
@Override @Override
protected void onContentClosing() { public void onContentClosing() {
} }
@Override @Override
protected void onContentClosed() { public void onContentClosed() {
if (mSensorManager != null) { if (mSensorManager != null) {
mSensorManager.unregisterListener(this); mSensorManager.unregisterListener(this);
} }
@@ -126,7 +126,7 @@ public class SearchFragment extends QKContentFragment implements RecyclerCursorA
} }
@Override @Override
protected void onContentOpened() { public void onContentOpened() {
// Show the keyboard and focus on the query text when the fragment is opened. // Show the keyboard and focus on the query text when the fragment is opened.
KeyboardUtils.showAndFocus(mContext, mQuery); KeyboardUtils.showAndFocus(mContext, mQuery);
} }
@@ -31,24 +31,25 @@ import android.widget.Toast;
import com.mariussoft.endlessjabber.sdk.EndlessJabberInterface; import com.mariussoft.endlessjabber.sdk.EndlessJabberInterface;
import com.moez.QKSMS.R; import com.moez.QKSMS.R;
import com.moez.QKSMS.common.AnalyticsManager; import com.moez.QKSMS.common.AnalyticsManager;
import com.moez.QKSMS.ui.dialog.BubblePreferenceDialog;
import com.moez.QKSMS.interfaces.LiveView;
import com.moez.QKSMS.receiver.NightModeAutoReceiver;
import com.moez.QKSMS.common.DonationManager; import com.moez.QKSMS.common.DonationManager;
import com.moez.QKSMS.common.ListviewHelper; import com.moez.QKSMS.common.ListviewHelper;
import com.moez.QKSMS.common.LiveViewManager; import com.moez.QKSMS.common.LiveViewManager;
import com.moez.QKSMS.common.utils.DateFormatter; import com.moez.QKSMS.common.utils.DateFormatter;
import com.moez.QKSMS.common.utils.KeyboardUtils; import com.moez.QKSMS.common.utils.KeyboardUtils;
import com.moez.QKSMS.interfaces.LiveView;
import com.moez.QKSMS.receiver.NightModeAutoReceiver;
import com.moez.QKSMS.transaction.EndlessJabber; import com.moez.QKSMS.transaction.EndlessJabber;
import com.moez.QKSMS.transaction.NotificationManager; import com.moez.QKSMS.transaction.NotificationManager;
import com.moez.QKSMS.transaction.SmsHelper; import com.moez.QKSMS.transaction.SmsHelper;
import com.moez.QKSMS.ui.ContentFragment;
import com.moez.QKSMS.ui.MainActivity; import com.moez.QKSMS.ui.MainActivity;
import com.moez.QKSMS.ui.ThemeManager; import com.moez.QKSMS.ui.ThemeManager;
import com.moez.QKSMS.ui.dialog.BubblePreferenceDialog;
import com.moez.QKSMS.ui.dialog.QKDialog; import com.moez.QKSMS.ui.dialog.QKDialog;
import com.moez.QKSMS.ui.dialog.mms.MMSSetupFragment; import com.moez.QKSMS.ui.dialog.mms.MMSSetupFragment;
import com.moez.QKSMS.ui.view.QKTextView;
import com.moez.QKSMS.ui.view.colorpicker.ColorPickerDialog; import com.moez.QKSMS.ui.view.colorpicker.ColorPickerDialog;
import com.moez.QKSMS.ui.view.colorpicker.ColorPickerSwatch; import com.moez.QKSMS.ui.view.colorpicker.ColorPickerSwatch;
import com.moez.QKSMS.ui.view.QKTextView;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
@@ -60,8 +61,8 @@ import java.util.HashSet;
import java.util.Set; import java.util.Set;
import java.util.Stack; import java.util.Stack;
public class SettingsFragment extends PreferenceFragment implements public class SettingsFragment extends PreferenceFragment implements Preference.OnPreferenceChangeListener,
Preference.OnPreferenceChangeListener, Preference.OnPreferenceClickListener, LiveView { Preference.OnPreferenceClickListener, LiveView, ContentFragment {
private final String TAG = "PreferenceFragment"; private final String TAG = "PreferenceFragment";
public static final String CATEGORY_APPEARANCE = "pref_key_category_appearance"; public static final String CATEGORY_APPEARANCE = "pref_key_category_appearance";
@@ -159,6 +160,7 @@ public class SettingsFragment extends PreferenceFragment implements
public static final String CATEGORY_TAG = "settings_category_fragment_tag"; public static final String CATEGORY_TAG = "settings_category_fragment_tag";
private MainActivity mContext; private MainActivity mContext;
private PreferenceManager mPreferenceManager;
private SharedPreferences mPrefs; private SharedPreferences mPrefs;
private Resources mRes; private Resources mRes;
private ListView mListView; private ListView mListView;
@@ -707,4 +709,23 @@ public class SettingsFragment extends PreferenceFragment implements
} }
} }
@Override
public void onContentOpening() {
}
@Override
public void onContentOpened() {
}
@Override
public void onContentClosing() {
}
@Override
public void onContentClosed() {
}
} }