|
|
@ -45,28 +45,9 @@ public class TabsManager { |
|
|
|
@Inject Bus mEventBus; |
|
|
|
@Inject Bus mEventBus; |
|
|
|
@Inject Application mApp; |
|
|
|
@Inject Application mApp; |
|
|
|
|
|
|
|
|
|
|
|
@Nullable private TabChangeListener mListener; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public interface TabChangeListener { |
|
|
|
|
|
|
|
void tabChanged(LightningView newTab); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Inject |
|
|
|
@Inject |
|
|
|
public TabsManager() {} |
|
|
|
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 |
|
|
|
* Restores old tabs that were open before the browser |
|
|
|
* was closed. Handles the intent used to open the browser. |
|
|
|
* was closed. Handles the intent used to open the browser. |
|
|
@ -156,7 +137,6 @@ public class TabsManager { |
|
|
|
* released for garbage collection. |
|
|
|
* released for garbage collection. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public synchronized void shutdown() { |
|
|
|
public synchronized void shutdown() { |
|
|
|
sendTabChangedEvent(null); |
|
|
|
|
|
|
|
for (LightningView tab : mTabList) { |
|
|
|
for (LightningView tab : mTabList) { |
|
|
|
tab.onDestroy(); |
|
|
|
tab.onDestroy(); |
|
|
|
} |
|
|
|
} |
|
|
@ -247,7 +227,7 @@ public class TabsManager { |
|
|
|
* |
|
|
|
* |
|
|
|
* @param position the position of the tab to delete. |
|
|
|
* @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); |
|
|
|
Log.d(TAG, "Delete tab: " + position); |
|
|
|
final LightningView currentTab = getCurrentTab(); |
|
|
|
final LightningView currentTab = getCurrentTab(); |
|
|
|
int current = positionOf(currentTab); |
|
|
|
int current = positionOf(currentTab); |
|
|
@ -261,10 +241,11 @@ public class TabsManager { |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
mCurrentTab = getTabAtPosition(current - 1); |
|
|
|
mCurrentTab = getTabAtPosition(current - 1); |
|
|
|
} |
|
|
|
} |
|
|
|
sendTabChangedEvent(mCurrentTab); |
|
|
|
|
|
|
|
removeTab(current); |
|
|
|
removeTab(current); |
|
|
|
|
|
|
|
return true; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
removeTab(position); |
|
|
|
removeTab(position); |
|
|
|
|
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -333,6 +314,16 @@ public class TabsManager { |
|
|
|
return mCurrentTab != null ? mCurrentTab.getWebView() : null; |
|
|
|
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 |
|
|
|
* Return the current {@link LightningView} or null if |
|
|
|
* no current tab has been set. |
|
|
|
* no current tab has been set. |
|
|
@ -356,32 +347,14 @@ public class TabsManager { |
|
|
|
Log.d(TAG, "switch to tab: " + position); |
|
|
|
Log.d(TAG, "switch to tab: " + position); |
|
|
|
if (position < 0 || position >= mTabList.size()) { |
|
|
|
if (position < 0 || position >= mTabList.size()) { |
|
|
|
Log.e(TAG, "Returning a null LightningView requested for position: " + position); |
|
|
|
Log.e(TAG, "Returning a null LightningView requested for position: " + position); |
|
|
|
sendTabChangedEvent(null); |
|
|
|
|
|
|
|
return null; |
|
|
|
return null; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
final LightningView tab = mTabList.get(position); |
|
|
|
final LightningView tab = mTabList.get(position); |
|
|
|
if (tab != null) { |
|
|
|
if (tab != null) { |
|
|
|
mCurrentTab = tab; |
|
|
|
mCurrentTab = tab; |
|
|
|
} |
|
|
|
} |
|
|
|
sendTabChangedEvent(tab); |
|
|
|
|
|
|
|
return 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); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|