Using butterknife to bind views in fragments
This commit is contained in:
parent
89caf33f46
commit
5f8470c577
@ -45,10 +45,6 @@ import acr.browser.lightning.utils.Utils;
|
|||||||
*/
|
*/
|
||||||
public class BrowserDialog {
|
public class BrowserDialog {
|
||||||
|
|
||||||
public interface Listener {
|
|
||||||
void onClick();
|
|
||||||
}
|
|
||||||
|
|
||||||
public interface EditorListener {
|
public interface EditorListener {
|
||||||
void onClick(String text);
|
void onClick(String text);
|
||||||
}
|
}
|
||||||
@ -58,12 +54,12 @@ public class BrowserDialog {
|
|||||||
private final int mTitle;
|
private final int mTitle;
|
||||||
private boolean mCondition = true;
|
private boolean mCondition = true;
|
||||||
|
|
||||||
public Item(@StringRes int title, boolean condition) {
|
Item(@StringRes int title, boolean condition) {
|
||||||
this(title);
|
this(title);
|
||||||
mCondition = condition;
|
mCondition = condition;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Item(@StringRes int title) {
|
protected Item(@StringRes int title) {
|
||||||
mTitle = title;
|
mTitle = title;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,6 +56,8 @@ import acr.browser.lightning.dialog.LightningDialogBuilder;
|
|||||||
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;
|
||||||
|
import butterknife.Bind;
|
||||||
|
import butterknife.ButterKnife;
|
||||||
|
|
||||||
public class BookmarksFragment extends Fragment implements View.OnClickListener, View.OnLongClickListener, BookmarksView {
|
public class BookmarksFragment extends Fragment implements View.OnClickListener, View.OnLongClickListener, BookmarksView {
|
||||||
|
|
||||||
@ -90,8 +92,9 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
|
|||||||
private final List<HistoryItem> mBookmarks = new ArrayList<>();
|
private final List<HistoryItem> mBookmarks = new ArrayList<>();
|
||||||
|
|
||||||
// Views
|
// Views
|
||||||
private ListView mBookmarksListView;
|
@Bind(R.id.right_drawer_list) ListView mBookmarksListView;
|
||||||
private ImageView mBookmarkTitleImage, mBookmarkImage;
|
@Bind(R.id.starIcon) ImageView mBookmarkTitleImage;
|
||||||
|
@Bind(R.id.icon_star) ImageView mBookmarkImage;
|
||||||
|
|
||||||
// Colors
|
// Colors
|
||||||
private int mIconColor, mScrollIndex;
|
private int mIconColor, mScrollIndex;
|
||||||
@ -126,7 +129,7 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
|
|||||||
mWebpageBitmap = ThemeUtils.getThemedBitmap(context, R.drawable.ic_webpage, darkTheme);
|
mWebpageBitmap = ThemeUtils.getThemedBitmap(context, R.drawable.ic_webpage, darkTheme);
|
||||||
mFolderBitmap = ThemeUtils.getThemedBitmap(context, R.drawable.ic_folder, darkTheme);
|
mFolderBitmap = ThemeUtils.getThemedBitmap(context, R.drawable.ic_folder, darkTheme);
|
||||||
mIconColor = darkTheme ? ThemeUtils.getIconDarkThemeColor(context) :
|
mIconColor = darkTheme ? ThemeUtils.getIconDarkThemeColor(context) :
|
||||||
ThemeUtils.getIconLightThemeColor(context);
|
ThemeUtils.getIconLightThemeColor(context);
|
||||||
|
|
||||||
mFaviconModel = new FaviconModel();
|
mFaviconModel = new FaviconModel();
|
||||||
}
|
}
|
||||||
@ -173,12 +176,10 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
|
|||||||
@Override
|
@Override
|
||||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
final View view = inflater.inflate(R.layout.bookmark_drawer, container, false);
|
final View view = inflater.inflate(R.layout.bookmark_drawer, container, false);
|
||||||
mBookmarksListView = (ListView) view.findViewById(R.id.right_drawer_list);
|
ButterKnife.bind(this, view);
|
||||||
mBookmarksListView.setOnItemClickListener(mItemClickListener);
|
mBookmarksListView.setOnItemClickListener(mItemClickListener);
|
||||||
mBookmarksListView.setOnItemLongClickListener(mItemLongClickListener);
|
mBookmarksListView.setOnItemLongClickListener(mItemLongClickListener);
|
||||||
mBookmarkTitleImage = (ImageView) view.findViewById(R.id.starIcon);
|
|
||||||
mBookmarkTitleImage.setColorFilter(mIconColor, PorterDuff.Mode.SRC_IN);
|
mBookmarkTitleImage.setColorFilter(mIconColor, PorterDuff.Mode.SRC_IN);
|
||||||
mBookmarkImage = (ImageView) view.findViewById(R.id.icon_star);
|
|
||||||
final View backView = view.findViewById(R.id.bookmark_back_button);
|
final View backView = view.findViewById(R.id.bookmark_back_button);
|
||||||
backView.setOnClickListener(new View.OnClickListener() {
|
backView.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
@ -195,16 +196,22 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
|
|||||||
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())
|
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) {
|
||||||
mBookmarksListView.setAdapter(mBookmarkAdapter);
|
mBookmarksListView.setAdapter(mBookmarkAdapter);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroyView() {
|
||||||
|
super.onDestroyView();
|
||||||
|
ButterKnife.unbind(this);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStart() {
|
public void onStart() {
|
||||||
super.onStart();
|
super.onStart();
|
||||||
@ -226,7 +233,7 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
|
|||||||
mWebpageBitmap = ThemeUtils.getThemedBitmap(activity, R.drawable.ic_webpage, darkTheme);
|
mWebpageBitmap = ThemeUtils.getThemedBitmap(activity, R.drawable.ic_webpage, darkTheme);
|
||||||
mFolderBitmap = ThemeUtils.getThemedBitmap(activity, R.drawable.ic_folder, darkTheme);
|
mFolderBitmap = ThemeUtils.getThemedBitmap(activity, R.drawable.ic_folder, darkTheme);
|
||||||
mIconColor = darkTheme ? ThemeUtils.getIconDarkThemeColor(activity) :
|
mIconColor = darkTheme ? ThemeUtils.getIconDarkThemeColor(activity) :
|
||||||
ThemeUtils.getIconLightThemeColor(activity);
|
ThemeUtils.getIconLightThemeColor(activity);
|
||||||
|
|
||||||
mFaviconModel = new FaviconModel();
|
mFaviconModel = new FaviconModel();
|
||||||
}
|
}
|
||||||
@ -407,20 +414,20 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
|
|||||||
final WeakReference<ImageView> imageViewReference = new WeakReference<>(holder.favicon);
|
final WeakReference<ImageView> imageViewReference = new WeakReference<>(holder.favicon);
|
||||||
|
|
||||||
mFaviconModel.faviconForUrl(url, mWebpageBitmap, true)
|
mFaviconModel.faviconForUrl(url, mWebpageBitmap, true)
|
||||||
.subscribeOn(Schedulers.worker())
|
.subscribeOn(Schedulers.worker())
|
||||||
.observeOn(Schedulers.main())
|
.observeOn(Schedulers.main())
|
||||||
.subscribe(new SingleOnSubscribe<Bitmap>() {
|
.subscribe(new SingleOnSubscribe<Bitmap>() {
|
||||||
@Override
|
@Override
|
||||||
public void onItem(@Nullable Bitmap item) {
|
public void onItem(@Nullable Bitmap item) {
|
||||||
ImageView imageView = imageViewReference.get();
|
ImageView imageView = imageViewReference.get();
|
||||||
Object tag = imageView != null ? imageView.getTag() : null;
|
Object tag = imageView != null ? imageView.getTag() : null;
|
||||||
if (tag != null && tag.equals(url.hashCode())) {
|
if (tag != null && tag.equals(url.hashCode())) {
|
||||||
imageView.setImageBitmap(item);
|
imageView.setImageBitmap(item);
|
||||||
}
|
|
||||||
|
|
||||||
web.setBitmap(item);
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
web.setBitmap(item);
|
||||||
|
}
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
holder.favicon.setImageBitmap(web.getBitmap());
|
holder.favicon.setImageBitmap(web.getBitmap());
|
||||||
}
|
}
|
||||||
|
@ -48,6 +48,8 @@ import acr.browser.lightning.utils.ThemeUtils;
|
|||||||
import acr.browser.lightning.utils.Utils;
|
import acr.browser.lightning.utils.Utils;
|
||||||
import acr.browser.lightning.view.BackgroundDrawable;
|
import acr.browser.lightning.view.BackgroundDrawable;
|
||||||
import acr.browser.lightning.view.LightningView;
|
import acr.browser.lightning.view.LightningView;
|
||||||
|
import butterknife.Bind;
|
||||||
|
import butterknife.ButterKnife;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A fragment that holds and manages the tabs and interaction with the tabs.
|
* A fragment that holds and manages the tabs and interaction with the tabs.
|
||||||
@ -74,7 +76,8 @@ public class TabsFragment extends Fragment implements View.OnClickListener, View
|
|||||||
|
|
||||||
@Nullable private LightningViewAdapter mTabsAdapter;
|
@Nullable private LightningViewAdapter mTabsAdapter;
|
||||||
private UIController mUiController;
|
private UIController mUiController;
|
||||||
private RecyclerView mRecyclerView;
|
|
||||||
|
@Bind(R.id.tabs_list) RecyclerView mRecyclerView;
|
||||||
|
|
||||||
private TabsManager mTabsManager;
|
private TabsManager mTabsManager;
|
||||||
@Inject Bus mBus;
|
@Inject Bus mBus;
|
||||||
@ -126,7 +129,9 @@ public class TabsFragment extends Fragment implements View.OnClickListener, View
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
mRecyclerView = (RecyclerView) view.findViewById(R.id.tabs_list);
|
|
||||||
|
ButterKnife.bind(this, view);
|
||||||
|
|
||||||
SimpleItemAnimator animator;
|
SimpleItemAnimator animator;
|
||||||
if (mShowInNavigationDrawer) {
|
if (mShowInNavigationDrawer) {
|
||||||
animator = new VerticalItemAnimator();
|
animator = new VerticalItemAnimator();
|
||||||
@ -144,9 +149,17 @@ public class TabsFragment extends Fragment implements View.OnClickListener, View
|
|||||||
mTabsAdapter = new LightningViewAdapter(mShowInNavigationDrawer);
|
mTabsAdapter = new LightningViewAdapter(mShowInNavigationDrawer);
|
||||||
mRecyclerView.setAdapter(mTabsAdapter);
|
mRecyclerView.setAdapter(mTabsAdapter);
|
||||||
mRecyclerView.setHasFixedSize(true);
|
mRecyclerView.setHasFixedSize(true);
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroyView() {
|
||||||
|
super.onDestroyView();
|
||||||
|
ButterKnife.unbind(this);
|
||||||
|
mTabsAdapter = null;
|
||||||
|
}
|
||||||
|
|
||||||
private TabsManager getTabsManager() {
|
private TabsManager getTabsManager() {
|
||||||
if (mTabsManager == null) {
|
if (mTabsManager == null) {
|
||||||
mTabsManager = mUiController.getTabModel();
|
mTabsManager = mUiController.getTabModel();
|
||||||
@ -163,12 +176,6 @@ public class TabsFragment extends Fragment implements View.OnClickListener, View
|
|||||||
buttonImage.setColorFilter(mIconColor, PorterDuff.Mode.SRC_IN);
|
buttonImage.setColorFilter(mIconColor, PorterDuff.Mode.SRC_IN);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDestroyView() {
|
|
||||||
super.onDestroyView();
|
|
||||||
mTabsAdapter = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStart() {
|
public void onStart() {
|
||||||
super.onStart();
|
super.onStart();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user