- Implemented improved bookmarks

- Fixed undo when only one tab exists
This commit is contained in:
Elad Keyshawn 2016-04-03 21:06:37 +03:00
parent 110f7318e5
commit 423351b713
9 changed files with 197 additions and 31 deletions

View File

@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.kiwix.kiwixmobile" android:installLocation="auto"
android:versionCode="27" android:versionCode="27"
android:versionName="1.97" android:versionName="1.97"
android:installLocation="auto"> package="org.kiwix.kiwixmobile">
<supports-screens <supports-screens
android:anyDensity="true" android:anyDensity="true"
@ -27,14 +27,14 @@
android:name=".KiwixMobileActivity" android:name=".KiwixMobileActivity"
android:configChanges="orientation|keyboardHidden|screenSize|locale" android:configChanges="orientation|keyboardHidden|screenSize|locale"
android:label="@string/app_name"> android:label="@string/app_name">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN"/> <action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/> <category android:name="android.intent.category.LAUNCHER"/>
</intent-filter> </intent-filter>
<intent-filter> <intent-filter>
<action android:name="android.intent.action.VIEW"/> <action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/> <category android:name="android.intent.category.DEFAULT"/>
<data android:scheme="file"/> <data android:scheme="file"/>
@ -43,7 +43,6 @@
<data android:pathPattern=".*\\..*\\..*\\.zim(aa|)"/> <data android:pathPattern=".*\\..*\\..*\\.zim(aa|)"/>
<data android:pathPattern=".*\\..*\\..*\\..*\\.zim(aa|)"/> <data android:pathPattern=".*\\..*\\..*\\..*\\.zim(aa|)"/>
</intent-filter> </intent-filter>
<intent-filter> <intent-filter>
<action android:name="android.intent.action.VIEW"/> <action android:name="android.intent.action.VIEW"/>
@ -57,7 +56,6 @@
<data android:pathPattern=".*\\..*\\..*\\.zim(aa|)"/> <data android:pathPattern=".*\\..*\\..*\\.zim(aa|)"/>
<data android:pathPattern=".*\\..*\\..*\\..*\\.zim(aa|)"/> <data android:pathPattern=".*\\..*\\..*\\..*\\.zim(aa|)"/>
</intent-filter> </intent-filter>
<intent-filter> <intent-filter>
<action android:name="android.intent.action.VIEW"/> <action android:name="android.intent.action.VIEW"/>
@ -71,7 +69,6 @@
<data android:pathPattern=".*\\..*\\..*\\.zim(aa|)"/> <data android:pathPattern=".*\\..*\\..*\\.zim(aa|)"/>
<data android:pathPattern=".*\\..*\\..*\\..*\\.zim(aa|)"/> <data android:pathPattern=".*\\..*\\..*\\..*\\.zim(aa|)"/>
</intent-filter> </intent-filter>
<intent-filter> <intent-filter>
<action android:name="android.intent.action.VIEW"/> <action android:name="android.intent.action.VIEW"/>
@ -85,12 +82,11 @@
<data android:pathPattern=".*\\..*\\..*\\.zim(aa|)"/> <data android:pathPattern=".*\\..*\\..*\\.zim(aa|)"/>
<data android:pathPattern=".*\\..*\\..*\\..*\\.zim(aa|)"/> <data android:pathPattern=".*\\..*\\..*\\..*\\.zim(aa|)"/>
</intent-filter> </intent-filter>
</activity> </activity>
<activity <activity
android:name=".ZimFileSelectActivity" android:name=".ZimFileSelectActivity"
android:label="@string/choose_file"> android:label="@string/choose_file">
<!-- TODO --> <!-- TODO -->
<intent-filter> <intent-filter>
<action android:name="android.intent.action.GET_CONTENT"/> <action android:name="android.intent.action.GET_CONTENT"/>
@ -101,15 +97,17 @@
<data android:mimeType="*/*"/> <data android:mimeType="*/*"/>
</intent-filter> </intent-filter>
</activity> </activity>
<activity android:name=".settings.KiwixSettingsActivity"/> <activity android:name=".settings.KiwixSettingsActivity"/>
<activity android:name=".SearchActivity"/> <activity android:name=".SearchActivity"/>
<activity android:name=".views.BookmarksActivity"/>
<provider <provider
android:name=".ZimContentProvider" android:name=".ZimContentProvider"
android:authorities="org.kiwix.zim.base" android:authorities="org.kiwix.zim.base"
android:exported="true"/> android:exported="true"/>
</application> </application>
</manifest> </manifest>

