diff --git a/res/layout/content_header.xml b/res/layout/content_header.xml new file mode 100644 index 000000000..06cb9c0e5 --- /dev/null +++ b/res/layout/content_header.xml @@ -0,0 +1,17 @@ + + \ No newline at end of file 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/KiwixMobileActivity.java b/src/org/kiwix/kiwixmobile/KiwixMobileActivity.java index 9f62ee763..699984b36 100644 --- a/src/org/kiwix/kiwixmobile/KiwixMobileActivity.java +++ b/src/org/kiwix/kiwixmobile/KiwixMobileActivity.java @@ -214,6 +214,8 @@ public class KiwixMobileActivity extends AppCompatActivity { private int tempVisitCount; + public static TextView headerView; + @Override public void onActionModeStarted(ActionMode mode) { if (mActionMode == null) { @@ -333,6 +335,24 @@ public class KiwixMobileActivity extends AppCompatActivity { mRightDrawerList = (ListView) findViewById(R.id.right_drawer_list); mRightDrawerList.setDivider(null); mRightDrawerList.setDividerHeight(0); + + + LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); + View view = inflater.inflate(R.layout.content_header, null); + headerView = (TextView) view.findViewById(R.id.contentHeader); + headerView.setText(R.string.no_section_info); + headerView.setPadding((int) (26 * 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) { + getCurrentWebView().setScrollY(0); + mRightDrawerLayout.closeDrawer(Gravity.RIGHT); + } + }); + mRightDrawerList.addHeaderView(headerView); + mRightDrawerList.setAdapter(mRightArrayAdapter); TextView tView = (TextView) findViewById(R.id.empty); mRightDrawerList.setEmptyView(tView); diff --git a/src/org/kiwix/kiwixmobile/utils/HTMLUtils.java b/src/org/kiwix/kiwixmobile/utils/HTMLUtils.java index 2dac5221a..6c0be7e06 100644 --- a/src/org/kiwix/kiwixmobile/utils/HTMLUtils.java +++ b/src/org/kiwix/kiwixmobile/utils/HTMLUtils.java @@ -1,20 +1,16 @@ package org.kiwix.kiwixmobile.utils; -import android.content.Context; import android.graphics.Color; import android.graphics.Typeface; import android.os.Handler; -import android.view.Gravity; -import android.view.LayoutInflater; -import android.view.View; import android.webkit.JavascriptInterface; import android.webkit.WebView; import android.widget.ArrayAdapter; +import android.widget.HeaderViewListAdapter; import android.widget.ListView; import android.widget.TextView; import java.util.List; import org.kiwix.kiwixmobile.KiwixMobileActivity; -import org.kiwix.kiwixmobile.R; public class HTMLUtils { @@ -23,14 +19,11 @@ public class HTMLUtils { private ArrayAdapter arrayAdapter; private KiwixMobileActivity context; private Handler mHandler; - private ListView mRightListView; - private TextView headerView; public HTMLUtils(List sectionProperties, List textViews, ListView listView, KiwixMobileActivity context, Handler handler) { this.sectionProperties = sectionProperties; this.textViews = textViews; - this.mRightListView = listView; - this.arrayAdapter = (ArrayAdapter) listView.getAdapter(); + this.arrayAdapter = ((ArrayAdapter)((HeaderViewListAdapter)listView.getAdapter()).getWrappedAdapter()); this.context = context; this.mHandler = handler; } @@ -50,22 +43,7 @@ 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); + KiwixMobileActivity.headerView.setText(sectionTitle); } else { textViews.add(i, new TextView(context)); sectionProperties.add(i, new KiwixMobileActivity.SectionProperties());