Search in sources :

Example 1 with FileReader

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();
    }
}
Also used : DocumentParser(org.kiwix.kiwixmobile.utils.DocumentParser) ActionBarDrawerToggle(android.support.v7.app.ActionBarDrawerToggle) Intent(android.content.Intent) TableClickListener(org.kiwix.kiwixmobile.TableDrawerAdapter.TableClickListener) SpannableString(android.text.SpannableString) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) ImageView(android.widget.ImageView) ToolbarScrollingKiwixWebView(org.kiwix.kiwixmobile.views.web.ToolbarScrollingKiwixWebView) RecyclerView(android.support.v7.widget.RecyclerView) BindView(butterknife.BindView) ActionMenuItemView(android.support.v7.view.menu.ActionMenuItemView) View(android.view.View) WebView(android.webkit.WebView) KiwixWebView(org.kiwix.kiwixmobile.views.web.KiwixWebView) ToolbarStaticKiwixWebView(org.kiwix.kiwixmobile.views.web.ToolbarStaticKiwixWebView) Uri(android.net.Uri) FileReader(org.kiwix.kiwixmobile.utils.files.FileReader) ArrayList(java.util.ArrayList) List(java.util.List) CompatFindActionModeCallback(org.kiwix.kiwixmobile.views.CompatFindActionModeCallback) File(java.io.File)

Aggregations

Intent (android.content.Intent)1 Uri (android.net.Uri)1 ActionBarDrawerToggle (android.support.v7.app.ActionBarDrawerToggle)1 ActionMenuItemView (android.support.v7.view.menu.ActionMenuItemView)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 SpannableString (android.text.SpannableString)1 View (android.view.View)1 WebView (android.webkit.WebView)1 ImageView (android.widget.ImageView)1 BindView (butterknife.BindView)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 TableClickListener (org.kiwix.kiwixmobile.TableDrawerAdapter.TableClickListener)1 DocumentParser (org.kiwix.kiwixmobile.utils.DocumentParser)1 FileReader (org.kiwix.kiwixmobile.utils.files.FileReader)1 CompatFindActionModeCallback (org.kiwix.kiwixmobile.views.CompatFindActionModeCallback)1 KiwixWebView (org.kiwix.kiwixmobile.views.web.KiwixWebView)1 ToolbarScrollingKiwixWebView (org.kiwix.kiwixmobile.views.web.ToolbarScrollingKiwixWebView)1