45 {
46 super.onCreate(savedInstanceState);
47 binding = HomeBinding.inflate(getLayoutInflater());
48 setContentView(binding.getRoot());
49
50 long heapSize = Runtime.getRuntime().maxMemory();
51 Log.i(TAG, "Max HeapSize: " + heapSize);
52 Log.i(TAG, "App data folder: " + getFilesDir().toString());
53
54
55 Intent caller = getIntent();
56 Uri callParameter = caller.getData();
57
58 if (Intent.ACTION_VIEW.equals(caller.getAction()) && callParameter != null)
59 {
60 String refStr = ConnectionReference.getFileReference(callParameter.getPath());
61 Bundle bundle = new Bundle();
62 bundle.putString(BookmarkActivity.PARAM_CONNECTION_REFERENCE, refStr);
63
64 Intent bookmarkIntent =
65 new Intent(this.getApplicationContext(), BookmarkActivity.class);
66 bookmarkIntent.putExtras(bundle);
67 startActivity(bookmarkIntent);
68 }
69
70 viewModel = new ViewModelProvider(this).get(HomeViewModel.class);
71
72 bookmarkListAdapter = new BookmarkListAdapter();
73 bookmarkListAdapter.setCallbacks(new BookmarkListAdapter.Callbacks() {
74 @Override public void onItemClick(String refStr)
75 {
76 if (ConnectionReference.isBookmarkReference(refStr) ||
77 ConnectionReference.isHostnameReference(refStr))
78 {
79 Bundle bundle = new Bundle();
80 bundle.putString(SessionActivity.PARAM_CONNECTION_REFERENCE, refStr);
81
82 Intent sessionIntent = new Intent(HomeActivity.this, SessionActivity.class);
83 sessionIntent.putExtras(bundle);
84 startActivity(sessionIntent);
85
86 if (searchView != null)
87 {
88 searchView.setQuery("", false);
89 searchView.setIconified(true);
90 }
91 if (searchMenuItem != null)
92 {
93 searchMenuItem.collapseActionView();
94 }
95 viewModel.loadBookmarks("");
96 }
97 }
98
99 @Override public void onDelete(long id)
100 {
101 viewModel.deleteBookmark(id);
102 }
103 });
104
105 binding.recyclerViewBookmarks.setLayoutManager(new LinearLayoutManager(this));
106 binding.recyclerViewBookmarks.setAdapter(bookmarkListAdapter);
107
108 viewModel.getBookmarks().observe(this,
109 bookmarks -> bookmarkListAdapter.setItems(bookmarks));
110
111
112 if (savedInstanceState != null)
113 {
114 String query = savedInstanceState.getString(PARAM_SEARCH_QUERY);
115 if (query != null && !query.isEmpty() && viewModel.getCurrentQuery().isEmpty())
116 {
117 viewModel.loadBookmarks(query);
118 }
119 }
120
121 getOnBackPressedDispatcher().addCallback(this, new OnBackPressedCallback(true) {
122 @Override public void handleOnBackPressed()
123 {
124 if (ApplicationSettingsActivity.getAskOnExit(HomeActivity.this))
125 {
126 new AlertDialog.Builder(HomeActivity.this)
127 .setTitle(R.string.dlg_title_exit)
128 .setMessage(R.string.dlg_msg_exit)
129 .setPositiveButton(R.string.yes, (dialog, which) -> finish())
130 .setNegativeButton(R.string.no, (dialog, which) -> dialog.dismiss())
131 .show();
132 }
133 else
134 {
135 finish();
136 }
137 }
138 });
139 }