mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-08-03 18:56:44 -04:00
- Implemented improved bookmarks
- Fixed undo when only one tab exists
This commit is contained in:
parent
110f7318e5
commit
423351b713
@ -1,9 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="org.kiwix.kiwixmobile"
|
||||
android:installLocation="auto"
|
||||
android:versionCode="27"
|
||||
android:versionName="1.97"
|
||||
android:installLocation="auto">
|
||||
package="org.kiwix.kiwixmobile">
|
||||
|
||||
<supports-screens
|
||||
android:anyDensity="true"
|
||||
@ -27,14 +27,14 @@
|
||||
android:name=".KiwixMobileActivity"
|
||||
android:configChanges="orientation|keyboardHidden|screenSize|locale"
|
||||
android:label="@string/app_name">
|
||||
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
</intent-filter>
|
||||
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW"/>
|
||||
|
||||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
|
||||
<data android:scheme="file"/>
|
||||
@ -43,7 +43,6 @@
|
||||
<data android:pathPattern=".*\\..*\\..*\\.zim(aa|)"/>
|
||||
<data android:pathPattern=".*\\..*\\..*\\..*\\.zim(aa|)"/>
|
||||
</intent-filter>
|
||||
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW"/>
|
||||
|
||||
@ -57,7 +56,6 @@
|
||||
<data android:pathPattern=".*\\..*\\..*\\.zim(aa|)"/>
|
||||
<data android:pathPattern=".*\\..*\\..*\\..*\\.zim(aa|)"/>
|
||||
</intent-filter>
|
||||
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW"/>
|
||||
|
||||
@ -71,7 +69,6 @@
|
||||
<data android:pathPattern=".*\\..*\\..*\\.zim(aa|)"/>
|
||||
<data android:pathPattern=".*\\..*\\..*\\..*\\.zim(aa|)"/>
|
||||
</intent-filter>
|
||||
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW"/>
|
||||
|
||||
@ -85,12 +82,11 @@
|
||||
<data android:pathPattern=".*\\..*\\..*\\.zim(aa|)"/>
|
||||
<data android:pathPattern=".*\\..*\\..*\\..*\\.zim(aa|)"/>
|
||||
</intent-filter>
|
||||
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name=".ZimFileSelectActivity"
|
||||
android:label="@string/choose_file">
|
||||
|
||||
<!-- TODO -->
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.GET_CONTENT"/>
|
||||
@ -101,15 +97,17 @@
|
||||
<data android:mimeType="*/*"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity android:name=".settings.KiwixSettingsActivity"/>
|
||||
|
||||
<activity android:name=".SearchActivity"/>
|
||||
<activity android:name=".views.BookmarksActivity"/>
|
||||
|
||||
<provider
|
||||
android:name=".ZimContentProvider"
|
||||
android:authorities="org.kiwix.zim.base"
|
||||
android:exported="true"/>
|
||||
|
||||
|
||||
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
|
45
res/layout/activity_bookmarks.xml
Normal file
45
res/layout/activity_bookmarks.xml
Normal file
@ -0,0 +1,45 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:orientation="vertical">
|
||||
|
||||
<android.support.v7.widget.Toolbar
|
||||
android:id="@+id/toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?actionBarSize"
|
||||
android:background="?colorPrimaryDark"
|
||||
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
|
||||
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
|
||||
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<ListView
|
||||
android:id="@+id/bookmarks_list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
/>
|
||||
|
||||
|
||||
<TextView
|
||||
android:id="@+id/bookmarks_list_nobookmarks"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
style="@android:style/TextAppearance.Large"
|
||||
android:paddingBottom="15dp"
|
||||
android:paddingTop="15dp"
|
||||
android:paddingLeft="10dp"
|
||||
android:paddingRight="10dp"
|
||||
android:text="@string/no_bookmarks"
|
||||
android:visibility="gone"/>
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
|
||||
|
||||
</LinearLayout>
|
16
res/layout/bookmarks_row.xml
Normal file
16
res/layout/bookmarks_row.xml
Normal file
@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<TextView
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:id="@+id/bookmark_title"
|
||||
android:textColor="@color/material_blue_grey_900"
|
||||
android:textSize="20sp"
|
||||
android:layout_margin="20dp"/>
|
||||
|
||||
</LinearLayout>
|
@ -15,6 +15,11 @@
|
||||
android:visible="false"
|
||||
app:showAsAction="ifRoom"/>
|
||||
|
||||
<item
|
||||
android:id="@+id/menu_bookmarks_list"
|
||||
android:title="@string/menu_bookmarks_list"
|
||||
app:showAsAction="never"/>
|
||||
|
||||
<item
|
||||
android:id="@+id/menu_home"
|
||||
android:title="@string/menu_home"
|
||||
|
6
res/values-w820dp/dimens.xml
Normal file
6
res/values-w820dp/dimens.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<resources>
|
||||
<!-- Example customization of dimensions originally defined in res/values/dimens.xml
|
||||
(such as screen margins) for screens with more than 820dp of available width. This
|
||||
would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). -->
|
||||
<dimen name="activity_horizontal_margin">64dp</dimen>
|
||||
</resources>
|
@ -53,4 +53,6 @@
|
||||
<string name="no_reader_application_installed">Could not find an installed application for this type of file</string>
|
||||
<string name="customapp_missing_content">Your application is corrupted.\nThis might happen when you remove files on the SD Card.\nYou need to uninstall then reinstall the App from the Play Store.</string>
|
||||
<string name="go_to_play_store">Go to Play Store</string>
|
||||
<string name="no_bookmarks">No Bookmarks!</string>
|
||||
<string name="menu_bookmarks_list">Bookmarks</string>
|
||||
</resources>
|
@ -71,6 +71,7 @@ import android.widget.ListView;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
import android.widget.ToggleButton;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
@ -91,11 +92,12 @@ import org.kiwix.kiwixmobile.utils.LanguageUtils;
|
||||
import org.kiwix.kiwixmobile.utils.files.FileUtils;
|
||||
import org.kiwix.kiwixmobile.utils.files.RateAppCounter;
|
||||
import org.kiwix.kiwixmobile.views.AnimatedProgressBar;
|
||||
import org.kiwix.kiwixmobile.views.BookmarksActivity;
|
||||
import org.kiwix.kiwixmobile.views.CompatFindActionModeCallback;
|
||||
import org.kiwix.kiwixmobile.views.KiwixWebView;
|
||||
|
||||
public class KiwixMobileActivity extends AppCompatActivity
|
||||
implements BookmarkDialogFragment.BookmarkDialogListener {
|
||||
{
|
||||
|
||||
public static final String TAG_KIWIX = "kiwix";
|
||||
|
||||
@ -179,7 +181,7 @@ public class KiwixMobileActivity extends AppCompatActivity
|
||||
private LinearLayout snackbarLayout;
|
||||
private RateAppCounter visitCounterPref;
|
||||
private int tempVisitCount;
|
||||
|
||||
private static final int BOOKMARK_CHOSEN_REQUEST = 1;
|
||||
@Override public void onActionModeStarted(ActionMode mode) {
|
||||
if (mActionMode == null) {
|
||||
mActionMode = mode;
|
||||
@ -474,9 +476,11 @@ public class KiwixMobileActivity extends AppCompatActivity
|
||||
mDrawerList.setItemChecked(mCurrentWebViewIndex, true);
|
||||
}
|
||||
} else {
|
||||
mWebViews.remove(0);
|
||||
mCurrentWebViewIndex = 0;
|
||||
tempForUndo = mWebViews.get(index);
|
||||
mWebViews.remove(index);
|
||||
newTab();
|
||||
mCurrentWebViewIndex = 0;
|
||||
undoSnackbar(index);
|
||||
}
|
||||
mDrawerAdapter.notifyDataSetChanged();
|
||||
}
|
||||
@ -485,9 +489,14 @@ public class KiwixMobileActivity extends AppCompatActivity
|
||||
Snackbar undoSnackbar = Snackbar.make(snackbarLayout, "Tab closed", Snackbar.LENGTH_LONG)
|
||||
.setAction("Undo", new View.OnClickListener() {
|
||||
@Override public void onClick(View v) {
|
||||
restoreTabAtIndex(tempForUndo.getUrl(), index);
|
||||
selectTab(index);
|
||||
if (index == 0)
|
||||
openArticleFromBookmark(tempForUndo.getTitle());
|
||||
else {
|
||||
restoreTabAtIndex(tempForUndo.getUrl(), index);
|
||||
selectTab(index);
|
||||
}
|
||||
mDrawerLayout.openDrawer(Gravity.LEFT);
|
||||
|
||||
}
|
||||
});
|
||||
undoSnackbar.setActionTextColor(getResources().getColor(R.color.white_undo));
|
||||
@ -537,9 +546,12 @@ public class KiwixMobileActivity extends AppCompatActivity
|
||||
break;
|
||||
|
||||
case R.id.menu_bookmarks:
|
||||
viewBookmarks();
|
||||
toggleBookmark();
|
||||
break;
|
||||
|
||||
case R.id.menu_bookmarks_list:
|
||||
goToBookmarks();
|
||||
break;
|
||||
case R.id.menu_randomarticle:
|
||||
openRandomArticle();
|
||||
break;
|
||||
@ -572,6 +584,12 @@ public class KiwixMobileActivity extends AppCompatActivity
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
private void goToBookmarks() {
|
||||
Intent intentBookmarks = new Intent(getBaseContext(), BookmarksActivity.class);
|
||||
intentBookmarks.putExtra("bookmark_contents", bookmarks.toArray(new String[0]));
|
||||
startActivityForResult(intentBookmarks, BOOKMARK_CHOSEN_REQUEST);
|
||||
}
|
||||
|
||||
private void openFullScreen() {
|
||||
|
||||
mToolbarContainer.setVisibility(View.GONE);
|
||||
@ -609,14 +627,7 @@ public class KiwixMobileActivity extends AppCompatActivity
|
||||
mIsFullscreenOpened = false;
|
||||
}
|
||||
|
||||
//These two methods are used with the BookmarkDialog.
|
||||
@Override public void onListItemSelect(String choice) {
|
||||
openArticleFromBookmark(choice);
|
||||
}
|
||||
|
||||
@Override public void onBookmarkButtonPressed() {
|
||||
toggleBookmark();
|
||||
}
|
||||
|
||||
public void showWelcome() {
|
||||
getCurrentWebView().loadUrl("file:///android_res/raw/welcome.html");
|
||||
@ -786,21 +797,42 @@ public class KiwixMobileActivity extends AppCompatActivity
|
||||
|
||||
public void toggleBookmark() {
|
||||
String title = getCurrentWebView().getTitle();
|
||||
|
||||
boolean isBookmark;
|
||||
if (title != null && !bookmarks.contains(title)) {
|
||||
bookmarks.add(title);
|
||||
isBookmark = true;
|
||||
popBookmarkSnackbar(isBookmark);
|
||||
} else {
|
||||
bookmarks.remove(title);
|
||||
isBookmark = false;
|
||||
popBookmarkSnackbar(isBookmark);
|
||||
}
|
||||
supportInvalidateOptionsMenu();
|
||||
|
||||
}
|
||||
|
||||
public void viewBookmarks() {
|
||||
new BookmarkDialogFragment(bookmarks.toArray(new String[bookmarks.size()]),
|
||||
bookmarks.contains(getCurrentWebView().getTitle())).show(getSupportFragmentManager(),
|
||||
"BookmarkDialog");
|
||||
private void popBookmarkSnackbar(boolean isBookmark) {
|
||||
if(isBookmark) {
|
||||
Snackbar bookmarkSnackbar =
|
||||
Snackbar.make(snackbarLayout, "Bookmark added", Snackbar.LENGTH_LONG)
|
||||
.setAction("Open", new View.OnClickListener() {
|
||||
@Override public void onClick(View v) {
|
||||
goToBookmarks();
|
||||
}
|
||||
});
|
||||
bookmarkSnackbar.setActionTextColor(getResources().getColor(R.color.white_undo));
|
||||
bookmarkSnackbar.show();
|
||||
}
|
||||
else{
|
||||
Snackbar bookmarkSnackbar =
|
||||
Snackbar.make(snackbarLayout, "Bookmark removed", Snackbar.LENGTH_LONG);
|
||||
bookmarkSnackbar.show();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void refreshBookmarks() {
|
||||
bookmarks.clear();
|
||||
if (ZimContentProvider.getId() != null) {
|
||||
@ -1027,6 +1059,13 @@ public class KiwixMobileActivity extends AppCompatActivity
|
||||
Log.e(TAG_KIWIX, KiwixMobileActivity.mPrefState.get(0).hasToBeRefreshed() + "");
|
||||
}
|
||||
break;
|
||||
|
||||
case BOOKMARK_CHOSEN_REQUEST:
|
||||
if (resultCode == RESULT_OK){
|
||||
String bookmarkChosen = data.getStringExtra("choseX");
|
||||
newTab();
|
||||
openArticleFromBookmark(bookmarkChosen);
|
||||
}
|
||||
}
|
||||
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
|
@ -176,7 +176,7 @@ public class ZimFileSelectActivity extends AppCompatActivity
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
|
||||
// Check, if the user has rescanned the file system, if he has, then we want to save this list,
|
||||
// so this can be shown again, if the actvitity is recreated (on a device rotation for example)
|
||||
// so this can be shown again, if the activity is recreated (on a device rotation for example)
|
||||
if (!mFiles.isEmpty()) {
|
||||
Log.i(TAG_KIWIX, "Saved state of the ListView");
|
||||
outState.putParcelableArrayList("rescanData", mFiles);
|
||||
|
55
src/org/kiwix/kiwixmobile/views/BookmarksActivity.java
Normal file
55
src/org/kiwix/kiwixmobile/views/BookmarksActivity.java
Normal file
@ -0,0 +1,55 @@
|
||||
package org.kiwix.kiwixmobile.views;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ListView;
|
||||
import android.widget.Toast;
|
||||
import java.util.ArrayList;
|
||||
import org.kiwix.kiwixmobile.R;
|
||||
|
||||
public class BookmarksActivity extends AppCompatActivity
|
||||
implements AdapterView.OnItemClickListener {
|
||||
|
||||
private String[] contents;
|
||||
private ListView bookmarksList;
|
||||
|
||||
@Override protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_bookmarks);
|
||||
setUpToolbar();
|
||||
contents = getIntent().getStringArrayExtra("bookmark_contents");
|
||||
bookmarksList = (ListView) findViewById(R.id.bookmarks_list);
|
||||
ArrayAdapter<String> adapter =
|
||||
new ArrayAdapter<>(getApplicationContext(),R.layout.bookmarks_row,R.id.bookmark_title, contents);
|
||||
bookmarksList.setAdapter(adapter);
|
||||
bookmarksList.setOnItemClickListener(this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private void setUpToolbar() {
|
||||
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
toolbar.setTitle(getResources().getString(R.string.menu_bookmarks_list));
|
||||
setSupportActionBar(toolbar);
|
||||
getSupportActionBar().setHomeButtonEnabled(true);
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
|
||||
@Override public void onClick(View v) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
Intent intent = new Intent();
|
||||
intent.putExtra("choseX",contents[position]);
|
||||
setResult(RESULT_OK, intent);
|
||||
finish();
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user