use of org.kiwix.kiwixmobile.utils.files.FileReader in project kiwix-android by kiwix.
the class KiwixMobileActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
super.onCreate(savedInstanceState);
wifiOnly = sharedPreferenceUtil.getPrefWifiOnly();
nightMode = KiwixSettingsActivity.nightMode(sharedPreferenceUtil);
if (nightMode) {
setTheme(R.style.AppTheme_Night);
}
handleLocaleCheck();
setContentView(R.layout.main);
ButterKnife.bind(this);
setUpToolbar();
checkForRateDialog();
initPlayStoreUri();
if (SDK_INT <= VERSION_CODES.LOLLIPOP) {
snackbarLayout.setFitsSystemWindows(true);
}
isHideToolbar = sharedPreferenceUtil.getPrefHideToolbar();
FileReader fileReader = new FileReader();
documentParserJs = fileReader.readFile("js/documentParser.js", this);
newTabButton.setOnClickListener((View view) -> newTab());
tabForwardButtonContainer.setOnClickListener((View view) -> {
if (getCurrentWebView().canGoForward()) {
getCurrentWebView().goForward();
}
});
tabBackButtonContainer.setOnClickListener((View view) -> {
if (getCurrentWebView().canGoBack()) {
getCurrentWebView().goBack();
}
});
documentSections = new ArrayList<>();
tabDrawerAdapter = new TabDrawerAdapter(mWebViews);
tabDrawerLeft.setLayoutManager(new LinearLayoutManager(this));
tabDrawerLeft.setAdapter(tabDrawerAdapter);
tableDrawerRight.setLayoutManager(new LinearLayoutManager(this));
TableDrawerAdapter tableDrawerAdapter = new TableDrawerAdapter();
tableDrawerRight.setAdapter(tableDrawerAdapter);
tableDrawerAdapter.setTableClickListener(new TableClickListener() {
@Override
public void onHeaderClick(View view) {
getCurrentWebView().setScrollY(0);
drawerLayout.closeDrawer(GravityCompat.END);
}
@Override
public void onSectionClick(View view, int position) {
getCurrentWebView().loadUrl("javascript:document.getElementById('" + documentSections.get(position).id + "').scrollIntoView();");
drawerLayout.closeDrawers();
}
});
tableDrawerAdapter.notifyDataSetChanged();
tabDrawerAdapter.setTabClickListener(new TabDrawerAdapter.TabClickListener() {
@Override
public void onSelectTab(View view, int position) {
selectTab(position);
/* Bug Fix
* Issue #592 in which the navigational history of the previously open tab (WebView) was
* carried forward to the newly selected/opened tab; causing erroneous enabling of
* navigational buttons.
*/
refreshNavigationButtons();
}
@Override
public void onCloseTab(View view, int position) {
closeTab(position);
}
});
ActionBarDrawerToggle drawerToggle = new KiwixActionBarDrawerToggle(this, drawerLayout, toolbar);
drawerLayout.addDrawerListener(drawerToggle);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
drawerToggle.syncState();
compatCallback = new CompatFindActionModeCallback(this);
setUpTTS();
documentParser = new DocumentParser(new DocumentParser.SectionsListener() {
@Override
public void sectionsLoaded(String title, List<DocumentSection> sections) {
documentSections.addAll(sections);
tableDrawerAdapter.setTitle(title);
tableDrawerAdapter.setSections(documentSections);
tableDrawerAdapter.notifyDataSetChanged();
}
@Override
public void clearSections() {
documentSections.clear();
tableDrawerAdapter.notifyDataSetChanged();
}
});
manageExternalLaunchAndRestoringViewState();
setUpExitFullscreenButton();
loadPrefs();
updateTitle(ZimContentProvider.getZimFileTitle());
Intent i = getIntent();
if (i.getBooleanExtra(EXTRA_LIBRARY, false)) {
manageZimFiles(2);
}
if (i.hasExtra(TAG_FILE_SEARCHED)) {
searchForTitle(i.getStringExtra(TAG_FILE_SEARCHED));
selectTab(mWebViews.size() - 1);
}
if (i.hasExtra(EXTRA_CHOSE_X_URL)) {
newTab();
getCurrentWebView().loadUrl(i.getStringExtra(EXTRA_CHOSE_X_URL));
}
if (i.hasExtra(EXTRA_CHOSE_X_TITLE)) {
newTab();
getCurrentWebView().loadUrl(i.getStringExtra(EXTRA_CHOSE_X_TITLE));
}
if (i.hasExtra(EXTRA_ZIM_FILE)) {
File file = new File(FileUtils.getFileName(i.getStringExtra(EXTRA_ZIM_FILE)));
LibraryFragment.mService.cancelNotification(i.getIntExtra(EXTRA_NOTIFICATION_ID, 0));
Uri uri = Uri.fromFile(file);
finish();
Intent zimFile = new Intent(KiwixMobileActivity.this, KiwixMobileActivity.class);
zimFile.setData(uri);
startActivity(zimFile);
}
pageBottomTabLayout.addOnTabSelectedListener(pageBottomTabListener);
View bookmarkTabView = LayoutInflater.from(KiwixMobileActivity.this).inflate(R.layout.bookmark_tab, null);
bookmarkTabView.setOnClickListener(view -> PageBottomTab.of(4).select(pageActionTabsCallback));
bookmarkTabView.setOnLongClickListener(view -> {
PageBottomTab.of(4).longClick(pageActionTabsCallback);
return true;
});
pageBottomTabLayout.getTabAt(4).setCustomView(bookmarkTabView);
wasHideToolbar = isHideToolbar;
if (nightMode) {
backToTopAppearNightly();
} else {
backToTopAppearDaily();
}
}
Aggregations