+ Fix bookmark displaying icon issue

This commit is contained in:
Kelson42 2014-10-09 00:51:02 +02:00
parent 8d20e52e38
commit 6fa08794fe
3 changed files with 89 additions and 72 deletions

View File

@ -14,13 +14,6 @@
android:visible="false" android:visible="false"
android:showAsAction="ifRoom"/> android:showAsAction="ifRoom"/>
<item
android:id="@+id/menu_forward"
android:title="@string/menu_forward"
android:icon="@drawable/navigation_forward"
android:visible="false"
android:showAsAction="ifRoom"/>
<item <item
android:id="@+id/menu_bookmarks" android:id="@+id/menu_bookmarks"
android:icon="@drawable/action_bookmarks" android:icon="@drawable/action_bookmarks"
@ -48,12 +41,19 @@
android:icon="@drawable/device_access_sd_storage" android:icon="@drawable/device_access_sd_storage"
android:showAsAction="ifRoom"/> android:showAsAction="ifRoom"/>
<item
android:id="@+id/menu_forward"
android:title="@string/menu_forward"
android:icon="@drawable/navigation_forward"
android:visible="false"
android:showAsAction="never"/>
<item <item
android:id="@+id/menu_searchintext" android:id="@+id/menu_searchintext"
android:icon="@drawable/action_search" android:icon="@drawable/action_search"
android:title="@string/menu_searchintext" android:title="@string/menu_searchintext"
android:visible="false" android:visible="false"
android:showAsAction="ifRoom"/> android:showAsAction="never"/>
<item <item
android:id="@+id/menu_fullscreen" android:id="@+id/menu_fullscreen"

View File

