Merge remote-tracking branch 'remotes/upstream/master'

# Conflicts resolved:
#	android/res/values/strings.xml
#	android/src/org/kiwix/kiwixmobile/KiwixMobileActivity.java
 Added snackbar when bookmarks removed
This commit is contained in:
Elad Keyshawn 2016-04-05 12:23:40 +03:00
parent 6373074848
commit cf3d00ad5b
3 changed files with 60 additions and 37 deletions

View File

@ -1,23 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/bookmarks_activity_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical">
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:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
>
<ListView
android:id="@+id/bookmarks_list"
@ -30,16 +34,16 @@
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:paddingTop="15dp"
android:text="@string/no_bookmarks"
android:visibility="gone"/>
android:visibility="gone"
style="@android:style/TextAppearance.Large"
/>
</RelativeLayout>
</LinearLayout>

View File

@ -12,7 +12,7 @@
android:layout_height="fill_parent"
android:layout_margin="15dp"
android:textColor="@color/material_blue_grey_900"
android:textSize="20sp"
android:textSize="15sp"
/>

View File

@ -1,6 +1,7 @@
package org.kiwix.kiwixmobile.views;
import android.content.Intent;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
@ -13,7 +14,9 @@ import android.view.View;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.Toast;
import java.util.ArrayList;
import org.kiwix.kiwixmobile.R;
@ -21,16 +24,19 @@ public class BookmarksActivity extends AppCompatActivity
implements AdapterView.OnItemClickListener {
private ArrayList<String> contents;
private ArrayList<String> tempContents;
private ListView bookmarksList;
private ArrayAdapter adapter;
private ArrayList<String> selected;
private int numOfSelected;
SparseBooleanArray sparseBooleanArray;
private LinearLayout snackbarLayout;
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_bookmarks);
setUpToolbar();
snackbarLayout = (LinearLayout) findViewById(R.id.bookmarks_activity_layout);
contents = getIntent().getStringArrayListExtra("bookmark_contents");
selected = new ArrayList<>();
bookmarksList = (ListView) findViewById(R.id.bookmarks_list);
@ -51,10 +57,6 @@ public class BookmarksActivity extends AppCompatActivity
numOfSelected--;
mode.setTitle(numOfSelected + " Selected");
}
//sparseBooleanArray = bookmarksList.getCheckedItemPositions();
//adapter.setSparse(sparseBooleanArray);
//adapter.notifyDataSetChanged();
}
@Override public boolean onCreateActionMode(ActionMode mode, Menu menu) {
@ -73,6 +75,7 @@ public class BookmarksActivity extends AppCompatActivity
switch (item.getItemId()) {
case R.id.menu_bookmarks_delete:
deleteSelectedItems();
popDeleteBookmarksSnackbar();
mode.finish();
return true;
default:
@ -87,8 +90,24 @@ public class BookmarksActivity extends AppCompatActivity
bookmarksList.setOnItemClickListener(this);
}
private void popDeleteBookmarksSnackbar() {
Snackbar bookmarkDeleteSnackbar =
Snackbar.make(snackbarLayout, numOfSelected + " deleted", Snackbar.LENGTH_LONG)
.setAction("Undo", new View.OnClickListener() {
@Override public void onClick(View v) {
contents.clear();
contents.addAll(tempContents);
adapter.notifyDataSetChanged();
Toast.makeText(getApplicationContext(), "Bookmarks restored", Toast.LENGTH_SHORT).show();
}
});
bookmarkDeleteSnackbar.setActionTextColor(getResources().getColor(R.color.white_undo));
bookmarkDeleteSnackbar.show();
}
private void deleteSelectedItems() {
sparseBooleanArray = bookmarksList.getCheckedItemPositions();
tempContents = new ArrayList<>(contents);
for (int i = sparseBooleanArray.size() - 1; i >= 0; i--)
contents.remove(sparseBooleanArray.keyAt(i));