1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-03 09:49:19 +02:00

formatting

This commit is contained in:
Nikolay Pultsin 2013-09-15 13:44:45 +01:00
parent 0cb1180467
commit e8695cf6f2
4 changed files with 67 additions and 73 deletions

View file

@ -1,23 +1,20 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout
xmlns:tools="http://schemas.android.com/tools" xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="horizontal" android:orientation="horizontal"
android:paddingTop="6dp" android:paddingTop="6dp"
android:paddingBottom="6dp"> android:paddingBottom="6dp"
>
<TextView <TextView
android:id="@+id/title" android:id="@+id/title"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:paddingLeft="10dp" android:paddingLeft="10dp"
android:singleLine="true" android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceMedium" android:textAppearance="?android:attr/textAppearanceMedium"
android:ellipsize="marquee" android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"/> android:marqueeRepeatLimit="marquee_forever"
/>
</LinearLayout> </LinearLayout>

View file

@ -1,12 +1,13 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout
android:layout_width="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent" android:layout_width="fill_parent"
android:orientation="vertical" > android:layout_height="match_parent"
android:orientation="vertical"
>
<ListView android:id="@+id/selectedList" <ListView
android:layout_width="fill_parent" android:id="@+id/selectedList"
android:layout_height="wrap_content" /> android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout> </LinearLayout>

View file

