1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-05 19:42:17 +02:00

catalog icons and sorting

This commit is contained in:
Dmitry Yuranov 2013-06-20 19:45:52 +04:00
parent ea6ac35fad
commit 57dc898a7a
6 changed files with 160 additions and 52 deletions

View file

@ -1,14 +1,14 @@
* SHORT-TERM (1.8.3)
+ check recently added catalogs are not lost (and are visible) after update
+ newly added catalog is not checked in filter activity
+ use language filter to detect visible catalogs on first start
** add catalog icons
** order catalogs alphabetically
+ extract litres API to a separate branch
+ check recently added catalogs are not lost (and are visible) after update
+ newly added catalog is not checked in filter activity
+ use language filter to detect visible catalogs on first start
+ add catalog icons
+ order catalogs alphabetically
+ extract litres API to a separate branch
** add RSS catalog
+ hardcoded strings ("Active/Inactive catalogs", may be some else?) => en.xml
+ "Library filter" => "All catalogs"
+ NetworkLibraryFilterActivity => AllCatalogsActivity
+ hardcoded strings ("Active/Inactive catalogs", may be some else?) => en.xml
+ "Library filter" => "All catalogs"
+ NetworkLibraryFilterActivity => AllCatalogsActivity
** make a separate branch for catalogs + master
** copyrights in all files

View file

@ -11,7 +11,16 @@
android:id="@+id/check_item"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
/>
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:adjustViewBounds="false"
android:paddingLeft="5dp"
android:paddingRight="5dp"
/>
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >

View file

