From cc1c75e2c91a88ef222745dabb20e47170dd00f4 Mon Sep 17 00:00:00 2001 From: mhutti1 Date: Sat, 9 Apr 2016 21:45:47 +0100 Subject: [PATCH] Possible fix for #19 --- .../kiwixmobile/BookmarkDialogFragment.java | 69 ------------------- .../kiwix/kiwixmobile/utils/HTMLUtils.java | 36 +++++----- 2 files changed, 20 insertions(+), 85 deletions(-) delete mode 100644 src/org/kiwix/kiwixmobile/BookmarkDialogFragment.java diff --git a/src/org/kiwix/kiwixmobile/BookmarkDialogFragment.java b/src/org/kiwix/kiwixmobile/BookmarkDialogFragment.java deleted file mode 100644 index c1108c3be..000000000 --- a/src/org/kiwix/kiwixmobile/BookmarkDialogFragment.java +++ /dev/null @@ -1,69 +0,0 @@ -package org.kiwix.kiwixmobile; - -import android.annotation.SuppressLint; -import android.app.Activity; -import android.app.AlertDialog; -import android.app.Dialog; -import android.content.DialogInterface; -import android.os.Bundle; -import android.support.v4.app.DialogFragment; - -@SuppressLint("ValidFragment") -public class BookmarkDialogFragment extends DialogFragment { - - private BookmarkDialogListener listen; - - private String[] contents; - - private boolean isBookmarked; - - public BookmarkDialogFragment(String[] contents, boolean isBookmarked) { - this.contents = contents; - this.isBookmarked = isBookmarked; - } - - public Dialog onCreateDialog(Bundle savedInstanceState) { - AlertDialog.Builder build = new AlertDialog.Builder(getActivity()); - //build.setTitle(R.string.menu_bookmarks); - String buttonText; - if (isBookmarked) { - buttonText = getResources().getString(R.string.remove_bookmark); - } else { - buttonText = getResources().getString(R.string.add_bookmark); - } - - if (contents.length != 0) { - build.setItems(contents, new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int choice) { - listen.onListItemSelect(contents[choice]); - } - }); - } - - build.setNeutralButton(buttonText, new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int choice) { - listen.onBookmarkButtonPressed(); - } - }); - - return build.create(); - } - - @Override - public void onAttach(Activity a) { - super.onAttach(a); - try { - listen = (BookmarkDialogListener) a; - } catch (ClassCastException e) { - throw new ClassCastException(a.toString() - + " must implement BookmarkDialogListener"); - } - } - - public interface BookmarkDialogListener { - - public void onListItemSelect(String choice); - - public void onBookmarkButtonPressed(); - } -} diff --git a/src/org/kiwix/kiwixmobile/utils/HTMLUtils.java b/src/org/kiwix/kiwixmobile/utils/HTMLUtils.java index 2dac5221a..683f94e37 100644 --- a/src/org/kiwix/kiwixmobile/utils/HTMLUtils.java +++ b/src/org/kiwix/kiwixmobile/utils/HTMLUtils.java @@ -50,22 +50,26 @@ public class HTMLUtils { @Override public void run() { if (element.equals("H1")) { - mRightListView.removeHeaderView(headerView); - LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); - View view = inflater.inflate(R.layout.section_list, null); - headerView = (TextView) view.findViewById(R.id.textTab); - headerView.setText(sectionTitle); - headerView.setPadding((int) (26 * context.getResources().getDisplayMetrics().density), 0, 0, 0); - headerView.setBackgroundColor(Color.LTGRAY); - headerView.setTypeface(Typeface.DEFAULT_BOLD); - headerView.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - context.getCurrentWebView().setScrollY(0); - context.mRightDrawerLayout.closeDrawer(Gravity.RIGHT); - } - }); - mRightListView.addHeaderView(headerView); + if (mRightListView.getHeaderViewsCount() == 0) { + mRightListView.removeHeaderView(headerView); + LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); + View view = inflater.inflate(R.layout.section_list, null); + headerView = (TextView) view.findViewById(R.id.textTab); + headerView.setText(sectionTitle); + headerView.setPadding((int) (26 * context.getResources().getDisplayMetrics().density), 0, 0, 0); + headerView.setBackgroundColor(Color.LTGRAY); + headerView.setTypeface(Typeface.DEFAULT_BOLD); + headerView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + context.getCurrentWebView().setScrollY(0); + context.mRightDrawerLayout.closeDrawer(Gravity.RIGHT); + } + }); + mRightListView.addHeaderView(headerView); + } else { + headerView.setText(sectionTitle); + } } else { textViews.add(i, new TextView(context)); sectionProperties.add(i, new KiwixMobileActivity.SectionProperties());