- Implemented improved bookmarks

- TODO: make selected bookmarks greyed out
This commit is contained in:
Elad Keyshawn 2016-04-04 15:36:53 +03:00
parent 5d38e8fd39
commit 47899c2ff8
4 changed files with 18 additions and 26 deletions

View File

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_selected="true"
android:drawable="@drawable/greyed_out_selected"/>
</selector>

View File

@ -3,7 +3,8 @@
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="horizontal"> android:orientation="horizontal"
>
<TextView <TextView
android:id="@+id/bookmark_title" android:id="@+id/bookmark_title"

View File

@ -14,5 +14,5 @@
<color name="drawer_background">#ffffff</color> <color name="drawer_background">#ffffff</color>
<color name="selected_light">#0F000000</color> <color name="selected_light">#0F000000</color>
<color name="divider_light">#1E000000</color> <color name="divider_light">#1E000000</color>
<drawable name="greyed_out_selected">#BDBDBD</drawable> <color name="greyed_out_selected">#BDBDBD</color>
</resources> </resources>

View File

@ -1,11 +1,9 @@
package org.kiwix.kiwixmobile.views; package org.kiwix.kiwixmobile.views;
import android.app.Activity;
import android.content.Intent; import android.content.Intent;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.os.Bundle; import android.os.Bundle;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.util.SparseBooleanArray; import android.util.SparseBooleanArray;
import android.view.ActionMode; import android.view.ActionMode;
import android.view.Menu; import android.view.Menu;
@ -16,9 +14,7 @@ import android.widget.AbsListView;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.ListView; import android.widget.ListView;
import android.widget.Toast;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import org.kiwix.kiwixmobile.R; import org.kiwix.kiwixmobile.R;
public class BookmarksActivity extends AppCompatActivity public class BookmarksActivity extends AppCompatActivity
@ -26,9 +22,10 @@ public class BookmarksActivity extends AppCompatActivity
private ArrayList<String> contents; private ArrayList<String> contents;
private ListView bookmarksList; private ListView bookmarksList;
private ArrayAdapter<String> adapter; private ArrayAdapter adapter;
private ArrayList<String> selected; private ArrayList<String> selected;
private int numOfSelected; private int numOfSelected;
SparseBooleanArray sparseBooleanArray;
@Override protected void onCreate(Bundle savedInstanceState) { @Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@ -37,8 +34,7 @@ public class BookmarksActivity extends AppCompatActivity
contents = getIntent().getStringArrayListExtra("bookmark_contents"); contents = getIntent().getStringArrayListExtra("bookmark_contents");
selected = new ArrayList<>(); selected = new ArrayList<>();
bookmarksList = (ListView) findViewById(R.id.bookmarks_list); bookmarksList = (ListView) findViewById(R.id.bookmarks_list);
adapter = adapter = new ArrayAdapter(getApplicationContext(), R.layout.bookmarks_row, R.id.bookmark_title,
new ArrayAdapter<>(getApplicationContext(), R.layout.bookmarks_row, R.id.bookmark_title,
contents); contents);
bookmarksList.setAdapter(adapter); bookmarksList.setAdapter(adapter);
bookmarksList.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE_MODAL); bookmarksList.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE_MODAL);
@ -55,6 +51,10 @@ public class BookmarksActivity extends AppCompatActivity
numOfSelected--; numOfSelected--;
mode.setTitle(numOfSelected + " Selected"); mode.setTitle(numOfSelected + " Selected");
} }
//sparseBooleanArray = bookmarksList.getCheckedItemPositions();
//adapter.setSparse(sparseBooleanArray);
//adapter.notifyDataSetChanged();
} }
@Override public boolean onCreateActionMode(ActionMode mode, Menu menu) { @Override public boolean onCreateActionMode(ActionMode mode, Menu menu) {
@ -88,8 +88,8 @@ public class BookmarksActivity extends AppCompatActivity
} }
private void deleteSelectedItems() { private void deleteSelectedItems() {
SparseBooleanArray sparseBooleanArray = bookmarksList.getCheckedItemPositions(); sparseBooleanArray = bookmarksList.getCheckedItemPositions();
for(int i = sparseBooleanArray.size() -1; i >= 0; i--) for (int i = sparseBooleanArray.size() - 1; i >= 0; i--)
contents.remove(sparseBooleanArray.keyAt(i)); contents.remove(sparseBooleanArray.keyAt(i));
adapter.notifyDataSetChanged(); adapter.notifyDataSetChanged();
@ -105,7 +105,7 @@ public class BookmarksActivity extends AppCompatActivity
@Override public void onClick(View v) { @Override public void onClick(View v) {
Intent intent = new Intent(); Intent intent = new Intent();
intent.putExtra("bookmarks_array_list", contents); intent.putExtra("bookmarks_array_list", contents);
intent.putExtra("bookmarkClicked" , false); intent.putExtra("bookmarkClicked", false);
setResult(RESULT_OK, intent); setResult(RESULT_OK, intent);
finish(); finish();
} }
@ -116,16 +116,15 @@ public class BookmarksActivity extends AppCompatActivity
Intent intent = new Intent(); Intent intent = new Intent();
intent.putExtra("choseX", contents.get(position)); intent.putExtra("choseX", contents.get(position));
intent.putExtra("bookmarks_array_list", contents); intent.putExtra("bookmarks_array_list", contents);
intent.putExtra("bookmarkClicked" , true); intent.putExtra("bookmarkClicked", true);
setResult(RESULT_OK, intent); setResult(RESULT_OK, intent);
finish(); finish();
} }
@Override @Override public void onBackPressed() {
public void onBackPressed() {
Intent intent = new Intent(); Intent intent = new Intent();
intent.putExtra("bookmarks_array_list", contents); intent.putExtra("bookmarks_array_list", contents);
intent.putExtra("bookmarkClicked" , false); intent.putExtra("bookmarkClicked", false);
setResult(RESULT_OK, intent); setResult(RESULT_OK, intent);
finish(); finish();
super.onBackPressed(); super.onBackPressed();