@ -14,37 +14,47 @@ public class BookmarkDialog extends DialogFragment {
private String[] contents; private String[] contents;
private boolean isBookmarked; private boolean isBookmarked;
public BookmarkDialog(String[] contents, boolean isBookmarked){ public BookmarkDialog(String[] contents, boolean isBookmarked){
this.contents=contents; this.contents = contents;
this.isBookmarked=isBookmarked; this.isBookmarked = isBookmarked;
} }
public Dialog onCreateDialog(Bundle savedInstanceState){ public Dialog onCreateDialog(Bundle savedInstanceState){
AlertDialog.Builder build = new AlertDialog.Builder(getActivity()); AlertDialog.Builder build = new AlertDialog.Builder(getActivity());
//build.setTitle(R.string.menu_bookmarks); //build.setTitle(R.string.menu_bookmarks);
String buttonText; String buttonText;
if(isBookmarked)buttonText=getResources().getString(R.string.remove_bookmark); if (isBookmarked) {
else buttonText=getResources().getString(R.string.add_bookmark); buttonText = getResources().getString(R.string.remove_bookmark);
if(contents.length!=0)build.setItems(contents, new DialogInterface.OnClickListener() { } 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) { public void onClick(DialogInterface dialog, int choice) {
listen.onListItemSelect(contents[choice]); listen.onListItemSelect(contents[choice]);
} }
}); });
}
build.setNeutralButton(buttonText, new DialogInterface.OnClickListener() { build.setNeutralButton(buttonText, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int choice) { public void onClick(DialogInterface dialog, int choice) {
listen.onBookmarkButtonPressed(); listen.onBookmarkButtonPressed();
} }
}); });
return build.create(); return build.create();
} }
@Override @Override
public void onAttach(Activity a){ public void onAttach(Activity a) {
super.onAttach(a); super.onAttach(a);
try{ try {
listen=(BookmarkDialogListener)a; listen=(BookmarkDialogListener)a;
}catch(ClassCastException e){ } catch (ClassCastException e){
throw new ClassCastException(a.toString() throw new ClassCastException(a.toString()
+ " must implement BookmarkDialogListener"); + " must implement BookmarkDialogListener");
} }
} }
public interface BookmarkDialogListener{ public interface BookmarkDialogListener{
public void onListItemSelect(String choice); public void onListItemSelect(String choice);
public void onBookmarkButtonPressed(); public void onBookmarkButtonPressed();

View File

@ -672,9 +672,10 @@ public class KiwixMobileFragment extends SherlockFragment {
public void onPrepareOptionsMenu(Menu menu) { public void onPrepareOptionsMenu(Menu menu) {
super.onPrepareOptionsMenu(menu); super.onPrepareOptionsMenu(menu);
if (webView.getTitle() == null || ZimContentProvider.getPageUrlFromTitle(webView.getTitle()) == null) { if (menu.findItem(R.id.menu_bookmarks) != null &&
menu.findItem(R.id.menu_bookmarks).setVisible(false); webView.getUrl() != null &&
} else { webView.getUrl() != "file:///android_res/raw/help.html" &&
ZimContentProvider.getId() != null) {
menu.findItem(R.id.menu_bookmarks).setVisible(true); menu.findItem(R.id.menu_bookmarks).setVisible(true);
if (bookmarks.contains(webView.getTitle())) { if (bookmarks.contains(webView.getTitle())) {
menu.findItem(R.id.menu_bookmarks).setIcon(R.drawable.action_bookmarks_active); menu.findItem(R.id.menu_bookmarks).setIcon(R.drawable.action_bookmarks_active);
@ -862,13 +863,13 @@ public class KiwixMobileFragment extends SherlockFragment {
public void toggleBookmark() { public void toggleBookmark() {
String title = webView.getTitle(); String title = webView.getTitle();
if (title!=null && !bookmarks.contains(title)){ if (title!=null && !bookmarks.contains(title)){
bookmarks.add(title); bookmarks.add(title);
} else { } else {
bookmarks.remove(title); bookmarks.remove(title);
} }
getSherlockActivity().supportInvalidateOptionsMenu();
getActivity().invalidateOptionsMenu();
} }
public void viewBookmarks() { public void viewBookmarks() {
@ -877,7 +878,8 @@ public class KiwixMobileFragment extends SherlockFragment {
private void refreshBookmarks() { private void refreshBookmarks() {
bookmarks.clear(); bookmarks.clear();
if (ZimContentProvider.getId()!=null) try { if (ZimContentProvider.getId()!=null) {
try {
InputStream stream = getActivity().openFileInput(ZimContentProvider.getId()+".txt"); InputStream stream = getActivity().openFileInput(ZimContentProvider.getId()+".txt");
String in; String in;
if (stream!= null) { if (stream!= null) {
@ -887,13 +889,13 @@ public class KiwixMobileFragment extends SherlockFragment {
} }
Log.d("Kiwix", "Switched to bookmarkfile "+ZimContentProvider.getId()); Log.d("Kiwix", "Switched to bookmarkfile "+ZimContentProvider.getId());
} }
} } catch (FileNotFoundException e) {
catch (FileNotFoundException e) {
Log.e("kiwix", "File not found: " + e.toString()); Log.e("kiwix", "File not found: " + e.toString());
} catch (IOException e) { } catch (IOException e) {
Log.e("kiwix", "Can not read file: " + e.toString()); Log.e("kiwix", "Can not read file: " + e.toString());
} }
} }
}
private void saveBookmarks() { private void saveBookmarks() {
try { try {
@ -924,16 +926,14 @@ public class KiwixMobileFragment extends SherlockFragment {
// hideSearchBar(); // hideSearchBar();
webView.loadUrl(Uri.parse(ZimContentProvider.CONTENT_URI webView.loadUrl(Uri.parse(ZimContentProvider.CONTENT_URI
+ articleUrl).toString()); + articleUrl).toString());
return true;
} else { } else {
String errorString = String.format(getResources().getString(R.string.error_articlenotfound), String errorString = String.format(getResources().getString(R.string.error_articlenotfound),
articleSearchtextView.getText().toString()); articleSearchtextView.getText().toString());
Toast.makeText(getActivity().getWindow().getContext(), errorString, Toast.LENGTH_SHORT).show(); Toast.makeText(getActivity().getWindow().getContext(), errorString, Toast.LENGTH_SHORT).show();
}
return true; return true;
} }
}
private boolean openArticleFromSearch() { private boolean openArticleFromSearch() {
Log.d(TAG_KIWIX, "openArticleFromSearch: " + articleSearchtextView.getText()); Log.d(TAG_KIWIX, "openArticleFromSearch: " + articleSearchtextView.getText());
@ -1100,6 +1100,12 @@ public class KiwixMobileFragment extends SherlockFragment {
getActivity().setProgress(progress * 100); getActivity().setProgress(progress * 100);
} }
if (progress > 20) {
if (getSherlockActivity() != null) {
getSherlockActivity().supportInvalidateOptionsMenu();
}
}
if (progress == 100) { if (progress == 100) {
Log.d(TAG_KIWIX, "Loading article finished."); Log.d(TAG_KIWIX, "Loading article finished.");
@ -1116,6 +1122,7 @@ public class KiwixMobileFragment extends SherlockFragment {
ToggleNightMode(); ToggleNightMode();
} }
} }
} }
} }