mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-20 10:23:30 -04:00
+ Fix bookmark displaying icon issue
This commit is contained in:
parent
8d20e52e38
commit
6fa08794fe
@ -14,13 +14,6 @@
|
||||
android:visible="false"
|
||||
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
|
||||
android:id="@+id/menu_bookmarks"
|
||||
android:icon="@drawable/action_bookmarks"
|
||||
@ -48,12 +41,19 @@
|
||||
android:icon="@drawable/device_access_sd_storage"
|
||||
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
|
||||
android:id="@+id/menu_searchintext"
|
||||
android:icon="@drawable/action_search"
|
||||
android:title="@string/menu_searchintext"
|
||||
android:visible="false"
|
||||
android:showAsAction="ifRoom"/>
|
||||
android:showAsAction="never"/>
|
||||
|
||||
<item
|
||||
android:id="@+id/menu_fullscreen"
|
||||
|
@ -1,52 +1,62 @@
|
||||
package org.kiwix.kiwixmobile;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
|
||||
@SuppressLint("ValidFragment")
|
||||
public class BookmarkDialog extends DialogFragment {
|
||||
private BookmarkDialogListener listen;
|
||||
private String[] contents;
|
||||
private boolean isBookmarked;
|
||||
public BookmarkDialog(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();
|
||||
}
|
||||
}
|
||||
package org.kiwix.kiwixmobile;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
|
||||
@SuppressLint("ValidFragment")
|
||||
public class BookmarkDialog extends DialogFragment {
|
||||
private BookmarkDialogListener listen;
|
||||
private String[] contents;
|
||||
private boolean isBookmarked;
|
||||
public BookmarkDialog(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();
|
||||
}
|
||||
}
|
||||
|
@ -672,9 +672,10 @@ public class KiwixMobileFragment extends SherlockFragment {
|
||||
public void onPrepareOptionsMenu(Menu menu) {
|
||||
super.onPrepareOptionsMenu(menu);
|
||||
|
||||
if (webView.getTitle() == null || ZimContentProvider.getPageUrlFromTitle(webView.getTitle()) == null) {
|
||||
menu.findItem(R.id.menu_bookmarks).setVisible(false);
|
||||
} else {
|
||||
if (menu.findItem(R.id.menu_bookmarks) != null &&
|
||||
webView.getUrl() != null &&
|
||||
webView.getUrl() != "file:///android_res/raw/help.html" &&
|
||||
ZimContentProvider.getId() != null) {
|
||||
menu.findItem(R.id.menu_bookmarks).setVisible(true);
|
||||
if (bookmarks.contains(webView.getTitle())) {
|
||||
menu.findItem(R.id.menu_bookmarks).setIcon(R.drawable.action_bookmarks_active);
|
||||
@ -862,13 +863,13 @@ public class KiwixMobileFragment extends SherlockFragment {
|
||||
|
||||
public void toggleBookmark() {
|
||||
String title = webView.getTitle();
|
||||
|
||||
if (title!=null && !bookmarks.contains(title)){
|
||||
bookmarks.add(title);
|
||||
} else {
|
||||
bookmarks.remove(title);
|
||||
}
|
||||
|
||||
getActivity().invalidateOptionsMenu();
|
||||
getSherlockActivity().supportInvalidateOptionsMenu();
|
||||
}
|
||||
|
||||
public void viewBookmarks() {
|
||||
@ -877,7 +878,8 @@ public class KiwixMobileFragment extends SherlockFragment {
|
||||
|
||||
private void refreshBookmarks() {
|
||||
bookmarks.clear();
|
||||
if (ZimContentProvider.getId()!=null) try {
|
||||
if (ZimContentProvider.getId()!=null) {
|
||||
try {
|
||||
InputStream stream = getActivity().openFileInput(ZimContentProvider.getId()+".txt");
|
||||
String in;
|
||||
if (stream!= null) {
|
||||
@ -887,12 +889,12 @@ public class KiwixMobileFragment extends SherlockFragment {
|
||||
}
|
||||
Log.d("Kiwix", "Switched to bookmarkfile "+ZimContentProvider.getId());
|
||||
}
|
||||
}
|
||||
catch (FileNotFoundException e) {
|
||||
} catch (FileNotFoundException e) {
|
||||
Log.e("kiwix", "File not found: " + e.toString());
|
||||
} catch (IOException e) {
|
||||
Log.e("kiwix", "Can not read file: " + e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void saveBookmarks() {
|
||||
@ -924,15 +926,13 @@ public class KiwixMobileFragment extends SherlockFragment {
|
||||
// hideSearchBar();
|
||||
webView.loadUrl(Uri.parse(ZimContentProvider.CONTENT_URI
|
||||
+ articleUrl).toString());
|
||||
return true;
|
||||
|
||||
} else {
|
||||
String errorString = String.format(getResources().getString(R.string.error_articlenotfound),
|
||||
articleSearchtextView.getText().toString());
|
||||
Toast.makeText(getActivity().getWindow().getContext(), errorString, Toast.LENGTH_SHORT).show();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean openArticleFromSearch() {
|
||||
@ -1100,6 +1100,12 @@ public class KiwixMobileFragment extends SherlockFragment {
|
||||
getActivity().setProgress(progress * 100);
|
||||
}
|
||||
|
||||
if (progress > 20) {
|
||||
if (getSherlockActivity() != null) {
|
||||
getSherlockActivity().supportInvalidateOptionsMenu();
|
||||
}
|
||||
}
|
||||
|
||||
if (progress == 100) {
|
||||
|
||||
Log.d(TAG_KIWIX, "Loading article finished.");
|
||||
@ -1116,6 +1122,7 @@ public class KiwixMobileFragment extends SherlockFragment {
|
||||
ToggleNightMode();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user