@ -2,11 +2,14 @@ package org.geometerplus.android.fbreader.network;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.TreeSet;
import org.geometerplus.android.fbreader.covers.CoverManager;
import org.geometerplus.fbreader.network.INetworkLink;
import org.geometerplus.fbreader.network.NetworkLibrary;
import org.geometerplus.fbreader.network.NetworkTree;
import org.geometerplus.fbreader.network.urlInfo.UrlInfo;
import org.geometerplus.fbreader.network.tree.NetworkCatalogRootTree;
import org.geometerplus.zlibrary.ui.android.R;
import android.app.Activity;
@ -18,17 +21,20 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
public class AllCatalogsActivity extends Activity {
final NetworkLibrary library = NetworkLibrary.Instance();
CheckListAdapter myAdapter;
ArrayList<String> ids = new ArrayList<String>();
ArrayList<String> allids = new ArrayList<String>();
ArrayList<String> inactiveIds = new ArrayList<String>();
public final static String IDS_LIST = "org.geometerplus.android.fbreader.network.IDS_LIST";
public final static String ALL_IDS_LIST = "org.geometerplus.android.fbreader.network.ALL_IDS_LIST";
public final static String INACTIVE_IDS_LIST = "org.geometerplus.android.fbreader.network.INACTIVE_IDS_LIST";
private boolean isChanged = false;
@Override
protected void onCreate(Bundle icicle) {
@ -38,27 +44,38 @@ public class AllCatalogsActivity extends Activity {
Intent intent = getIntent();
ids = intent.getStringArrayListExtra(IDS_LIST);
allids = intent.getStringArrayListExtra(ALL_IDS_LIST);
inactiveIds = intent.getStringArrayListExtra(INACTIVE_IDS_LIST);
}
@Override
protected void onStart() {
super.onStart();
ArrayList<CheckItem> idItems = new ArrayList<CheckItem>();
idItems.add(new CheckSection(getLabelByKey("active")));
for(String i : ids){
idItems.add(new CheckItem(i, true));
if(ids.size() > 0){
idItems.add(new CheckSection(getLabelByKey("active")));
// sort codes
final TreeSet<CheckItem> items = new TreeSet<CheckItem>();
for(String i : ids){
items.add(new CheckItem(i, true, library.getCatalogTreeByUrlAll(i)));
}
for (CheckItem i : items) {
idItems.add(i);
System.out.println("-- "+i.getTree().getTreeTitle());
}
}
if(allids.size() > 0){
if(inactiveIds.size() > 0){
idItems.add(new CheckSection(getLabelByKey("inactive")));
for(String i : allids){
idItems.add(new CheckItem(i, false));
for(String i : inactiveIds){
idItems.add(new CheckItem(i, false, library.getCatalogTreeByUrlAll(i)));
}
}
ListView selectedList = (ListView) findViewById(R.id.selectedList);
myAdapter = new CheckListAdapter(this, R.layout.checkbox_item, idItems);
myAdapter = new CheckListAdapter(this, R.layout.checkbox_item, idItems, this);
selectedList.setAdapter(myAdapter);
}
@ -80,22 +97,33 @@ public class AllCatalogsActivity extends Activity {
@Override
protected void onStop() {
super.onStop();
ArrayList<String> ids = new ArrayList<String>();
ArrayList<CheckItem> items = myAdapter.getItems();
for(CheckItem item : items){
if(!item.isSection() && item.isChecked()){
ids.add(item.getId());
if(isChanged){
ArrayList<String> ids = new ArrayList<String>();
ArrayList<CheckItem> items = myAdapter.getItems();
for(CheckItem item : items){
if(!item.isSection() && item.isChecked()){
ids.add(item.getId());
}
}
library.setActiveIds(ids);
library.synchronize();
}
library.setActiveIds(ids);
library.synchronize();
}
private class CheckItem{
private class CheckItem implements Comparable<CheckItem>{
private String myId;
private boolean isChecked;
NetworkTree myTree = null;
public CheckItem(String id, boolean checked, NetworkTree tree){
myId = id;
isChecked = checked;
if(tree instanceof NetworkCatalogRootTree){
myTree = tree;
}else{
System.out.println("Tree parameter should be an instance of NetworkCatalogRootTree");
}
}
public CheckItem(String id, boolean checked){
myId = id;
@ -106,6 +134,18 @@ public class AllCatalogsActivity extends Activity {
return myId;
}
public NetworkTree getTree(){
return myTree;
}
public String getTitle(){
return myTree.getLink().getTitle();
}
public String getTitleLower(){
return getTitle().toLowerCase(Locale.getDefault());
}
public boolean isChecked(){
return isChecked;
}
@ -117,6 +157,11 @@ public class AllCatalogsActivity extends Activity {
public boolean isSection(){
return false;
}
@Override
public int compareTo(CheckItem another) {
return getTitleLower().compareTo(another.getTitleLower());
}
}
private class CheckSection extends CheckItem{
@ -129,11 +174,13 @@ public class AllCatalogsActivity extends Activity {
}
private class CheckListAdapter extends ArrayAdapter<CheckItem> {
Activity myActivity;
private CoverManager myCoverManager;
private ArrayList<CheckItem> items = new ArrayList<CheckItem>();
public CheckListAdapter(Context context, int textViewResourceId, List<CheckItem> objects) {
public CheckListAdapter(Context context, int textViewResourceId, List<CheckItem> objects, Activity activity) {
super(context, textViewResourceId, objects);
myActivity = activity;
items.addAll(objects);
}
@ -145,46 +192,61 @@ public class AllCatalogsActivity extends Activity {
public View getView(int position, View convertView, final ViewGroup parent) {
View v = convertView;
CheckItem item = this.getItem(position);
if (item != null) {
if(item.isSection()){
LayoutInflater vi;
vi = LayoutInflater.from(getContext());
v = vi.inflate(R.layout.checkbox_section, null);
LayoutInflater vi;
vi = LayoutInflater.from(getContext());
v = vi.inflate(R.layout.checkbox_section, null);
TextView tt = (TextView) v.findViewById(R.id.title);
if (tt != null) {
tt.setText(item.getId());
}
}else{
if (myCoverManager == null) {
v.measure(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
final int coverHeight = v.getMeasuredHeight();
myCoverManager = new CoverManager(myActivity, coverHeight * 15 / 12, coverHeight);
v.requestLayout();
}
LayoutInflater vi;
vi = LayoutInflater.from(getContext());
v = vi.inflate(R.layout.checkbox_item, null);
INetworkLink link = library.getLinkByUrl(item.getId());
if(link != null){
TextView tt = (TextView) v.findViewById(R.id.title);
NetworkTree t = item.getTree();
if(t != null){
INetworkLink link = t.getLink();
TextView tt = (TextView)v.findViewById(R.id.title);
if (tt != null) {
tt.setText(link.getTitle());
}
tt = (TextView) v.findViewById(R.id.subtitle);
tt = (TextView)v.findViewById(R.id.subtitle);
if (tt != null) {
tt.setText(link.getSummary());
}
CheckBox ch = (CheckBox) v.findViewById(R.id.check_item);
ImageView coverView = (ImageView)v.findViewById(R.id.icon);
if (!myCoverManager.trySetCoverImage(coverView, t)) {
coverView.setImageResource(R.drawable.ic_list_library_books);
}
CheckBox ch = (CheckBox)v.findViewById(R.id.check_item);
if (ch != null) {
ch.setText("");
ch.setChecked(item.isChecked());
ch.setTag(item);
ch.setOnClickListener( new View.OnClickListener() {
public void onClick(View v) {
CheckBox cb = (CheckBox) v;
CheckBox cb = (CheckBox)v;
CheckItem checkedItem = (CheckItem) cb.getTag();
if(checkedItem != null){
checkedItem.setChecked(cb.isChecked());
}
isChanged = true;
}
});
}

View file

@ -5,10 +5,8 @@ import java.util.List;
import org.geometerplus.android.fbreader.OrientationUtil;
import org.geometerplus.android.fbreader.network.AllCatalogsActivity;
import org.geometerplus.android.fbreader.tree.TreeActivity;
import org.geometerplus.fbreader.network.*;
import org.geometerplus.fbreader.network.urlInfo.UrlInfo;
import org.geometerplus.zlibrary.core.language.Language;
import org.geometerplus.fbreader.network.NetworkLibrary;
import org.geometerplus.fbreader.network.NetworkTree;
import android.app.Activity;
import android.content.Intent;
@ -27,7 +25,7 @@ public class AllCatalogsAction extends RootAction {
ArrayList<String> ids = new ArrayList<String>();
ids.addAll(activeIds);
final ArrayList<String> allids = new ArrayList<String>();
final ArrayList<String> inactiveIds = new ArrayList<String>();
boolean found = false;
for(String id : library.linkIds()){
for(String aid : activeIds){
@ -37,7 +35,7 @@ public class AllCatalogsAction extends RootAction {
}
}
if(!found){
allids.add(id);
inactiveIds.add(id);
}
found = false;
}
@ -46,7 +44,7 @@ public class AllCatalogsAction extends RootAction {
myActivity,
new Intent(myActivity.getApplicationContext(), AllCatalogsActivity.class)
.putStringArrayListExtra(AllCatalogsActivity.IDS_LIST, ids)
.putStringArrayListExtra(AllCatalogsActivity.ALL_IDS_LIST, allids)
.putStringArrayListExtra(AllCatalogsActivity.INACTIVE_IDS_LIST, inactiveIds)
);
}

View file

@ -158,6 +158,7 @@ public abstract class TreeActivity<T extends FBTree> extends ListActivity {
setTitle(myCurrentTree.getTreeTitle());
final FBTree selectedTree =
selectedKey != null ? getTreeByKey(selectedKey) : adapter.getFirstSelectedItem();
final int index = adapter.getIndex(selectedTree);
if (index != -1) {
setSelection(index);

View file

@ -263,6 +263,19 @@ public class NetworkLibrary {
}
return null;
}
public NetworkTree getCatalogTreeByUrlAll(String url) {
for (FBTree tree : getRootAllTree().subTrees()) {
if (tree instanceof NetworkCatalogRootTree) {
final String cUrl =
((NetworkCatalogTree)tree).getLink().getUrlInfo(UrlInfo.Type.Catalog).Url;
if (url.equals(cUrl)) {
return (NetworkTree)tree;
}
}
}
return null;
}
public INetworkLink getLinkBySiteName(String siteName) {
synchronized (myLinks) {
@ -275,6 +288,7 @@ public class NetworkLibrary {
return null;
}
private final RootTree myRootAllTree = new RootTree("@AllRoot", false);
private final RootTree myRootTree = new RootTree("@Root", false);
private final RootTree myFakeRootTree = new RootTree("@FakeRoot", true);
@ -415,6 +429,23 @@ public class NetworkLibrary {
public void invalidateVisibility() {
myUpdateVisibility = true;
}
private void makeUpToDateRootAll() {
myRootAllTree.clear();
synchronized (myLinks) {
for (INetworkLink link : myLinks) {
int index = 0;
for (FBTree t : myRootAllTree.subTrees()) {
final INetworkLink l = ((NetworkTree)t).getLink();
if (l != null && link.compareTo(l) <= 0) {
break;
}
++index;
}
new NetworkCatalogRootTree(myRootAllTree, link, index);
}
}
}
private void makeUpToDate() {
updateActiveIds();
@ -422,7 +453,7 @@ public class NetworkLibrary {
final SortedSet<INetworkLink> linkSet = new TreeSet<INetworkLink>(activeLinks());
final LinkedList<FBTree> toRemove = new LinkedList<FBTree>();
// we do remove sum tree items:
for (FBTree t : myRootTree.subTrees()) {
if (t instanceof NetworkCatalogTree) {
@ -459,10 +490,12 @@ public class NetworkLibrary {
if (l != null && link.compareTo(l) <= 0) {
break;
}
++index;
}
new NetworkCatalogRootTree(myRootTree, link, index);
}
// we do add non-catalog items
new SearchCatalogTree(myRootTree, mySearchItem, 0);
new AddCustomCatalogItemTree(myRootTree);
@ -501,6 +534,7 @@ public class NetworkLibrary {
if (myChildrenAreInvalid) {
myChildrenAreInvalid = false;
makeUpToDate();
makeUpToDateRootAll();
}
if (myUpdateVisibility) {
myUpdateVisibility = false;
@ -511,6 +545,10 @@ public class NetworkLibrary {
public NetworkTree getRootTree() {
return myRootTree;
}
public NetworkTree getRootAllTree() {
return myRootAllTree;
}
public NetworkBookTree getFakeBookTree(NetworkBookItem book) {
final String id = book.getStringId();