|
|
|
@ -45,28 +45,9 @@ public class TabsManager {
@@ -45,28 +45,9 @@ public class TabsManager {
|
|
|
|
|
@Inject Bus mEventBus; |
|
|
|
|
@Inject Application mApp; |
|
|
|
|
|
|
|
|
|
@Nullable private TabChangeListener mListener; |
|
|
|
|
|
|
|
|
|
public interface TabChangeListener { |
|
|
|
|
void tabChanged(LightningView newTab); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Inject |
|
|
|
|
public TabsManager() {} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Sets the {@link TabChangeListener} to a new |
|
|
|
|
* listener. Can be set to null if the caller |
|
|
|
|
* wishes to unregister the listener. |
|
|
|
|
* |
|
|
|
|
* @param listener the new listener to use or |
|
|
|
|
* null if the caller wishes to |
|
|
|
|
* unregister the listener. |
|
|
|
|
*/ |
|
|
|
|
public void setTabChangeListener(@Nullable TabChangeListener listener) { |
|
|
|
|
mListener = listener; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Restores old tabs that were open before the browser |
|
|
|
|
* was closed. Handles the intent used to open the browser. |
|
|
|
@ -156,7 +137,6 @@ public class TabsManager {
@@ -156,7 +137,6 @@ public class TabsManager {
|
|
|
|
|
* released for garbage collection. |
|
|
|
|
*/ |
|
|
|
|
public synchronized void shutdown() { |
|
|
|
|
sendTabChangedEvent(null); |
|
|
|
|
for (LightningView tab : mTabList) { |
|
|
|
|
tab.onDestroy(); |
|
|
|
|
} |
|
|
|
@ -247,7 +227,7 @@ public class TabsManager {
@@ -247,7 +227,7 @@ public class TabsManager {
|
|
|
|
|
* |
|
|
|
|
* @param position the position of the tab to delete. |
|
|
|
|
*/ |
|
|
|
|
public synchronized void deleteTab(int position) { |
|
|
|
|
public synchronized boolean deleteTab(int position) { |
|
|
|
|
Log.d(TAG, "Delete tab: " + position); |
|
|
|
|
final LightningView currentTab = getCurrentTab(); |
|
|
|
|
int current = positionOf(currentTab); |
|
|
|
@ -261,10 +241,11 @@ public class TabsManager {
@@ -261,10 +241,11 @@ public class TabsManager {
|
|
|
|
|
} else { |
|
|
|
|
mCurrentTab = getTabAtPosition(current - 1); |
|
|
|
|
} |
|
|
|
|
sendTabChangedEvent(mCurrentTab); |
|
|
|
|
removeTab(current); |
|
|
|
|
return true; |
|
|
|
|
} else { |
|
|
|
|
removeTab(position); |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -333,6 +314,16 @@ public class TabsManager {
@@ -333,6 +314,16 @@ public class TabsManager {
|
|
|
|
|
return mCurrentTab != null ? mCurrentTab.getWebView() : null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Returns the index of the current tab. |
|
|
|
|
* |
|
|
|
|
* @return Return the index of the current tab, or -1 if the |
|
|
|
|
* current tab is null. |
|
|
|
|
*/ |
|
|
|
|
public int indexOfCurrentTab() { |
|
|
|
|
return mTabList.indexOf(mCurrentTab); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Return the current {@link LightningView} or null if |
|
|
|
|
* no current tab has been set. |
|
|
|
@ -356,32 +347,14 @@ public class TabsManager {
@@ -356,32 +347,14 @@ public class TabsManager {
|
|
|
|
|
Log.d(TAG, "switch to tab: " + position); |
|
|
|
|
if (position < 0 || position >= mTabList.size()) { |
|
|
|
|
Log.e(TAG, "Returning a null LightningView requested for position: " + position); |
|
|
|
|
sendTabChangedEvent(null); |
|
|
|
|
return null; |
|
|
|
|
} else { |
|
|
|
|
final LightningView tab = mTabList.get(position); |
|
|
|
|
if (tab != null) { |
|
|
|
|
mCurrentTab = tab; |
|
|
|
|
} |
|
|
|
|
sendTabChangedEvent(tab); |
|
|
|
|
return tab; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Send the event that the current tab has changed to |
|
|
|
|
* a new tab to the {@link TabChangeListener} if it is |
|
|
|
|
* not null. |
|
|
|
|
* |
|
|
|
|
* @param newView the new tab that we have switcted to, |
|
|
|
|
* can be null if the last tab has been |
|
|
|
|
* deleted. |
|
|
|
|
*/ |
|
|
|
|
private void sendTabChangedEvent(@Nullable LightningView newView) { |
|
|
|
|
Log.d(TAG, "NULL: " + (mListener == null)); |
|
|
|
|
if (mListener != null) { |
|
|
|
|
mListener.tabChanged(newView); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|