use of de.baumann.browser.database.RecordAction.STARTSITE_ITEM in project browser by scoute-dich.
the class BrowserActivity method initOverview.
// Views
@SuppressLint("ClickableViewAccessibility")
private void initOverview() {
bottomSheetDialog_OverView = findViewById(R.id.bottomSheetDialog_OverView);
ListView listView = bottomSheetDialog_OverView.findViewById(R.id.list_overView);
tab_container = bottomSheetDialog_OverView.findViewById(R.id.listOpenedTabs);
AtomicInteger intPage = new AtomicInteger();
NavigationBarView.OnItemSelectedListener navListener = menuItem -> {
if (menuItem.getItemId() == R.id.page_1) {
tab_container.setVisibility(View.GONE);
listView.setVisibility(View.VISIBLE);
omniBox_overview.setImageResource(R.drawable.icon_web);
overViewTab = getString(R.string.album_title_home);
intPage.set(R.id.page_1);
RecordAction action = new RecordAction(context);
action.open(false);
final List<Record> list = action.listStartSite(activity);
action.close();
adapter = new AdapterRecord(context, list);
listView.setAdapter(adapter);
adapter.notifyDataSetChanged();
listView.setOnItemClickListener((parent, view, position, id) -> {
if (list.get(position).getType() == BOOKMARK_ITEM || list.get(position).getType() == STARTSITE_ITEM) {
if (list.get(position).getDesktopMode() != ninjaWebView.isDesktopMode())
ninjaWebView.toggleDesktopMode(false);
if (list.get(position).getNightMode() == ninjaWebView.isNightMode() && !isNightMode) {
ninjaWebView.toggleNightMode();
isNightMode = ninjaWebView.isNightMode();
}
}
ninjaWebView.loadUrl(list.get(position).getURL());
hideOverview();
});
listView.setOnItemLongClickListener((parent, view, position, id) -> {
showContextMenuList(list.get(position).getTitle(), list.get(position).getURL(), adapter, list, position);
return true;
});
} else if (menuItem.getItemId() == R.id.page_2) {
tab_container.setVisibility(View.GONE);
listView.setVisibility(View.VISIBLE);
omniBox_overview.setImageResource(R.drawable.icon_bookmark);
overViewTab = getString(R.string.album_title_bookmarks);
intPage.set(R.id.page_2);
RecordAction action = new RecordAction(context);
action.open(false);
final List<Record> list;
list = action.listBookmark(activity, filter, filterBy);
action.close();
adapter = new AdapterRecord(context, list);
listView.setAdapter(adapter);
adapter.notifyDataSetChanged();
filter = false;
listView.setOnItemClickListener((parent, view, position, id) -> {
if (list.get(position).getType() == BOOKMARK_ITEM || list.get(position).getType() == STARTSITE_ITEM) {
if (list.get(position).getDesktopMode() != ninjaWebView.isDesktopMode())
ninjaWebView.toggleDesktopMode(false);
if (list.get(position).getNightMode() == ninjaWebView.isNightMode() && !isNightMode) {
ninjaWebView.toggleNightMode();
isNightMode = ninjaWebView.isNightMode();
}
}
ninjaWebView.loadUrl(list.get(position).getURL());
hideOverview();
});
listView.setOnItemLongClickListener((parent, view, position, id) -> {
showContextMenuList(list.get(position).getTitle(), list.get(position).getURL(), adapter, list, position);
return true;
});
} else if (menuItem.getItemId() == R.id.page_3) {
tab_container.setVisibility(View.GONE);
listView.setVisibility(View.VISIBLE);
omniBox_overview.setImageResource(R.drawable.icon_history);
overViewTab = getString(R.string.album_title_history);
intPage.set(R.id.page_3);
RecordAction action = new RecordAction(context);
action.open(false);
final List<Record> list;
list = action.listHistory();
action.close();
// noinspection NullableProblems
adapter = new AdapterRecord(context, list) {
@Override
public View getView(int position, View convertView, @NonNull ViewGroup parent) {
View v = super.getView(position, convertView, parent);
TextView record_item_time = v.findViewById(R.id.dateView);
record_item_time.setVisibility(View.VISIBLE);
TextView record_item_title = v.findViewById(R.id.titleView);
record_item_title.setPadding(0, 0, 150, 0);
return v;
}
};
listView.setAdapter(adapter);
adapter.notifyDataSetChanged();
listView.setOnItemClickListener((parent, view, position, id) -> {
if (list.get(position).getType() == BOOKMARK_ITEM || list.get(position).getType() == STARTSITE_ITEM) {
if (list.get(position).getDesktopMode() != ninjaWebView.isDesktopMode())
ninjaWebView.toggleDesktopMode(false);
if (list.get(position).getNightMode() == ninjaWebView.isNightMode() && !isNightMode) {
ninjaWebView.toggleNightMode();
isNightMode = ninjaWebView.isNightMode();
}
}
ninjaWebView.loadUrl(list.get(position).getURL());
hideOverview();
});
listView.setOnItemLongClickListener((parent, view, position, id) -> {
showContextMenuList(list.get(position).getTitle(), list.get(position).getURL(), adapter, list, position);
return true;
});
} else if (menuItem.getItemId() == R.id.page_4) {
PopupMenu popup = new PopupMenu(this, bottom_navigation.findViewById(R.id.page_2));
if (bottom_navigation.getSelectedItemId() == R.id.page_1)
popup.inflate(R.menu.menu_list_start);
else if (bottom_navigation.getSelectedItemId() == R.id.page_2)
popup.inflate(R.menu.menu_list_bookmark);
else if (bottom_navigation.getSelectedItemId() == R.id.page_3)
popup.inflate(R.menu.menu_list_history);
else if (bottom_navigation.getSelectedItemId() == R.id.page_0)
popup.inflate(R.menu.menu_list_tabs);
popup.setOnMenuItemClickListener(item -> {
if (item.getItemId() == R.id.menu_delete) {
MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(context);
builder.setIcon(R.drawable.icon_alert);
builder.setTitle(R.string.menu_delete);
builder.setMessage(R.string.hint_database);
builder.setPositiveButton(R.string.app_ok, (dialog, whichButton) -> {
if (overViewTab.equals(getString(R.string.album_title_home))) {
BrowserUnit.clearHome(context);
bottom_navigation.setSelectedItemId(R.id.page_1);
} else if (overViewTab.equals(getString(R.string.album_title_bookmarks))) {
BrowserUnit.clearBookmark(context);
bottom_navigation.setSelectedItemId(R.id.page_2);
} else if (overViewTab.equals(getString(R.string.album_title_history))) {
BrowserUnit.clearHistory(context);
bottom_navigation.setSelectedItemId(R.id.page_3);
}
});
builder.setNegativeButton(R.string.app_cancel, (dialog, whichButton) -> dialog.cancel());
AlertDialog dialog = builder.create();
dialog.show();
HelperUnit.setupDialog(context, dialog);
} else if (item.getItemId() == R.id.menu_sortName) {
if (overViewTab.equals(getString(R.string.album_title_bookmarks))) {
sp.edit().putString("sort_bookmark", "title").apply();
bottom_navigation.setSelectedItemId(R.id.page_2);
} else if (overViewTab.equals(getString(R.string.album_title_home))) {
sp.edit().putString("sort_startSite", "title").apply();
bottom_navigation.setSelectedItemId(R.id.page_1);
}
} else if (item.getItemId() == R.id.menu_sortIcon) {
sp.edit().putString("sort_bookmark", "time").apply();
bottom_navigation.setSelectedItemId(R.id.page_2);
} else if (item.getItemId() == R.id.menu_sortDate) {
sp.edit().putString("sort_startSite", "ordinal").apply();
bottom_navigation.setSelectedItemId(R.id.page_1);
} else if (item.getItemId() == R.id.menu_filter) {
showDialogFilter();
} else if (item.getItemId() == R.id.menu_help) {
Uri webpage = Uri.parse("https://github.com/scoute-dich/browser/wiki/Overview");
BrowserUnit.intentURL(this, webpage);
}
return true;
});
popup.show();
popup.setOnDismissListener(v -> {
if (intPage.intValue() == R.id.page_1)
bottom_navigation.setSelectedItemId(R.id.page_1);
else if (intPage.intValue() == R.id.page_2)
bottom_navigation.setSelectedItemId(R.id.page_2);
else if (intPage.intValue() == R.id.page_3)
bottom_navigation.setSelectedItemId(R.id.page_3);
else if (intPage.intValue() == R.id.page_0)
bottom_navigation.setSelectedItemId(R.id.page_0);
});
} else if (menuItem.getItemId() == R.id.page_0) {
intPage.set(R.id.page_0);
tab_container.setVisibility(View.VISIBLE);
listView.setVisibility(View.GONE);
}
return true;
};
bottom_navigation = bottomSheetDialog_OverView.findViewById(R.id.bottom_navigation);
bottom_navigation.setOnItemSelectedListener(navListener);
bottom_navigation.findViewById(R.id.page_2).setOnLongClickListener(v -> {
showDialogFilter();
return true;
});
setSelectedTab();
}
Aggregations