Skip to content

Commit

Permalink
removed unused code
Browse files Browse the repository at this point in the history
fallback to basic image viewer when gif library failed to load
improved keyboard shortcut in accounts dashboard
  • Loading branch information
mariotaku committed Apr 21, 2015
1 parent 5d7765b commit 68ba8d4
Show file tree
Hide file tree
Showing 22 changed files with 390 additions and 350 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

public class NetworkStateUtil {

public static final int TYPE_NO_NETWORK = -1;

private static int getConnectedTypeValue(Context context) {
if (context != null) {
ConnectivityManager mConnectivityManager = (ConnectivityManager) context
Expand All @@ -41,33 +43,22 @@ private static int getConnectedTypeValue(Context context) {
return -1;
}

public static String getConnectedType (Context context) {
int type = -1;
type = getConnectedTypeValue(context);
String network = "unknown";
switch (type) {
case 0:
network = "cellular";
break;
case 1:
network = "wifi";
break;
case 2:
network = "wimax";
break;
case 3:
network = "ethernet";
break;
case 4:
network = "bluetooth";
break;
case -1:
network = "ERROR";
break;
public static String getConnectedType(Context context) {
switch (getConnectedTypeValue(context)) {
case ConnectivityManager.TYPE_MOBILE:
return "cellular";
case ConnectivityManager.TYPE_WIFI:
return "wifi";
case ConnectivityManager.TYPE_WIMAX:
return "wimax";
case ConnectivityManager.TYPE_ETHERNET:
return "ethernet";
case ConnectivityManager.TYPE_BLUETOOTH:
return "bluetooth";
case TYPE_NO_NETWORK:
return "ERROR";
default:
network = "unknown";
break;
return "unknown";
}
return network;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.support.v7.widget.Toolbar;
import android.util.SparseArray;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.MenuItem;
Expand Down Expand Up @@ -74,7 +73,6 @@
import org.mariotaku.twidere.adapter.support.SupportTabsAdapter;
import org.mariotaku.twidere.app.TwidereApplication;
import org.mariotaku.twidere.fragment.CustomTabsFragment;
import org.mariotaku.twidere.fragment.iface.IBaseFragment;
import org.mariotaku.twidere.fragment.iface.RefreshScrollTopInterface;
import org.mariotaku.twidere.fragment.iface.SupportFragmentCallback;
import org.mariotaku.twidere.fragment.support.AccountsDashboardFragment;
Expand Down Expand Up @@ -138,7 +136,6 @@ public class HomeActivity extends BaseActionBarActivity implements OnClickListen

private final ContentObserver mAccountChangeObserver = new AccountChangeObserver(this, mHandler);

private final SparseArray<Fragment> mAttachedFragments = new SparseArray<>();
private ParcelableAccount mSelectedAccountToSearch;

private SharedPreferences mPreferences;
Expand All @@ -164,7 +161,6 @@ public class HomeActivity extends BaseActionBarActivity implements OnClickListen
private RightDrawerFrameLayout mRightDrawerContainer;
private TintedStatusFrameLayout mColorStatusFrameLayout;

private Fragment mCurrentVisibleFragment;
private UpdateUnreadCountTask mUpdateUnreadCountTask;

private int mTabDisplayOption;
Expand All @@ -184,35 +180,31 @@ public void closeAccountsDrawer() {
mSlidingMenu.showContent();
}

@Override
public Fragment getCurrentVisibleFragment() {
return mCurrentVisibleFragment;
}

@Override
public void onDetachFragment(final Fragment fragment) {
if (fragment instanceof IBaseFragment && ((IBaseFragment) fragment).getTabPosition() != -1) {
mAttachedFragments.remove(((IBaseFragment) fragment).getTabPosition());
public long[] getActivatedAccountIds() {
final Fragment fragment = getLeftDrawerFragment();
if (fragment instanceof AccountsDashboardFragment) {
return ((AccountsDashboardFragment) fragment).getActivatedAccountIds();
}
return Utils.getActivatedAccountIds(this);
}

@Override
public void onSetUserVisibleHint(final Fragment fragment, final boolean isVisibleToUser) {
if (isVisibleToUser) {
mCurrentVisibleFragment = fragment;
}
public Fragment getCurrentVisibleFragment() {
final int currentItem = mViewPager.getCurrentItem();
if (currentItem < 0 || currentItem >= mPagerAdapter.getCount()) return null;
return (Fragment) mPagerAdapter.instantiateItem(mViewPager, currentItem);
}

@Override
public boolean triggerRefresh(final int position) {
final Fragment f = mAttachedFragments.get(position);
return f instanceof RefreshScrollTopInterface && !f.isDetached()
&& ((RefreshScrollTopInterface) f).triggerRefresh();
final Fragment f = (Fragment) mPagerAdapter.instantiateItem(mViewPager, position);
if (!(f instanceof RefreshScrollTopInterface)) return false;
if (f.getActivity() == null || f.isDetached()) return false;
return ((RefreshScrollTopInterface) f).triggerRefresh();
}

@Override
public void setControlBarVisibleAnimate(boolean visible) {
mControlBarShowHideHelper.setControlBarVisibleAnimate(visible);
public Fragment getLeftDrawerFragment() {
return getSupportFragmentManager().findFragmentById(R.id.left_drawer);
}

@Override
Expand All @@ -223,15 +215,8 @@ public boolean getSystemWindowsInsets(Rect insets) {
}

@Override
public void setControlBarOffset(float offset) {
mTabsContainer.setTranslationY(mTabColumns > 1 ? 0 : getControlBarHeight() * (offset - 1));
final ViewGroup.LayoutParams lp = mActionsButton.getLayoutParams();
if (lp instanceof MarginLayoutParams) {
mActionsButton.setTranslationY((((MarginLayoutParams) lp).bottomMargin + mActionsButton.getHeight()) * (1 - offset));
} else {
mActionsButton.setTranslationY(mActionsButton.getHeight() * (1 - offset));
}
notifyControlBarOffsetChanged();
public void setControlBarVisibleAnimate(boolean visible) {
mControlBarShowHideHelper.setControlBarVisibleAnimate(visible);
}

@Override
Expand Down Expand Up @@ -298,15 +283,29 @@ public boolean handleKeyboardShortcutSingle(int keyCode, @NonNull KeyEvent event
switch (action) {
case "navigation.previous_tab": {
final int previous = mViewPager.getCurrentItem() - 1;
if (previous >= 0 && previous < mPagerAdapter.getCount()) {
mViewPager.setCurrentItem(previous, true);
if (previous < 0) {
mSlidingMenu.showMenu(true);
setControlBarVisibleAnimate(true);
} else if (previous < mPagerAdapter.getCount()) {
if (mSlidingMenu.isSecondaryMenuShowing()) {
mSlidingMenu.showContent(true);
} else {
mViewPager.setCurrentItem(previous, true);
}
}
return true;
}
case "navigation.next_tab": {
final int next = mViewPager.getCurrentItem() + 1;
if (next >= 0 && next < mPagerAdapter.getCount()) {
mViewPager.setCurrentItem(next, true);
if (next >= mPagerAdapter.getCount()) {
mSlidingMenu.showSecondaryMenu(true);
setControlBarVisibleAnimate(true);
} else if (next >= 0) {
if (mSlidingMenu.isMenuShowing()) {
mSlidingMenu.showContent(true);
} else {
mViewPager.setCurrentItem(next, true);
}
}
return true;
}
Expand All @@ -315,6 +314,18 @@ public boolean handleKeyboardShortcutSingle(int keyCode, @NonNull KeyEvent event
return mKeyboardShortcutsHandler.handleKey(this, null, keyCode, event);
}

@Override
public void setControlBarOffset(float offset) {
mTabsContainer.setTranslationY(mTabColumns > 1 ? 0 : getControlBarHeight() * (offset - 1));
final ViewGroup.LayoutParams lp = mActionsButton.getLayoutParams();
if (lp instanceof MarginLayoutParams) {
mActionsButton.setTranslationY((((MarginLayoutParams) lp).bottomMargin + mActionsButton.getHeight()) * (1 - offset));
} else {
mActionsButton.setTranslationY(mActionsButton.getHeight() * (1 - offset));
}
notifyControlBarOffsetChanged();
}

@Override
public boolean handleKeyboardShortcutRepeat(int keyCode, int repeatCount, @NonNull KeyEvent event) {
if (handleFragmentKeyboardShortcutRepeat(keyCode, repeatCount, event)) return true;
Expand Down Expand Up @@ -569,29 +580,13 @@ public void openSearchView(final ParcelableAccount account) {
}

public void setSystemWindowInsets(Rect insets) {
final Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.left_drawer);
final Fragment fragment = getLeftDrawerFragment();
if (fragment instanceof AccountsDashboardFragment) {
((AccountsDashboardFragment) fragment).setStatusBarHeight(insets.top);
}
mColorStatusFrameLayout.setStatusBarHeight(insets.top);
}

@Override
public float getControlBarOffset() {
if (mTabColumns > 1) {
final ViewGroup.LayoutParams lp = mActionsButton.getLayoutParams();
float total;
if (lp instanceof MarginLayoutParams) {
total = ((MarginLayoutParams) lp).bottomMargin + mActionsButton.getHeight();
} else {
total = mActionsButton.getHeight();
}
return 1 - mActionsButton.getTranslationY() / total;
}
final float totalHeight = getControlBarHeight();
return 1 + mTabsContainer.getTranslationY() / totalHeight;
}

public void updateUnreadCount() {
if (mTabIndicator == null || mUpdateUnreadCountTask != null
&& mUpdateUnreadCountTask.getStatus() == AsyncTask.Status.RUNNING) return;
Expand All @@ -612,11 +607,6 @@ protected void onActivityResult(final int requestCode, final int resultCode, fin
super.onActivityResult(requestCode, resultCode, data);
}

@Override
public int getControlBarHeight() {
return mTabIndicator.getHeight() - mTabIndicator.getStripHeight();
}

@Override
protected void onNewIntent(final Intent intent) {
final int tabPosition = handleIntent(intent, false);
Expand All @@ -625,13 +615,6 @@ protected void onNewIntent(final Intent intent) {
}
}

@Override
public void onAttachFragment(final Fragment fragment) {
if (fragment instanceof IBaseFragment && ((IBaseFragment) fragment).getTabPosition() != -1) {
mAttachedFragments.put(((IBaseFragment) fragment).getTabPosition(), fragment);
}
}

@Override
protected void onDestroy() {
// Delete unused items in databases.
Expand All @@ -649,6 +632,22 @@ public void onBackPressed() {
super.onBackPressed();
}

@Override
public float getControlBarOffset() {
if (mTabColumns > 1) {
final ViewGroup.LayoutParams lp = mActionsButton.getLayoutParams();
float total;
if (lp instanceof MarginLayoutParams) {
total = ((MarginLayoutParams) lp).bottomMargin + mActionsButton.getHeight();
} else {
total = mActionsButton.getHeight();
}
return 1 - mActionsButton.getTranslationY() / total;
}
final float totalHeight = getControlBarHeight();
return 1 + mTabsContainer.getTranslationY() / totalHeight;
}

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
if (event.getKeyCode() == KeyEvent.KEYCODE_MENU && event.getAction() == KeyEvent.ACTION_UP) {
Expand All @@ -675,26 +674,33 @@ public void onSupportContentChanged() {
mColorStatusFrameLayout = (TintedStatusFrameLayout) findViewById(R.id.home_content);
}

public long[] getActivatedAccountIds() {
final Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.left_drawer);
if (fragment instanceof AccountsDashboardFragment) {
return ((AccountsDashboardFragment) fragment).getActivatedAccountIds();
private Fragment getKeyboardShortcutRecipient() {
if (mSlidingMenu.isMenuShowing()) {
return getLeftDrawerFragment();
} else if (mSlidingMenu.isSecondaryMenuShowing()) {
return null;
} else {
return getCurrentVisibleFragment();
}
return Utils.getActivatedAccountIds(this);
}

private boolean handleFragmentKeyboardShortcutSingle(int keyCode, @NonNull KeyEvent event) {
final Fragment fragment = getCurrentVisibleFragment();
@Override
public int getControlBarHeight() {
return mTabIndicator.getHeight() - mTabIndicator.getStripHeight();
}

private boolean handleFragmentKeyboardShortcutRepeat(int keyCode, int repeatCount, @NonNull KeyEvent event) {
final Fragment fragment = getKeyboardShortcutRecipient();
if (fragment instanceof KeyboardShortcutCallback) {
return ((KeyboardShortcutCallback) fragment).handleKeyboardShortcutSingle(keyCode, event);
return ((KeyboardShortcutCallback) fragment).handleKeyboardShortcutRepeat(keyCode, repeatCount, event);
}
return false;
}

private boolean handleFragmentKeyboardShortcutRepeat(int keyCode, int repeatCount, @NonNull KeyEvent event) {
final Fragment fragment = getCurrentVisibleFragment();
private boolean handleFragmentKeyboardShortcutSingle(int keyCode, @NonNull KeyEvent event) {
final Fragment fragment = getKeyboardShortcutRecipient();
if (fragment instanceof KeyboardShortcutCallback) {
return ((KeyboardShortcutCallback) fragment).handleKeyboardShortcutRepeat(keyCode, repeatCount, event);
return ((KeyboardShortcutCallback) fragment).handleKeyboardShortcutSingle(keyCode, event);
}
return false;
}
Expand Down Expand Up @@ -957,7 +963,6 @@ private void updateSlidingMenuTouchMode() {
mSlidingMenu.setTouchModeAbove(mode);
}


private static final class AccountChangeObserver extends ContentObserver {
private final HomeActivity mActivity;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,6 @@ public Fragment getCurrentVisibleFragment() {
return getSupportFragmentManager().findFragmentById(R.id.main_content);
}

@Override
public void onDetachFragment(Fragment fragment) {

}

@Override
public void onSetUserVisibleHint(Fragment fragment, boolean isVisibleToUser) {

}

@Override
public boolean triggerRefresh(int position) {
return false;
Expand Down
Loading

0 comments on commit 68ba8d4

Please sign in to comment.