View 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>

View 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>

View File

@ -15,6 +15,11 @@
android:visible="false" android:visible="false"
app:showAsAction="ifRoom"/> app:showAsAction="ifRoom"/>
<item
android:id="@+id/menu_bookmarks_list"
android:title="@string/menu_bookmarks_list"
app:showAsAction="never"/>
<item <item
android:id="@+id/menu_home" android:id="@+id/menu_home"
android:title="@string/menu_home" android:title="@string/menu_home"

View 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>

View File

@ -53,4 +53,6 @@
<string name="no_reader_application_installed">Could not find an installed application for this type of file</string> <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="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="go_to_play_store">Go to Play Store</string>
<string name="no_bookmarks">No Bookmarks!</string>
<string name="menu_bookmarks_list">Bookmarks</string>
</resources> </resources>

View File

@ -71,6 +71,7 @@ import android.widget.ListView;
import android.widget.RelativeLayout; import android.widget.RelativeLayout;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import android.widget.ToggleButton;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; 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.FileUtils;
import org.kiwix.kiwixmobile.utils.files.RateAppCounter; import org.kiwix.kiwixmobile.utils.files.RateAppCounter;
import org.kiwix.kiwixmobile.views.AnimatedProgressBar; import org.kiwix.kiwixmobile.views.AnimatedProgressBar;
import org.kiwix.kiwixmobile.views.BookmarksActivity;
import org.kiwix.kiwixmobile.views.CompatFindActionModeCallback; import org.kiwix.kiwixmobile.views.CompatFindActionModeCallback;
import org.kiwix.kiwixmobile.views.KiwixWebView; import org.kiwix.kiwixmobile.views.KiwixWebView;
public class KiwixMobileActivity extends AppCompatActivity public class KiwixMobileActivity extends AppCompatActivity
implements BookmarkDialogFragment.BookmarkDialogListener { {
public static final String TAG_KIWIX = "kiwix"; public static final String TAG_KIWIX = "kiwix";
@ -179,7 +181,7 @@ public class KiwixMobileActivity extends AppCompatActivity
private LinearLayout snackbarLayout; private LinearLayout snackbarLayout;
private RateAppCounter visitCounterPref; private RateAppCounter visitCounterPref;
private int tempVisitCount; private int tempVisitCount;
private static final int BOOKMARK_CHOSEN_REQUEST = 1;
@Override public void onActionModeStarted(ActionMode mode) { @Override public void onActionModeStarted(ActionMode mode) {
if (mActionMode == null) { if (mActionMode == null) {
mActionMode = mode; mActionMode = mode;
@ -474,9 +476,11 @@ public class KiwixMobileActivity extends AppCompatActivity
mDrawerList.setItemChecked(mCurrentWebViewIndex, true); mDrawerList.setItemChecked(mCurrentWebViewIndex, true);
} }
} else { } else {
mWebViews.remove(0); tempForUndo = mWebViews.get(index);
mCurrentWebViewIndex = 0; mWebViews.remove(index);
newTab(); newTab();
mCurrentWebViewIndex = 0;
undoSnackbar(index);
} }
mDrawerAdapter.notifyDataSetChanged(); mDrawerAdapter.notifyDataSetChanged();
} }
@ -485,9 +489,14 @@ public class KiwixMobileActivity extends AppCompatActivity
Snackbar undoSnackbar = Snackbar.make(snackbarLayout, "Tab closed", Snackbar.LENGTH_LONG) Snackbar undoSnackbar = Snackbar.make(snackbarLayout, "Tab closed", Snackbar.LENGTH_LONG)
.setAction("Undo", new View.OnClickListener() { .setAction("Undo", new View.OnClickListener() {
@Override public void onClick(View v) { @Override public void onClick(View v) {
if (index == 0)
openArticleFromBookmark(tempForUndo.getTitle());
else {
restoreTabAtIndex(tempForUndo.getUrl(), index); restoreTabAtIndex(tempForUndo.getUrl(), index);
selectTab(index); selectTab(index);
}
mDrawerLayout.openDrawer(Gravity.LEFT); mDrawerLayout.openDrawer(Gravity.LEFT);
} }
}); });
undoSnackbar.setActionTextColor(getResources().getColor(R.color.white_undo)); undoSnackbar.setActionTextColor(getResources().getColor(R.color.white_undo));
@ -537,9 +546,12 @@ public class KiwixMobileActivity extends AppCompatActivity
break; break;
case R.id.menu_bookmarks: case R.id.menu_bookmarks:
viewBookmarks(); toggleBookmark();
break; break;
case R.id.menu_bookmarks_list:
goToBookmarks();
break;
case R.id.menu_randomarticle: case R.id.menu_randomarticle:
openRandomArticle(); openRandomArticle();
break; break;
@ -572,6 +584,12 @@ public class KiwixMobileActivity extends AppCompatActivity
return super.onOptionsItemSelected(item); 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() { private void openFullScreen() {
mToolbarContainer.setVisibility(View.GONE); mToolbarContainer.setVisibility(View.GONE);
@ -609,14 +627,7 @@ public class KiwixMobileActivity extends AppCompatActivity
mIsFullscreenOpened = false; 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() { public void showWelcome() {
getCurrentWebView().loadUrl("file:///android_res/raw/welcome.html"); getCurrentWebView().loadUrl("file:///android_res/raw/welcome.html");
@ -786,20 +797,41 @@ public class KiwixMobileActivity extends AppCompatActivity
public void toggleBookmark() { public void toggleBookmark() {
String title = getCurrentWebView().getTitle(); String title = getCurrentWebView().getTitle();
boolean isBookmark;
if (title != null && !bookmarks.contains(title)) { if (title != null && !bookmarks.contains(title)) {
bookmarks.add(title); bookmarks.add(title);
isBookmark = true;
popBookmarkSnackbar(isBookmark);
} else { } else {
bookmarks.remove(title); bookmarks.remove(title);
isBookmark = false;
popBookmarkSnackbar(isBookmark);
} }
supportInvalidateOptionsMenu(); supportInvalidateOptionsMenu();
} }
public void viewBookmarks() { private void popBookmarkSnackbar(boolean isBookmark) {
new BookmarkDialogFragment(bookmarks.toArray(new String[bookmarks.size()]), if(isBookmark) {
bookmarks.contains(getCurrentWebView().getTitle())).show(getSupportFragmentManager(), Snackbar bookmarkSnackbar =
"BookmarkDialog"); 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() { private void refreshBookmarks() {
bookmarks.clear(); bookmarks.clear();
@ -1027,6 +1059,13 @@ public class KiwixMobileActivity extends AppCompatActivity
Log.e(TAG_KIWIX, KiwixMobileActivity.mPrefState.get(0).hasToBeRefreshed() + ""); Log.e(TAG_KIWIX, KiwixMobileActivity.mPrefState.get(0).hasToBeRefreshed() + "");
} }
break; break;
case BOOKMARK_CHOSEN_REQUEST:
if (resultCode == RESULT_OK){
String bookmarkChosen = data.getStringExtra("choseX");
newTab();
openArticleFromBookmark(bookmarkChosen);
}
} }
super.onActivityResult(requestCode, resultCode, data); super.onActivityResult(requestCode, resultCode, data);

View File

@ -176,7 +176,7 @@ public class ZimFileSelectActivity extends AppCompatActivity
protected void onSaveInstanceState(Bundle outState) { protected void onSaveInstanceState(Bundle outState) {
// Check, if the user has rescanned the file system, if he has, then we want to save this list, // 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()) { if (!mFiles.isEmpty()) {
Log.i(TAG_KIWIX, "Saved state of the ListView"); Log.i(TAG_KIWIX, "Saved state of the ListView");
outState.putParcelableArrayList("rescanData", mFiles); outState.putParcelableArrayList("rescanData", mFiles);

View 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();
}
}