diff --git a/app/src/main/java/acr/browser/lightning/activity/TabsManager.java b/app/src/main/java/acr/browser/lightning/activity/TabsManager.java index 121c935..a248dd1 100644 --- a/app/src/main/java/acr/browser/lightning/activity/TabsManager.java +++ b/app/src/main/java/acr/browser/lightning/activity/TabsManager.java @@ -24,11 +24,11 @@ import acr.browser.lightning.R; import acr.browser.lightning.constant.Constants; import acr.browser.lightning.preference.PreferenceManager; import acr.browser.lightning.react.Action; +import acr.browser.lightning.react.Observable; import acr.browser.lightning.react.OnSubscribe; -import acr.browser.lightning.react.Subscriber; import acr.browser.lightning.react.Schedulers; +import acr.browser.lightning.react.Subscriber; import acr.browser.lightning.utils.FileUtils; -import acr.browser.lightning.react.Observable; import acr.browser.lightning.view.LightningView; /** @@ -308,6 +308,8 @@ public class TabsManager { * will switch the current tab to a new valid tab. * * @param position the position of the tab to delete. + * @return returns true if the current tab + * was deleted, false otherwise. */ public synchronized boolean deleteTab(int position) { Log.d(TAG, "Delete tab: " + position); @@ -319,22 +321,17 @@ public class TabsManager { mCurrentTab = null; } else if (current < size() - 1) { // There is another tab after this one - mCurrentTab = getTabAtPosition(current + 1); + switchToTab(current + 1); } else { - mCurrentTab = getTabAtPosition(current - 1); - } - removeTab(current); - if (mTabNumberListener != null) { - mTabNumberListener.tabNumberChanged(size()); + switchToTab(current - 1); } - return true; - } else { - removeTab(position); - if (mTabNumberListener != null) { - mTabNumberListener.tabNumberChanged(size()); - } - return false; } + + removeTab(position); + if (mTabNumberListener != null) { + mTabNumberListener.tabNumberChanged(size()); + } + return current == position; } /** diff --git a/app/src/main/java/acr/browser/lightning/browser/BrowserPresenter.java b/app/src/main/java/acr/browser/lightning/browser/BrowserPresenter.java index 7c17d2a..b87b1f0 100644 --- a/app/src/main/java/acr/browser/lightning/browser/BrowserPresenter.java +++ b/app/src/main/java/acr/browser/lightning/browser/BrowserPresenter.java @@ -99,7 +99,10 @@ public class BrowserPresenter { mView.setForwardButtonEnabled(newTab.canGoForward()); mView.updateUrl(newTab.getUrl(), true); mView.setTabView(newTab.getWebView()); - mView.notifyTabViewChanged(mTabsModel.indexOfTab(newTab)); + int index = mTabsModel.indexOfTab(newTab); + if (index >= 0) { + mView.notifyTabViewChanged(mTabsModel.indexOfTab(newTab)); + } } } diff --git a/app/src/main/java/acr/browser/lightning/fragment/anim/HorizontalItemAnimator.java b/app/src/main/java/acr/browser/lightning/fragment/anim/HorizontalItemAnimator.java index da92f60..cc5c03e 100644 --- a/app/src/main/java/acr/browser/lightning/fragment/anim/HorizontalItemAnimator.java +++ b/app/src/main/java/acr/browser/lightning/fragment/anim/HorizontalItemAnimator.java @@ -22,7 +22,10 @@ import android.support.v4.view.ViewPropertyAnimatorListener; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView.ViewHolder; import android.support.v7.widget.SimpleItemAnimator; +import android.util.Log; import android.view.View; +import android.view.animation.AccelerateInterpolator; +import android.view.animation.DecelerateInterpolator; import java.util.ArrayList; import java.util.List; @@ -197,7 +200,8 @@ public class HorizontalItemAnimator extends SimpleItemAnimator { final ViewPropertyAnimatorCompat animation = ViewCompat.animate(view); mRemoveAnimations.add(holder); animation.setDuration(getRemoveDuration()) - .alpha(0).translationY(holder.itemView.getHeight()).setListener(new VpaListenerAdapter() { + .alpha(0).translationY(holder.itemView.getHeight()) + .setInterpolator(new AccelerateInterpolator()).setListener(new VpaListenerAdapter() { @Override public void onAnimationStart(View view) { dispatchRemoveStarting(holder); @@ -207,6 +211,7 @@ public class HorizontalItemAnimator extends SimpleItemAnimator { public void onAnimationEnd(View view) { animation.setListener(null); ViewCompat.setAlpha(view, 1); + ViewCompat.setTranslationY(view, 0); dispatchRemoveFinished(holder); mRemoveAnimations.remove(holder); dispatchFinishedWhenDone(); @@ -227,8 +232,9 @@ public class HorizontalItemAnimator extends SimpleItemAnimator { final View view = holder.itemView; final ViewPropertyAnimatorCompat animation = ViewCompat.animate(view); mAddAnimations.add(holder); - animation.alpha(1).translationY(0).setDuration(getAddDuration()). - setListener(new VpaListenerAdapter() { + animation.alpha(1).translationY(0) + .setInterpolator(new DecelerateInterpolator()).setDuration(getAddDuration()) + .setListener(new VpaListenerAdapter() { @Override public void onAnimationStart(View view) { dispatchAddStarting(holder); @@ -236,6 +242,7 @@ public class HorizontalItemAnimator extends SimpleItemAnimator { @Override public void onAnimationCancel(View view) { + ViewCompat.setTranslationY(view, 0); ViewCompat.setAlpha(view, 1); } @@ -316,6 +323,17 @@ public class HorizontalItemAnimator extends SimpleItemAnimator { @Override public boolean animateChange(ViewHolder oldHolder, ViewHolder newHolder, int fromX, int fromY, int toX, int toY) { +// if (oldHolder != newHolder) { +// if (oldHolder != null) { +// dispatchChangeFinished(oldHolder, true); +// } +// if (newHolder != null) { +// dispatchChangeFinished(newHolder, false); +// } +// } else if (oldHolder != null) { +// dispatchChangeFinished(oldHolder, true); +// } +// return false; if (oldHolder == newHolder) { // Don't know how to run change animations when the same view holder is re-used. // run a move animation to handle position changes. diff --git a/app/src/main/java/acr/browser/lightning/fragment/anim/VerticalItemAnimator.java b/app/src/main/java/acr/browser/lightning/fragment/anim/VerticalItemAnimator.java index 4d435bc..463a4b3 100644 --- a/app/src/main/java/acr/browser/lightning/fragment/anim/VerticalItemAnimator.java +++ b/app/src/main/java/acr/browser/lightning/fragment/anim/VerticalItemAnimator.java @@ -22,7 +22,10 @@ import android.support.v4.view.ViewPropertyAnimatorListener; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView.ViewHolder; import android.support.v7.widget.SimpleItemAnimator; +import android.util.Log; import android.view.View; +import android.view.animation.AccelerateInterpolator; +import android.view.animation.DecelerateInterpolator; import java.util.ArrayList; import java.util.List; @@ -197,7 +200,8 @@ public class VerticalItemAnimator extends SimpleItemAnimator { final ViewPropertyAnimatorCompat animation = ViewCompat.animate(view); mRemoveAnimations.add(holder); animation.setDuration(getRemoveDuration()) - .alpha(0).translationX(-holder.itemView.getWidth() / 2).setListener(new VpaListenerAdapter() { + .alpha(0).translationX(-holder.itemView.getWidth() / 2) + .setInterpolator(new AccelerateInterpolator()).setListener(new VpaListenerAdapter() { @Override public void onAnimationStart(View view) { dispatchRemoveStarting(holder); @@ -207,6 +211,7 @@ public class VerticalItemAnimator extends SimpleItemAnimator { public void onAnimationEnd(View view) { animation.setListener(null); ViewCompat.setAlpha(view, 1); + ViewCompat.setTranslationX(view, 0); dispatchRemoveFinished(holder); mRemoveAnimations.remove(holder); dispatchFinishedWhenDone(); @@ -227,8 +232,8 @@ public class VerticalItemAnimator extends SimpleItemAnimator { final View view = holder.itemView; final ViewPropertyAnimatorCompat animation = ViewCompat.animate(view); mAddAnimations.add(holder); - animation.alpha(1).translationX(0).setDuration(getAddDuration()). - setListener(new VpaListenerAdapter() { + animation.alpha(1).translationX(0).setDuration(getAddDuration()) + .setInterpolator(new DecelerateInterpolator()).setListener(new VpaListenerAdapter() { @Override public void onAnimationStart(View view) { dispatchAddStarting(holder); @@ -237,6 +242,7 @@ public class VerticalItemAnimator extends SimpleItemAnimator { @Override public void onAnimationCancel(View view) { ViewCompat.setAlpha(view, 1); + ViewCompat.setTranslationX(view, 0); } @Override @@ -316,6 +322,17 @@ public class VerticalItemAnimator extends SimpleItemAnimator { @Override public boolean animateChange(ViewHolder oldHolder, ViewHolder newHolder, int fromX, int fromY, int toX, int toY) { +// if (oldHolder != newHolder) { +// if (oldHolder != null) { +// dispatchChangeFinished(oldHolder, true); +// } +// if (newHolder != null) { +// dispatchChangeFinished(newHolder, false); +// } +// } else if (oldHolder != null) { +// dispatchChangeFinished(oldHolder, true); +// } +// return false; if (oldHolder == newHolder) { // Don't know how to run change animations when the same view holder is re-used. // run a move animation to handle position changes.