Fixing fragment lifecycle for tab and bookmark drawers
This commit is contained in:
parent
413f76c00b
commit
f90e897995
@ -170,7 +170,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
private ValueCallback<Uri> mUploadMessage;
|
private ValueCallback<Uri> mUploadMessage;
|
||||||
private ValueCallback<Uri[]> mFilePathCallback;
|
private ValueCallback<Uri[]> mFilePathCallback;
|
||||||
|
|
||||||
// Primatives
|
// Primitives
|
||||||
private boolean mFullScreen;
|
private boolean mFullScreen;
|
||||||
private boolean mDarkTheme;
|
private boolean mDarkTheme;
|
||||||
private boolean mIsFullScreen = false;
|
private boolean mIsFullScreen = false;
|
||||||
@ -215,9 +215,9 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
private static final int API = android.os.Build.VERSION.SDK_INT;
|
private static final int API = android.os.Build.VERSION.SDK_INT;
|
||||||
private static final String NETWORK_BROADCAST_ACTION = "android.net.conn.CONNECTIVITY_CHANGE";
|
private static final String NETWORK_BROADCAST_ACTION = "android.net.conn.CONNECTIVITY_CHANGE";
|
||||||
private static final LayoutParams MATCH_PARENT = new LayoutParams(LayoutParams.MATCH_PARENT,
|
private static final LayoutParams MATCH_PARENT = new LayoutParams(LayoutParams.MATCH_PARENT,
|
||||||
LayoutParams.MATCH_PARENT);
|
LayoutParams.MATCH_PARENT);
|
||||||
private static final FrameLayout.LayoutParams COVER_SCREEN_PARAMS = new FrameLayout.LayoutParams(
|
private static final FrameLayout.LayoutParams COVER_SCREEN_PARAMS = new FrameLayout.LayoutParams(
|
||||||
LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
|
LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
|
||||||
|
|
||||||
protected abstract boolean isIncognito();
|
protected abstract boolean isIncognito();
|
||||||
|
|
||||||
@ -249,7 +249,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
mDarkTheme = mPreferences.getUseTheme() != 0 || isIncognito();
|
mDarkTheme = mPreferences.getUseTheme() != 0 || isIncognito();
|
||||||
mIconColor = mDarkTheme ? ThemeUtils.getIconDarkThemeColor(this) : ThemeUtils.getIconLightThemeColor(this);
|
mIconColor = mDarkTheme ? ThemeUtils.getIconDarkThemeColor(this) : ThemeUtils.getIconLightThemeColor(this);
|
||||||
mDisabledIconColor = mDarkTheme ? ContextCompat.getColor(this, R.color.icon_dark_theme_disabled) :
|
mDisabledIconColor = mDarkTheme ? ContextCompat.getColor(this, R.color.icon_dark_theme_disabled) :
|
||||||
ContextCompat.getColor(this, R.color.icon_light_theme_disabled);
|
ContextCompat.getColor(this, R.color.icon_light_theme_disabled);
|
||||||
mShowTabsInDrawer = mPreferences.getShowTabsInDrawer(!isTablet());
|
mShowTabsInDrawer = mPreferences.getShowTabsInDrawer(!isTablet());
|
||||||
mSwapBookmarksAndTabs = mPreferences.getBookmarksAndTabsSwapped();
|
mSwapBookmarksAndTabs = mPreferences.getBookmarksAndTabsSwapped();
|
||||||
|
|
||||||
@ -292,31 +292,37 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
|
|
||||||
mWebpageBitmap = ThemeUtils.getThemedBitmap(this, R.drawable.ic_webpage, mDarkTheme);
|
mWebpageBitmap = ThemeUtils.getThemedBitmap(this, R.drawable.ic_webpage, mDarkTheme);
|
||||||
|
|
||||||
final TabsFragment tabsFragment = new TabsFragment();
|
|
||||||
mTabsView = tabsFragment;
|
|
||||||
final Bundle tabsFragmentArguments = new Bundle();
|
|
||||||
tabsFragmentArguments.putBoolean(TabsFragment.IS_INCOGNITO, isIncognito());
|
|
||||||
tabsFragmentArguments.putBoolean(TabsFragment.VERTICAL_MODE, mShowTabsInDrawer);
|
|
||||||
tabsFragment.setArguments(tabsFragmentArguments);
|
|
||||||
|
|
||||||
final BookmarksFragment bookmarksFragment = new BookmarksFragment();
|
|
||||||
mBookmarksView = bookmarksFragment;
|
|
||||||
final Bundle bookmarksFragmentArguments = new Bundle();
|
|
||||||
bookmarksFragmentArguments.putBoolean(BookmarksFragment.INCOGNITO_MODE, isIncognito());
|
|
||||||
bookmarksFragment.setArguments(bookmarksFragmentArguments);
|
|
||||||
|
|
||||||
final FragmentManager fragmentManager = getSupportFragmentManager();
|
final FragmentManager fragmentManager = getSupportFragmentManager();
|
||||||
|
|
||||||
|
TabsFragment tabsFragment = (TabsFragment) fragmentManager.findFragmentByTag(TAG_TABS_FRAGMENT);
|
||||||
|
BookmarksFragment bookmarksFragment = (BookmarksFragment) fragmentManager.findFragmentByTag(TAG_BOOKMARK_FRAGMENT);
|
||||||
|
|
||||||
|
if (tabsFragment != null) {
|
||||||
|
fragmentManager.beginTransaction().remove(tabsFragment).commit();
|
||||||
|
}
|
||||||
|
tabsFragment = TabsFragment.createTabsFragment(isIncognito(), mShowTabsInDrawer);
|
||||||
|
|
||||||
|
mTabsView = tabsFragment;
|
||||||
|
|
||||||
|
if (bookmarksFragment != null) {
|
||||||
|
fragmentManager.beginTransaction().remove(bookmarksFragment).commit();
|
||||||
|
}
|
||||||
|
bookmarksFragment = BookmarksFragment.createFragment(isIncognito());
|
||||||
|
|
||||||
|
mBookmarksView = bookmarksFragment;
|
||||||
|
|
||||||
|
fragmentManager.executePendingTransactions();
|
||||||
|
|
||||||
fragmentManager
|
fragmentManager
|
||||||
.beginTransaction()
|
.beginTransaction()
|
||||||
.replace(getTabsFragmentViewId(), tabsFragment, TAG_TABS_FRAGMENT)
|
.replace(getTabsFragmentViewId(), tabsFragment, TAG_TABS_FRAGMENT)
|
||||||
.replace(getBookmarksFragmentViewId(), bookmarksFragment, TAG_BOOKMARK_FRAGMENT)
|
.replace(getBookmarksFragmentViewId(), bookmarksFragment, TAG_BOOKMARK_FRAGMENT)
|
||||||
.commit();
|
.commit();
|
||||||
if (mShowTabsInDrawer) {
|
if (mShowTabsInDrawer) {
|
||||||
mToolbarLayout.removeView(findViewById(R.id.tabs_toolbar_container));
|
mToolbarLayout.removeView(findViewById(R.id.tabs_toolbar_container));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (actionBar == null)
|
Preconditions.checkNonNull(actionBar);
|
||||||
return;
|
|
||||||
|
|
||||||
// set display options of the ActionBar
|
// set display options of the ActionBar
|
||||||
actionBar.setDisplayShowTitleEnabled(false);
|
actionBar.setDisplayShowTitleEnabled(false);
|
||||||
@ -337,11 +343,35 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
mArrowImage.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
|
mArrowImage.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
|
||||||
}
|
}
|
||||||
updateTabNumber(0);
|
updateTabNumber(0);
|
||||||
|
|
||||||
|
// Post drawer locking in case the activity is being recreated
|
||||||
|
Handlers.MAIN.post(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED, getTabDrawer());
|
||||||
|
}
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, getTabDrawer());
|
|
||||||
|
// Post drawer locking in case the activity is being recreated
|
||||||
|
Handlers.MAIN.post(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, getTabDrawer());
|
||||||
|
}
|
||||||
|
});
|
||||||
mArrowImage.setImageResource(R.drawable.ic_action_home);
|
mArrowImage.setImageResource(R.drawable.ic_action_home);
|
||||||
mArrowImage.setColorFilter(mIconColor, PorterDuff.Mode.SRC_IN);
|
mArrowImage.setColorFilter(mIconColor, PorterDuff.Mode.SRC_IN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Post drawer locking in case the activity is being recreated
|
||||||
|
Handlers.MAIN.post(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED, getBookmarkDrawer());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
arrowButton.setOnClickListener(this);
|
arrowButton.setOnClickListener(this);
|
||||||
|
|
||||||
// create the search EditText in the ToolBar
|
// create the search EditText in the ToolBar
|
||||||
@ -432,7 +462,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
private class SearchListenerClass implements OnKeyListener, OnEditorActionListener,
|
private class SearchListenerClass implements OnKeyListener, OnEditorActionListener,
|
||||||
OnFocusChangeListener, OnTouchListener, SearchView.PreFocusListener {
|
OnFocusChangeListener, OnTouchListener, SearchView.PreFocusListener {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onKey(View searchView, int keyCode, KeyEvent keyEvent) {
|
public boolean onKey(View searchView, int keyCode, KeyEvent keyEvent) {
|
||||||
@ -458,10 +488,10 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
// hide the keyboard and search the web when the enter key
|
// hide the keyboard and search the web when the enter key
|
||||||
// button is pressed
|
// button is pressed
|
||||||
if (actionId == EditorInfo.IME_ACTION_GO || actionId == EditorInfo.IME_ACTION_DONE
|
if (actionId == EditorInfo.IME_ACTION_GO || actionId == EditorInfo.IME_ACTION_DONE
|
||||||
|| actionId == EditorInfo.IME_ACTION_NEXT
|
|| actionId == EditorInfo.IME_ACTION_NEXT
|
||||||
|| actionId == EditorInfo.IME_ACTION_SEND
|
|| actionId == EditorInfo.IME_ACTION_SEND
|
||||||
|| actionId == EditorInfo.IME_ACTION_SEARCH
|
|| actionId == EditorInfo.IME_ACTION_SEARCH
|
||||||
|| (arg2.getAction() == KeyEvent.KEYCODE_ENTER)) {
|
|| (arg2.getAction() == KeyEvent.KEYCODE_ENTER)) {
|
||||||
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||||
imm.hideSoftInputFromWindow(mSearch.getWindowToken(), 0);
|
imm.hideSoftInputFromWindow(mSearch.getWindowToken(), 0);
|
||||||
searchTheWeb(mSearch.getText().toString());
|
searchTheWeb(mSearch.getText().toString());
|
||||||
@ -498,7 +528,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
public boolean onTouch(View v, MotionEvent event) {
|
public boolean onTouch(View v, MotionEvent event) {
|
||||||
if (mSearch.getCompoundDrawables()[2] != null) {
|
if (mSearch.getCompoundDrawables()[2] != null) {
|
||||||
boolean tappedX = event.getX() > (mSearch.getWidth()
|
boolean tappedX = event.getX() > (mSearch.getWidth()
|
||||||
- mSearch.getPaddingRight() - mIcon.getIntrinsicWidth());
|
- mSearch.getPaddingRight() - mIcon.getIntrinsicWidth());
|
||||||
if (tappedX) {
|
if (tappedX) {
|
||||||
if (event.getAction() == MotionEvent.ACTION_UP) {
|
if (event.getAction() == MotionEvent.ACTION_UP) {
|
||||||
if (mSearch.hasFocus()) {
|
if (mSearch.hasFocus()) {
|
||||||
@ -532,19 +562,25 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDrawerClosed(View v) {
|
public void onDrawerClosed(View v) {
|
||||||
if (v == mDrawerRight && mShowTabsInDrawer) {
|
View tabsDrawer = getTabDrawer();
|
||||||
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED, mDrawerLeft);
|
View bookmarksDrawer = getBookmarkDrawer();
|
||||||
} else {
|
|
||||||
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED, mDrawerRight);
|
if (v == tabsDrawer) {
|
||||||
|
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED, bookmarksDrawer);
|
||||||
|
} else if (mShowTabsInDrawer) {
|
||||||
|
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED, tabsDrawer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDrawerOpened(View v) {
|
public void onDrawerOpened(View v) {
|
||||||
if (v == mDrawerRight) {
|
View tabsDrawer = getTabDrawer();
|
||||||
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, mDrawerLeft);
|
View bookmarksDrawer = getBookmarkDrawer();
|
||||||
|
|
||||||
|
if (v == tabsDrawer) {
|
||||||
|
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, bookmarksDrawer);
|
||||||
} else {
|
} else {
|
||||||
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, mDrawerRight);
|
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, tabsDrawer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -566,23 +602,23 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
}
|
}
|
||||||
if (width > maxWidth) {
|
if (width > maxWidth) {
|
||||||
DrawerLayout.LayoutParams params = (android.support.v4.widget.DrawerLayout.LayoutParams) mDrawerLeft
|
DrawerLayout.LayoutParams params = (android.support.v4.widget.DrawerLayout.LayoutParams) mDrawerLeft
|
||||||
.getLayoutParams();
|
.getLayoutParams();
|
||||||
params.width = maxWidth;
|
params.width = maxWidth;
|
||||||
mDrawerLeft.setLayoutParams(params);
|
mDrawerLeft.setLayoutParams(params);
|
||||||
mDrawerLeft.requestLayout();
|
mDrawerLeft.requestLayout();
|
||||||
DrawerLayout.LayoutParams paramsRight = (android.support.v4.widget.DrawerLayout.LayoutParams) mDrawerRight
|
DrawerLayout.LayoutParams paramsRight = (android.support.v4.widget.DrawerLayout.LayoutParams) mDrawerRight
|
||||||
.getLayoutParams();
|
.getLayoutParams();
|
||||||
paramsRight.width = maxWidth;
|
paramsRight.width = maxWidth;
|
||||||
mDrawerRight.setLayoutParams(paramsRight);
|
mDrawerRight.setLayoutParams(paramsRight);
|
||||||
mDrawerRight.requestLayout();
|
mDrawerRight.requestLayout();
|
||||||
} else {
|
} else {
|
||||||
DrawerLayout.LayoutParams params = (android.support.v4.widget.DrawerLayout.LayoutParams) mDrawerLeft
|
DrawerLayout.LayoutParams params = (android.support.v4.widget.DrawerLayout.LayoutParams) mDrawerLeft
|
||||||
.getLayoutParams();
|
.getLayoutParams();
|
||||||
params.width = width;
|
params.width = width;
|
||||||
mDrawerLeft.setLayoutParams(params);
|
mDrawerLeft.setLayoutParams(params);
|
||||||
mDrawerLeft.requestLayout();
|
mDrawerLeft.requestLayout();
|
||||||
DrawerLayout.LayoutParams paramsRight = (android.support.v4.widget.DrawerLayout.LayoutParams) mDrawerRight
|
DrawerLayout.LayoutParams paramsRight = (android.support.v4.widget.DrawerLayout.LayoutParams) mDrawerRight
|
||||||
.getLayoutParams();
|
.getLayoutParams();
|
||||||
paramsRight.width = width;
|
paramsRight.width = width;
|
||||||
mDrawerRight.setLayoutParams(paramsRight);
|
mDrawerRight.setLayoutParams(paramsRight);
|
||||||
mDrawerRight.requestLayout();
|
mDrawerRight.requestLayout();
|
||||||
@ -612,7 +648,6 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
((BookmarksFragment) bookmarksFragment).reinitializePreferences();
|
((BookmarksFragment) bookmarksFragment).reinitializePreferences();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// TODO layout transition causing memory leak
|
// TODO layout transition causing memory leak
|
||||||
// mBrowserFrame.setLayoutTransition(new LayoutTransition());
|
// mBrowserFrame.setLayoutTransition(new LayoutTransition());
|
||||||
|
|
||||||
@ -622,7 +657,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
case 0:
|
case 0:
|
||||||
mSearchText = mPreferences.getSearchUrl();
|
mSearchText = mPreferences.getSearchUrl();
|
||||||
if (!mSearchText.startsWith(Constants.HTTP)
|
if (!mSearchText.startsWith(Constants.HTTP)
|
||||||
&& !mSearchText.startsWith(Constants.HTTPS)) {
|
&& !mSearchText.startsWith(Constants.HTTPS)) {
|
||||||
mSearchText = Constants.GOOGLE_SEARCH;
|
mSearchText = Constants.GOOGLE_SEARCH;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -676,8 +711,8 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
searchTheWeb(mSearch.getText().toString());
|
searchTheWeb(mSearch.getText().toString());
|
||||||
}
|
}
|
||||||
} else if ((keyCode == KeyEvent.KEYCODE_MENU)
|
} else if ((keyCode == KeyEvent.KEYCODE_MENU)
|
||||||
&& (Build.VERSION.SDK_INT <= Build.VERSION_CODES.JELLY_BEAN)
|
&& (Build.VERSION.SDK_INT <= Build.VERSION_CODES.JELLY_BEAN)
|
||||||
&& (Build.MANUFACTURER.compareTo("LGE") == 0)) {
|
&& (Build.MANUFACTURER.compareTo("LGE") == 0)) {
|
||||||
// Workaround for stupid LG devices that crash
|
// Workaround for stupid LG devices that crash
|
||||||
return true;
|
return true;
|
||||||
} else if (keyCode == KeyEvent.KEYCODE_BACK) {
|
} else if (keyCode == KeyEvent.KEYCODE_BACK) {
|
||||||
@ -698,8 +733,8 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
@Override
|
@Override
|
||||||
public boolean onKeyUp(int keyCode, @NonNull KeyEvent event) {
|
public boolean onKeyUp(int keyCode, @NonNull KeyEvent event) {
|
||||||
if ((keyCode == KeyEvent.KEYCODE_MENU)
|
if ((keyCode == KeyEvent.KEYCODE_MENU)
|
||||||
&& (Build.VERSION.SDK_INT <= Build.VERSION_CODES.JELLY_BEAN)
|
&& (Build.VERSION.SDK_INT <= Build.VERSION_CODES.JELLY_BEAN)
|
||||||
&& (Build.MANUFACTURER.compareTo("LGE") == 0)) {
|
&& (Build.MANUFACTURER.compareTo("LGE") == 0)) {
|
||||||
// Workaround for stupid LG devices that crash
|
// Workaround for stupid LG devices that crash
|
||||||
openOptionsMenu();
|
openOptionsMenu();
|
||||||
return true;
|
return true;
|
||||||
@ -796,8 +831,8 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
// By using a manager, adds a bookmark and notifies third parties about that
|
// By using a manager, adds a bookmark and notifies third parties about that
|
||||||
private void addBookmark(final String title, final String url) {
|
private void addBookmark(final String title, final String url) {
|
||||||
final HistoryItem item = !mBookmarkManager.isBookmark(url)
|
final HistoryItem item = !mBookmarkManager.isBookmark(url)
|
||||||
? new HistoryItem(url, title)
|
? new HistoryItem(url, title)
|
||||||
: null;
|
: null;
|
||||||
if (item != null && mBookmarkManager.addBookmark(item)) {
|
if (item != null && mBookmarkManager.addBookmark(item)) {
|
||||||
mSuggestionsAdapter.refreshBookmarks();
|
mSuggestionsAdapter.refreshBookmarks();
|
||||||
mBookmarksView.handleUpdatedUrl(url);
|
mBookmarksView.handleUpdatedUrl(url);
|
||||||
@ -806,8 +841,8 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
|
|
||||||
private void deleteBookmark(final String title, final String url) {
|
private void deleteBookmark(final String title, final String url) {
|
||||||
final HistoryItem item = mBookmarkManager.isBookmark(url)
|
final HistoryItem item = mBookmarkManager.isBookmark(url)
|
||||||
? new HistoryItem(url, title)
|
? new HistoryItem(url, title)
|
||||||
: null;
|
: null;
|
||||||
if (item != null && mBookmarkManager.deleteBookmark(item)) {
|
if (item != null && mBookmarkManager.deleteBookmark(item)) {
|
||||||
mSuggestionsAdapter.refreshBookmarks();
|
mSuggestionsAdapter.refreshBookmarks();
|
||||||
mBookmarksView.handleUpdatedUrl(url);
|
mBookmarksView.handleUpdatedUrl(url);
|
||||||
@ -852,17 +887,17 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
*/
|
*/
|
||||||
private void findInPage() {
|
private void findInPage() {
|
||||||
BrowserDialog.showEditText(this,
|
BrowserDialog.showEditText(this,
|
||||||
R.string.action_find,
|
R.string.action_find,
|
||||||
R.string.search_hint,
|
R.string.search_hint,
|
||||||
R.string.search_hint, new BrowserDialog.EditorListener() {
|
R.string.search_hint, new BrowserDialog.EditorListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(String text) {
|
public void onClick(String text) {
|
||||||
if (!TextUtils.isEmpty(text)) {
|
if (!TextUtils.isEmpty(text)) {
|
||||||
mPresenter.findInPage(text);
|
mPresenter.findInPage(text);
|
||||||
showFindInPageControls(text);
|
showFindInPageControls(text);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showFindInPageControls(@NonNull String text) {
|
private void showFindInPageControls(@NonNull String text) {
|
||||||
@ -892,24 +927,24 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
BrowserDialog.show(this, R.string.dialog_title_close_browser,
|
BrowserDialog.show(this, R.string.dialog_title_close_browser,
|
||||||
new BrowserDialog.Item(R.string.close_tab) {
|
new BrowserDialog.Item(R.string.close_tab) {
|
||||||
@Override
|
@Override
|
||||||
public void onClick() {
|
public void onClick() {
|
||||||
mPresenter.deleteTab(position);
|
mPresenter.deleteTab(position);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
new BrowserDialog.Item(R.string.close_other_tabs) {
|
new BrowserDialog.Item(R.string.close_other_tabs) {
|
||||||
@Override
|
@Override
|
||||||
public void onClick() {
|
public void onClick() {
|
||||||
mPresenter.closeAllOtherTabs();
|
mPresenter.closeAllOtherTabs();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
new BrowserDialog.Item(R.string.close_all_tabs) {
|
new BrowserDialog.Item(R.string.close_all_tabs) {
|
||||||
@Override
|
@Override
|
||||||
public void onClick() {
|
public void onClick() {
|
||||||
closeBrowser();
|
closeBrowser();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -1016,11 +1051,11 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
public void showBlockedLocalFileDialog(DialogInterface.OnClickListener listener) {
|
public void showBlockedLocalFileDialog(DialogInterface.OnClickListener listener) {
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||||
Dialog dialog = builder.setCancelable(true)
|
Dialog dialog = builder.setCancelable(true)
|
||||||
.setTitle(R.string.title_warning)
|
.setTitle(R.string.title_warning)
|
||||||
.setMessage(R.string.message_blocked_local)
|
.setMessage(R.string.message_blocked_local)
|
||||||
.setNegativeButton(android.R.string.cancel, null)
|
.setNegativeButton(android.R.string.cancel, null)
|
||||||
.setPositiveButton(R.string.action_open, listener)
|
.setPositiveButton(R.string.action_open, listener)
|
||||||
.show();
|
.show();
|
||||||
|
|
||||||
BrowserDialog.setDialogSize(this, dialog);
|
BrowserDialog.setDialogSize(this, dialog);
|
||||||
}
|
}
|
||||||
@ -1397,7 +1432,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
mCurrentUiColor = color;
|
mCurrentUiColor = color;
|
||||||
mToolbarLayout.setBackgroundColor(color);
|
mToolbarLayout.setBackgroundColor(color);
|
||||||
mSearchBackground.getBackground().setColorFilter(DrawableUtils.mixColor(interpolatedTime,
|
mSearchBackground.getBackground().setColorFilter(DrawableUtils.mixColor(interpolatedTime,
|
||||||
startSearchColor, finalSearchColor), PorterDuff.Mode.SRC_IN);
|
startSearchColor, finalSearchColor), PorterDuff.Mode.SRC_IN);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
animation.setDuration(300);
|
animation.setDuration(300);
|
||||||
@ -1462,7 +1497,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
public void updateTabNumber(int number) {
|
public void updateTabNumber(int number) {
|
||||||
if (mArrowImage != null && mShowTabsInDrawer) {
|
if (mArrowImage != null && mShowTabsInDrawer) {
|
||||||
mArrowImage.setImageBitmap(DrawableUtils.getRoundedNumberImage(number, Utils.dpToPx(24),
|
mArrowImage.setImageBitmap(DrawableUtils.getRoundedNumberImage(number, Utils.dpToPx(24),
|
||||||
Utils.dpToPx(24), ThemeUtils.getIconThemeColor(this, mDarkTheme), Utils.dpToPx(2.5f)));
|
Utils.dpToPx(24), ThemeUtils.getIconThemeColor(this, mDarkTheme), Utils.dpToPx(2.5f)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1478,13 +1513,13 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
HistoryModel.visitHistoryItem(url, title)
|
HistoryModel.visitHistoryItem(url, title)
|
||||||
.subscribeOn(Schedulers.io())
|
.subscribeOn(Schedulers.io())
|
||||||
.subscribe(new CompletableOnSubscribe() {
|
.subscribe(new CompletableOnSubscribe() {
|
||||||
@Override
|
@Override
|
||||||
public void onError(@NonNull Throwable throwable) {
|
public void onError(@NonNull Throwable throwable) {
|
||||||
Log.e(TAG, "Exception while updating history", throwable);
|
Log.e(TAG, "Exception while updating history", throwable);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1534,18 +1569,18 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
*/
|
*/
|
||||||
private void openHistory() {
|
private void openHistory() {
|
||||||
new HistoryPage().getHistoryPage()
|
new HistoryPage().getHistoryPage()
|
||||||
.subscribeOn(Schedulers.io())
|
.subscribeOn(Schedulers.io())
|
||||||
.observeOn(Schedulers.main())
|
.observeOn(Schedulers.main())
|
||||||
.subscribe(new SingleOnSubscribe<String>() {
|
.subscribe(new SingleOnSubscribe<String>() {
|
||||||
@Override
|
@Override
|
||||||
public void onItem(@Nullable String item) {
|
public void onItem(@Nullable String item) {
|
||||||
Preconditions.checkNonNull(item);
|
Preconditions.checkNonNull(item);
|
||||||
LightningView view = mTabsManager.getCurrentTab();
|
LightningView view = mTabsManager.getCurrentTab();
|
||||||
if (view != null) {
|
if (view != null) {
|
||||||
view.loadUrl(item);
|
view.loadUrl(item);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private View getBookmarkDrawer() {
|
private View getBookmarkDrawer() {
|
||||||
@ -1857,7 +1892,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
private class VideoCompletionListener implements MediaPlayer.OnCompletionListener,
|
private class VideoCompletionListener implements MediaPlayer.OnCompletionListener,
|
||||||
MediaPlayer.OnErrorListener {
|
MediaPlayer.OnErrorListener {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onError(MediaPlayer mp, int what, int extra) {
|
public boolean onError(MediaPlayer mp, int what, int extra) {
|
||||||
@ -1930,16 +1965,16 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
if (enabled) {
|
if (enabled) {
|
||||||
if (immersive) {
|
if (immersive) {
|
||||||
decor.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
|
decor.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
|
||||||
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
|
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
|
||||||
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|
||||||
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
|
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
|
||||||
| View.SYSTEM_UI_FLAG_FULLSCREEN
|
| View.SYSTEM_UI_FLAG_FULLSCREEN
|
||||||
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
|
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
|
||||||
} else {
|
} else {
|
||||||
decor.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
|
decor.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
|
||||||
}
|
}
|
||||||
window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
|
window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
|
||||||
WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||||
} else {
|
} else {
|
||||||
window.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
window.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||||
decor.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
|
decor.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
|
||||||
@ -2241,7 +2276,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
private void handleBookmarksChange() {
|
private void handleBookmarksChange() {
|
||||||
final LightningView currentTab = mTabsManager.getCurrentTab();
|
final LightningView currentTab = mTabsManager.getCurrentTab();
|
||||||
if (currentTab != null && currentTab.getUrl().startsWith(Constants.FILE)
|
if (currentTab != null && currentTab.getUrl().startsWith(Constants.FILE)
|
||||||
&& currentTab.getUrl().endsWith(BookmarkPage.FILENAME)) {
|
&& currentTab.getUrl().endsWith(BookmarkPage.FILENAME)) {
|
||||||
currentTab.loadBookmarkpage();
|
currentTab.loadBookmarkpage();
|
||||||
}
|
}
|
||||||
if (currentTab != null) {
|
if (currentTab != null) {
|
||||||
|
@ -32,6 +32,7 @@ import com.anthonycr.bonsai.Single;
|
|||||||
import com.anthonycr.bonsai.SingleAction;
|
import com.anthonycr.bonsai.SingleAction;
|
||||||
import com.anthonycr.bonsai.SingleOnSubscribe;
|
import com.anthonycr.bonsai.SingleOnSubscribe;
|
||||||
import com.anthonycr.bonsai.SingleSubscriber;
|
import com.anthonycr.bonsai.SingleSubscriber;
|
||||||
|
import com.anthonycr.bonsai.Subscription;
|
||||||
import com.squareup.otto.Bus;
|
import com.squareup.otto.Bus;
|
||||||
import com.squareup.otto.Subscribe;
|
import com.squareup.otto.Subscribe;
|
||||||
|
|
||||||
@ -45,7 +46,6 @@ import acr.browser.lightning.R;
|
|||||||
import acr.browser.lightning.activity.ReadingActivity;
|
import acr.browser.lightning.activity.ReadingActivity;
|
||||||
import acr.browser.lightning.activity.TabsManager;
|
import acr.browser.lightning.activity.TabsManager;
|
||||||
import acr.browser.lightning.app.BrowserApp;
|
import acr.browser.lightning.app.BrowserApp;
|
||||||
import acr.browser.lightning.favicon.FaviconModel;
|
|
||||||
import acr.browser.lightning.browser.BookmarksView;
|
import acr.browser.lightning.browser.BookmarksView;
|
||||||
import acr.browser.lightning.bus.BookmarkEvents;
|
import acr.browser.lightning.bus.BookmarkEvents;
|
||||||
import acr.browser.lightning.constant.Constants;
|
import acr.browser.lightning.constant.Constants;
|
||||||
@ -53,6 +53,7 @@ import acr.browser.lightning.controller.UIController;
|
|||||||
import acr.browser.lightning.database.BookmarkManager;
|
import acr.browser.lightning.database.BookmarkManager;
|
||||||
import acr.browser.lightning.database.HistoryItem;
|
import acr.browser.lightning.database.HistoryItem;
|
||||||
import acr.browser.lightning.dialog.LightningDialogBuilder;
|
import acr.browser.lightning.dialog.LightningDialogBuilder;
|
||||||
|
import acr.browser.lightning.favicon.FaviconModel;
|
||||||
import acr.browser.lightning.preference.PreferenceManager;
|
import acr.browser.lightning.preference.PreferenceManager;
|
||||||
import acr.browser.lightning.utils.ThemeUtils;
|
import acr.browser.lightning.utils.ThemeUtils;
|
||||||
import acr.browser.lightning.view.LightningView;
|
import acr.browser.lightning.view.LightningView;
|
||||||
@ -62,6 +63,16 @@ import butterknife.Unbinder;
|
|||||||
|
|
||||||
public class BookmarksFragment extends Fragment implements View.OnClickListener, View.OnLongClickListener, BookmarksView {
|
public class BookmarksFragment extends Fragment implements View.OnClickListener, View.OnLongClickListener, BookmarksView {
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
public static BookmarksFragment createFragment(boolean isIncognito) {
|
||||||
|
BookmarksFragment bookmarksFragment = new BookmarksFragment();
|
||||||
|
final Bundle bookmarksFragmentArguments = new Bundle();
|
||||||
|
bookmarksFragmentArguments.putBoolean(BookmarksFragment.INCOGNITO_MODE, isIncognito);
|
||||||
|
bookmarksFragment.setArguments(bookmarksFragmentArguments);
|
||||||
|
|
||||||
|
return bookmarksFragment;
|
||||||
|
}
|
||||||
|
|
||||||
private final static String TAG = BookmarksFragment.class.getSimpleName();
|
private final static String TAG = BookmarksFragment.class.getSimpleName();
|
||||||
|
|
||||||
public final static String INCOGNITO_MODE = TAG + ".INCOGNITO_MODE";
|
public final static String INCOGNITO_MODE = TAG + ".INCOGNITO_MODE";
|
||||||
@ -96,6 +107,8 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
|
|||||||
@BindView(R.id.right_drawer_list) ListView mBookmarksListView;
|
@BindView(R.id.right_drawer_list) ListView mBookmarksListView;
|
||||||
@BindView(R.id.starIcon) ImageView mBookmarkTitleImage;
|
@BindView(R.id.starIcon) ImageView mBookmarkTitleImage;
|
||||||
@BindView(R.id.icon_star) ImageView mBookmarkImage;
|
@BindView(R.id.icon_star) ImageView mBookmarkImage;
|
||||||
|
|
||||||
|
@Nullable
|
||||||
private Unbinder mUnbinder;
|
private Unbinder mUnbinder;
|
||||||
|
|
||||||
// Colors
|
// Colors
|
||||||
@ -103,6 +116,9 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
|
|||||||
|
|
||||||
private boolean mIsIncognito;
|
private boolean mIsIncognito;
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
private Subscription mBookmarksSubscription;
|
||||||
|
|
||||||
private Single<BookmarkViewAdapter> initBookmarkManager() {
|
private Single<BookmarkViewAdapter> initBookmarkManager() {
|
||||||
return Single.create(new SingleAction<BookmarkViewAdapter>() {
|
return Single.create(new SingleAction<BookmarkViewAdapter>() {
|
||||||
@Override
|
@Override
|
||||||
@ -197,11 +213,12 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
|
|||||||
setupNavigationButton(view, R.id.action_reading, R.id.icon_reading);
|
setupNavigationButton(view, R.id.action_reading, R.id.icon_reading);
|
||||||
setupNavigationButton(view, R.id.action_toggle_desktop, R.id.icon_desktop);
|
setupNavigationButton(view, R.id.action_toggle_desktop, R.id.icon_desktop);
|
||||||
|
|
||||||
initBookmarkManager().subscribeOn(Schedulers.io())
|
mBookmarksSubscription = initBookmarkManager().subscribeOn(Schedulers.io())
|
||||||
.observeOn(Schedulers.main())
|
.observeOn(Schedulers.main())
|
||||||
.subscribe(new SingleOnSubscribe<BookmarkViewAdapter>() {
|
.subscribe(new SingleOnSubscribe<BookmarkViewAdapter>() {
|
||||||
@Override
|
@Override
|
||||||
public void onItem(@Nullable BookmarkViewAdapter item) {
|
public void onItem(@Nullable BookmarkViewAdapter item) {
|
||||||
|
mBookmarksSubscription = null;
|
||||||
mBookmarksListView.setAdapter(mBookmarkAdapter);
|
mBookmarksListView.setAdapter(mBookmarkAdapter);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -211,12 +228,25 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
|
|||||||
@Override
|
@Override
|
||||||
public void onDestroyView() {
|
public void onDestroyView() {
|
||||||
super.onDestroyView();
|
super.onDestroyView();
|
||||||
|
if (mBookmarksSubscription != null) {
|
||||||
|
mBookmarksSubscription.unsubscribe();
|
||||||
|
mBookmarksSubscription = null;
|
||||||
|
}
|
||||||
if (mUnbinder != null) {
|
if (mUnbinder != null) {
|
||||||
mUnbinder.unbind();
|
mUnbinder.unbind();
|
||||||
mUnbinder = null;
|
mUnbinder = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroy() {
|
||||||
|
super.onDestroy();
|
||||||
|
if (mBookmarksSubscription != null) {
|
||||||
|
mBookmarksSubscription.unsubscribe();
|
||||||
|
mBookmarksSubscription = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStart() {
|
public void onStart() {
|
||||||
super.onStart();
|
super.onStart();
|
||||||
@ -382,7 +412,7 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
|
|||||||
|
|
||||||
final Context context;
|
final Context context;
|
||||||
|
|
||||||
public BookmarkViewAdapter(Context context, @NonNull List<HistoryItem> data) {
|
BookmarkViewAdapter(Context context, @NonNull List<HistoryItem> data) {
|
||||||
super(context, R.layout.bookmark_list_item, data);
|
super(context, R.layout.bookmark_list_item, data);
|
||||||
this.context = context;
|
this.context = context;
|
||||||
}
|
}
|
||||||
|
@ -61,6 +61,17 @@ import butterknife.Unbinder;
|
|||||||
*/
|
*/
|
||||||
public class TabsFragment extends Fragment implements View.OnClickListener, View.OnLongClickListener, TabsView {
|
public class TabsFragment extends Fragment implements View.OnClickListener, View.OnLongClickListener, TabsView {
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
public static TabsFragment createTabsFragment(boolean isIncognito, boolean showTabsInDrawer) {
|
||||||
|
TabsFragment tabsFragment = new TabsFragment();
|
||||||
|
final Bundle tabsFragmentArguments = new Bundle();
|
||||||
|
tabsFragmentArguments.putBoolean(TabsFragment.IS_INCOGNITO, isIncognito);
|
||||||
|
tabsFragmentArguments.putBoolean(TabsFragment.VERTICAL_MODE, showTabsInDrawer);
|
||||||
|
tabsFragment.setArguments(tabsFragmentArguments);
|
||||||
|
|
||||||
|
return tabsFragment;
|
||||||
|
}
|
||||||
|
|
||||||
private static final String TAG = TabsFragment.class.getSimpleName();
|
private static final String TAG = TabsFragment.class.getSimpleName();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user