@ -33,35 +33,33 @@ import org.geometerplus.fbreader.network.*;
import org.geometerplus.fbreader.network.tree.NetworkCatalogRootTree; import org.geometerplus.fbreader.network.tree.NetworkCatalogRootTree;
import org.geometerplus.android.fbreader.covers.CoverManager; import org.geometerplus.android.fbreader.covers.CoverManager;
public class AllCatalogsActivity extends Activity { public class AllCatalogsActivity extends Activity {
final NetworkLibrary library = NetworkLibrary.Instance(); final NetworkLibrary library = NetworkLibrary.Instance();
CheckListAdapter myAdapter; CheckListAdapter myAdapter;
ArrayList<String> ids = new ArrayList<String>(); ArrayList<String> ids = new ArrayList<String>();
ArrayList<String> inactiveIds = 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 IDS_LIST = "org.geometerplus.android.fbreader.network.IDS_LIST";
public final static String INACTIVE_IDS_LIST = "org.geometerplus.android.fbreader.network.INACTIVE_IDS_LIST"; public final static String INACTIVE_IDS_LIST = "org.geometerplus.android.fbreader.network.INACTIVE_IDS_LIST";
private boolean isChanged = false; private boolean isChanged = false;
@Override @Override
protected void onCreate(Bundle icicle) { protected void onCreate(Bundle icicle) {
super.onCreate(icicle); super.onCreate(icicle);
setContentView(R.layout.network_library_filter); setContentView(R.layout.network_library_filter);
Intent intent = getIntent(); Intent intent = getIntent();
ids = intent.getStringArrayListExtra(IDS_LIST); ids = intent.getStringArrayListExtra(IDS_LIST);
inactiveIds = intent.getStringArrayListExtra(INACTIVE_IDS_LIST); inactiveIds = intent.getStringArrayListExtra(INACTIVE_IDS_LIST);
} }
@Override @Override
protected void onStart() { protected void onStart() {
super.onStart(); super.onStart();
ArrayList<CheckItem> idItems = new ArrayList<CheckItem>(); ArrayList<CheckItem> idItems = new ArrayList<CheckItem>();
if(ids.size() > 0){ if(ids.size() > 0){
idItems.add(new CheckSection(getLabelByKey("active"))); idItems.add(new CheckSection(getLabelByKey("active")));
@ -76,34 +74,34 @@ public class AllCatalogsActivity extends Activity {
System.out.println("-- "+i.getTree().getTreeTitle()); System.out.println("-- "+i.getTree().getTreeTitle());
} }
} }
if(inactiveIds.size() > 0){ if(inactiveIds.size() > 0){
idItems.add(new CheckSection(getLabelByKey("inactive"))); idItems.add(new CheckSection(getLabelByKey("inactive")));
for(String i : inactiveIds){ for(String i : inactiveIds){
idItems.add(new CheckItem(i, false, library.getCatalogTreeByUrlAll(i))); idItems.add(new CheckItem(i, false, library.getCatalogTreeByUrlAll(i)));
} }
} }
ListView selectedList = (ListView) findViewById(R.id.selectedList); ListView selectedList = (ListView) findViewById(R.id.selectedList);
myAdapter = new CheckListAdapter(this, R.layout.checkbox_item, idItems, this); myAdapter = new CheckListAdapter(this, R.layout.checkbox_item, idItems, this);
selectedList.setAdapter(myAdapter); selectedList.setAdapter(myAdapter);
} }
private String getLabelByKey(String keyName) { private String getLabelByKey(String keyName) {
return NetworkLibrary.resource().getResource("allCatalogs").getResource(keyName).getValue(); return NetworkLibrary.resource().getResource("allCatalogs").getResource(keyName).getValue();
} }
@Override @Override
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
} }
@Override @Override
public void onDestroy() { public void onDestroy() {
super.onDestroy(); super.onDestroy();
} }
@Override @Override
protected void onStop() { protected void onStop() {
super.onStop(); super.onStop();
@ -119,12 +117,12 @@ public class AllCatalogsActivity extends Activity {
library.synchronize(); library.synchronize();
} }
} }
private class CheckItem implements Comparable<CheckItem>{ private class CheckItem implements Comparable<CheckItem>{
private String myId; private String myId;
private boolean isChecked; private boolean isChecked;
NetworkTree myTree = null; NetworkTree myTree = null;
public CheckItem(String id, boolean checked, NetworkTree tree){ public CheckItem(String id, boolean checked, NetworkTree tree){
myId = id; myId = id;
isChecked = checked; isChecked = checked;
@ -134,36 +132,36 @@ public class AllCatalogsActivity extends Activity {
System.out.println("Tree parameter should be an instance of NetworkCatalogRootTree"); System.out.println("Tree parameter should be an instance of NetworkCatalogRootTree");
} }
} }
public CheckItem(String id, boolean checked){ public CheckItem(String id, boolean checked){
myId = id; myId = id;
isChecked = checked; isChecked = checked;
} }
public String getId(){ public String getId(){
return myId; return myId;
} }
public NetworkTree getTree(){ public NetworkTree getTree(){
return myTree; return myTree;
} }
public String getTitle(){ public String getTitle(){
return myTree.getLink().getTitle(); return myTree.getLink().getTitle();
} }
public String getTitleLower(){ public String getTitleLower(){
return getTitle().toLowerCase(Locale.getDefault()); return getTitle().toLowerCase(Locale.getDefault());
} }
public boolean isChecked(){ public boolean isChecked(){
return isChecked; return isChecked;
} }
public void setChecked(boolean value){ public void setChecked(boolean value){
isChecked = value; isChecked = value;
} }
public boolean isSection(){ public boolean isSection(){
return false; return false;
} }
@ -173,7 +171,7 @@ public class AllCatalogsActivity extends Activity {
return getTitleLower().compareTo(another.getTitleLower()); return getTitleLower().compareTo(another.getTitleLower());
} }
} }
private class CheckSection extends CheckItem{ private class CheckSection extends CheckItem{
public CheckSection(String title){ public CheckSection(String title){
super(title, false); super(title, false);
@ -182,28 +180,28 @@ public class AllCatalogsActivity extends Activity {
return true; return true;
} }
} }
private class CheckListAdapter extends ArrayAdapter<CheckItem> { private class CheckListAdapter extends ArrayAdapter<CheckItem> {
Activity myActivity; Activity myActivity;
private CoverManager myCoverManager; private CoverManager myCoverManager;
private ArrayList<CheckItem> items = new ArrayList<CheckItem>(); private ArrayList<CheckItem> items = new ArrayList<CheckItem>();
public CheckListAdapter(Context context, int textViewResourceId, List<CheckItem> objects, Activity activity) { public CheckListAdapter(Context context, int textViewResourceId, List<CheckItem> objects, Activity activity) {
super(context, textViewResourceId, objects); super(context, textViewResourceId, objects);
myActivity = activity; myActivity = activity;
items.addAll(objects); items.addAll(objects);
} }
public ArrayList<CheckItem> getItems(){ public ArrayList<CheckItem> getItems(){
return items; return items;
} }
@Override @Override
public View getView(int position, View convertView, final ViewGroup parent) { public View getView(int position, View convertView, final ViewGroup parent) {
View v = convertView; View v = convertView;
CheckItem item = this.getItem(position); CheckItem item = this.getItem(position);
if (item != null) { if (item != null) {
if(item.isSection()){ if(item.isSection()){
LayoutInflater vi; LayoutInflater vi;
@ -214,20 +212,20 @@ public class AllCatalogsActivity extends Activity {
tt.setText(item.getId()); tt.setText(item.getId());
} }
}else{ }else{
if (myCoverManager == null) { if (myCoverManager == null) {
v.measure(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); v.measure(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
final int coverHeight = v.getMeasuredHeight(); final int coverHeight = v.getMeasuredHeight();
myCoverManager = new CoverManager(myActivity, coverHeight * 15 / 12, coverHeight); myCoverManager = new CoverManager(myActivity, coverHeight * 15 / 12, coverHeight);
v.requestLayout(); v.requestLayout();
} }
LayoutInflater vi; LayoutInflater vi;
vi = LayoutInflater.from(getContext()); vi = LayoutInflater.from(getContext());
v = vi.inflate(R.layout.checkbox_item, null); v = vi.inflate(R.layout.checkbox_item, null);
NetworkTree t = item.getTree(); NetworkTree t = item.getTree();
if(t != null){ if(t != null){
INetworkLink link = t.getLink(); INetworkLink link = t.getLink();
TextView tt = (TextView)v.findViewById(R.id.title); TextView tt = (TextView)v.findViewById(R.id.title);
@ -238,27 +236,27 @@ public class AllCatalogsActivity extends Activity {
if (tt != null) { if (tt != null) {
tt.setText(link.getSummary()); tt.setText(link.getSummary());
} }
ImageView coverView = (ImageView)v.findViewById(R.id.icon); ImageView coverView = (ImageView)v.findViewById(R.id.icon);
if (!myCoverManager.trySetCoverImage(coverView, t)) { if (!myCoverManager.trySetCoverImage(coverView, t)) {
coverView.setImageResource(R.drawable.ic_list_library_books); coverView.setImageResource(R.drawable.ic_list_library_books);
} }
CheckBox ch = (CheckBox)v.findViewById(R.id.check_item); CheckBox ch = (CheckBox)v.findViewById(R.id.check_item);
if (ch != null) { if (ch != null) {
ch.setText(""); ch.setText("");
ch.setChecked(item.isChecked()); ch.setChecked(item.isChecked());
ch.setTag(item); ch.setTag(item);
ch.setOnClickListener( new View.OnClickListener() { ch.setOnClickListener( new View.OnClickListener() {
public void onClick(View v) { public void onClick(View v) {
CheckBox cb = (CheckBox)v; CheckBox cb = (CheckBox)v;
CheckItem checkedItem = (CheckItem) cb.getTag(); CheckItem checkedItem = (CheckItem) cb.getTag();
if(checkedItem != null){ if(checkedItem != null){
checkedItem.setChecked(cb.isChecked()); checkedItem.setChecked(cb.isChecked());
} }
isChanged = true; isChanged = true;
} }
}); });
} }
} }
} }

View file

@ -475,12 +475,10 @@ public class NetworkLibrary {
if (l != null && link.compareTo(l) <= 0) { if (l != null && link.compareTo(l) <= 0) {
break; break;
} }
++index; ++index;
} }
new NetworkCatalogRootTree(myRootTree, link, index); new NetworkCatalogRootTree(myRootTree, link, index);
} }
// we do add non-catalog items // we do add non-catalog items
new SearchCatalogTree(myRootTree, mySearchItem, 0); new SearchCatalogTree(myRootTree, mySearchItem, 0);
new AddCustomCatalogItemTree(myRootTree); new AddCustomCatalogItemTree(myRootTree);